summaryrefslogtreecommitdiffstats
path: root/services/java
diff options
context:
space:
mode:
authorSvetoslav Ganov <svetoslavganov@google.com>2011-03-02 19:17:06 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-03-02 19:17:06 -0800
commit2da0c5826df40d9f528bfe7d2e762c3fbea03f7f (patch)
treeba23d0ff87d035f5933c5aa3ba082f985221899d /services/java
parentf99c91c9cf780f925d493e60e1ec479073580434 (diff)
parent54d068ec6af0ee6d261a135400efe6816c6f5ffe (diff)
downloadframeworks_base-2da0c5826df40d9f528bfe7d2e762c3fbea03f7f.zip
frameworks_base-2da0c5826df40d9f528bfe7d2e762c3fbea03f7f.tar.gz
frameworks_base-2da0c5826df40d9f528bfe7d2e762c3fbea03f7f.tar.bz2
Merge "Add system wide management of core settings"
Diffstat (limited to 'services/java')
-rw-r--r--services/java/com/android/server/am/ActivityManagerService.java20
-rw-r--r--services/java/com/android/server/am/CoreSettingsObserver.java106
2 files changed, 125 insertions, 1 deletions
diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java
index e6dfb7f..40417b1 100644
--- a/services/java/com/android/server/am/ActivityManagerService.java
+++ b/services/java/com/android/server/am/ActivityManagerService.java
@@ -717,6 +717,8 @@ public final class ActivityManagerService extends ActivityManagerNative
final private SparseArray<HashMap<Uri, UriPermission>> mGrantedUriPermissions
= new SparseArray<HashMap<Uri, UriPermission>>();
+ CoreSettingsObserver mCoreSettingsObserver;
+
/**
* Thread-local storage used to carry caller permissions over through
* indirect content-provider access.
@@ -3589,7 +3591,8 @@ public final class ActivityManagerService extends ActivityManagerNative
app.instrumentationClass, app.instrumentationProfileFile,
app.instrumentationArguments, app.instrumentationWatcher, testMode,
isRestrictedBackupMode || !normalMode,
- mConfiguration, getCommonServicesLocked());
+ mConfiguration, getCommonServicesLocked(),
+ mCoreSettingsObserver.getCoreSettingsLocked());
updateLruProcessLocked(app, false, true);
app.lastRequestedGc = app.lastLowMemory = SystemClock.uptimeMillis();
} catch (Exception e) {
@@ -5772,6 +5775,8 @@ public final class ActivityManagerService extends ActivityManagerNative
if (providers != null) {
mSystemThread.installSystemProviders(providers);
}
+
+ mSelf.mCoreSettingsObserver = new CoreSettingsObserver(mSelf);
}
/**
@@ -13030,4 +13035,17 @@ public final class ActivityManagerService extends ActivityManagerNative
public void monitor() {
synchronized (this) { }
}
+
+ public void onCoreSettingsChange(Bundle settings) {
+ for (int i = mLruProcesses.size() - 1; i >= 0; i--) {
+ ProcessRecord processRecord = mLruProcesses.get(i);
+ try {
+ if (processRecord.thread != null) {
+ processRecord.thread.setCoreSettings(settings);
+ }
+ } catch (RemoteException re) {
+ /* ignore */
+ }
+ }
+ }
}
diff --git a/services/java/com/android/server/am/CoreSettingsObserver.java b/services/java/com/android/server/am/CoreSettingsObserver.java
new file mode 100644
index 0000000..25db84a
--- /dev/null
+++ b/services/java/com/android/server/am/CoreSettingsObserver.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2006-2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.am;
+
+import android.content.Context;
+import android.database.ContentObserver;
+import android.net.Uri;
+import android.os.Bundle;
+import android.provider.Settings;
+import android.provider.Settings.SettingNotFoundException;
+import android.util.Log;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Helper class for watching a set of core settings which the framework
+ * propagates to application processes to avoid multiple lookups and potentially
+ * disk I/O operations. Note: This class assumes that all core settings reside
+ * in {@link Settings.Secure}.
+ */
+class CoreSettingsObserver extends ContentObserver {
+ private static final String LOG_TAG = CoreSettingsObserver.class.getSimpleName();
+
+ // mapping form property name to its type
+ private static final Map<String, Class<?>> sCoreSettingToTypeMap = new HashMap<
+ String, Class<?>>();
+ static {
+ sCoreSettingToTypeMap.put(Settings.Secure.LONG_PRESS_TIMEOUT, int.class);
+ // add other core settings here...
+ }
+
+ private final Bundle mCoreSettings = new Bundle();
+
+ private final ActivityManagerService mActivityManagerService;
+
+ public CoreSettingsObserver(ActivityManagerService activityManagerService) {
+ super(activityManagerService.mHandler);
+ mActivityManagerService = activityManagerService;
+ beginObserveCoreSettings();
+ populateCoreSettings(mCoreSettings);
+ }
+
+ public Bundle getCoreSettingsLocked() {
+ return (Bundle) mCoreSettings.clone();
+ }
+
+ @Override
+ public void onChange(boolean selfChange) {
+ synchronized (mActivityManagerService) {
+ populateCoreSettings(mCoreSettings);
+ mActivityManagerService.onCoreSettingsChange(mCoreSettings);
+ }
+ }
+
+ private void beginObserveCoreSettings() {
+ for (String setting : sCoreSettingToTypeMap.keySet()) {
+ Uri uri = Settings.Secure.getUriFor(setting);
+ mActivityManagerService.mContext.getContentResolver().registerContentObserver(
+ uri, false, this);
+ }
+ }
+
+ private void populateCoreSettings(Bundle snapshot) {
+ Context context = mActivityManagerService.mContext;
+ for (Map.Entry<String, Class<?>> entry : sCoreSettingToTypeMap.entrySet()) {
+ String setting = entry.getKey();
+ Class<?> type = entry.getValue();
+ try {
+ if (type == String.class) {
+ String value = Settings.Secure.getString(context.getContentResolver(),
+ setting);
+ snapshot.putString(setting, value);
+ } else if (type == int.class) {
+ int value = Settings.Secure.getInt(context.getContentResolver(),
+ setting);
+ snapshot.putInt(setting, value);
+ } else if (type == float.class) {
+ float value = Settings.Secure.getFloat(context.getContentResolver(),
+ setting);
+ snapshot.putFloat(setting, value);
+ } else if (type == long.class) {
+ long value = Settings.Secure.getLong(context.getContentResolver(),
+ setting);
+ snapshot.putLong(setting, value);
+ }
+ } catch (SettingNotFoundException snfe) {
+ Log.w(LOG_TAG, "Cannot find setting \"" + setting + "\"", snfe);
+ }
+ }
+ }
+}