SettingBase.java revision 37f05184b5641366b59c540ad6bf3e3b2a1ac6ea
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    int pkgFlags;
25    int pkgPrivateFlags;
26
27    protected final PermissionsState mPermissionsState;
28    private int[] mPermissionsUpdatedForUserIds = PermissionsState.USERS_NONE;
29
30    SettingBase(int pkgFlags, int pkgPrivateFlags) {
31        setFlags(pkgFlags);
32        setPrivateFlags(pkgPrivateFlags);
33        mPermissionsState = new PermissionsState();
34    }
35
36    SettingBase(SettingBase base) {
37        pkgFlags = base.pkgFlags;
38        pkgPrivateFlags = base.pkgPrivateFlags;
39        mPermissionsState = new PermissionsState(base.mPermissionsState);
40        setPermissionsUpdatedForUserIds(base.mPermissionsUpdatedForUserIds);
41    }
42
43    public PermissionsState getPermissionsState() {
44        return mPermissionsState;
45    }
46
47    public int[] getPermissionsUpdatedForUserIds() {
48        return mPermissionsUpdatedForUserIds;
49    }
50
51    public void setPermissionsUpdatedForUserIds(int[] userIds) {
52        if (Arrays.equals(mPermissionsUpdatedForUserIds, userIds)) {
53            return;
54        }
55
56        if (userIds == PermissionsState.USERS_NONE || userIds == PermissionsState.USERS_ALL) {
57            mPermissionsUpdatedForUserIds = userIds;
58        } else {
59            mPermissionsUpdatedForUserIds = Arrays.copyOf(userIds, userIds.length);
60        }
61    }
62
63    void setFlags(int pkgFlags) {
64        this.pkgFlags = pkgFlags
65                & (ApplicationInfo.FLAG_SYSTEM
66                        | ApplicationInfo.FLAG_EXTERNAL_STORAGE);
67    }
68
69    void setPrivateFlags(int pkgPrivateFlags) {
70        this.pkgPrivateFlags = pkgPrivateFlags
71                & (ApplicationInfo.PRIVATE_FLAG_PRIVILEGED
72                        | ApplicationInfo.PRIVATE_FLAG_FORWARD_LOCK);
73    }
74}
75