summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorAmith Yamasani <yamasani@google.com>2010-09-22 16:11:59 -0700
committerAmith Yamasani <yamasani@google.com>2010-09-22 16:11:59 -0700
commit8b61983ee81f4819319d22e05ddf473a9c64be77 (patch)
tree3e84806bdbd27b8b3532afee1f5a908165a8e142 /services
parent4374b23d6be406710b91be746229e6c548613410 (diff)
downloadframeworks_base-8b61983ee81f4819319d22e05ddf473a9c64be77.zip
frameworks_base-8b61983ee81f4819319d22e05ddf473a9c64be77.tar.gz
frameworks_base-8b61983ee81f4819319d22e05ddf473a9c64be77.tar.bz2
Fix NPE in PowerManagerService on boot, if some settings are corrupted.
Bug: 2715038 Change-Id: I10c08b359ff3cde732c37eb6dff0877cdb021cd9
Diffstat (limited to 'services')
-rw-r--r--services/java/com/android/server/PowerManagerService.java25
1 files changed, 17 insertions, 8 deletions
diff --git a/services/java/com/android/server/PowerManagerService.java b/services/java/com/android/server/PowerManagerService.java
index 8ab1bb8..5d32b74 100644
--- a/services/java/com/android/server/PowerManagerService.java
+++ b/services/java/com/android/server/PowerManagerService.java
@@ -25,6 +25,7 @@ import android.app.IActivityManager;
import android.content.BroadcastReceiver;
import android.content.ContentQueryMap;
import android.content.ContentResolver;
+import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
@@ -36,6 +37,7 @@ import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
+import android.os.BatteryManager;
import android.os.BatteryStats;
import android.os.Binder;
import android.os.Environment;
@@ -109,6 +111,9 @@ class PowerManagerService extends IPowerManager.Stub
// Cached secure settings; see updateSettingsValues()
private int mShortKeylightDelay = SHORT_KEYLIGHT_DELAY_DEFAULT;
+ // Default timeout for screen off, if not found in settings database = 15 seconds.
+ private static final int DEFAULT_SCREEN_OFF_TIMEOUT = 15000;
+
// flags for setPowerState
private static final int SCREEN_ON_BIT = 0x00000001;
private static final int SCREEN_BRIGHT_BIT = 0x00000002;
@@ -411,24 +416,28 @@ class PowerManagerService extends IPowerManager.Stub
}
private class SettingsObserver implements Observer {
- private int getInt(String name) {
- return mSettings.getValues(name).getAsInteger(Settings.System.VALUE);
+ private int getInt(String name, int defValue) {
+ ContentValues values = mSettings.getValues(name);
+ Integer iVal = values != null ? values.getAsInteger(Settings.System.VALUE) : null;
+ return iVal != null ? iVal : defValue;
}
public void update(Observable o, Object arg) {
synchronized (mLocks) {
- // STAY_ON_WHILE_PLUGGED_IN
- mStayOnConditions = getInt(STAY_ON_WHILE_PLUGGED_IN);
+ // STAY_ON_WHILE_PLUGGED_IN, default to when plugged into AC
+ mStayOnConditions = getInt(STAY_ON_WHILE_PLUGGED_IN,
+ BatteryManager.BATTERY_PLUGGED_AC);
updateWakeLockLocked();
- // SCREEN_OFF_TIMEOUT
- mScreenOffTimeoutSetting = getInt(SCREEN_OFF_TIMEOUT);
+ // SCREEN_OFF_TIMEOUT, default to 15 seconds
+ mScreenOffTimeoutSetting = getInt(SCREEN_OFF_TIMEOUT, DEFAULT_SCREEN_OFF_TIMEOUT);
// DIM_SCREEN
//mDimScreen = getInt(DIM_SCREEN) != 0;
- // SCREEN_BRIGHTNESS_MODE
- setScreenBrightnessMode(getInt(SCREEN_BRIGHTNESS_MODE));
+ // SCREEN_BRIGHTNESS_MODE, default to manual
+ setScreenBrightnessMode(getInt(SCREEN_BRIGHTNESS_MODE,
+ Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL));
// recalculate everything
setScreenOffTimeoutsLocked();