Loading core/java/android/service/dreams/DreamManagerInternal.java 0 → 100644 +39 −0 Original line number Original line Diff line number Diff line /* * Copyright (C) 2014 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 android.service.dreams; /** * Dream manager local system service interface. * * @hide Only for use within the system server. */ public abstract class DreamManagerInternal { /** * Called by the power manager to start a dream. */ public abstract void startDream(); /** * Called by the power manager to stop a dream. */ public abstract void stopDream(); /** * Called by the power manager to determine whether a dream is running. */ public abstract boolean isDreaming(); } services/core/java/com/android/server/dreams/DreamManagerService.java +223 −155 Original line number Original line Diff line number Diff line Loading @@ -18,7 +18,9 @@ package com.android.server.dreams; import com.android.internal.util.DumpUtils; import com.android.internal.util.DumpUtils; import com.android.server.FgThread; import com.android.server.FgThread; import com.android.server.SystemService; import android.Manifest; import android.app.ActivityManager; import android.app.ActivityManager; import android.content.BroadcastReceiver; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.ComponentName; Loading @@ -35,6 +37,8 @@ import android.os.PowerManager; import android.os.SystemClock; import android.os.SystemClock; import android.os.UserHandle; import android.os.UserHandle; import android.provider.Settings; import android.provider.Settings; import android.service.dreams.DreamManagerInternal; import android.service.dreams.DreamService; import android.service.dreams.IDreamManager; import android.service.dreams.IDreamManager; import android.util.Slog; import android.util.Slog; Loading @@ -50,7 +54,7 @@ import libcore.util.Objects; * * * @hide * @hide */ */ public final class DreamManagerService extends IDreamManager.Stub { public final class DreamManagerService extends SystemService { private static final boolean DEBUG = false; private static final boolean DEBUG = false; private static final String TAG = "DreamManagerService"; private static final String TAG = "DreamManagerService"; Loading @@ -67,6 +71,7 @@ public final class DreamManagerService extends IDreamManager.Stub { private boolean mCurrentDreamIsTest; private boolean mCurrentDreamIsTest; public DreamManagerService(Context context) { public DreamManagerService(Context context) { super(context); mContext = context; mContext = context; mHandler = new DreamHandler(FgThread.get().getLooper()); mHandler = new DreamHandler(FgThread.get().getLooper()); mController = new DreamController(context, mHandler, mControllerListener); mController = new DreamController(context, mHandler, mControllerListener); Loading @@ -74,7 +79,15 @@ public final class DreamManagerService extends IDreamManager.Stub { mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); } } public void systemRunning() { @Override public void onStart() { publishBinderService(DreamService.DREAM_SERVICE, new BinderService()); publishLocalService(DreamManagerInternal.class, new LocalService()); } @Override public void onBootPhase(int phase) { if (phase == SystemService.PHASE_THIRD_PARTY_APPS_CAN_START) { mContext.registerReceiver(new BroadcastReceiver() { mContext.registerReceiver(new BroadcastReceiver() { @Override @Override public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) { Loading @@ -84,17 +97,9 @@ public final class DreamManagerService extends IDreamManager.Stub { } } }, new IntentFilter(Intent.ACTION_USER_SWITCHED), null, mHandler); }, new IntentFilter(Intent.ACTION_USER_SWITCHED), null, mHandler); } } @Override protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { if (mContext.checkCallingOrSelfPermission("android.permission.DUMP") != PackageManager.PERMISSION_GRANTED) { pw.println("Permission Denial: can't dump DreamManager from pid=" + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()); return; } } private void dumpInternal(PrintWriter pw) { pw.println("DREAM MANAGER (dumpsys dreams)"); pw.println("DREAM MANAGER (dumpsys dreams)"); pw.println(); pw.println(); Loading @@ -112,66 +117,13 @@ public final class DreamManagerService extends IDreamManager.Stub { }, pw, 200); }, pw, 200); } } @Override // Binder call private boolean isDreamingInternal() { public ComponentName[] getDreamComponents() { checkPermission(android.Manifest.permission.READ_DREAM_STATE); final int userId = UserHandle.getCallingUserId(); final long ident = Binder.clearCallingIdentity(); try { return getDreamComponentsForUser(userId); } finally { Binder.restoreCallingIdentity(ident); } } @Override // Binder call public void setDreamComponents(ComponentName[] componentNames) { checkPermission(android.Manifest.permission.WRITE_DREAM_STATE); final int userId = UserHandle.getCallingUserId(); final long ident = Binder.clearCallingIdentity(); try { Settings.Secure.putStringForUser(mContext.getContentResolver(), Settings.Secure.SCREENSAVER_COMPONENTS, componentsToString(componentNames), userId); } finally { Binder.restoreCallingIdentity(ident); } } @Override // Binder call public ComponentName getDefaultDreamComponent() { checkPermission(android.Manifest.permission.READ_DREAM_STATE); final int userId = UserHandle.getCallingUserId(); final long ident = Binder.clearCallingIdentity(); try { String name = Settings.Secure.getStringForUser(mContext.getContentResolver(), Settings.Secure.SCREENSAVER_DEFAULT_COMPONENT, userId); return name == null ? null : ComponentName.unflattenFromString(name); } finally { Binder.restoreCallingIdentity(ident); } } @Override // Binder call public boolean isDreaming() { checkPermission(android.Manifest.permission.READ_DREAM_STATE); synchronized (mLock) { synchronized (mLock) { return mCurrentDreamToken != null && !mCurrentDreamIsTest; return mCurrentDreamToken != null && !mCurrentDreamIsTest; } } } } @Override // Binder call private void requestDreamInternal() { public void dream() { checkPermission(android.Manifest.permission.WRITE_DREAM_STATE); final long ident = Binder.clearCallingIdentity(); try { // Ask the power manager to nap. It will eventually call back into // Ask the power manager to nap. It will eventually call back into // startDream() if/when it is appropriate to start dreaming. // startDream() if/when it is appropriate to start dreaming. // Because napping could cause the screen to turn off immediately if the dream // Because napping could cause the screen to turn off immediately if the dream Loading @@ -179,64 +131,18 @@ public final class DreamManagerService extends IDreamManager.Stub { long time = SystemClock.uptimeMillis(); long time = SystemClock.uptimeMillis(); mPowerManager.userActivity(time, true /*noChangeLights*/); mPowerManager.userActivity(time, true /*noChangeLights*/); mPowerManager.nap(time); mPowerManager.nap(time); } finally { Binder.restoreCallingIdentity(ident); } } } @Override // Binder call public void testDream(ComponentName dream) { checkPermission(android.Manifest.permission.WRITE_DREAM_STATE); if (dream == null) { throw new IllegalArgumentException("dream must not be null"); } final int callingUserId = UserHandle.getCallingUserId(); final int currentUserId = ActivityManager.getCurrentUser(); if (callingUserId != currentUserId) { // This check is inherently prone to races but at least it's something. Slog.w(TAG, "Aborted attempt to start a test dream while a different " + " user is active: callingUserId=" + callingUserId + ", currentUserId=" + currentUserId); return; } final long ident = Binder.clearCallingIdentity(); try { synchronized (mLock) { startDreamLocked(dream, true /*isTest*/, callingUserId); } } finally { Binder.restoreCallingIdentity(ident); } } @Override // Binder call public void awaken() { checkPermission(android.Manifest.permission.WRITE_DREAM_STATE); final long ident = Binder.clearCallingIdentity(); private void requestAwakenInternal() { try { // Treat an explicit request to awaken as user activity so that the // Treat an explicit request to awaken as user activity so that the // device doesn't immediately go to sleep if the timeout expired, // device doesn't immediately go to sleep if the timeout expired, // for example when being undocked. // for example when being undocked. long time = SystemClock.uptimeMillis(); long time = SystemClock.uptimeMillis(); mPowerManager.userActivity(time, false /*noChangeLights*/); mPowerManager.userActivity(time, false /*noChangeLights*/); stopDream(); stopDreamInternal(); } finally { Binder.restoreCallingIdentity(ident); } } @Override // Binder call public void finishSelf(IBinder token) { // Requires no permission, called by Dream from an arbitrary process. if (token == null) { throw new IllegalArgumentException("token must not be null"); } } final long ident = Binder.clearCallingIdentity(); private void finishSelfInternal(IBinder token) { try { if (DEBUG) { if (DEBUG) { Slog.d(TAG, "Dream finished: " + token); Slog.d(TAG, "Dream finished: " + token); } } Loading @@ -253,15 +159,15 @@ public final class DreamManagerService extends IDreamManager.Stub { stopDreamLocked(); stopDreamLocked(); } } } } } finally { } Binder.restoreCallingIdentity(ident); private void testDreamInternal(ComponentName dream, int userId) { synchronized (mLock) { startDreamLocked(dream, true /*isTest*/, userId); } } } } /** private void startDreamInternal() { * Called by the power manager to start a dream. */ public void startDream() { int userId = ActivityManager.getCurrentUser(); int userId = ActivityManager.getCurrentUser(); ComponentName dream = chooseDreamForUser(userId); ComponentName dream = chooseDreamForUser(userId); if (dream != null) { if (dream != null) { Loading @@ -271,10 +177,7 @@ public final class DreamManagerService extends IDreamManager.Stub { } } } } /** private void stopDreamInternal() { * Called by the power manager to stop a dream. */ public void stopDream() { synchronized (mLock) { synchronized (mLock) { stopDreamLocked(); stopDreamLocked(); } } Loading Loading @@ -305,7 +208,7 @@ public final class DreamManagerService extends IDreamManager.Stub { // fallback to the default dream component if necessary // fallback to the default dream component if necessary if (validComponents.isEmpty()) { if (validComponents.isEmpty()) { ComponentName defaultDream = getDefaultDreamComponent(); ComponentName defaultDream = getDefaultDreamComponentForUser(userId); if (defaultDream != null) { if (defaultDream != null) { Slog.w(TAG, "Falling back to default dream " + defaultDream); Slog.w(TAG, "Falling back to default dream " + defaultDream); validComponents.add(defaultDream); validComponents.add(defaultDream); Loading @@ -314,6 +217,20 @@ public final class DreamManagerService extends IDreamManager.Stub { return validComponents.toArray(new ComponentName[validComponents.size()]); return validComponents.toArray(new ComponentName[validComponents.size()]); } } private void setDreamComponentsForUser(int userId, ComponentName[] componentNames) { Settings.Secure.putStringForUser(mContext.getContentResolver(), Settings.Secure.SCREENSAVER_COMPONENTS, componentsToString(componentNames), userId); } private ComponentName getDefaultDreamComponentForUser(int userId) { String name = Settings.Secure.getStringForUser(mContext.getContentResolver(), Settings.Secure.SCREENSAVER_DEFAULT_COMPONENT, userId); return name == null ? null : ComponentName.unflattenFromString(name); } private boolean serviceExists(ComponentName name) { private boolean serviceExists(ComponentName name) { try { try { return name != null && mContext.getPackageManager().getServiceInfo(name, 0) != null; return name != null && mContext.getPackageManager().getServiceInfo(name, 0) != null; Loading Loading @@ -423,4 +340,155 @@ public final class DreamManagerService extends IDreamManager.Stub { super(looper, null, true /*async*/); super(looper, null, true /*async*/); } } } } private final class BinderService extends IDreamManager.Stub { @Override // Binder call protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { if (mContext.checkCallingOrSelfPermission(Manifest.permission.DUMP) != PackageManager.PERMISSION_GRANTED) { pw.println("Permission Denial: can't dump DreamManager from from pid=" + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()); return; } final long ident = Binder.clearCallingIdentity(); try { dumpInternal(pw); } finally { Binder.restoreCallingIdentity(ident); } } @Override // Binder call public ComponentName[] getDreamComponents() { checkPermission(android.Manifest.permission.READ_DREAM_STATE); final int userId = UserHandle.getCallingUserId(); final long ident = Binder.clearCallingIdentity(); try { return getDreamComponentsForUser(userId); } finally { Binder.restoreCallingIdentity(ident); } } @Override // Binder call public void setDreamComponents(ComponentName[] componentNames) { checkPermission(android.Manifest.permission.WRITE_DREAM_STATE); final int userId = UserHandle.getCallingUserId(); final long ident = Binder.clearCallingIdentity(); try { setDreamComponentsForUser(userId, componentNames); } finally { Binder.restoreCallingIdentity(ident); } } @Override // Binder call public ComponentName getDefaultDreamComponent() { checkPermission(android.Manifest.permission.READ_DREAM_STATE); final int userId = UserHandle.getCallingUserId(); final long ident = Binder.clearCallingIdentity(); try { return getDefaultDreamComponentForUser(userId); } finally { Binder.restoreCallingIdentity(ident); } } @Override // Binder call public boolean isDreaming() { checkPermission(android.Manifest.permission.READ_DREAM_STATE); final long ident = Binder.clearCallingIdentity(); try { return isDreamingInternal(); } finally { Binder.restoreCallingIdentity(ident); } } @Override // Binder call public void dream() { checkPermission(android.Manifest.permission.WRITE_DREAM_STATE); final long ident = Binder.clearCallingIdentity(); try { requestDreamInternal(); } finally { Binder.restoreCallingIdentity(ident); } } @Override // Binder call public void testDream(ComponentName dream) { if (dream == null) { throw new IllegalArgumentException("dream must not be null"); } checkPermission(android.Manifest.permission.WRITE_DREAM_STATE); final int callingUserId = UserHandle.getCallingUserId(); final int currentUserId = ActivityManager.getCurrentUser(); if (callingUserId != currentUserId) { // This check is inherently prone to races but at least it's something. Slog.w(TAG, "Aborted attempt to start a test dream while a different " + " user is active: callingUserId=" + callingUserId + ", currentUserId=" + currentUserId); return; } final long ident = Binder.clearCallingIdentity(); try { testDreamInternal(dream, callingUserId); } finally { Binder.restoreCallingIdentity(ident); } } @Override // Binder call public void awaken() { checkPermission(android.Manifest.permission.WRITE_DREAM_STATE); final long ident = Binder.clearCallingIdentity(); try { requestAwakenInternal(); } finally { Binder.restoreCallingIdentity(ident); } } @Override // Binder call public void finishSelf(IBinder token) { // Requires no permission, called by Dream from an arbitrary process. if (token == null) { throw new IllegalArgumentException("token must not be null"); } final long ident = Binder.clearCallingIdentity(); try { finishSelfInternal(token); } finally { Binder.restoreCallingIdentity(ident); } } } private final class LocalService extends DreamManagerInternal { @Override public void startDream() { startDreamInternal(); } @Override public void stopDream() { stopDreamInternal(); } @Override public boolean isDreaming() { return isDreamingInternal(); } } } } services/core/java/com/android/server/power/PowerManagerService.java +7 −5 Original line number Original line Diff line number Diff line Loading @@ -20,12 +20,12 @@ import com.android.internal.app.IAppOpsService; import com.android.internal.app.IBatteryStats; import com.android.internal.app.IBatteryStats; import com.android.server.BatteryService; import com.android.server.BatteryService; import com.android.server.EventLogTags; import com.android.server.EventLogTags; import com.android.server.LocalServices; import com.android.server.ServiceThread; import com.android.server.ServiceThread; import com.android.server.lights.Light; import com.android.server.lights.Light; import com.android.server.lights.LightsManager; import com.android.server.lights.LightsManager; import com.android.server.twilight.TwilightManager; import com.android.server.twilight.TwilightManager; import com.android.server.Watchdog; import com.android.server.Watchdog; import com.android.server.dreams.DreamManagerService; import android.Manifest; import android.Manifest; import android.content.BroadcastReceiver; import android.content.BroadcastReceiver; Loading Loading @@ -57,6 +57,7 @@ import android.os.SystemService; import android.os.UserHandle; import android.os.UserHandle; import android.os.WorkSource; import android.os.WorkSource; import android.provider.Settings; import android.provider.Settings; import android.service.dreams.DreamManagerInternal; import android.util.EventLog; import android.util.EventLog; import android.util.Log; import android.util.Log; import android.util.Slog; import android.util.Slog; Loading Loading @@ -181,7 +182,7 @@ public final class PowerManagerService extends com.android.server.SystemService private DisplayPowerController mDisplayPowerController; private DisplayPowerController mDisplayPowerController; private WirelessChargerDetector mWirelessChargerDetector; private WirelessChargerDetector mWirelessChargerDetector; private SettingsObserver mSettingsObserver; private SettingsObserver mSettingsObserver; private DreamManagerService mDreamManager; private DreamManagerInternal mDreamManager; private Light mAttentionLight; private Light mAttentionLight; private final Object mLock = new Object(); private final Object mLock = new Object(); Loading Loading @@ -433,10 +434,10 @@ public final class PowerManagerService extends com.android.server.SystemService } } } } public void systemReady(TwilightManager twilight, DreamManagerService dreamManager) { public void systemReady() { synchronized (mLock) { synchronized (mLock) { mSystemReady = true; mSystemReady = true; mDreamManager = dreamManager; mDreamManager = LocalServices.getService(DreamManagerInternal.class); PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); mScreenBrightnessSettingMinimum = pm.getMinimumScreenBrightnessSetting(); mScreenBrightnessSettingMinimum = pm.getMinimumScreenBrightnessSetting(); Loading @@ -454,7 +455,8 @@ public final class PowerManagerService extends com.android.server.SystemService // The display power controller runs on the power manager service's // The display power controller runs on the power manager service's // own handler thread to ensure timely operation. // own handler thread to ensure timely operation. mDisplayPowerController = new DisplayPowerController(mHandler.getLooper(), mDisplayPowerController = new DisplayPowerController(mHandler.getLooper(), mContext, mNotifier, mLightsManager, twilight, sensorManager, mContext, mNotifier, mLightsManager, LocalServices.getService(TwilightManager.class), sensorManager, mDisplaySuspendBlocker, mDisplayBlanker, mDisplaySuspendBlocker, mDisplayBlanker, mDisplayPowerControllerCallbacks, mHandler); mDisplayPowerControllerCallbacks, mHandler); Loading services/java/com/android/server/SystemServer.java +5 −21 Original line number Original line Diff line number Diff line Loading @@ -75,7 +75,6 @@ import com.android.server.power.ShutdownThread; import com.android.server.search.SearchManagerService; import com.android.server.search.SearchManagerService; import com.android.server.statusbar.StatusBarManagerService; import com.android.server.statusbar.StatusBarManagerService; import com.android.server.storage.DeviceStorageMonitorService; import com.android.server.storage.DeviceStorageMonitorService; import com.android.server.twilight.TwilightManager; import com.android.server.twilight.TwilightService; import com.android.server.twilight.TwilightService; import com.android.server.usb.UsbService; import com.android.server.usb.UsbService; import com.android.server.wallpaper.WallpaperManagerService; import com.android.server.wallpaper.WallpaperManagerService; Loading Loading @@ -307,7 +306,6 @@ public final class SystemServer { DockObserver dock = null; DockObserver dock = null; UsbService usb = null; UsbService usb = null; SerialService serial = null; SerialService serial = null; TwilightManager twilight = null; RecognitionManagerService recognition = null; RecognitionManagerService recognition = null; NetworkTimeUpdateService networkTimeUpdater = null; NetworkTimeUpdateService networkTimeUpdater = null; CommonTimeManagementService commonTimeMgmtService = null; CommonTimeManagementService commonTimeMgmtService = null; Loading Loading @@ -464,7 +462,6 @@ public final class SystemServer { CountryDetectorService countryDetector = null; CountryDetectorService countryDetector = null; TextServicesManagerService tsms = null; TextServicesManagerService tsms = null; LockSettingsService lockSettings = null; LockSettingsService lockSettings = null; DreamManagerService dreamy = null; AssetAtlasService atlas = null; AssetAtlasService atlas = null; MediaRouterService mediaRouter = null; MediaRouterService mediaRouter = null; Loading Loading @@ -783,7 +780,6 @@ public final class SystemServer { } } mSystemServiceManager.startService(TwilightService.class); mSystemServiceManager.startService(TwilightService.class); twilight = LocalServices.getService(TwilightManager.class); mSystemServiceManager.startService(UiModeManagerService.class); mSystemServiceManager.startService(UiModeManagerService.class); Loading Loading @@ -859,16 +855,10 @@ public final class SystemServer { } } } } if (!disableNonCoreServices && if (!disableNonCoreServices context.getResources().getBoolean(R.bool.config_dreamsSupported)) { && context.getResources().getBoolean(R.bool.config_dreamsSupported)) { try { Slog.i(TAG, "Dreams Service"); // Dreams (interactive idle-time views, a/k/a screen savers) // Dreams (interactive idle-time views, a/k/a screen savers) dreamy = new DreamManagerService(context); mSystemServiceManager.startService(DreamManagerService.class); ServiceManager.addService(DreamService.DREAM_SERVICE, dreamy); } catch (Throwable e) { reportWtf("starting DreamManagerService", e); } } } if (!disableNonCoreServices) { if (!disableNonCoreServices) { Loading Loading @@ -963,7 +953,7 @@ public final class SystemServer { try { try { // TODO: use boot phase // TODO: use boot phase mPowerManagerService.systemReady(twilight, dreamy); mPowerManagerService.systemReady(); } catch (Throwable e) { } catch (Throwable e) { reportWtf("making Power Manager Service ready", e); reportWtf("making Power Manager Service ready", e); } } Loading Loading @@ -1000,7 +990,6 @@ public final class SystemServer { final CommonTimeManagementService commonTimeMgmtServiceF = commonTimeMgmtService; final CommonTimeManagementService commonTimeMgmtServiceF = commonTimeMgmtService; final TextServicesManagerService textServiceManagerServiceF = tsms; final TextServicesManagerService textServiceManagerServiceF = tsms; final StatusBarManagerService statusBarF = statusBar; final StatusBarManagerService statusBarF = statusBar; final DreamManagerService dreamyF = dreamy; final AssetAtlasService atlasF = atlas; final AssetAtlasService atlasF = atlas; final InputManagerService inputManagerF = inputManager; final InputManagerService inputManagerF = inputManager; final TelephonyRegistry telephonyRegistryF = telephonyRegistry; final TelephonyRegistry telephonyRegistryF = telephonyRegistry; Loading Loading @@ -1112,11 +1101,6 @@ public final class SystemServer { } catch (Throwable e) { } catch (Throwable e) { reportWtf("Notifying TextServicesManagerService running", e); reportWtf("Notifying TextServicesManagerService running", e); } } try { if (dreamyF != null) dreamyF.systemRunning(); } catch (Throwable e) { reportWtf("Notifying DreamManagerService running", e); } try { try { if (atlasF != null) atlasF.systemRunning(); if (atlasF != null) atlasF.systemRunning(); } catch (Throwable e) { } catch (Throwable e) { Loading Loading
core/java/android/service/dreams/DreamManagerInternal.java 0 → 100644 +39 −0 Original line number Original line Diff line number Diff line /* * Copyright (C) 2014 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 android.service.dreams; /** * Dream manager local system service interface. * * @hide Only for use within the system server. */ public abstract class DreamManagerInternal { /** * Called by the power manager to start a dream. */ public abstract void startDream(); /** * Called by the power manager to stop a dream. */ public abstract void stopDream(); /** * Called by the power manager to determine whether a dream is running. */ public abstract boolean isDreaming(); }
services/core/java/com/android/server/dreams/DreamManagerService.java +223 −155 Original line number Original line Diff line number Diff line Loading @@ -18,7 +18,9 @@ package com.android.server.dreams; import com.android.internal.util.DumpUtils; import com.android.internal.util.DumpUtils; import com.android.server.FgThread; import com.android.server.FgThread; import com.android.server.SystemService; import android.Manifest; import android.app.ActivityManager; import android.app.ActivityManager; import android.content.BroadcastReceiver; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.ComponentName; Loading @@ -35,6 +37,8 @@ import android.os.PowerManager; import android.os.SystemClock; import android.os.SystemClock; import android.os.UserHandle; import android.os.UserHandle; import android.provider.Settings; import android.provider.Settings; import android.service.dreams.DreamManagerInternal; import android.service.dreams.DreamService; import android.service.dreams.IDreamManager; import android.service.dreams.IDreamManager; import android.util.Slog; import android.util.Slog; Loading @@ -50,7 +54,7 @@ import libcore.util.Objects; * * * @hide * @hide */ */ public final class DreamManagerService extends IDreamManager.Stub { public final class DreamManagerService extends SystemService { private static final boolean DEBUG = false; private static final boolean DEBUG = false; private static final String TAG = "DreamManagerService"; private static final String TAG = "DreamManagerService"; Loading @@ -67,6 +71,7 @@ public final class DreamManagerService extends IDreamManager.Stub { private boolean mCurrentDreamIsTest; private boolean mCurrentDreamIsTest; public DreamManagerService(Context context) { public DreamManagerService(Context context) { super(context); mContext = context; mContext = context; mHandler = new DreamHandler(FgThread.get().getLooper()); mHandler = new DreamHandler(FgThread.get().getLooper()); mController = new DreamController(context, mHandler, mControllerListener); mController = new DreamController(context, mHandler, mControllerListener); Loading @@ -74,7 +79,15 @@ public final class DreamManagerService extends IDreamManager.Stub { mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); } } public void systemRunning() { @Override public void onStart() { publishBinderService(DreamService.DREAM_SERVICE, new BinderService()); publishLocalService(DreamManagerInternal.class, new LocalService()); } @Override public void onBootPhase(int phase) { if (phase == SystemService.PHASE_THIRD_PARTY_APPS_CAN_START) { mContext.registerReceiver(new BroadcastReceiver() { mContext.registerReceiver(new BroadcastReceiver() { @Override @Override public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) { Loading @@ -84,17 +97,9 @@ public final class DreamManagerService extends IDreamManager.Stub { } } }, new IntentFilter(Intent.ACTION_USER_SWITCHED), null, mHandler); }, new IntentFilter(Intent.ACTION_USER_SWITCHED), null, mHandler); } } @Override protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { if (mContext.checkCallingOrSelfPermission("android.permission.DUMP") != PackageManager.PERMISSION_GRANTED) { pw.println("Permission Denial: can't dump DreamManager from pid=" + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()); return; } } private void dumpInternal(PrintWriter pw) { pw.println("DREAM MANAGER (dumpsys dreams)"); pw.println("DREAM MANAGER (dumpsys dreams)"); pw.println(); pw.println(); Loading @@ -112,66 +117,13 @@ public final class DreamManagerService extends IDreamManager.Stub { }, pw, 200); }, pw, 200); } } @Override // Binder call private boolean isDreamingInternal() { public ComponentName[] getDreamComponents() { checkPermission(android.Manifest.permission.READ_DREAM_STATE); final int userId = UserHandle.getCallingUserId(); final long ident = Binder.clearCallingIdentity(); try { return getDreamComponentsForUser(userId); } finally { Binder.restoreCallingIdentity(ident); } } @Override // Binder call public void setDreamComponents(ComponentName[] componentNames) { checkPermission(android.Manifest.permission.WRITE_DREAM_STATE); final int userId = UserHandle.getCallingUserId(); final long ident = Binder.clearCallingIdentity(); try { Settings.Secure.putStringForUser(mContext.getContentResolver(), Settings.Secure.SCREENSAVER_COMPONENTS, componentsToString(componentNames), userId); } finally { Binder.restoreCallingIdentity(ident); } } @Override // Binder call public ComponentName getDefaultDreamComponent() { checkPermission(android.Manifest.permission.READ_DREAM_STATE); final int userId = UserHandle.getCallingUserId(); final long ident = Binder.clearCallingIdentity(); try { String name = Settings.Secure.getStringForUser(mContext.getContentResolver(), Settings.Secure.SCREENSAVER_DEFAULT_COMPONENT, userId); return name == null ? null : ComponentName.unflattenFromString(name); } finally { Binder.restoreCallingIdentity(ident); } } @Override // Binder call public boolean isDreaming() { checkPermission(android.Manifest.permission.READ_DREAM_STATE); synchronized (mLock) { synchronized (mLock) { return mCurrentDreamToken != null && !mCurrentDreamIsTest; return mCurrentDreamToken != null && !mCurrentDreamIsTest; } } } } @Override // Binder call private void requestDreamInternal() { public void dream() { checkPermission(android.Manifest.permission.WRITE_DREAM_STATE); final long ident = Binder.clearCallingIdentity(); try { // Ask the power manager to nap. It will eventually call back into // Ask the power manager to nap. It will eventually call back into // startDream() if/when it is appropriate to start dreaming. // startDream() if/when it is appropriate to start dreaming. // Because napping could cause the screen to turn off immediately if the dream // Because napping could cause the screen to turn off immediately if the dream Loading @@ -179,64 +131,18 @@ public final class DreamManagerService extends IDreamManager.Stub { long time = SystemClock.uptimeMillis(); long time = SystemClock.uptimeMillis(); mPowerManager.userActivity(time, true /*noChangeLights*/); mPowerManager.userActivity(time, true /*noChangeLights*/); mPowerManager.nap(time); mPowerManager.nap(time); } finally { Binder.restoreCallingIdentity(ident); } } } @Override // Binder call public void testDream(ComponentName dream) { checkPermission(android.Manifest.permission.WRITE_DREAM_STATE); if (dream == null) { throw new IllegalArgumentException("dream must not be null"); } final int callingUserId = UserHandle.getCallingUserId(); final int currentUserId = ActivityManager.getCurrentUser(); if (callingUserId != currentUserId) { // This check is inherently prone to races but at least it's something. Slog.w(TAG, "Aborted attempt to start a test dream while a different " + " user is active: callingUserId=" + callingUserId + ", currentUserId=" + currentUserId); return; } final long ident = Binder.clearCallingIdentity(); try { synchronized (mLock) { startDreamLocked(dream, true /*isTest*/, callingUserId); } } finally { Binder.restoreCallingIdentity(ident); } } @Override // Binder call public void awaken() { checkPermission(android.Manifest.permission.WRITE_DREAM_STATE); final long ident = Binder.clearCallingIdentity(); private void requestAwakenInternal() { try { // Treat an explicit request to awaken as user activity so that the // Treat an explicit request to awaken as user activity so that the // device doesn't immediately go to sleep if the timeout expired, // device doesn't immediately go to sleep if the timeout expired, // for example when being undocked. // for example when being undocked. long time = SystemClock.uptimeMillis(); long time = SystemClock.uptimeMillis(); mPowerManager.userActivity(time, false /*noChangeLights*/); mPowerManager.userActivity(time, false /*noChangeLights*/); stopDream(); stopDreamInternal(); } finally { Binder.restoreCallingIdentity(ident); } } @Override // Binder call public void finishSelf(IBinder token) { // Requires no permission, called by Dream from an arbitrary process. if (token == null) { throw new IllegalArgumentException("token must not be null"); } } final long ident = Binder.clearCallingIdentity(); private void finishSelfInternal(IBinder token) { try { if (DEBUG) { if (DEBUG) { Slog.d(TAG, "Dream finished: " + token); Slog.d(TAG, "Dream finished: " + token); } } Loading @@ -253,15 +159,15 @@ public final class DreamManagerService extends IDreamManager.Stub { stopDreamLocked(); stopDreamLocked(); } } } } } finally { } Binder.restoreCallingIdentity(ident); private void testDreamInternal(ComponentName dream, int userId) { synchronized (mLock) { startDreamLocked(dream, true /*isTest*/, userId); } } } } /** private void startDreamInternal() { * Called by the power manager to start a dream. */ public void startDream() { int userId = ActivityManager.getCurrentUser(); int userId = ActivityManager.getCurrentUser(); ComponentName dream = chooseDreamForUser(userId); ComponentName dream = chooseDreamForUser(userId); if (dream != null) { if (dream != null) { Loading @@ -271,10 +177,7 @@ public final class DreamManagerService extends IDreamManager.Stub { } } } } /** private void stopDreamInternal() { * Called by the power manager to stop a dream. */ public void stopDream() { synchronized (mLock) { synchronized (mLock) { stopDreamLocked(); stopDreamLocked(); } } Loading Loading @@ -305,7 +208,7 @@ public final class DreamManagerService extends IDreamManager.Stub { // fallback to the default dream component if necessary // fallback to the default dream component if necessary if (validComponents.isEmpty()) { if (validComponents.isEmpty()) { ComponentName defaultDream = getDefaultDreamComponent(); ComponentName defaultDream = getDefaultDreamComponentForUser(userId); if (defaultDream != null) { if (defaultDream != null) { Slog.w(TAG, "Falling back to default dream " + defaultDream); Slog.w(TAG, "Falling back to default dream " + defaultDream); validComponents.add(defaultDream); validComponents.add(defaultDream); Loading @@ -314,6 +217,20 @@ public final class DreamManagerService extends IDreamManager.Stub { return validComponents.toArray(new ComponentName[validComponents.size()]); return validComponents.toArray(new ComponentName[validComponents.size()]); } } private void setDreamComponentsForUser(int userId, ComponentName[] componentNames) { Settings.Secure.putStringForUser(mContext.getContentResolver(), Settings.Secure.SCREENSAVER_COMPONENTS, componentsToString(componentNames), userId); } private ComponentName getDefaultDreamComponentForUser(int userId) { String name = Settings.Secure.getStringForUser(mContext.getContentResolver(), Settings.Secure.SCREENSAVER_DEFAULT_COMPONENT, userId); return name == null ? null : ComponentName.unflattenFromString(name); } private boolean serviceExists(ComponentName name) { private boolean serviceExists(ComponentName name) { try { try { return name != null && mContext.getPackageManager().getServiceInfo(name, 0) != null; return name != null && mContext.getPackageManager().getServiceInfo(name, 0) != null; Loading Loading @@ -423,4 +340,155 @@ public final class DreamManagerService extends IDreamManager.Stub { super(looper, null, true /*async*/); super(looper, null, true /*async*/); } } } } private final class BinderService extends IDreamManager.Stub { @Override // Binder call protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { if (mContext.checkCallingOrSelfPermission(Manifest.permission.DUMP) != PackageManager.PERMISSION_GRANTED) { pw.println("Permission Denial: can't dump DreamManager from from pid=" + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()); return; } final long ident = Binder.clearCallingIdentity(); try { dumpInternal(pw); } finally { Binder.restoreCallingIdentity(ident); } } @Override // Binder call public ComponentName[] getDreamComponents() { checkPermission(android.Manifest.permission.READ_DREAM_STATE); final int userId = UserHandle.getCallingUserId(); final long ident = Binder.clearCallingIdentity(); try { return getDreamComponentsForUser(userId); } finally { Binder.restoreCallingIdentity(ident); } } @Override // Binder call public void setDreamComponents(ComponentName[] componentNames) { checkPermission(android.Manifest.permission.WRITE_DREAM_STATE); final int userId = UserHandle.getCallingUserId(); final long ident = Binder.clearCallingIdentity(); try { setDreamComponentsForUser(userId, componentNames); } finally { Binder.restoreCallingIdentity(ident); } } @Override // Binder call public ComponentName getDefaultDreamComponent() { checkPermission(android.Manifest.permission.READ_DREAM_STATE); final int userId = UserHandle.getCallingUserId(); final long ident = Binder.clearCallingIdentity(); try { return getDefaultDreamComponentForUser(userId); } finally { Binder.restoreCallingIdentity(ident); } } @Override // Binder call public boolean isDreaming() { checkPermission(android.Manifest.permission.READ_DREAM_STATE); final long ident = Binder.clearCallingIdentity(); try { return isDreamingInternal(); } finally { Binder.restoreCallingIdentity(ident); } } @Override // Binder call public void dream() { checkPermission(android.Manifest.permission.WRITE_DREAM_STATE); final long ident = Binder.clearCallingIdentity(); try { requestDreamInternal(); } finally { Binder.restoreCallingIdentity(ident); } } @Override // Binder call public void testDream(ComponentName dream) { if (dream == null) { throw new IllegalArgumentException("dream must not be null"); } checkPermission(android.Manifest.permission.WRITE_DREAM_STATE); final int callingUserId = UserHandle.getCallingUserId(); final int currentUserId = ActivityManager.getCurrentUser(); if (callingUserId != currentUserId) { // This check is inherently prone to races but at least it's something. Slog.w(TAG, "Aborted attempt to start a test dream while a different " + " user is active: callingUserId=" + callingUserId + ", currentUserId=" + currentUserId); return; } final long ident = Binder.clearCallingIdentity(); try { testDreamInternal(dream, callingUserId); } finally { Binder.restoreCallingIdentity(ident); } } @Override // Binder call public void awaken() { checkPermission(android.Manifest.permission.WRITE_DREAM_STATE); final long ident = Binder.clearCallingIdentity(); try { requestAwakenInternal(); } finally { Binder.restoreCallingIdentity(ident); } } @Override // Binder call public void finishSelf(IBinder token) { // Requires no permission, called by Dream from an arbitrary process. if (token == null) { throw new IllegalArgumentException("token must not be null"); } final long ident = Binder.clearCallingIdentity(); try { finishSelfInternal(token); } finally { Binder.restoreCallingIdentity(ident); } } } private final class LocalService extends DreamManagerInternal { @Override public void startDream() { startDreamInternal(); } @Override public void stopDream() { stopDreamInternal(); } @Override public boolean isDreaming() { return isDreamingInternal(); } } } }
services/core/java/com/android/server/power/PowerManagerService.java +7 −5 Original line number Original line Diff line number Diff line Loading @@ -20,12 +20,12 @@ import com.android.internal.app.IAppOpsService; import com.android.internal.app.IBatteryStats; import com.android.internal.app.IBatteryStats; import com.android.server.BatteryService; import com.android.server.BatteryService; import com.android.server.EventLogTags; import com.android.server.EventLogTags; import com.android.server.LocalServices; import com.android.server.ServiceThread; import com.android.server.ServiceThread; import com.android.server.lights.Light; import com.android.server.lights.Light; import com.android.server.lights.LightsManager; import com.android.server.lights.LightsManager; import com.android.server.twilight.TwilightManager; import com.android.server.twilight.TwilightManager; import com.android.server.Watchdog; import com.android.server.Watchdog; import com.android.server.dreams.DreamManagerService; import android.Manifest; import android.Manifest; import android.content.BroadcastReceiver; import android.content.BroadcastReceiver; Loading Loading @@ -57,6 +57,7 @@ import android.os.SystemService; import android.os.UserHandle; import android.os.UserHandle; import android.os.WorkSource; import android.os.WorkSource; import android.provider.Settings; import android.provider.Settings; import android.service.dreams.DreamManagerInternal; import android.util.EventLog; import android.util.EventLog; import android.util.Log; import android.util.Log; import android.util.Slog; import android.util.Slog; Loading Loading @@ -181,7 +182,7 @@ public final class PowerManagerService extends com.android.server.SystemService private DisplayPowerController mDisplayPowerController; private DisplayPowerController mDisplayPowerController; private WirelessChargerDetector mWirelessChargerDetector; private WirelessChargerDetector mWirelessChargerDetector; private SettingsObserver mSettingsObserver; private SettingsObserver mSettingsObserver; private DreamManagerService mDreamManager; private DreamManagerInternal mDreamManager; private Light mAttentionLight; private Light mAttentionLight; private final Object mLock = new Object(); private final Object mLock = new Object(); Loading Loading @@ -433,10 +434,10 @@ public final class PowerManagerService extends com.android.server.SystemService } } } } public void systemReady(TwilightManager twilight, DreamManagerService dreamManager) { public void systemReady() { synchronized (mLock) { synchronized (mLock) { mSystemReady = true; mSystemReady = true; mDreamManager = dreamManager; mDreamManager = LocalServices.getService(DreamManagerInternal.class); PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); mScreenBrightnessSettingMinimum = pm.getMinimumScreenBrightnessSetting(); mScreenBrightnessSettingMinimum = pm.getMinimumScreenBrightnessSetting(); Loading @@ -454,7 +455,8 @@ public final class PowerManagerService extends com.android.server.SystemService // The display power controller runs on the power manager service's // The display power controller runs on the power manager service's // own handler thread to ensure timely operation. // own handler thread to ensure timely operation. mDisplayPowerController = new DisplayPowerController(mHandler.getLooper(), mDisplayPowerController = new DisplayPowerController(mHandler.getLooper(), mContext, mNotifier, mLightsManager, twilight, sensorManager, mContext, mNotifier, mLightsManager, LocalServices.getService(TwilightManager.class), sensorManager, mDisplaySuspendBlocker, mDisplayBlanker, mDisplaySuspendBlocker, mDisplayBlanker, mDisplayPowerControllerCallbacks, mHandler); mDisplayPowerControllerCallbacks, mHandler); Loading
services/java/com/android/server/SystemServer.java +5 −21 Original line number Original line Diff line number Diff line Loading @@ -75,7 +75,6 @@ import com.android.server.power.ShutdownThread; import com.android.server.search.SearchManagerService; import com.android.server.search.SearchManagerService; import com.android.server.statusbar.StatusBarManagerService; import com.android.server.statusbar.StatusBarManagerService; import com.android.server.storage.DeviceStorageMonitorService; import com.android.server.storage.DeviceStorageMonitorService; import com.android.server.twilight.TwilightManager; import com.android.server.twilight.TwilightService; import com.android.server.twilight.TwilightService; import com.android.server.usb.UsbService; import com.android.server.usb.UsbService; import com.android.server.wallpaper.WallpaperManagerService; import com.android.server.wallpaper.WallpaperManagerService; Loading Loading @@ -307,7 +306,6 @@ public final class SystemServer { DockObserver dock = null; DockObserver dock = null; UsbService usb = null; UsbService usb = null; SerialService serial = null; SerialService serial = null; TwilightManager twilight = null; RecognitionManagerService recognition = null; RecognitionManagerService recognition = null; NetworkTimeUpdateService networkTimeUpdater = null; NetworkTimeUpdateService networkTimeUpdater = null; CommonTimeManagementService commonTimeMgmtService = null; CommonTimeManagementService commonTimeMgmtService = null; Loading Loading @@ -464,7 +462,6 @@ public final class SystemServer { CountryDetectorService countryDetector = null; CountryDetectorService countryDetector = null; TextServicesManagerService tsms = null; TextServicesManagerService tsms = null; LockSettingsService lockSettings = null; LockSettingsService lockSettings = null; DreamManagerService dreamy = null; AssetAtlasService atlas = null; AssetAtlasService atlas = null; MediaRouterService mediaRouter = null; MediaRouterService mediaRouter = null; Loading Loading @@ -783,7 +780,6 @@ public final class SystemServer { } } mSystemServiceManager.startService(TwilightService.class); mSystemServiceManager.startService(TwilightService.class); twilight = LocalServices.getService(TwilightManager.class); mSystemServiceManager.startService(UiModeManagerService.class); mSystemServiceManager.startService(UiModeManagerService.class); Loading Loading @@ -859,16 +855,10 @@ public final class SystemServer { } } } } if (!disableNonCoreServices && if (!disableNonCoreServices context.getResources().getBoolean(R.bool.config_dreamsSupported)) { && context.getResources().getBoolean(R.bool.config_dreamsSupported)) { try { Slog.i(TAG, "Dreams Service"); // Dreams (interactive idle-time views, a/k/a screen savers) // Dreams (interactive idle-time views, a/k/a screen savers) dreamy = new DreamManagerService(context); mSystemServiceManager.startService(DreamManagerService.class); ServiceManager.addService(DreamService.DREAM_SERVICE, dreamy); } catch (Throwable e) { reportWtf("starting DreamManagerService", e); } } } if (!disableNonCoreServices) { if (!disableNonCoreServices) { Loading Loading @@ -963,7 +953,7 @@ public final class SystemServer { try { try { // TODO: use boot phase // TODO: use boot phase mPowerManagerService.systemReady(twilight, dreamy); mPowerManagerService.systemReady(); } catch (Throwable e) { } catch (Throwable e) { reportWtf("making Power Manager Service ready", e); reportWtf("making Power Manager Service ready", e); } } Loading Loading @@ -1000,7 +990,6 @@ public final class SystemServer { final CommonTimeManagementService commonTimeMgmtServiceF = commonTimeMgmtService; final CommonTimeManagementService commonTimeMgmtServiceF = commonTimeMgmtService; final TextServicesManagerService textServiceManagerServiceF = tsms; final TextServicesManagerService textServiceManagerServiceF = tsms; final StatusBarManagerService statusBarF = statusBar; final StatusBarManagerService statusBarF = statusBar; final DreamManagerService dreamyF = dreamy; final AssetAtlasService atlasF = atlas; final AssetAtlasService atlasF = atlas; final InputManagerService inputManagerF = inputManager; final InputManagerService inputManagerF = inputManager; final TelephonyRegistry telephonyRegistryF = telephonyRegistry; final TelephonyRegistry telephonyRegistryF = telephonyRegistry; Loading Loading @@ -1112,11 +1101,6 @@ public final class SystemServer { } catch (Throwable e) { } catch (Throwable e) { reportWtf("Notifying TextServicesManagerService running", e); reportWtf("Notifying TextServicesManagerService running", e); } } try { if (dreamyF != null) dreamyF.systemRunning(); } catch (Throwable e) { reportWtf("Notifying DreamManagerService running", e); } try { try { if (atlasF != null) atlasF.systemRunning(); if (atlasF != null) atlasF.systemRunning(); } catch (Throwable e) { } catch (Throwable e) { Loading