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