Skip to content

Commit 5962b12

Browse files
author
Craig Mautner
committed
Adds showWhenLocked attribute to Activities.
The new attribute allows an Activity such as the alarm to appear on all users screens. Bug: 7213805 fixed. Change-Id: If7866b13d88c04af07debc69e0e875d0adc6050a
1 parent 88400d3 commit 5962b12

File tree

16 files changed

+69
-23
lines changed

16 files changed

+69
-23
lines changed

api/17.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,7 @@ package android {
912912
field public static final int showAsAction = 16843481; // 0x10102d9
913913
field public static final int showDefault = 16843258; // 0x10101fa
914914
field public static final int showDividers = 16843561; // 0x1010329
915+
field public static final int showOnLockScreen = 16843721; // 0x10103c9
915916
field public static final int showSilent = 16843259; // 0x10101fb
916917
field public static final int showWeekNumber = 16843582; // 0x101033e
917918
field public static final int shownWeekCount = 16843585; // 0x1010341

api/current.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,7 @@ package android {
912912
field public static final int showAsAction = 16843481; // 0x10102d9
913913
field public static final int showDefault = 16843258; // 0x10101fa
914914
field public static final int showDividers = 16843561; // 0x1010329
915+
field public static final int showOnLockScreen = 16843721; // 0x10103c9
915916
field public static final int showSilent = 16843259; // 0x10101fb
916917
field public static final int showWeekNumber = 16843582; // 0x101033e
917918
field public static final int shownWeekCount = 16843585; // 0x1010341

core/java/android/content/pm/ActivityInfo.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ public class ActivityInfo extends ComponentInfo
154154
* be hardware accelerated.
155155
*/
156156
public static final int FLAG_HARDWARE_ACCELERATED = 0x0200;
157+
/**
158+
* Value for {@link #flags}: true when the application can be displayed over the lockscreen
159+
* and consequently over all users' windows.
160+
* @hide
161+
*/
162+
public static final int FLAG_SHOW_ON_LOCK_SCREEN = 0x0400;
157163
/**
158164
* @hide
159165
* Bit in {@link #flags} corresponding to an immersive activity
@@ -170,7 +176,7 @@ public class ActivityInfo extends ComponentInfo
170176
* "toast" window).
171177
* {@see android.app.Notification#FLAG_HIGH_PRIORITY}
172178
*/
173-
public static final int FLAG_IMMERSIVE = 0x0400;
179+
public static final int FLAG_IMMERSIVE = 0x0800;
174180
/**
175181
* @hide Bit in {@link #flags}: If set, this component will only be seen
176182
* by the primary user. Only works with broadcast receivers. Set from the

core/java/android/content/pm/PackageParser.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2159,12 +2159,18 @@ private Activity parseActivity(Package owner, Resources res,
21592159
a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS;
21602160
}
21612161

2162+
if (sa.getBoolean(
2163+
com.android.internal.R.styleable.AndroidManifestActivity_showOnLockScreen,
2164+
false)) {
2165+
a.info.flags |= ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN;
2166+
}
2167+
21622168
if (sa.getBoolean(
21632169
com.android.internal.R.styleable.AndroidManifestActivity_immersive,
21642170
false)) {
21652171
a.info.flags |= ActivityInfo.FLAG_IMMERSIVE;
21662172
}
2167-
2173+
21682174
if (!receiver) {
21692175
if (sa.getBoolean(
21702176
com.android.internal.R.styleable.AndroidManifestActivity_hardwareAccelerated,

core/java/android/view/IWindowManager.aidl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ interface IWindowManager
7474
void addWindowToken(IBinder token, int type);
7575
void removeWindowToken(IBinder token);
7676
void addAppToken(int addPos, IApplicationToken token,
77-
int groupId, int requestedOrientation, boolean fullscreen);
77+
int groupId, int requestedOrientation, boolean fullscreen, boolean showWhenLocked);
7878
void setAppGroupId(IBinder token, int groupId);
7979
void setAppOrientation(IApplicationToken token, int requestedOrientation);
8080
int getAppOrientation(IApplicationToken token);

core/java/android/view/WindowManager.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,14 @@ public static class LayoutParams extends ViewGroup.LayoutParams
219219
* Window type: an application window that serves as the "base" window
220220
* of the overall application; all other application windows will
221221
* appear on top of it.
222+
* In multiuser systems shows only on the owning user's window.
222223
*/
223224
public static final int TYPE_BASE_APPLICATION = 1;
224225

225226
/**
226227
* Window type: a normal application window. The {@link #token} must be
227228
* an Activity token identifying who the window belongs to.
229+
* In multiuser systems shows only on the owning user's window.
228230
*/
229231
public static final int TYPE_APPLICATION = 2;
230232

@@ -233,6 +235,7 @@ public static class LayoutParams extends ViewGroup.LayoutParams
233235
* application is starting. Not for use by applications themselves;
234236
* this is used by the system to display something until the
235237
* application can show its own windows.
238+
* In multiuser systems shows on all users' windows.
236239
*/
237240
public static final int TYPE_APPLICATION_STARTING = 3;
238241

core/res/res/values/attrs_manifest.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,10 @@
444444
recently launched activities. -->
445445
<attr name="excludeFromRecents" format="boolean" />
446446

447+
<!-- Specify that an Activity should be shown over the lock screen and,
448+
in a multiuser environment, across all users' windows -->
449+
<attr name="showOnLockScreen" format="boolean" />
450+
447451
<!-- Specify the authorities under which this content provider can be
448452
found. Multiple authorities may be supplied by separating them
449453
with a semicolon. Authority names should use a Java-style naming
@@ -1376,6 +1380,7 @@
13761380
<attr name="alwaysRetainTaskState" />
13771381
<attr name="stateNotNeeded" />
13781382
<attr name="excludeFromRecents" />
1383+
<attr name="showOnLockScreen" />
13791384
<!-- Specify whether the activity is enabled or not (that is, can be instantiated by the system).
13801385
It can also be specified for an application as a whole, in which case a value of "false"
13811386
will override any component specific values (a value of "true" will not override the

core/res/res/values/public.xml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2018,10 +2018,12 @@
20182018
<public type="attr" name="permissionGroupFlags" id="0x010103c5" />
20192019
<public type="attr" name="labelFor" id="0x010103c6" />
20202020
<public type="attr" name="permissionFlags" id="0x010103c7" />
2021-
<public type="attr" name="checkedTextViewStyle" />
2022-
<public type="style" name="Widget.Holo.CheckedTextView" />
2023-
<public type="style" name="Widget.Holo.Light.CheckedTextView" />
2024-
<public type="style" name="Widget.DeviceDefault.CheckedTextView" />
2025-
<public type="style" name="Widget.DeviceDefault.Light.CheckedTextView" />
2021+
<public type="attr" name="checkedTextViewStyle" id="0x010103c8" />
2022+
<public type="attr" name="showOnLockScreen" id="0x010103c9" />
2023+
2024+
<public type="style" name="Widget.Holo.CheckedTextView" id="0x010301d9" />
2025+
<public type="style" name="Widget.Holo.Light.CheckedTextView" id="0x010301da" />
2026+
<public type="style" name="Widget.DeviceDefault.CheckedTextView" id="0x010301db" />
2027+
<public type="style" name="Widget.DeviceDefault.Light.CheckedTextView" id="0x010301dc" />
20262028

20272029
</resources>

services/java/com/android/server/am/ActivityManagerService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7453,6 +7453,7 @@ public final void showSafeModeOverlay() {
74537453
lp.format = v.getBackground().getOpacity();
74547454
lp.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
74557455
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
7456+
lp.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
74567457
((WindowManager)mContext.getSystemService(
74577458
Context.WINDOW_SERVICE)).addView(v, lp);
74587459
}

services/java/com/android/server/am/ActivityStack.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -420,12 +420,17 @@ public void handleMessage(Message msg) {
420420
mLaunchingActivity = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ActivityManager-Launch");
421421
mLaunchingActivity.setReferenceCounted(false);
422422
}
423-
423+
424+
private boolean okToShow(ActivityRecord r) {
425+
return r.userId == mCurrentUser
426+
|| (r.info.flags & ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN) != 0;
427+
}
428+
424429
final ActivityRecord topRunningActivityLocked(ActivityRecord notTop) {
425430
int i = mHistory.size()-1;
426431
while (i >= 0) {
427432
ActivityRecord r = mHistory.get(i);
428-
if (!r.finishing && r != notTop && r.userId == mCurrentUser) {
433+
if (!r.finishing && r != notTop && okToShow(r)) {
429434
return r;
430435
}
431436
i--;
@@ -437,7 +442,7 @@ final ActivityRecord topRunningNonDelayedActivityLocked(ActivityRecord notTop) {
437442
int i = mHistory.size()-1;
438443
while (i >= 0) {
439444
ActivityRecord r = mHistory.get(i);
440-
if (!r.finishing && !r.delayedResume && r != notTop && r.userId == mCurrentUser) {
445+
if (!r.finishing && !r.delayedResume && r != notTop && okToShow(r)) {
441446
return r;
442447
}
443448
i--;
@@ -460,7 +465,7 @@ final ActivityRecord topRunningActivityLocked(IBinder token, int taskId) {
460465
ActivityRecord r = mHistory.get(i);
461466
// Note: the taskId check depends on real taskId fields being non-zero
462467
if (!r.finishing && (token != r.appToken) && (taskId != r.task.taskId)
463-
&& r.userId == mCurrentUser) {
468+
&& okToShow(r)) {
464469
return r;
465470
}
466471
i--;
@@ -1806,7 +1811,8 @@ private final void startActivityLocked(ActivityRecord r, boolean newTask,
18061811
mHistory.add(addPos, r);
18071812
r.putInHistory();
18081813
mService.mWindowManager.addAppToken(addPos, r.appToken, r.task.taskId,
1809-
r.info.screenOrientation, r.fullscreen);
1814+
r.info.screenOrientation, r.fullscreen,
1815+
(r.info.flags & ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN) != 0);
18101816
if (VALIDATE_TOKENS) {
18111817
validateAppTokensLocked();
18121818
}
@@ -1870,7 +1876,8 @@ private final void startActivityLocked(ActivityRecord r, boolean newTask,
18701876
}
18711877
r.updateOptionsLocked(options);
18721878
mService.mWindowManager.addAppToken(
1873-
addPos, r.appToken, r.task.taskId, r.info.screenOrientation, r.fullscreen);
1879+
addPos, r.appToken, r.task.taskId, r.info.screenOrientation, r.fullscreen,
1880+
(r.info.flags & ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN) != 0);
18741881
boolean doShow = true;
18751882
if (newTask) {
18761883
// Even though this activity is starting fresh, we still need
@@ -1908,7 +1915,8 @@ private final void startActivityLocked(ActivityRecord r, boolean newTask,
19081915
// If this is the first activity, don't do any fancy animations,
19091916
// because there is nothing for it to animate on top of.
19101917
mService.mWindowManager.addAppToken(addPos, r.appToken, r.task.taskId,
1911-
r.info.screenOrientation, r.fullscreen);
1918+
r.info.screenOrientation, r.fullscreen,
1919+
(r.info.flags & ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN) != 0);
19121920
ActivityOptions.abort(options);
19131921
}
19141922
if (VALIDATE_TOKENS) {
@@ -2616,7 +2624,6 @@ final int startActivityUncheckedLocked(ActivityRecord r,
26162624
Bundle options) {
26172625
final Intent intent = r.intent;
26182626
final int callingUid = r.launchedFromUid;
2619-
final int userId = r.userId;
26202627

26212628
int launchFlags = intent.getFlags();
26222629

0 commit comments

Comments
 (0)