blob: 2d7d8a0641677aca5112a4002c681f0d163f9c00 [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;
Dianne Hackbornfd7aded2013-01-22 17:10:23 -080021import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED;
Dianne Hackborn0ac30312011-06-17 14:49:23 -070022import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER;
Kenny Rootcf0b38c2011-03-22 14:17:59 -070023import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
Jeff Sharkey1c27576a2012-04-11 19:07:08 -070024import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
Kenny Rootcf0b38c2011-03-22 14:17:59 -070025
Dianne Hackborn8a2ed1d2013-01-29 15:18:29 -080026import android.content.IntentFilter;
27import android.content.pm.ActivityInfo;
28import android.content.pm.ResolveInfo;
29import android.net.Uri;
30import android.os.PatternMatcher;
31import android.util.LogPrinter;
Kenny Rootcf0b38c2011-03-22 14:17:59 -070032import com.android.internal.util.FastXmlSerializer;
33import com.android.internal.util.JournaledFile;
34import com.android.internal.util.XmlUtils;
Kenny Root447106f2011-03-23 11:00:15 -070035import com.android.server.pm.PackageManagerService.DumpState;
Kenny Rootcf0b38c2011-03-22 14:17:59 -070036
37import org.xmlpull.v1.XmlPullParser;
38import org.xmlpull.v1.XmlPullParserException;
39import org.xmlpull.v1.XmlSerializer;
40
Kenny Root447106f2011-03-23 11:00:15 -070041import android.content.ComponentName;
Amith Yamasani258848d2012-08-10 17:06:33 -070042import android.content.Context;
Kenny Root447106f2011-03-23 11:00:15 -070043import android.content.Intent;
Kenny Rootcf0b38c2011-03-22 14:17:59 -070044import android.content.pm.ApplicationInfo;
45import android.content.pm.ComponentInfo;
Geremy Condraf1bcca82013-01-07 22:35:24 -080046import android.content.pm.KeySet;
Dianne Hackborn7767eac2012-08-23 18:25:40 -070047import android.content.pm.PackageCleanItem;
Kenny Rootcf0b38c2011-03-22 14:17:59 -070048import android.content.pm.PackageManager;
49import android.content.pm.PackageParser;
50import android.content.pm.PermissionInfo;
51import android.content.pm.Signature;
Amith Yamasani483f3b02012-03-13 16:08:00 -070052import android.content.pm.UserInfo;
Dianne Hackborn7767eac2012-08-23 18:25:40 -070053import android.content.pm.PackageUserState;
Kenny Root0aaa0d92011-09-12 16:42:55 -070054import android.content.pm.VerifierDeviceIdentity;
Kenny Root447106f2011-03-23 11:00:15 -070055import android.os.Binder;
Kenny Rootcf0b38c2011-03-22 14:17:59 -070056import android.os.Environment;
57import android.os.FileUtils;
58import android.os.Process;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070059import android.os.UserHandle;
Kenny Rootcf0b38c2011-03-22 14:17:59 -070060import android.util.Log;
Geremy Condraf1bcca82013-01-07 22:35:24 -080061import android.util.LongSparseArray;
Kenny Rootcf0b38c2011-03-22 14:17:59 -070062import android.util.Slog;
63import android.util.SparseArray;
64import android.util.Xml;
65
66import java.io.BufferedOutputStream;
67import java.io.File;
68import java.io.FileInputStream;
69import java.io.FileOutputStream;
70import java.io.IOException;
71import java.io.PrintWriter;
Geremy Condraf1bcca82013-01-07 22:35:24 -080072import java.security.PublicKey;
Kenny Root447106f2011-03-23 11:00:15 -070073import java.text.SimpleDateFormat;
Kenny Rootcf0b38c2011-03-22 14:17:59 -070074import java.util.ArrayList;
75import java.util.Arrays;
Kenny Root447106f2011-03-23 11:00:15 -070076import java.util.Date;
Kenny Rootcf0b38c2011-03-22 14:17:59 -070077import java.util.HashMap;
78import java.util.HashSet;
79import java.util.Iterator;
Amith Yamasani483f3b02012-03-13 16:08:00 -070080import java.util.List;
Andy McFadden2f362292012-01-20 14:43:38 -080081import java.util.Map;
Dianne Hackborn63092712012-10-07 14:45:35 -070082import java.util.Set;
83import java.util.Map.Entry;
Kenny Rootcf0b38c2011-03-22 14:17:59 -070084
Kenny Root62539e92011-11-10 09:35:38 -080085import libcore.io.IoUtils;
86
Kenny Rootcf0b38c2011-03-22 14:17:59 -070087/**
88 * Holds information about dynamic settings.
89 */
90final class Settings {
Kenny Root447106f2011-03-23 11:00:15 -070091 private static final String TAG = "PackageSettings";
92
93 private static final boolean DEBUG_STOPPED = false;
Amith Yamasani258848d2012-08-10 17:06:33 -070094 private static final boolean DEBUG_MU = false;
Kenny Root447106f2011-03-23 11:00:15 -070095
Jeff Sharkeyedc84ee82012-03-19 16:52:26 -070096 private static final String TAG_READ_EXTERNAL_STORAGE = "read-external-storage";
97 private static final String ATTR_ENFORCEMENT = "enforcement";
98
Amith Yamasani483f3b02012-03-13 16:08:00 -070099 private static final String TAG_ITEM = "item";
100 private static final String TAG_DISABLED_COMPONENTS = "disabled-components";
101 private static final String TAG_ENABLED_COMPONENTS = "enabled-components";
102 private static final String TAG_PACKAGE_RESTRICTIONS = "package-restrictions";
103 private static final String TAG_PACKAGE = "pkg";
104
105 private static final String ATTR_NAME = "name";
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700106 private static final String ATTR_USER = "user";
107 private static final String ATTR_CODE = "code";
Amith Yamasani483f3b02012-03-13 16:08:00 -0700108 private static final String ATTR_NOT_LAUNCHED = "nl";
109 private static final String ATTR_ENABLED = "enabled";
Dianne Hackborn3fa3c28a2013-03-26 16:15:41 -0700110 private static final String ATTR_ENABLED_CALLER = "enabledCaller";
Amith Yamasani483f3b02012-03-13 16:08:00 -0700111 private static final String ATTR_STOPPED = "stopped";
Amith Yamasani655d0e22013-06-12 14:19:10 -0700112 private static final String ATTR_BLOCKED = "blocked";
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700113 private static final String ATTR_INSTALLED = "inst";
Amith Yamasani483f3b02012-03-13 16:08:00 -0700114
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700115 private final File mSettingsFilename;
116 private final File mBackupSettingsFilename;
117 private final File mPackageListFilename;
118 private final File mStoppedPackagesFilename;
119 private final File mBackupStoppedPackagesFilename;
120 final HashMap<String, PackageSetting> mPackages =
121 new HashMap<String, PackageSetting>();
122 // List of replaced system applications
Kenny Rootc52d6fd2012-05-07 23:04:52 -0700123 private final HashMap<String, PackageSetting> mDisabledSysPackages =
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700124 new HashMap<String, PackageSetting>();
125
Geremy Condra12c18382013-03-06 16:49:06 -0800126 private static int mFirstAvailableUid = 0;
127
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700128 // These are the last platform API version we were using for
129 // the apps installed on internal and external storage. It is
130 // used to grant newer permissions one time during a system upgrade.
131 int mInternalSdkPlatform;
132 int mExternalSdkPlatform;
Kenny Root0aaa0d92011-09-12 16:42:55 -0700133
Jeff Sharkeyf5385772012-05-11 14:04:41 -0700134 Boolean mReadExternalStorageEnforced;
Jeff Sharkeyedc84ee82012-03-19 16:52:26 -0700135
Kenny Root0aaa0d92011-09-12 16:42:55 -0700136 /** Device identity for the purpose of package verification. */
137 private VerifierDeviceIdentity mVerifierDeviceIdentity;
138
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700139 // The user's preferred activities associated with particular intent
140 // filters.
Dianne Hackborn63092712012-10-07 14:45:35 -0700141 final SparseArray<PreferredIntentResolver> mPreferredActivities =
142 new SparseArray<PreferredIntentResolver>();
143
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700144 final HashMap<String, SharedUserSetting> mSharedUsers =
145 new HashMap<String, SharedUserSetting>();
146 private final ArrayList<Object> mUserIds = new ArrayList<Object>();
147 private final SparseArray<Object> mOtherUserIds =
148 new SparseArray<Object>();
149
150 // For reading/writing settings file.
151 private final ArrayList<Signature> mPastSignatures =
152 new ArrayList<Signature>();
153
154 // Mapping from permission names to info about them.
155 final HashMap<String, BasePermission> mPermissions =
156 new HashMap<String, BasePermission>();
157
158 // Mapping from permission tree names to info about them.
159 final HashMap<String, BasePermission> mPermissionTrees =
160 new HashMap<String, BasePermission>();
161
162 // Packages that have been uninstalled and still need their external
163 // storage data deleted.
Jeff Sharkey752cd922012-09-23 16:25:12 -0700164 final ArrayList<PackageCleanItem> mPackagesToBeCleaned = new ArrayList<PackageCleanItem>();
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700165
166 // Packages that have been renamed since they were first installed.
167 // Keys are the new names of the packages, values are the original
168 // names. The packages appear everwhere else under their original
169 // names.
170 final HashMap<String, String> mRenamedPackages = new HashMap<String, String>();
171
172 final StringBuilder mReadMessages = new StringBuilder();
173
Kenny Root447106f2011-03-23 11:00:15 -0700174 /**
175 * Used to track packages that have a shared user ID that hasn't been read
176 * in yet.
177 * <p>
178 * TODO: make this just a local variable that is passed in during package
179 * scanning to make it less confusing.
180 */
181 private final ArrayList<PendingPackage> mPendingPackages = new ArrayList<PendingPackage>();
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700182
Amith Yamasani258848d2012-08-10 17:06:33 -0700183 private final Context mContext;
184
Amith Yamasani483f3b02012-03-13 16:08:00 -0700185 private final File mSystemDir;
Geremy Condraf1bcca82013-01-07 22:35:24 -0800186
187 public final KeySetManager mKeySetManager = new KeySetManager(mPackages);
188
Amith Yamasani258848d2012-08-10 17:06:33 -0700189 Settings(Context context) {
190 this(context, Environment.getDataDirectory());
Amith Yamasani483f3b02012-03-13 16:08:00 -0700191 }
192
Amith Yamasani258848d2012-08-10 17:06:33 -0700193 Settings(Context context, File dataDir) {
194 mContext = context;
Amith Yamasani483f3b02012-03-13 16:08:00 -0700195 mSystemDir = new File(dataDir, "system");
196 mSystemDir.mkdirs();
197 FileUtils.setPermissions(mSystemDir.toString(),
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700198 FileUtils.S_IRWXU|FileUtils.S_IRWXG
199 |FileUtils.S_IROTH|FileUtils.S_IXOTH,
200 -1, -1);
Amith Yamasani483f3b02012-03-13 16:08:00 -0700201 mSettingsFilename = new File(mSystemDir, "packages.xml");
202 mBackupSettingsFilename = new File(mSystemDir, "packages-backup.xml");
203 mPackageListFilename = new File(mSystemDir, "packages.list");
204 // Deprecated: Needed for migration
205 mStoppedPackagesFilename = new File(mSystemDir, "packages-stopped.xml");
206 mBackupStoppedPackagesFilename = new File(mSystemDir, "packages-stopped-backup.xml");
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700207 }
208
Kenny Root447106f2011-03-23 11:00:15 -0700209 PackageSetting getPackageLPw(PackageParser.Package pkg, PackageSetting origPackage,
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700210 String realName, SharedUserSetting sharedUser, File codePath, File resourcePath,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700211 String nativeLibraryPathString, int pkgFlags, UserHandle user, boolean add) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700212 final String name = pkg.packageName;
Kenny Root447106f2011-03-23 11:00:15 -0700213 PackageSetting p = getPackageLPw(name, origPackage, realName, sharedUser, codePath,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700214 resourcePath, nativeLibraryPathString, pkg.mVersionCode, pkgFlags,
Amith Yamasanif031f232012-10-26 15:35:21 -0700215 user, add, true /* allowInstall */);
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700216 return p;
217 }
218
Kenny Root447106f2011-03-23 11:00:15 -0700219 PackageSetting peekPackageLPr(String name) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700220 return mPackages.get(name);
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700221 }
222
223 void setInstallStatus(String pkgName, int status) {
224 PackageSetting p = mPackages.get(pkgName);
225 if(p != null) {
226 if(p.getInstallStatus() != status) {
227 p.setInstallStatus(status);
228 }
229 }
230 }
231
232 void setInstallerPackageName(String pkgName,
233 String installerPkgName) {
234 PackageSetting p = mPackages.get(pkgName);
235 if(p != null) {
236 p.setInstallerPackageName(installerPkgName);
237 }
238 }
239
Kenny Root447106f2011-03-23 11:00:15 -0700240 SharedUserSetting getSharedUserLPw(String name,
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700241 int pkgFlags, boolean create) {
242 SharedUserSetting s = mSharedUsers.get(name);
243 if (s == null) {
244 if (!create) {
245 return null;
246 }
247 s = new SharedUserSetting(name, pkgFlags);
Dianne Hackborn21fbd1f2012-02-10 10:38:10 -0800248 s.userId = newUserIdLPw(s);
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700249 Log.i(PackageManagerService.TAG, "New shared user " + name + ": id=" + s.userId);
250 // < 0 means we couldn't assign a userid; fall out and return
251 // s, which is currently null
252 if (s.userId >= 0) {
253 mSharedUsers.put(name, s);
254 }
255 }
256
257 return s;
258 }
259
Kenny Root447106f2011-03-23 11:00:15 -0700260 boolean disableSystemPackageLPw(String name) {
261 final PackageSetting p = mPackages.get(name);
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700262 if(p == null) {
263 Log.w(PackageManagerService.TAG, "Package:"+name+" is not an installed package");
264 return false;
265 }
Kenny Root447106f2011-03-23 11:00:15 -0700266 final PackageSetting dp = mDisabledSysPackages.get(name);
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700267 // always make sure the system package code and resource paths dont change
268 if (dp == null) {
269 if((p.pkg != null) && (p.pkg.applicationInfo != null)) {
270 p.pkg.applicationInfo.flags |= ApplicationInfo.FLAG_UPDATED_SYSTEM_APP;
271 }
272 mDisabledSysPackages.put(name, p);
273
274 // a little trick... when we install the new package, we don't
275 // want to modify the existing PackageSetting for the built-in
276 // version. so at this point we need a new PackageSetting that
277 // is okay to muck with.
278 PackageSetting newp = new PackageSetting(p);
Kenny Root447106f2011-03-23 11:00:15 -0700279 replacePackageLPw(name, newp);
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700280 return true;
281 }
282 return false;
283 }
284
Kenny Root447106f2011-03-23 11:00:15 -0700285 PackageSetting enableSystemPackageLPw(String name) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700286 PackageSetting p = mDisabledSysPackages.get(name);
287 if(p == null) {
288 Log.w(PackageManagerService.TAG, "Package:"+name+" is not disabled");
289 return null;
290 }
291 // Reset flag in ApplicationInfo object
292 if((p.pkg != null) && (p.pkg.applicationInfo != null)) {
293 p.pkg.applicationInfo.flags &= ~ApplicationInfo.FLAG_UPDATED_SYSTEM_APP;
294 }
Kenny Root447106f2011-03-23 11:00:15 -0700295 PackageSetting ret = addPackageLPw(name, p.realName, p.codePath, p.resourcePath,
Amith Yamasani13593602012-03-22 16:16:17 -0700296 p.nativeLibraryPathString, p.appId, p.versionCode, p.pkgFlags);
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700297 mDisabledSysPackages.remove(name);
298 return ret;
299 }
300
Kenny Rootc52d6fd2012-05-07 23:04:52 -0700301 boolean isDisabledSystemPackageLPr(String name) {
302 return mDisabledSysPackages.containsKey(name);
303 }
304
305 void removeDisabledSystemPackageLPw(String name) {
306 mDisabledSysPackages.remove(name);
307 }
308
Kenny Root447106f2011-03-23 11:00:15 -0700309 PackageSetting addPackageLPw(String name, String realName, File codePath, File resourcePath,
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700310 String nativeLibraryPathString, int uid, int vc, int pkgFlags) {
311 PackageSetting p = mPackages.get(name);
312 if (p != null) {
Amith Yamasani13593602012-03-22 16:16:17 -0700313 if (p.appId == uid) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700314 return p;
315 }
316 PackageManagerService.reportSettingsProblem(Log.ERROR,
317 "Adding duplicate package, keeping first: " + name);
318 return null;
319 }
320 p = new PackageSetting(name, realName, codePath, resourcePath, nativeLibraryPathString,
321 vc, pkgFlags);
Amith Yamasani13593602012-03-22 16:16:17 -0700322 p.appId = uid;
Kenny Root447106f2011-03-23 11:00:15 -0700323 if (addUserIdLPw(uid, p, name)) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700324 mPackages.put(name, p);
325 return p;
326 }
327 return null;
328 }
329
Kenny Root447106f2011-03-23 11:00:15 -0700330 SharedUserSetting addSharedUserLPw(String name, int uid, int pkgFlags) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700331 SharedUserSetting s = mSharedUsers.get(name);
332 if (s != null) {
333 if (s.userId == uid) {
334 return s;
335 }
336 PackageManagerService.reportSettingsProblem(Log.ERROR,
337 "Adding duplicate shared user, keeping first: " + name);
338 return null;
339 }
340 s = new SharedUserSetting(name, pkgFlags);
341 s.userId = uid;
Kenny Root447106f2011-03-23 11:00:15 -0700342 if (addUserIdLPw(uid, s, name)) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700343 mSharedUsers.put(name, s);
344 return s;
345 }
346 return null;
347 }
348
349 // Transfer ownership of permissions from one package to another.
Kenny Root447106f2011-03-23 11:00:15 -0700350 void transferPermissionsLPw(String origPkg, String newPkg) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700351 // Transfer ownership of permissions to the new package.
352 for (int i=0; i<2; i++) {
353 HashMap<String, BasePermission> permissions =
354 i == 0 ? mPermissionTrees : mPermissions;
355 for (BasePermission bp : permissions.values()) {
356 if (origPkg.equals(bp.sourcePackage)) {
357 if (PackageManagerService.DEBUG_UPGRADE) Log.v(PackageManagerService.TAG,
358 "Moving permission " + bp.name
359 + " from pkg " + bp.sourcePackage
360 + " to " + newPkg);
361 bp.sourcePackage = newPkg;
362 bp.packageSetting = null;
363 bp.perm = null;
364 if (bp.pendingInfo != null) {
365 bp.pendingInfo.packageName = newPkg;
366 }
367 bp.uid = 0;
368 bp.gids = null;
369 }
370 }
371 }
372 }
Amith Yamasani483f3b02012-03-13 16:08:00 -0700373
Kenny Root447106f2011-03-23 11:00:15 -0700374 private PackageSetting getPackageLPw(String name, PackageSetting origPackage,
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700375 String realName, SharedUserSetting sharedUser, File codePath, File resourcePath,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700376 String nativeLibraryPathString, int vc, int pkgFlags,
Amith Yamasanif031f232012-10-26 15:35:21 -0700377 UserHandle installUser, boolean add, boolean allowInstall) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700378 PackageSetting p = mPackages.get(name);
379 if (p != null) {
380 if (!p.codePath.equals(codePath)) {
381 // Check to see if its a disabled system app
382 if ((p.pkgFlags & ApplicationInfo.FLAG_SYSTEM) != 0) {
383 // This is an updated system app with versions in both system
384 // and data partition. Just let the most recent version
385 // take precedence.
Amith Yamasani483f3b02012-03-13 16:08:00 -0700386 Slog.w(PackageManagerService.TAG, "Trying to update system app code path from "
387 + p.codePathString + " to " + codePath.toString());
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700388 } else {
389 // Just a change in the code path is not an issue, but
390 // let's log a message about it.
Amith Yamasani483f3b02012-03-13 16:08:00 -0700391 Slog.i(PackageManagerService.TAG, "Package " + name + " codePath changed from "
392 + p.codePath + " to " + codePath + "; Retaining data and using new");
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700393 /*
394 * Since we've changed paths, we need to prefer the new
395 * native library path over the one stored in the
396 * package settings since we might have moved from
397 * internal to external storage or vice versa.
398 */
399 p.nativeLibraryPathString = nativeLibraryPathString;
400 }
401 }
402 if (p.sharedUser != sharedUser) {
403 PackageManagerService.reportSettingsProblem(Log.WARN,
404 "Package " + name + " shared user changed from "
405 + (p.sharedUser != null ? p.sharedUser.name : "<nothing>")
406 + " to "
407 + (sharedUser != null ? sharedUser.name : "<nothing>")
408 + "; replacing with new");
409 p = null;
410 } else {
411 if ((pkgFlags&ApplicationInfo.FLAG_SYSTEM) != 0) {
412 // If what we are scanning is a system package, then
413 // make it so, regardless of whether it was previously
414 // installed only in the data partition.
415 p.pkgFlags |= ApplicationInfo.FLAG_SYSTEM;
416 }
417 }
418 }
419 if (p == null) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700420 if (origPackage != null) {
421 // We are consuming the data from an existing package.
422 p = new PackageSetting(origPackage.name, name, codePath, resourcePath,
423 nativeLibraryPathString, vc, pkgFlags);
Amith Yamasani483f3b02012-03-13 16:08:00 -0700424 if (PackageManagerService.DEBUG_UPGRADE) Log.v(PackageManagerService.TAG, "Package "
425 + name + " is adopting original package " + origPackage.name);
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700426 // Note that we will retain the new package's signature so
427 // that we can keep its data.
428 PackageSignatures s = p.signatures;
429 p.copyFrom(origPackage);
430 p.signatures = s;
431 p.sharedUser = origPackage.sharedUser;
Amith Yamasani13593602012-03-22 16:16:17 -0700432 p.appId = origPackage.appId;
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700433 p.origPackage = origPackage;
434 mRenamedPackages.put(name, origPackage.name);
435 name = origPackage.name;
436 // Update new package state.
437 p.setTimeStamp(codePath.lastModified());
438 } else {
439 p = new PackageSetting(name, realName, codePath, resourcePath,
440 nativeLibraryPathString, vc, pkgFlags);
441 p.setTimeStamp(codePath.lastModified());
442 p.sharedUser = sharedUser;
443 // If this is not a system app, it starts out stopped.
444 if ((pkgFlags&ApplicationInfo.FLAG_SYSTEM) == 0) {
Kenny Root447106f2011-03-23 11:00:15 -0700445 if (DEBUG_STOPPED) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700446 RuntimeException e = new RuntimeException("here");
447 e.fillInStackTrace();
448 Slog.i(PackageManagerService.TAG, "Stopping package " + name, e);
449 }
Amith Yamasani483f3b02012-03-13 16:08:00 -0700450 List<UserInfo> users = getAllUsers();
Amith Yamasanif031f232012-10-26 15:35:21 -0700451 if (users != null && allowInstall) {
Amith Yamasani483f3b02012-03-13 16:08:00 -0700452 for (UserInfo user : users) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700453 // By default we consider this app to be installed
454 // for the user if no user has been specified (which
455 // means to leave it at its original value, and the
456 // original default value is true), or we are being
457 // asked to install for all users, or this is the
458 // user we are installing for.
459 final boolean installed = installUser == null
460 || installUser.getIdentifier() == UserHandle.USER_ALL
461 || installUser.getIdentifier() == user.id;
462 p.setUserState(user.id, COMPONENT_ENABLED_STATE_DEFAULT,
463 installed,
464 true, // stopped,
465 true, // notLaunched
Amith Yamasani655d0e22013-06-12 14:19:10 -0700466 false, // blocked
Dianne Hackborn3fa3c28a2013-03-26 16:15:41 -0700467 null, null, null);
Amith Yamasani483f3b02012-03-13 16:08:00 -0700468 writePackageRestrictionsLPr(user.id);
469 }
470 }
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700471 }
472 if (sharedUser != null) {
Amith Yamasani13593602012-03-22 16:16:17 -0700473 p.appId = sharedUser.userId;
Dianne Hackborn21fbd1f2012-02-10 10:38:10 -0800474 } else {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700475 // Clone the setting here for disabled system packages
476 PackageSetting dis = mDisabledSysPackages.get(name);
477 if (dis != null) {
478 // For disabled packages a new setting is created
479 // from the existing user id. This still has to be
480 // added to list of user id's
481 // Copy signatures from previous setting
482 if (dis.signatures.mSignatures != null) {
483 p.signatures.mSignatures = dis.signatures.mSignatures.clone();
484 }
Amith Yamasani13593602012-03-22 16:16:17 -0700485 p.appId = dis.appId;
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700486 // Clone permissions
487 p.grantedPermissions = new HashSet<String>(dis.grantedPermissions);
488 // Clone component info
Amith Yamasani483f3b02012-03-13 16:08:00 -0700489 List<UserInfo> users = getAllUsers();
490 if (users != null) {
491 for (UserInfo user : users) {
492 int userId = user.id;
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700493 p.setDisabledComponentsCopy(
494 dis.getDisabledComponents(userId), userId);
495 p.setEnabledComponentsCopy(
496 dis.getEnabledComponents(userId), userId);
Amith Yamasani483f3b02012-03-13 16:08:00 -0700497 }
498 }
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700499 // Add new setting to list of user ids
Amith Yamasani13593602012-03-22 16:16:17 -0700500 addUserIdLPw(p.appId, p, name);
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700501 } else {
502 // Assign new user id
Amith Yamasani13593602012-03-22 16:16:17 -0700503 p.appId = newUserIdLPw(p);
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700504 }
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700505 }
506 }
Amith Yamasani13593602012-03-22 16:16:17 -0700507 if (p.appId < 0) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700508 PackageManagerService.reportSettingsProblem(Log.WARN,
509 "Package " + name + " could not be assigned a valid uid");
510 return null;
511 }
512 if (add) {
513 // Finish adding new package by adding it and updating shared
514 // user preferences
Kenny Root447106f2011-03-23 11:00:15 -0700515 addPackageSettingLPw(p, name, sharedUser);
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700516 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700517 } else {
Amith Yamasanif031f232012-10-26 15:35:21 -0700518 if (installUser != null && allowInstall) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700519 // The caller has explicitly specified the user they want this
520 // package installed for, and the package already exists.
521 // Make sure it conforms to the new request.
522 List<UserInfo> users = getAllUsers();
523 if (users != null) {
524 for (UserInfo user : users) {
525 if (installUser.getIdentifier() == UserHandle.USER_ALL
526 || installUser.getIdentifier() == user.id) {
527 boolean installed = p.getInstalled(user.id);
528 if (!installed) {
529 p.setInstalled(true, user.id);
530 writePackageRestrictionsLPr(user.id);
531 }
532 }
533 }
534 }
535 }
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700536 }
537 return p;
538 }
539
Kenny Root447106f2011-03-23 11:00:15 -0700540 void insertPackageSettingLPw(PackageSetting p, PackageParser.Package pkg) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700541 p.pkg = pkg;
Amith Yamasani483f3b02012-03-13 16:08:00 -0700542 // pkg.mSetEnabled = p.getEnabled(userId);
543 // pkg.mSetStopped = p.getStopped(userId);
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700544 final String codePath = pkg.applicationInfo.sourceDir;
545 final String resourcePath = pkg.applicationInfo.publicSourceDir;
546 // Update code path if needed
547 if (!codePath.equalsIgnoreCase(p.codePathString)) {
548 Slog.w(PackageManagerService.TAG, "Code path for pkg : " + p.pkg.packageName +
549 " changing from " + p.codePathString + " to " + codePath);
550 p.codePath = new File(codePath);
551 p.codePathString = codePath;
552 }
553 //Update resource path if needed
554 if (!resourcePath.equalsIgnoreCase(p.resourcePathString)) {
555 Slog.w(PackageManagerService.TAG, "Resource path for pkg : " + p.pkg.packageName +
556 " changing from " + p.resourcePathString + " to " + resourcePath);
557 p.resourcePath = new File(resourcePath);
558 p.resourcePathString = resourcePath;
559 }
560 // Update the native library path if needed
561 final String nativeLibraryPath = pkg.applicationInfo.nativeLibraryDir;
562 if (nativeLibraryPath != null
563 && !nativeLibraryPath.equalsIgnoreCase(p.nativeLibraryPathString)) {
564 p.nativeLibraryPathString = nativeLibraryPath;
565 }
566 // Update version code if needed
Amith Yamasani483f3b02012-03-13 16:08:00 -0700567 if (pkg.mVersionCode != p.versionCode) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700568 p.versionCode = pkg.mVersionCode;
569 }
Amith Yamasani483f3b02012-03-13 16:08:00 -0700570 // Update signatures if needed.
571 if (p.signatures.mSignatures == null) {
572 p.signatures.assignSignatures(pkg.mSignatures);
573 }
Kenny Root5455f682012-09-09 14:52:10 -0700574 // Update flags if needed.
575 if (pkg.applicationInfo.flags != p.pkgFlags) {
576 p.pkgFlags = pkg.applicationInfo.flags;
577 }
Amith Yamasani483f3b02012-03-13 16:08:00 -0700578 // If this app defines a shared user id initialize
579 // the shared user signatures as well.
580 if (p.sharedUser != null && p.sharedUser.signatures.mSignatures == null) {
581 p.sharedUser.signatures.assignSignatures(pkg.mSignatures);
582 }
Kenny Root447106f2011-03-23 11:00:15 -0700583 addPackageSettingLPw(p, pkg.packageName, p.sharedUser);
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700584 }
585
586 // Utility method that adds a PackageSetting to mPackages and
587 // completes updating the shared user attributes
Kenny Root447106f2011-03-23 11:00:15 -0700588 private void addPackageSettingLPw(PackageSetting p, String name,
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700589 SharedUserSetting sharedUser) {
590 mPackages.put(name, p);
591 if (sharedUser != null) {
592 if (p.sharedUser != null && p.sharedUser != sharedUser) {
593 PackageManagerService.reportSettingsProblem(Log.ERROR,
594 "Package " + p.name + " was user "
595 + p.sharedUser + " but is now " + sharedUser
596 + "; I am not changing its files so it will probably fail!");
597 p.sharedUser.packages.remove(p);
Amith Yamasani13593602012-03-22 16:16:17 -0700598 } else if (p.appId != sharedUser.userId) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700599 PackageManagerService.reportSettingsProblem(Log.ERROR,
Amith Yamasani13593602012-03-22 16:16:17 -0700600 "Package " + p.name + " was user id " + p.appId
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700601 + " but is now user " + sharedUser
602 + " with id " + sharedUser.userId
603 + "; I am not changing its files so it will probably fail!");
604 }
605
606 sharedUser.packages.add(p);
607 p.sharedUser = sharedUser;
Amith Yamasani13593602012-03-22 16:16:17 -0700608 p.appId = sharedUser.userId;
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700609 }
610 }
611
612 /*
613 * Update the shared user setting when a package using
614 * specifying the shared user id is removed. The gids
615 * associated with each permission of the deleted package
616 * are removed from the shared user's gid list only if its
617 * not in use by other permissions of packages in the
618 * shared user setting.
619 */
Kenny Root447106f2011-03-23 11:00:15 -0700620 void updateSharedUserPermsLPw(PackageSetting deletedPs, int[] globalGids) {
621 if ((deletedPs == null) || (deletedPs.pkg == null)) {
622 Slog.i(PackageManagerService.TAG,
623 "Trying to update info for null package. Just ignoring");
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700624 return;
625 }
626 // No sharedUserId
627 if (deletedPs.sharedUser == null) {
628 return;
629 }
630 SharedUserSetting sus = deletedPs.sharedUser;
631 // Update permissions
Kenny Root447106f2011-03-23 11:00:15 -0700632 for (String eachPerm : deletedPs.pkg.requestedPermissions) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700633 boolean used = false;
Kenny Root447106f2011-03-23 11:00:15 -0700634 if (!sus.grantedPermissions.contains(eachPerm)) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700635 continue;
636 }
637 for (PackageSetting pkg:sus.packages) {
638 if (pkg.pkg != null &&
639 !pkg.pkg.packageName.equals(deletedPs.pkg.packageName) &&
640 pkg.pkg.requestedPermissions.contains(eachPerm)) {
641 used = true;
642 break;
643 }
644 }
645 if (!used) {
646 // can safely delete this permission from list
647 sus.grantedPermissions.remove(eachPerm);
648 }
649 }
650 // Update gids
651 int newGids[] = globalGids;
652 for (String eachPerm : sus.grantedPermissions) {
653 BasePermission bp = mPermissions.get(eachPerm);
654 if (bp != null) {
655 newGids = PackageManagerService.appendInts(newGids, bp.gids);
656 }
657 }
658 sus.gids = newGids;
659 }
660
Kenny Root447106f2011-03-23 11:00:15 -0700661 int removePackageLPw(String name) {
662 final PackageSetting p = mPackages.get(name);
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700663 if (p != null) {
664 mPackages.remove(name);
665 if (p.sharedUser != null) {
666 p.sharedUser.packages.remove(p);
667 if (p.sharedUser.packages.size() == 0) {
668 mSharedUsers.remove(p.sharedUser.name);
Kenny Root447106f2011-03-23 11:00:15 -0700669 removeUserIdLPw(p.sharedUser.userId);
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700670 return p.sharedUser.userId;
671 }
672 } else {
Amith Yamasani13593602012-03-22 16:16:17 -0700673 removeUserIdLPw(p.appId);
674 return p.appId;
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700675 }
676 }
677 return -1;
678 }
679
Kenny Root447106f2011-03-23 11:00:15 -0700680 private void replacePackageLPw(String name, PackageSetting newp) {
681 final PackageSetting p = mPackages.get(name);
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700682 if (p != null) {
683 if (p.sharedUser != null) {
684 p.sharedUser.packages.remove(p);
685 p.sharedUser.packages.add(newp);
686 } else {
Amith Yamasani13593602012-03-22 16:16:17 -0700687 replaceUserIdLPw(p.appId, newp);
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700688 }
689 }
690 mPackages.put(name, newp);
691 }
692
Kenny Root447106f2011-03-23 11:00:15 -0700693 private boolean addUserIdLPw(int uid, Object obj, Object name) {
Dianne Hackborn21fbd1f2012-02-10 10:38:10 -0800694 if (uid > Process.LAST_APPLICATION_UID) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700695 return false;
696 }
697
Dianne Hackborn21fbd1f2012-02-10 10:38:10 -0800698 if (uid >= Process.FIRST_APPLICATION_UID) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700699 int N = mUserIds.size();
Dianne Hackborn21fbd1f2012-02-10 10:38:10 -0800700 final int index = uid - Process.FIRST_APPLICATION_UID;
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700701 while (index >= N) {
702 mUserIds.add(null);
703 N++;
704 }
705 if (mUserIds.get(index) != null) {
706 PackageManagerService.reportSettingsProblem(Log.ERROR,
707 "Adding duplicate user id: " + uid
708 + " name=" + name);
709 return false;
710 }
711 mUserIds.set(index, obj);
712 } else {
713 if (mOtherUserIds.get(uid) != null) {
714 PackageManagerService.reportSettingsProblem(Log.ERROR,
715 "Adding duplicate shared id: " + uid
716 + " name=" + name);
717 return false;
718 }
719 mOtherUserIds.put(uid, obj);
720 }
721 return true;
722 }
723
Kenny Root447106f2011-03-23 11:00:15 -0700724 public Object getUserIdLPr(int uid) {
Dianne Hackborn21fbd1f2012-02-10 10:38:10 -0800725 if (uid >= Process.FIRST_APPLICATION_UID) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700726 final int N = mUserIds.size();
Dianne Hackborn21fbd1f2012-02-10 10:38:10 -0800727 final int index = uid - Process.FIRST_APPLICATION_UID;
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700728 return index < N ? mUserIds.get(index) : null;
729 } else {
730 return mOtherUserIds.get(uid);
731 }
732 }
733
Kenny Root447106f2011-03-23 11:00:15 -0700734 private void removeUserIdLPw(int uid) {
Dianne Hackborn21fbd1f2012-02-10 10:38:10 -0800735 if (uid >= Process.FIRST_APPLICATION_UID) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700736 final int N = mUserIds.size();
Dianne Hackborn21fbd1f2012-02-10 10:38:10 -0800737 final int index = uid - Process.FIRST_APPLICATION_UID;
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700738 if (index < N) mUserIds.set(index, null);
739 } else {
740 mOtherUserIds.remove(uid);
741 }
Geremy Condra12c18382013-03-06 16:49:06 -0800742 setFirstAvailableUid(uid+1);
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700743 }
744
Kenny Root447106f2011-03-23 11:00:15 -0700745 private void replaceUserIdLPw(int uid, Object obj) {
Dianne Hackborn21fbd1f2012-02-10 10:38:10 -0800746 if (uid >= Process.FIRST_APPLICATION_UID) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700747 final int N = mUserIds.size();
Dianne Hackborn21fbd1f2012-02-10 10:38:10 -0800748 final int index = uid - Process.FIRST_APPLICATION_UID;
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700749 if (index < N) mUserIds.set(index, obj);
750 } else {
751 mOtherUserIds.put(uid, obj);
752 }
753 }
754
Dianne Hackborn63092712012-10-07 14:45:35 -0700755 PreferredIntentResolver editPreferredActivitiesLPw(int userId) {
756 PreferredIntentResolver pir = mPreferredActivities.get(userId);
757 if (pir == null) {
758 pir = new PreferredIntentResolver();
759 mPreferredActivities.put(userId, pir);
760 }
761 return pir;
762 }
763
Amith Yamasani483f3b02012-03-13 16:08:00 -0700764 private File getUserPackagesStateFile(int userId) {
Amith Yamasani61f57372012-08-31 12:12:28 -0700765 return new File(Environment.getUserSystemDirectory(userId), "package-restrictions.xml");
Amith Yamasani483f3b02012-03-13 16:08:00 -0700766 }
767
768 private File getUserPackagesStateBackupFile(int userId) {
Amith Yamasani61f57372012-08-31 12:12:28 -0700769 return new File(Environment.getUserSystemDirectory(userId),
770 "package-restrictions-backup.xml");
Amith Yamasani483f3b02012-03-13 16:08:00 -0700771 }
772
773 void writeAllUsersPackageRestrictionsLPr() {
774 List<UserInfo> users = getAllUsers();
775 if (users == null) return;
776
777 for (UserInfo user : users) {
778 writePackageRestrictionsLPr(user.id);
779 }
780 }
781
782 void readAllUsersPackageRestrictionsLPr() {
783 List<UserInfo> users = getAllUsers();
784 if (users == null) {
785 readPackageRestrictionsLPr(0);
786 return;
787 }
788
789 for (UserInfo user : users) {
790 readPackageRestrictionsLPr(user.id);
791 }
792 }
793
Dianne Hackborn63092712012-10-07 14:45:35 -0700794 private void readPreferredActivitiesLPw(XmlPullParser parser, int userId)
795 throws XmlPullParserException, IOException {
796 int outerDepth = parser.getDepth();
797 int type;
798 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
799 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
800 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
801 continue;
802 }
803
804 String tagName = parser.getName();
805 if (tagName.equals(TAG_ITEM)) {
806 PreferredActivity pa = new PreferredActivity(parser);
807 if (pa.mPref.getParseError() == null) {
808 editPreferredActivitiesLPw(userId).addFilter(pa);
809 } else {
810 PackageManagerService.reportSettingsProblem(Log.WARN,
811 "Error in package manager settings: <preferred-activity> "
812 + pa.mPref.getParseError() + " at "
813 + parser.getPositionDescription());
814 }
815 } else {
816 PackageManagerService.reportSettingsProblem(Log.WARN,
817 "Unknown element under <preferred-activities>: " + parser.getName());
818 XmlUtils.skipCurrentTag(parser);
819 }
820 }
821 }
822
Amith Yamasani483f3b02012-03-13 16:08:00 -0700823 void readPackageRestrictionsLPr(int userId) {
Amith Yamasani258848d2012-08-10 17:06:33 -0700824 if (DEBUG_MU) {
825 Log.i(TAG, "Reading package restrictions for user=" + userId);
826 }
Amith Yamasani483f3b02012-03-13 16:08:00 -0700827 FileInputStream str = null;
828 File userPackagesStateFile = getUserPackagesStateFile(userId);
829 File backupFile = getUserPackagesStateBackupFile(userId);
830 if (backupFile.exists()) {
831 try {
832 str = new FileInputStream(backupFile);
833 mReadMessages.append("Reading from backup stopped packages file\n");
834 PackageManagerService.reportSettingsProblem(Log.INFO,
835 "Need to read from backup stopped packages file");
836 if (userPackagesStateFile.exists()) {
837 // If both the backup and normal file exist, we
838 // ignore the normal one since it might have been
839 // corrupted.
840 Slog.w(PackageManagerService.TAG, "Cleaning up stopped packages file "
841 + userPackagesStateFile);
842 userPackagesStateFile.delete();
843 }
844 } catch (java.io.IOException e) {
845 // We'll try for the normal settings file.
846 }
847 }
848
849 try {
850 if (str == null) {
851 if (!userPackagesStateFile.exists()) {
852 mReadMessages.append("No stopped packages file found\n");
853 PackageManagerService.reportSettingsProblem(Log.INFO,
854 "No stopped packages file; "
855 + "assuming all started");
856 // At first boot, make sure no packages are stopped.
857 // We usually want to have third party apps initialize
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700858 // in the stopped state, but not at first boot. Also
859 // consider all applications to be installed.
Amith Yamasani483f3b02012-03-13 16:08:00 -0700860 for (PackageSetting pkg : mPackages.values()) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700861 pkg.setUserState(userId, COMPONENT_ENABLED_STATE_DEFAULT,
862 true, // installed
863 false, // stopped
864 false, // notLaunched
Amith Yamasani655d0e22013-06-12 14:19:10 -0700865 false, // blocked
Dianne Hackborn3fa3c28a2013-03-26 16:15:41 -0700866 null, null, null);
Amith Yamasani483f3b02012-03-13 16:08:00 -0700867 }
868 return;
869 }
870 str = new FileInputStream(userPackagesStateFile);
871 }
872 final XmlPullParser parser = Xml.newPullParser();
873 parser.setInput(str, null);
874
875 int type;
876 while ((type=parser.next()) != XmlPullParser.START_TAG
877 && type != XmlPullParser.END_DOCUMENT) {
878 ;
879 }
880
881 if (type != XmlPullParser.START_TAG) {
882 mReadMessages.append("No start tag found in package restrictions file\n");
883 PackageManagerService.reportSettingsProblem(Log.WARN,
884 "No start tag found in package manager stopped packages");
885 return;
886 }
887
888 int outerDepth = parser.getDepth();
889 PackageSetting ps = null;
890 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
891 && (type != XmlPullParser.END_TAG
892 || parser.getDepth() > outerDepth)) {
893 if (type == XmlPullParser.END_TAG
894 || type == XmlPullParser.TEXT) {
895 continue;
896 }
897
898 String tagName = parser.getName();
899 if (tagName.equals(TAG_PACKAGE)) {
900 String name = parser.getAttributeValue(null, ATTR_NAME);
901 ps = mPackages.get(name);
902 if (ps == null) {
903 Slog.w(PackageManagerService.TAG, "No package known for stopped package: "
904 + name);
905 XmlUtils.skipCurrentTag(parser);
906 continue;
907 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700908 final String enabledStr = parser.getAttributeValue(null, ATTR_ENABLED);
909 final int enabled = enabledStr == null
910 ? COMPONENT_ENABLED_STATE_DEFAULT : Integer.parseInt(enabledStr);
Dianne Hackborn3fa3c28a2013-03-26 16:15:41 -0700911 final String enabledCaller = parser.getAttributeValue(null,
912 ATTR_ENABLED_CALLER);
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700913 final String installedStr = parser.getAttributeValue(null, ATTR_INSTALLED);
914 final boolean installed = installedStr == null
915 ? true : Boolean.parseBoolean(installedStr);
916 final String stoppedStr = parser.getAttributeValue(null, ATTR_STOPPED);
917 final boolean stopped = stoppedStr == null
918 ? false : Boolean.parseBoolean(stoppedStr);
Amith Yamasani655d0e22013-06-12 14:19:10 -0700919 final String blockedStr = parser.getAttributeValue(null, ATTR_BLOCKED);
920 final boolean blocked = blockedStr == null
921 ? false : Boolean.parseBoolean(blockedStr);
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700922 final String notLaunchedStr = parser.getAttributeValue(null, ATTR_NOT_LAUNCHED);
923 final boolean notLaunched = stoppedStr == null
924 ? false : Boolean.parseBoolean(notLaunchedStr);
925
926 HashSet<String> enabledComponents = null;
927 HashSet<String> disabledComponents = null;
Amith Yamasani483f3b02012-03-13 16:08:00 -0700928
929 int packageDepth = parser.getDepth();
930 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
931 && (type != XmlPullParser.END_TAG
932 || parser.getDepth() > packageDepth)) {
933 if (type == XmlPullParser.END_TAG
934 || type == XmlPullParser.TEXT) {
935 continue;
936 }
937 tagName = parser.getName();
938 if (tagName.equals(TAG_ENABLED_COMPONENTS)) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700939 enabledComponents = readComponentsLPr(parser);
Amith Yamasani483f3b02012-03-13 16:08:00 -0700940 } else if (tagName.equals(TAG_DISABLED_COMPONENTS)) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700941 disabledComponents = readComponentsLPr(parser);
Amith Yamasani483f3b02012-03-13 16:08:00 -0700942 }
943 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700944
Amith Yamasani655d0e22013-06-12 14:19:10 -0700945 ps.setUserState(userId, enabled, installed, stopped, notLaunched, blocked,
Dianne Hackborn3fa3c28a2013-03-26 16:15:41 -0700946 enabledCaller, enabledComponents, disabledComponents);
Dianne Hackborn63092712012-10-07 14:45:35 -0700947 } else if (tagName.equals("preferred-activities")) {
948 readPreferredActivitiesLPw(parser, userId);
Amith Yamasani483f3b02012-03-13 16:08:00 -0700949 } else {
950 Slog.w(PackageManagerService.TAG, "Unknown element under <stopped-packages>: "
951 + parser.getName());
952 XmlUtils.skipCurrentTag(parser);
953 }
954 }
955
956 str.close();
957
958 } catch (XmlPullParserException e) {
959 mReadMessages.append("Error reading: " + e.toString());
960 PackageManagerService.reportSettingsProblem(Log.ERROR,
961 "Error reading stopped packages: " + e);
962 Log.wtf(PackageManagerService.TAG, "Error reading package manager stopped packages", e);
963
964 } catch (java.io.IOException e) {
965 mReadMessages.append("Error reading: " + e.toString());
966 PackageManagerService.reportSettingsProblem(Log.ERROR, "Error reading settings: " + e);
967 Log.wtf(PackageManagerService.TAG, "Error reading package manager stopped packages", e);
968 }
969 }
970
971 private HashSet<String> readComponentsLPr(XmlPullParser parser)
972 throws IOException, XmlPullParserException {
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700973 HashSet<String> components = null;
Amith Yamasani483f3b02012-03-13 16:08:00 -0700974 int type;
975 int outerDepth = parser.getDepth();
976 String tagName;
977 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
978 && (type != XmlPullParser.END_TAG
979 || parser.getDepth() > outerDepth)) {
980 if (type == XmlPullParser.END_TAG
981 || type == XmlPullParser.TEXT) {
982 continue;
983 }
984 tagName = parser.getName();
985 if (tagName.equals(TAG_ITEM)) {
986 String componentName = parser.getAttributeValue(null, ATTR_NAME);
987 if (componentName != null) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700988 if (components == null) {
989 components = new HashSet<String>();
990 }
Amith Yamasani483f3b02012-03-13 16:08:00 -0700991 components.add(componentName);
992 }
993 }
994 }
995 return components;
996 }
997
Dianne Hackborn8a2ed1d2013-01-29 15:18:29 -0800998 void writePreferredActivitiesLPr(XmlSerializer serializer, int userId, boolean full)
Dianne Hackborn63092712012-10-07 14:45:35 -0700999 throws IllegalArgumentException, IllegalStateException, IOException {
1000 serializer.startTag(null, "preferred-activities");
1001 PreferredIntentResolver pir = mPreferredActivities.get(userId);
1002 if (pir != null) {
1003 for (final PreferredActivity pa : pir.filterSet()) {
1004 serializer.startTag(null, TAG_ITEM);
Dianne Hackborn8a2ed1d2013-01-29 15:18:29 -08001005 pa.writeToXml(serializer, full);
Dianne Hackborn63092712012-10-07 14:45:35 -07001006 serializer.endTag(null, TAG_ITEM);
1007 }
1008 }
1009 serializer.endTag(null, "preferred-activities");
1010 }
1011
Amith Yamasani483f3b02012-03-13 16:08:00 -07001012 void writePackageRestrictionsLPr(int userId) {
Amith Yamasani258848d2012-08-10 17:06:33 -07001013 if (DEBUG_MU) {
1014 Log.i(TAG, "Writing package restrictions for user=" + userId);
1015 }
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001016 // Keep the old stopped packages around until we know the new ones have
1017 // been successfully written.
Amith Yamasani483f3b02012-03-13 16:08:00 -07001018 File userPackagesStateFile = getUserPackagesStateFile(userId);
1019 File backupFile = getUserPackagesStateBackupFile(userId);
1020 new File(userPackagesStateFile.getParent()).mkdirs();
1021 if (userPackagesStateFile.exists()) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001022 // Presence of backup settings file indicates that we failed
1023 // to persist packages earlier. So preserve the older
1024 // backup for future reference since the current packages
1025 // might have been corrupted.
Amith Yamasani483f3b02012-03-13 16:08:00 -07001026 if (!backupFile.exists()) {
1027 if (!userPackagesStateFile.renameTo(backupFile)) {
1028 Log.wtf(PackageManagerService.TAG, "Unable to backup user packages state file, "
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001029 + "current changes will be lost at reboot");
1030 return;
1031 }
1032 } else {
Amith Yamasani483f3b02012-03-13 16:08:00 -07001033 userPackagesStateFile.delete();
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001034 Slog.w(PackageManagerService.TAG, "Preserving older stopped packages backup");
1035 }
1036 }
1037
1038 try {
Amith Yamasani483f3b02012-03-13 16:08:00 -07001039 final FileOutputStream fstr = new FileOutputStream(userPackagesStateFile);
Kenny Root447106f2011-03-23 11:00:15 -07001040 final BufferedOutputStream str = new BufferedOutputStream(fstr);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001041
Kenny Root447106f2011-03-23 11:00:15 -07001042 final XmlSerializer serializer = new FastXmlSerializer();
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001043 serializer.setOutput(str, "utf-8");
1044 serializer.startDocument(null, true);
1045 serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
1046
Amith Yamasani483f3b02012-03-13 16:08:00 -07001047 serializer.startTag(null, TAG_PACKAGE_RESTRICTIONS);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001048
Kenny Root447106f2011-03-23 11:00:15 -07001049 for (final PackageSetting pkg : mPackages.values()) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001050 PackageUserState ustate = pkg.readUserState(userId);
1051 if (ustate.stopped || ustate.notLaunched || !ustate.installed
1052 || ustate.enabled != COMPONENT_ENABLED_STATE_DEFAULT
Amith Yamasani655d0e22013-06-12 14:19:10 -07001053 || ustate.blocked
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001054 || (ustate.enabledComponents != null
1055 && ustate.enabledComponents.size() > 0)
1056 || (ustate.disabledComponents != null
1057 && ustate.disabledComponents.size() > 0)) {
Amith Yamasani483f3b02012-03-13 16:08:00 -07001058 serializer.startTag(null, TAG_PACKAGE);
1059 serializer.attribute(null, ATTR_NAME, pkg.name);
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001060 if (DEBUG_MU) Log.i(TAG, " pkg=" + pkg.name + ", state=" + ustate.enabled);
Amith Yamasani483f3b02012-03-13 16:08:00 -07001061
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001062 if (!ustate.installed) {
1063 serializer.attribute(null, ATTR_INSTALLED, "false");
1064 }
1065 if (ustate.stopped) {
Amith Yamasani483f3b02012-03-13 16:08:00 -07001066 serializer.attribute(null, ATTR_STOPPED, "true");
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001067 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001068 if (ustate.notLaunched) {
Amith Yamasani483f3b02012-03-13 16:08:00 -07001069 serializer.attribute(null, ATTR_NOT_LAUNCHED, "true");
1070 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07001071 if (ustate.blocked) {
1072 serializer.attribute(null, ATTR_BLOCKED, "true");
1073 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001074 if (ustate.enabled != COMPONENT_ENABLED_STATE_DEFAULT) {
1075 serializer.attribute(null, ATTR_ENABLED,
1076 Integer.toString(ustate.enabled));
Dianne Hackborn3fa3c28a2013-03-26 16:15:41 -07001077 if (ustate.lastDisableAppCaller != null) {
1078 serializer.attribute(null, ATTR_ENABLED_CALLER,
1079 ustate.lastDisableAppCaller);
1080 }
Amith Yamasani483f3b02012-03-13 16:08:00 -07001081 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001082 if (ustate.enabledComponents != null
1083 && ustate.enabledComponents.size() > 0) {
Amith Yamasani483f3b02012-03-13 16:08:00 -07001084 serializer.startTag(null, TAG_ENABLED_COMPONENTS);
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001085 for (final String name : ustate.enabledComponents) {
Amith Yamasani483f3b02012-03-13 16:08:00 -07001086 serializer.startTag(null, TAG_ITEM);
1087 serializer.attribute(null, ATTR_NAME, name);
1088 serializer.endTag(null, TAG_ITEM);
1089 }
1090 serializer.endTag(null, TAG_ENABLED_COMPONENTS);
1091 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001092 if (ustate.disabledComponents != null
1093 && ustate.disabledComponents.size() > 0) {
Amith Yamasani483f3b02012-03-13 16:08:00 -07001094 serializer.startTag(null, TAG_DISABLED_COMPONENTS);
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001095 for (final String name : ustate.disabledComponents) {
Amith Yamasani483f3b02012-03-13 16:08:00 -07001096 serializer.startTag(null, TAG_ITEM);
1097 serializer.attribute(null, ATTR_NAME, name);
1098 serializer.endTag(null, TAG_ITEM);
1099 }
1100 serializer.endTag(null, TAG_DISABLED_COMPONENTS);
1101 }
1102 serializer.endTag(null, TAG_PACKAGE);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001103 }
1104 }
1105
Dianne Hackborn8a2ed1d2013-01-29 15:18:29 -08001106 writePreferredActivitiesLPr(serializer, userId, true);
Dianne Hackborn63092712012-10-07 14:45:35 -07001107
Amith Yamasani483f3b02012-03-13 16:08:00 -07001108 serializer.endTag(null, TAG_PACKAGE_RESTRICTIONS);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001109
1110 serializer.endDocument();
1111
1112 str.flush();
1113 FileUtils.sync(fstr);
1114 str.close();
1115
1116 // New settings successfully written, old ones are no longer
1117 // needed.
Amith Yamasani483f3b02012-03-13 16:08:00 -07001118 backupFile.delete();
1119 FileUtils.setPermissions(userPackagesStateFile.toString(),
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001120 FileUtils.S_IRUSR|FileUtils.S_IWUSR
Nick Kralevich70522ad2012-01-06 13:58:01 -08001121 |FileUtils.S_IRGRP|FileUtils.S_IWGRP,
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001122 -1, -1);
1123
1124 // Done, all is good!
1125 return;
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001126 } catch(java.io.IOException e) {
Amith Yamasani483f3b02012-03-13 16:08:00 -07001127 Log.wtf(PackageManagerService.TAG,
1128 "Unable to write package manager user packages state, "
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001129 + " current changes will be lost at reboot", e);
1130 }
1131
1132 // Clean up partially written files
Amith Yamasani483f3b02012-03-13 16:08:00 -07001133 if (userPackagesStateFile.exists()) {
1134 if (!userPackagesStateFile.delete()) {
1135 Log.i(PackageManagerService.TAG, "Failed to clean up mangled file: "
1136 + mStoppedPackagesFilename);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001137 }
1138 }
1139 }
1140
1141 // Note: assumed "stopped" field is already cleared in all packages.
Amith Yamasani483f3b02012-03-13 16:08:00 -07001142 // Legacy reader, used to read in the old file format after an upgrade. Not used after that.
Kenny Root447106f2011-03-23 11:00:15 -07001143 void readStoppedLPw() {
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001144 FileInputStream str = null;
1145 if (mBackupStoppedPackagesFilename.exists()) {
1146 try {
1147 str = new FileInputStream(mBackupStoppedPackagesFilename);
1148 mReadMessages.append("Reading from backup stopped packages file\n");
Amith Yamasani483f3b02012-03-13 16:08:00 -07001149 PackageManagerService.reportSettingsProblem(Log.INFO,
1150 "Need to read from backup stopped packages file");
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001151 if (mSettingsFilename.exists()) {
1152 // If both the backup and normal file exist, we
1153 // ignore the normal one since it might have been
1154 // corrupted.
1155 Slog.w(PackageManagerService.TAG, "Cleaning up stopped packages file "
1156 + mStoppedPackagesFilename);
1157 mStoppedPackagesFilename.delete();
1158 }
1159 } catch (java.io.IOException e) {
1160 // We'll try for the normal settings file.
1161 }
1162 }
1163
1164 try {
1165 if (str == null) {
1166 if (!mStoppedPackagesFilename.exists()) {
1167 mReadMessages.append("No stopped packages file found\n");
Amith Yamasani483f3b02012-03-13 16:08:00 -07001168 PackageManagerService.reportSettingsProblem(Log.INFO,
1169 "No stopped packages file file; assuming all started");
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001170 // At first boot, make sure no packages are stopped.
1171 // We usually want to have third party apps initialize
1172 // in the stopped state, but not at first boot.
1173 for (PackageSetting pkg : mPackages.values()) {
Amith Yamasani483f3b02012-03-13 16:08:00 -07001174 pkg.setStopped(false, 0);
1175 pkg.setNotLaunched(false, 0);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001176 }
1177 return;
1178 }
1179 str = new FileInputStream(mStoppedPackagesFilename);
1180 }
Kenny Root447106f2011-03-23 11:00:15 -07001181 final XmlPullParser parser = Xml.newPullParser();
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001182 parser.setInput(str, null);
1183
1184 int type;
1185 while ((type=parser.next()) != XmlPullParser.START_TAG
1186 && type != XmlPullParser.END_DOCUMENT) {
1187 ;
1188 }
1189
1190 if (type != XmlPullParser.START_TAG) {
1191 mReadMessages.append("No start tag found in stopped packages file\n");
1192 PackageManagerService.reportSettingsProblem(Log.WARN,
1193 "No start tag found in package manager stopped packages");
1194 return;
1195 }
1196
1197 int outerDepth = parser.getDepth();
1198 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
1199 && (type != XmlPullParser.END_TAG
1200 || parser.getDepth() > outerDepth)) {
1201 if (type == XmlPullParser.END_TAG
1202 || type == XmlPullParser.TEXT) {
1203 continue;
1204 }
1205
1206 String tagName = parser.getName();
Amith Yamasani483f3b02012-03-13 16:08:00 -07001207 if (tagName.equals(TAG_PACKAGE)) {
1208 String name = parser.getAttributeValue(null, ATTR_NAME);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001209 PackageSetting ps = mPackages.get(name);
1210 if (ps != null) {
Amith Yamasani483f3b02012-03-13 16:08:00 -07001211 ps.setStopped(true, 0);
1212 if ("1".equals(parser.getAttributeValue(null, ATTR_NOT_LAUNCHED))) {
1213 ps.setNotLaunched(true, 0);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001214 }
1215 } else {
Amith Yamasani483f3b02012-03-13 16:08:00 -07001216 Slog.w(PackageManagerService.TAG,
1217 "No package known for stopped package: " + name);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001218 }
1219 XmlUtils.skipCurrentTag(parser);
1220 } else {
1221 Slog.w(PackageManagerService.TAG, "Unknown element under <stopped-packages>: "
1222 + parser.getName());
1223 XmlUtils.skipCurrentTag(parser);
1224 }
1225 }
1226
1227 str.close();
1228
Amith Yamasani483f3b02012-03-13 16:08:00 -07001229 } catch (XmlPullParserException e) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001230 mReadMessages.append("Error reading: " + e.toString());
Amith Yamasani483f3b02012-03-13 16:08:00 -07001231 PackageManagerService.reportSettingsProblem(Log.ERROR,
1232 "Error reading stopped packages: " + e);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001233 Log.wtf(PackageManagerService.TAG, "Error reading package manager stopped packages", e);
1234
Amith Yamasani483f3b02012-03-13 16:08:00 -07001235 } catch (java.io.IOException e) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001236 mReadMessages.append("Error reading: " + e.toString());
1237 PackageManagerService.reportSettingsProblem(Log.ERROR, "Error reading settings: " + e);
1238 Log.wtf(PackageManagerService.TAG, "Error reading package manager stopped packages", e);
1239
1240 }
1241 }
1242
Kenny Root447106f2011-03-23 11:00:15 -07001243 void writeLPr() {
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001244 //Debug.startMethodTracing("/data/system/packageprof", 8 * 1024 * 1024);
1245
1246 // Keep the old settings around until we know the new ones have
1247 // been successfully written.
1248 if (mSettingsFilename.exists()) {
1249 // Presence of backup settings file indicates that we failed
1250 // to persist settings earlier. So preserve the older
1251 // backup for future reference since the current settings
1252 // might have been corrupted.
1253 if (!mBackupSettingsFilename.exists()) {
1254 if (!mSettingsFilename.renameTo(mBackupSettingsFilename)) {
1255 Log.wtf(PackageManagerService.TAG, "Unable to backup package manager settings, "
1256 + " current changes will be lost at reboot");
1257 return;
1258 }
1259 } else {
1260 mSettingsFilename.delete();
1261 Slog.w(PackageManagerService.TAG, "Preserving older settings backup");
1262 }
1263 }
1264
1265 mPastSignatures.clear();
1266
1267 try {
1268 FileOutputStream fstr = new FileOutputStream(mSettingsFilename);
1269 BufferedOutputStream str = new BufferedOutputStream(fstr);
1270
1271 //XmlSerializer serializer = XmlUtils.serializerInstance();
1272 XmlSerializer serializer = new FastXmlSerializer();
1273 serializer.setOutput(str, "utf-8");
1274 serializer.startDocument(null, true);
1275 serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
1276
1277 serializer.startTag(null, "packages");
1278
1279 serializer.startTag(null, "last-platform-version");
1280 serializer.attribute(null, "internal", Integer.toString(mInternalSdkPlatform));
1281 serializer.attribute(null, "external", Integer.toString(mExternalSdkPlatform));
1282 serializer.endTag(null, "last-platform-version");
Jeff Sharkeyedc84ee82012-03-19 16:52:26 -07001283
Kenny Root0aaa0d92011-09-12 16:42:55 -07001284 if (mVerifierDeviceIdentity != null) {
1285 serializer.startTag(null, "verifier");
1286 serializer.attribute(null, "device", mVerifierDeviceIdentity.toString());
1287 serializer.endTag(null, "verifier");
1288 }
1289
Jeff Sharkeyf5385772012-05-11 14:04:41 -07001290 if (mReadExternalStorageEnforced != null) {
Jeff Sharkeyedc84ee82012-03-19 16:52:26 -07001291 serializer.startTag(null, TAG_READ_EXTERNAL_STORAGE);
1292 serializer.attribute(
Jeff Sharkey5d32e772012-04-12 15:59:23 -07001293 null, ATTR_ENFORCEMENT, mReadExternalStorageEnforced ? "1" : "0");
Jeff Sharkeyedc84ee82012-03-19 16:52:26 -07001294 serializer.endTag(null, TAG_READ_EXTERNAL_STORAGE);
1295 }
1296
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001297 serializer.startTag(null, "permission-trees");
1298 for (BasePermission bp : mPermissionTrees.values()) {
Kenny Root447106f2011-03-23 11:00:15 -07001299 writePermissionLPr(serializer, bp);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001300 }
1301 serializer.endTag(null, "permission-trees");
1302
1303 serializer.startTag(null, "permissions");
1304 for (BasePermission bp : mPermissions.values()) {
Kenny Root447106f2011-03-23 11:00:15 -07001305 writePermissionLPr(serializer, bp);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001306 }
1307 serializer.endTag(null, "permissions");
1308
Kenny Root447106f2011-03-23 11:00:15 -07001309 for (final PackageSetting pkg : mPackages.values()) {
1310 writePackageLPr(serializer, pkg);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001311 }
1312
Kenny Root447106f2011-03-23 11:00:15 -07001313 for (final PackageSetting pkg : mDisabledSysPackages.values()) {
1314 writeDisabledSysPackageLPr(serializer, pkg);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001315 }
1316
Kenny Root447106f2011-03-23 11:00:15 -07001317 for (final SharedUserSetting usr : mSharedUsers.values()) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001318 serializer.startTag(null, "shared-user");
Amith Yamasani483f3b02012-03-13 16:08:00 -07001319 serializer.attribute(null, ATTR_NAME, usr.name);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001320 serializer.attribute(null, "userId",
1321 Integer.toString(usr.userId));
1322 usr.signatures.writeXml(serializer, "sigs", mPastSignatures);
1323 serializer.startTag(null, "perms");
1324 for (String name : usr.grantedPermissions) {
Amith Yamasani483f3b02012-03-13 16:08:00 -07001325 serializer.startTag(null, TAG_ITEM);
1326 serializer.attribute(null, ATTR_NAME, name);
1327 serializer.endTag(null, TAG_ITEM);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001328 }
1329 serializer.endTag(null, "perms");
1330 serializer.endTag(null, "shared-user");
1331 }
1332
1333 if (mPackagesToBeCleaned.size() > 0) {
Jeff Sharkey752cd922012-09-23 16:25:12 -07001334 for (PackageCleanItem item : mPackagesToBeCleaned) {
1335 final String userStr = Integer.toString(item.userId);
1336 serializer.startTag(null, "cleaning-package");
1337 serializer.attribute(null, ATTR_NAME, item.packageName);
1338 serializer.attribute(null, ATTR_CODE, item.andCode ? "true" : "false");
1339 serializer.attribute(null, ATTR_USER, userStr);
1340 serializer.endTag(null, "cleaning-package");
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001341 }
1342 }
1343
1344 if (mRenamedPackages.size() > 0) {
Andy McFadden2f362292012-01-20 14:43:38 -08001345 for (Map.Entry<String, String> e : mRenamedPackages.entrySet()) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001346 serializer.startTag(null, "renamed-package");
1347 serializer.attribute(null, "new", e.getKey());
1348 serializer.attribute(null, "old", e.getValue());
1349 serializer.endTag(null, "renamed-package");
1350 }
1351 }
1352
Geremy Condraf1bcca82013-01-07 22:35:24 -08001353 mKeySetManager.writeKeySetManagerLPr(serializer);
1354
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001355 serializer.endTag(null, "packages");
1356
1357 serializer.endDocument();
1358
1359 str.flush();
1360 FileUtils.sync(fstr);
1361 str.close();
1362
1363 // New settings successfully written, old ones are no longer
1364 // needed.
1365 mBackupSettingsFilename.delete();
1366 FileUtils.setPermissions(mSettingsFilename.toString(),
1367 FileUtils.S_IRUSR|FileUtils.S_IWUSR
Nick Kralevich70522ad2012-01-06 13:58:01 -08001368 |FileUtils.S_IRGRP|FileUtils.S_IWGRP,
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001369 -1, -1);
1370
1371 // Write package list file now, use a JournaledFile.
1372 //
1373 File tempFile = new File(mPackageListFilename.toString() + ".tmp");
1374 JournaledFile journal = new JournaledFile(mPackageListFilename, tempFile);
1375
1376 fstr = new FileOutputStream(journal.chooseForWrite());
1377 str = new BufferedOutputStream(fstr);
1378 try {
1379 StringBuilder sb = new StringBuilder();
Kenny Root447106f2011-03-23 11:00:15 -07001380 for (final PackageSetting pkg : mPackages.values()) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001381 ApplicationInfo ai = pkg.pkg.applicationInfo;
1382 String dataPath = ai.dataDir;
1383 boolean isDebug = (ai.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
1384
1385 // Avoid any application that has a space in its path
1386 // or that is handled by the system.
Magnus Eriksson1358ebe2012-03-27 15:40:18 +02001387 if (dataPath.indexOf(" ") >= 0 || ai.uid < Process.FIRST_APPLICATION_UID)
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001388 continue;
1389
1390 // we store on each line the following information for now:
1391 //
1392 // pkgName - package name
1393 // userId - application-specific user id
1394 // debugFlag - 0 or 1 if the package is debuggable.
1395 // dataPath - path to package's data path
Robert Craig4a453732013-03-26 08:21:37 -04001396 // seinfo - seinfo label for the app (assigned at install time)
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001397 //
1398 // NOTE: We prefer not to expose all ApplicationInfo flags for now.
1399 //
1400 // DO NOT MODIFY THIS FORMAT UNLESS YOU CAN ALSO MODIFY ITS USERS
1401 // FROM NATIVE CODE. AT THE MOMENT, LOOK AT THE FOLLOWING SOURCES:
1402 // system/core/run-as/run-as.c
1403 //
1404 sb.setLength(0);
1405 sb.append(ai.packageName);
1406 sb.append(" ");
1407 sb.append((int)ai.uid);
1408 sb.append(isDebug ? " 1 " : " 0 ");
1409 sb.append(dataPath);
Robert Craig4a453732013-03-26 08:21:37 -04001410 sb.append(" ");
1411 sb.append(ai.seinfo);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001412 sb.append("\n");
1413 str.write(sb.toString().getBytes());
1414 }
1415 str.flush();
1416 FileUtils.sync(fstr);
1417 str.close();
1418 journal.commit();
Kenny Root62539e92011-11-10 09:35:38 -08001419 } catch (Exception e) {
1420 IoUtils.closeQuietly(str);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001421 journal.rollback();
1422 }
1423
1424 FileUtils.setPermissions(mPackageListFilename.toString(),
1425 FileUtils.S_IRUSR|FileUtils.S_IWUSR
Nick Kralevich70522ad2012-01-06 13:58:01 -08001426 |FileUtils.S_IRGRP|FileUtils.S_IWGRP,
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001427 -1, -1);
1428
Amith Yamasani483f3b02012-03-13 16:08:00 -07001429 writeAllUsersPackageRestrictionsLPr();
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001430 return;
1431
1432 } catch(XmlPullParserException e) {
1433 Log.wtf(PackageManagerService.TAG, "Unable to write package manager settings, "
1434 + "current changes will be lost at reboot", e);
1435 } catch(java.io.IOException e) {
1436 Log.wtf(PackageManagerService.TAG, "Unable to write package manager settings, "
1437 + "current changes will be lost at reboot", e);
1438 }
1439 // Clean up partially written files
1440 if (mSettingsFilename.exists()) {
1441 if (!mSettingsFilename.delete()) {
Amith Yamasani483f3b02012-03-13 16:08:00 -07001442 Log.wtf(PackageManagerService.TAG, "Failed to clean up mangled file: "
1443 + mSettingsFilename);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001444 }
1445 }
1446 //Debug.stopMethodTracing();
1447 }
1448
Kenny Root447106f2011-03-23 11:00:15 -07001449 void writeDisabledSysPackageLPr(XmlSerializer serializer, final PackageSetting pkg)
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001450 throws java.io.IOException {
1451 serializer.startTag(null, "updated-package");
Amith Yamasani483f3b02012-03-13 16:08:00 -07001452 serializer.attribute(null, ATTR_NAME, pkg.name);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001453 if (pkg.realName != null) {
1454 serializer.attribute(null, "realName", pkg.realName);
1455 }
1456 serializer.attribute(null, "codePath", pkg.codePathString);
1457 serializer.attribute(null, "ft", Long.toHexString(pkg.timeStamp));
1458 serializer.attribute(null, "it", Long.toHexString(pkg.firstInstallTime));
1459 serializer.attribute(null, "ut", Long.toHexString(pkg.lastUpdateTime));
1460 serializer.attribute(null, "version", String.valueOf(pkg.versionCode));
1461 if (!pkg.resourcePathString.equals(pkg.codePathString)) {
1462 serializer.attribute(null, "resourcePath", pkg.resourcePathString);
1463 }
1464 if (pkg.nativeLibraryPathString != null) {
1465 serializer.attribute(null, "nativeLibraryPath", pkg.nativeLibraryPathString);
1466 }
1467 if (pkg.sharedUser == null) {
Amith Yamasani13593602012-03-22 16:16:17 -07001468 serializer.attribute(null, "userId", Integer.toString(pkg.appId));
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001469 } else {
Amith Yamasani13593602012-03-22 16:16:17 -07001470 serializer.attribute(null, "sharedUserId", Integer.toString(pkg.appId));
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001471 }
1472 serializer.startTag(null, "perms");
1473 if (pkg.sharedUser == null) {
1474 // If this is a shared user, the permissions will
1475 // be written there. We still need to write an
1476 // empty permissions list so permissionsFixed will
1477 // be set.
1478 for (final String name : pkg.grantedPermissions) {
1479 BasePermission bp = mPermissions.get(name);
1480 if (bp != null) {
1481 // We only need to write signature or system permissions but
1482 // this wont
1483 // match the semantics of grantedPermissions. So write all
1484 // permissions.
Amith Yamasani483f3b02012-03-13 16:08:00 -07001485 serializer.startTag(null, TAG_ITEM);
1486 serializer.attribute(null, ATTR_NAME, name);
1487 serializer.endTag(null, TAG_ITEM);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001488 }
1489 }
1490 }
1491 serializer.endTag(null, "perms");
1492 serializer.endTag(null, "updated-package");
1493 }
1494
Kenny Root447106f2011-03-23 11:00:15 -07001495 void writePackageLPr(XmlSerializer serializer, final PackageSetting pkg)
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001496 throws java.io.IOException {
1497 serializer.startTag(null, "package");
Amith Yamasani483f3b02012-03-13 16:08:00 -07001498 serializer.attribute(null, ATTR_NAME, pkg.name);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001499 if (pkg.realName != null) {
1500 serializer.attribute(null, "realName", pkg.realName);
1501 }
1502 serializer.attribute(null, "codePath", pkg.codePathString);
1503 if (!pkg.resourcePathString.equals(pkg.codePathString)) {
1504 serializer.attribute(null, "resourcePath", pkg.resourcePathString);
1505 }
1506 if (pkg.nativeLibraryPathString != null) {
1507 serializer.attribute(null, "nativeLibraryPath", pkg.nativeLibraryPathString);
1508 }
1509 serializer.attribute(null, "flags", Integer.toString(pkg.pkgFlags));
1510 serializer.attribute(null, "ft", Long.toHexString(pkg.timeStamp));
1511 serializer.attribute(null, "it", Long.toHexString(pkg.firstInstallTime));
1512 serializer.attribute(null, "ut", Long.toHexString(pkg.lastUpdateTime));
1513 serializer.attribute(null, "version", String.valueOf(pkg.versionCode));
1514 if (pkg.sharedUser == null) {
Amith Yamasani13593602012-03-22 16:16:17 -07001515 serializer.attribute(null, "userId", Integer.toString(pkg.appId));
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001516 } else {
Amith Yamasani13593602012-03-22 16:16:17 -07001517 serializer.attribute(null, "sharedUserId", Integer.toString(pkg.appId));
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001518 }
1519 if (pkg.uidError) {
1520 serializer.attribute(null, "uidError", "true");
1521 }
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001522 if (pkg.installStatus == PackageSettingBase.PKG_INSTALL_INCOMPLETE) {
1523 serializer.attribute(null, "installStatus", "false");
1524 }
1525 if (pkg.installerPackageName != null) {
1526 serializer.attribute(null, "installer", pkg.installerPackageName);
1527 }
1528 pkg.signatures.writeXml(serializer, "sigs", mPastSignatures);
1529 if ((pkg.pkgFlags & ApplicationInfo.FLAG_SYSTEM) == 0) {
1530 serializer.startTag(null, "perms");
1531 if (pkg.sharedUser == null) {
1532 // If this is a shared user, the permissions will
1533 // be written there. We still need to write an
1534 // empty permissions list so permissionsFixed will
1535 // be set.
1536 for (final String name : pkg.grantedPermissions) {
Amith Yamasani483f3b02012-03-13 16:08:00 -07001537 serializer.startTag(null, TAG_ITEM);
1538 serializer.attribute(null, ATTR_NAME, name);
1539 serializer.endTag(null, TAG_ITEM);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001540 }
1541 }
1542 serializer.endTag(null, "perms");
1543 }
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001544
Geremy Condraf1bcca82013-01-07 22:35:24 -08001545 writeSigningKeySetsLPr(serializer, pkg.keySetData);
1546 writeKeySetAliasesLPr(serializer, pkg.keySetData);
1547
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001548 serializer.endTag(null, "package");
1549 }
1550
Geremy Condraf1bcca82013-01-07 22:35:24 -08001551 void writeSigningKeySetsLPr(XmlSerializer serializer,
1552 PackageKeySetData data) throws IOException {
1553 for (long id : data.getSigningKeySets()) {
1554 serializer.startTag(null, "signing-keyset");
1555 serializer.attribute(null, "identifier", Long.toString(id));
1556 serializer.endTag(null, "signing-keyset");
1557 }
1558 }
1559
1560 void writeKeySetAliasesLPr(XmlSerializer serializer,
1561 PackageKeySetData data) throws IOException {
1562 for (Map.Entry<String, Long> e: data.getAliases().entrySet()) {
1563 serializer.startTag(null, "defined-keyset");
1564 serializer.attribute(null, "alias", e.getKey());
1565 serializer.attribute(null, "identifier", Long.toString(e.getValue()));
1566 serializer.endTag(null, "defined-keyset");
1567 }
1568 }
1569
Kenny Root447106f2011-03-23 11:00:15 -07001570 void writePermissionLPr(XmlSerializer serializer, BasePermission bp)
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001571 throws XmlPullParserException, java.io.IOException {
1572 if (bp.type != BasePermission.TYPE_BUILTIN && bp.sourcePackage != null) {
Amith Yamasani483f3b02012-03-13 16:08:00 -07001573 serializer.startTag(null, TAG_ITEM);
1574 serializer.attribute(null, ATTR_NAME, bp.name);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001575 serializer.attribute(null, "package", bp.sourcePackage);
1576 if (bp.protectionLevel != PermissionInfo.PROTECTION_NORMAL) {
1577 serializer.attribute(null, "protection", Integer.toString(bp.protectionLevel));
1578 }
1579 if (PackageManagerService.DEBUG_SETTINGS)
1580 Log.v(PackageManagerService.TAG, "Writing perm: name=" + bp.name + " type="
1581 + bp.type);
1582 if (bp.type == BasePermission.TYPE_DYNAMIC) {
Kenny Root447106f2011-03-23 11:00:15 -07001583 final PermissionInfo pi = bp.perm != null ? bp.perm.info : bp.pendingInfo;
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001584 if (pi != null) {
1585 serializer.attribute(null, "type", "dynamic");
1586 if (pi.icon != 0) {
1587 serializer.attribute(null, "icon", Integer.toString(pi.icon));
1588 }
1589 if (pi.nonLocalizedLabel != null) {
1590 serializer.attribute(null, "label", pi.nonLocalizedLabel.toString());
1591 }
1592 }
1593 }
Amith Yamasani483f3b02012-03-13 16:08:00 -07001594 serializer.endTag(null, TAG_ITEM);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001595 }
1596 }
1597
Kenny Root447106f2011-03-23 11:00:15 -07001598 ArrayList<PackageSetting> getListOfIncompleteInstallPackagesLPr() {
1599 final HashSet<String> kList = new HashSet<String>(mPackages.keySet());
1600 final Iterator<String> its = kList.iterator();
1601 final ArrayList<PackageSetting> ret = new ArrayList<PackageSetting>();
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001602 while (its.hasNext()) {
Kenny Root447106f2011-03-23 11:00:15 -07001603 final String key = its.next();
1604 final PackageSetting ps = mPackages.get(key);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001605 if (ps.getInstallStatus() == PackageSettingBase.PKG_INSTALL_INCOMPLETE) {
1606 ret.add(ps);
1607 }
1608 }
1609 return ret;
1610 }
1611
Jeff Sharkey752cd922012-09-23 16:25:12 -07001612 void addPackageToCleanLPw(PackageCleanItem pkg) {
1613 if (!mPackagesToBeCleaned.contains(pkg)) {
1614 mPackagesToBeCleaned.add(pkg);
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001615 }
1616 }
1617
Dianne Hackborn8a2ed1d2013-01-29 15:18:29 -08001618 boolean readLPw(PackageManagerService service, List<UserInfo> users, int sdkVersion,
1619 boolean onlyCore) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001620 FileInputStream str = null;
1621 if (mBackupSettingsFilename.exists()) {
1622 try {
1623 str = new FileInputStream(mBackupSettingsFilename);
1624 mReadMessages.append("Reading from backup settings file\n");
1625 PackageManagerService.reportSettingsProblem(Log.INFO,
1626 "Need to read from backup settings file");
1627 if (mSettingsFilename.exists()) {
1628 // If both the backup and settings file exist, we
1629 // ignore the settings since it might have been
1630 // corrupted.
1631 Slog.w(PackageManagerService.TAG, "Cleaning up settings file "
1632 + mSettingsFilename);
1633 mSettingsFilename.delete();
1634 }
1635 } catch (java.io.IOException e) {
1636 // We'll try for the normal settings file.
1637 }
1638 }
1639
Kenny Root447106f2011-03-23 11:00:15 -07001640 mPendingPackages.clear();
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001641 mPastSignatures.clear();
1642
1643 try {
1644 if (str == null) {
1645 if (!mSettingsFilename.exists()) {
1646 mReadMessages.append("No settings file found\n");
1647 PackageManagerService.reportSettingsProblem(Log.INFO,
1648 "No settings file; creating initial state");
Dianne Hackborn13579ed2012-11-28 18:05:36 -08001649 mInternalSdkPlatform = mExternalSdkPlatform = sdkVersion;
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001650 return false;
1651 }
1652 str = new FileInputStream(mSettingsFilename);
1653 }
1654 XmlPullParser parser = Xml.newPullParser();
1655 parser.setInput(str, null);
1656
1657 int type;
1658 while ((type = parser.next()) != XmlPullParser.START_TAG
1659 && type != XmlPullParser.END_DOCUMENT) {
1660 ;
1661 }
1662
1663 if (type != XmlPullParser.START_TAG) {
1664 mReadMessages.append("No start tag found in settings file\n");
1665 PackageManagerService.reportSettingsProblem(Log.WARN,
1666 "No start tag found in package manager settings");
Dianne Hackborn58f42a52011-10-10 13:46:34 -07001667 Log.wtf(PackageManagerService.TAG,
1668 "No start tag found in package manager settings");
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001669 return false;
1670 }
1671
1672 int outerDepth = parser.getDepth();
1673 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
1674 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
1675 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
1676 continue;
1677 }
1678
1679 String tagName = parser.getName();
1680 if (tagName.equals("package")) {
Kenny Root447106f2011-03-23 11:00:15 -07001681 readPackageLPw(parser);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001682 } else if (tagName.equals("permissions")) {
Kenny Root447106f2011-03-23 11:00:15 -07001683 readPermissionsLPw(mPermissions, parser);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001684 } else if (tagName.equals("permission-trees")) {
Kenny Root447106f2011-03-23 11:00:15 -07001685 readPermissionsLPw(mPermissionTrees, parser);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001686 } else if (tagName.equals("shared-user")) {
Kenny Root447106f2011-03-23 11:00:15 -07001687 readSharedUserLPw(parser);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001688 } else if (tagName.equals("preferred-packages")) {
1689 // no longer used.
1690 } else if (tagName.equals("preferred-activities")) {
Dianne Hackborn63092712012-10-07 14:45:35 -07001691 // Upgrading from old single-user implementation;
1692 // these are the preferred activities for user 0.
1693 readPreferredActivitiesLPw(parser, 0);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001694 } else if (tagName.equals("updated-package")) {
Kenny Root447106f2011-03-23 11:00:15 -07001695 readDisabledSysPackageLPw(parser);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001696 } else if (tagName.equals("cleaning-package")) {
Amith Yamasani483f3b02012-03-13 16:08:00 -07001697 String name = parser.getAttributeValue(null, ATTR_NAME);
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001698 String userStr = parser.getAttributeValue(null, ATTR_USER);
1699 String codeStr = parser.getAttributeValue(null, ATTR_CODE);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001700 if (name != null) {
Jeff Sharkey752cd922012-09-23 16:25:12 -07001701 int userId = 0;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001702 boolean andCode = true;
1703 try {
1704 if (userStr != null) {
Jeff Sharkey752cd922012-09-23 16:25:12 -07001705 userId = Integer.parseInt(userStr);
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001706 }
1707 } catch (NumberFormatException e) {
1708 }
1709 if (codeStr != null) {
1710 andCode = Boolean.parseBoolean(codeStr);
1711 }
Jeff Sharkey752cd922012-09-23 16:25:12 -07001712 addPackageToCleanLPw(new PackageCleanItem(userId, name, andCode));
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001713 }
1714 } else if (tagName.equals("renamed-package")) {
1715 String nname = parser.getAttributeValue(null, "new");
1716 String oname = parser.getAttributeValue(null, "old");
1717 if (nname != null && oname != null) {
1718 mRenamedPackages.put(nname, oname);
1719 }
1720 } else if (tagName.equals("last-platform-version")) {
1721 mInternalSdkPlatform = mExternalSdkPlatform = 0;
1722 try {
1723 String internal = parser.getAttributeValue(null, "internal");
1724 if (internal != null) {
1725 mInternalSdkPlatform = Integer.parseInt(internal);
1726 }
1727 String external = parser.getAttributeValue(null, "external");
1728 if (external != null) {
1729 mExternalSdkPlatform = Integer.parseInt(external);
1730 }
1731 } catch (NumberFormatException e) {
1732 }
Kenny Root0aaa0d92011-09-12 16:42:55 -07001733 } else if (tagName.equals("verifier")) {
1734 final String deviceIdentity = parser.getAttributeValue(null, "device");
1735 try {
1736 mVerifierDeviceIdentity = VerifierDeviceIdentity.parse(deviceIdentity);
1737 } catch (IllegalArgumentException e) {
1738 Slog.w(PackageManagerService.TAG, "Discard invalid verifier device id: "
1739 + e.getMessage());
1740 }
Jeff Sharkeyedc84ee82012-03-19 16:52:26 -07001741 } else if (TAG_READ_EXTERNAL_STORAGE.equals(tagName)) {
1742 final String enforcement = parser.getAttributeValue(null, ATTR_ENFORCEMENT);
Jeff Sharkey5d32e772012-04-12 15:59:23 -07001743 mReadExternalStorageEnforced = "1".equals(enforcement);
Geremy Condraf1bcca82013-01-07 22:35:24 -08001744 } else if (tagName.equals("keyset-settings")) {
1745 mKeySetManager.readKeySetsLPw(parser);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001746 } else {
1747 Slog.w(PackageManagerService.TAG, "Unknown element under <packages>: "
1748 + parser.getName());
1749 XmlUtils.skipCurrentTag(parser);
1750 }
1751 }
1752
1753 str.close();
1754
1755 } catch (XmlPullParserException e) {
1756 mReadMessages.append("Error reading: " + e.toString());
1757 PackageManagerService.reportSettingsProblem(Log.ERROR, "Error reading settings: " + e);
1758 Log.wtf(PackageManagerService.TAG, "Error reading package manager settings", e);
1759
1760 } catch (java.io.IOException e) {
1761 mReadMessages.append("Error reading: " + e.toString());
1762 PackageManagerService.reportSettingsProblem(Log.ERROR, "Error reading settings: " + e);
1763 Log.wtf(PackageManagerService.TAG, "Error reading package manager settings", e);
Amith Yamasani258848d2012-08-10 17:06:33 -07001764 }
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001765
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001766 final int N = mPendingPackages.size();
1767 for (int i = 0; i < N; i++) {
1768 final PendingPackage pp = mPendingPackages.get(i);
Kenny Root447106f2011-03-23 11:00:15 -07001769 Object idObj = getUserIdLPr(pp.sharedId);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001770 if (idObj != null && idObj instanceof SharedUserSetting) {
Kenny Root447106f2011-03-23 11:00:15 -07001771 PackageSetting p = getPackageLPw(pp.name, null, pp.realName,
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001772 (SharedUserSetting) idObj, pp.codePath, pp.resourcePath,
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001773 pp.nativeLibraryPathString, pp.versionCode, pp.pkgFlags,
Amith Yamasanif031f232012-10-26 15:35:21 -07001774 null, true /* add */, false /* allowInstall */);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001775 if (p == null) {
1776 PackageManagerService.reportSettingsProblem(Log.WARN,
1777 "Unable to create application package for " + pp.name);
1778 continue;
1779 }
1780 p.copyFrom(pp);
1781 } else if (idObj != null) {
1782 String msg = "Bad package setting: package " + pp.name + " has shared uid "
1783 + pp.sharedId + " that is not a shared uid\n";
1784 mReadMessages.append(msg);
1785 PackageManagerService.reportSettingsProblem(Log.ERROR, msg);
1786 } else {
1787 String msg = "Bad package setting: package " + pp.name + " has shared uid "
1788 + pp.sharedId + " that is not defined\n";
1789 mReadMessages.append(msg);
1790 PackageManagerService.reportSettingsProblem(Log.ERROR, msg);
1791 }
1792 }
1793 mPendingPackages.clear();
1794
Amith Yamasanif031f232012-10-26 15:35:21 -07001795 if (mBackupStoppedPackagesFilename.exists()
1796 || mStoppedPackagesFilename.exists()) {
1797 // Read old file
1798 readStoppedLPw();
1799 mBackupStoppedPackagesFilename.delete();
1800 mStoppedPackagesFilename.delete();
1801 // Migrate to new file format
1802 writePackageRestrictionsLPr(0);
1803 } else {
1804 if (users == null) {
1805 readPackageRestrictionsLPr(0);
1806 } else {
1807 for (UserInfo user : users) {
1808 readPackageRestrictionsLPr(user.id);
1809 }
1810 }
1811 }
1812
Kenny Root1d1b4892011-04-08 14:25:24 -07001813 /*
1814 * Make sure all the updated system packages have their shared users
1815 * associated with them.
1816 */
1817 final Iterator<PackageSetting> disabledIt = mDisabledSysPackages.values().iterator();
1818 while (disabledIt.hasNext()) {
1819 final PackageSetting disabledPs = disabledIt.next();
Amith Yamasani13593602012-03-22 16:16:17 -07001820 final Object id = getUserIdLPr(disabledPs.appId);
Kenny Root1d1b4892011-04-08 14:25:24 -07001821 if (id != null && id instanceof SharedUserSetting) {
1822 disabledPs.sharedUser = (SharedUserSetting) id;
1823 }
1824 }
1825
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001826 mReadMessages.append("Read completed successfully: " + mPackages.size() + " packages, "
1827 + mSharedUsers.size() + " shared uids\n");
1828
1829 return true;
1830 }
1831
Dianne Hackborn8a2ed1d2013-01-29 15:18:29 -08001832 void readDefaultPreferredAppsLPw(PackageManagerService service, int userId) {
Dianne Hackbornfc8b7fe2012-06-18 15:38:12 -07001833 // Read preferred apps from .../etc/preferred-apps directory.
1834 File preferredDir = new File(Environment.getRootDirectory(), "etc/preferred-apps");
1835 if (!preferredDir.exists() || !preferredDir.isDirectory()) {
1836 return;
1837 }
1838 if (!preferredDir.canRead()) {
1839 Slog.w(TAG, "Directory " + preferredDir + " cannot be read");
1840 return;
1841 }
1842
1843 // Iterate over the files in the directory and scan .xml files
1844 for (File f : preferredDir.listFiles()) {
1845 if (!f.getPath().endsWith(".xml")) {
1846 Slog.i(TAG, "Non-xml file " + f + " in " + preferredDir + " directory, ignoring");
1847 continue;
1848 }
1849 if (!f.canRead()) {
1850 Slog.w(TAG, "Preferred apps file " + f + " cannot be read");
1851 continue;
1852 }
1853
Dianne Hackborn8a2ed1d2013-01-29 15:18:29 -08001854 if (PackageManagerService.DEBUG_PREFERRED) Log.d(TAG, "Reading default preferred " + f);
Dianne Hackbornfc8b7fe2012-06-18 15:38:12 -07001855 FileInputStream str = null;
1856 try {
1857 str = new FileInputStream(f);
1858 XmlPullParser parser = Xml.newPullParser();
1859 parser.setInput(str, null);
1860
1861 int type;
1862 while ((type = parser.next()) != XmlPullParser.START_TAG
1863 && type != XmlPullParser.END_DOCUMENT) {
1864 ;
1865 }
1866
1867 if (type != XmlPullParser.START_TAG) {
1868 Slog.w(TAG, "Preferred apps file " + f + " does not have start tag");
1869 continue;
1870 }
1871 if (!"preferred-activities".equals(parser.getName())) {
1872 Slog.w(TAG, "Preferred apps file " + f
1873 + " does not start with 'preferred-activities'");
1874 continue;
1875 }
Dianne Hackborn8a2ed1d2013-01-29 15:18:29 -08001876 readDefaultPreferredActivitiesLPw(service, parser, userId);
Dianne Hackbornfc8b7fe2012-06-18 15:38:12 -07001877 } catch (XmlPullParserException e) {
1878 Slog.w(TAG, "Error reading apps file " + f, e);
1879 } catch (IOException e) {
1880 Slog.w(TAG, "Error reading apps file " + f, e);
1881 } finally {
1882 if (str != null) {
1883 try {
1884 str.close();
1885 } catch (IOException e) {
1886 }
1887 }
1888 }
1889 }
1890 }
1891
Dianne Hackborn8a2ed1d2013-01-29 15:18:29 -08001892 private void readDefaultPreferredActivitiesLPw(PackageManagerService service,
1893 XmlPullParser parser, int userId)
1894 throws XmlPullParserException, IOException {
1895 int outerDepth = parser.getDepth();
1896 int type;
1897 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
1898 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
1899 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
1900 continue;
1901 }
1902
1903 String tagName = parser.getName();
1904 if (tagName.equals(TAG_ITEM)) {
1905 PreferredActivity tmpPa = new PreferredActivity(parser);
1906 if (tmpPa.mPref.getParseError() == null) {
1907 // The initial preferences only specify the target activity
1908 // component and intent-filter, not the set of matches. So we
1909 // now need to query for the matches to build the correct
1910 // preferred activity entry.
1911 if (PackageManagerService.DEBUG_PREFERRED) {
1912 Log.d(TAG, "Processing preferred:");
1913 tmpPa.dump(new LogPrinter(Log.DEBUG, TAG), " ");
1914 }
1915 final ComponentName cn = tmpPa.mPref.mComponent;
1916 Intent intent = new Intent();
1917 int flags = 0;
1918 intent.setAction(tmpPa.getAction(0));
1919 for (int i=0; i<tmpPa.countCategories(); i++) {
1920 String cat = tmpPa.getCategory(i);
1921 if (cat.equals(Intent.CATEGORY_DEFAULT)) {
1922 flags |= PackageManager.MATCH_DEFAULT_ONLY;
1923 } else {
1924 intent.addCategory(cat);
1925 }
1926 }
1927 if (tmpPa.countDataSchemes() > 0) {
1928 Uri.Builder builder = new Uri.Builder();
1929 builder.scheme(tmpPa.getDataScheme(0));
Dianne Hackborndf1c0bf2013-06-12 16:21:38 -07001930 if (tmpPa.countDataSchemeSpecificParts() > 0) {
1931 PatternMatcher path = tmpPa.getDataSchemeSpecificPart(0);
1932 builder.opaquePart(path.getPath());
1933 } else {
1934 if (tmpPa.countDataAuthorities() > 0) {
1935 IntentFilter.AuthorityEntry auth = tmpPa.getDataAuthority(0);
1936 if (auth.getHost() != null) {
1937 builder.authority(auth.getHost());
1938 }
Dianne Hackborn8a2ed1d2013-01-29 15:18:29 -08001939 }
Dianne Hackborndf1c0bf2013-06-12 16:21:38 -07001940 if (tmpPa.countDataPaths() > 0) {
1941 PatternMatcher path = tmpPa.getDataPath(0);
1942 builder.path(path.getPath());
1943 }
Dianne Hackborn8a2ed1d2013-01-29 15:18:29 -08001944 }
1945 intent.setData(builder.build());
1946 } else if (tmpPa.countDataTypes() > 0) {
1947 intent.setType(tmpPa.getDataType(0));
1948 }
1949 List<ResolveInfo> ri = service.mActivities.queryIntent(intent,
1950 intent.getType(), flags, 0);
1951 if (PackageManagerService.DEBUG_PREFERRED) Log.d(TAG, "Queried " + intent
1952 + " results: " + ri);
1953 int match = 0;
1954 if (ri != null && ri.size() > 1) {
1955 boolean haveAct = false;
1956 boolean haveNonSys = false;
1957 ComponentName[] set = new ComponentName[ri.size()];
1958 for (int i=0; i<ri.size(); i++) {
1959 ActivityInfo ai = ri.get(i).activityInfo;
1960 set[i] = new ComponentName(ai.packageName, ai.name);
1961 if ((ai.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) == 0) {
1962 // If any of the matches are not system apps, then
1963 // there is a third party app that is now an option...
1964 // so don't set a default since we don't want to hide it.
1965 if (PackageManagerService.DEBUG_PREFERRED) Log.d(TAG, "Result "
1966 + ai.packageName + "/" + ai.name + ": non-system!");
1967 haveNonSys = true;
1968 break;
1969 } else if (cn.getPackageName().equals(ai.packageName)
1970 && cn.getClassName().equals(ai.name)) {
1971 if (PackageManagerService.DEBUG_PREFERRED) Log.d(TAG, "Result "
1972 + ai.packageName + "/" + ai.name + ": default!");
1973 haveAct = true;
1974 match = ri.get(i).match;
1975 } else {
1976 if (PackageManagerService.DEBUG_PREFERRED) Log.d(TAG, "Result "
1977 + ai.packageName + "/" + ai.name + ": skipped");
1978 }
1979 }
1980 if (haveAct && !haveNonSys) {
1981 PreferredActivity pa = new PreferredActivity(tmpPa, match, set,
1982 tmpPa.mPref.mComponent);
1983 editPreferredActivitiesLPw(userId).addFilter(pa);
1984 } else if (!haveNonSys) {
1985 Slog.w(TAG, "No component found for default preferred activity "
1986 + tmpPa.mPref.mComponent);
1987 }
1988 }
1989 } else {
1990 PackageManagerService.reportSettingsProblem(Log.WARN,
1991 "Error in package manager settings: <preferred-activity> "
1992 + tmpPa.mPref.getParseError() + " at "
1993 + parser.getPositionDescription());
1994 }
1995 } else {
1996 PackageManagerService.reportSettingsProblem(Log.WARN,
1997 "Unknown element under <preferred-activities>: " + parser.getName());
1998 XmlUtils.skipCurrentTag(parser);
1999 }
2000 }
2001 }
2002
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002003 private int readInt(XmlPullParser parser, String ns, String name, int defValue) {
2004 String v = parser.getAttributeValue(ns, name);
2005 try {
2006 if (v == null) {
2007 return defValue;
2008 }
2009 return Integer.parseInt(v);
2010 } catch (NumberFormatException e) {
2011 PackageManagerService.reportSettingsProblem(Log.WARN,
2012 "Error in package manager settings: attribute " + name
2013 + " has bad integer value " + v + " at "
2014 + parser.getPositionDescription());
2015 }
2016 return defValue;
2017 }
2018
Kenny Root447106f2011-03-23 11:00:15 -07002019 private void readPermissionsLPw(HashMap<String, BasePermission> out, XmlPullParser parser)
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002020 throws IOException, XmlPullParserException {
2021 int outerDepth = parser.getDepth();
2022 int type;
2023 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
2024 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
2025 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2026 continue;
2027 }
2028
Kenny Root447106f2011-03-23 11:00:15 -07002029 final String tagName = parser.getName();
Amith Yamasani483f3b02012-03-13 16:08:00 -07002030 if (tagName.equals(TAG_ITEM)) {
2031 final String name = parser.getAttributeValue(null, ATTR_NAME);
Kenny Root447106f2011-03-23 11:00:15 -07002032 final String sourcePackage = parser.getAttributeValue(null, "package");
2033 final String ptype = parser.getAttributeValue(null, "type");
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002034 if (name != null && sourcePackage != null) {
Kenny Root447106f2011-03-23 11:00:15 -07002035 final boolean dynamic = "dynamic".equals(ptype);
2036 final BasePermission bp = new BasePermission(name, sourcePackage,
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002037 dynamic ? BasePermission.TYPE_DYNAMIC : BasePermission.TYPE_NORMAL);
2038 bp.protectionLevel = readInt(parser, null, "protection",
2039 PermissionInfo.PROTECTION_NORMAL);
Dianne Hackborne639da72012-02-21 15:11:13 -08002040 bp.protectionLevel = PermissionInfo.fixProtectionLevel(bp.protectionLevel);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002041 if (dynamic) {
2042 PermissionInfo pi = new PermissionInfo();
2043 pi.packageName = sourcePackage.intern();
2044 pi.name = name.intern();
2045 pi.icon = readInt(parser, null, "icon", 0);
2046 pi.nonLocalizedLabel = parser.getAttributeValue(null, "label");
2047 pi.protectionLevel = bp.protectionLevel;
2048 bp.pendingInfo = pi;
2049 }
2050 out.put(bp.name, bp);
2051 } else {
2052 PackageManagerService.reportSettingsProblem(Log.WARN,
2053 "Error in package manager settings: permissions has" + " no name at "
2054 + parser.getPositionDescription());
2055 }
2056 } else {
2057 PackageManagerService.reportSettingsProblem(Log.WARN,
2058 "Unknown element reading permissions: " + parser.getName() + " at "
2059 + parser.getPositionDescription());
2060 }
2061 XmlUtils.skipCurrentTag(parser);
2062 }
2063 }
2064
Kenny Root447106f2011-03-23 11:00:15 -07002065 private void readDisabledSysPackageLPw(XmlPullParser parser) throws XmlPullParserException,
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002066 IOException {
Amith Yamasani483f3b02012-03-13 16:08:00 -07002067 String name = parser.getAttributeValue(null, ATTR_NAME);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002068 String realName = parser.getAttributeValue(null, "realName");
2069 String codePathStr = parser.getAttributeValue(null, "codePath");
2070 String resourcePathStr = parser.getAttributeValue(null, "resourcePath");
2071 String nativeLibraryPathStr = parser.getAttributeValue(null, "nativeLibraryPath");
2072 if (resourcePathStr == null) {
2073 resourcePathStr = codePathStr;
2074 }
2075 String version = parser.getAttributeValue(null, "version");
2076 int versionCode = 0;
2077 if (version != null) {
2078 try {
2079 versionCode = Integer.parseInt(version);
2080 } catch (NumberFormatException e) {
2081 }
2082 }
2083
2084 int pkgFlags = 0;
2085 pkgFlags |= ApplicationInfo.FLAG_SYSTEM;
2086 PackageSetting ps = new PackageSetting(name, realName, new File(codePathStr),
2087 new File(resourcePathStr), nativeLibraryPathStr, versionCode, pkgFlags);
2088 String timeStampStr = parser.getAttributeValue(null, "ft");
2089 if (timeStampStr != null) {
2090 try {
2091 long timeStamp = Long.parseLong(timeStampStr, 16);
2092 ps.setTimeStamp(timeStamp);
2093 } catch (NumberFormatException e) {
2094 }
2095 } else {
2096 timeStampStr = parser.getAttributeValue(null, "ts");
2097 if (timeStampStr != null) {
2098 try {
2099 long timeStamp = Long.parseLong(timeStampStr);
2100 ps.setTimeStamp(timeStamp);
2101 } catch (NumberFormatException e) {
2102 }
2103 }
2104 }
2105 timeStampStr = parser.getAttributeValue(null, "it");
2106 if (timeStampStr != null) {
2107 try {
2108 ps.firstInstallTime = Long.parseLong(timeStampStr, 16);
2109 } catch (NumberFormatException e) {
2110 }
2111 }
2112 timeStampStr = parser.getAttributeValue(null, "ut");
2113 if (timeStampStr != null) {
2114 try {
2115 ps.lastUpdateTime = Long.parseLong(timeStampStr, 16);
2116 } catch (NumberFormatException e) {
2117 }
2118 }
2119 String idStr = parser.getAttributeValue(null, "userId");
Amith Yamasani13593602012-03-22 16:16:17 -07002120 ps.appId = idStr != null ? Integer.parseInt(idStr) : 0;
2121 if (ps.appId <= 0) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002122 String sharedIdStr = parser.getAttributeValue(null, "sharedUserId");
Amith Yamasani13593602012-03-22 16:16:17 -07002123 ps.appId = sharedIdStr != null ? Integer.parseInt(sharedIdStr) : 0;
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002124 }
2125 int outerDepth = parser.getDepth();
2126 int type;
2127 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
2128 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
2129 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2130 continue;
2131 }
2132
2133 String tagName = parser.getName();
2134 if (tagName.equals("perms")) {
Kenny Root447106f2011-03-23 11:00:15 -07002135 readGrantedPermissionsLPw(parser, ps.grantedPermissions);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002136 } else {
2137 PackageManagerService.reportSettingsProblem(Log.WARN,
2138 "Unknown element under <updated-package>: " + parser.getName());
2139 XmlUtils.skipCurrentTag(parser);
2140 }
2141 }
2142 mDisabledSysPackages.put(name, ps);
2143 }
2144
Kenny Root447106f2011-03-23 11:00:15 -07002145 private void readPackageLPw(XmlPullParser parser) throws XmlPullParserException, IOException {
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002146 String name = null;
2147 String realName = null;
2148 String idStr = null;
2149 String sharedIdStr = null;
2150 String codePathStr = null;
2151 String resourcePathStr = null;
2152 String nativeLibraryPathStr = null;
2153 String systemStr = null;
2154 String installerPackageName = null;
2155 String uidError = null;
2156 int pkgFlags = 0;
2157 long timeStamp = 0;
2158 long firstInstallTime = 0;
2159 long lastUpdateTime = 0;
2160 PackageSettingBase packageSetting = null;
2161 String version = null;
2162 int versionCode = 0;
2163 try {
Amith Yamasani483f3b02012-03-13 16:08:00 -07002164 name = parser.getAttributeValue(null, ATTR_NAME);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002165 realName = parser.getAttributeValue(null, "realName");
2166 idStr = parser.getAttributeValue(null, "userId");
2167 uidError = parser.getAttributeValue(null, "uidError");
2168 sharedIdStr = parser.getAttributeValue(null, "sharedUserId");
2169 codePathStr = parser.getAttributeValue(null, "codePath");
2170 resourcePathStr = parser.getAttributeValue(null, "resourcePath");
2171 nativeLibraryPathStr = parser.getAttributeValue(null, "nativeLibraryPath");
2172 version = parser.getAttributeValue(null, "version");
2173 if (version != null) {
2174 try {
2175 versionCode = Integer.parseInt(version);
2176 } catch (NumberFormatException e) {
2177 }
2178 }
2179 installerPackageName = parser.getAttributeValue(null, "installer");
2180
2181 systemStr = parser.getAttributeValue(null, "flags");
2182 if (systemStr != null) {
2183 try {
2184 pkgFlags = Integer.parseInt(systemStr);
2185 } catch (NumberFormatException e) {
2186 }
2187 } else {
2188 // For backward compatibility
2189 systemStr = parser.getAttributeValue(null, "system");
2190 if (systemStr != null) {
2191 pkgFlags |= ("true".equalsIgnoreCase(systemStr)) ? ApplicationInfo.FLAG_SYSTEM
2192 : 0;
2193 } else {
2194 // Old settings that don't specify system... just treat
2195 // them as system, good enough.
2196 pkgFlags |= ApplicationInfo.FLAG_SYSTEM;
2197 }
2198 }
2199 String timeStampStr = parser.getAttributeValue(null, "ft");
2200 if (timeStampStr != null) {
2201 try {
2202 timeStamp = Long.parseLong(timeStampStr, 16);
2203 } catch (NumberFormatException e) {
2204 }
2205 } else {
2206 timeStampStr = parser.getAttributeValue(null, "ts");
2207 if (timeStampStr != null) {
2208 try {
2209 timeStamp = Long.parseLong(timeStampStr);
2210 } catch (NumberFormatException e) {
2211 }
2212 }
2213 }
2214 timeStampStr = parser.getAttributeValue(null, "it");
2215 if (timeStampStr != null) {
2216 try {
2217 firstInstallTime = Long.parseLong(timeStampStr, 16);
2218 } catch (NumberFormatException e) {
2219 }
2220 }
2221 timeStampStr = parser.getAttributeValue(null, "ut");
2222 if (timeStampStr != null) {
2223 try {
2224 lastUpdateTime = Long.parseLong(timeStampStr, 16);
2225 } catch (NumberFormatException e) {
2226 }
2227 }
2228 if (PackageManagerService.DEBUG_SETTINGS)
2229 Log.v(PackageManagerService.TAG, "Reading package: " + name + " userId=" + idStr
2230 + " sharedUserId=" + sharedIdStr);
2231 int userId = idStr != null ? Integer.parseInt(idStr) : 0;
2232 if (resourcePathStr == null) {
2233 resourcePathStr = codePathStr;
2234 }
2235 if (realName != null) {
2236 realName = realName.intern();
2237 }
2238 if (name == null) {
2239 PackageManagerService.reportSettingsProblem(Log.WARN,
2240 "Error in package manager settings: <package> has no name at "
2241 + parser.getPositionDescription());
2242 } else if (codePathStr == null) {
2243 PackageManagerService.reportSettingsProblem(Log.WARN,
2244 "Error in package manager settings: <package> has no codePath at "
2245 + parser.getPositionDescription());
2246 } else if (userId > 0) {
Kenny Root447106f2011-03-23 11:00:15 -07002247 packageSetting = addPackageLPw(name.intern(), realName, new File(codePathStr),
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002248 new File(resourcePathStr), nativeLibraryPathStr, userId, versionCode,
2249 pkgFlags);
2250 if (PackageManagerService.DEBUG_SETTINGS)
2251 Log.i(PackageManagerService.TAG, "Reading package " + name + ": userId="
2252 + userId + " pkg=" + packageSetting);
2253 if (packageSetting == null) {
2254 PackageManagerService.reportSettingsProblem(Log.ERROR, "Failure adding uid "
2255 + userId + " while parsing settings at "
2256 + parser.getPositionDescription());
2257 } else {
2258 packageSetting.setTimeStamp(timeStamp);
2259 packageSetting.firstInstallTime = firstInstallTime;
2260 packageSetting.lastUpdateTime = lastUpdateTime;
2261 }
2262 } else if (sharedIdStr != null) {
2263 userId = sharedIdStr != null ? Integer.parseInt(sharedIdStr) : 0;
2264 if (userId > 0) {
2265 packageSetting = new PendingPackage(name.intern(), realName, new File(
2266 codePathStr), new File(resourcePathStr), nativeLibraryPathStr, userId,
2267 versionCode, pkgFlags);
2268 packageSetting.setTimeStamp(timeStamp);
2269 packageSetting.firstInstallTime = firstInstallTime;
2270 packageSetting.lastUpdateTime = lastUpdateTime;
2271 mPendingPackages.add((PendingPackage) packageSetting);
2272 if (PackageManagerService.DEBUG_SETTINGS)
2273 Log.i(PackageManagerService.TAG, "Reading package " + name
2274 + ": sharedUserId=" + userId + " pkg=" + packageSetting);
2275 } else {
2276 PackageManagerService.reportSettingsProblem(Log.WARN,
2277 "Error in package manager settings: package " + name
2278 + " has bad sharedId " + sharedIdStr + " at "
2279 + parser.getPositionDescription());
2280 }
2281 } else {
2282 PackageManagerService.reportSettingsProblem(Log.WARN,
2283 "Error in package manager settings: package " + name + " has bad userId "
2284 + idStr + " at " + parser.getPositionDescription());
2285 }
2286 } catch (NumberFormatException e) {
2287 PackageManagerService.reportSettingsProblem(Log.WARN,
2288 "Error in package manager settings: package " + name + " has bad userId "
2289 + idStr + " at " + parser.getPositionDescription());
2290 }
2291 if (packageSetting != null) {
2292 packageSetting.uidError = "true".equals(uidError);
2293 packageSetting.installerPackageName = installerPackageName;
2294 packageSetting.nativeLibraryPathString = nativeLibraryPathStr;
Amith Yamasani483f3b02012-03-13 16:08:00 -07002295 // Handle legacy string here for single-user mode
2296 final String enabledStr = parser.getAttributeValue(null, ATTR_ENABLED);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002297 if (enabledStr != null) {
Dianne Hackbornb8f40002011-07-19 15:17:43 -07002298 try {
Dianne Hackborn3fa3c28a2013-03-26 16:15:41 -07002299 packageSetting.setEnabled(Integer.parseInt(enabledStr), 0 /* userId */, null);
Dianne Hackbornb8f40002011-07-19 15:17:43 -07002300 } catch (NumberFormatException e) {
2301 if (enabledStr.equalsIgnoreCase("true")) {
Dianne Hackborn3fa3c28a2013-03-26 16:15:41 -07002302 packageSetting.setEnabled(COMPONENT_ENABLED_STATE_ENABLED, 0, null);
Dianne Hackbornb8f40002011-07-19 15:17:43 -07002303 } else if (enabledStr.equalsIgnoreCase("false")) {
Dianne Hackborn3fa3c28a2013-03-26 16:15:41 -07002304 packageSetting.setEnabled(COMPONENT_ENABLED_STATE_DISABLED, 0, null);
Dianne Hackbornb8f40002011-07-19 15:17:43 -07002305 } else if (enabledStr.equalsIgnoreCase("default")) {
Dianne Hackborn3fa3c28a2013-03-26 16:15:41 -07002306 packageSetting.setEnabled(COMPONENT_ENABLED_STATE_DEFAULT, 0, null);
Dianne Hackbornb8f40002011-07-19 15:17:43 -07002307 } else {
2308 PackageManagerService.reportSettingsProblem(Log.WARN,
2309 "Error in package manager settings: package " + name
2310 + " has bad enabled value: " + idStr + " at "
2311 + parser.getPositionDescription());
2312 }
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002313 }
2314 } else {
Dianne Hackborn3fa3c28a2013-03-26 16:15:41 -07002315 packageSetting.setEnabled(COMPONENT_ENABLED_STATE_DEFAULT, 0, null);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002316 }
Amith Yamasani483f3b02012-03-13 16:08:00 -07002317
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002318 final String installStatusStr = parser.getAttributeValue(null, "installStatus");
2319 if (installStatusStr != null) {
2320 if (installStatusStr.equalsIgnoreCase("false")) {
2321 packageSetting.installStatus = PackageSettingBase.PKG_INSTALL_INCOMPLETE;
2322 } else {
2323 packageSetting.installStatus = PackageSettingBase.PKG_INSTALL_COMPLETE;
2324 }
2325 }
2326
2327 int outerDepth = parser.getDepth();
2328 int type;
2329 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
2330 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
2331 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2332 continue;
2333 }
2334
2335 String tagName = parser.getName();
Amith Yamasani483f3b02012-03-13 16:08:00 -07002336 // Legacy
2337 if (tagName.equals(TAG_DISABLED_COMPONENTS)) {
2338 readDisabledComponentsLPw(packageSetting, parser, 0);
2339 } else if (tagName.equals(TAG_ENABLED_COMPONENTS)) {
2340 readEnabledComponentsLPw(packageSetting, parser, 0);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002341 } else if (tagName.equals("sigs")) {
2342 packageSetting.signatures.readXml(parser, mPastSignatures);
2343 } else if (tagName.equals("perms")) {
Kenny Root447106f2011-03-23 11:00:15 -07002344 readGrantedPermissionsLPw(parser, packageSetting.grantedPermissions);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002345 packageSetting.permissionsFixed = true;
Geremy Condraf1bcca82013-01-07 22:35:24 -08002346 } else if (tagName.equals("signing-keyset")) {
2347 long id = Long.parseLong(parser.getAttributeValue(null, "identifier"));
2348 packageSetting.keySetData.addSigningKeySet(id);
Geremy Condrabf7b1f42013-06-18 10:38:27 -07002349 Slog.d(TAG, "Adding signing keyset " + Long.toString(id) + " to " + name);
Geremy Condraf1bcca82013-01-07 22:35:24 -08002350 } else if (tagName.equals("defined-keyset")) {
2351 long id = Long.parseLong(parser.getAttributeValue(null, "identifier"));
2352 String alias = parser.getAttributeValue(null, "alias");
2353 packageSetting.keySetData.addDefinedKeySet(id, alias);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002354 } else {
2355 PackageManagerService.reportSettingsProblem(Log.WARN,
2356 "Unknown element under <package>: " + parser.getName());
2357 XmlUtils.skipCurrentTag(parser);
2358 }
2359 }
Geremy Condraf1bcca82013-01-07 22:35:24 -08002360
2361
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002362 } else {
2363 XmlUtils.skipCurrentTag(parser);
2364 }
2365 }
2366
Amith Yamasani483f3b02012-03-13 16:08:00 -07002367 private void readDisabledComponentsLPw(PackageSettingBase packageSetting, XmlPullParser parser,
2368 int userId) throws IOException, XmlPullParserException {
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002369 int outerDepth = parser.getDepth();
2370 int type;
2371 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
2372 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
2373 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2374 continue;
2375 }
2376
2377 String tagName = parser.getName();
Amith Yamasani483f3b02012-03-13 16:08:00 -07002378 if (tagName.equals(TAG_ITEM)) {
2379 String name = parser.getAttributeValue(null, ATTR_NAME);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002380 if (name != null) {
Amith Yamasani483f3b02012-03-13 16:08:00 -07002381 packageSetting.addDisabledComponent(name.intern(), userId);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002382 } else {
2383 PackageManagerService.reportSettingsProblem(Log.WARN,
2384 "Error in package manager settings: <disabled-components> has"
2385 + " no name at " + parser.getPositionDescription());
2386 }
2387 } else {
2388 PackageManagerService.reportSettingsProblem(Log.WARN,
2389 "Unknown element under <disabled-components>: " + parser.getName());
2390 }
2391 XmlUtils.skipCurrentTag(parser);
2392 }
2393 }
2394
Amith Yamasani483f3b02012-03-13 16:08:00 -07002395 private void readEnabledComponentsLPw(PackageSettingBase packageSetting, XmlPullParser parser,
2396 int userId) throws IOException, XmlPullParserException {
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002397 int outerDepth = parser.getDepth();
2398 int type;
2399 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
2400 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
2401 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2402 continue;
2403 }
2404
2405 String tagName = parser.getName();
Amith Yamasani483f3b02012-03-13 16:08:00 -07002406 if (tagName.equals(TAG_ITEM)) {
2407 String name = parser.getAttributeValue(null, ATTR_NAME);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002408 if (name != null) {
Amith Yamasani483f3b02012-03-13 16:08:00 -07002409 packageSetting.addEnabledComponent(name.intern(), userId);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002410 } else {
2411 PackageManagerService.reportSettingsProblem(Log.WARN,
2412 "Error in package manager settings: <enabled-components> has"
2413 + " no name at " + parser.getPositionDescription());
2414 }
2415 } else {
2416 PackageManagerService.reportSettingsProblem(Log.WARN,
2417 "Unknown element under <enabled-components>: " + parser.getName());
2418 }
2419 XmlUtils.skipCurrentTag(parser);
2420 }
2421 }
2422
Amith Yamasani483f3b02012-03-13 16:08:00 -07002423 private void readSharedUserLPw(XmlPullParser parser) throws XmlPullParserException,IOException {
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002424 String name = null;
2425 String idStr = null;
2426 int pkgFlags = 0;
2427 SharedUserSetting su = null;
2428 try {
Amith Yamasani483f3b02012-03-13 16:08:00 -07002429 name = parser.getAttributeValue(null, ATTR_NAME);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002430 idStr = parser.getAttributeValue(null, "userId");
2431 int userId = idStr != null ? Integer.parseInt(idStr) : 0;
2432 if ("true".equals(parser.getAttributeValue(null, "system"))) {
2433 pkgFlags |= ApplicationInfo.FLAG_SYSTEM;
2434 }
2435 if (name == null) {
2436 PackageManagerService.reportSettingsProblem(Log.WARN,
2437 "Error in package manager settings: <shared-user> has no name at "
2438 + parser.getPositionDescription());
2439 } else if (userId == 0) {
2440 PackageManagerService.reportSettingsProblem(Log.WARN,
2441 "Error in package manager settings: shared-user " + name
2442 + " has bad userId " + idStr + " at "
2443 + parser.getPositionDescription());
2444 } else {
Kenny Root447106f2011-03-23 11:00:15 -07002445 if ((su = addSharedUserLPw(name.intern(), userId, pkgFlags)) == null) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002446 PackageManagerService
2447 .reportSettingsProblem(Log.ERROR, "Occurred while parsing settings at "
2448 + parser.getPositionDescription());
2449 }
2450 }
2451 } catch (NumberFormatException e) {
2452 PackageManagerService.reportSettingsProblem(Log.WARN,
2453 "Error in package manager settings: package " + name + " has bad userId "
2454 + idStr + " at " + parser.getPositionDescription());
2455 }
2456 ;
2457
2458 if (su != null) {
2459 int outerDepth = parser.getDepth();
2460 int type;
2461 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
2462 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
2463 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2464 continue;
2465 }
2466
2467 String tagName = parser.getName();
2468 if (tagName.equals("sigs")) {
2469 su.signatures.readXml(parser, mPastSignatures);
2470 } else if (tagName.equals("perms")) {
Kenny Root447106f2011-03-23 11:00:15 -07002471 readGrantedPermissionsLPw(parser, su.grantedPermissions);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002472 } else {
2473 PackageManagerService.reportSettingsProblem(Log.WARN,
2474 "Unknown element under <shared-user>: " + parser.getName());
2475 XmlUtils.skipCurrentTag(parser);
2476 }
2477 }
2478
2479 } else {
2480 XmlUtils.skipCurrentTag(parser);
2481 }
2482 }
2483
Kenny Root447106f2011-03-23 11:00:15 -07002484 private void readGrantedPermissionsLPw(XmlPullParser parser, HashSet<String> outPerms)
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002485 throws IOException, XmlPullParserException {
2486 int outerDepth = parser.getDepth();
2487 int type;
2488 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
2489 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
2490 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2491 continue;
2492 }
2493
2494 String tagName = parser.getName();
Amith Yamasani483f3b02012-03-13 16:08:00 -07002495 if (tagName.equals(TAG_ITEM)) {
2496 String name = parser.getAttributeValue(null, ATTR_NAME);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002497 if (name != null) {
2498 outPerms.add(name.intern());
2499 } else {
2500 PackageManagerService.reportSettingsProblem(Log.WARN,
2501 "Error in package manager settings: <perms> has" + " no name at "
2502 + parser.getPositionDescription());
2503 }
2504 } else {
2505 PackageManagerService.reportSettingsProblem(Log.WARN,
2506 "Unknown element under <perms>: " + parser.getName());
2507 }
2508 XmlUtils.skipCurrentTag(parser);
2509 }
2510 }
2511
Dianne Hackborn8a2ed1d2013-01-29 15:18:29 -08002512 void createNewUserLILPw(PackageManagerService service, Installer installer,
2513 int userHandle, File path) {
Dianne Hackborn63092712012-10-07 14:45:35 -07002514 path.mkdir();
2515 FileUtils.setPermissions(path.toString(), FileUtils.S_IRWXU | FileUtils.S_IRWXG
2516 | FileUtils.S_IXOTH, -1, -1);
2517 for (PackageSetting ps : mPackages.values()) {
2518 // Only system apps are initially installed.
2519 ps.setInstalled((ps.pkgFlags&ApplicationInfo.FLAG_SYSTEM) != 0, userHandle);
2520 // Need to create a data directory for all apps under this user.
2521 installer.createUserData(ps.name,
Nick Kralevich15069212013-01-09 15:54:56 -08002522 UserHandle.getUid(userHandle, ps.appId), userHandle);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002523 }
Dianne Hackborn8a2ed1d2013-01-29 15:18:29 -08002524 readDefaultPreferredAppsLPw(service, userHandle);
Dianne Hackborn63092712012-10-07 14:45:35 -07002525 writePackageRestrictionsLPr(userHandle);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002526 }
2527
Amith Yamasani13593602012-03-22 16:16:17 -07002528 void removeUserLPr(int userId) {
Dianne Hackborn63092712012-10-07 14:45:35 -07002529 Set<Entry<String, PackageSetting>> entries = mPackages.entrySet();
2530 for (Entry<String, PackageSetting> entry : entries) {
2531 entry.getValue().removeUser(userId);
2532 }
2533 mPreferredActivities.remove(userId);
Amith Yamasani13593602012-03-22 16:16:17 -07002534 File file = getUserPackagesStateFile(userId);
2535 file.delete();
2536 file = getUserPackagesStateBackupFile(userId);
2537 file.delete();
2538 }
2539
Geremy Condra12c18382013-03-06 16:49:06 -08002540 // This should be called (at least) whenever an application is removed
2541 private void setFirstAvailableUid(int uid) {
2542 if (uid > mFirstAvailableUid) {
2543 mFirstAvailableUid = uid;
2544 }
2545 }
2546
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002547 // Returns -1 if we could not find an available UserId to assign
Kenny Root447106f2011-03-23 11:00:15 -07002548 private int newUserIdLPw(Object obj) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002549 // Let's be stupidly inefficient for now...
2550 final int N = mUserIds.size();
Geremy Condra12c18382013-03-06 16:49:06 -08002551 for (int i = mFirstAvailableUid; i < N; i++) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002552 if (mUserIds.get(i) == null) {
2553 mUserIds.set(i, obj);
Dianne Hackborn21fbd1f2012-02-10 10:38:10 -08002554 return Process.FIRST_APPLICATION_UID + i;
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002555 }
2556 }
2557
2558 // None left?
Dianne Hackborn21fbd1f2012-02-10 10:38:10 -08002559 if (N > (Process.LAST_APPLICATION_UID-Process.FIRST_APPLICATION_UID)) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002560 return -1;
2561 }
2562
2563 mUserIds.add(obj);
Dianne Hackborn21fbd1f2012-02-10 10:38:10 -08002564 return Process.FIRST_APPLICATION_UID + N;
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002565 }
2566
Kenny Root0aaa0d92011-09-12 16:42:55 -07002567 public VerifierDeviceIdentity getVerifierDeviceIdentityLPw() {
2568 if (mVerifierDeviceIdentity == null) {
2569 mVerifierDeviceIdentity = VerifierDeviceIdentity.generate();
2570
2571 writeLPr();
2572 }
2573
2574 return mVerifierDeviceIdentity;
2575 }
2576
Kenny Root447106f2011-03-23 11:00:15 -07002577 public PackageSetting getDisabledSystemPkgLPr(String name) {
2578 PackageSetting ps = mDisabledSysPackages.get(name);
2579 return ps;
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002580 }
2581
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002582 private String compToString(HashSet<String> cmp) {
2583 return cmp != null ? Arrays.toString(cmp.toArray()) : "[]";
2584 }
2585
Amith Yamasani483f3b02012-03-13 16:08:00 -07002586 boolean isEnabledLPr(ComponentInfo componentInfo, int flags, int userId) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002587 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
2588 return true;
2589 }
Amith Yamasani483f3b02012-03-13 16:08:00 -07002590 final String pkgName = componentInfo.packageName;
2591 final PackageSetting packageSettings = mPackages.get(pkgName);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002592 if (PackageManagerService.DEBUG_SETTINGS) {
Amith Yamasani483f3b02012-03-13 16:08:00 -07002593 Log.v(PackageManagerService.TAG, "isEnabledLock - packageName = "
2594 + componentInfo.packageName + " componentName = " + componentInfo.name);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002595 Log.v(PackageManagerService.TAG, "enabledComponents: "
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002596 + compToString(packageSettings.getEnabledComponents(userId)));
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002597 Log.v(PackageManagerService.TAG, "disabledComponents: "
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002598 + compToString(packageSettings.getDisabledComponents(userId)));
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002599 }
2600 if (packageSettings == null) {
2601 return false;
2602 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002603 PackageUserState ustate = packageSettings.readUserState(userId);
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08002604 if ((flags&PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS) != 0) {
2605 if (ustate.enabled == COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) {
2606 return true;
2607 }
2608 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002609 if (ustate.enabled == COMPONENT_ENABLED_STATE_DISABLED
2610 || ustate.enabled == COMPONENT_ENABLED_STATE_DISABLED_USER
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08002611 || ustate.enabled == COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002612 || (packageSettings.pkg != null && !packageSettings.pkg.applicationInfo.enabled
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002613 && ustate.enabled == COMPONENT_ENABLED_STATE_DEFAULT)) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002614 return false;
2615 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002616 if (ustate.enabledComponents != null
2617 && ustate.enabledComponents.contains(componentInfo.name)) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002618 return true;
2619 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002620 if (ustate.disabledComponents != null
2621 && ustate.disabledComponents.contains(componentInfo.name)) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002622 return false;
2623 }
2624 return componentInfo.enabled;
2625 }
Kenny Root447106f2011-03-23 11:00:15 -07002626
2627 String getInstallerPackageNameLPr(String packageName) {
2628 final PackageSetting pkg = mPackages.get(packageName);
2629 if (pkg == null) {
2630 throw new IllegalArgumentException("Unknown package: " + packageName);
2631 }
2632 return pkg.installerPackageName;
2633 }
2634
Amith Yamasani483f3b02012-03-13 16:08:00 -07002635 int getApplicationEnabledSettingLPr(String packageName, int userId) {
Kenny Root447106f2011-03-23 11:00:15 -07002636 final PackageSetting pkg = mPackages.get(packageName);
2637 if (pkg == null) {
2638 throw new IllegalArgumentException("Unknown package: " + packageName);
2639 }
Amith Yamasani483f3b02012-03-13 16:08:00 -07002640 return pkg.getEnabled(userId);
Kenny Root447106f2011-03-23 11:00:15 -07002641 }
2642
Amith Yamasani483f3b02012-03-13 16:08:00 -07002643 int getComponentEnabledSettingLPr(ComponentName componentName, int userId) {
Kenny Root447106f2011-03-23 11:00:15 -07002644 final String packageName = componentName.getPackageName();
2645 final PackageSetting pkg = mPackages.get(packageName);
2646 if (pkg == null) {
2647 throw new IllegalArgumentException("Unknown component: " + componentName);
2648 }
2649 final String classNameStr = componentName.getClassName();
Amith Yamasani483f3b02012-03-13 16:08:00 -07002650 return pkg.getCurrentEnabledStateLPr(classNameStr, userId);
Kenny Root447106f2011-03-23 11:00:15 -07002651 }
Amith Yamasani483f3b02012-03-13 16:08:00 -07002652
Kenny Root447106f2011-03-23 11:00:15 -07002653 boolean setPackageStoppedStateLPw(String packageName, boolean stopped,
Amith Yamasani483f3b02012-03-13 16:08:00 -07002654 boolean allowedByPermission, int uid, int userId) {
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07002655 int appId = UserHandle.getAppId(uid);
Kenny Root447106f2011-03-23 11:00:15 -07002656 final PackageSetting pkgSetting = mPackages.get(packageName);
2657 if (pkgSetting == null) {
2658 throw new IllegalArgumentException("Unknown package: " + packageName);
2659 }
Amith Yamasani13593602012-03-22 16:16:17 -07002660 if (!allowedByPermission && (appId != pkgSetting.appId)) {
Kenny Root447106f2011-03-23 11:00:15 -07002661 throw new SecurityException(
2662 "Permission Denial: attempt to change stopped state from pid="
2663 + Binder.getCallingPid()
Amith Yamasani13593602012-03-22 16:16:17 -07002664 + ", uid=" + uid + ", package uid=" + pkgSetting.appId);
Kenny Root447106f2011-03-23 11:00:15 -07002665 }
2666 if (DEBUG_STOPPED) {
2667 if (stopped) {
2668 RuntimeException e = new RuntimeException("here");
2669 e.fillInStackTrace();
2670 Slog.i(TAG, "Stopping package " + packageName, e);
2671 }
2672 }
Amith Yamasani483f3b02012-03-13 16:08:00 -07002673 if (pkgSetting.getStopped(userId) != stopped) {
2674 pkgSetting.setStopped(stopped, userId);
2675 // pkgSetting.pkg.mSetStopped = stopped;
2676 if (pkgSetting.getNotLaunched(userId)) {
Kenny Root447106f2011-03-23 11:00:15 -07002677 if (pkgSetting.installerPackageName != null) {
2678 PackageManagerService.sendPackageBroadcast(Intent.ACTION_PACKAGE_FIRST_LAUNCH,
2679 pkgSetting.name, null,
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002680 pkgSetting.installerPackageName, null, new int[] {userId});
Kenny Root447106f2011-03-23 11:00:15 -07002681 }
Amith Yamasani483f3b02012-03-13 16:08:00 -07002682 pkgSetting.setNotLaunched(false, userId);
Kenny Root447106f2011-03-23 11:00:15 -07002683 }
2684 return true;
2685 }
2686 return false;
2687 }
2688
Amith Yamasani483f3b02012-03-13 16:08:00 -07002689 private List<UserInfo> getAllUsers() {
Amith Yamasani7ea3e7d2012-04-20 15:19:35 -07002690 long id = Binder.clearCallingIdentity();
Amith Yamasani483f3b02012-03-13 16:08:00 -07002691 try {
Amith Yamasani920ace02012-09-20 22:15:37 -07002692 return UserManagerService.getInstance().getUsers(false);
Amith Yamasani483f3b02012-03-13 16:08:00 -07002693 } catch (NullPointerException npe) {
2694 // packagemanager not yet initialized
Amith Yamasani7ea3e7d2012-04-20 15:19:35 -07002695 } finally {
2696 Binder.restoreCallingIdentity(id);
Amith Yamasani483f3b02012-03-13 16:08:00 -07002697 }
2698 return null;
2699 }
2700
Joe Onorato20963df2012-01-04 18:13:24 -08002701 static final void printFlags(PrintWriter pw, int val, Object[] spec) {
2702 pw.print("[ ");
2703 for (int i=0; i<spec.length; i+=2) {
2704 int mask = (Integer)spec[i];
2705 if ((val & mask) != 0) {
2706 pw.print(spec[i+1]);
2707 pw.print(" ");
2708 }
2709 }
2710 pw.print("]");
2711 }
2712
2713 static final Object[] FLAG_DUMP_SPEC = new Object[] {
2714 ApplicationInfo.FLAG_SYSTEM, "SYSTEM",
2715 ApplicationInfo.FLAG_DEBUGGABLE, "DEBUGGABLE",
2716 ApplicationInfo.FLAG_HAS_CODE, "HAS_CODE",
2717 ApplicationInfo.FLAG_PERSISTENT, "PERSISTENT",
2718 ApplicationInfo.FLAG_FACTORY_TEST, "FACTORY_TEST",
2719 ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING, "ALLOW_TASK_REPARENTING",
2720 ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA, "ALLOW_CLEAR_USER_DATA",
2721 ApplicationInfo.FLAG_UPDATED_SYSTEM_APP, "UPDATED_SYSTEM_APP",
2722 ApplicationInfo.FLAG_TEST_ONLY, "TEST_ONLY",
2723 ApplicationInfo.FLAG_VM_SAFE_MODE, "VM_SAFE_MODE",
2724 ApplicationInfo.FLAG_ALLOW_BACKUP, "ALLOW_BACKUP",
2725 ApplicationInfo.FLAG_KILL_AFTER_RESTORE, "KILL_AFTER_RESTORE",
2726 ApplicationInfo.FLAG_RESTORE_ANY_VERSION, "RESTORE_ANY_VERSION",
2727 ApplicationInfo.FLAG_EXTERNAL_STORAGE, "EXTERNAL_STORAGE",
2728 ApplicationInfo.FLAG_LARGE_HEAP, "LARGE_HEAP",
Joe Onorato20963df2012-01-04 18:13:24 -08002729 ApplicationInfo.FLAG_FORWARD_LOCK, "FORWARD_LOCK",
2730 ApplicationInfo.FLAG_CANT_SAVE_STATE, "CANT_SAVE_STATE",
2731 };
2732
Dianne Hackbornc895be72013-03-11 17:48:43 -07002733 void dumpPackageLPr(PrintWriter pw, String prefix, PackageSetting ps, SimpleDateFormat sdf,
2734 Date date, List<UserInfo> users) {
2735 pw.print(prefix); pw.print("Package [");
2736 pw.print(ps.realName != null ? ps.realName : ps.name);
2737 pw.print("] (");
2738 pw.print(Integer.toHexString(System.identityHashCode(ps)));
2739 pw.println("):");
2740
2741 if (ps.realName != null) {
2742 pw.print(prefix); pw.print(" compat name=");
2743 pw.println(ps.name);
2744 }
2745
2746 pw.print(prefix); pw.print(" userId="); pw.print(ps.appId);
2747 pw.print(" gids="); pw.println(PackageManagerService.arrayToString(ps.gids));
2748 if (ps.sharedUser != null) {
2749 pw.print(prefix); pw.print(" sharedUser="); pw.println(ps.sharedUser);
2750 }
2751 pw.print(prefix); pw.print(" pkg="); pw.println(ps.pkg);
2752 pw.print(prefix); pw.print(" codePath="); pw.println(ps.codePathString);
2753 pw.print(prefix); pw.print(" resourcePath="); pw.println(ps.resourcePathString);
2754 pw.print(prefix); pw.print(" nativeLibraryPath="); pw.println(ps.nativeLibraryPathString);
2755 pw.print(prefix); pw.print(" versionCode="); pw.print(ps.versionCode);
2756 if (ps.pkg != null) {
2757 pw.print(" targetSdk="); pw.print(ps.pkg.applicationInfo.targetSdkVersion);
2758 }
2759 pw.println();
2760 if (ps.pkg != null) {
2761 pw.print(prefix); pw.print(" versionName="); pw.println(ps.pkg.mVersionName);
2762 pw.print(prefix); pw.print(" applicationInfo=");
2763 pw.println(ps.pkg.applicationInfo.toString());
2764 pw.print(prefix); pw.print(" flags="); printFlags(pw, ps.pkg.applicationInfo.flags,
2765 FLAG_DUMP_SPEC); pw.println();
2766 pw.print(prefix); pw.print(" dataDir="); pw.println(ps.pkg.applicationInfo.dataDir);
2767 if (ps.pkg.mOperationPending) {
2768 pw.print(prefix); pw.println(" mOperationPending=true");
2769 }
2770 pw.print(prefix); pw.print(" supportsScreens=[");
2771 boolean first = true;
2772 if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS) != 0) {
2773 if (!first)
2774 pw.print(", ");
2775 first = false;
2776 pw.print("small");
2777 }
2778 if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS) != 0) {
2779 if (!first)
2780 pw.print(", ");
2781 first = false;
2782 pw.print("medium");
2783 }
2784 if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS) != 0) {
2785 if (!first)
2786 pw.print(", ");
2787 first = false;
2788 pw.print("large");
2789 }
2790 if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS) != 0) {
2791 if (!first)
2792 pw.print(", ");
2793 first = false;
2794 pw.print("xlarge");
2795 }
2796 if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS) != 0) {
2797 if (!first)
2798 pw.print(", ");
2799 first = false;
2800 pw.print("resizeable");
2801 }
2802 if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES) != 0) {
2803 if (!first)
2804 pw.print(", ");
2805 first = false;
2806 pw.print("anyDensity");
2807 }
2808 pw.println("]");
2809 if (ps.pkg.libraryNames != null && ps.pkg.libraryNames.size() > 0) {
2810 pw.print(prefix); pw.println(" libraries:");
2811 for (int i=0; i<ps.pkg.libraryNames.size(); i++) {
2812 pw.print(prefix); pw.print(" "); pw.println(ps.pkg.libraryNames.get(i));
2813 }
2814 }
2815 if (ps.pkg.usesLibraries != null && ps.pkg.usesLibraries.size() > 0) {
2816 pw.print(prefix); pw.println(" usesLibraries:");
2817 for (int i=0; i<ps.pkg.usesLibraries.size(); i++) {
2818 pw.print(prefix); pw.print(" "); pw.println(ps.pkg.usesLibraries.get(i));
2819 }
2820 }
2821 if (ps.pkg.usesOptionalLibraries != null
2822 && ps.pkg.usesOptionalLibraries.size() > 0) {
2823 pw.print(prefix); pw.println(" usesOptionalLibraries:");
2824 for (int i=0; i<ps.pkg.usesOptionalLibraries.size(); i++) {
2825 pw.print(prefix); pw.print(" ");
2826 pw.println(ps.pkg.usesOptionalLibraries.get(i));
2827 }
2828 }
2829 if (ps.pkg.usesLibraryFiles != null
2830 && ps.pkg.usesLibraryFiles.length > 0) {
2831 pw.print(prefix); pw.println(" usesLibraryFiles:");
2832 for (int i=0; i<ps.pkg.usesLibraryFiles.length; i++) {
2833 pw.print(prefix); pw.print(" "); pw.println(ps.pkg.usesLibraryFiles[i]);
2834 }
2835 }
2836 }
2837 pw.print(prefix); pw.print(" timeStamp=");
2838 date.setTime(ps.timeStamp);
2839 pw.println(sdf.format(date));
2840 pw.print(prefix); pw.print(" firstInstallTime=");
2841 date.setTime(ps.firstInstallTime);
2842 pw.println(sdf.format(date));
2843 pw.print(prefix); pw.print(" lastUpdateTime=");
2844 date.setTime(ps.lastUpdateTime);
2845 pw.println(sdf.format(date));
2846 if (ps.installerPackageName != null) {
2847 pw.print(prefix); pw.print(" installerPackageName=");
2848 pw.println(ps.installerPackageName);
2849 }
2850 pw.print(prefix); pw.print(" signatures="); pw.println(ps.signatures);
2851 pw.print(prefix); pw.print(" permissionsFixed="); pw.print(ps.permissionsFixed);
2852 pw.print(" haveGids="); pw.print(ps.haveGids);
2853 pw.print(" installStatus="); pw.println(ps.installStatus);
2854 pw.print(prefix); pw.print(" pkgFlags="); printFlags(pw, ps.pkgFlags, FLAG_DUMP_SPEC);
2855 pw.println();
2856 for (UserInfo user : users) {
2857 pw.print(prefix); pw.print(" User "); pw.print(user.id); pw.print(": ");
2858 pw.print(" installed=");
2859 pw.print(ps.getInstalled(user.id));
Amith Yamasani655d0e22013-06-12 14:19:10 -07002860 pw.print(" blocked=");
2861 pw.print(ps.getBlocked(user.id));
Dianne Hackbornc895be72013-03-11 17:48:43 -07002862 pw.print(" stopped=");
2863 pw.print(ps.getStopped(user.id));
2864 pw.print(" notLaunched=");
2865 pw.print(ps.getNotLaunched(user.id));
2866 pw.print(" enabled=");
2867 pw.println(ps.getEnabled(user.id));
Dianne Hackborn3fa3c28a2013-03-26 16:15:41 -07002868 String lastDisabledAppCaller = ps.getLastDisabledAppCaller(user.id);
2869 if (lastDisabledAppCaller != null) {
2870 pw.print(prefix); pw.print(" lastDisabledCaller: ");
2871 pw.println(lastDisabledAppCaller);
2872 }
Dianne Hackbornc895be72013-03-11 17:48:43 -07002873 HashSet<String> cmp = ps.getDisabledComponents(user.id);
2874 if (cmp != null && cmp.size() > 0) {
2875 pw.print(prefix); pw.println(" disabledComponents:");
2876 for (String s : cmp) {
2877 pw.print(prefix); pw.print(" "); pw.println(s);
2878 }
2879 }
2880 cmp = ps.getEnabledComponents(user.id);
2881 if (cmp != null && cmp.size() > 0) {
2882 pw.print(prefix); pw.println(" enabledComponents:");
2883 for (String s : cmp) {
2884 pw.print(prefix); pw.print(" "); pw.println(s);
2885 }
2886 }
2887 }
2888 if (ps.grantedPermissions.size() > 0) {
2889 pw.print(prefix); pw.println(" grantedPermissions:");
2890 for (String s : ps.grantedPermissions) {
2891 pw.print(prefix); pw.print(" "); pw.println(s);
2892 }
2893 }
2894 }
2895
Kenny Root447106f2011-03-23 11:00:15 -07002896 void dumpPackagesLPr(PrintWriter pw, String packageName, DumpState dumpState) {
2897 final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
2898 final Date date = new Date();
2899 boolean printedSomething = false;
Amith Yamasani7ea3e7d2012-04-20 15:19:35 -07002900 List<UserInfo> users = getAllUsers();
Kenny Root447106f2011-03-23 11:00:15 -07002901 for (final PackageSetting ps : mPackages.values()) {
2902 if (packageName != null && !packageName.equals(ps.realName)
2903 && !packageName.equals(ps.name)) {
2904 continue;
2905 }
2906
2907 if (packageName != null) {
2908 dumpState.setSharedUser(ps.sharedUser);
2909 }
2910
2911 if (!printedSomething) {
2912 if (dumpState.onTitlePrinted())
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07002913 pw.println();
Kenny Root447106f2011-03-23 11:00:15 -07002914 pw.println("Packages:");
2915 printedSomething = true;
2916 }
Dianne Hackbornc895be72013-03-11 17:48:43 -07002917 dumpPackageLPr(pw, " ", ps, sdf, date, users);
Kenny Root447106f2011-03-23 11:00:15 -07002918 }
2919
2920 printedSomething = false;
2921 if (mRenamedPackages.size() > 0) {
Andy McFadden2f362292012-01-20 14:43:38 -08002922 for (final Map.Entry<String, String> e : mRenamedPackages.entrySet()) {
Kenny Root447106f2011-03-23 11:00:15 -07002923 if (packageName != null && !packageName.equals(e.getKey())
2924 && !packageName.equals(e.getValue())) {
2925 continue;
2926 }
2927 if (!printedSomething) {
2928 if (dumpState.onTitlePrinted())
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07002929 pw.println();
Kenny Root447106f2011-03-23 11:00:15 -07002930 pw.println("Renamed packages:");
2931 printedSomething = true;
2932 }
2933 pw.print(" ");
2934 pw.print(e.getKey());
2935 pw.print(" -> ");
2936 pw.println(e.getValue());
2937 }
2938 }
2939
2940 printedSomething = false;
2941 if (mDisabledSysPackages.size() > 0) {
2942 for (final PackageSetting ps : mDisabledSysPackages.values()) {
2943 if (packageName != null && !packageName.equals(ps.realName)
2944 && !packageName.equals(ps.name)) {
2945 continue;
2946 }
2947 if (!printedSomething) {
2948 if (dumpState.onTitlePrinted())
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07002949 pw.println();
Kenny Root447106f2011-03-23 11:00:15 -07002950 pw.println("Hidden system packages:");
2951 printedSomething = true;
2952 }
Dianne Hackbornc895be72013-03-11 17:48:43 -07002953 dumpPackageLPr(pw, " ", ps, sdf, date, users);
Kenny Root447106f2011-03-23 11:00:15 -07002954 }
2955 }
2956 }
Amith Yamasani483f3b02012-03-13 16:08:00 -07002957
Kenny Root447106f2011-03-23 11:00:15 -07002958 void dumpPermissionsLPr(PrintWriter pw, String packageName, DumpState dumpState) {
2959 boolean printedSomething = false;
2960 for (BasePermission p : mPermissions.values()) {
2961 if (packageName != null && !packageName.equals(p.sourcePackage)) {
2962 continue;
2963 }
2964 if (!printedSomething) {
2965 if (dumpState.onTitlePrinted())
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07002966 pw.println();
Kenny Root447106f2011-03-23 11:00:15 -07002967 pw.println("Permissions:");
2968 printedSomething = true;
2969 }
2970 pw.print(" Permission ["); pw.print(p.name); pw.print("] (");
2971 pw.print(Integer.toHexString(System.identityHashCode(p)));
2972 pw.println("):");
2973 pw.print(" sourcePackage="); pw.println(p.sourcePackage);
2974 pw.print(" uid="); pw.print(p.uid);
2975 pw.print(" gids="); pw.print(PackageManagerService.arrayToString(p.gids));
2976 pw.print(" type="); pw.print(p.type);
Dianne Hackborne639da72012-02-21 15:11:13 -08002977 pw.print(" prot=");
2978 pw.println(PermissionInfo.protectionToString(p.protectionLevel));
Kenny Root447106f2011-03-23 11:00:15 -07002979 if (p.packageSetting != null) {
2980 pw.print(" packageSetting="); pw.println(p.packageSetting);
2981 }
2982 if (p.perm != null) {
2983 pw.print(" perm="); pw.println(p.perm);
2984 }
Jeff Sharkey1c27576a2012-04-11 19:07:08 -07002985 if (READ_EXTERNAL_STORAGE.equals(p.name)) {
Jeff Sharkey5d32e772012-04-12 15:59:23 -07002986 pw.print(" enforced=");
2987 pw.println(mReadExternalStorageEnforced);
Jeff Sharkey1c27576a2012-04-11 19:07:08 -07002988 }
Kenny Root447106f2011-03-23 11:00:15 -07002989 }
2990 }
Jeff Sharkey1c27576a2012-04-11 19:07:08 -07002991
Kenny Root447106f2011-03-23 11:00:15 -07002992 void dumpSharedUsersLPr(PrintWriter pw, String packageName, DumpState dumpState) {
2993 boolean printedSomething = false;
2994 for (SharedUserSetting su : mSharedUsers.values()) {
2995 if (packageName != null && su != dumpState.getSharedUser()) {
2996 continue;
2997 }
2998 if (!printedSomething) {
2999 if (dumpState.onTitlePrinted())
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003000 pw.println();
Kenny Root447106f2011-03-23 11:00:15 -07003001 pw.println("Shared users:");
3002 printedSomething = true;
3003 }
3004 pw.print(" SharedUser [");
3005 pw.print(su.name);
3006 pw.print("] (");
3007 pw.print(Integer.toHexString(System.identityHashCode(su)));
3008 pw.println("):");
3009 pw.print(" userId=");
3010 pw.print(su.userId);
3011 pw.print(" gids=");
3012 pw.println(PackageManagerService.arrayToString(su.gids));
3013 pw.println(" grantedPermissions:");
3014 for (String s : su.grantedPermissions) {
3015 pw.print(" ");
3016 pw.println(s);
3017 }
3018 }
3019 }
3020
3021 void dumpReadMessagesLPr(PrintWriter pw, DumpState dumpState) {
3022 pw.println("Settings parse messages:");
3023 pw.print(mReadMessages.toString());
3024 }
Andy McFadden2f362292012-01-20 14:43:38 -08003025}