Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 59b9885b authored by chaviw's avatar chaviw
Browse files

Added Activity flags to show on lock screen.

Added two new flags to the Activity to turn the screen on and
show on the lock screen. These can be used instead of the Window flags
LayouParams.FLAG_TURN_SCREEN_ON and LayoutParams.FLAG_SHOW_WHEN_LOCKED
to prevent the double onStart/onResume lifecycle events.

The flags can be set as an attr for the Activity in the AndroidManifest
using android:showWhenLocked="true" and android:turnScreenOn="true".
They can also be set through methods in the Activity class using
setShowWhenLocked(true) and setTurnScreen(true).

Fixes: 36850100
Test: Created sample application, tests/ShowWhenLockedApp, that set the
      flags in the manifest and code. Tested multiple scenarios to
      launch the Activity with the flags set and unset.
Test: cts-tradefed run commandAndExit cts-dev --module CtsServicesHostTestCases -t android.server.cts.KeyguardTransitionTests
Test: cts-tradefed run commandAndExit cts-dev --module CtsServicesHostTestCases -t android.server.cts.ActivityManagerActivityVisibilityTests
Test: cts-tradefed run commandAndExit cts-dev --module CtsServicesHostTestCases -t android.server.cts.KeyguardTests

Change-Id: I44f0e313df4531d49c7ac56108b6bf80e41fefc1
parent e3bb95dd
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -1180,6 +1180,7 @@ package android {
    field public static final int showSilent = 16843259; // 0x10101fb
    field public static final int showText = 16843949; // 0x10104ad
    field public static final deprecated int showWeekNumber = 16843582; // 0x101033e
    field public static final int showWhenLocked = 16844137; // 0x1010569
    field public static final deprecated int shownWeekCount = 16843585; // 0x1010341
    field public static final int shrinkColumns = 16843082; // 0x101014a
    field public static final deprecated int singleLine = 16843101; // 0x101015d
@@ -1438,6 +1439,7 @@ package android {
    field public static final int trimPathOffset = 16843786; // 0x101040a
    field public static final int trimPathStart = 16843784; // 0x1010408
    field public static final int tunerCount = 16844061; // 0x101051d
    field public static final int turnScreenOn = 16844138; // 0x101056a
    field public static final int type = 16843169; // 0x10101a1
    field public static final int typeface = 16842902; // 0x1010096
    field public static final int uiOptions = 16843672; // 0x1010398
@@ -3764,10 +3766,12 @@ package android.app {
    method public final void setResult(int);
    method public final void setResult(int, android.content.Intent);
    method public final deprecated void setSecondaryProgress(int);
    method public void setShowWhenLocked(boolean);
    method public void setTaskDescription(android.app.ActivityManager.TaskDescription);
    method public void setTitle(java.lang.CharSequence);
    method public void setTitle(int);
    method public deprecated void setTitleColor(int);
    method public void setTurnScreenOn(boolean);
    method public void setVisible(boolean);
    method public final void setVolumeControlStream(int);
    method public void setVrModeEnabled(boolean, android.content.ComponentName) throws android.content.pm.PackageManager.NameNotFoundException;
@@ -46969,12 +46973,12 @@ package android.view {
    field public static final int FLAG_SCALED = 16384; // 0x4000
    field public static final int FLAG_SECURE = 8192; // 0x2000
    field public static final int FLAG_SHOW_WALLPAPER = 1048576; // 0x100000
    field public static final int FLAG_SHOW_WHEN_LOCKED = 524288; // 0x80000
    field public static final deprecated int FLAG_SHOW_WHEN_LOCKED = 524288; // 0x80000
    field public static final int FLAG_SPLIT_TOUCH = 8388608; // 0x800000
    field public static final deprecated int FLAG_TOUCHABLE_WHEN_WAKING = 64; // 0x40
    field public static final int FLAG_TRANSLUCENT_NAVIGATION = 134217728; // 0x8000000
    field public static final int FLAG_TRANSLUCENT_STATUS = 67108864; // 0x4000000
    field public static final int FLAG_TURN_SCREEN_ON = 2097152; // 0x200000
    field public static final deprecated int FLAG_TURN_SCREEN_ON = 2097152; // 0x200000
    field public static final int FLAG_WATCH_OUTSIDE_TOUCH = 262144; // 0x40000
    field public static final int FORMAT_CHANGED = 8; // 0x8
    field public static final int LAST_APPLICATION_WINDOW = 99; // 0x63
+6 −2
Original line number Diff line number Diff line
@@ -1307,6 +1307,7 @@ package android {
    field public static final int showSilent = 16843259; // 0x10101fb
    field public static final int showText = 16843949; // 0x10104ad
    field public static final deprecated int showWeekNumber = 16843582; // 0x101033e
    field public static final int showWhenLocked = 16844137; // 0x1010569
    field public static final deprecated int shownWeekCount = 16843585; // 0x1010341
    field public static final int shrinkColumns = 16843082; // 0x101014a
    field public static final deprecated int singleLine = 16843101; // 0x101015d
@@ -1565,6 +1566,7 @@ package android {
    field public static final int trimPathOffset = 16843786; // 0x101040a
    field public static final int trimPathStart = 16843784; // 0x1010408
    field public static final int tunerCount = 16844061; // 0x101051d
    field public static final int turnScreenOn = 16844138; // 0x101056a
    field public static final int type = 16843169; // 0x10101a1
    field public static final int typeface = 16842902; // 0x1010096
    field public static final int uiOptions = 16843672; // 0x1010398
@@ -3900,10 +3902,12 @@ package android.app {
    method public final void setResult(int);
    method public final void setResult(int, android.content.Intent);
    method public final deprecated void setSecondaryProgress(int);
    method public void setShowWhenLocked(boolean);
    method public void setTaskDescription(android.app.ActivityManager.TaskDescription);
    method public void setTitle(java.lang.CharSequence);
    method public void setTitle(int);
    method public deprecated void setTitleColor(int);
    method public void setTurnScreenOn(boolean);
    method public void setVisible(boolean);
    method public final void setVolumeControlStream(int);
    method public void setVrModeEnabled(boolean, android.content.ComponentName) throws android.content.pm.PackageManager.NameNotFoundException;
@@ -50522,12 +50526,12 @@ package android.view {
    field public static final int FLAG_SCALED = 16384; // 0x4000
    field public static final int FLAG_SECURE = 8192; // 0x2000
    field public static final int FLAG_SHOW_WALLPAPER = 1048576; // 0x100000
    field public static final int FLAG_SHOW_WHEN_LOCKED = 524288; // 0x80000
    field public static final deprecated int FLAG_SHOW_WHEN_LOCKED = 524288; // 0x80000
    field public static final int FLAG_SPLIT_TOUCH = 8388608; // 0x800000
    field public static final deprecated int FLAG_TOUCHABLE_WHEN_WAKING = 64; // 0x40
    field public static final int FLAG_TRANSLUCENT_NAVIGATION = 134217728; // 0x8000000
    field public static final int FLAG_TRANSLUCENT_STATUS = 67108864; // 0x4000000
    field public static final int FLAG_TURN_SCREEN_ON = 2097152; // 0x200000
    field public static final deprecated int FLAG_TURN_SCREEN_ON = 2097152; // 0x200000
    field public static final int FLAG_WATCH_OUTSIDE_TOUCH = 262144; // 0x40000
    field public static final int FORMAT_CHANGED = 8; // 0x8
    field public static final int LAST_APPLICATION_WINDOW = 99; // 0x63
+6 −2
Original line number Diff line number Diff line
@@ -1180,6 +1180,7 @@ package android {
    field public static final int showSilent = 16843259; // 0x10101fb
    field public static final int showText = 16843949; // 0x10104ad
    field public static final deprecated int showWeekNumber = 16843582; // 0x101033e
    field public static final int showWhenLocked = 16844137; // 0x1010569
    field public static final deprecated int shownWeekCount = 16843585; // 0x1010341
    field public static final int shrinkColumns = 16843082; // 0x101014a
    field public static final deprecated int singleLine = 16843101; // 0x101015d
@@ -1438,6 +1439,7 @@ package android {
    field public static final int trimPathOffset = 16843786; // 0x101040a
    field public static final int trimPathStart = 16843784; // 0x1010408
    field public static final int tunerCount = 16844061; // 0x101051d
    field public static final int turnScreenOn = 16844138; // 0x101056a
    field public static final int type = 16843169; // 0x10101a1
    field public static final int typeface = 16842902; // 0x1010096
    field public static final int uiOptions = 16843672; // 0x1010398
@@ -3766,10 +3768,12 @@ package android.app {
    method public final void setResult(int);
    method public final void setResult(int, android.content.Intent);
    method public final deprecated void setSecondaryProgress(int);
    method public void setShowWhenLocked(boolean);
    method public void setTaskDescription(android.app.ActivityManager.TaskDescription);
    method public void setTitle(java.lang.CharSequence);
    method public void setTitle(int);
    method public deprecated void setTitleColor(int);
    method public void setTurnScreenOn(boolean);
    method public void setVisible(boolean);
    method public final void setVolumeControlStream(int);
    method public void setVrModeEnabled(boolean, android.content.ComponentName) throws android.content.pm.PackageManager.NameNotFoundException;
@@ -47385,12 +47389,12 @@ package android.view {
    field public static final int FLAG_SCALED = 16384; // 0x4000
    field public static final int FLAG_SECURE = 8192; // 0x2000
    field public static final int FLAG_SHOW_WALLPAPER = 1048576; // 0x100000
    field public static final int FLAG_SHOW_WHEN_LOCKED = 524288; // 0x80000
    field public static final deprecated int FLAG_SHOW_WHEN_LOCKED = 524288; // 0x80000
    field public static final int FLAG_SPLIT_TOUCH = 8388608; // 0x800000
    field public static final deprecated int FLAG_TOUCHABLE_WHEN_WAKING = 64; // 0x40
    field public static final int FLAG_TRANSLUCENT_NAVIGATION = 134217728; // 0x8000000
    field public static final int FLAG_TRANSLUCENT_STATUS = 67108864; // 0x4000000
    field public static final int FLAG_TURN_SCREEN_ON = 2097152; // 0x200000
    field public static final deprecated int FLAG_TURN_SCREEN_ON = 2097152; // 0x200000
    field public static final int FLAG_WATCH_OUTSIDE_TOUCH = 262144; // 0x40000
    field public static final int FORMAT_CHANGED = 8; // 0x8
    field public static final int LAST_APPLICATION_WINDOW = 99; // 0x63
+47 −0
Original line number Diff line number Diff line
@@ -7548,6 +7548,53 @@ public class Activity extends ContextThemeWrapper
        }
    }

    /**
     * Specifies whether an {@link Activity} should be shown on top of the the lock screen whenever
     * the lockscreen is up and the activity is resumed. Normally an activity will be transitioned
     * to the stopped state if it is started while the lockscreen is up, but with this flag set the
     * activity will remain in the resumed state visible on-top of the lock screen. This value can
     * be set as a manifest attribute using {@link android.R.attr#showWhenLocked}.
     *
     * @param showWhenLocked {@code true} to show the {@link Activity} on top of the lock screen;
     *                                   {@code false} otherwise.
     * @see #setTurnScreenOn(boolean)
     * @see android.R.attr#turnScreenOn
     * @see android.R.attr#showWhenLocked
     */
    public void setShowWhenLocked(boolean showWhenLocked) {
        try {
            ActivityManager.getService().setShowWhenLocked(mToken, showWhenLocked);
        } catch (RemoteException e) {
            Log.e(TAG, "Failed to call setShowWhenLocked", e);
        }
    }

    /**
     * Specifies whether the screen should be turned on when the {@link Activity} is resumed.
     * Normally an activity will be transitioned to the stopped state if it is started while the
     * screen if off, but with this flag set the activity will cause the screen to turn on if the
     * activity will be visible and resumed due to the screen coming on. The screen will not be
     * turned on if the activity won't be visible after the screen is turned on. This flag is
     * normally used in conjunction with the {@link android.R.attr#showWhenLocked} flag to make sure
     * the activity is visible after the screen is turned on when the lockscreen is up. In addition,
     * if this flag is set and the activity calls {@link
     * KeyguardManager#requestDismissKeyguard(Activity, KeyguardManager.KeyguardDismissCallback)}
     * the screen will turn on.
     *
     * @param turnScreenOn {@code true} to turn on the screen; {@code false} otherwise.
     *
     * @see #setShowWhenLocked(boolean)
     * @see android.R.attr#turnScreenOn
     * @see android.R.attr#showWhenLocked
     */
    public void setTurnScreenOn(boolean turnScreenOn) {
        try {
            ActivityManager.getService().setTurnScreenOn(mToken, turnScreenOn);
        } catch (RemoteException e) {
            Log.e(TAG, "Failed to call setTurnScreenOn", e);
        }
    }

    class HostCallbacks extends FragmentHostCallback<Activity> {
        public HostCallbacks() {
            super(Activity.this /*activity*/);
+3 −0
Original line number Diff line number Diff line
@@ -633,4 +633,7 @@ interface IActivityManager {
    // side. If so, make sure they are using the correct transaction ids and arguments.
    // If a transaction which will also be used on the native side is being inserted, add it
    // alongside with other transactions of this kind at the top of this file.

     void setShowWhenLocked(in IBinder token, boolean showWhenLocked);
     void setTurnScreenOn(in IBinder token, boolean turnScreenOn);
}
Loading