diff options
author | Dianne Hackborn <hackbod@google.com> | 2012-09-24 11:36:57 -0700 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2012-09-24 14:15:14 -0700 |
commit | 139748fd724b482e2c012a6ec44d1c5abc0c0e97 (patch) | |
tree | aef4a2d661092f667e3c932e195c6bacd1208663 /core/java | |
parent | 4249be40bd1c51dae37c27f9450ed01f19edcbef (diff) | |
download | frameworks_base-139748fd724b482e2c012a6ec44d1c5abc0c0e97.zip frameworks_base-139748fd724b482e2c012a6ec44d1c5abc0c0e97.tar.gz frameworks_base-139748fd724b482e2c012a6ec44d1c5abc0c0e97.tar.bz2 |
Fix issue #7215984: java.lang.RuntimeException: Unable to create...
...service com.android.systemui.SystemUIService: java.lang.NullPointerException
- Don't acquire the activity manager lock in handleIncomingUser(),
there is really no need to do so.
- Rework the settings provider client side cache code to not hold
locks while calling into the provider.
I also changed the way the settings provider uses system properties
so that there is one property for all users. We can't do one per
user, since the system property name space is limited with a fixed
size. And we don't really need to do that; the worse that happens
by combining all users is that if one running user changes one of its
settings, all other running users will think they need to reload
settings when they go to fetch them next.
Change-Id: I13b90b832310d117eb6d721aacd122cfba7d749a
Diffstat (limited to 'core/java')
-rw-r--r-- | core/java/android/provider/Settings.java | 124 |
1 files changed, 47 insertions, 77 deletions
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index f41e12c..9aae1ec 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -764,10 +764,6 @@ public final class Settings { return true; } - public boolean putString(ContentResolver cr, String name, String value) { - return putStringForUser(cr, name, value, UserHandle.myUserId()); - } - public String getStringForUser(ContentResolver cr, String name, final int userHandle) { final boolean isSelf = (userHandle == UserHandle.myUserId()); if (isSelf) { @@ -855,10 +851,6 @@ public final class Settings { if (c != null) c.close(); } } - - public String getString(ContentResolver cr, String name) { - return getStringForUser(cr, name, UserHandle.myUserId()); - } } /** @@ -869,8 +861,17 @@ public final class Settings { public static final class System extends NameValueTable { public static final String SYS_PROP_SETTING_VERSION = "sys.settings_system_version"; - // Populated lazily, guarded by class object: - private static NameValueCache sNameValueCache = null; + /** + * The content:// style URL for this table + */ + public static final Uri CONTENT_URI = + Uri.parse("content://" + AUTHORITY + "/system"); + + private static final NameValueCache sNameValueCache = new NameValueCache( + SYS_PROP_SETTING_VERSION, + CONTENT_URI, + CALL_METHOD_GET_SYSTEM, + CALL_METHOD_PUT_SYSTEM); private static final HashSet<String> MOVED_TO_SECURE; static { @@ -937,28 +938,18 @@ public final class Settings { MOVED_TO_GLOBAL.add(Settings.Global.MODE_RINGER); } - private static void lazyInitCache() { - if (sNameValueCache == null) { - sNameValueCache = new NameValueCache( - SYS_PROP_SETTING_VERSION + '_' + UserHandle.myUserId(), - CONTENT_URI, - CALL_METHOD_GET_SYSTEM, - CALL_METHOD_PUT_SYSTEM); - } - } - /** * Look up a name in the database. * @param resolver to access the database with * @param name to look up in the table * @return the corresponding value, or null if not present */ - public synchronized static String getString(ContentResolver resolver, String name) { + public static String getString(ContentResolver resolver, String name) { return getStringForUser(resolver, name, UserHandle.myUserId()); } /** @hide */ - public synchronized static String getStringForUser(ContentResolver resolver, String name, + public static String getStringForUser(ContentResolver resolver, String name, int userHandle) { if (MOVED_TO_SECURE.contains(name)) { Log.w(TAG, "Setting " + name + " has moved from android.provider.Settings.System" @@ -970,7 +961,6 @@ public final class Settings { + " to android.provider.Settings.Global, returning read-only value."); return Global.getStringForUser(resolver, name, userHandle); } - lazyInitCache(); return sNameValueCache.getStringForUser(resolver, name, userHandle); } @@ -998,7 +988,6 @@ public final class Settings { + " to android.provider.Settings.Global, value is unchanged."); return false; } - lazyInitCache(); return sNameValueCache.putStringForUser(resolver, name, value, userHandle); } @@ -1368,12 +1357,6 @@ public final class Settings { } /** - * The content:// style URL for this table - */ - public static final Uri CONTENT_URI = - Uri.parse("content://" + AUTHORITY + "/system"); - - /** * @deprecated Use {@link android.provider.Settings.Global#STAY_ON_WHILE_PLUGGED_IN} instead */ @Deprecated @@ -2549,8 +2532,18 @@ public final class Settings { public static final class Secure extends NameValueTable { public static final String SYS_PROP_SETTING_VERSION = "sys.settings_secure_version"; + /** + * The content:// style URL for this table + */ + public static final Uri CONTENT_URI = + Uri.parse("content://" + AUTHORITY + "/secure"); + // Populated lazily, guarded by class object: - private static NameValueCache sNameValueCache = null; + private static final NameValueCache sNameValueCache = new NameValueCache( + SYS_PROP_SETTING_VERSION, + CONTENT_URI, + CALL_METHOD_GET_SECURE, + CALL_METHOD_PUT_SECURE); private static ILockSettings sLockSettings = null; @@ -2654,28 +2647,18 @@ public final class Settings { MOVED_TO_GLOBAL.add(Settings.Global.WTF_IS_FATAL); } - private static void lazyInitCache() { - if (sNameValueCache == null) { - sNameValueCache = new NameValueCache( - SYS_PROP_SETTING_VERSION + '_' + UserHandle.myUserId(), - CONTENT_URI, - CALL_METHOD_GET_SECURE, - CALL_METHOD_PUT_SECURE); - } - } - /** * Look up a name in the database. * @param resolver to access the database with * @param name to look up in the table * @return the corresponding value, or null if not present */ - public synchronized static String getString(ContentResolver resolver, String name) { + public static String getString(ContentResolver resolver, String name) { return getStringForUser(resolver, name, UserHandle.myUserId()); } /** @hide */ - public synchronized static String getStringForUser(ContentResolver resolver, String name, + public static String getStringForUser(ContentResolver resolver, String name, int userHandle) { if (MOVED_TO_GLOBAL.contains(name)) { Log.w(TAG, "Setting " + name + " has moved from android.provider.Settings.Secure" @@ -2683,21 +2666,23 @@ public final class Settings { return Global.getStringForUser(resolver, name, userHandle); } - if (sLockSettings == null) { - sLockSettings = ILockSettings.Stub.asInterface( - (IBinder) ServiceManager.getService("lock_settings")); - sIsSystemProcess = Process.myUid() == Process.SYSTEM_UID; - } - if (sLockSettings != null && !sIsSystemProcess - && MOVED_TO_LOCK_SETTINGS.contains(name)) { - try { - return sLockSettings.getString(name, "0", userHandle); - } catch (RemoteException re) { - // Fall through + if (MOVED_TO_LOCK_SETTINGS.contains(name)) { + synchronized (Secure.class) { + if (sLockSettings == null) { + sLockSettings = ILockSettings.Stub.asInterface( + (IBinder) ServiceManager.getService("lock_settings")); + sIsSystemProcess = Process.myUid() == Process.SYSTEM_UID; + } + } + if (sLockSettings != null && !sIsSystemProcess) { + try { + return sLockSettings.getString(name, "0", userHandle); + } catch (RemoteException re) { + // Fall through + } } } - lazyInitCache(); return sNameValueCache.getStringForUser(resolver, name, userHandle); } @@ -2720,7 +2705,6 @@ public final class Settings { + " to android.provider.Settings.Global"); return Global.putStringForUser(resolver, name, value, userHandle); } - lazyInitCache(); return sNameValueCache.putStringForUser(resolver, name, value, userHandle); } @@ -3001,12 +2985,6 @@ public final class Settings { } /** - * The content:// style URL for this table - */ - public static final Uri CONTENT_URI = - Uri.parse("content://" + AUTHORITY + "/secure"); - - /** * @deprecated Use {@link android.provider.Settings.Global#DEVELOPMENT_SETTINGS_ENABLED} * instead */ @@ -5765,17 +5743,11 @@ public final class Settings { // Populated lazily, guarded by class object: - private static NameValueCache sNameValueCache = null; - - private static void lazyInitCache() { - if (sNameValueCache == null) { - sNameValueCache = new NameValueCache( - SYS_PROP_SETTING_VERSION, - CONTENT_URI, - CALL_METHOD_GET_GLOBAL, - CALL_METHOD_PUT_GLOBAL); - } - } + private static NameValueCache sNameValueCache = new NameValueCache( + SYS_PROP_SETTING_VERSION, + CONTENT_URI, + CALL_METHOD_GET_GLOBAL, + CALL_METHOD_PUT_GLOBAL); /** * Look up a name in the database. @@ -5783,14 +5755,13 @@ public final class Settings { * @param name to look up in the table * @return the corresponding value, or null if not present */ - public synchronized static String getString(ContentResolver resolver, String name) { + public static String getString(ContentResolver resolver, String name) { return getStringForUser(resolver, name, UserHandle.myUserId()); } /** @hide */ - public synchronized static String getStringForUser(ContentResolver resolver, String name, + public static String getStringForUser(ContentResolver resolver, String name, int userHandle) { - lazyInitCache(); return sNameValueCache.getStringForUser(resolver, name, userHandle); } @@ -5809,7 +5780,6 @@ public final class Settings { /** @hide */ public static boolean putStringForUser(ContentResolver resolver, String name, String value, int userHandle) { - lazyInitCache(); if (LOCAL_LOGV) { Log.v(TAG, "Global.putString(name=" + name + ", value=" + value + " for " + userHandle); |