Fix issue #2133206: dialogs/menus should auto-dismiss when screen turns off
Lot of infrastructure for more things to go away when "clear system dialogs"
happens, and now do this when we turn on the lock screen.
Change-Id: I567130296fe47ce82df065ed58ef21b37416ceaf
diff --git a/api/current.xml b/api/current.xml
index 36a82a8..b5352d1 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -3573,6 +3573,17 @@
visibility="public"
>
</field>
+<field name="finishOnCloseSystemDialogs"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16843431"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
<field name="finishOnTaskLaunch"
type="int"
transient="false"
@@ -39185,6 +39196,17 @@
visibility="public"
>
</field>
+<field name="FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="256"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
<field name="FLAG_FINISH_ON_TASK_LAUNCH"
type="int"
transient="false"
@@ -156755,6 +156777,19 @@
visibility="public"
>
</method>
+<method name="onCloseSystemDialogs"
+ return="void"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="reason" type="java.lang.String">
+</parameter>
+</method>
<method name="onCreateContextMenu"
return="void"
abstract="false"
diff --git a/core/java/android/content/pm/ActivityInfo.java b/core/java/android/content/pm/ActivityInfo.java
index 1ad13c5..87da55f 100644
--- a/core/java/android/content/pm/ActivityInfo.java
+++ b/core/java/android/content/pm/ActivityInfo.java
@@ -127,12 +127,20 @@
*/
public static final int FLAG_NO_HISTORY = 0x0080;
/**
+ * Bit in {@link #flags} indicating that, when a request to close system
+ * windows happens, this activity is finished.
+ * Set from the
+ * {@link android.R.attr#finishOnCloseSystemDialogs} attribute.
+ */
+ public static final int FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS = 0x0100;
+ /**
* Options that have been set in the activity declaration in the
* manifest: {@link #FLAG_MULTIPROCESS},
* {@link #FLAG_FINISH_ON_TASK_LAUNCH}, {@link #FLAG_CLEAR_TASK_ON_LAUNCH},
* {@link #FLAG_ALWAYS_RETAIN_TASK_STATE},
* {@link #FLAG_STATE_NOT_NEEDED}, {@link #FLAG_EXCLUDE_FROM_RECENTS},
- * {@link #FLAG_ALLOW_TASK_REPARENTING}, {@link #FLAG_NO_HISTORY}.
+ * {@link #FLAG_ALLOW_TASK_REPARENTING}, {@link #FLAG_NO_HISTORY},
+ * {@link #FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS}.
*/
public int flags;
diff --git a/core/java/android/content/pm/PackageParser.java b/core/java/android/content/pm/PackageParser.java
index b4a6fee..27c65f0 100644
--- a/core/java/android/content/pm/PackageParser.java
+++ b/core/java/android/content/pm/PackageParser.java
@@ -1658,6 +1658,12 @@
a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING;
}
+ if (sa.getBoolean(
+ com.android.internal.R.styleable.AndroidManifestActivity_finishOnCloseSystemDialogs,
+ false)) {
+ a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS;
+ }
+
if (!receiver) {
a.info.launchMode = sa.getInt(
com.android.internal.R.styleable.AndroidManifestActivity_launchMode,
diff --git a/core/java/android/view/IWindow.aidl b/core/java/android/view/IWindow.aidl
index b7953af2..7977578 100644
--- a/core/java/android/view/IWindow.aidl
+++ b/core/java/android/view/IWindow.aidl
@@ -57,6 +57,8 @@
*/
void windowFocusChanged(boolean hasFocus, boolean inTouchMode);
+ void closeSystemDialogs(String reason);
+
/**
* Called for wallpaper windows when their offsets change.
*/
diff --git a/core/java/android/view/IWindowManager.aidl b/core/java/android/view/IWindowManager.aidl
index 3e6cdc2..7d1872a 100644
--- a/core/java/android/view/IWindowManager.aidl
+++ b/core/java/android/view/IWindowManager.aidl
@@ -90,6 +90,8 @@
void exitKeyguardSecurely(IOnKeyguardExitResult callback);
boolean inKeyguardRestrictedInputMode();
+ void closeSystemDialogs(String reason);
+
// These can only be called with the SET_ANIMATON_SCALE permission.
float getAnimationScale(int which);
float[] getAnimationScales();
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 6ff0fc8..642f0fa 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -8099,6 +8099,13 @@
}
/**
+ * This needs to be a better API (NOT ON VIEW) before it is exposed. If
+ * it is ever exposed at all.
+ */
+ public void onCloseSystemDialogs(String reason) {
+ }
+
+ /**
* Given a Drawable whose bounds have been set to draw into this view,
* update a Region being computed for {@link #gatherTransparentRegion} so
* that any non-transparent parts of the Drawable are removed from the
diff --git a/core/java/android/view/ViewRoot.java b/core/java/android/view/ViewRoot.java
index c6937a3..398abf8 100644
--- a/core/java/android/view/ViewRoot.java
+++ b/core/java/android/view/ViewRoot.java
@@ -1610,6 +1610,7 @@
public final static int DISPATCH_KEY_FROM_IME = 1011;
public final static int FINISH_INPUT_CONNECTION = 1012;
public final static int CHECK_FOCUS = 1013;
+ public final static int CLOSE_SYSTEM_DIALOGS = 1014;
@Override
public void handleMessage(Message msg) {
@@ -1867,6 +1868,11 @@
imm.checkFocus();
}
} break;
+ case CLOSE_SYSTEM_DIALOGS: {
+ if (mView != null) {
+ mView.onCloseSystemDialogs((String)msg.obj);
+ }
+ } break;
}
}
@@ -2630,6 +2636,13 @@
sendMessage(msg);
}
+ public void dispatchCloseSystemDialogs(String reason) {
+ Message msg = Message.obtain();
+ msg.what = CLOSE_SYSTEM_DIALOGS;
+ msg.obj = reason;
+ sendMessage(msg);
+ }
+
/**
* The window is getting focus so if there is anything focused/selected
* send an {@link AccessibilityEvent} to announce that.
@@ -2869,6 +2882,13 @@
}
}
+ public void closeSystemDialogs(String reason) {
+ final ViewRoot viewRoot = mViewRoot.get();
+ if (viewRoot != null) {
+ viewRoot.dispatchCloseSystemDialogs(reason);
+ }
+ }
+
public void dispatchWallpaperOffsets(float x, float y, boolean sync) {
if (sync) {
try {
diff --git a/core/java/com/android/internal/view/BaseIWindow.java b/core/java/com/android/internal/view/BaseIWindow.java
index b8d19ac..38ef0c2 100644
--- a/core/java/com/android/internal/view/BaseIWindow.java
+++ b/core/java/com/android/internal/view/BaseIWindow.java
@@ -90,6 +90,9 @@
public void executeCommand(String command, String parameters, ParcelFileDescriptor out) {
}
+ public void closeSystemDialogs(String reason) {
+ }
+
public void dispatchWallpaperOffsets(float x, float y, boolean sync) {
if (sync) {
try {
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index c4536be..3242ed2 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -1134,6 +1134,7 @@
android:icon="@drawable/ic_launcher_android">
<activity android:name="com.android.internal.app.ChooserActivity"
android:theme="@style/Theme.Dialog.Alert"
+ android:finishOnCloseSystemDialogs="true"
android:excludeFromRecents="true"
android:multiprocess="true">
<intent-filter>
diff --git a/core/res/res/anim/task_close_enter.xml b/core/res/res/anim/task_close_enter.xml
index 303cfd6..c42ad83 100644
--- a/core/res/res/anim/task_close_enter.xml
+++ b/core/res/res/anim/task_close_enter.xml
@@ -18,9 +18,14 @@
-->
<set xmlns:android="http://schemas.android.com/apk/res/android"
- android:interpolator="@anim/decelerate_interpolator">
+ android:interpolator="@anim/decelerate_interpolator"
+ android:zAdjustment="top">
+ <!-- For now stay like the normal activity transition.
<scale android:fromXScale="2.0" android:toXScale="1.0"
android:fromYScale="2.0" android:toYScale="1.0"
- android:pivotX="50%p" android:pivotY="50%p"
- android:duration="@android:integer/config_mediumAnimTime" />
+ android:pivotX="100%p" android:pivotY="50%p"
+ android:duration="@android:integer/config_shortAnimTime" />
+ -->
+ <translate android:fromXDelta="-100%" android:toXDelta="0"
+ android:duration="@android:integer/config_shortAnimTime"/>
</set>
diff --git a/core/res/res/anim/task_close_exit.xml b/core/res/res/anim/task_close_exit.xml
index a28ac3b..66d3480 100644
--- a/core/res/res/anim/task_close_exit.xml
+++ b/core/res/res/anim/task_close_exit.xml
@@ -18,12 +18,7 @@
-->
<set xmlns:android="http://schemas.android.com/apk/res/android"
- android:interpolator="@anim/decelerate_interpolator"
- android:zAdjustment="top">
- <scale android:fromXScale="1.0" android:toXScale=".5"
- android:fromYScale="1.0" android:toYScale=".5"
- android:pivotX="50%p" android:pivotY="50%p"
- android:duration="@android:integer/config_mediumAnimTime" />
- <alpha android:fromAlpha="1.0" android:toAlpha="0"
- android:duration="@android:integer/config_mediumAnimTime"/>
+ android:interpolator="@anim/decelerate_interpolator">
+ <translate android:fromXDelta="0%" android:toXDelta="33%"
+ android:duration="@android:integer/config_shortAnimTime"/>
</set>
diff --git a/core/res/res/anim/task_open_enter.xml b/core/res/res/anim/task_open_enter.xml
index 234abb2..66adf9f 100644
--- a/core/res/res/anim/task_open_enter.xml
+++ b/core/res/res/anim/task_open_enter.xml
@@ -18,12 +18,7 @@
-->
<set xmlns:android="http://schemas.android.com/apk/res/android"
- android:interpolator="@anim/decelerate_interpolator"
- android:zAdjustment="top">
- <scale android:fromXScale=".5" android:toXScale="1.0"
- android:fromYScale=".5" android:toYScale="1.0"
- android:pivotX="50%p" android:pivotY="50%p"
- android:duration="@android:integer/config_mediumAnimTime" />
- <alpha android:fromAlpha="0.0" android:toAlpha="1.0"
- android:duration="@android:integer/config_mediumAnimTime"/>
+ android:interpolator="@anim/decelerate_interpolator">
+ <translate android:fromXDelta="33%" android:toXDelta="0"
+ android:duration="@android:integer/config_shortAnimTime"/>
</set>
diff --git a/core/res/res/anim/task_open_exit.xml b/core/res/res/anim/task_open_exit.xml
index db331b1..4a2cef4 100644
--- a/core/res/res/anim/task_open_exit.xml
+++ b/core/res/res/anim/task_open_exit.xml
@@ -18,9 +18,14 @@
-->
<set xmlns:android="http://schemas.android.com/apk/res/android"
- android:interpolator="@anim/decelerate_interpolator">
+ android:interpolator="@anim/decelerate_interpolator"
+ android:zAdjustment="top">
+ <!-- For now stay like the normal activity transition.
<scale android:fromXScale="1.0" android:toXScale="2.0"
android:fromYScale="1.0" android:toYScale="2.0"
- android:pivotX="50%p" android:pivotY="50%p"
- android:duration="@android:integer/config_mediumAnimTime" />
+ android:pivotX="100%p" android:pivotY="50%p"
+ android:duration="@android:integer/config_shortAnimTime" />
+ -->
+ <translate android:fromXDelta="0%" android:toXDelta="-100%"
+ android:duration="@android:integer/config_shortAnimTime"/>
</set>
diff --git a/core/res/res/values/attrs_manifest.xml b/core/res/res/values/attrs_manifest.xml
index 365363a..85f5ce3 100644
--- a/core/res/res/values/attrs_manifest.xml
+++ b/core/res/res/values/attrs_manifest.xml
@@ -288,6 +288,12 @@
ignored and the activity simply finished. -->
<attr name="finishOnTaskLaunch" format="boolean" />
+ <!-- Specify whether an activity should be finished when a "close system
+ windows" request has been made. This happens, for example, when
+ the home key is pressed, when the device is locked, when a system
+ dialog like recent apps is displayed, etc. -->
+ <attr name="finishOnCloseSystemDialogs" format="boolean" />
+
<!-- Specify whether an activity's task should be cleared when it
is re-launched from the home screen. As a result, every time the
user starts the task, they will be brought to its root activity,
@@ -1078,6 +1084,7 @@
<attr name="taskAffinity" />
<attr name="allowTaskReparenting" />
<attr name="finishOnTaskLaunch" />
+ <attr name="finishOnCloseSystemDialogs" />
<attr name="clearTaskOnLaunch" />
<attr name="noHistory" />
<attr name="alwaysRetainTaskState" />
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index a32f519..b508372 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -30,7 +30,7 @@
<integer name="config_shortAnimTime">150</integer>
<!-- The duration (in milliseconds) of a medium-length animation. -->
- <integer name="config_mediumAnimTime">250</integer>
+ <integer name="config_mediumAnimTime">200</integer>
<!-- The duration (in milliseconds) of a long animation. -->
<integer name="config_longAnimTime">400</integer>
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index 305e415..257e0f2 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -1171,6 +1171,7 @@
<public type="attr" name="detailSocialSummary" />
<public type="attr" name="thumbnail" />
<public type="attr" name="detachWallpaper" />
+ <public type="attr" name="finishOnCloseSystemDialogs" />
<public type="style" name="Theme.Wallpaper" />
<public type="style" name="Theme.Wallpaper.NoTitleBar" />
diff --git a/core/res/res/values/styles.xml b/core/res/res/values/styles.xml
index 6426080..47c68ad 100644
--- a/core/res/res/values/styles.xml
+++ b/core/res/res/values/styles.xml
@@ -58,19 +58,6 @@
<item name="activityOpenExitAnimation">@anim/activity_open_exit</item>
<item name="activityCloseEnterAnimation">@anim/activity_close_enter</item>
<item name="activityCloseExitAnimation">@anim/activity_close_exit</item>
- <item name="taskOpenEnterAnimation">@anim/activity_open_enter</item>
- <item name="taskOpenExitAnimation">@anim/activity_open_exit</item>
- <item name="taskCloseEnterAnimation">@anim/activity_close_enter</item>
- <item name="taskCloseExitAnimation">@anim/activity_close_exit</item>
- <item name="taskToFrontEnterAnimation">@anim/activity_open_enter</item>
- <item name="taskToFrontExitAnimation">@anim/activity_open_exit</item>
- <item name="taskToBackEnterAnimation">@anim/activity_close_enter</item>
- <item name="taskToBackExitAnimation">@anim/activity_close_exit</item>
- <!-- There is a good argument to be made that the user shouldn't
- be aware of task transitions, so we are going to use the same
- animation for them as we do for regular activity transitions. -->
- <!-- These provide an alternative animation for task transitions. -->
- <!--
<item name="taskOpenEnterAnimation">@anim/task_open_enter</item>
<item name="taskOpenExitAnimation">@anim/task_open_exit</item>
<item name="taskCloseEnterAnimation">@anim/task_close_enter</item>
@@ -79,7 +66,6 @@
<item name="taskToFrontExitAnimation">@anim/task_open_exit</item>
<item name="taskToBackEnterAnimation">@anim/task_close_enter</item>
<item name="taskToBackExitAnimation">@anim/task_close_exit</item>
- -->
<item name="wallpaperOpenEnterAnimation">@anim/wallpaper_open_enter</item>
<item name="wallpaperOpenExitAnimation">@anim/wallpaper_open_exit</item>
<item name="wallpaperCloseEnterAnimation">@anim/wallpaper_close_enter</item>
diff --git a/services/java/com/android/server/WindowManagerService.java b/services/java/com/android/server/WindowManagerService.java
index f742f9f..2c39c2a 100644
--- a/services/java/com/android/server/WindowManagerService.java
+++ b/services/java/com/android/server/WindowManagerService.java
@@ -3913,6 +3913,20 @@
return mPolicy.inKeyguardRestrictedKeyInputMode();
}
+ public void closeSystemDialogs(String reason) {
+ synchronized(mWindowMap) {
+ for (int i=mWindows.size()-1; i>=0; i--) {
+ WindowState w = (WindowState)mWindows.get(i);
+ if (w.mSurface != null) {
+ try {
+ w.mClient.closeSystemDialogs(reason);
+ } catch (RemoteException e) {
+ }
+ }
+ }
+ }
+ }
+
static float fixScale(float scale) {
if (scale < 0) scale = 0;
else if (scale > 20) scale = 20;
diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java
index 8ea2221..750c44e 100644
--- a/services/java/com/android/server/am/ActivityManagerService.java
+++ b/services/java/com/android/server/am/ActivityManagerService.java
@@ -4957,6 +4957,16 @@
}
mWatchers.finishBroadcast();
+ mWindowManager.closeSystemDialogs(reason);
+
+ for (i=mHistory.size()-1; i>=0; i--) {
+ HistoryRecord r = (HistoryRecord)mHistory.get(i);
+ if ((r.info.flags&ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS) != 0) {
+ finishActivityLocked(r, i,
+ Activity.RESULT_CANCELED, null, "close-sys");
+ }
+ }
+
broadcastIntentLocked(null, null, intent, null,
null, 0, null, null, null, false, false, -1, uid);
}
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java
index e4ff494..d28a151 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java
@@ -1067,7 +1067,12 @@
public void wallpaperOffsetsComplete(IBinder window) {
// pass for now.
}
-
+
+ @SuppressWarnings("unused")
+ public void closeSystemDialogs(String reason) {
+ // pass for now.
+ }
+
public IBinder asBinder() {
// pass for now.
return null;
@@ -1126,6 +1131,11 @@
// pass for now.
}
+ @SuppressWarnings("unused")
+ public void closeSystemDialogs(String reason) {
+ // pass for now.
+ }
+
public IBinder asBinder() {
// pass for now.
return null;