Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 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 static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DEFAULT; |
| 20 | import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED; |
| 21 | import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED; |
| 22 | |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 23 | import android.content.pm.PackageUserState; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 24 | import android.util.SparseArray; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 25 | |
| 26 | import java.io.File; |
| 27 | import java.util.HashSet; |
| 28 | |
| 29 | /** |
| 30 | * Settings base class for pending and resolved classes. |
| 31 | */ |
| 32 | class PackageSettingBase extends GrantedPermissions { |
| 33 | /** |
| 34 | * Indicates the state of installation. Used by PackageManager to figure out |
| 35 | * incomplete installations. Say a package is being installed (the state is |
| 36 | * set to PKG_INSTALL_INCOMPLETE) and remains so till the package |
| 37 | * installation is successful or unsuccessful in which case the |
| 38 | * PackageManager will no longer maintain state information associated with |
| 39 | * the package. If some exception(like device freeze or battery being pulled |
| 40 | * out) occurs during installation of a package, the PackageManager needs |
| 41 | * this information to clean up the previously failed installation. |
| 42 | */ |
| 43 | static final int PKG_INSTALL_COMPLETE = 1; |
| 44 | static final int PKG_INSTALL_INCOMPLETE = 0; |
| 45 | |
| 46 | final String name; |
| 47 | final String realName; |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 48 | |
| 49 | /** |
| 50 | * Path where this package was found on disk. For monolithic packages |
| 51 | * this is path to single base APK file; for cluster packages this is |
| 52 | * path to the cluster directory. |
| 53 | */ |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 54 | File codePath; |
| 55 | String codePathString; |
| 56 | File resourcePath; |
| 57 | String resourcePathString; |
| 58 | String nativeLibraryPathString; |
Narayan Kamath | 34f6084 | 2014-04-30 14:38:46 +0100 | [diff] [blame] | 59 | String cpuAbiString; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 60 | long timeStamp; |
| 61 | long firstInstallTime; |
| 62 | long lastUpdateTime; |
| 63 | int versionCode; |
| 64 | |
| 65 | boolean uidError; |
| 66 | |
| 67 | PackageSignatures signatures = new PackageSignatures(); |
| 68 | |
| 69 | boolean permissionsFixed; |
| 70 | boolean haveGids; |
| 71 | |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 72 | PackageKeySetData keySetData = new PackageKeySetData(); |
| 73 | |
Dianne Hackborn | 4a9f071 | 2012-10-02 15:29:06 -0700 | [diff] [blame] | 74 | private static final PackageUserState DEFAULT_USER_STATE = new PackageUserState(); |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 75 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 76 | // Whether this package is currently stopped, thus can not be |
| 77 | // started until explicitly launched by the user. |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 78 | private final SparseArray<PackageUserState> userState = new SparseArray<PackageUserState>(); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 79 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 80 | int installStatus = PKG_INSTALL_COMPLETE; |
| 81 | |
| 82 | PackageSettingBase origPackage; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 83 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 84 | /* package name of the app that installed this package */ |
| 85 | String installerPackageName; |
| 86 | PackageSettingBase(String name, String realName, File codePath, File resourcePath, |
Narayan Kamath | 34f6084 | 2014-04-30 14:38:46 +0100 | [diff] [blame] | 87 | String nativeLibraryPathString, String cpuAbiString, int pVersionCode, int pkgFlags) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 88 | super(pkgFlags); |
| 89 | this.name = name; |
| 90 | this.realName = realName; |
Narayan Kamath | 34f6084 | 2014-04-30 14:38:46 +0100 | [diff] [blame] | 91 | init(codePath, resourcePath, nativeLibraryPathString, cpuAbiString, pVersionCode); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | /** |
| 95 | * New instance of PackageSetting with one-level-deep cloning. |
| 96 | */ |
| 97 | @SuppressWarnings("unchecked") |
| 98 | PackageSettingBase(PackageSettingBase base) { |
| 99 | super(base); |
| 100 | |
| 101 | name = base.name; |
| 102 | realName = base.realName; |
| 103 | codePath = base.codePath; |
| 104 | codePathString = base.codePathString; |
| 105 | resourcePath = base.resourcePath; |
| 106 | resourcePathString = base.resourcePathString; |
| 107 | nativeLibraryPathString = base.nativeLibraryPathString; |
Narayan Kamath | 34f6084 | 2014-04-30 14:38:46 +0100 | [diff] [blame] | 108 | cpuAbiString = base.cpuAbiString; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 109 | timeStamp = base.timeStamp; |
| 110 | firstInstallTime = base.firstInstallTime; |
| 111 | lastUpdateTime = base.lastUpdateTime; |
| 112 | versionCode = base.versionCode; |
| 113 | |
| 114 | uidError = base.uidError; |
| 115 | |
| 116 | signatures = new PackageSignatures(base.signatures); |
| 117 | |
| 118 | permissionsFixed = base.permissionsFixed; |
| 119 | haveGids = base.haveGids; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 120 | userState.clear(); |
| 121 | for (int i=0; i<base.userState.size(); i++) { |
| 122 | userState.put(base.userState.keyAt(i), |
| 123 | new PackageUserState(base.userState.valueAt(i))); |
| 124 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 125 | installStatus = base.installStatus; |
| 126 | |
| 127 | origPackage = base.origPackage; |
| 128 | |
| 129 | installerPackageName = base.installerPackageName; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 130 | |
| 131 | keySetData = new PackageKeySetData(base.keySetData); |
| 132 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | void init(File codePath, File resourcePath, String nativeLibraryPathString, |
Ramin Zaghi | ff0c470 | 2014-04-01 15:02:29 +0100 | [diff] [blame] | 136 | String requiredCpuAbiString, int pVersionCode) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 137 | this.codePath = codePath; |
| 138 | this.codePathString = codePath.toString(); |
| 139 | this.resourcePath = resourcePath; |
| 140 | this.resourcePathString = resourcePath.toString(); |
| 141 | this.nativeLibraryPathString = nativeLibraryPathString; |
Narayan Kamath | 34f6084 | 2014-04-30 14:38:46 +0100 | [diff] [blame] | 142 | this.cpuAbiString = requiredCpuAbiString; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 143 | this.versionCode = pVersionCode; |
| 144 | } |
| 145 | |
| 146 | public void setInstallerPackageName(String packageName) { |
| 147 | installerPackageName = packageName; |
| 148 | } |
| 149 | |
| 150 | String getInstallerPackageName() { |
| 151 | return installerPackageName; |
| 152 | } |
| 153 | |
| 154 | public void setInstallStatus(int newStatus) { |
| 155 | installStatus = newStatus; |
| 156 | } |
| 157 | |
| 158 | public int getInstallStatus() { |
| 159 | return installStatus; |
| 160 | } |
| 161 | |
| 162 | public void setTimeStamp(long newStamp) { |
| 163 | timeStamp = newStamp; |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Make a shallow copy of this package settings. |
| 168 | */ |
| 169 | public void copyFrom(PackageSettingBase base) { |
| 170 | grantedPermissions = base.grantedPermissions; |
| 171 | gids = base.gids; |
| 172 | |
Narayan Kamath | 34f6084 | 2014-04-30 14:38:46 +0100 | [diff] [blame] | 173 | cpuAbiString = base.cpuAbiString; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 174 | timeStamp = base.timeStamp; |
| 175 | firstInstallTime = base.firstInstallTime; |
| 176 | lastUpdateTime = base.lastUpdateTime; |
| 177 | signatures = base.signatures; |
| 178 | permissionsFixed = base.permissionsFixed; |
| 179 | haveGids = base.haveGids; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 180 | userState.clear(); |
| 181 | for (int i=0; i<base.userState.size(); i++) { |
| 182 | userState.put(base.userState.keyAt(i), base.userState.valueAt(i)); |
| 183 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 184 | installStatus = base.installStatus; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 185 | keySetData = base.keySetData; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 188 | private PackageUserState modifyUserState(int userId) { |
| 189 | PackageUserState state = userState.get(userId); |
| 190 | if (state == null) { |
Dianne Hackborn | 4a9f071 | 2012-10-02 15:29:06 -0700 | [diff] [blame] | 191 | state = new PackageUserState(); |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 192 | userState.put(userId, state); |
| 193 | } |
| 194 | return state; |
| 195 | } |
| 196 | |
| 197 | public PackageUserState readUserState(int userId) { |
| 198 | PackageUserState state = userState.get(userId); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 199 | if (state != null) { |
| 200 | return state; |
| 201 | } |
Dianne Hackborn | 4a9f071 | 2012-10-02 15:29:06 -0700 | [diff] [blame] | 202 | return DEFAULT_USER_STATE; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Dianne Hackborn | 3fa3c28a | 2013-03-26 16:15:41 -0700 | [diff] [blame] | 205 | void setEnabled(int state, int userId, String callingPackage) { |
| 206 | PackageUserState st = modifyUserState(userId); |
| 207 | st.enabled = state; |
| 208 | st.lastDisableAppCaller = callingPackage; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | int getEnabled(int userId) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 212 | return readUserState(userId).enabled; |
| 213 | } |
| 214 | |
Dianne Hackborn | 3fa3c28a | 2013-03-26 16:15:41 -0700 | [diff] [blame] | 215 | String getLastDisabledAppCaller(int userId) { |
| 216 | return readUserState(userId).lastDisableAppCaller; |
| 217 | } |
| 218 | |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 219 | void setInstalled(boolean inst, int userId) { |
| 220 | modifyUserState(userId).installed = inst; |
| 221 | } |
| 222 | |
| 223 | boolean getInstalled(int userId) { |
| 224 | return readUserState(userId).installed; |
| 225 | } |
| 226 | |
| 227 | boolean isAnyInstalled(int[] users) { |
| 228 | for (int user: users) { |
| 229 | if (readUserState(user).installed) { |
| 230 | return true; |
| 231 | } |
| 232 | } |
| 233 | return false; |
| 234 | } |
| 235 | |
Dianne Hackborn | 786b440 | 2012-08-27 15:14:02 -0700 | [diff] [blame] | 236 | int[] queryInstalledUsers(int[] users, boolean installed) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 237 | int num = 0; |
| 238 | for (int user : users) { |
Dianne Hackborn | 786b440 | 2012-08-27 15:14:02 -0700 | [diff] [blame] | 239 | if (getInstalled(user) == installed) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 240 | num++; |
| 241 | } |
| 242 | } |
| 243 | int[] res = new int[num]; |
| 244 | num = 0; |
| 245 | for (int user : users) { |
Dianne Hackborn | 786b440 | 2012-08-27 15:14:02 -0700 | [diff] [blame] | 246 | if (getInstalled(user) == installed) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 247 | res[num] = user; |
| 248 | num++; |
| 249 | } |
| 250 | } |
| 251 | return res; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | boolean getStopped(int userId) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 255 | return readUserState(userId).stopped; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | void setStopped(boolean stop, int userId) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 259 | modifyUserState(userId).stopped = stop; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | boolean getNotLaunched(int userId) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 263 | return readUserState(userId).notLaunched; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | void setNotLaunched(boolean stop, int userId) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 267 | modifyUserState(userId).notLaunched = stop; |
| 268 | } |
| 269 | |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 270 | boolean getBlocked(int userId) { |
| 271 | return readUserState(userId).blocked; |
| 272 | } |
| 273 | |
| 274 | void setBlocked(boolean blocked, int userId) { |
| 275 | modifyUserState(userId).blocked = blocked; |
| 276 | } |
| 277 | |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame^] | 278 | boolean getBlockUninstall(int userId) { |
| 279 | return readUserState(userId).blockUninstall; |
| 280 | } |
| 281 | |
| 282 | void setBlockUninstall(boolean blockUninstall, int userId) { |
| 283 | modifyUserState(userId).blockUninstall = blockUninstall; |
| 284 | } |
| 285 | |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 286 | void setUserState(int userId, int enabled, boolean installed, boolean stopped, |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 287 | boolean notLaunched, boolean blocked, |
| 288 | String lastDisableAppCaller, HashSet<String> enabledComponents, |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame^] | 289 | HashSet<String> disabledComponents, boolean blockUninstall) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 290 | PackageUserState state = modifyUserState(userId); |
| 291 | state.enabled = enabled; |
| 292 | state.installed = installed; |
| 293 | state.stopped = stopped; |
| 294 | state.notLaunched = notLaunched; |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 295 | state.blocked = blocked; |
Dianne Hackborn | 3fa3c28a | 2013-03-26 16:15:41 -0700 | [diff] [blame] | 296 | state.lastDisableAppCaller = lastDisableAppCaller; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 297 | state.enabledComponents = enabledComponents; |
| 298 | state.disabledComponents = disabledComponents; |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame^] | 299 | state.blockUninstall = blockUninstall; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | HashSet<String> getEnabledComponents(int userId) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 303 | return readUserState(userId).enabledComponents; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | HashSet<String> getDisabledComponents(int userId) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 307 | return readUserState(userId).disabledComponents; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | void setEnabledComponents(HashSet<String> components, int userId) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 311 | modifyUserState(userId).enabledComponents = components; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | void setDisabledComponents(HashSet<String> components, int userId) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 315 | modifyUserState(userId).disabledComponents = components; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 316 | } |
| 317 | |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 318 | void setEnabledComponentsCopy(HashSet<String> components, int userId) { |
| 319 | modifyUserState(userId).enabledComponents = components != null |
| 320 | ? new HashSet<String>(components) : null; |
| 321 | } |
| 322 | |
| 323 | void setDisabledComponentsCopy(HashSet<String> components, int userId) { |
| 324 | modifyUserState(userId).disabledComponents = components != null |
| 325 | ? new HashSet<String>(components) : null; |
| 326 | } |
| 327 | |
| 328 | PackageUserState modifyUserStateComponents(int userId, boolean disabled, boolean enabled) { |
| 329 | PackageUserState state = modifyUserState(userId); |
| 330 | if (disabled && state.disabledComponents == null) { |
| 331 | state.disabledComponents = new HashSet<String>(1); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 332 | } |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 333 | if (enabled && state.enabledComponents == null) { |
| 334 | state.enabledComponents = new HashSet<String>(1); |
| 335 | } |
| 336 | return state; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | void addDisabledComponent(String componentClassName, int userId) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 340 | modifyUserStateComponents(userId, true, false).disabledComponents.add(componentClassName); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | void addEnabledComponent(String componentClassName, int userId) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 344 | modifyUserStateComponents(userId, false, true).enabledComponents.add(componentClassName); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | boolean enableComponentLPw(String componentClassName, int userId) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 348 | PackageUserState state = modifyUserStateComponents(userId, false, true); |
| 349 | boolean changed = state.disabledComponents != null |
| 350 | ? state.disabledComponents.remove(componentClassName) : false; |
| 351 | changed |= state.enabledComponents.add(componentClassName); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 352 | return changed; |
| 353 | } |
| 354 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 355 | boolean disableComponentLPw(String componentClassName, int userId) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 356 | PackageUserState state = modifyUserStateComponents(userId, true, false); |
| 357 | boolean changed = state.enabledComponents != null |
| 358 | ? state.enabledComponents.remove(componentClassName) : false; |
| 359 | changed |= state.disabledComponents.add(componentClassName); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 360 | return changed; |
| 361 | } |
| 362 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 363 | boolean restoreComponentLPw(String componentClassName, int userId) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 364 | PackageUserState state = modifyUserStateComponents(userId, true, true); |
| 365 | boolean changed = state.disabledComponents != null |
| 366 | ? state.disabledComponents.remove(componentClassName) : false; |
| 367 | changed |= state.enabledComponents != null |
| 368 | ? state.enabledComponents.remove(componentClassName) : false; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 369 | return changed; |
| 370 | } |
| 371 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 372 | int getCurrentEnabledStateLPr(String componentName, int userId) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 373 | PackageUserState state = readUserState(userId); |
| 374 | if (state.enabledComponents != null && state.enabledComponents.contains(componentName)) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 375 | return COMPONENT_ENABLED_STATE_ENABLED; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 376 | } else if (state.disabledComponents != null |
| 377 | && state.disabledComponents.contains(componentName)) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 378 | return COMPONENT_ENABLED_STATE_DISABLED; |
| 379 | } else { |
| 380 | return COMPONENT_ENABLED_STATE_DEFAULT; |
| 381 | } |
| 382 | } |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 383 | |
| 384 | void removeUser(int userId) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 385 | userState.delete(userId); |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 386 | } |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 387 | } |