PackageSetting.java revision c170e20c6f8ff40876887f3d74e2caec0caef6f5
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; 22import android.content.pm.UserInfo; 23import android.service.pm.PackageProto; 24import android.util.proto.ProtoOutputStream; 25 26import com.android.server.pm.permission.PermissionsState; 27 28import java.io.File; 29import java.util.List; 30 31/** 32 * Settings data for a particular package we know about. 33 */ 34public final class PackageSetting extends PackageSettingBase { 35 int appId; 36 PackageParser.Package pkg; 37 /** 38 * WARNING. The object reference is important. We perform integer equality and NOT 39 * object equality to check whether shared user settings are the same. 40 */ 41 SharedUserSetting sharedUser; 42 /** 43 * Temporary holding space for the shared user ID. While parsing package settings, the 44 * shared users tag may come after the packages. In this case, we must delay linking the 45 * shared user setting with the package setting. The shared user ID lets us link the 46 * two objects. 47 */ 48 private int sharedUserId; 49 50 PackageSetting(String name, String realName, File codePath, File resourcePath, 51 String legacyNativeLibraryPathString, String primaryCpuAbiString, 52 String secondaryCpuAbiString, String cpuAbiOverrideString, 53 long pVersionCode, int pkgFlags, int privateFlags, String parentPackageName, 54 List<String> childPackageNames, int sharedUserId, String[] usesStaticLibraries, 55 long[] usesStaticLibrariesVersions) { 56 super(name, realName, codePath, resourcePath, legacyNativeLibraryPathString, 57 primaryCpuAbiString, secondaryCpuAbiString, cpuAbiOverrideString, 58 pVersionCode, pkgFlags, privateFlags, parentPackageName, childPackageNames, 59 usesStaticLibraries, usesStaticLibrariesVersions); 60 this.sharedUserId = sharedUserId; 61 } 62 63 /** 64 * New instance of PackageSetting replicating the original settings. 65 * Note that it keeps the same PackageParser.Package instance. 66 */ 67 PackageSetting(PackageSetting orig) { 68 super(orig, orig.realName); 69 doCopy(orig); 70 } 71 72 /** 73 * New instance of PackageSetting replicating the original settings, but, allows specifying 74 * a real package name. 75 * Note that it keeps the same PackageParser.Package instance. 76 */ 77 PackageSetting(PackageSetting orig, String realPkgName) { 78 super(orig, realPkgName); 79 doCopy(orig); 80 } 81 82 public int getSharedUserId() { 83 if (sharedUser != null) { 84 return sharedUser.userId; 85 } 86 return sharedUserId; 87 } 88 89 public SharedUserSetting getSharedUser() { 90 return sharedUser; 91 } 92 93 @Override 94 public String toString() { 95 return "PackageSetting{" 96 + Integer.toHexString(System.identityHashCode(this)) 97 + " " + name + "/" + appId + "}"; 98 } 99 100 // Temporary to catch potential issues with refactoring 101 public String dumpState_temp() { 102 String flags = ""; 103 flags += ((pkgFlags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0 ? "U" : ""); 104 flags += ((pkgFlags & ApplicationInfo.FLAG_SYSTEM) != 0 ? "S" : ""); 105 if ("".equals(flags)) { 106 flags = "-"; 107 } 108 String privFlags = ""; 109 privFlags += ((pkgPrivateFlags & ApplicationInfo.PRIVATE_FLAG_PRIVILEGED) != 0 ? "P" : ""); 110 privFlags += ((pkgPrivateFlags & ApplicationInfo.PRIVATE_FLAG_OEM) != 0 ? "O" : ""); 111 privFlags += ((pkgPrivateFlags & ApplicationInfo.PRIVATE_FLAG_VENDOR) != 0 ? "V" : ""); 112 if ("".equals(privFlags)) { 113 privFlags = "-"; 114 } 115 return "PackageSetting{" 116 + Integer.toHexString(System.identityHashCode(this)) 117 + " " + name + (realName == null ? "" : "("+realName+")") + "/" + appId + (sharedUser==null?"":" u:" + sharedUser.name+"("+sharedUserId+")") 118 + ", ver:" + versionCode 119 + ", path: " + codePath 120 + ", pABI: " + primaryCpuAbiString 121 + ", sABI: " + secondaryCpuAbiString 122 + ", oABI: " + cpuAbiOverrideString 123 + ", flags: " + flags 124 + ", privFlags: " + privFlags 125 + ", pkg: " + (pkg == null ? "<<NULL>>" : "{" + Integer.toHexString(System.identityHashCode(pkg)) + "}") 126 + "}"; 127 } 128 129 public void copyFrom(PackageSetting orig) { 130 super.copyFrom(orig); 131 doCopy(orig); 132 } 133 134 private void doCopy(PackageSetting orig) { 135 appId = orig.appId; 136 pkg = orig.pkg; 137 sharedUser = orig.sharedUser; 138 sharedUserId = orig.sharedUserId; 139 } 140 141 @Override 142 public PermissionsState getPermissionsState() { 143 return (sharedUser != null) 144 ? sharedUser.getPermissionsState() 145 : super.getPermissionsState(); 146 } 147 148 public PackageParser.Package getPackage() { 149 return pkg; 150 } 151 152 public int getAppId() { 153 return appId; 154 } 155 156 public void setInstallPermissionsFixed(boolean fixed) { 157 installPermissionsFixed = fixed; 158 } 159 160 public boolean areInstallPermissionsFixed() { 161 return installPermissionsFixed; 162 } 163 164 public boolean isPrivileged() { 165 return (pkgPrivateFlags & ApplicationInfo.PRIVATE_FLAG_PRIVILEGED) != 0; 166 } 167 168 public boolean isOem() { 169 return (pkgPrivateFlags & ApplicationInfo.PRIVATE_FLAG_OEM) != 0; 170 } 171 172 public boolean isVendor() { 173 return (pkgPrivateFlags & ApplicationInfo.PRIVATE_FLAG_VENDOR) != 0; 174 } 175 176 public boolean isForwardLocked() { 177 return (pkgPrivateFlags & ApplicationInfo.PRIVATE_FLAG_FORWARD_LOCK) != 0; 178 } 179 180 public boolean isSystem() { 181 return (pkgFlags & ApplicationInfo.FLAG_SYSTEM) != 0; 182 } 183 184 public boolean isUpdatedSystem() { 185 return (pkgFlags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0; 186 } 187 188 @Override 189 public boolean isSharedUser() { 190 return sharedUser != null; 191 } 192 193 public boolean isMatch(int flags) { 194 if ((flags & PackageManager.MATCH_SYSTEM_ONLY) != 0) { 195 return isSystem(); 196 } 197 return true; 198 } 199 200 public boolean hasChildPackages() { 201 return childPackageNames != null && !childPackageNames.isEmpty(); 202 } 203 204 public void writeToProto(ProtoOutputStream proto, long fieldId, List<UserInfo> users) { 205 final long packageToken = proto.start(fieldId); 206 proto.write(PackageProto.NAME, (realName != null ? realName : name)); 207 proto.write(PackageProto.UID, appId); 208 proto.write(PackageProto.VERSION_CODE, versionCode); 209 proto.write(PackageProto.VERSION_STRING, pkg.mVersionName); 210 proto.write(PackageProto.INSTALL_TIME_MS, firstInstallTime); 211 proto.write(PackageProto.UPDATE_TIME_MS, lastUpdateTime); 212 proto.write(PackageProto.INSTALLER_NAME, installerPackageName); 213 214 if (pkg != null) { 215 long splitToken = proto.start(PackageProto.SPLITS); 216 proto.write(PackageProto.SplitProto.NAME, "base"); 217 proto.write(PackageProto.SplitProto.REVISION_CODE, pkg.baseRevisionCode); 218 proto.end(splitToken); 219 if (pkg.splitNames != null) { 220 for (int i = 0; i < pkg.splitNames.length; i++) { 221 splitToken = proto.start(PackageProto.SPLITS); 222 proto.write(PackageProto.SplitProto.NAME, pkg.splitNames[i]); 223 proto.write(PackageProto.SplitProto.REVISION_CODE, pkg.splitRevisionCodes[i]); 224 proto.end(splitToken); 225 } 226 } 227 } 228 writeUsersInfoToProto(proto, PackageProto.USERS); 229 proto.end(packageToken); 230 } 231} 232