blob: e2f83adda16b95c8efe767d1d861ae3cb76a06bc [file] [log] [blame]
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001/*
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 static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
20import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
21import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
22
23
24import java.io.File;
25import java.util.HashSet;
26
27/**
28 * Settings base class for pending and resolved classes.
29 */
30class PackageSettingBase extends GrantedPermissions {
31 /**
32 * Indicates the state of installation. Used by PackageManager to figure out
33 * incomplete installations. Say a package is being installed (the state is
34 * set to PKG_INSTALL_INCOMPLETE) and remains so till the package
35 * installation is successful or unsuccessful in which case the
36 * PackageManager will no longer maintain state information associated with
37 * the package. If some exception(like device freeze or battery being pulled
38 * out) occurs during installation of a package, the PackageManager needs
39 * this information to clean up the previously failed installation.
40 */
41 static final int PKG_INSTALL_COMPLETE = 1;
42 static final int PKG_INSTALL_INCOMPLETE = 0;
43
44 final String name;
45 final String realName;
46 File codePath;
47 String codePathString;
48 File resourcePath;
49 String resourcePathString;
50 String nativeLibraryPathString;
51 long timeStamp;
52 long firstInstallTime;
53 long lastUpdateTime;
54 int versionCode;
55
56 boolean uidError;
57
58 PackageSignatures signatures = new PackageSignatures();
59
60 boolean permissionsFixed;
61 boolean haveGids;
62
63 // Whether this package is currently stopped, thus can not be
64 // started until explicitly launched by the user.
65 public boolean stopped;
66
67 // Set to true if we have never launched this app.
68 public boolean notLaunched;
69
70 /* Explicitly disabled components */
71 HashSet<String> disabledComponents = new HashSet<String>(0);
72 /* Explicitly enabled components */
73 HashSet<String> enabledComponents = new HashSet<String>(0);
74 int enabled = COMPONENT_ENABLED_STATE_DEFAULT;
75 int installStatus = PKG_INSTALL_COMPLETE;
76
77 PackageSettingBase origPackage;
78
79 /* package name of the app that installed this package */
80 String installerPackageName;
81 PackageSettingBase(String name, String realName, File codePath, File resourcePath,
82 String nativeLibraryPathString, int pVersionCode, int pkgFlags) {
83 super(pkgFlags);
84 this.name = name;
85 this.realName = realName;
86 init(codePath, resourcePath, nativeLibraryPathString, pVersionCode);
87 }
88
89 /**
90 * New instance of PackageSetting with one-level-deep cloning.
91 */
92 @SuppressWarnings("unchecked")
93 PackageSettingBase(PackageSettingBase base) {
94 super(base);
95
96 name = base.name;
97 realName = base.realName;
98 codePath = base.codePath;
99 codePathString = base.codePathString;
100 resourcePath = base.resourcePath;
101 resourcePathString = base.resourcePathString;
102 nativeLibraryPathString = base.nativeLibraryPathString;
103 timeStamp = base.timeStamp;
104 firstInstallTime = base.firstInstallTime;
105 lastUpdateTime = base.lastUpdateTime;
106 versionCode = base.versionCode;
107
108 uidError = base.uidError;
109
110 signatures = new PackageSignatures(base.signatures);
111
112 permissionsFixed = base.permissionsFixed;
113 haveGids = base.haveGids;
114 stopped = base.stopped;
115 notLaunched = base.notLaunched;
116
117 disabledComponents = (HashSet<String>) base.disabledComponents.clone();
118
119 enabledComponents = (HashSet<String>) base.enabledComponents.clone();
120
121 enabled = base.enabled;
122 installStatus = base.installStatus;
123
124 origPackage = base.origPackage;
125
126 installerPackageName = base.installerPackageName;
127 }
128
129 void init(File codePath, File resourcePath, String nativeLibraryPathString,
130 int pVersionCode) {
131 this.codePath = codePath;
132 this.codePathString = codePath.toString();
133 this.resourcePath = resourcePath;
134 this.resourcePathString = resourcePath.toString();
135 this.nativeLibraryPathString = nativeLibraryPathString;
136 this.versionCode = pVersionCode;
137 }
138
139 public void setInstallerPackageName(String packageName) {
140 installerPackageName = packageName;
141 }
142
143 String getInstallerPackageName() {
144 return installerPackageName;
145 }
146
147 public void setInstallStatus(int newStatus) {
148 installStatus = newStatus;
149 }
150
151 public int getInstallStatus() {
152 return installStatus;
153 }
154
155 public void setTimeStamp(long newStamp) {
156 timeStamp = newStamp;
157 }
158
159 /**
160 * Make a shallow copy of this package settings.
161 */
162 public void copyFrom(PackageSettingBase base) {
163 grantedPermissions = base.grantedPermissions;
164 gids = base.gids;
165
166 timeStamp = base.timeStamp;
167 firstInstallTime = base.firstInstallTime;
168 lastUpdateTime = base.lastUpdateTime;
169 signatures = base.signatures;
170 permissionsFixed = base.permissionsFixed;
171 haveGids = base.haveGids;
172 stopped = base.stopped;
173 notLaunched = base.notLaunched;
174 disabledComponents = base.disabledComponents;
175 enabledComponents = base.enabledComponents;
176 enabled = base.enabled;
177 installStatus = base.installStatus;
178 }
179
Kenny Root447106f2011-03-23 11:00:15 -0700180 boolean enableComponentLPw(String componentClassName) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700181 boolean changed = disabledComponents.remove(componentClassName);
182 changed |= enabledComponents.add(componentClassName);
183 return changed;
184 }
185
Kenny Root447106f2011-03-23 11:00:15 -0700186 boolean disableComponentLPw(String componentClassName) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700187 boolean changed = enabledComponents.remove(componentClassName);
188 changed |= disabledComponents.add(componentClassName);
189 return changed;
190 }
191
Kenny Root447106f2011-03-23 11:00:15 -0700192 boolean restoreComponentLPw(String componentClassName) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700193 boolean changed = enabledComponents.remove(componentClassName);
194 changed |= disabledComponents.remove(componentClassName);
195 return changed;
196 }
197
Kenny Root447106f2011-03-23 11:00:15 -0700198 int getCurrentEnabledStateLPr(String componentName) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700199 if (enabledComponents.contains(componentName)) {
200 return COMPONENT_ENABLED_STATE_ENABLED;
201 } else if (disabledComponents.contains(componentName)) {
202 return COMPONENT_ENABLED_STATE_DISABLED;
203 } else {
204 return COMPONENT_ENABLED_STATE_DEFAULT;
205 }
206 }
207}