blob: 2720bf8609b249c0c4e9952f9de0f77beb8f9139 [file] [log] [blame]
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.pm;
18
19import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
20import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
21import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
22
23import com.android.internal.util.FastXmlSerializer;
24import com.android.internal.util.JournaledFile;
25import com.android.internal.util.XmlUtils;
26import com.android.server.IntentResolver;
Kenny Root447106f2011-03-23 11:00:15 -070027import com.android.server.pm.PackageManagerService.DumpState;
Kenny Rootcf0b38c2011-03-22 14:17:59 -070028
29import org.xmlpull.v1.XmlPullParser;
30import org.xmlpull.v1.XmlPullParserException;
31import org.xmlpull.v1.XmlSerializer;
32
Kenny Root447106f2011-03-23 11:00:15 -070033import android.content.ComponentName;
34import android.content.Intent;
Kenny Rootcf0b38c2011-03-22 14:17:59 -070035import android.content.pm.ApplicationInfo;
36import android.content.pm.ComponentInfo;
37import android.content.pm.PackageManager;
38import android.content.pm.PackageParser;
39import android.content.pm.PermissionInfo;
40import android.content.pm.Signature;
Kenny Root447106f2011-03-23 11:00:15 -070041import android.os.Binder;
Kenny Rootcf0b38c2011-03-22 14:17:59 -070042import android.os.Environment;
43import android.os.FileUtils;
44import android.os.Process;
45import android.util.Log;
46import android.util.Slog;
47import android.util.SparseArray;
48import android.util.Xml;
49
50import java.io.BufferedOutputStream;
51import java.io.File;
52import java.io.FileInputStream;
53import java.io.FileOutputStream;
54import java.io.IOException;
55import java.io.PrintWriter;
Kenny Root447106f2011-03-23 11:00:15 -070056import java.text.SimpleDateFormat;
Kenny Rootcf0b38c2011-03-22 14:17:59 -070057import java.util.ArrayList;
58import java.util.Arrays;
Kenny Root447106f2011-03-23 11:00:15 -070059import java.util.Date;
Kenny Rootcf0b38c2011-03-22 14:17:59 -070060import java.util.HashMap;
61import java.util.HashSet;
62import java.util.Iterator;
63
64/**
65 * Holds information about dynamic settings.
66 */
67final class Settings {
Kenny Root447106f2011-03-23 11:00:15 -070068 private static final String TAG = "PackageSettings";
69
70 private static final boolean DEBUG_STOPPED = false;
71
Kenny Rootcf0b38c2011-03-22 14:17:59 -070072 private final File mSettingsFilename;
73 private final File mBackupSettingsFilename;
74 private final File mPackageListFilename;
75 private final File mStoppedPackagesFilename;
76 private final File mBackupStoppedPackagesFilename;
77 final HashMap<String, PackageSetting> mPackages =
78 new HashMap<String, PackageSetting>();
79 // List of replaced system applications
80 final HashMap<String, PackageSetting> mDisabledSysPackages =
81 new HashMap<String, PackageSetting>();
82
83 // These are the last platform API version we were using for
84 // the apps installed on internal and external storage. It is
85 // used to grant newer permissions one time during a system upgrade.
86 int mInternalSdkPlatform;
87 int mExternalSdkPlatform;
88
89 // The user's preferred activities associated with particular intent
90 // filters.
91 final IntentResolver<PreferredActivity, PreferredActivity> mPreferredActivities =
92 new IntentResolver<PreferredActivity, PreferredActivity>() {
93 @Override
94 protected String packageForFilter(PreferredActivity filter) {
95 return filter.mPref.mComponent.getPackageName();
96 }
97 @Override
98 protected void dumpFilter(PrintWriter out, String prefix,
99 PreferredActivity filter) {
100 filter.mPref.dump(out, prefix, filter);
101 }
102 };
103 final HashMap<String, SharedUserSetting> mSharedUsers =
104 new HashMap<String, SharedUserSetting>();
105 private final ArrayList<Object> mUserIds = new ArrayList<Object>();
106 private final SparseArray<Object> mOtherUserIds =
107 new SparseArray<Object>();
108
109 // For reading/writing settings file.
110 private final ArrayList<Signature> mPastSignatures =
111 new ArrayList<Signature>();
112
113 // Mapping from permission names to info about them.
114 final HashMap<String, BasePermission> mPermissions =
115 new HashMap<String, BasePermission>();
116
117 // Mapping from permission tree names to info about them.
118 final HashMap<String, BasePermission> mPermissionTrees =
119 new HashMap<String, BasePermission>();
120
121 // Packages that have been uninstalled and still need their external
122 // storage data deleted.
123 final ArrayList<String> mPackagesToBeCleaned = new ArrayList<String>();
124
125 // Packages that have been renamed since they were first installed.
126 // Keys are the new names of the packages, values are the original
127 // names. The packages appear everwhere else under their original
128 // names.
129 final HashMap<String, String> mRenamedPackages = new HashMap<String, String>();
130
131 final StringBuilder mReadMessages = new StringBuilder();
132
Kenny Root447106f2011-03-23 11:00:15 -0700133 /**
134 * Used to track packages that have a shared user ID that hasn't been read
135 * in yet.
136 * <p>
137 * TODO: make this just a local variable that is passed in during package
138 * scanning to make it less confusing.
139 */
140 private final ArrayList<PendingPackage> mPendingPackages = new ArrayList<PendingPackage>();
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700141
142 Settings() {
143 File dataDir = Environment.getDataDirectory();
144 File systemDir = new File(dataDir, "system");
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700145 systemDir.mkdirs();
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700146 FileUtils.setPermissions(systemDir.toString(),
147 FileUtils.S_IRWXU|FileUtils.S_IRWXG
148 |FileUtils.S_IROTH|FileUtils.S_IXOTH,
149 -1, -1);
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700150 mSettingsFilename = new File(systemDir, "packages.xml");
151 mBackupSettingsFilename = new File(systemDir, "packages-backup.xml");
152 mPackageListFilename = new File(systemDir, "packages.list");
153 mStoppedPackagesFilename = new File(systemDir, "packages-stopped.xml");
154 mBackupStoppedPackagesFilename = new File(systemDir, "packages-stopped-backup.xml");
155 }
156
Kenny Root447106f2011-03-23 11:00:15 -0700157 PackageSetting getPackageLPw(PackageParser.Package pkg, PackageSetting origPackage,
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700158 String realName, SharedUserSetting sharedUser, File codePath, File resourcePath,
159 String nativeLibraryPathString, int pkgFlags, boolean create, boolean add) {
160 final String name = pkg.packageName;
Kenny Root447106f2011-03-23 11:00:15 -0700161 PackageSetting p = getPackageLPw(name, origPackage, realName, sharedUser, codePath,
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700162 resourcePath, nativeLibraryPathString, pkg.mVersionCode, pkgFlags, create, add);
163 return p;
164 }
165
Kenny Root447106f2011-03-23 11:00:15 -0700166 PackageSetting peekPackageLPr(String name) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700167 return mPackages.get(name);
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700168 }
169
170 void setInstallStatus(String pkgName, int status) {
171 PackageSetting p = mPackages.get(pkgName);
172 if(p != null) {
173 if(p.getInstallStatus() != status) {
174 p.setInstallStatus(status);
175 }
176 }
177 }
178
179 void setInstallerPackageName(String pkgName,
180 String installerPkgName) {
181 PackageSetting p = mPackages.get(pkgName);
182 if(p != null) {
183 p.setInstallerPackageName(installerPkgName);
184 }
185 }
186
Kenny Root447106f2011-03-23 11:00:15 -0700187 SharedUserSetting getSharedUserLPw(String name,
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700188 int pkgFlags, boolean create) {
189 SharedUserSetting s = mSharedUsers.get(name);
190 if (s == null) {
191 if (!create) {
192 return null;
193 }
194 s = new SharedUserSetting(name, pkgFlags);
195 if (PackageManagerService.MULTIPLE_APPLICATION_UIDS) {
Kenny Root447106f2011-03-23 11:00:15 -0700196 s.userId = newUserIdLPw(s);
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700197 } else {
198 s.userId = PackageManagerService.FIRST_APPLICATION_UID;
199 }
200 Log.i(PackageManagerService.TAG, "New shared user " + name + ": id=" + s.userId);
201 // < 0 means we couldn't assign a userid; fall out and return
202 // s, which is currently null
203 if (s.userId >= 0) {
204 mSharedUsers.put(name, s);
205 }
206 }
207
208 return s;
209 }
210
Kenny Root447106f2011-03-23 11:00:15 -0700211 boolean disableSystemPackageLPw(String name) {
212 final PackageSetting p = mPackages.get(name);
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700213 if(p == null) {
214 Log.w(PackageManagerService.TAG, "Package:"+name+" is not an installed package");
215 return false;
216 }
Kenny Root447106f2011-03-23 11:00:15 -0700217 final PackageSetting dp = mDisabledSysPackages.get(name);
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700218 // always make sure the system package code and resource paths dont change
219 if (dp == null) {
220 if((p.pkg != null) && (p.pkg.applicationInfo != null)) {
221 p.pkg.applicationInfo.flags |= ApplicationInfo.FLAG_UPDATED_SYSTEM_APP;
222 }
223 mDisabledSysPackages.put(name, p);
224
225 // a little trick... when we install the new package, we don't
226 // want to modify the existing PackageSetting for the built-in
227 // version. so at this point we need a new PackageSetting that
228 // is okay to muck with.
229 PackageSetting newp = new PackageSetting(p);
Kenny Root447106f2011-03-23 11:00:15 -0700230 replacePackageLPw(name, newp);
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700231 return true;
232 }
233 return false;
234 }
235
Kenny Root447106f2011-03-23 11:00:15 -0700236 PackageSetting enableSystemPackageLPw(String name) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700237 PackageSetting p = mDisabledSysPackages.get(name);
238 if(p == null) {
239 Log.w(PackageManagerService.TAG, "Package:"+name+" is not disabled");
240 return null;
241 }
242 // Reset flag in ApplicationInfo object
243 if((p.pkg != null) && (p.pkg.applicationInfo != null)) {
244 p.pkg.applicationInfo.flags &= ~ApplicationInfo.FLAG_UPDATED_SYSTEM_APP;
245 }
Kenny Root447106f2011-03-23 11:00:15 -0700246 PackageSetting ret = addPackageLPw(name, p.realName, p.codePath, p.resourcePath,
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700247 p.nativeLibraryPathString, p.userId, p.versionCode, p.pkgFlags);
248 mDisabledSysPackages.remove(name);
249 return ret;
250 }
251
Kenny Root447106f2011-03-23 11:00:15 -0700252 PackageSetting addPackageLPw(String name, String realName, File codePath, File resourcePath,
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700253 String nativeLibraryPathString, int uid, int vc, int pkgFlags) {
254 PackageSetting p = mPackages.get(name);
255 if (p != null) {
256 if (p.userId == uid) {
257 return p;
258 }
259 PackageManagerService.reportSettingsProblem(Log.ERROR,
260 "Adding duplicate package, keeping first: " + name);
261 return null;
262 }
263 p = new PackageSetting(name, realName, codePath, resourcePath, nativeLibraryPathString,
264 vc, pkgFlags);
265 p.userId = uid;
Kenny Root447106f2011-03-23 11:00:15 -0700266 if (addUserIdLPw(uid, p, name)) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700267 mPackages.put(name, p);
268 return p;
269 }
270 return null;
271 }
272
Kenny Root447106f2011-03-23 11:00:15 -0700273 SharedUserSetting addSharedUserLPw(String name, int uid, int pkgFlags) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700274 SharedUserSetting s = mSharedUsers.get(name);
275 if (s != null) {
276 if (s.userId == uid) {
277 return s;
278 }
279 PackageManagerService.reportSettingsProblem(Log.ERROR,
280 "Adding duplicate shared user, keeping first: " + name);
281 return null;
282 }
283 s = new SharedUserSetting(name, pkgFlags);
284 s.userId = uid;
Kenny Root447106f2011-03-23 11:00:15 -0700285 if (addUserIdLPw(uid, s, name)) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700286 mSharedUsers.put(name, s);
287 return s;
288 }
289 return null;
290 }
291
292 // Transfer ownership of permissions from one package to another.
Kenny Root447106f2011-03-23 11:00:15 -0700293 void transferPermissionsLPw(String origPkg, String newPkg) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700294 // Transfer ownership of permissions to the new package.
295 for (int i=0; i<2; i++) {
296 HashMap<String, BasePermission> permissions =
297 i == 0 ? mPermissionTrees : mPermissions;
298 for (BasePermission bp : permissions.values()) {
299 if (origPkg.equals(bp.sourcePackage)) {
300 if (PackageManagerService.DEBUG_UPGRADE) Log.v(PackageManagerService.TAG,
301 "Moving permission " + bp.name
302 + " from pkg " + bp.sourcePackage
303 + " to " + newPkg);
304 bp.sourcePackage = newPkg;
305 bp.packageSetting = null;
306 bp.perm = null;
307 if (bp.pendingInfo != null) {
308 bp.pendingInfo.packageName = newPkg;
309 }
310 bp.uid = 0;
311 bp.gids = null;
312 }
313 }
314 }
315 }
316
Kenny Root447106f2011-03-23 11:00:15 -0700317 private PackageSetting getPackageLPw(String name, PackageSetting origPackage,
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700318 String realName, SharedUserSetting sharedUser, File codePath, File resourcePath,
319 String nativeLibraryPathString, int vc, int pkgFlags, boolean create, boolean add) {
320 PackageSetting p = mPackages.get(name);
321 if (p != null) {
322 if (!p.codePath.equals(codePath)) {
323 // Check to see if its a disabled system app
324 if ((p.pkgFlags & ApplicationInfo.FLAG_SYSTEM) != 0) {
325 // This is an updated system app with versions in both system
326 // and data partition. Just let the most recent version
327 // take precedence.
328 Slog.w(PackageManagerService.TAG, "Trying to update system app code path from " +
329 p.codePathString + " to " + codePath.toString());
330 } else {
331 // Just a change in the code path is not an issue, but
332 // let's log a message about it.
333 Slog.i(PackageManagerService.TAG, "Package " + name + " codePath changed from " + p.codePath
334 + " to " + codePath + "; Retaining data and using new");
335 /*
336 * Since we've changed paths, we need to prefer the new
337 * native library path over the one stored in the
338 * package settings since we might have moved from
339 * internal to external storage or vice versa.
340 */
341 p.nativeLibraryPathString = nativeLibraryPathString;
342 }
343 }
344 if (p.sharedUser != sharedUser) {
345 PackageManagerService.reportSettingsProblem(Log.WARN,
346 "Package " + name + " shared user changed from "
347 + (p.sharedUser != null ? p.sharedUser.name : "<nothing>")
348 + " to "
349 + (sharedUser != null ? sharedUser.name : "<nothing>")
350 + "; replacing with new");
351 p = null;
352 } else {
353 if ((pkgFlags&ApplicationInfo.FLAG_SYSTEM) != 0) {
354 // If what we are scanning is a system package, then
355 // make it so, regardless of whether it was previously
356 // installed only in the data partition.
357 p.pkgFlags |= ApplicationInfo.FLAG_SYSTEM;
358 }
359 }
360 }
361 if (p == null) {
362 // Create a new PackageSettings entry. this can end up here because
363 // of code path mismatch or user id mismatch of an updated system partition
364 if (!create) {
365 return null;
366 }
367 if (origPackage != null) {
368 // We are consuming the data from an existing package.
369 p = new PackageSetting(origPackage.name, name, codePath, resourcePath,
370 nativeLibraryPathString, vc, pkgFlags);
371 if (PackageManagerService.DEBUG_UPGRADE) Log.v(PackageManagerService.TAG, "Package " + name
372 + " is adopting original package " + origPackage.name);
373 // Note that we will retain the new package's signature so
374 // that we can keep its data.
375 PackageSignatures s = p.signatures;
376 p.copyFrom(origPackage);
377 p.signatures = s;
378 p.sharedUser = origPackage.sharedUser;
379 p.userId = origPackage.userId;
380 p.origPackage = origPackage;
381 mRenamedPackages.put(name, origPackage.name);
382 name = origPackage.name;
383 // Update new package state.
384 p.setTimeStamp(codePath.lastModified());
385 } else {
386 p = new PackageSetting(name, realName, codePath, resourcePath,
387 nativeLibraryPathString, vc, pkgFlags);
388 p.setTimeStamp(codePath.lastModified());
389 p.sharedUser = sharedUser;
390 // If this is not a system app, it starts out stopped.
391 if ((pkgFlags&ApplicationInfo.FLAG_SYSTEM) == 0) {
Kenny Root447106f2011-03-23 11:00:15 -0700392 if (DEBUG_STOPPED) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700393 RuntimeException e = new RuntimeException("here");
394 e.fillInStackTrace();
395 Slog.i(PackageManagerService.TAG, "Stopping package " + name, e);
396 }
397 p.stopped = true;
398 p.notLaunched = true;
399 }
400 if (sharedUser != null) {
401 p.userId = sharedUser.userId;
402 } else if (PackageManagerService.MULTIPLE_APPLICATION_UIDS) {
403 // Clone the setting here for disabled system packages
404 PackageSetting dis = mDisabledSysPackages.get(name);
405 if (dis != null) {
406 // For disabled packages a new setting is created
407 // from the existing user id. This still has to be
408 // added to list of user id's
409 // Copy signatures from previous setting
410 if (dis.signatures.mSignatures != null) {
411 p.signatures.mSignatures = dis.signatures.mSignatures.clone();
412 }
413 p.userId = dis.userId;
414 // Clone permissions
415 p.grantedPermissions = new HashSet<String>(dis.grantedPermissions);
416 // Clone component info
417 p.disabledComponents = new HashSet<String>(dis.disabledComponents);
418 p.enabledComponents = new HashSet<String>(dis.enabledComponents);
419 // Add new setting to list of user ids
Kenny Root447106f2011-03-23 11:00:15 -0700420 addUserIdLPw(p.userId, p, name);
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700421 } else {
422 // Assign new user id
Kenny Root447106f2011-03-23 11:00:15 -0700423 p.userId = newUserIdLPw(p);
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700424 }
425 } else {
426 p.userId = PackageManagerService.FIRST_APPLICATION_UID;
427 }
428 }
429 if (p.userId < 0) {
430 PackageManagerService.reportSettingsProblem(Log.WARN,
431 "Package " + name + " could not be assigned a valid uid");
432 return null;
433 }
434 if (add) {
435 // Finish adding new package by adding it and updating shared
436 // user preferences
Kenny Root447106f2011-03-23 11:00:15 -0700437 addPackageSettingLPw(p, name, sharedUser);
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700438 }
439 }
440 return p;
441 }
442
Kenny Root447106f2011-03-23 11:00:15 -0700443 void insertPackageSettingLPw(PackageSetting p, PackageParser.Package pkg) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700444 p.pkg = pkg;
445 pkg.mSetEnabled = p.enabled;
446 pkg.mSetStopped = p.stopped;
447 final String codePath = pkg.applicationInfo.sourceDir;
448 final String resourcePath = pkg.applicationInfo.publicSourceDir;
449 // Update code path if needed
450 if (!codePath.equalsIgnoreCase(p.codePathString)) {
451 Slog.w(PackageManagerService.TAG, "Code path for pkg : " + p.pkg.packageName +
452 " changing from " + p.codePathString + " to " + codePath);
453 p.codePath = new File(codePath);
454 p.codePathString = codePath;
455 }
456 //Update resource path if needed
457 if (!resourcePath.equalsIgnoreCase(p.resourcePathString)) {
458 Slog.w(PackageManagerService.TAG, "Resource path for pkg : " + p.pkg.packageName +
459 " changing from " + p.resourcePathString + " to " + resourcePath);
460 p.resourcePath = new File(resourcePath);
461 p.resourcePathString = resourcePath;
462 }
463 // Update the native library path if needed
464 final String nativeLibraryPath = pkg.applicationInfo.nativeLibraryDir;
465 if (nativeLibraryPath != null
466 && !nativeLibraryPath.equalsIgnoreCase(p.nativeLibraryPathString)) {
467 p.nativeLibraryPathString = nativeLibraryPath;
468 }
469 // Update version code if needed
470 if (pkg.mVersionCode != p.versionCode) {
471 p.versionCode = pkg.mVersionCode;
472 }
473 // Update signatures if needed.
474 if (p.signatures.mSignatures == null) {
475 p.signatures.assignSignatures(pkg.mSignatures);
476 }
477 // If this app defines a shared user id initialize
478 // the shared user signatures as well.
479 if (p.sharedUser != null && p.sharedUser.signatures.mSignatures == null) {
480 p.sharedUser.signatures.assignSignatures(pkg.mSignatures);
481 }
Kenny Root447106f2011-03-23 11:00:15 -0700482 addPackageSettingLPw(p, pkg.packageName, p.sharedUser);
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700483 }
484
485 // Utility method that adds a PackageSetting to mPackages and
486 // completes updating the shared user attributes
Kenny Root447106f2011-03-23 11:00:15 -0700487 private void addPackageSettingLPw(PackageSetting p, String name,
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700488 SharedUserSetting sharedUser) {
489 mPackages.put(name, p);
490 if (sharedUser != null) {
491 if (p.sharedUser != null && p.sharedUser != sharedUser) {
492 PackageManagerService.reportSettingsProblem(Log.ERROR,
493 "Package " + p.name + " was user "
494 + p.sharedUser + " but is now " + sharedUser
495 + "; I am not changing its files so it will probably fail!");
496 p.sharedUser.packages.remove(p);
497 } else if (p.userId != sharedUser.userId) {
498 PackageManagerService.reportSettingsProblem(Log.ERROR,
499 "Package " + p.name + " was user id " + p.userId
500 + " but is now user " + sharedUser
501 + " with id " + sharedUser.userId
502 + "; I am not changing its files so it will probably fail!");
503 }
504
505 sharedUser.packages.add(p);
506 p.sharedUser = sharedUser;
507 p.userId = sharedUser.userId;
508 }
509 }
510
511 /*
512 * Update the shared user setting when a package using
513 * specifying the shared user id is removed. The gids
514 * associated with each permission of the deleted package
515 * are removed from the shared user's gid list only if its
516 * not in use by other permissions of packages in the
517 * shared user setting.
518 */
Kenny Root447106f2011-03-23 11:00:15 -0700519 void updateSharedUserPermsLPw(PackageSetting deletedPs, int[] globalGids) {
520 if ((deletedPs == null) || (deletedPs.pkg == null)) {
521 Slog.i(PackageManagerService.TAG,
522 "Trying to update info for null package. Just ignoring");
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700523 return;
524 }
525 // No sharedUserId
526 if (deletedPs.sharedUser == null) {
527 return;
528 }
529 SharedUserSetting sus = deletedPs.sharedUser;
530 // Update permissions
Kenny Root447106f2011-03-23 11:00:15 -0700531 for (String eachPerm : deletedPs.pkg.requestedPermissions) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700532 boolean used = false;
Kenny Root447106f2011-03-23 11:00:15 -0700533 if (!sus.grantedPermissions.contains(eachPerm)) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700534 continue;
535 }
536 for (PackageSetting pkg:sus.packages) {
537 if (pkg.pkg != null &&
538 !pkg.pkg.packageName.equals(deletedPs.pkg.packageName) &&
539 pkg.pkg.requestedPermissions.contains(eachPerm)) {
540 used = true;
541 break;
542 }
543 }
544 if (!used) {
545 // can safely delete this permission from list
546 sus.grantedPermissions.remove(eachPerm);
547 }
548 }
549 // Update gids
550 int newGids[] = globalGids;
551 for (String eachPerm : sus.grantedPermissions) {
552 BasePermission bp = mPermissions.get(eachPerm);
553 if (bp != null) {
554 newGids = PackageManagerService.appendInts(newGids, bp.gids);
555 }
556 }
557 sus.gids = newGids;
558 }
559
Kenny Root447106f2011-03-23 11:00:15 -0700560 int removePackageLPw(String name) {
561 final PackageSetting p = mPackages.get(name);
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700562 if (p != null) {
563 mPackages.remove(name);
564 if (p.sharedUser != null) {
565 p.sharedUser.packages.remove(p);
566 if (p.sharedUser.packages.size() == 0) {
567 mSharedUsers.remove(p.sharedUser.name);
Kenny Root447106f2011-03-23 11:00:15 -0700568 removeUserIdLPw(p.sharedUser.userId);
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700569 return p.sharedUser.userId;
570 }
571 } else {
Kenny Root447106f2011-03-23 11:00:15 -0700572 removeUserIdLPw(p.userId);
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700573 return p.userId;
574 }
575 }
576 return -1;
577 }
578
Kenny Root447106f2011-03-23 11:00:15 -0700579 private void replacePackageLPw(String name, PackageSetting newp) {
580 final PackageSetting p = mPackages.get(name);
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700581 if (p != null) {
582 if (p.sharedUser != null) {
583 p.sharedUser.packages.remove(p);
584 p.sharedUser.packages.add(newp);
585 } else {
Kenny Root447106f2011-03-23 11:00:15 -0700586 replaceUserIdLPw(p.userId, newp);
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700587 }
588 }
589 mPackages.put(name, newp);
590 }
591
Kenny Root447106f2011-03-23 11:00:15 -0700592 private boolean addUserIdLPw(int uid, Object obj, Object name) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700593 if (uid >= PackageManagerService.FIRST_APPLICATION_UID + PackageManagerService.MAX_APPLICATION_UIDS) {
594 return false;
595 }
596
597 if (uid >= PackageManagerService.FIRST_APPLICATION_UID) {
598 int N = mUserIds.size();
599 final int index = uid - PackageManagerService.FIRST_APPLICATION_UID;
600 while (index >= N) {
601 mUserIds.add(null);
602 N++;
603 }
604 if (mUserIds.get(index) != null) {
605 PackageManagerService.reportSettingsProblem(Log.ERROR,
606 "Adding duplicate user id: " + uid
607 + " name=" + name);
608 return false;
609 }
610 mUserIds.set(index, obj);
611 } else {
612 if (mOtherUserIds.get(uid) != null) {
613 PackageManagerService.reportSettingsProblem(Log.ERROR,
614 "Adding duplicate shared id: " + uid
615 + " name=" + name);
616 return false;
617 }
618 mOtherUserIds.put(uid, obj);
619 }
620 return true;
621 }
622
Kenny Root447106f2011-03-23 11:00:15 -0700623 public Object getUserIdLPr(int uid) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700624 if (uid >= PackageManagerService.FIRST_APPLICATION_UID) {
625 final int N = mUserIds.size();
626 final int index = uid - PackageManagerService.FIRST_APPLICATION_UID;
627 return index < N ? mUserIds.get(index) : null;
628 } else {
629 return mOtherUserIds.get(uid);
630 }
631 }
632
Kenny Root447106f2011-03-23 11:00:15 -0700633 private void removeUserIdLPw(int uid) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700634 if (uid >= PackageManagerService.FIRST_APPLICATION_UID) {
635 final int N = mUserIds.size();
636 final int index = uid - PackageManagerService.FIRST_APPLICATION_UID;
637 if (index < N) mUserIds.set(index, null);
638 } else {
639 mOtherUserIds.remove(uid);
640 }
641 }
642
Kenny Root447106f2011-03-23 11:00:15 -0700643 private void replaceUserIdLPw(int uid, Object obj) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700644 if (uid >= PackageManagerService.FIRST_APPLICATION_UID) {
645 final int N = mUserIds.size();
646 final int index = uid - PackageManagerService.FIRST_APPLICATION_UID;
647 if (index < N) mUserIds.set(index, obj);
648 } else {
649 mOtherUserIds.put(uid, obj);
650 }
651 }
652
Kenny Root447106f2011-03-23 11:00:15 -0700653 void writeStoppedLPr() {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700654 // Keep the old stopped packages around until we know the new ones have
655 // been successfully written.
656 if (mStoppedPackagesFilename.exists()) {
657 // Presence of backup settings file indicates that we failed
658 // to persist packages earlier. So preserve the older
659 // backup for future reference since the current packages
660 // might have been corrupted.
661 if (!mBackupStoppedPackagesFilename.exists()) {
662 if (!mStoppedPackagesFilename.renameTo(mBackupStoppedPackagesFilename)) {
663 Log.wtf(PackageManagerService.TAG, "Unable to backup package manager stopped packages, "
664 + "current changes will be lost at reboot");
665 return;
666 }
667 } else {
668 mStoppedPackagesFilename.delete();
669 Slog.w(PackageManagerService.TAG, "Preserving older stopped packages backup");
670 }
671 }
672
673 try {
Kenny Root447106f2011-03-23 11:00:15 -0700674 final FileOutputStream fstr = new FileOutputStream(mStoppedPackagesFilename);
675 final BufferedOutputStream str = new BufferedOutputStream(fstr);
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700676
677 //XmlSerializer serializer = XmlUtils.serializerInstance();
Kenny Root447106f2011-03-23 11:00:15 -0700678 final XmlSerializer serializer = new FastXmlSerializer();
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700679 serializer.setOutput(str, "utf-8");
680 serializer.startDocument(null, true);
681 serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
682
683 serializer.startTag(null, "stopped-packages");
684
Kenny Root447106f2011-03-23 11:00:15 -0700685 for (final PackageSetting pkg : mPackages.values()) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700686 if (pkg.stopped) {
687 serializer.startTag(null, "pkg");
688 serializer.attribute(null, "name", pkg.name);
689 if (pkg.notLaunched) {
690 serializer.attribute(null, "nl", "1");
691 }
692 serializer.endTag(null, "pkg");
693 }
694 }
695
696 serializer.endTag(null, "stopped-packages");
697
698 serializer.endDocument();
699
700 str.flush();
701 FileUtils.sync(fstr);
702 str.close();
703
704 // New settings successfully written, old ones are no longer
705 // needed.
706 mBackupStoppedPackagesFilename.delete();
707 FileUtils.setPermissions(mStoppedPackagesFilename.toString(),
708 FileUtils.S_IRUSR|FileUtils.S_IWUSR
709 |FileUtils.S_IRGRP|FileUtils.S_IWGRP
710 |FileUtils.S_IROTH,
711 -1, -1);
712
713 // Done, all is good!
714 return;
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700715 } catch(java.io.IOException e) {
716 Log.wtf(PackageManagerService.TAG, "Unable to write package manager stopped packages, "
717 + " current changes will be lost at reboot", e);
718 }
719
720 // Clean up partially written files
721 if (mStoppedPackagesFilename.exists()) {
722 if (!mStoppedPackagesFilename.delete()) {
723 Log.i(PackageManagerService.TAG, "Failed to clean up mangled file: " + mStoppedPackagesFilename);
724 }
725 }
726 }
727
728 // Note: assumed "stopped" field is already cleared in all packages.
Kenny Root447106f2011-03-23 11:00:15 -0700729 void readStoppedLPw() {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700730 FileInputStream str = null;
731 if (mBackupStoppedPackagesFilename.exists()) {
732 try {
733 str = new FileInputStream(mBackupStoppedPackagesFilename);
734 mReadMessages.append("Reading from backup stopped packages file\n");
735 PackageManagerService.reportSettingsProblem(Log.INFO, "Need to read from backup stopped packages file");
736 if (mSettingsFilename.exists()) {
737 // If both the backup and normal file exist, we
738 // ignore the normal one since it might have been
739 // corrupted.
740 Slog.w(PackageManagerService.TAG, "Cleaning up stopped packages file "
741 + mStoppedPackagesFilename);
742 mStoppedPackagesFilename.delete();
743 }
744 } catch (java.io.IOException e) {
745 // We'll try for the normal settings file.
746 }
747 }
748
749 try {
750 if (str == null) {
751 if (!mStoppedPackagesFilename.exists()) {
752 mReadMessages.append("No stopped packages file found\n");
753 PackageManagerService.reportSettingsProblem(Log.INFO, "No stopped packages file file; "
754 + "assuming all started");
755 // At first boot, make sure no packages are stopped.
756 // We usually want to have third party apps initialize
757 // in the stopped state, but not at first boot.
758 for (PackageSetting pkg : mPackages.values()) {
759 pkg.stopped = false;
760 pkg.notLaunched = false;
761 }
762 return;
763 }
764 str = new FileInputStream(mStoppedPackagesFilename);
765 }
Kenny Root447106f2011-03-23 11:00:15 -0700766 final XmlPullParser parser = Xml.newPullParser();
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700767 parser.setInput(str, null);
768
769 int type;
770 while ((type=parser.next()) != XmlPullParser.START_TAG
771 && type != XmlPullParser.END_DOCUMENT) {
772 ;
773 }
774
775 if (type != XmlPullParser.START_TAG) {
776 mReadMessages.append("No start tag found in stopped packages file\n");
777 PackageManagerService.reportSettingsProblem(Log.WARN,
778 "No start tag found in package manager stopped packages");
779 return;
780 }
781
782 int outerDepth = parser.getDepth();
783 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
784 && (type != XmlPullParser.END_TAG
785 || parser.getDepth() > outerDepth)) {
786 if (type == XmlPullParser.END_TAG
787 || type == XmlPullParser.TEXT) {
788 continue;
789 }
790
791 String tagName = parser.getName();
792 if (tagName.equals("pkg")) {
793 String name = parser.getAttributeValue(null, "name");
794 PackageSetting ps = mPackages.get(name);
795 if (ps != null) {
796 ps.stopped = true;
797 if ("1".equals(parser.getAttributeValue(null, "nl"))) {
798 ps.notLaunched = true;
799 }
800 } else {
801 Slog.w(PackageManagerService.TAG, "No package known for stopped package: " + name);
802 }
803 XmlUtils.skipCurrentTag(parser);
804 } else {
805 Slog.w(PackageManagerService.TAG, "Unknown element under <stopped-packages>: "
806 + parser.getName());
807 XmlUtils.skipCurrentTag(parser);
808 }
809 }
810
811 str.close();
812
813 } catch(XmlPullParserException e) {
814 mReadMessages.append("Error reading: " + e.toString());
815 PackageManagerService.reportSettingsProblem(Log.ERROR, "Error reading stopped packages: " + e);
816 Log.wtf(PackageManagerService.TAG, "Error reading package manager stopped packages", e);
817
818 } catch(java.io.IOException e) {
819 mReadMessages.append("Error reading: " + e.toString());
820 PackageManagerService.reportSettingsProblem(Log.ERROR, "Error reading settings: " + e);
821 Log.wtf(PackageManagerService.TAG, "Error reading package manager stopped packages", e);
822
823 }
824 }
825
Kenny Root447106f2011-03-23 11:00:15 -0700826 void writeLPr() {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700827 //Debug.startMethodTracing("/data/system/packageprof", 8 * 1024 * 1024);
828
829 // Keep the old settings around until we know the new ones have
830 // been successfully written.
831 if (mSettingsFilename.exists()) {
832 // Presence of backup settings file indicates that we failed
833 // to persist settings earlier. So preserve the older
834 // backup for future reference since the current settings
835 // might have been corrupted.
836 if (!mBackupSettingsFilename.exists()) {
837 if (!mSettingsFilename.renameTo(mBackupSettingsFilename)) {
838 Log.wtf(PackageManagerService.TAG, "Unable to backup package manager settings, "
839 + " current changes will be lost at reboot");
840 return;
841 }
842 } else {
843 mSettingsFilename.delete();
844 Slog.w(PackageManagerService.TAG, "Preserving older settings backup");
845 }
846 }
847
848 mPastSignatures.clear();
849
850 try {
851 FileOutputStream fstr = new FileOutputStream(mSettingsFilename);
852 BufferedOutputStream str = new BufferedOutputStream(fstr);
853
854 //XmlSerializer serializer = XmlUtils.serializerInstance();
855 XmlSerializer serializer = new FastXmlSerializer();
856 serializer.setOutput(str, "utf-8");
857 serializer.startDocument(null, true);
858 serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
859
860 serializer.startTag(null, "packages");
861
862 serializer.startTag(null, "last-platform-version");
863 serializer.attribute(null, "internal", Integer.toString(mInternalSdkPlatform));
864 serializer.attribute(null, "external", Integer.toString(mExternalSdkPlatform));
865 serializer.endTag(null, "last-platform-version");
866
867 serializer.startTag(null, "permission-trees");
868 for (BasePermission bp : mPermissionTrees.values()) {
Kenny Root447106f2011-03-23 11:00:15 -0700869 writePermissionLPr(serializer, bp);
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700870 }
871 serializer.endTag(null, "permission-trees");
872
873 serializer.startTag(null, "permissions");
874 for (BasePermission bp : mPermissions.values()) {
Kenny Root447106f2011-03-23 11:00:15 -0700875 writePermissionLPr(serializer, bp);
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700876 }
877 serializer.endTag(null, "permissions");
878
Kenny Root447106f2011-03-23 11:00:15 -0700879 for (final PackageSetting pkg : mPackages.values()) {
880 writePackageLPr(serializer, pkg);
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700881 }
882
Kenny Root447106f2011-03-23 11:00:15 -0700883 for (final PackageSetting pkg : mDisabledSysPackages.values()) {
884 writeDisabledSysPackageLPr(serializer, pkg);
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700885 }
886
887 serializer.startTag(null, "preferred-activities");
Kenny Root447106f2011-03-23 11:00:15 -0700888 for (final PreferredActivity pa : mPreferredActivities.filterSet()) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700889 serializer.startTag(null, "item");
890 pa.writeToXml(serializer);
891 serializer.endTag(null, "item");
892 }
893 serializer.endTag(null, "preferred-activities");
894
Kenny Root447106f2011-03-23 11:00:15 -0700895 for (final SharedUserSetting usr : mSharedUsers.values()) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700896 serializer.startTag(null, "shared-user");
897 serializer.attribute(null, "name", usr.name);
898 serializer.attribute(null, "userId",
899 Integer.toString(usr.userId));
900 usr.signatures.writeXml(serializer, "sigs", mPastSignatures);
901 serializer.startTag(null, "perms");
902 for (String name : usr.grantedPermissions) {
903 serializer.startTag(null, "item");
904 serializer.attribute(null, "name", name);
905 serializer.endTag(null, "item");
906 }
907 serializer.endTag(null, "perms");
908 serializer.endTag(null, "shared-user");
909 }
910
911 if (mPackagesToBeCleaned.size() > 0) {
912 for (int i=0; i<mPackagesToBeCleaned.size(); i++) {
913 serializer.startTag(null, "cleaning-package");
914 serializer.attribute(null, "name", mPackagesToBeCleaned.get(i));
915 serializer.endTag(null, "cleaning-package");
916 }
917 }
918
919 if (mRenamedPackages.size() > 0) {
920 for (HashMap.Entry<String, String> e : mRenamedPackages.entrySet()) {
921 serializer.startTag(null, "renamed-package");
922 serializer.attribute(null, "new", e.getKey());
923 serializer.attribute(null, "old", e.getValue());
924 serializer.endTag(null, "renamed-package");
925 }
926 }
927
928 serializer.endTag(null, "packages");
929
930 serializer.endDocument();
931
932 str.flush();
933 FileUtils.sync(fstr);
934 str.close();
935
936 // New settings successfully written, old ones are no longer
937 // needed.
938 mBackupSettingsFilename.delete();
939 FileUtils.setPermissions(mSettingsFilename.toString(),
940 FileUtils.S_IRUSR|FileUtils.S_IWUSR
941 |FileUtils.S_IRGRP|FileUtils.S_IWGRP
942 |FileUtils.S_IROTH,
943 -1, -1);
944
945 // Write package list file now, use a JournaledFile.
946 //
947 File tempFile = new File(mPackageListFilename.toString() + ".tmp");
948 JournaledFile journal = new JournaledFile(mPackageListFilename, tempFile);
949
950 fstr = new FileOutputStream(journal.chooseForWrite());
951 str = new BufferedOutputStream(fstr);
952 try {
953 StringBuilder sb = new StringBuilder();
Kenny Root447106f2011-03-23 11:00:15 -0700954 for (final PackageSetting pkg : mPackages.values()) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700955 ApplicationInfo ai = pkg.pkg.applicationInfo;
956 String dataPath = ai.dataDir;
957 boolean isDebug = (ai.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
958
959 // Avoid any application that has a space in its path
960 // or that is handled by the system.
961 if (dataPath.indexOf(" ") >= 0 || ai.uid <= Process.FIRST_APPLICATION_UID)
962 continue;
963
964 // we store on each line the following information for now:
965 //
966 // pkgName - package name
967 // userId - application-specific user id
968 // debugFlag - 0 or 1 if the package is debuggable.
969 // dataPath - path to package's data path
970 //
971 // NOTE: We prefer not to expose all ApplicationInfo flags for now.
972 //
973 // DO NOT MODIFY THIS FORMAT UNLESS YOU CAN ALSO MODIFY ITS USERS
974 // FROM NATIVE CODE. AT THE MOMENT, LOOK AT THE FOLLOWING SOURCES:
975 // system/core/run-as/run-as.c
976 //
977 sb.setLength(0);
978 sb.append(ai.packageName);
979 sb.append(" ");
980 sb.append((int)ai.uid);
981 sb.append(isDebug ? " 1 " : " 0 ");
982 sb.append(dataPath);
983 sb.append("\n");
984 str.write(sb.toString().getBytes());
985 }
986 str.flush();
987 FileUtils.sync(fstr);
988 str.close();
989 journal.commit();
990 }
991 catch (Exception e) {
992 journal.rollback();
993 }
994
995 FileUtils.setPermissions(mPackageListFilename.toString(),
996 FileUtils.S_IRUSR|FileUtils.S_IWUSR
997 |FileUtils.S_IRGRP|FileUtils.S_IWGRP
998 |FileUtils.S_IROTH,
999 -1, -1);
1000
Kenny Root447106f2011-03-23 11:00:15 -07001001 writeStoppedLPr();
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001002
1003 return;
1004
1005 } catch(XmlPullParserException e) {
1006 Log.wtf(PackageManagerService.TAG, "Unable to write package manager settings, "
1007 + "current changes will be lost at reboot", e);
1008 } catch(java.io.IOException e) {
1009 Log.wtf(PackageManagerService.TAG, "Unable to write package manager settings, "
1010 + "current changes will be lost at reboot", e);
1011 }
1012 // Clean up partially written files
1013 if (mSettingsFilename.exists()) {
1014 if (!mSettingsFilename.delete()) {
1015 Log.wtf(PackageManagerService.TAG, "Failed to clean up mangled file: " + mSettingsFilename);
1016 }
1017 }
1018 //Debug.stopMethodTracing();
1019 }
1020
Kenny Root447106f2011-03-23 11:00:15 -07001021 void writeDisabledSysPackageLPr(XmlSerializer serializer, final PackageSetting pkg)
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001022 throws java.io.IOException {
1023 serializer.startTag(null, "updated-package");
1024 serializer.attribute(null, "name", pkg.name);
1025 if (pkg.realName != null) {
1026 serializer.attribute(null, "realName", pkg.realName);
1027 }
1028 serializer.attribute(null, "codePath", pkg.codePathString);
1029 serializer.attribute(null, "ft", Long.toHexString(pkg.timeStamp));
1030 serializer.attribute(null, "it", Long.toHexString(pkg.firstInstallTime));
1031 serializer.attribute(null, "ut", Long.toHexString(pkg.lastUpdateTime));
1032 serializer.attribute(null, "version", String.valueOf(pkg.versionCode));
1033 if (!pkg.resourcePathString.equals(pkg.codePathString)) {
1034 serializer.attribute(null, "resourcePath", pkg.resourcePathString);
1035 }
1036 if (pkg.nativeLibraryPathString != null) {
1037 serializer.attribute(null, "nativeLibraryPath", pkg.nativeLibraryPathString);
1038 }
1039 if (pkg.sharedUser == null) {
1040 serializer.attribute(null, "userId", Integer.toString(pkg.userId));
1041 } else {
1042 serializer.attribute(null, "sharedUserId", Integer.toString(pkg.userId));
1043 }
1044 serializer.startTag(null, "perms");
1045 if (pkg.sharedUser == null) {
1046 // If this is a shared user, the permissions will
1047 // be written there. We still need to write an
1048 // empty permissions list so permissionsFixed will
1049 // be set.
1050 for (final String name : pkg.grantedPermissions) {
1051 BasePermission bp = mPermissions.get(name);
1052 if (bp != null) {
1053 // We only need to write signature or system permissions but
1054 // this wont
1055 // match the semantics of grantedPermissions. So write all
1056 // permissions.
1057 serializer.startTag(null, "item");
1058 serializer.attribute(null, "name", name);
1059 serializer.endTag(null, "item");
1060 }
1061 }
1062 }
1063 serializer.endTag(null, "perms");
1064 serializer.endTag(null, "updated-package");
1065 }
1066
Kenny Root447106f2011-03-23 11:00:15 -07001067 void writePackageLPr(XmlSerializer serializer, final PackageSetting pkg)
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001068 throws java.io.IOException {
1069 serializer.startTag(null, "package");
1070 serializer.attribute(null, "name", pkg.name);
1071 if (pkg.realName != null) {
1072 serializer.attribute(null, "realName", pkg.realName);
1073 }
1074 serializer.attribute(null, "codePath", pkg.codePathString);
1075 if (!pkg.resourcePathString.equals(pkg.codePathString)) {
1076 serializer.attribute(null, "resourcePath", pkg.resourcePathString);
1077 }
1078 if (pkg.nativeLibraryPathString != null) {
1079 serializer.attribute(null, "nativeLibraryPath", pkg.nativeLibraryPathString);
1080 }
1081 serializer.attribute(null, "flags", Integer.toString(pkg.pkgFlags));
1082 serializer.attribute(null, "ft", Long.toHexString(pkg.timeStamp));
1083 serializer.attribute(null, "it", Long.toHexString(pkg.firstInstallTime));
1084 serializer.attribute(null, "ut", Long.toHexString(pkg.lastUpdateTime));
1085 serializer.attribute(null, "version", String.valueOf(pkg.versionCode));
1086 if (pkg.sharedUser == null) {
1087 serializer.attribute(null, "userId", Integer.toString(pkg.userId));
1088 } else {
1089 serializer.attribute(null, "sharedUserId", Integer.toString(pkg.userId));
1090 }
1091 if (pkg.uidError) {
1092 serializer.attribute(null, "uidError", "true");
1093 }
1094 if (pkg.enabled != COMPONENT_ENABLED_STATE_DEFAULT) {
1095 serializer.attribute(null, "enabled",
1096 pkg.enabled == COMPONENT_ENABLED_STATE_ENABLED ? "true" : "false");
1097 }
1098 if (pkg.installStatus == PackageSettingBase.PKG_INSTALL_INCOMPLETE) {
1099 serializer.attribute(null, "installStatus", "false");
1100 }
1101 if (pkg.installerPackageName != null) {
1102 serializer.attribute(null, "installer", pkg.installerPackageName);
1103 }
1104 pkg.signatures.writeXml(serializer, "sigs", mPastSignatures);
1105 if ((pkg.pkgFlags & ApplicationInfo.FLAG_SYSTEM) == 0) {
1106 serializer.startTag(null, "perms");
1107 if (pkg.sharedUser == null) {
1108 // If this is a shared user, the permissions will
1109 // be written there. We still need to write an
1110 // empty permissions list so permissionsFixed will
1111 // be set.
1112 for (final String name : pkg.grantedPermissions) {
1113 serializer.startTag(null, "item");
1114 serializer.attribute(null, "name", name);
1115 serializer.endTag(null, "item");
1116 }
1117 }
1118 serializer.endTag(null, "perms");
1119 }
1120 if (pkg.disabledComponents.size() > 0) {
1121 serializer.startTag(null, "disabled-components");
1122 for (final String name : pkg.disabledComponents) {
1123 serializer.startTag(null, "item");
1124 serializer.attribute(null, "name", name);
1125 serializer.endTag(null, "item");
1126 }
1127 serializer.endTag(null, "disabled-components");
1128 }
1129 if (pkg.enabledComponents.size() > 0) {
1130 serializer.startTag(null, "enabled-components");
1131 for (final String name : pkg.enabledComponents) {
1132 serializer.startTag(null, "item");
1133 serializer.attribute(null, "name", name);
1134 serializer.endTag(null, "item");
1135 }
1136 serializer.endTag(null, "enabled-components");
1137 }
1138
1139 serializer.endTag(null, "package");
1140 }
1141
Kenny Root447106f2011-03-23 11:00:15 -07001142 void writePermissionLPr(XmlSerializer serializer, BasePermission bp)
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001143 throws XmlPullParserException, java.io.IOException {
1144 if (bp.type != BasePermission.TYPE_BUILTIN && bp.sourcePackage != null) {
1145 serializer.startTag(null, "item");
1146 serializer.attribute(null, "name", bp.name);
1147 serializer.attribute(null, "package", bp.sourcePackage);
1148 if (bp.protectionLevel != PermissionInfo.PROTECTION_NORMAL) {
1149 serializer.attribute(null, "protection", Integer.toString(bp.protectionLevel));
1150 }
1151 if (PackageManagerService.DEBUG_SETTINGS)
1152 Log.v(PackageManagerService.TAG, "Writing perm: name=" + bp.name + " type="
1153 + bp.type);
1154 if (bp.type == BasePermission.TYPE_DYNAMIC) {
Kenny Root447106f2011-03-23 11:00:15 -07001155 final PermissionInfo pi = bp.perm != null ? bp.perm.info : bp.pendingInfo;
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001156 if (pi != null) {
1157 serializer.attribute(null, "type", "dynamic");
1158 if (pi.icon != 0) {
1159 serializer.attribute(null, "icon", Integer.toString(pi.icon));
1160 }
1161 if (pi.nonLocalizedLabel != null) {
1162 serializer.attribute(null, "label", pi.nonLocalizedLabel.toString());
1163 }
1164 }
1165 }
1166 serializer.endTag(null, "item");
1167 }
1168 }
1169
Kenny Root447106f2011-03-23 11:00:15 -07001170 ArrayList<PackageSetting> getListOfIncompleteInstallPackagesLPr() {
1171 final HashSet<String> kList = new HashSet<String>(mPackages.keySet());
1172 final Iterator<String> its = kList.iterator();
1173 final ArrayList<PackageSetting> ret = new ArrayList<PackageSetting>();
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001174 while (its.hasNext()) {
Kenny Root447106f2011-03-23 11:00:15 -07001175 final String key = its.next();
1176 final PackageSetting ps = mPackages.get(key);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001177 if (ps.getInstallStatus() == PackageSettingBase.PKG_INSTALL_INCOMPLETE) {
1178 ret.add(ps);
1179 }
1180 }
1181 return ret;
1182 }
1183
Kenny Root447106f2011-03-23 11:00:15 -07001184 boolean readLPw() {
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001185 FileInputStream str = null;
1186 if (mBackupSettingsFilename.exists()) {
1187 try {
1188 str = new FileInputStream(mBackupSettingsFilename);
1189 mReadMessages.append("Reading from backup settings file\n");
1190 PackageManagerService.reportSettingsProblem(Log.INFO,
1191 "Need to read from backup settings file");
1192 if (mSettingsFilename.exists()) {
1193 // If both the backup and settings file exist, we
1194 // ignore the settings since it might have been
1195 // corrupted.
1196 Slog.w(PackageManagerService.TAG, "Cleaning up settings file "
1197 + mSettingsFilename);
1198 mSettingsFilename.delete();
1199 }
1200 } catch (java.io.IOException e) {
1201 // We'll try for the normal settings file.
1202 }
1203 }
1204
Kenny Root447106f2011-03-23 11:00:15 -07001205 mPendingPackages.clear();
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001206 mPastSignatures.clear();
1207
1208 try {
1209 if (str == null) {
1210 if (!mSettingsFilename.exists()) {
1211 mReadMessages.append("No settings file found\n");
1212 PackageManagerService.reportSettingsProblem(Log.INFO,
1213 "No settings file; creating initial state");
1214 return false;
1215 }
1216 str = new FileInputStream(mSettingsFilename);
1217 }
1218 XmlPullParser parser = Xml.newPullParser();
1219 parser.setInput(str, null);
1220
1221 int type;
1222 while ((type = parser.next()) != XmlPullParser.START_TAG
1223 && type != XmlPullParser.END_DOCUMENT) {
1224 ;
1225 }
1226
1227 if (type != XmlPullParser.START_TAG) {
1228 mReadMessages.append("No start tag found in settings file\n");
1229 PackageManagerService.reportSettingsProblem(Log.WARN,
1230 "No start tag found in package manager settings");
1231 Log
1232 .wtf(PackageManagerService.TAG,
1233 "No start tag found in package manager settings");
1234 return false;
1235 }
1236
1237 int outerDepth = parser.getDepth();
1238 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
1239 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
1240 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
1241 continue;
1242 }
1243
1244 String tagName = parser.getName();
1245 if (tagName.equals("package")) {
Kenny Root447106f2011-03-23 11:00:15 -07001246 readPackageLPw(parser);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001247 } else if (tagName.equals("permissions")) {
Kenny Root447106f2011-03-23 11:00:15 -07001248 readPermissionsLPw(mPermissions, parser);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001249 } else if (tagName.equals("permission-trees")) {
Kenny Root447106f2011-03-23 11:00:15 -07001250 readPermissionsLPw(mPermissionTrees, parser);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001251 } else if (tagName.equals("shared-user")) {
Kenny Root447106f2011-03-23 11:00:15 -07001252 readSharedUserLPw(parser);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001253 } else if (tagName.equals("preferred-packages")) {
1254 // no longer used.
1255 } else if (tagName.equals("preferred-activities")) {
Kenny Root447106f2011-03-23 11:00:15 -07001256 readPreferredActivitiesLPw(parser);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001257 } else if (tagName.equals("updated-package")) {
Kenny Root447106f2011-03-23 11:00:15 -07001258 readDisabledSysPackageLPw(parser);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001259 } else if (tagName.equals("cleaning-package")) {
1260 String name = parser.getAttributeValue(null, "name");
1261 if (name != null) {
1262 mPackagesToBeCleaned.add(name);
1263 }
1264 } else if (tagName.equals("renamed-package")) {
1265 String nname = parser.getAttributeValue(null, "new");
1266 String oname = parser.getAttributeValue(null, "old");
1267 if (nname != null && oname != null) {
1268 mRenamedPackages.put(nname, oname);
1269 }
1270 } else if (tagName.equals("last-platform-version")) {
1271 mInternalSdkPlatform = mExternalSdkPlatform = 0;
1272 try {
1273 String internal = parser.getAttributeValue(null, "internal");
1274 if (internal != null) {
1275 mInternalSdkPlatform = Integer.parseInt(internal);
1276 }
1277 String external = parser.getAttributeValue(null, "external");
1278 if (external != null) {
1279 mExternalSdkPlatform = Integer.parseInt(external);
1280 }
1281 } catch (NumberFormatException e) {
1282 }
1283 } else {
1284 Slog.w(PackageManagerService.TAG, "Unknown element under <packages>: "
1285 + parser.getName());
1286 XmlUtils.skipCurrentTag(parser);
1287 }
1288 }
1289
1290 str.close();
1291
1292 } catch (XmlPullParserException e) {
1293 mReadMessages.append("Error reading: " + e.toString());
1294 PackageManagerService.reportSettingsProblem(Log.ERROR, "Error reading settings: " + e);
1295 Log.wtf(PackageManagerService.TAG, "Error reading package manager settings", e);
1296
1297 } catch (java.io.IOException e) {
1298 mReadMessages.append("Error reading: " + e.toString());
1299 PackageManagerService.reportSettingsProblem(Log.ERROR, "Error reading settings: " + e);
1300 Log.wtf(PackageManagerService.TAG, "Error reading package manager settings", e);
1301
1302 }
1303
1304 final int N = mPendingPackages.size();
1305 for (int i = 0; i < N; i++) {
1306 final PendingPackage pp = mPendingPackages.get(i);
Kenny Root447106f2011-03-23 11:00:15 -07001307 Object idObj = getUserIdLPr(pp.sharedId);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001308 if (idObj != null && idObj instanceof SharedUserSetting) {
Kenny Root447106f2011-03-23 11:00:15 -07001309 PackageSetting p = getPackageLPw(pp.name, null, pp.realName,
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001310 (SharedUserSetting) idObj, pp.codePath, pp.resourcePath,
1311 pp.nativeLibraryPathString, pp.versionCode, pp.pkgFlags, true, true);
1312 if (p == null) {
1313 PackageManagerService.reportSettingsProblem(Log.WARN,
1314 "Unable to create application package for " + pp.name);
1315 continue;
1316 }
1317 p.copyFrom(pp);
1318 } else if (idObj != null) {
1319 String msg = "Bad package setting: package " + pp.name + " has shared uid "
1320 + pp.sharedId + " that is not a shared uid\n";
1321 mReadMessages.append(msg);
1322 PackageManagerService.reportSettingsProblem(Log.ERROR, msg);
1323 } else {
1324 String msg = "Bad package setting: package " + pp.name + " has shared uid "
1325 + pp.sharedId + " that is not defined\n";
1326 mReadMessages.append(msg);
1327 PackageManagerService.reportSettingsProblem(Log.ERROR, msg);
1328 }
1329 }
1330 mPendingPackages.clear();
1331
Kenny Root1d1b4892011-04-08 14:25:24 -07001332 /*
1333 * Make sure all the updated system packages have their shared users
1334 * associated with them.
1335 */
1336 final Iterator<PackageSetting> disabledIt = mDisabledSysPackages.values().iterator();
1337 while (disabledIt.hasNext()) {
1338 final PackageSetting disabledPs = disabledIt.next();
1339 final Object id = getUserIdLPr(disabledPs.userId);
1340 if (id != null && id instanceof SharedUserSetting) {
1341 disabledPs.sharedUser = (SharedUserSetting) id;
1342 }
1343 }
1344
Kenny Root447106f2011-03-23 11:00:15 -07001345 readStoppedLPw();
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001346
1347 mReadMessages.append("Read completed successfully: " + mPackages.size() + " packages, "
1348 + mSharedUsers.size() + " shared uids\n");
1349
1350 return true;
1351 }
1352
1353 private int readInt(XmlPullParser parser, String ns, String name, int defValue) {
1354 String v = parser.getAttributeValue(ns, name);
1355 try {
1356 if (v == null) {
1357 return defValue;
1358 }
1359 return Integer.parseInt(v);
1360 } catch (NumberFormatException e) {
1361 PackageManagerService.reportSettingsProblem(Log.WARN,
1362 "Error in package manager settings: attribute " + name
1363 + " has bad integer value " + v + " at "
1364 + parser.getPositionDescription());
1365 }
1366 return defValue;
1367 }
1368
Kenny Root447106f2011-03-23 11:00:15 -07001369 private void readPermissionsLPw(HashMap<String, BasePermission> out, XmlPullParser parser)
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001370 throws IOException, XmlPullParserException {
1371 int outerDepth = parser.getDepth();
1372 int type;
1373 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
1374 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
1375 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
1376 continue;
1377 }
1378
Kenny Root447106f2011-03-23 11:00:15 -07001379 final String tagName = parser.getName();
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001380 if (tagName.equals("item")) {
Kenny Root447106f2011-03-23 11:00:15 -07001381 final String name = parser.getAttributeValue(null, "name");
1382 final String sourcePackage = parser.getAttributeValue(null, "package");
1383 final String ptype = parser.getAttributeValue(null, "type");
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001384 if (name != null && sourcePackage != null) {
Kenny Root447106f2011-03-23 11:00:15 -07001385 final boolean dynamic = "dynamic".equals(ptype);
1386 final BasePermission bp = new BasePermission(name, sourcePackage,
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001387 dynamic ? BasePermission.TYPE_DYNAMIC : BasePermission.TYPE_NORMAL);
1388 bp.protectionLevel = readInt(parser, null, "protection",
1389 PermissionInfo.PROTECTION_NORMAL);
1390 if (dynamic) {
1391 PermissionInfo pi = new PermissionInfo();
1392 pi.packageName = sourcePackage.intern();
1393 pi.name = name.intern();
1394 pi.icon = readInt(parser, null, "icon", 0);
1395 pi.nonLocalizedLabel = parser.getAttributeValue(null, "label");
1396 pi.protectionLevel = bp.protectionLevel;
1397 bp.pendingInfo = pi;
1398 }
1399 out.put(bp.name, bp);
1400 } else {
1401 PackageManagerService.reportSettingsProblem(Log.WARN,
1402 "Error in package manager settings: permissions has" + " no name at "
1403 + parser.getPositionDescription());
1404 }
1405 } else {
1406 PackageManagerService.reportSettingsProblem(Log.WARN,
1407 "Unknown element reading permissions: " + parser.getName() + " at "
1408 + parser.getPositionDescription());
1409 }
1410 XmlUtils.skipCurrentTag(parser);
1411 }
1412 }
1413
Kenny Root447106f2011-03-23 11:00:15 -07001414 private void readDisabledSysPackageLPw(XmlPullParser parser) throws XmlPullParserException,
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001415 IOException {
1416 String name = parser.getAttributeValue(null, "name");
1417 String realName = parser.getAttributeValue(null, "realName");
1418 String codePathStr = parser.getAttributeValue(null, "codePath");
1419 String resourcePathStr = parser.getAttributeValue(null, "resourcePath");
1420 String nativeLibraryPathStr = parser.getAttributeValue(null, "nativeLibraryPath");
1421 if (resourcePathStr == null) {
1422 resourcePathStr = codePathStr;
1423 }
1424 String version = parser.getAttributeValue(null, "version");
1425 int versionCode = 0;
1426 if (version != null) {
1427 try {
1428 versionCode = Integer.parseInt(version);
1429 } catch (NumberFormatException e) {
1430 }
1431 }
1432
1433 int pkgFlags = 0;
1434 pkgFlags |= ApplicationInfo.FLAG_SYSTEM;
1435 PackageSetting ps = new PackageSetting(name, realName, new File(codePathStr),
1436 new File(resourcePathStr), nativeLibraryPathStr, versionCode, pkgFlags);
1437 String timeStampStr = parser.getAttributeValue(null, "ft");
1438 if (timeStampStr != null) {
1439 try {
1440 long timeStamp = Long.parseLong(timeStampStr, 16);
1441 ps.setTimeStamp(timeStamp);
1442 } catch (NumberFormatException e) {
1443 }
1444 } else {
1445 timeStampStr = parser.getAttributeValue(null, "ts");
1446 if (timeStampStr != null) {
1447 try {
1448 long timeStamp = Long.parseLong(timeStampStr);
1449 ps.setTimeStamp(timeStamp);
1450 } catch (NumberFormatException e) {
1451 }
1452 }
1453 }
1454 timeStampStr = parser.getAttributeValue(null, "it");
1455 if (timeStampStr != null) {
1456 try {
1457 ps.firstInstallTime = Long.parseLong(timeStampStr, 16);
1458 } catch (NumberFormatException e) {
1459 }
1460 }
1461 timeStampStr = parser.getAttributeValue(null, "ut");
1462 if (timeStampStr != null) {
1463 try {
1464 ps.lastUpdateTime = Long.parseLong(timeStampStr, 16);
1465 } catch (NumberFormatException e) {
1466 }
1467 }
1468 String idStr = parser.getAttributeValue(null, "userId");
1469 ps.userId = idStr != null ? Integer.parseInt(idStr) : 0;
1470 if (ps.userId <= 0) {
1471 String sharedIdStr = parser.getAttributeValue(null, "sharedUserId");
1472 ps.userId = sharedIdStr != null ? Integer.parseInt(sharedIdStr) : 0;
1473 }
1474 int outerDepth = parser.getDepth();
1475 int type;
1476 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
1477 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
1478 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
1479 continue;
1480 }
1481
1482 String tagName = parser.getName();
1483 if (tagName.equals("perms")) {
Kenny Root447106f2011-03-23 11:00:15 -07001484 readGrantedPermissionsLPw(parser, ps.grantedPermissions);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001485 } else {
1486 PackageManagerService.reportSettingsProblem(Log.WARN,
1487 "Unknown element under <updated-package>: " + parser.getName());
1488 XmlUtils.skipCurrentTag(parser);
1489 }
1490 }
1491 mDisabledSysPackages.put(name, ps);
1492 }
1493
Kenny Root447106f2011-03-23 11:00:15 -07001494 private void readPackageLPw(XmlPullParser parser) throws XmlPullParserException, IOException {
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001495 String name = null;
1496 String realName = null;
1497 String idStr = null;
1498 String sharedIdStr = null;
1499 String codePathStr = null;
1500 String resourcePathStr = null;
1501 String nativeLibraryPathStr = null;
1502 String systemStr = null;
1503 String installerPackageName = null;
1504 String uidError = null;
1505 int pkgFlags = 0;
1506 long timeStamp = 0;
1507 long firstInstallTime = 0;
1508 long lastUpdateTime = 0;
1509 PackageSettingBase packageSetting = null;
1510 String version = null;
1511 int versionCode = 0;
1512 try {
1513 name = parser.getAttributeValue(null, "name");
1514 realName = parser.getAttributeValue(null, "realName");
1515 idStr = parser.getAttributeValue(null, "userId");
1516 uidError = parser.getAttributeValue(null, "uidError");
1517 sharedIdStr = parser.getAttributeValue(null, "sharedUserId");
1518 codePathStr = parser.getAttributeValue(null, "codePath");
1519 resourcePathStr = parser.getAttributeValue(null, "resourcePath");
1520 nativeLibraryPathStr = parser.getAttributeValue(null, "nativeLibraryPath");
1521 version = parser.getAttributeValue(null, "version");
1522 if (version != null) {
1523 try {
1524 versionCode = Integer.parseInt(version);
1525 } catch (NumberFormatException e) {
1526 }
1527 }
1528 installerPackageName = parser.getAttributeValue(null, "installer");
1529
1530 systemStr = parser.getAttributeValue(null, "flags");
1531 if (systemStr != null) {
1532 try {
1533 pkgFlags = Integer.parseInt(systemStr);
1534 } catch (NumberFormatException e) {
1535 }
1536 } else {
1537 // For backward compatibility
1538 systemStr = parser.getAttributeValue(null, "system");
1539 if (systemStr != null) {
1540 pkgFlags |= ("true".equalsIgnoreCase(systemStr)) ? ApplicationInfo.FLAG_SYSTEM
1541 : 0;
1542 } else {
1543 // Old settings that don't specify system... just treat
1544 // them as system, good enough.
1545 pkgFlags |= ApplicationInfo.FLAG_SYSTEM;
1546 }
1547 }
1548 String timeStampStr = parser.getAttributeValue(null, "ft");
1549 if (timeStampStr != null) {
1550 try {
1551 timeStamp = Long.parseLong(timeStampStr, 16);
1552 } catch (NumberFormatException e) {
1553 }
1554 } else {
1555 timeStampStr = parser.getAttributeValue(null, "ts");
1556 if (timeStampStr != null) {
1557 try {
1558 timeStamp = Long.parseLong(timeStampStr);
1559 } catch (NumberFormatException e) {
1560 }
1561 }
1562 }
1563 timeStampStr = parser.getAttributeValue(null, "it");
1564 if (timeStampStr != null) {
1565 try {
1566 firstInstallTime = Long.parseLong(timeStampStr, 16);
1567 } catch (NumberFormatException e) {
1568 }
1569 }
1570 timeStampStr = parser.getAttributeValue(null, "ut");
1571 if (timeStampStr != null) {
1572 try {
1573 lastUpdateTime = Long.parseLong(timeStampStr, 16);
1574 } catch (NumberFormatException e) {
1575 }
1576 }
1577 if (PackageManagerService.DEBUG_SETTINGS)
1578 Log.v(PackageManagerService.TAG, "Reading package: " + name + " userId=" + idStr
1579 + " sharedUserId=" + sharedIdStr);
1580 int userId = idStr != null ? Integer.parseInt(idStr) : 0;
1581 if (resourcePathStr == null) {
1582 resourcePathStr = codePathStr;
1583 }
1584 if (realName != null) {
1585 realName = realName.intern();
1586 }
1587 if (name == null) {
1588 PackageManagerService.reportSettingsProblem(Log.WARN,
1589 "Error in package manager settings: <package> has no name at "
1590 + parser.getPositionDescription());
1591 } else if (codePathStr == null) {
1592 PackageManagerService.reportSettingsProblem(Log.WARN,
1593 "Error in package manager settings: <package> has no codePath at "
1594 + parser.getPositionDescription());
1595 } else if (userId > 0) {
Kenny Root447106f2011-03-23 11:00:15 -07001596 packageSetting = addPackageLPw(name.intern(), realName, new File(codePathStr),
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001597 new File(resourcePathStr), nativeLibraryPathStr, userId, versionCode,
1598 pkgFlags);
1599 if (PackageManagerService.DEBUG_SETTINGS)
1600 Log.i(PackageManagerService.TAG, "Reading package " + name + ": userId="
1601 + userId + " pkg=" + packageSetting);
1602 if (packageSetting == null) {
1603 PackageManagerService.reportSettingsProblem(Log.ERROR, "Failure adding uid "
1604 + userId + " while parsing settings at "
1605 + parser.getPositionDescription());
1606 } else {
1607 packageSetting.setTimeStamp(timeStamp);
1608 packageSetting.firstInstallTime = firstInstallTime;
1609 packageSetting.lastUpdateTime = lastUpdateTime;
1610 }
1611 } else if (sharedIdStr != null) {
1612 userId = sharedIdStr != null ? Integer.parseInt(sharedIdStr) : 0;
1613 if (userId > 0) {
1614 packageSetting = new PendingPackage(name.intern(), realName, new File(
1615 codePathStr), new File(resourcePathStr), nativeLibraryPathStr, userId,
1616 versionCode, pkgFlags);
1617 packageSetting.setTimeStamp(timeStamp);
1618 packageSetting.firstInstallTime = firstInstallTime;
1619 packageSetting.lastUpdateTime = lastUpdateTime;
1620 mPendingPackages.add((PendingPackage) packageSetting);
1621 if (PackageManagerService.DEBUG_SETTINGS)
1622 Log.i(PackageManagerService.TAG, "Reading package " + name
1623 + ": sharedUserId=" + userId + " pkg=" + packageSetting);
1624 } else {
1625 PackageManagerService.reportSettingsProblem(Log.WARN,
1626 "Error in package manager settings: package " + name
1627 + " has bad sharedId " + sharedIdStr + " at "
1628 + parser.getPositionDescription());
1629 }
1630 } else {
1631 PackageManagerService.reportSettingsProblem(Log.WARN,
1632 "Error in package manager settings: package " + name + " has bad userId "
1633 + idStr + " at " + parser.getPositionDescription());
1634 }
1635 } catch (NumberFormatException e) {
1636 PackageManagerService.reportSettingsProblem(Log.WARN,
1637 "Error in package manager settings: package " + name + " has bad userId "
1638 + idStr + " at " + parser.getPositionDescription());
1639 }
1640 if (packageSetting != null) {
1641 packageSetting.uidError = "true".equals(uidError);
1642 packageSetting.installerPackageName = installerPackageName;
1643 packageSetting.nativeLibraryPathString = nativeLibraryPathStr;
1644 final String enabledStr = parser.getAttributeValue(null, "enabled");
1645 if (enabledStr != null) {
1646 if (enabledStr.equalsIgnoreCase("true")) {
1647 packageSetting.enabled = COMPONENT_ENABLED_STATE_ENABLED;
1648 } else if (enabledStr.equalsIgnoreCase("false")) {
1649 packageSetting.enabled = COMPONENT_ENABLED_STATE_DISABLED;
1650 } else if (enabledStr.equalsIgnoreCase("default")) {
1651 packageSetting.enabled = COMPONENT_ENABLED_STATE_DEFAULT;
1652 } else {
1653 PackageManagerService.reportSettingsProblem(Log.WARN,
1654 "Error in package manager settings: package " + name
1655 + " has bad enabled value: " + idStr + " at "
1656 + parser.getPositionDescription());
1657 }
1658 } else {
1659 packageSetting.enabled = COMPONENT_ENABLED_STATE_DEFAULT;
1660 }
1661 final String installStatusStr = parser.getAttributeValue(null, "installStatus");
1662 if (installStatusStr != null) {
1663 if (installStatusStr.equalsIgnoreCase("false")) {
1664 packageSetting.installStatus = PackageSettingBase.PKG_INSTALL_INCOMPLETE;
1665 } else {
1666 packageSetting.installStatus = PackageSettingBase.PKG_INSTALL_COMPLETE;
1667 }
1668 }
1669
1670 int outerDepth = parser.getDepth();
1671 int type;
1672 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
1673 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
1674 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
1675 continue;
1676 }
1677
1678 String tagName = parser.getName();
1679 if (tagName.equals("disabled-components")) {
Kenny Root447106f2011-03-23 11:00:15 -07001680 readDisabledComponentsLPw(packageSetting, parser);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001681 } else if (tagName.equals("enabled-components")) {
Kenny Root447106f2011-03-23 11:00:15 -07001682 readEnabledComponentsLPw(packageSetting, parser);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001683 } else if (tagName.equals("sigs")) {
1684 packageSetting.signatures.readXml(parser, mPastSignatures);
1685 } else if (tagName.equals("perms")) {
Kenny Root447106f2011-03-23 11:00:15 -07001686 readGrantedPermissionsLPw(parser, packageSetting.grantedPermissions);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001687 packageSetting.permissionsFixed = true;
1688 } else {
1689 PackageManagerService.reportSettingsProblem(Log.WARN,
1690 "Unknown element under <package>: " + parser.getName());
1691 XmlUtils.skipCurrentTag(parser);
1692 }
1693 }
1694 } else {
1695 XmlUtils.skipCurrentTag(parser);
1696 }
1697 }
1698
Kenny Root447106f2011-03-23 11:00:15 -07001699 private void readDisabledComponentsLPw(PackageSettingBase packageSetting, XmlPullParser parser)
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001700 throws IOException, XmlPullParserException {
1701 int outerDepth = parser.getDepth();
1702 int type;
1703 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
1704 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
1705 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
1706 continue;
1707 }
1708
1709 String tagName = parser.getName();
1710 if (tagName.equals("item")) {
1711 String name = parser.getAttributeValue(null, "name");
1712 if (name != null) {
1713 packageSetting.disabledComponents.add(name.intern());
1714 } else {
1715 PackageManagerService.reportSettingsProblem(Log.WARN,
1716 "Error in package manager settings: <disabled-components> has"
1717 + " no name at " + parser.getPositionDescription());
1718 }
1719 } else {
1720 PackageManagerService.reportSettingsProblem(Log.WARN,
1721 "Unknown element under <disabled-components>: " + parser.getName());
1722 }
1723 XmlUtils.skipCurrentTag(parser);
1724 }
1725 }
1726
Kenny Root447106f2011-03-23 11:00:15 -07001727 private void readEnabledComponentsLPw(PackageSettingBase packageSetting, XmlPullParser parser)
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001728 throws IOException, XmlPullParserException {
1729 int outerDepth = parser.getDepth();
1730 int type;
1731 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
1732 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
1733 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
1734 continue;
1735 }
1736
1737 String tagName = parser.getName();
1738 if (tagName.equals("item")) {
1739 String name = parser.getAttributeValue(null, "name");
1740 if (name != null) {
1741 packageSetting.enabledComponents.add(name.intern());
1742 } else {
1743 PackageManagerService.reportSettingsProblem(Log.WARN,
1744 "Error in package manager settings: <enabled-components> has"
1745 + " no name at " + parser.getPositionDescription());
1746 }
1747 } else {
1748 PackageManagerService.reportSettingsProblem(Log.WARN,
1749 "Unknown element under <enabled-components>: " + parser.getName());
1750 }
1751 XmlUtils.skipCurrentTag(parser);
1752 }
1753 }
1754
Kenny Root447106f2011-03-23 11:00:15 -07001755 private void readSharedUserLPw(XmlPullParser parser) throws XmlPullParserException, IOException {
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001756 String name = null;
1757 String idStr = null;
1758 int pkgFlags = 0;
1759 SharedUserSetting su = null;
1760 try {
1761 name = parser.getAttributeValue(null, "name");
1762 idStr = parser.getAttributeValue(null, "userId");
1763 int userId = idStr != null ? Integer.parseInt(idStr) : 0;
1764 if ("true".equals(parser.getAttributeValue(null, "system"))) {
1765 pkgFlags |= ApplicationInfo.FLAG_SYSTEM;
1766 }
1767 if (name == null) {
1768 PackageManagerService.reportSettingsProblem(Log.WARN,
1769 "Error in package manager settings: <shared-user> has no name at "
1770 + parser.getPositionDescription());
1771 } else if (userId == 0) {
1772 PackageManagerService.reportSettingsProblem(Log.WARN,
1773 "Error in package manager settings: shared-user " + name
1774 + " has bad userId " + idStr + " at "
1775 + parser.getPositionDescription());
1776 } else {
Kenny Root447106f2011-03-23 11:00:15 -07001777 if ((su = addSharedUserLPw(name.intern(), userId, pkgFlags)) == null) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001778 PackageManagerService
1779 .reportSettingsProblem(Log.ERROR, "Occurred while parsing settings at "
1780 + parser.getPositionDescription());
1781 }
1782 }
1783 } catch (NumberFormatException e) {
1784 PackageManagerService.reportSettingsProblem(Log.WARN,
1785 "Error in package manager settings: package " + name + " has bad userId "
1786 + idStr + " at " + parser.getPositionDescription());
1787 }
1788 ;
1789
1790 if (su != null) {
1791 int outerDepth = parser.getDepth();
1792 int type;
1793 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
1794 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
1795 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
1796 continue;
1797 }
1798
1799 String tagName = parser.getName();
1800 if (tagName.equals("sigs")) {
1801 su.signatures.readXml(parser, mPastSignatures);
1802 } else if (tagName.equals("perms")) {
Kenny Root447106f2011-03-23 11:00:15 -07001803 readGrantedPermissionsLPw(parser, su.grantedPermissions);
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001804 } else {
1805 PackageManagerService.reportSettingsProblem(Log.WARN,
1806 "Unknown element under <shared-user>: " + parser.getName());
1807 XmlUtils.skipCurrentTag(parser);
1808 }
1809 }
1810
1811 } else {
1812 XmlUtils.skipCurrentTag(parser);
1813 }
1814 }
1815
Kenny Root447106f2011-03-23 11:00:15 -07001816 private void readGrantedPermissionsLPw(XmlPullParser parser, HashSet<String> outPerms)
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001817 throws IOException, XmlPullParserException {
1818 int outerDepth = parser.getDepth();
1819 int type;
1820 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
1821 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
1822 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
1823 continue;
1824 }
1825
1826 String tagName = parser.getName();
1827 if (tagName.equals("item")) {
1828 String name = parser.getAttributeValue(null, "name");
1829 if (name != null) {
1830 outPerms.add(name.intern());
1831 } else {
1832 PackageManagerService.reportSettingsProblem(Log.WARN,
1833 "Error in package manager settings: <perms> has" + " no name at "
1834 + parser.getPositionDescription());
1835 }
1836 } else {
1837 PackageManagerService.reportSettingsProblem(Log.WARN,
1838 "Unknown element under <perms>: " + parser.getName());
1839 }
1840 XmlUtils.skipCurrentTag(parser);
1841 }
1842 }
1843
Kenny Root447106f2011-03-23 11:00:15 -07001844 private void readPreferredActivitiesLPw(XmlPullParser parser) throws XmlPullParserException,
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001845 IOException {
1846 int outerDepth = parser.getDepth();
1847 int type;
1848 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
1849 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
1850 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
1851 continue;
1852 }
1853
1854 String tagName = parser.getName();
1855 if (tagName.equals("item")) {
1856 PreferredActivity pa = new PreferredActivity(parser);
1857 if (pa.mPref.getParseError() == null) {
1858 mPreferredActivities.addFilter(pa);
1859 } else {
1860 PackageManagerService.reportSettingsProblem(Log.WARN,
1861 "Error in package manager settings: <preferred-activity> "
1862 + pa.mPref.getParseError() + " at "
1863 + parser.getPositionDescription());
1864 }
1865 } else {
1866 PackageManagerService.reportSettingsProblem(Log.WARN,
1867 "Unknown element under <preferred-activities>: " + parser.getName());
1868 XmlUtils.skipCurrentTag(parser);
1869 }
1870 }
1871 }
1872
1873 // Returns -1 if we could not find an available UserId to assign
Kenny Root447106f2011-03-23 11:00:15 -07001874 private int newUserIdLPw(Object obj) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001875 // Let's be stupidly inefficient for now...
1876 final int N = mUserIds.size();
1877 for (int i = 0; i < N; i++) {
1878 if (mUserIds.get(i) == null) {
1879 mUserIds.set(i, obj);
1880 return PackageManagerService.FIRST_APPLICATION_UID + i;
1881 }
1882 }
1883
1884 // None left?
1885 if (N >= PackageManagerService.MAX_APPLICATION_UIDS) {
1886 return -1;
1887 }
1888
1889 mUserIds.add(obj);
1890 return PackageManagerService.FIRST_APPLICATION_UID + N;
1891 }
1892
Kenny Root447106f2011-03-23 11:00:15 -07001893 public PackageSetting getDisabledSystemPkgLPr(String name) {
1894 PackageSetting ps = mDisabledSysPackages.get(name);
1895 return ps;
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001896 }
1897
Kenny Root447106f2011-03-23 11:00:15 -07001898 boolean isEnabledLPr(ComponentInfo componentInfo, int flags) {
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001899 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
1900 return true;
1901 }
1902 final PackageSetting packageSettings = mPackages.get(componentInfo.packageName);
1903 if (PackageManagerService.DEBUG_SETTINGS) {
1904 Log.v(PackageManagerService.TAG, "isEnabledLock - packageName = " + componentInfo.packageName
1905 + " componentName = " + componentInfo.name);
1906 Log.v(PackageManagerService.TAG, "enabledComponents: "
1907 + Arrays.toString(packageSettings.enabledComponents.toArray()));
1908 Log.v(PackageManagerService.TAG, "disabledComponents: "
1909 + Arrays.toString(packageSettings.disabledComponents.toArray()));
1910 }
1911 if (packageSettings == null) {
1912 return false;
1913 }
1914 if (packageSettings.enabled == COMPONENT_ENABLED_STATE_DISABLED
1915 || (packageSettings.pkg != null && !packageSettings.pkg.applicationInfo.enabled
1916 && packageSettings.enabled == COMPONENT_ENABLED_STATE_DEFAULT)) {
1917 return false;
1918 }
1919 if (packageSettings.enabledComponents.contains(componentInfo.name)) {
1920 return true;
1921 }
1922 if (packageSettings.disabledComponents.contains(componentInfo.name)) {
1923 return false;
1924 }
1925 return componentInfo.enabled;
1926 }
Kenny Root447106f2011-03-23 11:00:15 -07001927
1928 String getInstallerPackageNameLPr(String packageName) {
1929 final PackageSetting pkg = mPackages.get(packageName);
1930 if (pkg == null) {
1931 throw new IllegalArgumentException("Unknown package: " + packageName);
1932 }
1933 return pkg.installerPackageName;
1934 }
1935
1936 int getApplicationEnabledSettingLPr(String packageName) {
1937 final PackageSetting pkg = mPackages.get(packageName);
1938 if (pkg == null) {
1939 throw new IllegalArgumentException("Unknown package: " + packageName);
1940 }
1941 return pkg.enabled;
1942 }
1943
1944 int getComponentEnabledSettingLPr(ComponentName componentName) {
1945 final String packageName = componentName.getPackageName();
1946 final PackageSetting pkg = mPackages.get(packageName);
1947 if (pkg == null) {
1948 throw new IllegalArgumentException("Unknown component: " + componentName);
1949 }
1950 final String classNameStr = componentName.getClassName();
1951 return pkg.getCurrentEnabledStateLPr(classNameStr);
1952 }
1953
1954 boolean setPackageStoppedStateLPw(String packageName, boolean stopped,
1955 boolean allowedByPermission, int uid) {
1956 final PackageSetting pkgSetting = mPackages.get(packageName);
1957 if (pkgSetting == null) {
1958 throw new IllegalArgumentException("Unknown package: " + packageName);
1959 }
1960 if (!allowedByPermission && (uid != pkgSetting.userId)) {
1961 throw new SecurityException(
1962 "Permission Denial: attempt to change stopped state from pid="
1963 + Binder.getCallingPid()
1964 + ", uid=" + uid + ", package uid=" + pkgSetting.userId);
1965 }
1966 if (DEBUG_STOPPED) {
1967 if (stopped) {
1968 RuntimeException e = new RuntimeException("here");
1969 e.fillInStackTrace();
1970 Slog.i(TAG, "Stopping package " + packageName, e);
1971 }
1972 }
1973 if (pkgSetting.stopped != stopped) {
1974 pkgSetting.stopped = stopped;
1975 pkgSetting.pkg.mSetStopped = stopped;
1976 if (pkgSetting.notLaunched) {
1977 if (pkgSetting.installerPackageName != null) {
1978 PackageManagerService.sendPackageBroadcast(Intent.ACTION_PACKAGE_FIRST_LAUNCH,
1979 pkgSetting.name, null,
1980 pkgSetting.installerPackageName, null);
1981 }
1982 pkgSetting.notLaunched = false;
1983 }
1984 return true;
1985 }
1986 return false;
1987 }
1988
1989 void dumpPackagesLPr(PrintWriter pw, String packageName, DumpState dumpState) {
1990 final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
1991 final Date date = new Date();
1992 boolean printedSomething = false;
1993 for (final PackageSetting ps : mPackages.values()) {
1994 if (packageName != null && !packageName.equals(ps.realName)
1995 && !packageName.equals(ps.name)) {
1996 continue;
1997 }
1998
1999 if (packageName != null) {
2000 dumpState.setSharedUser(ps.sharedUser);
2001 }
2002
2003 if (!printedSomething) {
2004 if (dumpState.onTitlePrinted())
2005 pw.println(" ");
2006 pw.println("Packages:");
2007 printedSomething = true;
2008 }
2009 pw.print(" Package [");
2010 pw.print(ps.realName != null ? ps.realName : ps.name);
2011 pw.print("] (");
2012 pw.print(Integer.toHexString(System.identityHashCode(ps)));
2013 pw.println("):");
2014
2015 if (ps.realName != null) {
2016 pw.print(" compat name=");
2017 pw.println(ps.name);
2018 }
2019
2020 pw.print(" userId="); pw.print(ps.userId);
2021 pw.print(" gids="); pw.println(PackageManagerService.arrayToString(ps.gids));
2022 pw.print(" sharedUser="); pw.println(ps.sharedUser);
2023 pw.print(" pkg="); pw.println(ps.pkg);
2024 pw.print(" codePath="); pw.println(ps.codePathString);
2025 pw.print(" resourcePath="); pw.println(ps.resourcePathString);
2026 pw.print(" nativeLibraryPath="); pw.println(ps.nativeLibraryPathString);
2027 pw.print(" versionCode="); pw.println(ps.versionCode);
2028 if (ps.pkg != null) {
2029 pw.print(" versionName="); pw.println(ps.pkg.mVersionName);
2030 pw.print(" dataDir="); pw.println(ps.pkg.applicationInfo.dataDir);
2031 pw.print(" targetSdk="); pw.println(ps.pkg.applicationInfo.targetSdkVersion);
2032 if (ps.pkg.mOperationPending) {
2033 pw.println(" mOperationPending=true");
2034 }
2035 pw.print(" supportsScreens=[");
2036 boolean first = true;
2037 if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS) != 0) {
2038 if (!first)
2039 pw.print(", ");
2040 first = false;
2041 pw.print("small");
2042 }
2043 if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS) != 0) {
2044 if (!first)
2045 pw.print(", ");
2046 first = false;
2047 pw.print("medium");
2048 }
2049 if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS) != 0) {
2050 if (!first)
2051 pw.print(", ");
2052 first = false;
2053 pw.print("large");
2054 }
2055 if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS) != 0) {
2056 if (!first)
2057 pw.print(", ");
2058 first = false;
2059 pw.print("xlarge");
2060 }
2061 if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS) != 0) {
2062 if (!first)
2063 pw.print(", ");
2064 first = false;
2065 pw.print("resizeable");
2066 }
2067 if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES) != 0) {
2068 if (!first)
2069 pw.print(", ");
2070 first = false;
2071 pw.print("anyDensity");
2072 }
2073 }
2074 pw.println("]");
2075 pw.print(" timeStamp=");
2076 date.setTime(ps.timeStamp);
2077 pw.println(sdf.format(date));
2078 pw.print(" firstInstallTime=");
2079 date.setTime(ps.firstInstallTime);
2080 pw.println(sdf.format(date));
2081 pw.print(" lastUpdateTime=");
2082 date.setTime(ps.lastUpdateTime);
2083 pw.println(sdf.format(date));
2084 if (ps.installerPackageName != null) {
2085 pw.print(" installerPackageName="); pw.println(ps.installerPackageName);
2086 }
2087 pw.print(" signatures="); pw.println(ps.signatures);
2088 pw.print(" permissionsFixed="); pw.print(ps.permissionsFixed);
2089 pw.print(" haveGids="); pw.println(ps.haveGids);
2090 pw.print(" pkgFlags=0x"); pw.print(Integer.toHexString(ps.pkgFlags));
2091 pw.print(" installStatus="); pw.print(ps.installStatus);
2092 pw.print(" stopped="); pw.print(ps.stopped);
2093 pw.print(" enabled="); pw.println(ps.enabled);
2094 if (ps.disabledComponents.size() > 0) {
2095 pw.println(" disabledComponents:");
2096 for (String s : ps.disabledComponents) {
2097 pw.print(" "); pw.println(s);
2098 }
2099 }
2100 if (ps.enabledComponents.size() > 0) {
2101 pw.println(" enabledComponents:");
2102 for (String s : ps.enabledComponents) {
2103 pw.print(" "); pw.println(s);
2104 }
2105 }
2106 if (ps.grantedPermissions.size() > 0) {
2107 pw.println(" grantedPermissions:");
2108 for (String s : ps.grantedPermissions) {
2109 pw.print(" "); pw.println(s);
2110 }
2111 }
2112 }
2113
2114 printedSomething = false;
2115 if (mRenamedPackages.size() > 0) {
2116 for (final HashMap.Entry<String, String> e : mRenamedPackages.entrySet()) {
2117 if (packageName != null && !packageName.equals(e.getKey())
2118 && !packageName.equals(e.getValue())) {
2119 continue;
2120 }
2121 if (!printedSomething) {
2122 if (dumpState.onTitlePrinted())
2123 pw.println(" ");
2124 pw.println("Renamed packages:");
2125 printedSomething = true;
2126 }
2127 pw.print(" ");
2128 pw.print(e.getKey());
2129 pw.print(" -> ");
2130 pw.println(e.getValue());
2131 }
2132 }
2133
2134 printedSomething = false;
2135 if (mDisabledSysPackages.size() > 0) {
2136 for (final PackageSetting ps : mDisabledSysPackages.values()) {
2137 if (packageName != null && !packageName.equals(ps.realName)
2138 && !packageName.equals(ps.name)) {
2139 continue;
2140 }
2141 if (!printedSomething) {
2142 if (dumpState.onTitlePrinted())
2143 pw.println(" ");
2144 pw.println("Hidden system packages:");
2145 printedSomething = true;
2146 }
2147 pw.print(" Package [");
2148 pw.print(ps.realName != null ? ps.realName : ps.name);
2149 pw.print("] (");
2150 pw.print(Integer.toHexString(System.identityHashCode(ps)));
2151 pw.println("):");
2152 if (ps.realName != null) {
2153 pw.print(" compat name=");
2154 pw.println(ps.name);
2155 }
2156 pw.print(" userId=");
2157 pw.println(ps.userId);
2158 pw.print(" sharedUser=");
2159 pw.println(ps.sharedUser);
2160 pw.print(" codePath=");
2161 pw.println(ps.codePathString);
2162 pw.print(" resourcePath=");
2163 pw.println(ps.resourcePathString);
2164 }
2165 }
2166 }
2167
2168 void dumpPermissionsLPr(PrintWriter pw, String packageName, DumpState dumpState) {
2169 boolean printedSomething = false;
2170 for (BasePermission p : mPermissions.values()) {
2171 if (packageName != null && !packageName.equals(p.sourcePackage)) {
2172 continue;
2173 }
2174 if (!printedSomething) {
2175 if (dumpState.onTitlePrinted())
2176 pw.println(" ");
2177 pw.println("Permissions:");
2178 printedSomething = true;
2179 }
2180 pw.print(" Permission ["); pw.print(p.name); pw.print("] (");
2181 pw.print(Integer.toHexString(System.identityHashCode(p)));
2182 pw.println("):");
2183 pw.print(" sourcePackage="); pw.println(p.sourcePackage);
2184 pw.print(" uid="); pw.print(p.uid);
2185 pw.print(" gids="); pw.print(PackageManagerService.arrayToString(p.gids));
2186 pw.print(" type="); pw.print(p.type);
2187 pw.print(" prot="); pw.println(p.protectionLevel);
2188 if (p.packageSetting != null) {
2189 pw.print(" packageSetting="); pw.println(p.packageSetting);
2190 }
2191 if (p.perm != null) {
2192 pw.print(" perm="); pw.println(p.perm);
2193 }
2194 }
2195 }
2196
2197 void dumpSharedUsersLPr(PrintWriter pw, String packageName, DumpState dumpState) {
2198 boolean printedSomething = false;
2199 for (SharedUserSetting su : mSharedUsers.values()) {
2200 if (packageName != null && su != dumpState.getSharedUser()) {
2201 continue;
2202 }
2203 if (!printedSomething) {
2204 if (dumpState.onTitlePrinted())
2205 pw.println(" ");
2206 pw.println("Shared users:");
2207 printedSomething = true;
2208 }
2209 pw.print(" SharedUser [");
2210 pw.print(su.name);
2211 pw.print("] (");
2212 pw.print(Integer.toHexString(System.identityHashCode(su)));
2213 pw.println("):");
2214 pw.print(" userId=");
2215 pw.print(su.userId);
2216 pw.print(" gids=");
2217 pw.println(PackageManagerService.arrayToString(su.gids));
2218 pw.println(" grantedPermissions:");
2219 for (String s : su.grantedPermissions) {
2220 pw.print(" ");
2221 pw.println(s);
2222 }
2223 }
2224 }
2225
2226 void dumpReadMessagesLPr(PrintWriter pw, DumpState dumpState) {
2227 pw.println("Settings parse messages:");
2228 pw.print(mReadMessages.toString());
2229 }
Kenny Rootcf0b38c2011-03-22 14:17:59 -07002230}