OSDN Git Service

Merge "Don't remove starting window for visible app." into oc-dr1-dev am: d4b83f96f8
[android-x86/frameworks-base.git] / services / core / java / com / android / server / am / ActivityRecord.java
index 6a8f6d3..4a57369 100644 (file)
@@ -47,11 +47,13 @@ import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE;
 import static android.content.pm.ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE;
 import static android.content.pm.ActivityInfo.CONFIG_UI_MODE;
 import static android.content.pm.ActivityInfo.FLAG_ALWAYS_FOCUSABLE;
+import static android.content.pm.ActivityInfo.FLAG_SHOW_WHEN_LOCKED;
 import static android.content.pm.ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
 import static android.content.pm.ActivityInfo.FLAG_IMMERSIVE;
 import static android.content.pm.ActivityInfo.FLAG_MULTIPROCESS;
 import static android.content.pm.ActivityInfo.FLAG_SHOW_FOR_ALL_USERS;
 import static android.content.pm.ActivityInfo.FLAG_STATE_NOT_NEEDED;
+import static android.content.pm.ActivityInfo.FLAG_TURN_SCREEN_ON;
 import static android.content.pm.ActivityInfo.LAUNCH_MULTIPLE;
 import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_INSTANCE;
 import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_TASK;
@@ -91,7 +93,6 @@ import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_THUMBNAIL
 import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_VISIBILITY;
 import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
 import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
-import static com.android.server.am.ActivityManagerService.IS_USER_BUILD;
 import static com.android.server.am.ActivityManagerService.TAKE_FULLSCREEN_SCREENSHOTS;
 import static com.android.server.am.ActivityStack.ActivityState.DESTROYED;
 import static com.android.server.am.ActivityStack.ActivityState.DESTROYING;
@@ -345,6 +346,9 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo
     // handle calculating override configuration from the bounds.
     private final Rect mBounds = new Rect();
 
+    private boolean mShowWhenLocked;
+    private boolean mTurnScreenOn;
+
     /**
      * Temp configs used in {@link #ensureActivityConfigurationLocked(int, boolean)}
      */
@@ -905,6 +909,9 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo
 
         requestedVrComponent = (aInfo.requestedVrComponent == null) ?
                 null : ComponentName.unflattenFromString(aInfo.requestedVrComponent);
+
+        mShowWhenLocked = (aInfo.flags & FLAG_SHOW_WHEN_LOCKED) != 0;
+        mTurnScreenOn = (aInfo.flags & FLAG_TURN_SCREEN_ON) != 0;
     }
 
     AppWindowContainerController getWindowContainerController() {
@@ -1259,13 +1266,6 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo
         return (info.flags & FLAG_ALWAYS_FOCUSABLE) != 0;
     }
 
-    /**
-     * @return true if the activity contains windows that have
-     *         {@link LayoutParams#FLAG_SHOW_WHEN_LOCKED} set
-     */
-    boolean hasShowWhenLockedWindows() {
-        return service.mWindowManager.containsShowWhenLockedWindow(appToken);
-    }
 
     /**
      * @return true if the activity contains windows that have
@@ -1276,20 +1276,16 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo
     }
 
     void makeFinishingLocked() {
-        if (!finishing) {
-            final ActivityStack stack = getStack();
-            if (stack != null && this == stack.getVisibleBehindActivity()) {
-                // A finishing activity should not remain as visible in the background
-                mStackSupervisor.requestVisibleBehindLocked(this, false);
-            }
-            finishing = true;
-            if (stopped) {
-                clearOptionsLocked();
-            }
+        if (finishing) {
+            return;
+        }
+        finishing = true;
+        if (stopped) {
+            clearOptionsLocked();
+        }
 
-            if (service != null) {
-                service.mTaskChangeNotificationController.notifyTaskStackChanged();
-            }
+        if (service != null) {
+            service.mTaskChangeNotificationController.notifyTaskStackChanged();
         }
     }
 
@@ -1346,11 +1342,7 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo
                 intent, getUriPermissionsLocked(), userId);
         final ReferrerIntent rintent = new ReferrerIntent(intent, referrer);
         boolean unsent = true;
-        final ActivityStack stack = getStack();
-        final boolean isTopActivityInStack =
-                stack != null && stack.topRunningActivityLocked() == this;
-        final boolean isTopActivityWhileSleeping =
-                service.isSleepingLocked() && isTopActivityInStack;
+        final boolean isTopActivityWhileSleeping = service.isSleepingLocked() && isTopRunningActivity();
 
         // We want to immediately deliver the intent to the activity if:
         // - It is currently resumed or paused. i.e. it is currently visible to the user and we want
@@ -1622,20 +1614,12 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo
      *
      * @see {@link ActivityStack#checkKeyguardVisibility}
      */
