summaryrefslogtreecommitdiffstats
path: root/services/java/com/android/server/UiModeManagerService.java
diff options
context:
space:
mode:
Diffstat (limited to 'services/java/com/android/server/UiModeManagerService.java')
-rw-r--r--services/java/com/android/server/UiModeManagerService.java334
1 files changed, 159 insertions, 175 deletions
diff --git a/services/java/com/android/server/UiModeManagerService.java b/services/java/com/android/server/UiModeManagerService.java
index e9e3163..0e456f1 100644
--- a/services/java/com/android/server/UiModeManagerService.java
+++ b/services/java/com/android/server/UiModeManagerService.java
@@ -37,11 +37,9 @@ import android.os.Handler;
import android.os.PowerManager;
import android.os.RemoteException;
import android.os.ServiceManager;
-import android.os.SystemClock;
import android.os.UserHandle;
import android.provider.Settings;
-import android.service.dreams.DreamService;
-import android.service.dreams.IDreamManager;
+import android.service.dreams.Sandman;
import android.util.Slog;
import java.io.FileDescriptor;
@@ -51,7 +49,7 @@ import com.android.internal.R;
import com.android.internal.app.DisableCarModeActivity;
import com.android.server.TwilightService.TwilightState;
-class UiModeManagerService extends IUiModeManager.Stub {
+final class UiModeManagerService extends IUiModeManager.Stub {
private static final String TAG = UiModeManager.class.getSimpleName();
private static final boolean LOG = false;
@@ -59,9 +57,6 @@ class UiModeManagerService extends IUiModeManager.Stub {
private static final boolean ENABLE_LAUNCH_CAR_DOCK_APP = true;
private static final boolean ENABLE_LAUNCH_DESK_DOCK_APP = true;
- private static final int DEFAULT_SCREENSAVER_ENABLED = 1;
- private static final int DEFAULT_SCREENSAVER_ACTIVATED_ON_DOCK = 1;
-
private final Context mContext;
private final TwilightService mTwilightService;
private final Handler mHandler = new Handler();
@@ -186,57 +181,79 @@ class UiModeManagerService extends IUiModeManager.Stub {
mTwilightService.registerListener(mTwilightListener, mHandler);
}
+ @Override // Binder call
public void disableCarMode(int flags) {
- synchronized (mLock) {
- setCarModeLocked(false);
- if (mSystemReady) {
- updateLocked(0, flags);
+ final long ident = Binder.clearCallingIdentity();
+ try {
+ synchronized (mLock) {
+ setCarModeLocked(false);
+ if (mSystemReady) {
+ updateLocked(0, flags);
+ }
}
+ } finally {
+ Binder.restoreCallingIdentity(ident);
}
}
+ @Override // Binder call
public void enableCarMode(int flags) {
- synchronized (mLock) {
- setCarModeLocked(true);
- if (mSystemReady) {
- updateLocked(flags, 0);
+ final long ident = Binder.clearCallingIdentity();
+ try {
+ synchronized (mLock) {
+ setCarModeLocked(true);
+ if (mSystemReady) {
+ updateLocked(flags, 0);
+ }
}
+ } finally {
+ Binder.restoreCallingIdentity(ident);
}
}
+ @Override // Binder call
public int getCurrentModeType() {
- synchronized (mLock) {
- return mCurUiMode & Configuration.UI_MODE_TYPE_MASK;
+ final long ident = Binder.clearCallingIdentity();
+ try {
+ synchronized (mLock) {
+ return mCurUiMode & Configuration.UI_MODE_TYPE_MASK;
+ }
+ } finally {
+ Binder.restoreCallingIdentity(ident);
}
}
- public void setNightMode(int mode) throws RemoteException {
- synchronized (mLock) {
- switch (mode) {
- case UiModeManager.MODE_NIGHT_NO:
- case UiModeManager.MODE_NIGHT_YES:
- case UiModeManager.MODE_NIGHT_AUTO:
- break;
- default:
- throw new IllegalArgumentException("Unknown mode: " + mode);
- }
- if (!isDoingNightMode()) {
- return;
- }
+ @Override // Binder call
+ public void setNightMode(int mode) {
+ switch (mode) {
+ case UiModeManager.MODE_NIGHT_NO:
+ case UiModeManager.MODE_NIGHT_YES:
+ case UiModeManager.MODE_NIGHT_AUTO:
+ break;
+ default:
+ throw new IllegalArgumentException("Unknown mode: " + mode);
+ }
- if (mNightMode != mode) {
- long ident = Binder.clearCallingIdentity();
- Settings.Secure.putInt(mContext.getContentResolver(),
- Settings.Secure.UI_NIGHT_MODE, mode);
- Binder.restoreCallingIdentity(ident);
- mNightMode = mode;
- updateLocked(0, 0);
+ final long ident = Binder.clearCallingIdentity();
+ try {
+ synchronized (mLock) {
+ if (isDoingNightModeLocked() && mNightMode != mode) {
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.UI_NIGHT_MODE, mode);
+ mNightMode = mode;
+ updateLocked(0, 0);
+ }
}
+ } finally {
+ Binder.restoreCallingIdentity(ident);
}
}
- public int getNightMode() throws RemoteException {
- return mNightMode;
+ @Override // Binder call
+ public int getNightMode() {
+ synchronized (mLock) {
+ return mNightMode;
+ }
}
void systemReady() {
@@ -248,17 +265,17 @@ class UiModeManagerService extends IUiModeManager.Stub {
}
}
- boolean isDoingNightMode() {
+ private boolean isDoingNightModeLocked() {
return mCarModeEnabled || mDockState != Intent.EXTRA_DOCK_STATE_UNDOCKED;
}
- void setCarModeLocked(boolean enabled) {
+ private void setCarModeLocked(boolean enabled) {
if (mCarModeEnabled != enabled) {
mCarModeEnabled = enabled;
}
}
- void updateDockState(int newState) {
+ private void updateDockState(int newState) {
synchronized (mLock) {
if (newState != mDockState) {
mDockState = newState;
@@ -270,7 +287,7 @@ class UiModeManagerService extends IUiModeManager.Stub {
}
}
- final static boolean isDeskDockState(int state) {
+ private static boolean isDeskDockState(int state) {
switch (state) {
case Intent.EXTRA_DOCK_STATE_DESK:
case Intent.EXTRA_DOCK_STATE_LE_DESK:
@@ -281,7 +298,7 @@ class UiModeManagerService extends IUiModeManager.Stub {
}
}
- final void updateConfigurationLocked() {
+ private void updateConfigurationLocked() {
int uiMode = mTelevision ? Configuration.UI_MODE_TYPE_TELEVISION : mDefaultUiModeType;
if (mCarModeEnabled) {
uiMode = Configuration.UI_MODE_TYPE_CAR;
@@ -315,7 +332,7 @@ class UiModeManagerService extends IUiModeManager.Stub {
}
}
- final void sendConfigurationLocked() {
+ private void sendConfigurationLocked() {
if (mSetUiMode != mConfiguration.uiMode) {
mSetUiMode = mConfiguration.uiMode;
@@ -327,105 +344,99 @@ class UiModeManagerService extends IUiModeManager.Stub {
}
}
- final void updateLocked(int enableFlags, int disableFlags) {
- long ident = Binder.clearCallingIdentity();
+ private void updateLocked(int enableFlags, int disableFlags) {
+ String action = null;
+ String oldAction = null;
+ if (mLastBroadcastState == Intent.EXTRA_DOCK_STATE_CAR) {
+ adjustStatusBarCarModeLocked();
+ oldAction = UiModeManager.ACTION_EXIT_CAR_MODE;
+ } else if (isDeskDockState(mLastBroadcastState)) {
+ oldAction = UiModeManager.ACTION_EXIT_DESK_MODE;
+ }
- try {
- String action = null;
- String oldAction = null;
- if (mLastBroadcastState == Intent.EXTRA_DOCK_STATE_CAR) {
+ if (mCarModeEnabled) {
+ if (mLastBroadcastState != Intent.EXTRA_DOCK_STATE_CAR) {
adjustStatusBarCarModeLocked();
- oldAction = UiModeManager.ACTION_EXIT_CAR_MODE;
- } else if (isDeskDockState(mLastBroadcastState)) {
- oldAction = UiModeManager.ACTION_EXIT_DESK_MODE;
- }
- if (mCarModeEnabled) {
- if (mLastBroadcastState != Intent.EXTRA_DOCK_STATE_CAR) {
- adjustStatusBarCarModeLocked();
-
- if (oldAction != null) {
- mContext.sendBroadcastAsUser(new Intent(oldAction), UserHandle.ALL);
- }
- mLastBroadcastState = Intent.EXTRA_DOCK_STATE_CAR;
- action = UiModeManager.ACTION_ENTER_CAR_MODE;
+ if (oldAction != null) {
+ mContext.sendBroadcastAsUser(new Intent(oldAction), UserHandle.ALL);
}
- } else if (isDeskDockState(mDockState)) {
- if (!isDeskDockState(mLastBroadcastState)) {
- if (oldAction != null) {
- mContext.sendBroadcastAsUser(new Intent(oldAction), UserHandle.ALL);
- }
- mLastBroadcastState = mDockState;
- action = UiModeManager.ACTION_ENTER_DESK_MODE;
+ mLastBroadcastState = Intent.EXTRA_DOCK_STATE_CAR;
+ action = UiModeManager.ACTION_ENTER_CAR_MODE;
+ }
+ } else if (isDeskDockState(mDockState)) {
+ if (!isDeskDockState(mLastBroadcastState)) {
+ if (oldAction != null) {
+ mContext.sendBroadcastAsUser(new Intent(oldAction), UserHandle.ALL);
}
- } else {
- mLastBroadcastState = Intent.EXTRA_DOCK_STATE_UNDOCKED;
- action = oldAction;
+ mLastBroadcastState = mDockState;
+ action = UiModeManager.ACTION_ENTER_DESK_MODE;
}
+ } else {
+ mLastBroadcastState = Intent.EXTRA_DOCK_STATE_UNDOCKED;
+ action = oldAction;
+ }
- if (action != null) {
- if (LOG) {
- Slog.v(TAG, String.format(
- "updateLocked: preparing broadcast: action=%s enable=0x%08x disable=0x%08x",
- action, enableFlags, disableFlags));
- }
+ if (action != null) {
+ if (LOG) {
+ Slog.v(TAG, String.format(
+ "updateLocked: preparing broadcast: action=%s enable=0x%08x disable=0x%08x",
+ action, enableFlags, disableFlags));
+ }
- // Send the ordered broadcast; the result receiver will receive after all
- // broadcasts have been sent. If any broadcast receiver changes the result
- // code from the initial value of RESULT_OK, then the result receiver will
- // not launch the corresponding dock application. This gives apps a chance
- // to override the behavior and stay in their app even when the device is
- // placed into a dock.
- Intent intent = new Intent(action);
- intent.putExtra("enableFlags", enableFlags);
- intent.putExtra("disableFlags", disableFlags);
- mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT, null,
- mResultReceiver, null, Activity.RESULT_OK, null, null);
-
- // Attempting to make this transition a little more clean, we are going
- // to hold off on doing a configuration change until we have finished
- // the broadcast and started the home activity.
- mHoldingConfiguration = true;
- updateConfigurationLocked();
- } else {
- String category = null;
- if (mCarModeEnabled) {
- if (ENABLE_LAUNCH_CAR_DOCK_APP
- && (enableFlags & UiModeManager.ENABLE_CAR_MODE_GO_CAR_HOME) != 0) {
- category = Intent.CATEGORY_CAR_DOCK;
- }
- } else if (isDeskDockState(mDockState)) {
- if (ENABLE_LAUNCH_DESK_DOCK_APP
- && (enableFlags & UiModeManager.ENABLE_CAR_MODE_GO_CAR_HOME) != 0) {
- category = Intent.CATEGORY_DESK_DOCK;
- }
- } else {
- if ((disableFlags & UiModeManager.DISABLE_CAR_MODE_GO_HOME) != 0) {
- category = Intent.CATEGORY_HOME;
- }
+ // Send the ordered broadcast; the result receiver will receive after all
+ // broadcasts have been sent. If any broadcast receiver changes the result
+ // code from the initial value of RESULT_OK, then the result receiver will
+ // not launch the corresponding dock application. This gives apps a chance
+ // to override the behavior and stay in their app even when the device is
+ // placed into a dock.
+ Intent intent = new Intent(action);
+ intent.putExtra("enableFlags", enableFlags);
+ intent.putExtra("disableFlags", disableFlags);
+ mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT, null,
+ mResultReceiver, null, Activity.RESULT_OK, null, null);
+
+ // Attempting to make this transition a little more clean, we are going
+ // to hold off on doing a configuration change until we have finished
+ // the broadcast and started the home activity.
+ mHoldingConfiguration = true;
+ updateConfigurationLocked();
+ } else {
+ String category = null;
+ if (mCarModeEnabled) {
+ if (ENABLE_LAUNCH_CAR_DOCK_APP
+ && (enableFlags & UiModeManager.ENABLE_CAR_MODE_GO_CAR_HOME) != 0) {
+ category = Intent.CATEGORY_CAR_DOCK;
}
-
- if (LOG) {
- Slog.v(TAG, "updateLocked: null action, mDockState="
- + mDockState +", category=" + category);
+ } else if (isDeskDockState(mDockState)) {
+ if (ENABLE_LAUNCH_DESK_DOCK_APP
+ && (enableFlags & UiModeManager.ENABLE_CAR_MODE_GO_CAR_HOME) != 0) {
+ category = Intent.CATEGORY_DESK_DOCK;
}
+ } else {
+ if ((disableFlags & UiModeManager.DISABLE_CAR_MODE_GO_HOME) != 0) {
+ category = Intent.CATEGORY_HOME;
+ }
+ }
- sendConfigurationAndStartDreamOrDockAppLocked(category);
+ if (LOG) {
+ Slog.v(TAG, "updateLocked: null action, mDockState="
+ + mDockState +", category=" + category);
}
- // keep screen on when charging and in car mode
- boolean keepScreenOn = mCharging &&
- ((mCarModeEnabled && mCarModeKeepsScreenOn) ||
- (mCurUiMode == Configuration.UI_MODE_TYPE_DESK && mDeskModeKeepsScreenOn));
- if (keepScreenOn != mWakeLock.isHeld()) {
- if (keepScreenOn) {
- mWakeLock.acquire();
- } else {
- mWakeLock.release();
- }
+ sendConfigurationAndStartDreamOrDockAppLocked(category);
+ }
+
+ // keep screen on when charging and in car mode
+ boolean keepScreenOn = mCharging &&
+ ((mCarModeEnabled && mCarModeKeepsScreenOn) ||
+ (mCurUiMode == Configuration.UI_MODE_TYPE_DESK && mDeskModeKeepsScreenOn));
+ if (keepScreenOn != mWakeLock.isHeld()) {
+ if (keepScreenOn) {
+ mWakeLock.acquire();
+ } else {
+ mWakeLock.release();
}
- } finally {
- Binder.restoreCallingIdentity(ident);
}
}
@@ -480,18 +491,20 @@ class UiModeManagerService extends IUiModeManager.Stub {
// activity manager take care of both the start and config
// change.
Intent homeIntent = buildHomeIntent(category);
- try {
- int result = ActivityManagerNative.getDefault().startActivityWithConfig(
- null, homeIntent, null, null, null, 0, 0,
- mConfiguration, null, UserHandle.USER_CURRENT);
- if (result >= ActivityManager.START_SUCCESS) {
- dockAppStarted = true;
- } else if (result != ActivityManager.START_INTENT_NOT_RESOLVED) {
- Slog.e(TAG, "Could not start dock app: " + homeIntent
- + ", startActivityWithConfig result " + result);
+ if (Sandman.shouldStartDockApp(mContext, homeIntent)) {
+ try {
+ int result = ActivityManagerNative.getDefault().startActivityWithConfig(
+ null, homeIntent, null, null, null, 0, 0,
+ mConfiguration, null, UserHandle.USER_CURRENT);
+ if (result >= ActivityManager.START_SUCCESS) {
+ dockAppStarted = true;
+ } else if (result != ActivityManager.START_INTENT_NOT_RESOLVED) {
+ Slog.e(TAG, "Could not start dock app: " + homeIntent
+ + ", startActivityWithConfig result " + result);
+ }
+ } catch (RemoteException ex) {
+ Slog.e(TAG, "Could not start dock app: " + homeIntent, ex);
}
- } catch (RemoteException ex) {
- Slog.e(TAG, "Could not start dock app: " + homeIntent, ex);
}
}
@@ -499,44 +512,15 @@ class UiModeManagerService extends IUiModeManager.Stub {
sendConfigurationLocked();
// If we did not start a dock app, then start dreaming if supported.
- if (category != null && !dockAppStarted
- && isScreenSaverEnabled() && isScreenSaverActivatedOnDock()) {
- Slog.i(TAG, "Activating dream while docked.");
- try {
- IDreamManager dreamManagerService = IDreamManager.Stub.asInterface(
- ServiceManager.getService(DreamService.DREAM_SERVICE));
- if (dreamManagerService != null && !dreamManagerService.isDreaming()) {
- // Wake up.
- // The power manager will wake up the system when it starts receiving power
- // but there is a race between that happening and the UI mode manager
- // starting a dream. We want the system to already be awake
- // by the time this happens. Otherwise the dream may not start.
- mPowerManager.wakeUp(SystemClock.uptimeMillis());
-
- // Dream.
- dreamManagerService.dream();
- }
- } catch (RemoteException ex) {
- Slog.e(TAG, "Could not start dream when docked.", ex);
- }
+ if (category != null && !dockAppStarted) {
+ Sandman.startDreamWhenDockedIfAppropriate(mContext);
}
}
- private boolean isScreenSaverEnabled() {
- return Settings.Secure.getIntForUser(mContext.getContentResolver(),
- Settings.Secure.SCREENSAVER_ENABLED, DEFAULT_SCREENSAVER_ENABLED,
- UserHandle.USER_CURRENT) != 0;
- }
-
- private boolean isScreenSaverActivatedOnDock() {
- return Settings.Secure.getIntForUser(mContext.getContentResolver(),
- Settings.Secure.SCREENSAVER_ACTIVATE_ON_DOCK,
- DEFAULT_SCREENSAVER_ACTIVATED_ON_DOCK, UserHandle.USER_CURRENT) != 0;
- }
-
private void adjustStatusBarCarModeLocked() {
if (mStatusBarManager == null) {
- mStatusBarManager = (StatusBarManager) mContext.getSystemService(Context.STATUS_BAR_SERVICE);
+ mStatusBarManager = (StatusBarManager)
+ mContext.getSystemService(Context.STATUS_BAR_SERVICE);
}
// Fear not: StatusBarManagerService manages a list of requests to disable
@@ -581,7 +565,7 @@ class UiModeManagerService extends IUiModeManager.Stub {
private void updateTwilight() {
synchronized (mLock) {
- if (isDoingNightMode() && mNightMode == UiModeManager.MODE_NIGHT_AUTO) {
+ if (isDoingNightModeLocked() && mNightMode == UiModeManager.MODE_NIGHT_AUTO) {
updateComputedNightModeLocked();
updateLocked(0, 0);
}