Skip to content

Commit a2fbe53

Browse files
committed
More termination conditions for Dreams.
Default implementation of Dreams will finish() on KEYCODE_BACK. PhoneStatusBar will awaken() from any Dream when the Home key is pressed. Change-Id: I55e2a5d533a7fb93debc4c54514dba3b9098f009
1 parent 7c46e43 commit a2fbe53

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

core/java/android/service/dreams/Dream.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,13 @@ public class Dream extends Service implements Window.Callback {
7070
// begin Window.Callback methods
7171
@Override
7272
public boolean dispatchKeyEvent(KeyEvent event) {
73-
if (!mInteractive) {
73+
// TODO: create more flexible version of mInteractive that allows use of KEYCODE_BACK
74+
if (!mInteractive) {
75+
if (DEBUG) Slog.v(TAG, "finishing on keyEvent");
76+
finish();
77+
return true;
78+
} else if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
79+
if (DEBUG) Slog.v(TAG, "finishing on back key");
7480
finish();
7581
return true;
7682
}
@@ -80,6 +86,7 @@ public boolean dispatchKeyEvent(KeyEvent event) {
8086
@Override
8187
public boolean dispatchKeyShortcutEvent(KeyEvent event) {
8288
if (!mInteractive) {
89+
if (DEBUG) Slog.v(TAG, "finishing on keyShortcutEvent");
8390
finish();
8491
return true;
8592
}
@@ -88,7 +95,10 @@ public boolean dispatchKeyShortcutEvent(KeyEvent event) {
8895

8996
@Override
9097
public boolean dispatchTouchEvent(MotionEvent event) {
98+
// TODO: create more flexible version of mInteractive that allows clicks
99+
// but finish()es on any other kind of activity
91100
if (!mInteractive) {
101+
if (DEBUG) Slog.v(TAG, "finishing on touchEvent");
92102
finish();
93103
return true;
94104
}
@@ -97,7 +107,8 @@ public boolean dispatchTouchEvent(MotionEvent event) {
97107

98108
@Override
99109
public boolean dispatchTrackballEvent(MotionEvent event) {
100-
if (!mInteractive) {
110+
if (!mInteractive) {
111+
if (DEBUG) Slog.v(TAG, "finishing on trackballEvent");
101112
finish();
102113
return true;
103114
}
@@ -107,6 +118,7 @@ public boolean dispatchTrackballEvent(MotionEvent event) {
107118
@Override
108119
public boolean dispatchGenericMotionEvent(MotionEvent event) {
109120
if (!mInteractive) {
121+
if (DEBUG) Slog.v(TAG, "finishing on genericMotionEvent");
110122
finish();
111123
return true;
112124
}

packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import android.os.SystemClock;
4949
import android.os.UserId;
5050
import android.provider.Settings;
51+
import android.service.dreams.IDreamManager;
5152
import android.util.DisplayMetrics;
5253
import android.util.Log;
5354
import android.util.Slog;
@@ -153,6 +154,7 @@ public class PhoneStatusBar extends BaseStatusBar {
153154
Display mDisplay;
154155

155156
IWindowManager mWindowManager;
157+
IDreamManager mDreamManager;
156158

157159
StatusBarWindowView mStatusBarWindow;
158160
PhoneStatusBarView mStatusBarView;
@@ -302,6 +304,9 @@ public void start() {
302304
mWindowManager = IWindowManager.Stub.asInterface(
303305
ServiceManager.getService(Context.WINDOW_SERVICE));
304306

307+
mDreamManager = IDreamManager.Stub.asInterface(
308+
ServiceManager.checkService("dreams"));
309+
305310
super.start(); // calls createAndAddWindows()
306311

307312
addNavigationBar();
@@ -606,6 +611,7 @@ public void onClick(View v) {
606611
private Runnable mShowSearchPanel = new Runnable() {
607612
public void run() {
608613
showSearchPanel();
614+
awakenDreams();
609615
}
610616
};
611617

@@ -622,12 +628,23 @@ public boolean onTouch(View v, MotionEvent event) {
622628
case MotionEvent.ACTION_UP:
623629
case MotionEvent.ACTION_CANCEL:
624630
mHandler.removeCallbacks(mShowSearchPanel);
631+
awakenDreams();
625632
break;
626633
}
627634
return false;
628635
}
629636
};
630637

638+
private void awakenDreams() {
639+
if (mDreamManager != null) {
640+
try {
641+
mDreamManager.awaken();
642+
} catch (RemoteException e) {
643+
// fine, stay asleep then
644+
}
645+
}
646+
}
647+
631648
private void prepareNavigationBarView() {
632649
mNavigationBarView.reorient();
633650

0 commit comments

Comments
 (0)