1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.packageinstaller.permission.model; 18 19 import android.content.pm.PackageManager; 20 21 public final class Permission { 22 private final String mName; 23 private final String mAppOp; 24 25 private boolean mGranted; 26 private boolean mAppOpAllowed; 27 private int mFlags; 28 Permission(String name, boolean granted, String appOp, boolean appOpAllowed, int flags)29 public Permission(String name, boolean granted, 30 String appOp, boolean appOpAllowed, int flags) { 31 mName = name; 32 mGranted = granted; 33 mAppOp = appOp; 34 mAppOpAllowed = appOpAllowed; 35 mFlags = flags; 36 } 37 getName()38 public String getName() { 39 return mName; 40 } 41 getAppOp()42 public String getAppOp() { 43 return mAppOp; 44 } 45 getFlags()46 public int getFlags() { 47 return mFlags; 48 } 49 hasAppOp()50 public boolean hasAppOp() { 51 return mAppOp != null; 52 } 53 isGranted()54 public boolean isGranted() { 55 return mGranted; 56 } 57 isReviewRequired()58 public boolean isReviewRequired() { 59 return (mFlags & PackageManager.FLAG_PERMISSION_REVIEW_REQUIRED) != 0; 60 } 61 resetReviewRequired()62 public void resetReviewRequired() { 63 mFlags &= ~PackageManager.FLAG_PERMISSION_REVIEW_REQUIRED; 64 } 65 setGranted(boolean mGranted)66 public void setGranted(boolean mGranted) { 67 this.mGranted = mGranted; 68 } 69 isAppOpAllowed()70 public boolean isAppOpAllowed() { 71 return mAppOpAllowed; 72 } 73 isUserFixed()74 public boolean isUserFixed() { 75 return (mFlags & PackageManager.FLAG_PERMISSION_USER_FIXED) != 0; 76 } 77 setUserFixed(boolean userFixed)78 public void setUserFixed(boolean userFixed) { 79 if (userFixed) { 80 mFlags |= PackageManager.FLAG_PERMISSION_USER_FIXED; 81 } else { 82 mFlags &= ~PackageManager.FLAG_PERMISSION_USER_FIXED; 83 } 84 } 85 isSystemFixed()86 public boolean isSystemFixed() { 87 return (mFlags & PackageManager.FLAG_PERMISSION_SYSTEM_FIXED) != 0; 88 } 89 isPolicyFixed()90 public boolean isPolicyFixed() { 91 return (mFlags & PackageManager.FLAG_PERMISSION_POLICY_FIXED) != 0; 92 } 93 isUserSet()94 public boolean isUserSet() { 95 return (mFlags & PackageManager.FLAG_PERMISSION_USER_SET) != 0; 96 } 97 isGrantedByDefault()98 public boolean isGrantedByDefault() { 99 return (mFlags & PackageManager.FLAG_PERMISSION_GRANTED_BY_DEFAULT) != 0; 100 } 101 setUserSet(boolean userSet)102 public void setUserSet(boolean userSet) { 103 if (userSet) { 104 mFlags |= PackageManager.FLAG_PERMISSION_USER_SET; 105 } else { 106 mFlags &= ~PackageManager.FLAG_PERMISSION_USER_SET; 107 } 108 } 109 setPolicyFixed(boolean policyFixed)110 public void setPolicyFixed(boolean policyFixed) { 111 if (policyFixed) { 112 mFlags |= PackageManager.FLAG_PERMISSION_POLICY_FIXED; 113 } else { 114 mFlags &= ~PackageManager.FLAG_PERMISSION_POLICY_FIXED; 115 } 116 } 117 shouldRevokeOnUpgrade()118 public boolean shouldRevokeOnUpgrade() { 119 return (mFlags & PackageManager.FLAG_PERMISSION_REVOKE_ON_UPGRADE) != 0; 120 } 121 setRevokeOnUpgrade(boolean revokeOnUpgrade)122 public void setRevokeOnUpgrade(boolean revokeOnUpgrade) { 123 if (revokeOnUpgrade) { 124 mFlags |= PackageManager.FLAG_PERMISSION_REVOKE_ON_UPGRADE; 125 } else { 126 mFlags &= ~PackageManager.FLAG_PERMISSION_REVOKE_ON_UPGRADE; 127 } 128 } 129 setAppOpAllowed(boolean mAppOpAllowed)130 public void setAppOpAllowed(boolean mAppOpAllowed) { 131 this.mAppOpAllowed = mAppOpAllowed; 132 } 133 }