-    boolean shouldBeVisibleIgnoringKeyguard(boolean behindTranslucentActivity,
-            boolean stackVisibleBehind, ActivityRecord visibleBehind,
-            boolean behindFullscreenActivity) {
+    boolean shouldBeVisibleIgnoringKeyguard(boolean behindFullscreenActivity) {
         if (!okToShowLocked()) {
             return false;
         }
 
-        // mLaunchingBehind: Activities launching behind are at the back of the task stack
-        // but must be drawn initially for the animation as though they were visible.
-        final boolean activityVisibleBehind =
-                (behindTranslucentActivity || stackVisibleBehind) && visibleBehind == this;
-
-        boolean isVisible =
-                !behindFullscreenActivity || mLaunchTaskBehind || activityVisibleBehind;
+        boolean isVisible = !behindFullscreenActivity || mLaunchTaskBehind;
 
         if (service.mSupportsLeanbackOnly && isVisible && isRecentsActivity()) {
             // On devices that support leanback only (Android TV), Recents activity can only be
@@ -1747,11 +1731,14 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo
 
         returningOptions = null;
 
-        if (stack.getVisibleBehindActivity() == this) {
-            // When resuming an activity, require it to call requestVisibleBehind() again.
-            stack.setVisibleBehindActivity(null /* ActivityRecord */);
+        if (canTurnScreenOn()) {
+            mStackSupervisor.wakeUp("turnScreenOnFlag");
+        } else {
+            // If the screen is going to turn on because the caller explicitly requested it and
+            // the keyguard is not showing don't attempt to sleep. Otherwise the Activity will
+            // pause and then resume again later, which will result in a double life-cycle event.
+            mStackSupervisor.checkReadyForSleepLocked();
         }
-        mStackSupervisor.checkReadyForSleepLocked();
     }
 
     final void activityStoppedLocked(Bundle newIcicle, PersistableBundle newPersistentState,
@@ -1784,9 +1771,6 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo
 
             mWindowContainerController.notifyAppStopped();
 
-            if (stack.getVisibleBehindActivity() == this) {
-                mStackSupervisor.requestVisibleBehindLocked(this, false /* visible */);
-            }
             if (finishing) {
                 clearOptionsLocked();
             } else {
@@ -1801,7 +1785,7 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo
     }
 
     void startLaunchTickingLocked() {
-        if (IS_USER_BUILD) {
+        if (Build.IS_USER) {
             return;
         }
         if (launchTickTime == 0) {
@@ -2818,6 +2802,44 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo
         return info.applicationInfo.uid;
     }
 
+    void setShowWhenLocked(boolean showWhenLocked) {
+        mShowWhenLocked = showWhenLocked;
+    }
+
+    /**
+     * @return true if the activity contains windows that have
+     *         {@link LayoutParams#FLAG_SHOW_WHEN_LOCKED} set or if the activity has set
+     *         {@link #mShowWhenLocked}.
+     */
+    boolean canShowWhenLocked() {
+        return mShowWhenLocked || service.mWindowManager.containsShowWhenLockedWindow(appToken);
+    }
+
+    void setTurnScreenOn(boolean turnScreenOn) {
+        mTurnScreenOn = turnScreenOn;
+    }
+
+    /**
+     * Determines whether this ActivityRecord can turn the screen on. It checks whether the flag
+     * {@link #mTurnScreenOn} is set and checks whether the ActivityRecord should be visible
+     * depending on Keyguard state
+     *
+     * @return true if the screen can be turned on, false otherwise.
+     */
+    boolean canTurnScreenOn() {
+        final ActivityStack stack = getStack();
+        return mTurnScreenOn && stack != null &&
+                stack.checkKeyguardVisibility(this, true /* shouldBeVisible */, true /* isTop */);
+    }
+
+    boolean getTurnScreenOnFlag() {
+        return mTurnScreenOn;
+    }
+
+    boolean isTopRunningActivity() {
+        return mStackSupervisor.topRunningActivityLocked() == this;
+    }
+
     @Override
     public String toString() {
         if (stringName != null) {