From b3d4cb369e37b1b7e85832cc035226dc7cc8f380 Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Fri, 9 Jan 2015 09:54:06 -0800 Subject: [PATCH] Fix issue #18942959: Phone getting stuck then restarts after unplugging from Audi FastPrintWriter needs to have its own lock for each instance, or else one getting blocked can cause others to block and whacky deadlocks result. Also: - Improve error reporting of SystemConfig to tell you which config file is the problem. - Fix CoreSettingsProvider to not spew errors if a setting is not defined (it should just use a default value). - Get rid of noisy init output of ConditionProviders. - Reduce log noise of starting a process; move some of that information to ProcessRecord to print on demand. Change-Id: I1032d141ddd449968b74ab7b88ab36f2d228ad1a --- .../internal/util/FastPrintWriter.java | 8 +- .../java/com/android/server/SystemConfig.java | 26 +++--- .../server/am/ActivityManagerService.java | 26 ++---- .../server/am/CoreSettingsObserver.java | 82 +++++++++---------- .../com/android/server/am/ProcessRecord.java | 15 +++- .../notification/ConditionProviders.java | 1 - 6 files changed, 78 insertions(+), 80 deletions(-) diff --git a/core/java/com/android/internal/util/FastPrintWriter.java b/core/java/com/android/internal/util/FastPrintWriter.java index c70a2430687b4..c74fea05b6d6c 100644 --- a/core/java/com/android/internal/util/FastPrintWriter.java +++ b/core/java/com/android/internal/util/FastPrintWriter.java @@ -15,7 +15,7 @@ import java.nio.charset.CoderResult; import java.nio.charset.CodingErrorAction; public class FastPrintWriter extends PrintWriter { - private static Writer sDummyWriter = new Writer() { + private static class DummyWriter extends Writer { @Override public void close() throws IOException { UnsupportedOperationException ex @@ -100,7 +100,7 @@ public class FastPrintWriter extends PrintWriter { * if {@code out} is {@code null}. */ public FastPrintWriter(OutputStream out, boolean autoFlush, int bufferLen) { - super(sDummyWriter, autoFlush); + super(new DummyWriter(), autoFlush); if (out == null) { throw new NullPointerException("out is null"); } @@ -169,7 +169,7 @@ public class FastPrintWriter extends PrintWriter { * if {@code wr} is {@code null}. */ public FastPrintWriter(Writer wr, boolean autoFlush, int bufferLen) { - super(sDummyWriter, autoFlush); + super(new DummyWriter(), autoFlush); if (wr == null) { throw new NullPointerException("wr is null"); } @@ -212,7 +212,7 @@ public class FastPrintWriter extends PrintWriter { * if {@code pr} is {@code null}. */ public FastPrintWriter(Printer pr, int bufferLen) { - super(sDummyWriter, true); + super(new DummyWriter(), true); if (pr == null) { throw new NullPointerException("pr is null"); } diff --git a/services/core/java/com/android/server/SystemConfig.java b/services/core/java/com/android/server/SystemConfig.java index eb89f2132f59c..6ad128c982c4b 100644 --- a/services/core/java/com/android/server/SystemConfig.java +++ b/services/core/java/com/android/server/SystemConfig.java @@ -205,8 +205,8 @@ public class SystemConfig { } if (!parser.getName().equals("permissions") && !parser.getName().equals("config")) { - throw new XmlPullParserException("Unexpected start tag: found " + parser.getName() + - ", expected 'permissions' or 'config'"); + throw new XmlPullParserException("Unexpected start tag in " + permFile + + ": found " + parser.getName() + ", expected 'permissions' or 'config'"); } while (true) { @@ -222,7 +222,7 @@ public class SystemConfig { int gid = android.os.Process.getGidForName(gidStr); mGlobalGids = appendInt(mGlobalGids, gid); } else { - Slog.w(TAG, " without gid at " + Slog.w(TAG, " without gid in " + permFile + " at " + parser.getPositionDescription()); } @@ -231,7 +231,7 @@ public class SystemConfig { } else if ("permission".equals(name) && !onlyFeatures) { String perm = parser.getAttributeValue(null, "name"); if (perm == null) { - Slog.w(TAG, " without name at " + Slog.w(TAG, " without name in " + permFile + " at " + parser.getPositionDescription()); XmlUtils.skipCurrentTag(parser); continue; @@ -242,14 +242,14 @@ public class SystemConfig { } else if ("assign-permission".equals(name) && !onlyFeatures) { String perm = parser.getAttributeValue(null, "name"); if (perm == null) { - Slog.w(TAG, " without name at " + Slog.w(TAG, " without name in " + permFile + " at " + parser.getPositionDescription()); XmlUtils.skipCurrentTag(parser); continue; } String uidStr = parser.getAttributeValue(null, "uid"); if (uidStr == null) { - Slog.w(TAG, " without uid at " + Slog.w(TAG, " without uid in " + permFile + " at " + parser.getPositionDescription()); XmlUtils.skipCurrentTag(parser); continue; @@ -257,7 +257,7 @@ public class SystemConfig { int uid = Process.getUidForName(uidStr); if (uid < 0) { Slog.w(TAG, " with unknown uid \"" - + uidStr + "\" at " + + uidStr + " in " + permFile + " at " + parser.getPositionDescription()); XmlUtils.skipCurrentTag(parser); continue; @@ -275,10 +275,10 @@ public class SystemConfig { String lname = parser.getAttributeValue(null, "name"); String lfile = parser.getAttributeValue(null, "file"); if (lname == null) { - Slog.w(TAG, " without name at " + Slog.w(TAG, " without name in " + permFile + " at " + parser.getPositionDescription()); } else if (lfile == null) { - Slog.w(TAG, " without file at " + Slog.w(TAG, " without file in " + permFile + " at " + parser.getPositionDescription()); } else { //Log.i(TAG, "Got library " + lname + " in " + lfile); @@ -297,7 +297,7 @@ public class SystemConfig { allowed = !"true".equals(notLowRam); } if (fname == null) { - Slog.w(TAG, " without name at " + Slog.w(TAG, " without name in " + permFile + " at " + parser.getPositionDescription()); } else if (allowed) { //Log.i(TAG, "Got feature " + fname); @@ -311,7 +311,7 @@ public class SystemConfig { } else if ("unavailable-feature".equals(name)) { String fname = parser.getAttributeValue(null, "name"); if (fname == null) { - Slog.w(TAG, " without name at " + Slog.w(TAG, " without name in " + permFile + " at " + parser.getPositionDescription()); } else { mUnavailableFeatures.add(fname); @@ -322,7 +322,7 @@ public class SystemConfig { } else if ("allow-in-power-save".equals(name) && !onlyFeatures) { String pkgname = parser.getAttributeValue(null, "package"); if (pkgname == null) { - Slog.w(TAG, " without package at " + Slog.w(TAG, " without package in " + permFile + " at " + parser.getPositionDescription()); } else { mAllowInPowerSave.add(pkgname); @@ -333,7 +333,7 @@ public class SystemConfig { } else if ("fixed-ime-app".equals(name) && !onlyFeatures) { String pkgname = parser.getAttributeValue(null, "package"); if (pkgname == null) { - Slog.w(TAG, " without package at " + Slog.w(TAG, " without package in " + permFile + " at " + parser.getPositionDescription()); } else { mFixedImeApps.add(pkgname); diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 97b43532e7ef5..4b7fb2b281713 100755 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -2998,6 +2998,10 @@ public final class ActivityManagerService extends ActivityManagerNative instructionSet = VMRuntime.getInstructionSet(app.info.primaryCpuAbi); } + app.gids = gids; + app.requiredAbi = requiredAbi; + app.instructionSet = instructionSet; + // Start the process. It will either succeed and return a result containing // the PID of the new process, or else throw a RuntimeException. boolean isActivityProcess = (entryPoint == null); @@ -3028,7 +3032,11 @@ public final class ActivityManagerService extends ActivityManagerNative StringBuilder buf = mStringBuilder; buf.setLength(0); buf.append("Start proc "); + buf.append(startResult.pid); + buf.append(':'); buf.append(app.processName); + buf.append('/'); + UserHandle.formatUid(buf, uid); if (!isActivityProcess) { buf.append(" ["); buf.append(entryPoint); @@ -3040,23 +3048,6 @@ public final class ActivityManagerService extends ActivityManagerNative buf.append(" "); buf.append(hostingNameStr); } - buf.append(": pid="); - buf.append(startResult.pid); - buf.append(" uid="); - buf.append(uid); - buf.append(" gids={"); - if (gids != null) { - for (int gi=0; gi> entry : map.entrySet()) { String setting = entry.getKey(); Class type = entry.getValue(); - try { - if (type == String.class) { - final String value; - if (map == sSecureSettingToTypeMap) { - value = Settings.Secure.getString(context.getContentResolver(), setting); - } else if (map == sSystemSettingToTypeMap) { - value = Settings.System.getString(context.getContentResolver(), setting); - } else { - value = Settings.Global.getString(context.getContentResolver(), setting); - } - snapshot.putString(setting, value); - } else if (type == int.class) { - final int value; - if (map == sSecureSettingToTypeMap) { - value = Settings.Secure.getInt(context.getContentResolver(), setting); - } else if (map == sSystemSettingToTypeMap) { - value = Settings.System.getInt(context.getContentResolver(), setting); - } else { - value = Settings.Global.getInt(context.getContentResolver(), setting); - } - snapshot.putInt(setting, value); - } else if (type == float.class) { - final float value; - if (map == sSecureSettingToTypeMap) { - value = Settings.Secure.getFloat(context.getContentResolver(), setting); - } else if (map == sSystemSettingToTypeMap) { - value = Settings.System.getFloat(context.getContentResolver(), setting); - } else { - value = Settings.Global.getFloat(context.getContentResolver(), setting); - } - snapshot.putFloat(setting, value); - } else if (type == long.class) { - final long value; - if (map == sSecureSettingToTypeMap) { - value = Settings.Secure.getLong(context.getContentResolver(), setting); - } else if (map == sSystemSettingToTypeMap) { - value = Settings.System.getLong(context.getContentResolver(), setting); - } else { - value = Settings.Global.getLong(context.getContentResolver(), setting); - } - snapshot.putLong(setting, value); + if (type == String.class) { + final String value; + if (map == sSecureSettingToTypeMap) { + value = Settings.Secure.getString(context.getContentResolver(), setting); + } else if (map == sSystemSettingToTypeMap) { + value = Settings.System.getString(context.getContentResolver(), setting); + } else { + value = Settings.Global.getString(context.getContentResolver(), setting); } - } catch (SettingNotFoundException snfe) { - Log.w(LOG_TAG, "Cannot find setting \"" + setting + "\"", snfe); + snapshot.putString(setting, value); + } else if (type == int.class) { + final int value; + if (map == sSecureSettingToTypeMap) { + value = Settings.Secure.getInt(context.getContentResolver(), setting, 0); + } else if (map == sSystemSettingToTypeMap) { + value = Settings.System.getInt(context.getContentResolver(), setting, 0); + } else { + value = Settings.Global.getInt(context.getContentResolver(), setting, 0); + } + snapshot.putInt(setting, value); + } else if (type == float.class) { + final float value; + if (map == sSecureSettingToTypeMap) { + value = Settings.Secure.getFloat(context.getContentResolver(), setting, 0); + } else if (map == sSystemSettingToTypeMap) { + value = Settings.System.getFloat(context.getContentResolver(), setting, 0); + } else { + value = Settings.Global.getFloat(context.getContentResolver(), setting, 0); + } + snapshot.putFloat(setting, value); + } else if (type == long.class) { + final long value; + if (map == sSecureSettingToTypeMap) { + value = Settings.Secure.getLong(context.getContentResolver(), setting, 0); + } else if (map == sSystemSettingToTypeMap) { + value = Settings.System.getLong(context.getContentResolver(), setting, 0); + } else { + value = Settings.Global.getLong(context.getContentResolver(), setting, 0); + } + snapshot.putLong(setting, value); } } } diff --git a/services/core/java/com/android/server/am/ProcessRecord.java b/services/core/java/com/android/server/am/ProcessRecord.java index 7c48f3e00fac1..a6c616ae8de2c 100644 --- a/services/core/java/com/android/server/am/ProcessRecord.java +++ b/services/core/java/com/android/server/am/ProcessRecord.java @@ -64,6 +64,9 @@ final class ProcessRecord { ProcessStats.ProcessState baseProcessTracker; BatteryStatsImpl.Uid.Proc curProcBatteryStats; int pid; // The process of this application; 0 if none + int[] gids; // The gids this process was launched with + String requiredAbi; // The ABI this process was launched with + String instructionSet; // The instruction set this process was launched with boolean starting; // True if the process is being started long lastActivityTime; // For managing the LRU list long lastPssTime; // Last time we retrieved PSS data @@ -183,7 +186,17 @@ final class ProcessRecord { if (uid != info.uid) { pw.print(" ISOLATED uid="); pw.print(uid); } - pw.println(); + pw.print(" gids={"); + if (gids != null) { + for (int gi=0; gi