* commit '8a4c2bb1f07cf1d971290a7310d7b71aceb71590': Refactor dream manager to new pattern.
This commit is contained in:
39
core/java/android/service/dreams/DreamManagerInternal.java
Normal file
39
core/java/android/service/dreams/DreamManagerInternal.java
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* 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();
|
||||||
|
}
|
@ -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;
|
||||||
@ -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;
|
||||||
|
|
||||||
@ -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";
|
||||||
|
|
||||||
@ -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);
|
||||||
@ -74,27 +79,27 @@ 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
|
||||||
mContext.registerReceiver(new BroadcastReceiver() {
|
public void onStart() {
|
||||||
@Override
|
publishBinderService(DreamService.DREAM_SERVICE, new BinderService());
|
||||||
public void onReceive(Context context, Intent intent) {
|
publishLocalService(DreamManagerInternal.class, new LocalService());
|
||||||
synchronized (mLock) {
|
|
||||||
stopDreamLocked();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, new IntentFilter(Intent.ACTION_USER_SWITCHED), null, mHandler);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
|
public void onBootPhase(int phase) {
|
||||||
if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
|
if (phase == SystemService.PHASE_THIRD_PARTY_APPS_CAN_START) {
|
||||||
!= PackageManager.PERMISSION_GRANTED) {
|
mContext.registerReceiver(new BroadcastReceiver() {
|
||||||
pw.println("Permission Denial: can't dump DreamManager from pid="
|
@Override
|
||||||
+ Binder.getCallingPid()
|
public void onReceive(Context context, Intent intent) {
|
||||||
+ ", uid=" + Binder.getCallingUid());
|
synchronized (mLock) {
|
||||||
return;
|
stopDreamLocked();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, new IntentFilter(Intent.ACTION_USER_SWITCHED), null, mHandler);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void dumpInternal(PrintWriter pw) {
|
||||||
pw.println("DREAM MANAGER (dumpsys dreams)");
|
pw.println("DREAM MANAGER (dumpsys dreams)");
|
||||||
pw.println();
|
pw.println();
|
||||||
|
|
||||||
@ -112,156 +117,57 @@ 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() {
|
// Ask the power manager to nap. It will eventually call back into
|
||||||
checkPermission(android.Manifest.permission.WRITE_DREAM_STATE);
|
// startDream() if/when it is appropriate to start dreaming.
|
||||||
|
// Because napping could cause the screen to turn off immediately if the dream
|
||||||
final long ident = Binder.clearCallingIdentity();
|
// cannot be started, we keep one eye open and gently poke user activity.
|
||||||
try {
|
long time = SystemClock.uptimeMillis();
|
||||||
// Ask the power manager to nap. It will eventually call back into
|
mPowerManager.userActivity(time, true /*noChangeLights*/);
|
||||||
// startDream() if/when it is appropriate to start dreaming.
|
mPowerManager.nap(time);
|
||||||
// Because napping could cause the screen to turn off immediately if the dream
|
|
||||||
// cannot be started, we keep one eye open and gently poke user activity.
|
|
||||||
long time = SystemClock.uptimeMillis();
|
|
||||||
mPowerManager.userActivity(time, true /*noChangeLights*/);
|
|
||||||
mPowerManager.nap(time);
|
|
||||||
} finally {
|
|
||||||
Binder.restoreCallingIdentity(ident);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override // Binder call
|
private void requestAwakenInternal() {
|
||||||
public void testDream(ComponentName dream) {
|
// Treat an explicit request to awaken as user activity so that the
|
||||||
checkPermission(android.Manifest.permission.WRITE_DREAM_STATE);
|
// device doesn't immediately go to sleep if the timeout expired,
|
||||||
|
// for example when being undocked.
|
||||||
|
long time = SystemClock.uptimeMillis();
|
||||||
|
mPowerManager.userActivity(time, false /*noChangeLights*/);
|
||||||
|
stopDreamInternal();
|
||||||
|
}
|
||||||
|
|
||||||
if (dream == null) {
|
private void finishSelfInternal(IBinder token) {
|
||||||
throw new IllegalArgumentException("dream must not be null");
|
if (DEBUG) {
|
||||||
|
Slog.d(TAG, "Dream finished: " + token);
|
||||||
}
|
}
|
||||||
|
|
||||||
final int callingUserId = UserHandle.getCallingUserId();
|
// Note that a dream finishing and self-terminating is not
|
||||||
final int currentUserId = ActivityManager.getCurrentUser();
|
// itself considered user activity. If the dream is ending because
|
||||||
if (callingUserId != currentUserId) {
|
// the user interacted with the device then user activity will already
|
||||||
// This check is inherently prone to races but at least it's something.
|
// have been poked so the device will stay awake a bit longer.
|
||||||
Slog.w(TAG, "Aborted attempt to start a test dream while a different "
|
// If the dream is ending on its own for other reasons and no wake
|
||||||
+ " user is active: callingUserId=" + callingUserId
|
// locks are held and the user activity timeout has expired then the
|
||||||
+ ", currentUserId=" + currentUserId);
|
// device may simply go to sleep.
|
||||||
return;
|
synchronized (mLock) {
|
||||||
}
|
if (mCurrentDreamToken == token) {
|
||||||
final long ident = Binder.clearCallingIdentity();
|
stopDreamLocked();
|
||||||
try {
|
|
||||||
synchronized (mLock) {
|
|
||||||
startDreamLocked(dream, true /*isTest*/, callingUserId);
|
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
Binder.restoreCallingIdentity(ident);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override // Binder call
|
private void testDreamInternal(ComponentName dream, int userId) {
|
||||||
public void awaken() {
|
synchronized (mLock) {
|
||||||
checkPermission(android.Manifest.permission.WRITE_DREAM_STATE);
|
startDreamLocked(dream, true /*isTest*/, userId);
|
||||||
|
|
||||||
final long ident = Binder.clearCallingIdentity();
|
|
||||||
try {
|
|
||||||
// Treat an explicit request to awaken as user activity so that the
|
|
||||||
// device doesn't immediately go to sleep if the timeout expired,
|
|
||||||
// for example when being undocked.
|
|
||||||
long time = SystemClock.uptimeMillis();
|
|
||||||
mPowerManager.userActivity(time, false /*noChangeLights*/);
|
|
||||||
stopDream();
|
|
||||||
} finally {
|
|
||||||
Binder.restoreCallingIdentity(ident);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override // Binder call
|
private void startDreamInternal() {
|
||||||
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 {
|
|
||||||
if (DEBUG) {
|
|
||||||
Slog.d(TAG, "Dream finished: " + token);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Note that a dream finishing and self-terminating is not
|
|
||||||
// itself considered user activity. If the dream is ending because
|
|
||||||
// the user interacted with the device then user activity will already
|
|
||||||
// have been poked so the device will stay awake a bit longer.
|
|
||||||
// If the dream is ending on its own for other reasons and no wake
|
|
||||||
// locks are held and the user activity timeout has expired then the
|
|
||||||
// device may simply go to sleep.
|
|
||||||
synchronized (mLock) {
|
|
||||||
if (mCurrentDreamToken == token) {
|
|
||||||
stopDreamLocked();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
Binder.restoreCallingIdentity(ident);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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) {
|
||||||
@ -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();
|
||||||
}
|
}
|
||||||
@ -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);
|
||||||
@ -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;
|
||||||
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
@ -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;
|
||||||
@ -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();
|
||||||
@ -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();
|
||||||
@ -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);
|
||||||
|
|
||||||
|
@ -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;
|
||||||
@ -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;
|
||||||
@ -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;
|
||||||
|
|
||||||
@ -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);
|
||||||
|
|
||||||
@ -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 {
|
// Dreams (interactive idle-time views, a/k/a screen savers)
|
||||||
Slog.i(TAG, "Dreams Service");
|
mSystemServiceManager.startService(DreamManagerService.class);
|
||||||
// Dreams (interactive idle-time views, a/k/a screen savers)
|
|
||||||
dreamy = new DreamManagerService(context);
|
|
||||||
ServiceManager.addService(DreamService.DREAM_SERVICE, dreamy);
|
|
||||||
} catch (Throwable e) {
|
|
||||||
reportWtf("starting DreamManagerService", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!disableNonCoreServices) {
|
if (!disableNonCoreServices) {
|
||||||
@ -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);
|
||||||
}
|
}
|
||||||
@ -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;
|
||||||
@ -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) {
|
||||||
|
Reference in New Issue
Block a user