diff options
Diffstat (limited to 'services')
5 files changed, 139 insertions, 66 deletions
diff --git a/services/java/com/android/server/AppWidgetService.java b/services/java/com/android/server/AppWidgetService.java index 3c46954..f8b8ecc 100644 --- a/services/java/com/android/server/AppWidgetService.java +++ b/services/java/com/android/server/AppWidgetService.java @@ -816,7 +816,10 @@ class AppWidgetService extends IAppWidgetService.Stub temp.delete(); } - writeStateToFileLocked(temp); + if (!writeStateToFileLocked(temp)) { + Log.w(TAG, "Failed to persist new settings"); + return; + } //noinspection ResultOfMethodCallIgnored real.delete(); @@ -824,7 +827,7 @@ class AppWidgetService extends IAppWidgetService.Stub temp.renameTo(real); } - void writeStateToFileLocked(File file) { + boolean writeStateToFileLocked(File file) { FileOutputStream stream = null; int N; @@ -877,6 +880,7 @@ class AppWidgetService extends IAppWidgetService.Stub out.endDocument(); stream.close(); + return true; } catch (IOException e) { try { if (stream != null) { @@ -889,6 +893,7 @@ class AppWidgetService extends IAppWidgetService.Stub //noinspection ResultOfMethodCallIgnored file.delete(); } + return false; } } diff --git a/services/java/com/android/server/PackageManagerService.java b/services/java/com/android/server/PackageManagerService.java index 867f215..5eb78c3 100644 --- a/services/java/com/android/server/PackageManagerService.java +++ b/services/java/com/android/server/PackageManagerService.java @@ -178,6 +178,7 @@ class PackageManagerService extends IPackageManager.Stub { final File mFrameworkDir; final File mSystemAppDir; final File mAppInstallDir; + final File mDalvikCacheDir; // Directory containing the private parts (e.g. code and non-resource assets) of forward-locked // apps. @@ -438,8 +439,11 @@ class PackageManagerService extends IPackageManager.Stub { final HashSet<String> libFiles = new HashSet<String>(); mFrameworkDir = new File(Environment.getRootDirectory(), "framework"); + mDalvikCacheDir = new File(dataDir, "dalvik-cache"); if (mInstaller != null) { + boolean didDexOpt = false; + /** * Out of paranoia, ensure that everything in the boot class * path has been dexed. @@ -452,6 +456,7 @@ class PackageManagerService extends IPackageManager.Stub { if (dalvik.system.DexFile.isDexOptNeeded(paths[i])) { libFiles.add(paths[i]); mInstaller.dexopt(paths[i], Process.SYSTEM_UID, true); + didDexOpt = true; } } catch (FileNotFoundException e) { Log.w(TAG, "Boot class path not found: " + paths[i]); @@ -474,6 +479,7 @@ class PackageManagerService extends IPackageManager.Stub { if (dalvik.system.DexFile.isDexOptNeeded(lib)) { libFiles.add(lib); mInstaller.dexopt(lib, Process.SYSTEM_UID, true); + didDexOpt = true; } } catch (FileNotFoundException e) { Log.w(TAG, "Library not found: " + lib); @@ -493,7 +499,7 @@ class PackageManagerService extends IPackageManager.Stub { * run from a non-root shell. */ String[] frameworkFiles = mFrameworkDir.list(); - if (frameworkFiles != null && mInstaller != null) { + if (frameworkFiles != null) { for (int i=0; i<frameworkFiles.length; i++) { File libPath = new File(mFrameworkDir, frameworkFiles[i]); String path = libPath.getPath(); @@ -508,6 +514,7 @@ class PackageManagerService extends IPackageManager.Stub { try { if (dalvik.system.DexFile.isDexOptNeeded(path)) { mInstaller.dexopt(path, Process.SYSTEM_UID, true); + didDexOpt = true; } } catch (FileNotFoundException e) { Log.w(TAG, "Jar not found: " + path); @@ -516,6 +523,25 @@ class PackageManagerService extends IPackageManager.Stub { } } } + + if (didDexOpt) { + // If we had to do a dexopt of one of the previous + // things, then something on the system has changed. + // Consider this significant, and wipe away all other + // existing dexopt files to ensure we don't leave any + // dangling around. + String[] files = mDalvikCacheDir.list(); + if (files != null) { + for (int i=0; i<files.length; i++) { + String fn = files[i]; + if (fn.startsWith("data@app@") + || fn.startsWith("data@app-private@")) { + Log.i(TAG, "Pruning dalvik file: " + fn); + (new File(mDalvikCacheDir, fn)).delete(); + } + } + } + } } mFrameworkInstallObserver = new AppDirObserver( @@ -641,6 +667,27 @@ class PackageManagerService extends IPackageManager.Stub { final File permFile = new File(Environment.getRootDirectory(), "etc/permissions/platform.xml"); readPermissionsFromXml(permFile); + + StringBuilder sb = new StringBuilder(128); + sb.append("Libs:"); + Iterator<String> it = mSharedLibraries.keySet().iterator(); + while (it.hasNext()) { + sb.append(' '); + String name = it.next(); + sb.append(name); + sb.append(':'); + sb.append(mSharedLibraries.get(name)); + } + Log.i(TAG, sb.toString()); + + sb.setLength(0); + sb.append("Features:"); + it = mAvailableFeatures.keySet().iterator(); + while (it.hasNext()) { + sb.append(' '); + sb.append(it.next()); + } + Log.i(TAG, sb.toString()); } private void readPermissionsFromXml(File permFile) { @@ -730,7 +777,7 @@ class PackageManagerService extends IPackageManager.Stub { Log.w(TAG, "<library> without file at " + parser.getPositionDescription()); } else { - Log.i(TAG, "Got library " + lname + " in " + lfile); + //Log.i(TAG, "Got library " + lname + " in " + lfile); mSharedLibraries.put(lname, lfile); } XmlUtils.skipCurrentTag(parser); @@ -742,7 +789,7 @@ class PackageManagerService extends IPackageManager.Stub { Log.w(TAG, "<feature> without name at " + parser.getPositionDescription()); } else { - Log.i(TAG, "Got feature " + fname); + //Log.i(TAG, "Got feature " + fname); FeatureInfo fi = new FeatureInfo(); fi.name = fname; mAvailableFeatures.put(fname, fi); @@ -1974,27 +2021,25 @@ class PackageManagerService extends IPackageManager.Stub { } if ((parseFlags&PackageParser.PARSE_IS_SYSTEM) != 0) { // Check for updated system applications here - if (updatedPkg != null) { - if ((ps != null) && (!ps.codePath.getPath().equals(scanFile.getPath()))) { - if (pkg.mVersionCode <= ps.versionCode) { - // The system package has been updated and the code path does not match - // Ignore entry. Just return - Log.w(TAG, "Package:" + pkg.packageName + - " has been updated. Ignoring the one from path:"+scanFile); - mLastScanError = PackageManager.INSTALL_FAILED_DUPLICATE_PACKAGE; - return null; - } else { - // Delete the older apk pointed to by ps - // At this point, its safely assumed that package installation for - // apps in system partition will go through. If not there won't be a working - // version of the app - synchronized (mPackages) { - // Just remove the loaded entries from package lists. - mPackages.remove(ps.name); - } - deletePackageResourcesLI(ps.name, ps.codePathString, ps.resourcePathString); - mSettings.enableSystemPackageLP(ps.name); + if ((ps != null) && (!ps.codePath.equals(scanFile))) { + if (pkg.mVersionCode < ps.versionCode) { + // The system package has been updated and the code path does not match + // Ignore entry. Just return + Log.w(TAG, "Package:" + pkg.packageName + + " has been updated. Ignoring the one from path:"+scanFile); + mLastScanError = PackageManager.INSTALL_FAILED_DUPLICATE_PACKAGE; + return null; + } else { + // Delete the older apk pointed to by ps + // At this point, its safely assumed that package installation for + // apps in system partition will go through. If not there won't be a working + // version of the app + synchronized (mPackages) { + // Just remove the loaded entries from package lists. + mPackages.remove(ps.name); } + deletePackageResourcesLI(ps.name, ps.codePathString, ps.resourcePathString); + mSettings.enableSystemPackageLP(ps.name); } } } @@ -2004,7 +2049,7 @@ class PackageManagerService extends IPackageManager.Stub { scanMode |= SCAN_FORWARD_LOCKED; } File resFile = destResourceFile; - if ((scanMode & SCAN_FORWARD_LOCKED) != 0) { + if (ps != null && ((scanMode & SCAN_FORWARD_LOCKED) != 0)) { resFile = getFwdLockedResource(ps.name); } // Note that we invoke the following method only if we are about to unpack an application @@ -3814,14 +3859,13 @@ class PackageManagerService extends IPackageManager.Stub { final ApplicationInfo deletedPackageAppInfo = deletedPackage.applicationInfo; final ApplicationInfo installedPackageAppInfo = newPackage.applicationInfo; - if (!deletedPackageAppInfo.sourceDir - .equals(installedPackageAppInfo.sourceDir)) { - new File(deletedPackageAppInfo.sourceDir).delete(); - } - if (!deletedPackageAppInfo.publicSourceDir - .equals(installedPackageAppInfo.publicSourceDir)) { - new File(deletedPackageAppInfo.publicSourceDir).delete(); - } + deletePackageResourcesLI(pkgName, + !deletedPackageAppInfo.sourceDir + .equals(installedPackageAppInfo.sourceDir) + ? deletedPackageAppInfo.sourceDir : null, + !deletedPackageAppInfo.publicSourceDir + .equals(installedPackageAppInfo.publicSourceDir) + ? deletedPackageAppInfo.publicSourceDir : null); //update signature on the new package setting //this should always succeed, since we checked the //signature earlier. @@ -4504,22 +4548,30 @@ class PackageManagerService extends IPackageManager.Stub { private void deletePackageResourcesLI(String packageName, String sourceDir, String publicSourceDir) { - File sourceFile = new File(sourceDir); - if (!sourceFile.exists()) { - Log.w(TAG, "Package source " + sourceDir + " does not exist."); - } - // Delete application's code and resources - sourceFile.delete(); - final File publicSourceFile = new File(publicSourceDir); - if (publicSourceFile.exists()) { - publicSourceFile.delete(); + if (sourceDir != null) { + File sourceFile = new File(sourceDir); + if (!sourceFile.exists()) { + Log.w(TAG, "Package source " + sourceDir + " does not exist."); + } + // Delete application's code and resources + sourceFile.delete(); + if (mInstaller != null) { + int retCode = mInstaller.rmdex(sourceFile.toString()); + if (retCode < 0) { + Log.w(TAG, "Couldn't remove dex file for package: " + + packageName + " at location " + + sourceFile.toString() + ", retcode=" + retCode); + // we don't consider this to be a failure of the core package deletion + } + } } - if (mInstaller != null) { - int retCode = mInstaller.rmdex(sourceFile.toString()); - if (retCode < 0) { - Log.w(TAG, "Couldn't remove dex file for package: " - + packageName + " at location " + sourceFile.toString() + ", retcode=" + retCode); - // we don't consider this to be a failure of the core package deletion + if (publicSourceDir != null && !publicSourceDir.equals(sourceDir)) { + final File publicSourceFile = new File(publicSourceDir); + if (!publicSourceFile.exists()) { + Log.w(TAG, "Package public source " + publicSourceFile + " does not exist."); + } + if (publicSourceFile.exists()) { + publicSourceFile.delete(); } } } @@ -5725,7 +5777,7 @@ class PackageManagerService extends IPackageManager.Stub { } static class GrantedPermissions { - final int pkgFlags; + int pkgFlags; HashSet<String> grantedPermissions = new HashSet<String>(); int[] gids; @@ -6143,10 +6195,10 @@ class PackageManagerService extends IPackageManager.Stub { // Let the app continue with previous uid if code path changes. reportSettingsProblem(Log.WARN, "Package " + name + " codePath changed from " + p.codePath - + " to " + codePath + "; Retaining data and using new code from " + - codePath); + + " to " + codePath + "; Retaining data and using new"); } - } else if (p.sharedUser != sharedUser) { + } + if (p.sharedUser != sharedUser) { reportSettingsProblem(Log.WARN, "Package " + name + " shared user changed from " + (p.sharedUser != null ? p.sharedUser.name : "<nothing>") @@ -6154,6 +6206,13 @@ class PackageManagerService extends IPackageManager.Stub { + (sharedUser != null ? sharedUser.name : "<nothing>") + "; replacing with new"); p = null; + } else { + if ((pkgFlags&ApplicationInfo.FLAG_SYSTEM) != 0) { + // If what we are scanning is a system package, then + // make it so, regardless of whether it was previously + // installed only in the data partition. + p.pkgFlags |= ApplicationInfo.FLAG_SYSTEM; + } } } if (p == null) { @@ -6214,14 +6273,14 @@ class PackageManagerService extends IPackageManager.Stub { // Update code path if needed if (!codePath.toString().equalsIgnoreCase(p.codePathString)) { Log.w(TAG, "Code path for pkg : " + p.pkg.packageName + - " changing form " + p.codePathString + " to " + codePath); + " changing from " + p.codePathString + " to " + codePath); p.codePath = codePath; p.codePathString = codePath.toString(); } //Update resource path if needed if (!resourcePath.toString().equalsIgnoreCase(p.resourcePathString)) { Log.w(TAG, "Resource path for pkg : " + p.pkg.packageName + - " changing form " + p.resourcePathString + " to " + resourcePath); + " changing from " + p.resourcePathString + " to " + resourcePath); p.resourcePath = resourcePath; p.resourcePathString = resourcePath.toString(); } @@ -6470,15 +6529,19 @@ class PackageManagerService extends IPackageManager.Stub { |FileUtils.S_IRGRP|FileUtils.S_IWGRP |FileUtils.S_IROTH, -1, -1); + return; } catch(XmlPullParserException e) { Log.w(TAG, "Unable to write package manager settings, current changes will be lost at reboot", e); - } catch(java.io.IOException e) { Log.w(TAG, "Unable to write package manager settings, current changes will be lost at reboot", e); - } - + // Clean up partially written file + if (mSettingsFilename.exists()) { + if (!mSettingsFilename.delete()) { + Log.i(TAG, "Failed to clean up mangled file: " + mSettingsFilename); + } + } //Debug.stopMethodTracing(); } diff --git a/services/java/com/android/server/WindowManagerService.java b/services/java/com/android/server/WindowManagerService.java index 84ed3ed..e5b6720 100644 --- a/services/java/com/android/server/WindowManagerService.java +++ b/services/java/com/android/server/WindowManagerService.java @@ -233,8 +233,8 @@ public class WindowManagerService extends IWindowManager.Stub mPolicy.enableKeyguard(false); } public void released() { + mPolicy.enableKeyguard(true); synchronized (mKeyguardDisabled) { - mPolicy.enableKeyguard(true); mWaitingUntilKeyguardReenabled = false; mKeyguardDisabled.notifyAll(); } diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java index 6858c75..c62444d 100644 --- a/services/java/com/android/server/am/ActivityManagerService.java +++ b/services/java/com/android/server/am/ActivityManagerService.java @@ -140,7 +140,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen static final boolean DEBUG_PROVIDER = localLOGV || false; static final boolean DEBUG_USER_LEAVING = localLOGV || false; static final boolean DEBUG_RESULTS = localLOGV || false; - static final boolean DEBUG_BACKUP = localLOGV || true; + static final boolean DEBUG_BACKUP = localLOGV || false; static final boolean DEBUG_CONFIGURATION = localLOGV || false; static final boolean VALIDATE_TOKENS = false; static final boolean SHOW_ACTIVITY_START_TIME = true; @@ -2252,7 +2252,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen mHandler.sendMessage(msg); } - reportResumedActivity(next); + reportResumedActivityLocked(next); next.thumbnail = null; setFocusedActivityLocked(next); @@ -2525,7 +2525,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen } } - private void reportResumedActivity(HistoryRecord r) { + private void reportResumedActivityLocked(HistoryRecord r) { //Log.i(TAG, "**** REPORT RESUME: " + r); final int identHash = System.identityHashCode(r); @@ -10340,9 +10340,11 @@ public final class ActivityManagerService extends ActivityManagerNative implemen try { if (DEBUG_SERVICE) Log.v(TAG, "Scheduling start service: " + r.name + " " + r.intent); + mStringBuilder.setLength(0); + r.intent.getIntent().toShortString(mStringBuilder, false, true); EventLog.writeEvent(LOG_AM_CREATE_SERVICE, System.identityHashCode(r), r.shortName, - r.intent.getIntent().toString(), r.app.pid); + mStringBuilder.toString(), r.app.pid); synchronized (r.stats.getBatteryStats()) { r.stats.startLaunchedLocked(); } @@ -11372,8 +11374,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen try { proc.thread.scheduleCreateBackupAgent(app, backupMode); } catch (RemoteException e) { - // !!! TODO: notify the backup manager that we crashed, or rely on - // death notices, or...? + // Will time out on the backup manager side } } else { if (DEBUG_BACKUP) Log.v(TAG, "Agent proc not running, waiting for attach"); @@ -12812,6 +12813,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen if (andResume) { r.results = null; r.newIntents = null; + reportResumedActivityLocked(r); } return true; diff --git a/services/java/com/android/server/am/UsageStatsService.java b/services/java/com/android/server/am/UsageStatsService.java index 66868a3..373b44e 100644 --- a/services/java/com/android/server/am/UsageStatsService.java +++ b/services/java/com/android/server/am/UsageStatsService.java @@ -381,7 +381,10 @@ public final class UsageStatsService extends IUsageStats.Stub { mFileLeaf = getCurrentDateStr(FILE_PREFIX); // Copy current file to back up File backupFile = new File(mFile.getPath() + ".bak"); - mFile.renameTo(backupFile); + if (!mFile.renameTo(backupFile)) { + Log.w(TAG, "Failed to persist new stats"); + return; + } try { // Write mStats to file writeStatsFLOCK(); |