am 3185b376: Merge "Re-enable dreams: frameworks/base" into jb-mr1-dev

* commit '3185b376b0b9b8c393fb8300b18df441a3481ad0':
  Re-enable dreams: frameworks/base
This commit is contained in:
John Spurlock
2012-08-03 08:40:43 -07:00
committed by Android Git Automerger
8 changed files with 130 additions and 37 deletions

View File

@@ -19927,6 +19927,50 @@ package android.security {
} }
package android.service.dreams {
public class Dream extends android.app.Service implements android.view.Window.Callback {
ctor public Dream();
method public void addContentView(android.view.View, android.view.ViewGroup.LayoutParams);
method public boolean dispatchGenericMotionEvent(android.view.MotionEvent);
method public boolean dispatchKeyEvent(android.view.KeyEvent);
method public boolean dispatchKeyShortcutEvent(android.view.KeyEvent);
method public boolean dispatchPopulateAccessibilityEvent(android.view.accessibility.AccessibilityEvent);
method public boolean dispatchTouchEvent(android.view.MotionEvent);
method public boolean dispatchTrackballEvent(android.view.MotionEvent);
method public android.view.View findViewById(int);
method public void finish();
method public android.view.Window getWindow();
method public android.view.WindowManager getWindowManager();
method public boolean isInteractive();
method protected void lightsOut();
method public void onActionModeFinished(android.view.ActionMode);
method public void onActionModeStarted(android.view.ActionMode);
method public void onAttachedToWindow();
method public final android.os.IBinder onBind(android.content.Intent);
method public void onContentChanged();
method public boolean onCreatePanelMenu(int, android.view.Menu);
method public android.view.View onCreatePanelView(int);
method public void onDetachedFromWindow();
method public boolean onMenuItemSelected(int, android.view.MenuItem);
method public boolean onMenuOpened(int, android.view.Menu);
method public void onPanelClosed(int, android.view.Menu);
method public boolean onPreparePanel(int, android.view.View, android.view.Menu);
method public boolean onSearchRequested();
method public void onStart();
method public final int onStartCommand(android.content.Intent, int, int);
method public void onWindowAttributesChanged(android.view.WindowManager.LayoutParams);
method public void onWindowFocusChanged(boolean);
method public android.view.ActionMode onWindowStartingActionMode(android.view.ActionMode.Callback);
method public void setContentView(int);
method public void setContentView(android.view.View);
method public void setContentView(android.view.View, android.view.ViewGroup.LayoutParams);
method public void setInteractive(boolean);
field public static final java.lang.String SERVICE_INTERFACE = "android.service.dreams.Dream";
}
}
package android.service.textservice { package android.service.textservice {
public abstract class SpellCheckerService extends android.app.Service { public abstract class SpellCheckerService extends android.app.Service {

View File

@@ -1,26 +1,31 @@
/** /**
* * Copyright (C) 2012 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; package android.service.dreams;
import com.android.internal.policy.PolicyManager;
import android.annotation.SdkConstant; import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType; import android.annotation.SdkConstant.SdkConstantType;
import android.app.Service; import android.app.Service;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
import android.os.Binder;
import android.os.Handler; import android.os.Handler;
import android.os.IBinder; import android.os.IBinder;
import android.os.Looper;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.ServiceManager; import android.os.ServiceManager;
import android.util.Slog; import android.util.Slog;
import android.view.ActionMode; import android.view.ActionMode;
import android.view.IWindowManager;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
@@ -28,14 +33,14 @@ import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.Window; import android.view.Window;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams; import android.view.WindowManager.LayoutParams;
import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityEvent;
import android.view.WindowManager;
import android.view.WindowManagerImpl; import com.android.internal.policy.PolicyManager;
/** /**
* @hide * Extend this class to implement a custom screensaver.
*
*/ */
public class Dream extends Service implements Window.Callback { public class Dream extends Service implements Window.Callback {
private final static boolean DEBUG = true; private final static boolean DEBUG = true;
@@ -61,7 +66,7 @@ public class Dream extends Service implements Window.Callback {
final Handler mHandler = new Handler(); final Handler mHandler = new Handler();
boolean mFinished = false; boolean mFinished = false;
// begin Window.Callback methods // begin Window.Callback methods
@Override @Override
public boolean dispatchKeyEvent(KeyEvent event) { public boolean dispatchKeyEvent(KeyEvent event) {
@@ -210,19 +215,14 @@ public class Dream extends Service implements Window.Callback {
mSandman = IDreamManager.Stub.asInterface(ServiceManager.getService("dreams")); mSandman = IDreamManager.Stub.asInterface(ServiceManager.getService("dreams"));
} }
/** /**
* Called when this Dream is started. Place your initialization here. * Called when this Dream is started.
*
* Subclasses must call through to the superclass implementation.
*
* XXX(dsandler) Might want to make this final and have a different method for clients to override
*/ */
@Override public void onStart() {
public int onStartCommand(Intent intent, int flags, int startId) { // hook for subclasses
return super.onStartCommand(intent, flags, startId);
} }
/** /**
* Inflate a layout resource and set it to be the content view for this Dream. * Inflate a layout resource and set it to be the content view for this Dream.
* Behaves similarly to {@link android.app.Activity#setContentView(int)}. * Behaves similarly to {@link android.app.Activity#setContentView(int)}.
@@ -351,9 +351,12 @@ public class Dream extends Service implements Window.Callback {
@Override @Override
public void run() { public void run() {
if (DEBUG) Slog.v(TAG, "Dream window added on thread " + Thread.currentThread().getId()); if (DEBUG) Slog.v(TAG, "Dream window added on thread " + Thread.currentThread().getId());
getWindowManager().addView(mWindow.getDecorView(), mWindow.getAttributes()); getWindowManager().addView(mWindow.getDecorView(), mWindow.getAttributes());
}});
// start it up
onStart();
}});
} }
/** /**

View File

@@ -114,11 +114,19 @@ public class DreamManagerService
if (DEBUG) Slog.v(TAG, "awaken()"); if (DEBUG) Slog.v(TAG, "awaken()");
synchronized (mLock) { synchronized (mLock) {
if (mCurrentDream != null) { if (mCurrentDream != null) {
if (DEBUG) Slog.v(TAG, "disconnecting: " + mCurrentDreamComponent + " service: " + mCurrentDream);
mContext.unbindService(this); mContext.unbindService(this);
mCurrentDream = null;
mCurrentDreamToken = null;
} }
} }
} }
// IDreamManager method
public boolean isDreaming() {
return mCurrentDream != null;
}
public void bindDreamComponentL(ComponentName componentName, boolean test) { public void bindDreamComponentL(ComponentName componentName, boolean test) {
if (DEBUG) Slog.v(TAG, "bindDreamComponent: componentName=" + componentName if (DEBUG) Slog.v(TAG, "bindDreamComponent: componentName=" + componentName
+ " pid=" + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()); + " pid=" + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid());
@@ -129,11 +137,7 @@ public class DreamManagerService
Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
) )
.putExtra("android.dreams.TEST", test); .putExtra("android.dreams.TEST", test);
if (!mContext.bindService(intent, this, Context.BIND_AUTO_CREATE)) {
Slog.w(TAG, "unable to bind service: " + componentName);
return;
}
mCurrentDreamComponent = componentName; mCurrentDreamComponent = componentName;
mCurrentDreamToken = new Binder(); mCurrentDreamToken = new Binder();
try { try {
@@ -145,6 +149,9 @@ public class DreamManagerService
Slog.w(TAG, "Unable to add window token. Proceed at your own risk."); Slog.w(TAG, "Unable to add window token. Proceed at your own risk.");
} }
if (!mContext.bindService(intent, this, Context.BIND_AUTO_CREATE)) {
Slog.w(TAG, "unable to bind service: " + componentName);
}
} }
@Override @Override
@@ -163,8 +170,7 @@ public class DreamManagerService
@Override @Override
public void onServiceDisconnected(ComponentName name) { public void onServiceDisconnected(ComponentName name) {
if (DEBUG) Slog.v(TAG, "disconnected: " + name + " service: " + mCurrentDream); if (DEBUG) Slog.v(TAG, "disconnected: " + name + " service: " + mCurrentDream);
mCurrentDream = null; // Only happens in exceptional circumstances
mCurrentDreamToken = null;
} }
@Override @Override

View File

@@ -27,4 +27,5 @@ interface IDreamManager {
void setDreamComponent(in ComponentName componentName); void setDreamComponent(in ComponentName componentName);
ComponentName getDreamComponent(); ComponentName getDreamComponent();
void testDream(in ComponentName componentName); void testDream(in ComponentName componentName);
boolean isDreaming();
} }

View File

@@ -852,7 +852,7 @@
<string name="config_wimaxStateTrackerClassname" translatable="false"></string> <string name="config_wimaxStateTrackerClassname" translatable="false"></string>
<!-- enable screen saver feature --> <!-- enable screen saver feature -->
<bool name="config_enableDreams">false</bool> <bool name="config_enableDreams">true</bool>
<!-- Name of screensaver components to look for if none has been chosen by the user --> <!-- Name of screensaver components to look for if none has been chosen by the user -->
<string name="config_defaultDreamComponent" translatable="false">com.google.android.deskclock/com.android.deskclock.Screensaver</string> <string name="config_defaultDreamComponent" translatable="false">com.google.android.deskclock/com.android.deskclock.Screensaver</string>

View File

@@ -1132,7 +1132,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
com.android.internal.R.bool.config_enableDreams); com.android.internal.R.bool.config_enableDreams);
mScreenSaverEnabledByUser = 0 != Settings.Secure.getInt(resolver, mScreenSaverEnabledByUser = 0 != Settings.Secure.getInt(resolver,
Settings.Secure.SCREENSAVER_ENABLED, 1); Settings.Secure.SCREENSAVER_ENABLED, 0);
if (SEPARATE_TIMEOUT_FOR_SCREEN_SAVER) { if (SEPARATE_TIMEOUT_FOR_SCREEN_SAVER) {
mScreenSaverTimeout = Settings.Secure.getInt(resolver, mScreenSaverTimeout = Settings.Secure.getInt(resolver,
@@ -4076,7 +4076,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
if (dm == null) return; if (dm == null) return;
try { try {
if (localLOGV) Log.v(TAG, "startScreenSaver: awakening..."); if (!dm.isDreaming()) return;
if (localLOGV) Log.v(TAG, "stopScreenSaver: awakening...");
dm.awaken(); dm.awaken();
} catch (RemoteException ex) { } catch (RemoteException ex) {

View File

@@ -29,9 +29,12 @@ import android.media.RingtoneManager;
import android.net.Uri; import android.net.Uri;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock; import android.os.SystemClock;
import android.os.UEventObserver; import android.os.UEventObserver;
import android.provider.Settings; import android.provider.Settings;
import android.service.dreams.IDreamManager;
import android.util.Log; import android.util.Log;
import android.util.Slog; import android.util.Slog;
@@ -194,7 +197,29 @@ class DockObserver extends UEventObserver {
} }
} }
mContext.sendStickyBroadcast(intent); IDreamManager mgr = IDreamManager.Stub.asInterface(ServiceManager.getService("dreams"));
if (mgr != null) {
// dreams feature enabled
boolean undocked = mDockState == Intent.EXTRA_DOCK_STATE_UNDOCKED;
if (undocked) {
try {
if (mgr.isDreaming()) {
mgr.awaken();
}
} catch (RemoteException e) {
Slog.w(TAG, "Unable to awaken!", e);
}
} else {
try {
mgr.dream();
} catch (RemoteException e) {
Slog.w(TAG, "Unable to dream!", e);
}
}
} else {
// dreams feature not enabled, send legacy intent
mContext.sendStickyBroadcast(intent);
}
} }
break; break;
} }

View File

@@ -424,6 +424,11 @@ public class PowerManagerService extends IPowerManager.Stub
forceUserActivityLocked(); forceUserActivityLocked();
} }
} }
// stop the screensaver if we're now unplugged
if (mPolicy != null) {
mPolicy.stopScreenSaver();
}
} }
} }
} }
@@ -1826,7 +1831,7 @@ public class PowerManagerService extends IPowerManager.Stub
final boolean stateChanged = mPowerState != newState; final boolean stateChanged = mPowerState != newState;
if (stateChanged && reason == WindowManagerPolicy.OFF_BECAUSE_OF_TIMEOUT) { if (stateChanged && reason == WindowManagerPolicy.OFF_BECAUSE_OF_TIMEOUT) {
if (mPolicy != null && mPolicy.isScreenSaverEnabled()) { if (mPolicy != null && mPolicy.isScreenSaverEnabled() && mIsPowered) {
if (DEBUG) { if (DEBUG) {
Slog.d(TAG, "setPowerState: running screen saver instead of turning off screen"); Slog.d(TAG, "setPowerState: running screen saver instead of turning off screen");
} }
@@ -1922,6 +1927,13 @@ public class PowerManagerService extends IPowerManager.Stub
} else { } else {
err = 0; err = 0;
} }
// stop the screensaver if user turned screen off
if (stateChanged && reason == WindowManagerPolicy.OFF_BECAUSE_OF_USER) {
if (mPolicy != null) {
mPolicy.stopScreenSaver();
}
}
} }
} else if (stateChanged) { } else if (stateChanged) {
// Screen on/off didn't change, but lights may have. // Screen on/off didn't change, but lights may have.