Home | History | Annotate | Download | only in model
      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.app.AppOpsManager;
     20 import android.content.pm.PackageManager;
     21 
     22 public final class Permission {
     23     private final String mName;
     24     private final int mAppOp;
     25 
     26     private boolean mGranted;
     27     private boolean mAppOpAllowed;
     28     private int mFlags;
     29 
     30     public Permission(String name, boolean granted,
     31             int appOp, boolean appOpAllowed, int flags) {
     32         mName = name;
     33         mGranted = granted;
     34         mAppOp = appOp;
     35         mAppOpAllowed = appOpAllowed;
     36         mFlags = flags;
     37     }
     38 
     39     public String getName() {
     40         return mName;
     41     }
     42 
     43     public int getAppOp() {
     44         return mAppOp;
     45     }
     46 
     47     public int getFlags() {
     48         return mFlags;
     49     }
     50 
     51     public boolean hasAppOp() {
     52         return mAppOp != AppOpsManager.OP_NONE;
     53     }
     54 
     55     public boolean isGranted() {
     56         return mGranted;
     57     }
     58 
     59     public void setGranted(boolean mGranted) {
     60         this.mGranted = mGranted;
     61     }
     62 
     63     public boolean isAppOpAllowed() {
     64         return mAppOpAllowed;
     65     }
     66 
     67     public boolean isUserFixed() {
     68         return (mFlags & PackageManager.FLAG_PERMISSION_USER_FIXED) != 0;
     69     }
     70 
     71     public void setUserFixed(boolean userFixed) {
     72         if (userFixed) {
     73             mFlags |= PackageManager.FLAG_PERMISSION_USER_FIXED;
     74         } else {
     75             mFlags &= ~PackageManager.FLAG_PERMISSION_USER_FIXED;
     76         }
     77     }
     78 
     79     public boolean isSystemFixed() {
     80         return (mFlags & PackageManager.FLAG_PERMISSION_SYSTEM_FIXED) != 0;
     81     }
     82 
     83     public boolean isPolicyFixed() {
     84         return (mFlags & PackageManager.FLAG_PERMISSION_POLICY_FIXED) != 0;
     85     }
     86 
     87     public boolean isUserSet() {
     88         return (mFlags & PackageManager.FLAG_PERMISSION_USER_SET) != 0;
     89     }
     90 
     91     public boolean isGrantedByDefault() {
     92         return (mFlags & PackageManager.FLAG_PERMISSION_GRANTED_BY_DEFAULT) != 0;
     93     }
     94 
     95     public void setUserSet(boolean userSet) {
     96         if (userSet) {
     97             mFlags |= PackageManager.FLAG_PERMISSION_USER_SET;
     98         } else {
     99             mFlags &= ~PackageManager.FLAG_PERMISSION_USER_SET;
    100         }
    101     }
    102 
    103     public void setPolicyFixed(boolean policyFixed) {
    104         if (policyFixed) {
    105             mFlags |= PackageManager.FLAG_PERMISSION_POLICY_FIXED;
    106         } else {
    107             mFlags &= ~PackageManager.FLAG_PERMISSION_POLICY_FIXED;
    108         }
    109     }
    110 
    111     public boolean shouldRevokeOnUpgrade() {
    112         return (mFlags & PackageManager.FLAG_PERMISSION_REVOKE_ON_UPGRADE) != 0;
    113     }
    114 
    115     public void setRevokeOnUpgrade(boolean revokeOnUpgrade) {
    116         if (revokeOnUpgrade) {
    117             mFlags |= PackageManager.FLAG_PERMISSION_REVOKE_ON_UPGRADE;
    118         } else {
    119             mFlags &= ~PackageManager.FLAG_PERMISSION_REVOKE_ON_UPGRADE;
    120         }
    121     }
    122 
    123     public void setAppOpAllowed(boolean mAppOpAllowed) {
    124         this.mAppOpAllowed = mAppOpAllowed;
    125     }
    126 }