PackageSetting.java revision 6788212d17f54475ca9c3dd689a863e031db868f
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; 24import java.util.List; 25 26/** 27 * Settings data for a particular package we know about. 28 */ 29final class PackageSetting extends PackageSettingBase { 30 int appId; 31 PackageParser.Package pkg; 32 /** 33 * WARNING. The object reference is important. We perform integer equality and NOT 34 * object equality to check whether shared user settings are the same. 35 */ 36 SharedUserSetting sharedUser; 37 /** 38 * Temporary holding space for the shared user ID. While parsing package settings, the 39 * shared users tag may come after the packages. In this case, we must delay linking the 40 * shared user setting with the package setting. The shared user ID lets us link the 41 * two objects. 42 */ 43 private int sharedUserId; 44 45 PackageSetting(String name, String realName, File codePath, File resourcePath, 46 String legacyNativeLibraryPathString, String primaryCpuAbiString, 47 String secondaryCpuAbiString, String cpuAbiOverrideString, 48 int pVersionCode, int pkgFlags, int privateFlags, String parentPackageName, 49 List<String> childPackageNames, int sharedUserId, String[] usesStaticLibraries, 50 int[] usesStaticLibrariesVersions) { 51 super(name, realName, codePath, resourcePath, legacyNativeLibraryPathString, 52 primaryCpuAbiString, secondaryCpuAbiString, cpuAbiOverrideString, 53 pVersionCode, pkgFlags, privateFlags, parentPackageName, childPackageNames, 54 usesStaticLibraries, usesStaticLibrariesVersions); 55 this.sharedUserId = sharedUserId; 56 } 57 58 /** 59 * New instance of PackageSetting replicating the original settings. 60 * Note that it keeps the same PackageParser.Package instance. 61 */ 62 PackageSetting(PackageSetting orig) { 63 super(orig, orig.realName); 64 doCopy(orig); 65 } 66 67 /** 68 * New instance of PackageSetting replicating the original settings, but, allows specifying 69 * a real package name. 70 * Note that it keeps the same PackageParser.Package instance. 71 */ 72 PackageSetting(PackageSetting orig, String realPkgName) { 73 super(orig, realPkgName); 74 doCopy(orig); 75 } 76 77 public int getSharedUserId() { 78 if (sharedUser != null) { 79 return sharedUser.userId; 80 } 81 return sharedUserId; 82 } 83 84 @Override 85 public String toString() { 86 return "PackageSetting{" 87 + Integer.toHexString(System.identityHashCode(this)) 88 + " " + name + "/" + appId + "}"; 89 } 90 91 public void copyFrom(PackageSetting orig) { 92 super.copyFrom(orig); 93 doCopy(orig); 94 } 95 96 private void doCopy(PackageSetting orig) { 97 appId = orig.appId; 98 pkg = orig.pkg; 99 sharedUser = orig.sharedUser; 100 sharedUserId = orig.sharedUserId; 101 } 102 103 public PermissionsState getPermissionsState() { 104 return (sharedUser != null) 105 ? sharedUser.getPermissionsState() 106 : super.getPermissionsState(); 107 } 108 109 public boolean isPrivileged() { 110 return (pkgPrivateFlags & ApplicationInfo.PRIVATE_FLAG_PRIVILEGED) != 0; 111 } 112 113 public boolean isForwardLocked() { 114 return (pkgPrivateFlags & ApplicationInfo.PRIVATE_FLAG_FORWARD_LOCK) != 0; 115 } 116 117 public boolean isSystem() { 118 return (pkgFlags & ApplicationInfo.FLAG_SYSTEM) != 0; 119 } 120 121 public boolean isSharedUser() { 122 return sharedUser != null; 123 } 124 125 public boolean isMatch(int flags) { 126 if ((flags & PackageManager.MATCH_SYSTEM_ONLY) != 0) { 127 return isSystem(); 128 } 129 return true; 130 } 131} 132