SettingBase.java revision 8c7f700a59ad26e75c9791335d78f14322cad49a
1/* 2 * Copyright (C) 2011 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 17package com.android.server.pm; 18 19import android.content.pm.ApplicationInfo; 20 21import java.util.Arrays; 22 23abstract class SettingBase { 24 private static final int[] USERS_NONE = new int[0]; 25 26 int pkgFlags; 27 int pkgPrivateFlags; 28 29 protected final PermissionsState mPermissionsState; 30 private int[] mPermissionsUpdatedForUserIds = USERS_NONE; 31 32 SettingBase(int pkgFlags, int pkgPrivateFlags) { 33 setFlags(pkgFlags); 34 setPrivateFlags(pkgPrivateFlags); 35 mPermissionsState = new PermissionsState(); 36 } 37 38 SettingBase(SettingBase base) { 39 pkgFlags = base.pkgFlags; 40 pkgPrivateFlags = base.pkgPrivateFlags; 41 mPermissionsState = new PermissionsState(base.mPermissionsState); 42 setPermissionsUpdatedForUserIds(base.mPermissionsUpdatedForUserIds); 43 } 44 45 public PermissionsState getPermissionsState() { 46 return mPermissionsState; 47 } 48 49 public int[] getPermissionsUpdatedForUserIds() { 50 return mPermissionsUpdatedForUserIds; 51 } 52 53 public void setPermissionsUpdatedForUserIds(int[] userIds) { 54 if (Arrays.equals(mPermissionsUpdatedForUserIds, userIds)) { 55 return; 56 } 57 58 if (userIds == USERS_NONE) { 59 mPermissionsUpdatedForUserIds = userIds; 60 } else { 61 mPermissionsUpdatedForUserIds = Arrays.copyOf(userIds, userIds.length); 62 } 63 } 64 65 void setFlags(int pkgFlags) { 66 this.pkgFlags = pkgFlags 67 & (ApplicationInfo.FLAG_SYSTEM 68 | ApplicationInfo.FLAG_EXTERNAL_STORAGE); 69 } 70 71 void setPrivateFlags(int pkgPrivateFlags) { 72 this.pkgPrivateFlags = pkgPrivateFlags 73 & (ApplicationInfo.PRIVATE_FLAG_PRIVILEGED 74 | ApplicationInfo.PRIVATE_FLAG_FORWARD_LOCK); 75 } 76} 77