PackageSetting.java revision c5967e9862489024c932b0c7fcb84ed0af2a7fd7
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;
20import android.content.pm.PackageManager;
21import android.content.pm.PackageParser;
22
23import java.io.File;
24
25/**
26 * Settings data for a particular package we know about.
27 */
28final class PackageSetting extends PackageSettingBase {
29    int appId;
30    PackageParser.Package pkg;
31    SharedUserSetting sharedUser;
32
33    PackageSetting(String name, String realName, File codePath, File resourcePath,
34            String legacyNativeLibraryPathString, String primaryCpuAbiString,
35            String secondaryCpuAbiString, String cpuAbiOverrideString,
36            int pVersionCode, int pkgFlags, int privateFlags) {
37        super(name, realName, codePath, resourcePath, legacyNativeLibraryPathString,
38                primaryCpuAbiString, secondaryCpuAbiString, cpuAbiOverrideString,
39                pVersionCode, pkgFlags, privateFlags);
40    }
41
42    /**
43     * New instance of PackageSetting replicating the original settings.
44     * Note that it keeps the same PackageParser.Package instance.
45     */
46    PackageSetting(PackageSetting orig) {
47        super(orig);
48
49        appId = orig.appId;
50        pkg = orig.pkg;
51        sharedUser = orig.sharedUser;
52    }
53
54    @Override
55    public String toString() {
56        return "PackageSetting{"
57            + Integer.toHexString(System.identityHashCode(this))
58            + " " + name + "/" + appId + "}";
59    }
60
61    public PermissionsState getPermissionsState() {
62        return (sharedUser != null)
63                ? sharedUser.getPermissionsState()
64                : super.getPermissionsState();
65    }
66
67    public boolean isPrivileged() {
68        return (pkgPrivateFlags & ApplicationInfo.PRIVATE_FLAG_PRIVILEGED) != 0;
69    }
70
71    public boolean isForwardLocked() {
72        return (pkgPrivateFlags & ApplicationInfo.PRIVATE_FLAG_FORWARD_LOCK) != 0;
73    }
74
75    public boolean isSystem() {
76        return (pkgFlags & ApplicationInfo.FLAG_SYSTEM) != 0;
77    }
78
79    public boolean isSharedUser() {
80        return sharedUser != null;
81    }
82
83    public boolean isMatch(int flags) {
84        if ((flags & PackageManager.MATCH_SYSTEM_ONLY) != 0) {
85            return isSystem();
86        }
87        return true;
88    }
89}
90