The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.am; |
| 18 | |
Jorim Jaggi | 0a93214 | 2016-02-01 17:42:25 -0800 | [diff] [blame] | 19 | import android.annotation.Nullable; |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 20 | import android.app.Activity; |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 21 | import android.app.ActivityManager; |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 22 | import android.app.ActivityManager.StackId; |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 23 | import android.app.ActivityManager.TaskDescription; |
Wale Ogunwale | ff3c66c | 2015-11-18 19:22:49 -0800 | [diff] [blame] | 24 | import android.app.ActivityManager.TaskThumbnail; |
Winson | c809cbb | 2015-11-02 12:06:15 -0800 | [diff] [blame] | 25 | import android.app.ActivityManager.TaskThumbnailInfo; |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 26 | import android.app.ActivityOptions; |
Dianne Hackborn | 885fbe5 | 2014-08-23 15:23:58 -0700 | [diff] [blame] | 27 | import android.app.AppGlobals; |
Jorim Jaggi | 0a93214 | 2016-02-01 17:42:25 -0800 | [diff] [blame] | 28 | import android.app.IActivityManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | import android.content.ComponentName; |
| 30 | import android.content.Intent; |
| 31 | import android.content.pm.ActivityInfo; |
Dianne Hackborn | 885fbe5 | 2014-08-23 15:23:58 -0700 | [diff] [blame] | 32 | import android.content.pm.ApplicationInfo; |
| 33 | import android.content.pm.IPackageManager; |
| 34 | import android.content.pm.PackageManager; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 35 | import android.content.res.Configuration; |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 36 | import android.graphics.Bitmap; |
Winson | c809cbb | 2015-11-02 12:06:15 -0800 | [diff] [blame] | 37 | import android.graphics.Point; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 38 | import android.graphics.Rect; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 39 | import android.os.Debug; |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 40 | import android.os.ParcelFileDescriptor; |
Dianne Hackborn | 885fbe5 | 2014-08-23 15:23:58 -0700 | [diff] [blame] | 41 | import android.os.RemoteException; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 42 | import android.os.UserHandle; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 43 | import android.service.voice.IVoiceInteractionSession; |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 44 | import android.util.DisplayMetrics; |
Dianne Hackborn | 7f96b79 | 2012-05-29 18:46:45 -0700 | [diff] [blame] | 45 | import android.util.Slog; |
Suprabh Shukla | 2359314 | 2015-11-03 17:31:15 -0800 | [diff] [blame] | 46 | |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 47 | import com.android.internal.app.IVoiceInteractor; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 48 | import com.android.internal.util.XmlUtils; |
Suprabh Shukla | 2359314 | 2015-11-03 17:31:15 -0800 | [diff] [blame] | 49 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 50 | import org.xmlpull.v1.XmlPullParser; |
| 51 | import org.xmlpull.v1.XmlPullParserException; |
| 52 | import org.xmlpull.v1.XmlSerializer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 54 | import java.io.File; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 55 | import java.io.IOException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | import java.io.PrintWriter; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 57 | import java.util.ArrayList; |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 58 | import java.util.Objects; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | |
Jorim Jaggi | 0a93214 | 2016-02-01 17:42:25 -0800 | [diff] [blame] | 60 | import static android.app.ActivityManager.StackId.DOCKED_STACK_ID; |
| 61 | import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID; |
| 62 | import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID; |
| 63 | import static android.app.ActivityManager.StackId.HOME_STACK_ID; |
| 64 | import static android.app.ActivityManager.StackId.INVALID_STACK_ID; |
| 65 | import static android.app.ActivityManager.StackId.PINNED_STACK_ID; |
| 66 | import static android.content.Intent.FLAG_ACTIVITY_NEW_DOCUMENT; |
| 67 | import static android.content.Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS; |
| 68 | import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_ALWAYS; |
| 69 | import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_DEFAULT; |
| 70 | import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED; |
| 71 | import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_NEVER; |
| 72 | import static android.content.pm.ActivityInfo.RESIZE_MODE_CROP_WINDOWS; |
Wale Ogunwale | d829d36 | 2016-02-10 19:24:49 -0800 | [diff] [blame] | 73 | import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZEABLE; |
Jorim Jaggi | 0a93214 | 2016-02-01 17:42:25 -0800 | [diff] [blame] | 74 | import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE; |
| 75 | import static android.content.pm.ActivityInfo.RESIZE_MODE_UNRESIZEABLE; |
| 76 | import static android.content.pm.ApplicationInfo.PRIVATE_FLAG_PRIVILEGED; |
| 77 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ADD_REMOVE; |
| 78 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_LOCKTASK; |
| 79 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_RECENTS; |
| 80 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_TASKS; |
| 81 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_ADD_REMOVE; |
| 82 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_LOCKTASK; |
| 83 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_RECENTS; |
| 84 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_TASKS; |
| 85 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM; |
| 86 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 87 | import static com.android.server.am.ActivityManagerService.LOCK_SCREEN_SHOWN; |
| 88 | import static com.android.server.am.ActivityRecord.APPLICATION_ACTIVITY_TYPE; |
| 89 | import static com.android.server.am.ActivityRecord.HOME_ACTIVITY_TYPE; |
| 90 | import static com.android.server.am.ActivityRecord.RECENTS_ACTIVITY_TYPE; |
| 91 | |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 92 | final class TaskRecord { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 93 | private static final String TAG = TAG_WITH_CLASS_NAME ? "TaskRecord" : TAG_AM; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 94 | private static final String TAG_ADD_REMOVE = TAG + POSTFIX_ADD_REMOVE; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 95 | private static final String TAG_RECENTS = TAG + POSTFIX_RECENTS; |
Craig Mautner | e057020 | 2015-05-13 13:06:11 -0700 | [diff] [blame] | 96 | private static final String TAG_LOCKTASK = TAG + POSTFIX_LOCKTASK; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 97 | private static final String TAG_TASKS = TAG + POSTFIX_TASKS; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 98 | |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 99 | static final String ATTR_TASKID = "task_id"; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 100 | private static final String TAG_INTENT = "intent"; |
| 101 | private static final String TAG_AFFINITYINTENT = "affinity_intent"; |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 102 | static final String ATTR_REALACTIVITY = "real_activity"; |
Andrei Stingaceanu | 4ccec53 | 2016-01-13 12:10:21 +0000 | [diff] [blame] | 103 | static final String ATTR_REALACTIVITY_SUSPENDED = "real_activity_suspended"; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 104 | private static final String ATTR_ORIGACTIVITY = "orig_activity"; |
Stefan Kuhne | e88d1e5 | 2015-05-18 10:33:45 -0700 | [diff] [blame] | 105 | private static final String TAG_ACTIVITY = "activity"; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 106 | private static final String ATTR_AFFINITY = "affinity"; |
Dianne Hackborn | 7922882 | 2014-09-16 11:11:23 -0700 | [diff] [blame] | 107 | private static final String ATTR_ROOT_AFFINITY = "root_affinity"; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 108 | private static final String ATTR_ROOTHASRESET = "root_has_reset"; |
Dianne Hackborn | 13420f2 | 2014-07-18 15:43:56 -0700 | [diff] [blame] | 109 | private static final String ATTR_AUTOREMOVERECENTS = "auto_remove_recents"; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 110 | private static final String ATTR_ASKEDCOMPATMODE = "asked_compat_mode"; |
| 111 | private static final String ATTR_USERID = "user_id"; |
Wale Ogunwale | f80170f | 2016-02-04 15:12:29 -0800 | [diff] [blame] | 112 | private static final String ATTR_USER_SETUP_COMPLETE = "user_setup_complete"; |
Dianne Hackborn | 885fbe5 | 2014-08-23 15:23:58 -0700 | [diff] [blame] | 113 | private static final String ATTR_EFFECTIVE_UID = "effective_uid"; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 114 | private static final String ATTR_TASKTYPE = "task_type"; |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 115 | private static final String ATTR_FIRSTACTIVETIME = "first_active_time"; |
Winson Chung | f1fbd77 | 2014-06-24 18:06:58 -0700 | [diff] [blame] | 116 | private static final String ATTR_LASTACTIVETIME = "last_active_time"; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 117 | private static final String ATTR_LASTDESCRIPTION = "last_description"; |
| 118 | private static final String ATTR_LASTTIMEMOVED = "last_time_moved"; |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 119 | private static final String ATTR_NEVERRELINQUISH = "never_relinquish_identity"; |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 120 | static final String ATTR_TASK_AFFILIATION = "task_affiliation"; |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 121 | private static final String ATTR_PREV_AFFILIATION = "prev_affiliation"; |
| 122 | private static final String ATTR_NEXT_AFFILIATION = "next_affiliation"; |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame] | 123 | private static final String ATTR_TASK_AFFILIATION_COLOR = "task_affiliation_color"; |
Craig Mautner | dc00cbe | 2014-07-20 17:48:47 -0700 | [diff] [blame] | 124 | private static final String ATTR_CALLING_UID = "calling_uid"; |
| 125 | private static final String ATTR_CALLING_PACKAGE = "calling_package"; |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 126 | private static final String ATTR_RESIZE_MODE = "resize_mode"; |
Wale Ogunwale | a7afaa2 | 2015-05-01 20:39:18 -0700 | [diff] [blame] | 127 | private static final String ATTR_PRIVILEGED = "privileged"; |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 128 | private static final String ATTR_NON_FULLSCREEN_BOUNDS = "non_fullscreen_bounds"; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 129 | |
| 130 | private static final String TASK_THUMBNAIL_SUFFIX = "_task_thumbnail"; |
| 131 | |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 132 | static final int INVALID_TASK_ID = -1; |
| 133 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 134 | final int taskId; // Unique identifier for this task. |
Dianne Hackborn | 7922882 | 2014-09-16 11:11:23 -0700 | [diff] [blame] | 135 | String affinity; // The affinity name for this task, or null; may change identity. |
| 136 | String rootAffinity; // Initial base affinity, or null; does not change from initial root. |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 137 | final IVoiceInteractionSession voiceSession; // Voice interaction session driving task |
| 138 | final IVoiceInteractor voiceInteractor; // Associated interactor to provide to app |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 139 | Intent intent; // The original intent that started the task. |
| 140 | Intent affinityIntent; // Intent of affinity-moved activity that started this task. |
Dianne Hackborn | 885fbe5 | 2014-08-23 15:23:58 -0700 | [diff] [blame] | 141 | int effectiveUid; // The current effective uid of the identity of this task. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | ComponentName origActivity; // The non-alias activity component of the intent. |
| 143 | ComponentName realActivity; // The actual activity component that started the task. |
Andrei Stingaceanu | 4ccec53 | 2016-01-13 12:10:21 +0000 | [diff] [blame] | 144 | boolean realActivitySuspended; // True if the actual activity component that started the |
| 145 | // task is suspended. |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 146 | long firstActiveTime; // First time this task was active. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 147 | long lastActiveTime; // Last time this task was active, including sleep. |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 148 | boolean inRecents; // Actually in the recents list? |
| 149 | boolean isAvailable; // Is the activity available to be launched? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 150 | boolean rootWasReset; // True if the intent at the root of the task had |
| 151 | // the FLAG_ACTIVITY_RESET_TASK_IF_NEEDED flag. |
Dianne Hackborn | 13420f2 | 2014-07-18 15:43:56 -0700 | [diff] [blame] | 152 | boolean autoRemoveRecents; // If true, we should automatically remove the task from |
| 153 | // recents when activity finishes |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 154 | boolean askedCompatMode;// Have asked the user about compat mode for this task. |
Dianne Hackborn | d38aed8 | 2014-06-10 21:36:35 -0700 | [diff] [blame] | 155 | boolean hasBeenVisible; // Set if any activities in the task have been visible to the user. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 156 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 157 | String stringName; // caching of toString() result. |
Dianne Hackborn | 9da2d40 | 2012-03-15 13:43:08 -0700 | [diff] [blame] | 158 | int userId; // user for which this task was created |
Wale Ogunwale | f80170f | 2016-02-04 15:12:29 -0800 | [diff] [blame] | 159 | boolean mUserSetupComplete; // The user set-up is complete as of the last time the task activity |
| 160 | // was changed. |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 161 | |
| 162 | int numFullscreen; // Number of fullscreen activities. |
| 163 | |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 164 | int mResizeMode; // The resize mode of this task and its activities. |
| 165 | // Based on the {@link ActivityInfo#resizeMode} of the root activity. |
Jorim Jaggi | 8202b2a | 2016-02-03 19:24:31 -0800 | [diff] [blame] | 166 | boolean mTemporarilyUnresizable; // Separate flag from mResizeMode used to suppress resize |
| 167 | // changes on a temporary basis. |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 168 | int mLockTaskMode; // Which tasklock mode to launch this task in. One of |
| 169 | // ActivityManager.LOCK_TASK_LAUNCH_MODE_* |
Wale Ogunwale | a7afaa2 | 2015-05-01 20:39:18 -0700 | [diff] [blame] | 170 | private boolean mPrivileged; // The root activity application of this task holds |
| 171 | // privileged permissions. |
| 172 | |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 173 | /** Can't be put in lockTask mode. */ |
| 174 | final static int LOCK_TASK_AUTH_DONT_LOCK = 0; |
Benjamin Franz | 469dd58 | 2015-06-09 14:24:36 +0100 | [diff] [blame] | 175 | /** Can enter app pinning with user approval. Can never start over existing lockTask task. */ |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 176 | final static int LOCK_TASK_AUTH_PINNABLE = 1; |
| 177 | /** Starts in LOCK_TASK_MODE_LOCKED automatically. Can start over existing lockTask task. */ |
| 178 | final static int LOCK_TASK_AUTH_LAUNCHABLE = 2; |
Benjamin Franz | 469dd58 | 2015-06-09 14:24:36 +0100 | [diff] [blame] | 179 | /** Can enter lockTask without user approval. Can start over existing lockTask task. */ |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 180 | final static int LOCK_TASK_AUTH_WHITELISTED = 3; |
Benjamin Franz | 469dd58 | 2015-06-09 14:24:36 +0100 | [diff] [blame] | 181 | /** Priv-app that starts in LOCK_TASK_MODE_LOCKED automatically. Can start over existing |
| 182 | * lockTask task. */ |
| 183 | final static int LOCK_TASK_AUTH_LAUNCHABLE_PRIV = 4; |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 184 | int mLockTaskAuth = LOCK_TASK_AUTH_PINNABLE; |
| 185 | |
| 186 | int mLockTaskUid = -1; // The uid of the application that called startLockTask(). |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 187 | |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 188 | // This represents the last resolved activity values for this task |
| 189 | // NOTE: This value needs to be persisted with each task |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 190 | TaskDescription lastTaskDescription = new TaskDescription(); |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 191 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 192 | /** List of all activities in the task arranged in history order */ |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 193 | final ArrayList<ActivityRecord> mActivities; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 194 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 195 | /** Current stack */ |
| 196 | ActivityStack stack; |
| 197 | |
Craig Mautner | 2c1faed | 2013-07-23 12:56:02 -0700 | [diff] [blame] | 198 | /** Takes on same set of values as ActivityRecord.mActivityType */ |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 199 | int taskType; |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 200 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 201 | /** Takes on same value as first root activity */ |
| 202 | boolean isPersistable = false; |
Craig Mautner | ffcfcaa | 2014-06-05 09:54:38 -0700 | [diff] [blame] | 203 | int maxRecents; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 204 | |
| 205 | /** Only used for persistable tasks, otherwise 0. The last time this task was moved. Used for |
| 206 | * determining the order when restoring. Sign indicates whether last task movement was to front |
| 207 | * (positive) or back (negative). Absolute value indicates time. */ |
| 208 | long mLastTimeMoved = System.currentTimeMillis(); |
| 209 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 210 | /** Indication of what to run next when task exits. Use ActivityRecord types. |
| 211 | * ActivityRecord.APPLICATION_ACTIVITY_TYPE indicates to resume the task below this one in the |
| 212 | * task stack. */ |
| 213 | private int mTaskToReturnTo = APPLICATION_ACTIVITY_TYPE; |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 214 | |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 215 | /** If original intent did not allow relinquishing task identity, save that information */ |
| 216 | boolean mNeverRelinquishIdentity = true; |
| 217 | |
Craig Mautner | 362449a | 2014-06-20 14:04:39 -0700 | [diff] [blame] | 218 | // Used in the unique case where we are clearing the task in order to reuse it. In that case we |
| 219 | // do not want to delete the stack when the task goes empty. |
Filip Gruszczynski | be9dabd | 2016-01-19 12:23:10 -0800 | [diff] [blame] | 220 | private boolean mReuseTask = false; |
Craig Mautner | 362449a | 2014-06-20 14:04:39 -0700 | [diff] [blame] | 221 | |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 222 | private Bitmap mLastThumbnail; // Last thumbnail captured for this item. |
Wale Ogunwale | be23ff4 | 2014-10-21 16:29:51 -0700 | [diff] [blame] | 223 | private final File mLastThumbnailFile; // File containing last thumbnail. |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 224 | private final String mFilename; |
Winson | c809cbb | 2015-11-02 12:06:15 -0800 | [diff] [blame] | 225 | private TaskThumbnailInfo mLastThumbnailInfo; |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 226 | CharSequence lastDescription; // Last description captured for this item. |
| 227 | |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 228 | int mAffiliatedTaskId; // taskId of parent affiliation or self if no parent. |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame] | 229 | int mAffiliatedTaskColor; // color of the parent task affiliation. |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 230 | TaskRecord mPrevAffiliate; // previous task in affiliated chain. |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 231 | int mPrevAffiliateTaskId = INVALID_TASK_ID; // previous id for persistence. |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 232 | TaskRecord mNextAffiliate; // next task in affiliated chain. |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 233 | int mNextAffiliateTaskId = INVALID_TASK_ID; // next id for persistence. |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 234 | |
Craig Mautner | dc00cbe | 2014-07-20 17:48:47 -0700 | [diff] [blame] | 235 | // For relaunching the task from recents as though it was launched by the original launcher. |
| 236 | int mCallingUid; |
| 237 | String mCallingPackage; |
| 238 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 239 | final ActivityManagerService mService; |
| 240 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 241 | // Whether or not this task covers the entire screen; by default tasks are fullscreen. |
| 242 | boolean mFullscreen = true; |
| 243 | |
| 244 | // Bounds of the Task. null for fullscreen tasks. |
| 245 | Rect mBounds = null; |
Jorim Jaggi | 82c9dc9 | 2016-02-05 15:10:33 -0800 | [diff] [blame] | 246 | private final Rect mTmpStableBounds = new Rect(); |
| 247 | private final Rect mTmpNonDecorBounds = new Rect(); |
Wale Ogunwale | 9a08f82 | 2016-02-17 19:03:58 -0800 | [diff] [blame^] | 248 | private final Rect mTmpRect = new Rect(); |
Jorim Jaggi | 0a93214 | 2016-02-01 17:42:25 -0800 | [diff] [blame] | 249 | private final Rect mTmpRect2 = new Rect(); |
| 250 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 251 | // Last non-fullscreen bounds the task was launched in or resized to. |
| 252 | // The information is persisted and used to determine the appropriate stack to launch the |
| 253 | // task into on restore. |
| 254 | Rect mLastNonFullscreenBounds = null; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 255 | // Minimal size for width/height of this task when it's resizeable. -1 means it should use the |
| 256 | // default minimal size. |
| 257 | final int mMinimalSize; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 258 | |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 259 | // Ranking (from top) of this task among all visible tasks. (-1 means it's not visible) |
| 260 | // This number will be assigned when we evaluate OOM scores for all visible tasks. |
| 261 | int mLayerRank = -1; |
| 262 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 263 | Configuration mOverrideConfig = Configuration.EMPTY; |
| 264 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 265 | TaskRecord(ActivityManagerService service, int _taskId, ActivityInfo info, Intent _intent, |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 266 | IVoiceInteractionSession _voiceSession, IVoiceInteractor _voiceInteractor) { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 267 | mService = service; |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 268 | mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX + |
| 269 | TaskPersister.IMAGE_EXTENSION; |
Suprabh Shukla | 2359314 | 2015-11-03 17:31:15 -0800 | [diff] [blame] | 270 | userId = UserHandle.getUserId(info.applicationInfo.uid); |
| 271 | mLastThumbnailFile = new File(TaskPersister.getUserImagesDir(userId), mFilename); |
Winson | c809cbb | 2015-11-02 12:06:15 -0800 | [diff] [blame] | 272 | mLastThumbnailInfo = new TaskThumbnailInfo(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 273 | taskId = _taskId; |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 274 | mAffiliatedTaskId = _taskId; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 275 | voiceSession = _voiceSession; |
| 276 | voiceInteractor = _voiceInteractor; |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 277 | isAvailable = true; |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 278 | mActivities = new ArrayList<>(); |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 279 | mCallingUid = info.applicationInfo.uid; |
| 280 | mCallingPackage = info.packageName; |
Martijn Coenen | d4a6970 | 2014-06-30 11:12:17 -0700 | [diff] [blame] | 281 | setIntent(_intent, info); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 282 | mMinimalSize = info != null && info.layout != null ? info.layout.minimalSize : -1; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 283 | } |
| 284 | |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 285 | TaskRecord(ActivityManagerService service, int _taskId, ActivityInfo info, Intent _intent, |
Winson | c809cbb | 2015-11-02 12:06:15 -0800 | [diff] [blame] | 286 | TaskDescription _taskDescription, TaskThumbnailInfo thumbnailInfo) { |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 287 | mService = service; |
| 288 | mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX + |
| 289 | TaskPersister.IMAGE_EXTENSION; |
Suprabh Shukla | 2359314 | 2015-11-03 17:31:15 -0800 | [diff] [blame] | 290 | userId = UserHandle.getUserId(info.applicationInfo.uid); |
| 291 | mLastThumbnailFile = new File(TaskPersister.getUserImagesDir(userId), mFilename); |
Winson | c809cbb | 2015-11-02 12:06:15 -0800 | [diff] [blame] | 292 | mLastThumbnailInfo = thumbnailInfo; |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 293 | taskId = _taskId; |
| 294 | mAffiliatedTaskId = _taskId; |
| 295 | voiceSession = null; |
| 296 | voiceInteractor = null; |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 297 | isAvailable = true; |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 298 | mActivities = new ArrayList<>(); |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 299 | mCallingUid = info.applicationInfo.uid; |
| 300 | mCallingPackage = info.packageName; |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 301 | setIntent(_intent, info); |
| 302 | |
| 303 | taskType = ActivityRecord.APPLICATION_ACTIVITY_TYPE; |
| 304 | isPersistable = true; |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 305 | // Clamp to [1, max]. |
| 306 | maxRecents = Math.min(Math.max(info.maxRecents, 1), |
| 307 | ActivityManager.getMaxAppRecentsLimitStatic()); |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 308 | |
| 309 | taskType = APPLICATION_ACTIVITY_TYPE; |
| 310 | mTaskToReturnTo = HOME_ACTIVITY_TYPE; |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 311 | lastTaskDescription = _taskDescription; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 312 | mMinimalSize = info != null && info.layout != null ? info.layout.minimalSize : -1; |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 313 | } |
| 314 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 315 | private TaskRecord(ActivityManagerService service, int _taskId, Intent _intent, |
| 316 | Intent _affinityIntent, String _affinity, String _rootAffinity, |
| 317 | ComponentName _realActivity, ComponentName _origActivity, boolean _rootWasReset, |
| 318 | boolean _autoRemoveRecents, boolean _askedCompatMode, int _taskType, int _userId, |
| 319 | int _effectiveUid, String _lastDescription, ArrayList<ActivityRecord> activities, |
| 320 | long _firstActiveTime, long _lastActiveTime, long lastTimeMoved, |
| 321 | boolean neverRelinquishIdentity, TaskDescription _lastTaskDescription, |
Winson | c809cbb | 2015-11-02 12:06:15 -0800 | [diff] [blame] | 322 | TaskThumbnailInfo lastThumbnailInfo, int taskAffiliation, int prevTaskId, |
| 323 | int nextTaskId, int taskAffiliationColor, int callingUid, String callingPackage, |
Wale Ogunwale | f80170f | 2016-02-04 15:12:29 -0800 | [diff] [blame] | 324 | int resizeMode, boolean privileged, boolean _realActivitySuspended, |
| 325 | boolean userSetupComplete) { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 326 | mService = service; |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 327 | mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX + |
| 328 | TaskPersister.IMAGE_EXTENSION; |
Suprabh Shukla | 2359314 | 2015-11-03 17:31:15 -0800 | [diff] [blame] | 329 | mLastThumbnailFile = new File(TaskPersister.getUserImagesDir(_userId), mFilename); |
Winson | c809cbb | 2015-11-02 12:06:15 -0800 | [diff] [blame] | 330 | mLastThumbnailInfo = lastThumbnailInfo; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 331 | taskId = _taskId; |
| 332 | intent = _intent; |
| 333 | affinityIntent = _affinityIntent; |
| 334 | affinity = _affinity; |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 335 | rootAffinity = _rootAffinity; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 336 | voiceSession = null; |
| 337 | voiceInteractor = null; |
| 338 | realActivity = _realActivity; |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 339 | realActivitySuspended = _realActivitySuspended; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 340 | origActivity = _origActivity; |
| 341 | rootWasReset = _rootWasReset; |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 342 | isAvailable = true; |
Dianne Hackborn | 13420f2 | 2014-07-18 15:43:56 -0700 | [diff] [blame] | 343 | autoRemoveRecents = _autoRemoveRecents; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 344 | askedCompatMode = _askedCompatMode; |
| 345 | taskType = _taskType; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 346 | mTaskToReturnTo = HOME_ACTIVITY_TYPE; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 347 | userId = _userId; |
Wale Ogunwale | f80170f | 2016-02-04 15:12:29 -0800 | [diff] [blame] | 348 | mUserSetupComplete = userSetupComplete; |
Dianne Hackborn | 885fbe5 | 2014-08-23 15:23:58 -0700 | [diff] [blame] | 349 | effectiveUid = _effectiveUid; |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 350 | firstActiveTime = _firstActiveTime; |
Winson Chung | f1fbd77 | 2014-06-24 18:06:58 -0700 | [diff] [blame] | 351 | lastActiveTime = _lastActiveTime; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 352 | lastDescription = _lastDescription; |
| 353 | mActivities = activities; |
| 354 | mLastTimeMoved = lastTimeMoved; |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 355 | mNeverRelinquishIdentity = neverRelinquishIdentity; |
Winson Chung | 2cb86c7 | 2014-06-25 12:03:30 -0700 | [diff] [blame] | 356 | lastTaskDescription = _lastTaskDescription; |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 357 | mAffiliatedTaskId = taskAffiliation; |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame] | 358 | mAffiliatedTaskColor = taskAffiliationColor; |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 359 | mPrevAffiliateTaskId = prevTaskId; |
| 360 | mNextAffiliateTaskId = nextTaskId; |
Craig Mautner | dc00cbe | 2014-07-20 17:48:47 -0700 | [diff] [blame] | 361 | mCallingUid = callingUid; |
| 362 | mCallingPackage = callingPackage; |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 363 | mResizeMode = resizeMode; |
Wale Ogunwale | a7afaa2 | 2015-05-01 20:39:18 -0700 | [diff] [blame] | 364 | mPrivileged = privileged; |
Suprabh Shukla | 74f9f16 | 2015-11-06 15:39:42 -0800 | [diff] [blame] | 365 | ActivityInfo info = (mActivities.size() > 0) ? mActivities.get(0).info : null; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 366 | mMinimalSize = info != null && info.layout != null ? info.layout.minimalSize : -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | void touchActiveTime() { |
Craig Mautner | 494f6bdd | 2014-07-21 11:17:46 -0700 | [diff] [blame] | 370 | lastActiveTime = System.currentTimeMillis(); |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 371 | if (firstActiveTime == 0) { |
| 372 | firstActiveTime = lastActiveTime; |
| 373 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 374 | } |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 375 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 376 | long getInactiveDuration() { |
Craig Mautner | 494f6bdd | 2014-07-21 11:17:46 -0700 | [diff] [blame] | 377 | return System.currentTimeMillis() - lastActiveTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 378 | } |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 379 | |
Winson Chung | fee2677 | 2014-08-05 12:21:52 -0700 | [diff] [blame] | 380 | /** Sets the original intent, and the calling uid and package. */ |
| 381 | void setIntent(ActivityRecord r) { |
Winson Chung | fee2677 | 2014-08-05 12:21:52 -0700 | [diff] [blame] | 382 | mCallingUid = r.launchedFromUid; |
| 383 | mCallingPackage = r.launchedFromPackage; |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 384 | setIntent(r.intent, r.info); |
Winson Chung | fee2677 | 2014-08-05 12:21:52 -0700 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | /** Sets the original intent, _without_ updating the calling uid or package. */ |
| 388 | private void setIntent(Intent _intent, ActivityInfo info) { |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 389 | if (intent == null) { |
| 390 | mNeverRelinquishIdentity = |
| 391 | (info.flags & ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY) == 0; |
| 392 | } else if (mNeverRelinquishIdentity) { |
| 393 | return; |
| 394 | } |
| 395 | |
| 396 | affinity = info.taskAffinity; |
Dianne Hackborn | 7922882 | 2014-09-16 11:11:23 -0700 | [diff] [blame] | 397 | if (intent == null) { |
| 398 | // If this task already has an intent associated with it, don't set the root |
| 399 | // affinity -- we don't want it changing after initially set, but the initially |
| 400 | // set value may be null. |
| 401 | rootAffinity = affinity; |
| 402 | } |
Dianne Hackborn | 885fbe5 | 2014-08-23 15:23:58 -0700 | [diff] [blame] | 403 | effectiveUid = info.applicationInfo.uid; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 404 | stringName = null; |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 405 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 406 | if (info.targetActivity == null) { |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 407 | if (_intent != null) { |
| 408 | // If this Intent has a selector, we want to clear it for the |
| 409 | // recent task since it is not relevant if the user later wants |
| 410 | // to re-launch the app. |
Dianne Hackborn | d367ca8 | 2012-05-07 15:49:39 -0700 | [diff] [blame] | 411 | if (_intent.getSelector() != null || _intent.getSourceBounds() != null) { |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 412 | _intent = new Intent(_intent); |
| 413 | _intent.setSelector(null); |
Dianne Hackborn | d367ca8 | 2012-05-07 15:49:39 -0700 | [diff] [blame] | 414 | _intent.setSourceBounds(null); |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 415 | } |
| 416 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 417 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Setting Intent of " + this + " to " + _intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 418 | intent = _intent; |
| 419 | realActivity = _intent != null ? _intent.getComponent() : null; |
| 420 | origActivity = null; |
| 421 | } else { |
| 422 | ComponentName targetComponent = new ComponentName( |
| 423 | info.packageName, info.targetActivity); |
| 424 | if (_intent != null) { |
| 425 | Intent targetIntent = new Intent(_intent); |
| 426 | targetIntent.setComponent(targetComponent); |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 427 | targetIntent.setSelector(null); |
Dianne Hackborn | d367ca8 | 2012-05-07 15:49:39 -0700 | [diff] [blame] | 428 | targetIntent.setSourceBounds(null); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 429 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
Dianne Hackborn | 7f96b79 | 2012-05-29 18:46:45 -0700 | [diff] [blame] | 430 | "Setting Intent of " + this + " to target " + targetIntent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 431 | intent = targetIntent; |
| 432 | realActivity = targetComponent; |
| 433 | origActivity = _intent.getComponent(); |
| 434 | } else { |
| 435 | intent = null; |
| 436 | realActivity = targetComponent; |
| 437 | origActivity = new ComponentName(info.packageName, info.name); |
| 438 | } |
| 439 | } |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 440 | |
Craig Mautner | 47b20ba | 2014-09-17 17:23:44 -0700 | [diff] [blame] | 441 | final int intentFlags = intent == null ? 0 : intent.getFlags(); |
| 442 | if ((intentFlags & Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 443 | // Once we are set to an Intent with this flag, we count this |
| 444 | // task as having a true root activity. |
| 445 | rootWasReset = true; |
| 446 | } |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 447 | |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 448 | userId = UserHandle.getUserId(info.applicationInfo.uid); |
Wale Ogunwale | f80170f | 2016-02-04 15:12:29 -0800 | [diff] [blame] | 449 | mUserSetupComplete = mService.mUserController.isUserSetupCompleteLocked(userId); |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 450 | if ((info.flags & ActivityInfo.FLAG_AUTO_REMOVE_FROM_RECENTS) != 0) { |
Dianne Hackborn | 13420f2 | 2014-07-18 15:43:56 -0700 | [diff] [blame] | 451 | // If the activity itself has requested auto-remove, then just always do it. |
| 452 | autoRemoveRecents = true; |
Wale Ogunwale | 843bfb9 | 2015-03-27 11:06:48 -0700 | [diff] [blame] | 453 | } else if ((intentFlags & (FLAG_ACTIVITY_NEW_DOCUMENT | FLAG_ACTIVITY_RETAIN_IN_RECENTS)) |
| 454 | == FLAG_ACTIVITY_NEW_DOCUMENT) { |
Dianne Hackborn | 13420f2 | 2014-07-18 15:43:56 -0700 | [diff] [blame] | 455 | // If the caller has not asked for the document to be retained, then we may |
| 456 | // want to turn on auto-remove, depending on whether the target has set its |
| 457 | // own document launch mode. |
| 458 | if (info.documentLaunchMode != ActivityInfo.DOCUMENT_LAUNCH_NONE) { |
| 459 | autoRemoveRecents = false; |
| 460 | } else { |
| 461 | autoRemoveRecents = true; |
| 462 | } |
| 463 | } else { |
| 464 | autoRemoveRecents = false; |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 465 | } |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 466 | mResizeMode = info.resizeMode; |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 467 | mLockTaskMode = info.lockTaskLaunchMode; |
Wale Ogunwale | a7afaa2 | 2015-05-01 20:39:18 -0700 | [diff] [blame] | 468 | mPrivileged = (info.applicationInfo.privateFlags & PRIVATE_FLAG_PRIVILEGED) != 0; |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 469 | setLockTaskAuth(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 470 | } |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 471 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 472 | void setTaskToReturnTo(int taskToReturnTo) { |
Wale Ogunwale | 673cbd2 | 2016-01-30 18:30:55 -0800 | [diff] [blame] | 473 | mTaskToReturnTo = (taskToReturnTo == RECENTS_ACTIVITY_TYPE) |
| 474 | ? HOME_ACTIVITY_TYPE : taskToReturnTo; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | int getTaskToReturnTo() { |
| 478 | return mTaskToReturnTo; |
| 479 | } |
| 480 | |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 481 | void setPrevAffiliate(TaskRecord prevAffiliate) { |
| 482 | mPrevAffiliate = prevAffiliate; |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 483 | mPrevAffiliateTaskId = prevAffiliate == null ? INVALID_TASK_ID : prevAffiliate.taskId; |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | void setNextAffiliate(TaskRecord nextAffiliate) { |
| 487 | mNextAffiliate = nextAffiliate; |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 488 | mNextAffiliateTaskId = nextAffiliate == null ? INVALID_TASK_ID : nextAffiliate.taskId; |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | // Close up recents linked list. |
| 492 | void closeRecentsChain() { |
| 493 | if (mPrevAffiliate != null) { |
| 494 | mPrevAffiliate.setNextAffiliate(mNextAffiliate); |
| 495 | } |
| 496 | if (mNextAffiliate != null) { |
| 497 | mNextAffiliate.setPrevAffiliate(mPrevAffiliate); |
| 498 | } |
| 499 | setPrevAffiliate(null); |
| 500 | setNextAffiliate(null); |
| 501 | } |
| 502 | |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 503 | void removedFromRecents() { |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 504 | disposeThumbnail(); |
| 505 | closeRecentsChain(); |
| 506 | if (inRecents) { |
| 507 | inRecents = false; |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 508 | mService.notifyTaskPersisterLocked(this, false); |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 509 | } |
| 510 | } |
| 511 | |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 512 | void setTaskToAffiliateWith(TaskRecord taskToAffiliateWith) { |
| 513 | closeRecentsChain(); |
| 514 | mAffiliatedTaskId = taskToAffiliateWith.mAffiliatedTaskId; |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame] | 515 | mAffiliatedTaskColor = taskToAffiliateWith.mAffiliatedTaskColor; |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 516 | // Find the end |
| 517 | while (taskToAffiliateWith.mNextAffiliate != null) { |
| 518 | final TaskRecord nextRecents = taskToAffiliateWith.mNextAffiliate; |
| 519 | if (nextRecents.mAffiliatedTaskId != mAffiliatedTaskId) { |
| 520 | Slog.e(TAG, "setTaskToAffiliateWith: nextRecents=" + nextRecents + " affilTaskId=" |
| 521 | + nextRecents.mAffiliatedTaskId + " should be " + mAffiliatedTaskId); |
| 522 | if (nextRecents.mPrevAffiliate == taskToAffiliateWith) { |
| 523 | nextRecents.setPrevAffiliate(null); |
| 524 | } |
| 525 | taskToAffiliateWith.setNextAffiliate(null); |
| 526 | break; |
| 527 | } |
| 528 | taskToAffiliateWith = nextRecents; |
| 529 | } |
| 530 | taskToAffiliateWith.setNextAffiliate(this); |
| 531 | setPrevAffiliate(taskToAffiliateWith); |
| 532 | setNextAffiliate(null); |
| 533 | } |
| 534 | |
Winson Chung | 096f36b | 2014-08-20 15:39:01 -0700 | [diff] [blame] | 535 | /** |
Winson | c809cbb | 2015-11-02 12:06:15 -0800 | [diff] [blame] | 536 | * Sets the last thumbnail with the current task bounds and the system orientation. |
Winson Chung | 096f36b | 2014-08-20 15:39:01 -0700 | [diff] [blame] | 537 | * @return whether the thumbnail was set |
| 538 | */ |
Winson | c809cbb | 2015-11-02 12:06:15 -0800 | [diff] [blame] | 539 | boolean setLastThumbnailLocked(Bitmap thumbnail) { |
| 540 | final Configuration serviceConfig = mService.mConfiguration; |
| 541 | int taskWidth = 0; |
| 542 | int taskHeight = 0; |
| 543 | if (mBounds != null) { |
| 544 | // Non-fullscreen tasks |
| 545 | taskWidth = mBounds.width(); |
| 546 | taskHeight = mBounds.height(); |
| 547 | } else if (stack != null) { |
| 548 | // Fullscreen tasks |
| 549 | final Point displaySize = new Point(); |
| 550 | stack.getDisplaySize(displaySize); |
| 551 | taskWidth = displaySize.x; |
| 552 | taskHeight = displaySize.y; |
| 553 | } else { |
| 554 | Slog.e(TAG, "setLastThumbnailLocked() called on Task without stack"); |
| 555 | } |
| 556 | return setLastThumbnailLocked(thumbnail, taskWidth, taskHeight, serviceConfig.orientation); |
| 557 | } |
| 558 | |
| 559 | /** |
| 560 | * Sets the last thumbnail with the current task bounds. |
| 561 | * @return whether the thumbnail was set |
| 562 | */ |
| 563 | private boolean setLastThumbnailLocked(Bitmap thumbnail, int taskWidth, int taskHeight, |
| 564 | int screenOrientation) { |
Winson Chung | 096f36b | 2014-08-20 15:39:01 -0700 | [diff] [blame] | 565 | if (mLastThumbnail != thumbnail) { |
| 566 | mLastThumbnail = thumbnail; |
Winson | c809cbb | 2015-11-02 12:06:15 -0800 | [diff] [blame] | 567 | mLastThumbnailInfo.taskWidth = taskWidth; |
| 568 | mLastThumbnailInfo.taskHeight = taskHeight; |
| 569 | mLastThumbnailInfo.screenOrientation = screenOrientation; |
Winson Chung | 096f36b | 2014-08-20 15:39:01 -0700 | [diff] [blame] | 570 | if (thumbnail == null) { |
| 571 | if (mLastThumbnailFile != null) { |
| 572 | mLastThumbnailFile.delete(); |
| 573 | } |
| 574 | } else { |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 575 | mService.mRecentTasks.saveImage(thumbnail, mLastThumbnailFile.getAbsolutePath()); |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 576 | } |
Winson Chung | 096f36b | 2014-08-20 15:39:01 -0700 | [diff] [blame] | 577 | return true; |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 578 | } |
Winson Chung | 096f36b | 2014-08-20 15:39:01 -0700 | [diff] [blame] | 579 | return false; |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 580 | } |
| 581 | |
| 582 | void getLastThumbnail(TaskThumbnail thumbs) { |
| 583 | thumbs.mainThumbnail = mLastThumbnail; |
Winson | c809cbb | 2015-11-02 12:06:15 -0800 | [diff] [blame] | 584 | thumbs.thumbnailInfo = mLastThumbnailInfo; |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 585 | thumbs.thumbnailFileDescriptor = null; |
Craig Mautner | f4f8bb7 | 2014-07-29 10:41:40 -0700 | [diff] [blame] | 586 | if (mLastThumbnail == null) { |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 587 | thumbs.mainThumbnail = mService.mRecentTasks.getImageFromWriteQueue( |
Suprabh Shukla | 2359314 | 2015-11-03 17:31:15 -0800 | [diff] [blame] | 588 | mLastThumbnailFile.getAbsolutePath()); |
Craig Mautner | f4f8bb7 | 2014-07-29 10:41:40 -0700 | [diff] [blame] | 589 | } |
Winson Chung | 096f36b | 2014-08-20 15:39:01 -0700 | [diff] [blame] | 590 | // Only load the thumbnail file if we don't have a thumbnail |
| 591 | if (thumbs.mainThumbnail == null && mLastThumbnailFile.exists()) { |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 592 | try { |
| 593 | thumbs.thumbnailFileDescriptor = ParcelFileDescriptor.open(mLastThumbnailFile, |
| 594 | ParcelFileDescriptor.MODE_READ_ONLY); |
| 595 | } catch (IOException e) { |
Dianne Hackborn | 9844d29 | 2013-10-04 16:44:22 -0700 | [diff] [blame] | 596 | } |
| 597 | } |
| 598 | } |
| 599 | |
Winson | c809cbb | 2015-11-02 12:06:15 -0800 | [diff] [blame] | 600 | /** |
| 601 | * Removes in-memory thumbnail data when the max number of in-memory task thumbnails is reached. |
| 602 | */ |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 603 | void freeLastThumbnail() { |
| 604 | mLastThumbnail = null; |
| 605 | } |
| 606 | |
Winson | c809cbb | 2015-11-02 12:06:15 -0800 | [diff] [blame] | 607 | /** |
| 608 | * Removes all associated thumbnail data when a task is removed or pruned from recents. |
| 609 | */ |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 610 | void disposeThumbnail() { |
Winson | c6a2da0 | 2015-11-11 18:11:59 -0800 | [diff] [blame] | 611 | mLastThumbnailInfo.reset(); |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 612 | mLastThumbnail = null; |
| 613 | lastDescription = null; |
| 614 | } |
| 615 | |
Winson Chung | 1147c40 | 2014-05-14 11:05:00 -0700 | [diff] [blame] | 616 | /** Returns the intent for the root activity for this task */ |
| 617 | Intent getBaseIntent() { |
| 618 | return intent != null ? intent : affinityIntent; |
| 619 | } |
| 620 | |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 621 | /** Returns the first non-finishing activity from the root. */ |
| 622 | ActivityRecord getRootActivity() { |
| 623 | for (int i = 0; i < mActivities.size(); i++) { |
| 624 | final ActivityRecord r = mActivities.get(i); |
| 625 | if (r.finishing) { |
| 626 | continue; |
| 627 | } |
| 628 | return r; |
| 629 | } |
| 630 | return null; |
| 631 | } |
| 632 | |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 633 | ActivityRecord getTopActivity() { |
| 634 | for (int i = mActivities.size() - 1; i >= 0; --i) { |
| 635 | final ActivityRecord r = mActivities.get(i); |
| 636 | if (r.finishing) { |
| 637 | continue; |
| 638 | } |
| 639 | return r; |
| 640 | } |
| 641 | return null; |
| 642 | } |
| 643 | |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 644 | ActivityRecord topRunningActivityLocked() { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 645 | if (stack != null) { |
| 646 | for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 647 | ActivityRecord r = mActivities.get(activityNdx); |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 648 | if (!r.finishing && stack.okToShowLocked(r)) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 649 | return r; |
| 650 | } |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 651 | } |
| 652 | } |
| 653 | return null; |
| 654 | } |
| 655 | |
Wale Ogunwale | 6d42df6 | 2015-11-05 09:50:55 -0800 | [diff] [blame] | 656 | void setFrontOfTask() { |
| 657 | setFrontOfTask(null); |
| 658 | } |
| 659 | |
Craig Mautner | 3b475fe | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 660 | /** Call after activity movement or finish to make sure that frontOfTask is set correctly */ |
Wale Ogunwale | 6d42df6 | 2015-11-05 09:50:55 -0800 | [diff] [blame] | 661 | void setFrontOfTask(ActivityRecord newTop) { |
| 662 | // If a top candidate is suggested by the caller, go ahead and use it and mark all others |
| 663 | // as not front. This is needed in situations where the current front activity in the |
| 664 | // task isn't finished yet and we want to set the front to the activity moved to the front |
| 665 | // of the task. |
| 666 | boolean foundFront = newTop != null ? true : false; |
| 667 | |
Craig Mautner | 3b475fe | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 668 | final int numActivities = mActivities.size(); |
Craig Mautner | 704e40b | 2013-12-18 16:43:51 -0800 | [diff] [blame] | 669 | for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) { |
Craig Mautner | 3b475fe | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 670 | final ActivityRecord r = mActivities.get(activityNdx); |
| 671 | if (foundFront || r.finishing) { |
| 672 | r.frontOfTask = false; |
| 673 | } else { |
| 674 | r.frontOfTask = true; |
| 675 | // Set frontOfTask false for every following activity. |
| 676 | foundFront = true; |
| 677 | } |
| 678 | } |
Craig Mautner | 9587ee0 | 2014-06-23 15:00:10 +0000 | [diff] [blame] | 679 | if (!foundFront && numActivities > 0) { |
| 680 | // All activities of this task are finishing. As we ought to have a frontOfTask |
| 681 | // activity, make the bottom activity front. |
| 682 | mActivities.get(0).frontOfTask = true; |
| 683 | } |
Wale Ogunwale | 6d42df6 | 2015-11-05 09:50:55 -0800 | [diff] [blame] | 684 | if (newTop != null) { |
| 685 | newTop.frontOfTask = true; |
| 686 | } |
Craig Mautner | 3b475fe | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 687 | } |
| 688 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 689 | /** |
Craig Mautner | 3b475fe | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 690 | * Reorder the history stack so that the passed activity is brought to the front. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 691 | */ |
| 692 | final void moveActivityToFrontLocked(ActivityRecord newTop) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 693 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 694 | "Removing and adding activity " + newTop |
| 695 | + " to stack at top callers=" + Debug.getCallers(4)); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 696 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 697 | mActivities.remove(newTop); |
| 698 | mActivities.add(newTop); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 699 | updateEffectiveIntent(); |
Craig Mautner | 3b475fe | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 700 | |
Wale Ogunwale | 6d42df6 | 2015-11-05 09:50:55 -0800 | [diff] [blame] | 701 | setFrontOfTask(newTop); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 702 | } |
| 703 | |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 704 | void addActivityAtBottom(ActivityRecord r) { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 705 | addActivityAtIndex(0, r); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | void addActivityToTop(ActivityRecord r) { |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 709 | addActivityAtIndex(mActivities.size(), r); |
| 710 | } |
| 711 | |
| 712 | void addActivityAtIndex(int index, ActivityRecord r) { |
Craig Mautner | 6170f73 | 2013-04-02 13:05:23 -0700 | [diff] [blame] | 713 | // Remove r first, and if it wasn't already in the list and it's fullscreen, count it. |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 714 | if (!mActivities.remove(r) && r.fullscreen) { |
| 715 | // Was not previously in list. |
| 716 | numFullscreen++; |
| 717 | } |
Craig Mautner | 2c1faed | 2013-07-23 12:56:02 -0700 | [diff] [blame] | 718 | // Only set this based on the first activity |
| 719 | if (mActivities.isEmpty()) { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 720 | taskType = r.mActivityType; |
| 721 | isPersistable = r.isPersistable(); |
Craig Mautner | dc00cbe | 2014-07-20 17:48:47 -0700 | [diff] [blame] | 722 | mCallingUid = r.launchedFromUid; |
| 723 | mCallingPackage = r.launchedFromPackage; |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 724 | // Clamp to [1, max]. |
| 725 | maxRecents = Math.min(Math.max(r.info.maxRecents, 1), |
| 726 | ActivityManager.getMaxAppRecentsLimitStatic()); |
Craig Mautner | 2c1faed | 2013-07-23 12:56:02 -0700 | [diff] [blame] | 727 | } else { |
| 728 | // Otherwise make all added activities match this one. |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 729 | r.mActivityType = taskType; |
Craig Mautner | 7873300 | 2013-06-10 13:54:49 -0700 | [diff] [blame] | 730 | } |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 731 | mActivities.add(index, r); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 732 | updateEffectiveIntent(); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 733 | if (r.isPersistable()) { |
| 734 | mService.notifyTaskPersisterLocked(this, false); |
| 735 | } |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 736 | } |
| 737 | |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 738 | /** @return true if this was the last activity in the task */ |
| 739 | boolean removeActivity(ActivityRecord r) { |
| 740 | if (mActivities.remove(r) && r.fullscreen) { |
| 741 | // Was previously in list. |
| 742 | numFullscreen--; |
| 743 | } |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 744 | if (r.isPersistable()) { |
| 745 | mService.notifyTaskPersisterLocked(this, false); |
| 746 | } |
Craig Mautner | 4132620 | 2014-06-20 14:38:21 -0700 | [diff] [blame] | 747 | if (mActivities.isEmpty()) { |
Craig Mautner | 5afcd4d | 2014-06-21 18:11:33 -0700 | [diff] [blame] | 748 | return !mReuseTask; |
Craig Mautner | 4132620 | 2014-06-20 14:38:21 -0700 | [diff] [blame] | 749 | } |
| 750 | updateEffectiveIntent(); |
| 751 | return false; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 752 | } |
| 753 | |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 754 | boolean autoRemoveFromRecents() { |
Dianne Hackborn | d38aed8 | 2014-06-10 21:36:35 -0700 | [diff] [blame] | 755 | // We will automatically remove the task either if it has explicitly asked for |
| 756 | // this, or it is empty and has never contained an activity that got shown to |
| 757 | // the user. |
Dianne Hackborn | 13420f2 | 2014-07-18 15:43:56 -0700 | [diff] [blame] | 758 | return autoRemoveRecents || (mActivities.isEmpty() && !hasBeenVisible); |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 759 | } |
| 760 | |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 761 | /** |
| 762 | * Completely remove all activities associated with an existing |
| 763 | * task starting at a specified index. |
| 764 | */ |
| 765 | final void performClearTaskAtIndexLocked(int activityNdx) { |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 766 | int numActivities = mActivities.size(); |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 767 | for ( ; activityNdx < numActivities; ++activityNdx) { |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 768 | final ActivityRecord r = mActivities.get(activityNdx); |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 769 | if (r.finishing) { |
| 770 | continue; |
| 771 | } |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 772 | if (stack == null) { |
| 773 | // Task was restored from persistent storage. |
| 774 | r.takeFromHistory(); |
| 775 | mActivities.remove(activityNdx); |
| 776 | --activityNdx; |
| 777 | --numActivities; |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 778 | } else if (stack.finishActivityLocked( |
| 779 | r, Activity.RESULT_CANCELED, null, "clear-task-index", false)) { |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 780 | --activityNdx; |
| 781 | --numActivities; |
| 782 | } |
| 783 | } |
| 784 | } |
| 785 | |
| 786 | /** |
| 787 | * Completely remove all activities associated with an existing task. |
| 788 | */ |
| 789 | final void performClearTaskLocked() { |
Craig Mautner | 362449a | 2014-06-20 14:04:39 -0700 | [diff] [blame] | 790 | mReuseTask = true; |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 791 | performClearTaskAtIndexLocked(0); |
Craig Mautner | 362449a | 2014-06-20 14:04:39 -0700 | [diff] [blame] | 792 | mReuseTask = false; |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 793 | } |
| 794 | |
Filip Gruszczynski | be9dabd | 2016-01-19 12:23:10 -0800 | [diff] [blame] | 795 | ActivityRecord performClearTaskForReuseLocked(ActivityRecord newR, int launchFlags) { |
| 796 | mReuseTask = true; |
| 797 | final ActivityRecord result = performClearTaskLocked(newR, launchFlags); |
| 798 | mReuseTask = false; |
| 799 | return result; |
| 800 | } |
| 801 | |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 802 | /** |
| 803 | * Perform clear operation as requested by |
| 804 | * {@link Intent#FLAG_ACTIVITY_CLEAR_TOP}: search from the top of the |
| 805 | * stack to the given task, then look for |
| 806 | * an instance of that activity in the stack and, if found, finish all |
| 807 | * activities on top of it and return the instance. |
| 808 | * |
| 809 | * @param newR Description of the new activity being started. |
| 810 | * @return Returns the old activity that should be continued to be used, |
| 811 | * or null if none was found. |
| 812 | */ |
| 813 | final ActivityRecord performClearTaskLocked(ActivityRecord newR, int launchFlags) { |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 814 | int numActivities = mActivities.size(); |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 815 | for (int activityNdx = numActivities - 1; activityNdx >= 0; --activityNdx) { |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 816 | ActivityRecord r = mActivities.get(activityNdx); |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 817 | if (r.finishing) { |
| 818 | continue; |
| 819 | } |
| 820 | if (r.realActivity.equals(newR.realActivity)) { |
| 821 | // Here it is! Now finish everything in front... |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 822 | final ActivityRecord ret = r; |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 823 | |
| 824 | for (++activityNdx; activityNdx < numActivities; ++activityNdx) { |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 825 | r = mActivities.get(activityNdx); |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 826 | if (r.finishing) { |
| 827 | continue; |
| 828 | } |
| 829 | ActivityOptions opts = r.takeOptionsLocked(); |
| 830 | if (opts != null) { |
| 831 | ret.updateOptionsLocked(opts); |
| 832 | } |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 833 | if (stack != null && stack.finishActivityLocked( |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 834 | r, Activity.RESULT_CANCELED, null, "clear-task-stack", false)) { |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 835 | --activityNdx; |
| 836 | --numActivities; |
| 837 | } |
| 838 | } |
| 839 | |
| 840 | // Finally, if this is a normal launch mode (that is, not |
| 841 | // expecting onNewIntent()), then we will finish the current |
| 842 | // instance of the activity so a new fresh one can be started. |
| 843 | if (ret.launchMode == ActivityInfo.LAUNCH_MULTIPLE |
| 844 | && (launchFlags & Intent.FLAG_ACTIVITY_SINGLE_TOP) == 0) { |
| 845 | if (!ret.finishing) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 846 | if (stack != null) { |
| 847 | stack.finishActivityLocked( |
| 848 | ret, Activity.RESULT_CANCELED, null, "clear-task-top", false); |
| 849 | } |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 850 | return null; |
| 851 | } |
| 852 | } |
| 853 | |
| 854 | return ret; |
| 855 | } |
| 856 | } |
| 857 | |
| 858 | return null; |
| 859 | } |
| 860 | |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 861 | public TaskThumbnail getTaskThumbnailLocked() { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 862 | if (stack != null) { |
| 863 | final ActivityRecord resumedActivity = stack.mResumedActivity; |
| 864 | if (resumedActivity != null && resumedActivity.task == this) { |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 865 | final Bitmap thumbnail = stack.screenshotActivitiesLocked(resumedActivity); |
Winson | c809cbb | 2015-11-02 12:06:15 -0800 | [diff] [blame] | 866 | setLastThumbnailLocked(thumbnail); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 867 | } |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 868 | } |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 869 | final TaskThumbnail taskThumbnail = new TaskThumbnail(); |
| 870 | getLastThumbnail(taskThumbnail); |
| 871 | return taskThumbnail; |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 872 | } |
| 873 | |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 874 | public void removeTaskActivitiesLocked() { |
| 875 | // Just remove the entire task. |
| 876 | performClearTaskAtIndexLocked(0); |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 877 | } |
| 878 | |
Craig Mautner | 432f64e | 2015-05-20 14:59:57 -0700 | [diff] [blame] | 879 | String lockTaskAuthToString() { |
| 880 | switch (mLockTaskAuth) { |
| 881 | case LOCK_TASK_AUTH_DONT_LOCK: return "LOCK_TASK_AUTH_DONT_LOCK"; |
| 882 | case LOCK_TASK_AUTH_PINNABLE: return "LOCK_TASK_AUTH_PINNABLE"; |
| 883 | case LOCK_TASK_AUTH_LAUNCHABLE: return "LOCK_TASK_AUTH_LAUNCHABLE"; |
| 884 | case LOCK_TASK_AUTH_WHITELISTED: return "LOCK_TASK_AUTH_WHITELISTED"; |
Benjamin Franz | 469dd58 | 2015-06-09 14:24:36 +0100 | [diff] [blame] | 885 | case LOCK_TASK_AUTH_LAUNCHABLE_PRIV: return "LOCK_TASK_AUTH_LAUNCHABLE_PRIV"; |
Craig Mautner | 432f64e | 2015-05-20 14:59:57 -0700 | [diff] [blame] | 886 | default: return "unknown=" + mLockTaskAuth; |
| 887 | } |
| 888 | } |
| 889 | |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 890 | void setLockTaskAuth() { |
Benjamin Franz | 469dd58 | 2015-06-09 14:24:36 +0100 | [diff] [blame] | 891 | if (!mPrivileged && |
| 892 | (mLockTaskMode == LOCK_TASK_LAUNCH_MODE_ALWAYS || |
| 893 | mLockTaskMode == LOCK_TASK_LAUNCH_MODE_NEVER)) { |
| 894 | // Non-priv apps are not allowed to use always or never, fall back to default |
| 895 | mLockTaskMode = LOCK_TASK_LAUNCH_MODE_DEFAULT; |
| 896 | } |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 897 | switch (mLockTaskMode) { |
| 898 | case LOCK_TASK_LAUNCH_MODE_DEFAULT: |
| 899 | mLockTaskAuth = isLockTaskWhitelistedLocked() ? |
| 900 | LOCK_TASK_AUTH_WHITELISTED : LOCK_TASK_AUTH_PINNABLE; |
| 901 | break; |
| 902 | |
| 903 | case LOCK_TASK_LAUNCH_MODE_NEVER: |
Benjamin Franz | 469dd58 | 2015-06-09 14:24:36 +0100 | [diff] [blame] | 904 | mLockTaskAuth = LOCK_TASK_AUTH_DONT_LOCK; |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 905 | break; |
| 906 | |
| 907 | case LOCK_TASK_LAUNCH_MODE_ALWAYS: |
Benjamin Franz | 469dd58 | 2015-06-09 14:24:36 +0100 | [diff] [blame] | 908 | mLockTaskAuth = LOCK_TASK_AUTH_LAUNCHABLE_PRIV; |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 909 | break; |
| 910 | |
| 911 | case LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED: |
| 912 | mLockTaskAuth = isLockTaskWhitelistedLocked() ? |
| 913 | LOCK_TASK_AUTH_LAUNCHABLE : LOCK_TASK_AUTH_PINNABLE; |
| 914 | break; |
| 915 | } |
Craig Mautner | 432f64e | 2015-05-20 14:59:57 -0700 | [diff] [blame] | 916 | if (DEBUG_LOCKTASK) Slog.d(TAG_LOCKTASK, "setLockTaskAuth: task=" + this + |
| 917 | " mLockTaskAuth=" + lockTaskAuthToString()); |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | boolean isLockTaskWhitelistedLocked() { |
Benjamin Franz | 6fd84cc | 2015-08-06 18:09:03 +0100 | [diff] [blame] | 921 | String pkg = (realActivity != null) ? realActivity.getPackageName() : null; |
| 922 | if (pkg == null) { |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 923 | return false; |
| 924 | } |
| 925 | String[] packages = mService.mLockTaskPackages.get(userId); |
| 926 | if (packages == null) { |
| 927 | return false; |
| 928 | } |
| 929 | for (int i = packages.length - 1; i >= 0; --i) { |
Benjamin Franz | 6fd84cc | 2015-08-06 18:09:03 +0100 | [diff] [blame] | 930 | if (pkg.equals(packages[i])) { |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 931 | return true; |
| 932 | } |
| 933 | } |
| 934 | return false; |
| 935 | } |
Wale Ogunwale | 74e2659 | 2016-02-05 11:48:37 -0800 | [diff] [blame] | 936 | |
Craig Mautner | a82aa09 | 2013-09-13 15:34:08 -0700 | [diff] [blame] | 937 | boolean isHomeTask() { |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 938 | return taskType == HOME_ACTIVITY_TYPE; |
Craig Mautner | a82aa09 | 2013-09-13 15:34:08 -0700 | [diff] [blame] | 939 | } |
| 940 | |
Wale Ogunwale | 74e2659 | 2016-02-05 11:48:37 -0800 | [diff] [blame] | 941 | boolean isRecentsTask() { |
| 942 | return taskType == RECENTS_ACTIVITY_TYPE; |
| 943 | } |
| 944 | |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 945 | boolean isApplicationTask() { |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 946 | return taskType == APPLICATION_ACTIVITY_TYPE; |
| 947 | } |
| 948 | |
| 949 | boolean isOverHomeStack() { |
| 950 | return mTaskToReturnTo == HOME_ACTIVITY_TYPE || mTaskToReturnTo == RECENTS_ACTIVITY_TYPE; |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 951 | } |
| 952 | |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 953 | boolean isResizeable() { |
| 954 | return !isHomeTask() && (mService.mForceResizableActivities |
Jorim Jaggi | 8202b2a | 2016-02-03 19:24:31 -0800 | [diff] [blame] | 955 | || ActivityInfo.isResizeableMode(mResizeMode)) && !mTemporarilyUnresizable; |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 956 | } |
| 957 | |
| 958 | boolean inCropWindowsResizeMode() { |
| 959 | return !isResizeable() && mResizeMode == RESIZE_MODE_CROP_WINDOWS; |
| 960 | } |
| 961 | |
Wale Ogunwale | 513346d | 2016-01-27 10:55:01 -0800 | [diff] [blame] | 962 | boolean canGoInDockedStack() { |
| 963 | return isResizeable() || inCropWindowsResizeMode(); |
| 964 | } |
| 965 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 966 | /** |
| 967 | * Find the activity in the history stack within the given task. Returns |
| 968 | * the index within the history at which it's found, or < 0 if not found. |
| 969 | */ |
| 970 | final ActivityRecord findActivityInHistoryLocked(ActivityRecord r) { |
| 971 | final ComponentName realActivity = r.realActivity; |
| 972 | for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 973 | ActivityRecord candidate = mActivities.get(activityNdx); |
| 974 | if (candidate.finishing) { |
| 975 | continue; |
| 976 | } |
| 977 | if (candidate.realActivity.equals(realActivity)) { |
| 978 | return candidate; |
| 979 | } |
| 980 | } |
| 981 | return null; |
| 982 | } |
| 983 | |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 984 | /** Updates the last task description values. */ |
| 985 | void updateTaskDescription() { |
| 986 | // Traverse upwards looking for any break between main task activities and |
| 987 | // utility activities. |
| 988 | int activityNdx; |
| 989 | final int numActivities = mActivities.size(); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 990 | final boolean relinquish = numActivities == 0 ? false : |
| 991 | (mActivities.get(0).info.flags & ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY) != 0; |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 992 | for (activityNdx = Math.min(numActivities, 1); activityNdx < numActivities; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 993 | ++activityNdx) { |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 994 | final ActivityRecord r = mActivities.get(activityNdx); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 995 | if (relinquish && (r.info.flags & ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY) == 0) { |
| 996 | // This will be the top activity for determining taskDescription. Pre-inc to |
| 997 | // overcome initial decrement below. |
| 998 | ++activityNdx; |
| 999 | break; |
| 1000 | } |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1001 | if (r.intent != null && |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 1002 | (r.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) { |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1003 | break; |
| 1004 | } |
| 1005 | } |
| 1006 | if (activityNdx > 0) { |
| 1007 | // Traverse downwards starting below break looking for set label, icon. |
| 1008 | // Note that if there are activities in the task but none of them set the |
| 1009 | // recent activity values, then we do not fall back to the last set |
| 1010 | // values in the TaskRecord. |
| 1011 | String label = null; |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 1012 | String iconFilename = null; |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1013 | int colorPrimary = 0; |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 1014 | int colorBackground = 0; |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1015 | for (--activityNdx; activityNdx >= 0; --activityNdx) { |
| 1016 | final ActivityRecord r = mActivities.get(activityNdx); |
| 1017 | if (r.taskDescription != null) { |
| 1018 | if (label == null) { |
| 1019 | label = r.taskDescription.getLabel(); |
| 1020 | } |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 1021 | if (iconFilename == null) { |
| 1022 | iconFilename = r.taskDescription.getIconFilename(); |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1023 | } |
| 1024 | if (colorPrimary == 0) { |
| 1025 | colorPrimary = r.taskDescription.getPrimaryColor(); |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1026 | } |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 1027 | if (colorBackground == 0) { |
| 1028 | colorBackground = r.taskDescription.getBackgroundColor(); |
| 1029 | } |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1030 | } |
| 1031 | } |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 1032 | lastTaskDescription = new TaskDescription(label, null, iconFilename, colorPrimary, |
| 1033 | colorBackground); |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame] | 1034 | // Update the task affiliation color if we are the parent of the group |
| 1035 | if (taskId == mAffiliatedTaskId) { |
| 1036 | mAffiliatedTaskColor = lastTaskDescription.getPrimaryColor(); |
| 1037 | } |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1038 | } |
| 1039 | } |
| 1040 | |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 1041 | int findEffectiveRootIndex() { |
Craig Mautner | 4767f4b | 2014-09-18 15:38:33 -0700 | [diff] [blame] | 1042 | int effectiveNdx = 0; |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 1043 | final int topActivityNdx = mActivities.size() - 1; |
Dianne Hackborn | 39569af | 2014-09-23 10:56:58 -0700 | [diff] [blame] | 1044 | for (int activityNdx = 0; activityNdx <= topActivityNdx; ++activityNdx) { |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 1045 | final ActivityRecord r = mActivities.get(activityNdx); |
| 1046 | if (r.finishing) { |
| 1047 | continue; |
| 1048 | } |
Craig Mautner | 4767f4b | 2014-09-18 15:38:33 -0700 | [diff] [blame] | 1049 | effectiveNdx = activityNdx; |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 1050 | if ((r.info.flags & ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY) == 0) { |
| 1051 | break; |
| 1052 | } |
| 1053 | } |
Craig Mautner | 4767f4b | 2014-09-18 15:38:33 -0700 | [diff] [blame] | 1054 | return effectiveNdx; |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 1055 | } |
| 1056 | |
| 1057 | void updateEffectiveIntent() { |
| 1058 | final int effectiveRootIndex = findEffectiveRootIndex(); |
| 1059 | final ActivityRecord r = mActivities.get(effectiveRootIndex); |
Winson Chung | fee2677 | 2014-08-05 12:21:52 -0700 | [diff] [blame] | 1060 | setIntent(r); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 1061 | } |
| 1062 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1063 | void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1064 | if (DEBUG_RECENTS) Slog.i(TAG_RECENTS, "Saving task=" + this); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1065 | |
| 1066 | out.attribute(null, ATTR_TASKID, String.valueOf(taskId)); |
| 1067 | if (realActivity != null) { |
| 1068 | out.attribute(null, ATTR_REALACTIVITY, realActivity.flattenToShortString()); |
| 1069 | } |
Andrei Stingaceanu | 4ccec53 | 2016-01-13 12:10:21 +0000 | [diff] [blame] | 1070 | out.attribute(null, ATTR_REALACTIVITY_SUSPENDED, String.valueOf(realActivitySuspended)); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1071 | if (origActivity != null) { |
| 1072 | out.attribute(null, ATTR_ORIGACTIVITY, origActivity.flattenToShortString()); |
| 1073 | } |
Dianne Hackborn | 7922882 | 2014-09-16 11:11:23 -0700 | [diff] [blame] | 1074 | // Write affinity, and root affinity if it is different from affinity. |
| 1075 | // We use the special string "@" for a null root affinity, so we can identify |
| 1076 | // later whether we were given a root affinity or should just make it the |
| 1077 | // same as the affinity. |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1078 | if (affinity != null) { |
| 1079 | out.attribute(null, ATTR_AFFINITY, affinity); |
Dianne Hackborn | 7922882 | 2014-09-16 11:11:23 -0700 | [diff] [blame] | 1080 | if (!affinity.equals(rootAffinity)) { |
| 1081 | out.attribute(null, ATTR_ROOT_AFFINITY, rootAffinity != null ? rootAffinity : "@"); |
| 1082 | } |
| 1083 | } else if (rootAffinity != null) { |
| 1084 | out.attribute(null, ATTR_ROOT_AFFINITY, rootAffinity != null ? rootAffinity : "@"); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1085 | } |
| 1086 | out.attribute(null, ATTR_ROOTHASRESET, String.valueOf(rootWasReset)); |
Dianne Hackborn | 13420f2 | 2014-07-18 15:43:56 -0700 | [diff] [blame] | 1087 | out.attribute(null, ATTR_AUTOREMOVERECENTS, String.valueOf(autoRemoveRecents)); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1088 | out.attribute(null, ATTR_ASKEDCOMPATMODE, String.valueOf(askedCompatMode)); |
| 1089 | out.attribute(null, ATTR_USERID, String.valueOf(userId)); |
Wale Ogunwale | f80170f | 2016-02-04 15:12:29 -0800 | [diff] [blame] | 1090 | out.attribute(null, ATTR_USER_SETUP_COMPLETE, String.valueOf(mUserSetupComplete)); |
Dianne Hackborn | 885fbe5 | 2014-08-23 15:23:58 -0700 | [diff] [blame] | 1091 | out.attribute(null, ATTR_EFFECTIVE_UID, String.valueOf(effectiveUid)); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1092 | out.attribute(null, ATTR_TASKTYPE, String.valueOf(taskType)); |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 1093 | out.attribute(null, ATTR_FIRSTACTIVETIME, String.valueOf(firstActiveTime)); |
Winson Chung | f1fbd77 | 2014-06-24 18:06:58 -0700 | [diff] [blame] | 1094 | out.attribute(null, ATTR_LASTACTIVETIME, String.valueOf(lastActiveTime)); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1095 | out.attribute(null, ATTR_LASTTIMEMOVED, String.valueOf(mLastTimeMoved)); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 1096 | out.attribute(null, ATTR_NEVERRELINQUISH, String.valueOf(mNeverRelinquishIdentity)); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1097 | if (lastDescription != null) { |
| 1098 | out.attribute(null, ATTR_LASTDESCRIPTION, lastDescription.toString()); |
| 1099 | } |
Winson Chung | 2cb86c7 | 2014-06-25 12:03:30 -0700 | [diff] [blame] | 1100 | if (lastTaskDescription != null) { |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 1101 | lastTaskDescription.saveToXml(out); |
Winson Chung | 2cb86c7 | 2014-06-25 12:03:30 -0700 | [diff] [blame] | 1102 | } |
Winson | c809cbb | 2015-11-02 12:06:15 -0800 | [diff] [blame] | 1103 | mLastThumbnailInfo.saveToXml(out); |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame] | 1104 | out.attribute(null, ATTR_TASK_AFFILIATION_COLOR, String.valueOf(mAffiliatedTaskColor)); |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 1105 | out.attribute(null, ATTR_TASK_AFFILIATION, String.valueOf(mAffiliatedTaskId)); |
| 1106 | out.attribute(null, ATTR_PREV_AFFILIATION, String.valueOf(mPrevAffiliateTaskId)); |
| 1107 | out.attribute(null, ATTR_NEXT_AFFILIATION, String.valueOf(mNextAffiliateTaskId)); |
Craig Mautner | dc00cbe | 2014-07-20 17:48:47 -0700 | [diff] [blame] | 1108 | out.attribute(null, ATTR_CALLING_UID, String.valueOf(mCallingUid)); |
| 1109 | out.attribute(null, ATTR_CALLING_PACKAGE, mCallingPackage == null ? "" : mCallingPackage); |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 1110 | out.attribute(null, ATTR_RESIZE_MODE, String.valueOf(mResizeMode)); |
Wale Ogunwale | a7afaa2 | 2015-05-01 20:39:18 -0700 | [diff] [blame] | 1111 | out.attribute(null, ATTR_PRIVILEGED, String.valueOf(mPrivileged)); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 1112 | if (mLastNonFullscreenBounds != null) { |
| 1113 | out.attribute( |
| 1114 | null, ATTR_NON_FULLSCREEN_BOUNDS, mLastNonFullscreenBounds.flattenToString()); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1115 | } |
Winson Chung | 2cb86c7 | 2014-06-25 12:03:30 -0700 | [diff] [blame] | 1116 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1117 | if (affinityIntent != null) { |
| 1118 | out.startTag(null, TAG_AFFINITYINTENT); |
| 1119 | affinityIntent.saveToXml(out); |
| 1120 | out.endTag(null, TAG_AFFINITYINTENT); |
| 1121 | } |
| 1122 | |
| 1123 | out.startTag(null, TAG_INTENT); |
| 1124 | intent.saveToXml(out); |
| 1125 | out.endTag(null, TAG_INTENT); |
| 1126 | |
| 1127 | final ArrayList<ActivityRecord> activities = mActivities; |
| 1128 | final int numActivities = activities.size(); |
| 1129 | for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) { |
| 1130 | final ActivityRecord r = activities.get(activityNdx); |
Craig Mautner | 43e52ed | 2014-06-16 17:18:52 -0700 | [diff] [blame] | 1131 | if (r.info.persistableMode == ActivityInfo.PERSIST_ROOT_ONLY || !r.isPersistable() || |
Wale Ogunwale | 843bfb9 | 2015-03-27 11:06:48 -0700 | [diff] [blame] | 1132 | ((r.intent.getFlags() & FLAG_ACTIVITY_NEW_DOCUMENT |
| 1133 | | FLAG_ACTIVITY_RETAIN_IN_RECENTS) == FLAG_ACTIVITY_NEW_DOCUMENT) && |
Craig Mautner | 43e52ed | 2014-06-16 17:18:52 -0700 | [diff] [blame] | 1134 | activityNdx > 0) { |
Craig Mautner | f357c0c | 2014-06-09 09:23:27 -0700 | [diff] [blame] | 1135 | // Stop at first non-persistable or first break in task (CLEAR_WHEN_TASK_RESET). |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1136 | break; |
| 1137 | } |
| 1138 | out.startTag(null, TAG_ACTIVITY); |
| 1139 | r.saveToXml(out); |
| 1140 | out.endTag(null, TAG_ACTIVITY); |
| 1141 | } |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1142 | } |
| 1143 | |
| 1144 | static TaskRecord restoreFromXml(XmlPullParser in, ActivityStackSupervisor stackSupervisor) |
| 1145 | throws IOException, XmlPullParserException { |
| 1146 | Intent intent = null; |
| 1147 | Intent affinityIntent = null; |
Winson | c809cbb | 2015-11-02 12:06:15 -0800 | [diff] [blame] | 1148 | ArrayList<ActivityRecord> activities = new ArrayList<>(); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1149 | ComponentName realActivity = null; |
Andrei Stingaceanu | 4ccec53 | 2016-01-13 12:10:21 +0000 | [diff] [blame] | 1150 | boolean realActivitySuspended = false; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1151 | ComponentName origActivity = null; |
| 1152 | String affinity = null; |
Dianne Hackborn | 7922882 | 2014-09-16 11:11:23 -0700 | [diff] [blame] | 1153 | String rootAffinity = null; |
| 1154 | boolean hasRootAffinity = false; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1155 | boolean rootHasReset = false; |
Dianne Hackborn | 13420f2 | 2014-07-18 15:43:56 -0700 | [diff] [blame] | 1156 | boolean autoRemoveRecents = false; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1157 | boolean askedCompatMode = false; |
| 1158 | int taskType = ActivityRecord.APPLICATION_ACTIVITY_TYPE; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1159 | int userId = 0; |
Wale Ogunwale | f80170f | 2016-02-04 15:12:29 -0800 | [diff] [blame] | 1160 | boolean userSetupComplete = true; |
Dianne Hackborn | 885fbe5 | 2014-08-23 15:23:58 -0700 | [diff] [blame] | 1161 | int effectiveUid = -1; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1162 | String lastDescription = null; |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 1163 | long firstActiveTime = -1; |
Winson Chung | 2cb86c7 | 2014-06-25 12:03:30 -0700 | [diff] [blame] | 1164 | long lastActiveTime = -1; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1165 | long lastTimeOnTop = 0; |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 1166 | boolean neverRelinquishIdentity = true; |
Stefan Kuhne | e88d1e5 | 2015-05-18 10:33:45 -0700 | [diff] [blame] | 1167 | int taskId = INVALID_TASK_ID; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1168 | final int outerDepth = in.getDepth(); |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 1169 | TaskDescription taskDescription = new TaskDescription(); |
Winson | c809cbb | 2015-11-02 12:06:15 -0800 | [diff] [blame] | 1170 | TaskThumbnailInfo thumbnailInfo = new TaskThumbnailInfo(); |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 1171 | int taskAffiliation = INVALID_TASK_ID; |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame] | 1172 | int taskAffiliationColor = 0; |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 1173 | int prevTaskId = INVALID_TASK_ID; |
| 1174 | int nextTaskId = INVALID_TASK_ID; |
Craig Mautner | dc00cbe | 2014-07-20 17:48:47 -0700 | [diff] [blame] | 1175 | int callingUid = -1; |
| 1176 | String callingPackage = ""; |
Wale Ogunwale | d829d36 | 2016-02-10 19:24:49 -0800 | [diff] [blame] | 1177 | int resizeMode = RESIZE_MODE_FORCE_RESIZEABLE; |
Wale Ogunwale | a7afaa2 | 2015-05-01 20:39:18 -0700 | [diff] [blame] | 1178 | boolean privileged = false; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1179 | Rect bounds = null; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1180 | |
| 1181 | for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) { |
| 1182 | final String attrName = in.getAttributeName(attrNdx); |
| 1183 | final String attrValue = in.getAttributeValue(attrNdx); |
Stefan Kuhne | e88d1e5 | 2015-05-18 10:33:45 -0700 | [diff] [blame] | 1184 | if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: attribute name=" + |
| 1185 | attrName + " value=" + attrValue); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1186 | if (ATTR_TASKID.equals(attrName)) { |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 1187 | if (taskId == INVALID_TASK_ID) taskId = Integer.valueOf(attrValue); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1188 | } else if (ATTR_REALACTIVITY.equals(attrName)) { |
| 1189 | realActivity = ComponentName.unflattenFromString(attrValue); |
Andrei Stingaceanu | 4ccec53 | 2016-01-13 12:10:21 +0000 | [diff] [blame] | 1190 | } else if (ATTR_REALACTIVITY_SUSPENDED.equals(attrName)) { |
| 1191 | realActivitySuspended = Boolean.valueOf(attrValue); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1192 | } else if (ATTR_ORIGACTIVITY.equals(attrName)) { |
| 1193 | origActivity = ComponentName.unflattenFromString(attrValue); |
| 1194 | } else if (ATTR_AFFINITY.equals(attrName)) { |
| 1195 | affinity = attrValue; |
Dianne Hackborn | 7922882 | 2014-09-16 11:11:23 -0700 | [diff] [blame] | 1196 | } else if (ATTR_ROOT_AFFINITY.equals(attrName)) { |
| 1197 | rootAffinity = attrValue; |
| 1198 | hasRootAffinity = true; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1199 | } else if (ATTR_ROOTHASRESET.equals(attrName)) { |
| 1200 | rootHasReset = Boolean.valueOf(attrValue); |
Dianne Hackborn | 13420f2 | 2014-07-18 15:43:56 -0700 | [diff] [blame] | 1201 | } else if (ATTR_AUTOREMOVERECENTS.equals(attrName)) { |
| 1202 | autoRemoveRecents = Boolean.valueOf(attrValue); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1203 | } else if (ATTR_ASKEDCOMPATMODE.equals(attrName)) { |
| 1204 | askedCompatMode = Boolean.valueOf(attrValue); |
| 1205 | } else if (ATTR_USERID.equals(attrName)) { |
| 1206 | userId = Integer.valueOf(attrValue); |
Wale Ogunwale | f80170f | 2016-02-04 15:12:29 -0800 | [diff] [blame] | 1207 | } else if (ATTR_USER_SETUP_COMPLETE.equals(attrName)) { |
| 1208 | userSetupComplete = Boolean.valueOf(attrValue); |
Dianne Hackborn | 885fbe5 | 2014-08-23 15:23:58 -0700 | [diff] [blame] | 1209 | } else if (ATTR_EFFECTIVE_UID.equals(attrName)) { |
| 1210 | effectiveUid = Integer.valueOf(attrValue); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1211 | } else if (ATTR_TASKTYPE.equals(attrName)) { |
| 1212 | taskType = Integer.valueOf(attrValue); |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 1213 | } else if (ATTR_FIRSTACTIVETIME.equals(attrName)) { |
| 1214 | firstActiveTime = Long.valueOf(attrValue); |
Winson Chung | f1fbd77 | 2014-06-24 18:06:58 -0700 | [diff] [blame] | 1215 | } else if (ATTR_LASTACTIVETIME.equals(attrName)) { |
| 1216 | lastActiveTime = Long.valueOf(attrValue); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1217 | } else if (ATTR_LASTDESCRIPTION.equals(attrName)) { |
| 1218 | lastDescription = attrValue; |
| 1219 | } else if (ATTR_LASTTIMEMOVED.equals(attrName)) { |
| 1220 | lastTimeOnTop = Long.valueOf(attrValue); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 1221 | } else if (ATTR_NEVERRELINQUISH.equals(attrName)) { |
| 1222 | neverRelinquishIdentity = Boolean.valueOf(attrValue); |
Winson | c809cbb | 2015-11-02 12:06:15 -0800 | [diff] [blame] | 1223 | } else if (attrName.startsWith(TaskThumbnailInfo.ATTR_TASK_THUMBNAILINFO_PREFIX)) { |
| 1224 | thumbnailInfo.restoreFromXml(attrName, attrValue); |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 1225 | } else if (attrName.startsWith(TaskDescription.ATTR_TASKDESCRIPTION_PREFIX)) { |
| 1226 | taskDescription.restoreFromXml(attrName, attrValue); |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 1227 | } else if (ATTR_TASK_AFFILIATION.equals(attrName)) { |
| 1228 | taskAffiliation = Integer.valueOf(attrValue); |
| 1229 | } else if (ATTR_PREV_AFFILIATION.equals(attrName)) { |
| 1230 | prevTaskId = Integer.valueOf(attrValue); |
| 1231 | } else if (ATTR_NEXT_AFFILIATION.equals(attrName)) { |
| 1232 | nextTaskId = Integer.valueOf(attrValue); |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame] | 1233 | } else if (ATTR_TASK_AFFILIATION_COLOR.equals(attrName)) { |
| 1234 | taskAffiliationColor = Integer.valueOf(attrValue); |
Craig Mautner | dc00cbe | 2014-07-20 17:48:47 -0700 | [diff] [blame] | 1235 | } else if (ATTR_CALLING_UID.equals(attrName)) { |
| 1236 | callingUid = Integer.valueOf(attrValue); |
| 1237 | } else if (ATTR_CALLING_PACKAGE.equals(attrName)) { |
| 1238 | callingPackage = attrValue; |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 1239 | } else if (ATTR_RESIZE_MODE.equals(attrName)) { |
| 1240 | resizeMode = Integer.valueOf(attrValue); |
Wale Ogunwale | d829d36 | 2016-02-10 19:24:49 -0800 | [diff] [blame] | 1241 | resizeMode = (resizeMode == RESIZE_MODE_CROP_WINDOWS) |
| 1242 | ? RESIZE_MODE_FORCE_RESIZEABLE : resizeMode; |
Wale Ogunwale | a7afaa2 | 2015-05-01 20:39:18 -0700 | [diff] [blame] | 1243 | } else if (ATTR_PRIVILEGED.equals(attrName)) { |
| 1244 | privileged = Boolean.valueOf(attrValue); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 1245 | } else if (ATTR_NON_FULLSCREEN_BOUNDS.equals(attrName)) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1246 | bounds = Rect.unflattenFromString(attrValue); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1247 | } else { |
| 1248 | Slog.w(TAG, "TaskRecord: Unknown attribute=" + attrName); |
| 1249 | } |
| 1250 | } |
| 1251 | |
| 1252 | int event; |
| 1253 | while (((event = in.next()) != XmlPullParser.END_DOCUMENT) && |
Ben Kwa | 8814cf4 | 2015-07-08 10:54:56 -0700 | [diff] [blame] | 1254 | (event != XmlPullParser.END_TAG || in.getDepth() >= outerDepth)) { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1255 | if (event == XmlPullParser.START_TAG) { |
| 1256 | final String name = in.getName(); |
Stefan Kuhne | e88d1e5 | 2015-05-18 10:33:45 -0700 | [diff] [blame] | 1257 | if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: START_TAG name=" + |
| 1258 | name); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1259 | if (TAG_AFFINITYINTENT.equals(name)) { |
| 1260 | affinityIntent = Intent.restoreFromXml(in); |
| 1261 | } else if (TAG_INTENT.equals(name)) { |
| 1262 | intent = Intent.restoreFromXml(in); |
| 1263 | } else if (TAG_ACTIVITY.equals(name)) { |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 1264 | ActivityRecord activity = ActivityRecord.restoreFromXml(in, stackSupervisor); |
Stefan Kuhne | e88d1e5 | 2015-05-18 10:33:45 -0700 | [diff] [blame] | 1265 | if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: activity=" + |
| 1266 | activity); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1267 | if (activity != null) { |
| 1268 | activities.add(activity); |
| 1269 | } |
| 1270 | } else { |
| 1271 | Slog.e(TAG, "restoreTask: Unexpected name=" + name); |
| 1272 | XmlUtils.skipCurrentTag(in); |
| 1273 | } |
| 1274 | } |
| 1275 | } |
Dianne Hackborn | 7922882 | 2014-09-16 11:11:23 -0700 | [diff] [blame] | 1276 | if (!hasRootAffinity) { |
| 1277 | rootAffinity = affinity; |
| 1278 | } else if ("@".equals(rootAffinity)) { |
| 1279 | rootAffinity = null; |
| 1280 | } |
Dianne Hackborn | 885fbe5 | 2014-08-23 15:23:58 -0700 | [diff] [blame] | 1281 | if (effectiveUid <= 0) { |
| 1282 | Intent checkIntent = intent != null ? intent : affinityIntent; |
| 1283 | effectiveUid = 0; |
| 1284 | if (checkIntent != null) { |
| 1285 | IPackageManager pm = AppGlobals.getPackageManager(); |
| 1286 | try { |
| 1287 | ApplicationInfo ai = pm.getApplicationInfo( |
| 1288 | checkIntent.getComponent().getPackageName(), |
| 1289 | PackageManager.GET_UNINSTALLED_PACKAGES |
| 1290 | | PackageManager.GET_DISABLED_COMPONENTS, userId); |
| 1291 | if (ai != null) { |
| 1292 | effectiveUid = ai.uid; |
| 1293 | } |
| 1294 | } catch (RemoteException e) { |
| 1295 | } |
| 1296 | } |
| 1297 | Slog.w(TAG, "Updating task #" + taskId + " for " + checkIntent |
| 1298 | + ": effectiveUid=" + effectiveUid); |
| 1299 | } |
| 1300 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1301 | final TaskRecord task = new TaskRecord(stackSupervisor.mService, taskId, intent, |
Dianne Hackborn | 7922882 | 2014-09-16 11:11:23 -0700 | [diff] [blame] | 1302 | affinityIntent, affinity, rootAffinity, realActivity, origActivity, rootHasReset, |
Dianne Hackborn | 885fbe5 | 2014-08-23 15:23:58 -0700 | [diff] [blame] | 1303 | autoRemoveRecents, askedCompatMode, taskType, userId, effectiveUid, lastDescription, |
| 1304 | activities, firstActiveTime, lastActiveTime, lastTimeOnTop, neverRelinquishIdentity, |
Winson | c809cbb | 2015-11-02 12:06:15 -0800 | [diff] [blame] | 1305 | taskDescription, thumbnailInfo, taskAffiliation, prevTaskId, nextTaskId, |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 1306 | taskAffiliationColor, callingUid, callingPackage, resizeMode, privileged, |
Wale Ogunwale | f80170f | 2016-02-04 15:12:29 -0800 | [diff] [blame] | 1307 | realActivitySuspended, userSetupComplete); |
Filip Gruszczynski | aff7f13 | 2015-09-02 17:21:21 -0700 | [diff] [blame] | 1308 | task.updateOverrideConfiguration(bounds); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1309 | |
| 1310 | for (int activityNdx = activities.size() - 1; activityNdx >=0; --activityNdx) { |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 1311 | activities.get(activityNdx).task = task; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1312 | } |
| 1313 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1314 | if (DEBUG_RECENTS) Slog.d(TAG_RECENTS, "Restored task=" + task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1315 | return task; |
| 1316 | } |
| 1317 | |
Wale Ogunwale | 9a08f82 | 2016-02-17 19:03:58 -0800 | [diff] [blame^] | 1318 | private void adjustForMinimalTaskDimensions(Rect bounds) { |
| 1319 | if (bounds == null) { |
| 1320 | return; |
| 1321 | } |
| 1322 | final int minimalSize = mMinimalSize == -1 |
| 1323 | ? mService.mStackSupervisor.mDefaultMinimalSizeOfResizeableTask : mMinimalSize; |
| 1324 | final boolean adjustWidth = minimalSize > bounds.width(); |
| 1325 | final boolean adjustHeight = minimalSize > bounds.height(); |
| 1326 | if (!(adjustWidth || adjustHeight)) { |
| 1327 | return; |
| 1328 | } |
| 1329 | |
| 1330 | if (adjustWidth) { |
| 1331 | if (mBounds != null && bounds.right == mBounds.right) { |
| 1332 | bounds.left = bounds.right - minimalSize; |
| 1333 | } else { |
| 1334 | // Either left bounds match, or neither match, or the previous bounds were |
| 1335 | // fullscreen and we default to keeping left. |
| 1336 | bounds.right = bounds.left + minimalSize; |
| 1337 | } |
| 1338 | } |
| 1339 | if (adjustHeight) { |
| 1340 | if (mBounds != null && bounds.bottom == mBounds.bottom) { |
| 1341 | bounds.top = bounds.bottom - minimalSize; |
| 1342 | } else { |
| 1343 | // Either top bounds match, or neither match, or the previous bounds were |
| 1344 | // fullscreen and we default to keeping top. |
| 1345 | bounds.bottom = bounds.top + minimalSize; |
| 1346 | } |
| 1347 | } |
| 1348 | } |
| 1349 | |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 1350 | /** |
| 1351 | * Update task's override configuration based on the bounds. |
Jorim Jaggi | 0a93214 | 2016-02-01 17:42:25 -0800 | [diff] [blame] | 1352 | * @param bounds The bounds of the task. |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 1353 | * @return Update configuration or null if there is no change. |
| 1354 | */ |
Filip Gruszczynski | aff7f13 | 2015-09-02 17:21:21 -0700 | [diff] [blame] | 1355 | Configuration updateOverrideConfiguration(Rect bounds) { |
Jorim Jaggi | 0a93214 | 2016-02-01 17:42:25 -0800 | [diff] [blame] | 1356 | return updateOverrideConfiguration(bounds, null /* insetBounds */); |
| 1357 | } |
| 1358 | |
| 1359 | /** |
| 1360 | * Update task's override configuration based on the bounds. |
| 1361 | * @param bounds The bounds of the task. |
| 1362 | * @param insetBounds The bounds used to calculate the system insets, which is used here to |
| 1363 | * subtract the navigation bar/status bar size from the screen size reported |
| 1364 | * to the application. See {@link IActivityManager#resizeDockedStack}. |
| 1365 | * @return Update configuration or null if there is no change. |
| 1366 | */ |
| 1367 | Configuration updateOverrideConfiguration(Rect bounds, @Nullable Rect insetBounds) { |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 1368 | if (Objects.equals(mBounds, bounds)) { |
| 1369 | return null; |
| 1370 | } |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1371 | final Configuration oldConfig = mOverrideConfig; |
| 1372 | final boolean oldFullscreen = mFullscreen; |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 1373 | |
| 1374 | mFullscreen = bounds == null; |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 1375 | if (mFullscreen) { |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 1376 | if (mBounds != null && StackId.persistTaskBounds(stack.mStackId)) { |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 1377 | mLastNonFullscreenBounds = mBounds; |
| 1378 | } |
| 1379 | mBounds = null; |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 1380 | mOverrideConfig = Configuration.EMPTY; |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 1381 | } else { |
Wale Ogunwale | 9a08f82 | 2016-02-17 19:03:58 -0800 | [diff] [blame^] | 1382 | mTmpRect.set(bounds); |
| 1383 | adjustForMinimalTaskDimensions(mTmpRect); |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 1384 | if (mBounds == null) { |
Wale Ogunwale | 9a08f82 | 2016-02-17 19:03:58 -0800 | [diff] [blame^] | 1385 | mBounds = new Rect(mTmpRect); |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 1386 | } else { |
Wale Ogunwale | 9a08f82 | 2016-02-17 19:03:58 -0800 | [diff] [blame^] | 1387 | mBounds.set(mTmpRect); |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 1388 | } |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 1389 | if (stack == null || StackId.persistTaskBounds(stack.mStackId)) { |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1390 | mLastNonFullscreenBounds = mBounds; |
| 1391 | } |
Wale Ogunwale | 9a08f82 | 2016-02-17 19:03:58 -0800 | [diff] [blame^] | 1392 | mOverrideConfig = calculateOverrideConfig(mTmpRect, insetBounds); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 1393 | } |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1394 | |
| 1395 | if (mFullscreen != oldFullscreen) { |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 1396 | mService.mStackSupervisor.scheduleReportMultiWindowChanged(this); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1397 | } |
| 1398 | |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 1399 | return !mOverrideConfig.equals(oldConfig) ? mOverrideConfig : null; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1400 | } |
| 1401 | |
Jorim Jaggi | 82c9dc9 | 2016-02-05 15:10:33 -0800 | [diff] [blame] | 1402 | private void subtractNonDecorInsets(Rect inOutBounds, Rect inInsetBounds) { |
| 1403 | mTmpRect2.set(inInsetBounds); |
| 1404 | mService.mWindowManager.subtractNonDecorInsets(mTmpRect2); |
| 1405 | int leftInset = mTmpRect2.left - inInsetBounds.left; |
| 1406 | int topInset = mTmpRect2.top - inInsetBounds.top; |
| 1407 | int rightInset = inInsetBounds.right - mTmpRect2.right; |
| 1408 | int bottomInset = inInsetBounds.bottom - mTmpRect2.bottom; |
| 1409 | inOutBounds.inset(leftInset, topInset, rightInset, bottomInset); |
| 1410 | } |
| 1411 | |
Jorim Jaggi | 0a93214 | 2016-02-01 17:42:25 -0800 | [diff] [blame] | 1412 | private void subtractStableInsets(Rect inOutBounds, Rect inInsetBounds) { |
| 1413 | mTmpRect2.set(inInsetBounds); |
| 1414 | mService.mWindowManager.subtractStableInsets(mTmpRect2); |
| 1415 | int leftInset = mTmpRect2.left - inInsetBounds.left; |
| 1416 | int topInset = mTmpRect2.top - inInsetBounds.top; |
| 1417 | int rightInset = inInsetBounds.right - mTmpRect2.right; |
| 1418 | int bottomInset = inInsetBounds.bottom - mTmpRect2.bottom; |
| 1419 | inOutBounds.inset(leftInset, topInset, rightInset, bottomInset); |
| 1420 | } |
| 1421 | |
Jorim Jaggi | 82c9dc9 | 2016-02-05 15:10:33 -0800 | [diff] [blame] | 1422 | private Configuration calculateOverrideConfig(Rect bounds, Rect insetBounds) { |
| 1423 | mTmpNonDecorBounds.set(bounds); |
| 1424 | mTmpStableBounds.set(bounds); |
| 1425 | subtractNonDecorInsets( |
| 1426 | mTmpNonDecorBounds, insetBounds != null ? insetBounds : bounds); |
| 1427 | subtractStableInsets( |
| 1428 | mTmpStableBounds, insetBounds != null ? insetBounds : bounds); |
| 1429 | |
| 1430 | // For calculating screenWidthDp, screenWidthDp, we use the stable inset screen area, |
| 1431 | // i.e. the screen area without the system bars. |
Jorim Jaggi | a95ca8d | 2016-01-15 22:54:46 -0800 | [diff] [blame] | 1432 | final Configuration serviceConfig = mService.mConfiguration; |
| 1433 | final Configuration config = new Configuration(Configuration.EMPTY); |
| 1434 | // TODO(multidisplay): Update Dp to that of display stack is on. |
| 1435 | final float density = serviceConfig.densityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE; |
| 1436 | config.screenWidthDp = |
Jorim Jaggi | 82c9dc9 | 2016-02-05 15:10:33 -0800 | [diff] [blame] | 1437 | Math.min((int)(mTmpStableBounds.width() / density), serviceConfig.screenWidthDp); |
Jorim Jaggi | a95ca8d | 2016-01-15 22:54:46 -0800 | [diff] [blame] | 1438 | config.screenHeightDp = |
Jorim Jaggi | 82c9dc9 | 2016-02-05 15:10:33 -0800 | [diff] [blame] | 1439 | Math.min((int)(mTmpStableBounds.height() / density), serviceConfig.screenHeightDp); |
| 1440 | config.smallestScreenWidthDp = Math.min(config.screenWidthDp, config.screenHeightDp); |
| 1441 | |
| 1442 | // TODO: Orientation? |
Jorim Jaggi | a95ca8d | 2016-01-15 22:54:46 -0800 | [diff] [blame] | 1443 | config.orientation = (config.screenWidthDp <= config.screenHeightDp) |
| 1444 | ? Configuration.ORIENTATION_PORTRAIT |
| 1445 | : Configuration.ORIENTATION_LANDSCAPE; |
Jorim Jaggi | 82c9dc9 | 2016-02-05 15:10:33 -0800 | [diff] [blame] | 1446 | |
| 1447 | // For calculating screen layout, we need to use the non-decor inset screen area for the |
| 1448 | // calculation for compatibility reasons, i.e. screen area without system bars that could |
| 1449 | // never go away in Honeycomb. |
| 1450 | final int compatScreenWidthDp = (int)(mTmpNonDecorBounds.width() / density); |
| 1451 | final int compatScreenHeightDp = (int)(mTmpNonDecorBounds.height() / density); |
Jorim Jaggi | a95ca8d | 2016-01-15 22:54:46 -0800 | [diff] [blame] | 1452 | final int sl = Configuration.resetScreenLayout(serviceConfig.screenLayout); |
Jorim Jaggi | 82c9dc9 | 2016-02-05 15:10:33 -0800 | [diff] [blame] | 1453 | final int longSize = Math.max(compatScreenHeightDp, compatScreenWidthDp); |
| 1454 | final int shortSize = Math.min(compatScreenHeightDp, compatScreenWidthDp); |
Jorim Jaggi | 0a93214 | 2016-02-01 17:42:25 -0800 | [diff] [blame] | 1455 | config.screenLayout = Configuration.reduceScreenLayout(sl, longSize, shortSize); |
Jorim Jaggi | a95ca8d | 2016-01-15 22:54:46 -0800 | [diff] [blame] | 1456 | return config; |
| 1457 | } |
| 1458 | |
| 1459 | /** |
| 1460 | * Using the existing configuration {@param config}, creates a new task override config such |
| 1461 | * that all the fields that are usually set in an override config are set to the ones in |
| 1462 | * {@param config}. |
| 1463 | */ |
| 1464 | Configuration extractOverrideConfig(Configuration config) { |
| 1465 | final Configuration extracted = new Configuration(Configuration.EMPTY); |
| 1466 | extracted.screenWidthDp = config.screenWidthDp; |
| 1467 | extracted.screenHeightDp = config.screenHeightDp; |
| 1468 | extracted.smallestScreenWidthDp = config.smallestScreenWidthDp; |
| 1469 | extracted.orientation = config.orientation; |
| 1470 | extracted.screenLayout = config.screenLayout; |
| 1471 | return extracted; |
| 1472 | } |
| 1473 | |
Filip Gruszczynski | dce2d16 | 2016-01-12 15:40:13 -0800 | [diff] [blame] | 1474 | Rect updateOverrideConfigurationFromLaunchBounds() { |
| 1475 | final Rect bounds = validateBounds(getLaunchBounds()); |
| 1476 | updateOverrideConfiguration(bounds); |
| 1477 | return bounds; |
| 1478 | } |
| 1479 | |
| 1480 | static Rect validateBounds(Rect bounds) { |
| 1481 | if (bounds != null && bounds.isEmpty()) { |
| 1482 | Slog.wtf(TAG, "Received strange task bounds: " + bounds, new Throwable()); |
| 1483 | return null; |
| 1484 | } |
| 1485 | return bounds; |
| 1486 | } |
| 1487 | |
Wale Ogunwale | 935e502 | 2015-11-10 12:36:10 -0800 | [diff] [blame] | 1488 | /** Updates the task's bounds and override configuration to match what is expected for the |
| 1489 | * input stack. */ |
| 1490 | void updateOverrideConfigurationForStack(ActivityStack inStack) { |
| 1491 | if (stack != null && stack == inStack) { |
| 1492 | return; |
| 1493 | } |
| 1494 | |
| 1495 | if (inStack.mStackId == FREEFORM_WORKSPACE_STACK_ID) { |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 1496 | if (!isResizeable()) { |
Wale Ogunwale | 935e502 | 2015-11-10 12:36:10 -0800 | [diff] [blame] | 1497 | throw new IllegalArgumentException("Can not position non-resizeable task=" |
| 1498 | + this + " in stack=" + inStack); |
| 1499 | } |
| 1500 | if (mBounds != null) { |
| 1501 | return; |
| 1502 | } |
| 1503 | if (mLastNonFullscreenBounds != null) { |
| 1504 | updateOverrideConfiguration(mLastNonFullscreenBounds); |
| 1505 | } else { |
| 1506 | inStack.layoutTaskInStack(this, null); |
| 1507 | } |
| 1508 | } else { |
| 1509 | updateOverrideConfiguration(inStack.mBounds); |
| 1510 | } |
| 1511 | } |
| 1512 | |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 1513 | /** |
| 1514 | * Returns the correct stack to use based on task type and currently set bounds, |
| 1515 | * regardless of the focused stack and current stack association of the task. |
| 1516 | * The task will be moved (and stack focus changed) later if necessary. |
| 1517 | */ |
| 1518 | int getLaunchStackId() { |
| 1519 | if (!isApplicationTask()) { |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 1520 | return HOME_STACK_ID; |
| 1521 | } |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 1522 | if (mBounds != null) { |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 1523 | return FREEFORM_WORKSPACE_STACK_ID; |
| 1524 | } |
| 1525 | return FULLSCREEN_WORKSPACE_STACK_ID; |
| 1526 | } |
| 1527 | |
| 1528 | /** Returns the bounds that should be used to launch this task. */ |
| 1529 | Rect getLaunchBounds() { |
Chong Zhang | 75b3720 | 2015-12-04 14:16:36 -0800 | [diff] [blame] | 1530 | // If we're over lockscreen, forget about stack bounds and use fullscreen. |
| 1531 | if (mService.mLockScreenShown == LOCK_SCREEN_SHOWN) { |
| 1532 | return null; |
| 1533 | } |
| 1534 | |
Chong Zhang | 7d5f510 | 2016-01-13 10:29:24 -0800 | [diff] [blame] | 1535 | if (stack == null) { |
| 1536 | return null; |
| 1537 | } |
| 1538 | |
| 1539 | final int stackId = stack.mStackId; |
| 1540 | if (stackId == HOME_STACK_ID |
| 1541 | || stackId == FULLSCREEN_WORKSPACE_STACK_ID |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 1542 | || (stackId == DOCKED_STACK_ID && !isResizeable())) { |
| 1543 | return isResizeable() ? stack.mBounds : null; |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 1544 | } else if (!StackId.persistTaskBounds(stackId)) { |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1545 | return stack.mBounds; |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 1546 | } |
| 1547 | return mLastNonFullscreenBounds; |
| 1548 | } |
| 1549 | |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 1550 | boolean canMatchRootAffinity() { |
| 1551 | // We don't allow root affinity matching on the pinned stack as no other task should |
| 1552 | // be launching in it based on affinity. |
| 1553 | return rootAffinity != null && (stack == null || stack.mStackId != PINNED_STACK_ID); |
| 1554 | } |
| 1555 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1556 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 1557 | pw.print(prefix); pw.print("userId="); pw.print(userId); |
Dianne Hackborn | 885fbe5 | 2014-08-23 15:23:58 -0700 | [diff] [blame] | 1558 | pw.print(" effectiveUid="); UserHandle.formatUid(pw, effectiveUid); |
| 1559 | pw.print(" mCallingUid="); UserHandle.formatUid(pw, mCallingUid); |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 1560 | pw.print(" mCallingPackage="); pw.println(mCallingPackage); |
Dianne Hackborn | 7922882 | 2014-09-16 11:11:23 -0700 | [diff] [blame] | 1561 | if (affinity != null || rootAffinity != null) { |
| 1562 | pw.print(prefix); pw.print("affinity="); pw.print(affinity); |
| 1563 | if (affinity == null || !affinity.equals(rootAffinity)) { |
| 1564 | pw.print(" root="); pw.println(rootAffinity); |
| 1565 | } else { |
| 1566 | pw.println(); |
| 1567 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1568 | } |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 1569 | if (voiceSession != null || voiceInteractor != null) { |
| 1570 | pw.print(prefix); pw.print("VOICE: session=0x"); |
| 1571 | pw.print(Integer.toHexString(System.identityHashCode(voiceSession))); |
| 1572 | pw.print(" interactor=0x"); |
| 1573 | pw.println(Integer.toHexString(System.identityHashCode(voiceInteractor))); |
| 1574 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1575 | if (intent != null) { |
| 1576 | StringBuilder sb = new StringBuilder(128); |
| 1577 | sb.append(prefix); sb.append("intent={"); |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 1578 | intent.toShortString(sb, false, true, false, true); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1579 | sb.append('}'); |
| 1580 | pw.println(sb.toString()); |
| 1581 | } |
| 1582 | if (affinityIntent != null) { |
| 1583 | StringBuilder sb = new StringBuilder(128); |
| 1584 | sb.append(prefix); sb.append("affinityIntent={"); |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 1585 | affinityIntent.toShortString(sb, false, true, false, true); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1586 | sb.append('}'); |
| 1587 | pw.println(sb.toString()); |
| 1588 | } |
| 1589 | if (origActivity != null) { |
| 1590 | pw.print(prefix); pw.print("origActivity="); |
| 1591 | pw.println(origActivity.flattenToShortString()); |
| 1592 | } |
| 1593 | if (realActivity != null) { |
| 1594 | pw.print(prefix); pw.print("realActivity="); |
| 1595 | pw.println(realActivity.flattenToShortString()); |
| 1596 | } |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 1597 | if (autoRemoveRecents || isPersistable || taskType != 0 || mTaskToReturnTo != 0 |
| 1598 | || numFullscreen != 0) { |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 1599 | pw.print(prefix); pw.print("autoRemoveRecents="); pw.print(autoRemoveRecents); |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 1600 | pw.print(" isPersistable="); pw.print(isPersistable); |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 1601 | pw.print(" numFullscreen="); pw.print(numFullscreen); |
| 1602 | pw.print(" taskType="); pw.print(taskType); |
| 1603 | pw.print(" mTaskToReturnTo="); pw.println(mTaskToReturnTo); |
| 1604 | } |
Craig Mautner | 432f64e | 2015-05-20 14:59:57 -0700 | [diff] [blame] | 1605 | if (rootWasReset || mNeverRelinquishIdentity || mReuseTask |
| 1606 | || mLockTaskAuth != LOCK_TASK_AUTH_PINNABLE) { |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 1607 | pw.print(prefix); pw.print("rootWasReset="); pw.print(rootWasReset); |
| 1608 | pw.print(" mNeverRelinquishIdentity="); pw.print(mNeverRelinquishIdentity); |
Craig Mautner | 432f64e | 2015-05-20 14:59:57 -0700 | [diff] [blame] | 1609 | pw.print(" mReuseTask="); pw.print(mReuseTask); |
| 1610 | pw.print(" mLockTaskAuth="); pw.println(lockTaskAuthToString()); |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 1611 | } |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 1612 | if (mAffiliatedTaskId != taskId || mPrevAffiliateTaskId != INVALID_TASK_ID |
| 1613 | || mPrevAffiliate != null || mNextAffiliateTaskId != INVALID_TASK_ID |
| 1614 | || mNextAffiliate != null) { |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 1615 | pw.print(prefix); pw.print("affiliation="); pw.print(mAffiliatedTaskId); |
| 1616 | pw.print(" prevAffiliation="); pw.print(mPrevAffiliateTaskId); |
| 1617 | pw.print(" ("); |
| 1618 | if (mPrevAffiliate == null) { |
| 1619 | pw.print("null"); |
| 1620 | } else { |
| 1621 | pw.print(Integer.toHexString(System.identityHashCode(mPrevAffiliate))); |
| 1622 | } |
| 1623 | pw.print(") nextAffiliation="); pw.print(mNextAffiliateTaskId); |
| 1624 | pw.print(" ("); |
| 1625 | if (mNextAffiliate == null) { |
| 1626 | pw.print("null"); |
| 1627 | } else { |
| 1628 | pw.print(Integer.toHexString(System.identityHashCode(mNextAffiliate))); |
| 1629 | } |
| 1630 | pw.println(")"); |
| 1631 | } |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1632 | pw.print(prefix); pw.print("Activities="); pw.println(mActivities); |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 1633 | if (!askedCompatMode || !inRecents || !isAvailable) { |
| 1634 | pw.print(prefix); pw.print("askedCompatMode="); pw.print(askedCompatMode); |
| 1635 | pw.print(" inRecents="); pw.print(inRecents); |
| 1636 | pw.print(" isAvailable="); pw.println(isAvailable); |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 1637 | } |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 1638 | pw.print(prefix); pw.print("lastThumbnail="); pw.print(mLastThumbnail); |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 1639 | pw.print(" lastThumbnailFile="); pw.println(mLastThumbnailFile); |
| 1640 | if (lastDescription != null) { |
| 1641 | pw.print(prefix); pw.print("lastDescription="); pw.println(lastDescription); |
| 1642 | } |
Wale Ogunwale | 069fbe4 | 2015-07-29 11:38:01 -0700 | [diff] [blame] | 1643 | if (stack != null) { |
| 1644 | pw.print(prefix); pw.print("stackId="); pw.println(stack.mStackId); |
| 1645 | } |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 1646 | pw.print(prefix + "hasBeenVisible=" + hasBeenVisible); |
| 1647 | pw.print(" mResizeMode=" + ActivityInfo.resizeModeToString(mResizeMode)); |
| 1648 | pw.print(" isResizeable=" + isResizeable()); |
| 1649 | pw.print(" firstActiveTime=" + lastActiveTime); |
| 1650 | pw.print(" lastActiveTime=" + lastActiveTime); |
| 1651 | pw.println(" (inactive for " + (getInactiveDuration() / 1000) + "s)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1652 | } |
| 1653 | |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1654 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1655 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1656 | StringBuilder sb = new StringBuilder(128); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1657 | if (stringName != null) { |
| 1658 | sb.append(stringName); |
| 1659 | sb.append(" U="); |
| 1660 | sb.append(userId); |
Wale Ogunwale | 6c5eb1c | 2015-11-10 07:52:22 -0800 | [diff] [blame] | 1661 | sb.append(" StackId="); |
| 1662 | sb.append(stack != null ? stack.mStackId : INVALID_STACK_ID); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1663 | sb.append(" sz="); |
| 1664 | sb.append(mActivities.size()); |
| 1665 | sb.append('}'); |
| 1666 | return sb.toString(); |
| 1667 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1668 | sb.append("TaskRecord{"); |
| 1669 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 1670 | sb.append(" #"); |
| 1671 | sb.append(taskId); |
| 1672 | if (affinity != null) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1673 | sb.append(" A="); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1674 | sb.append(affinity); |
| 1675 | } else if (intent != null) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1676 | sb.append(" I="); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1677 | sb.append(intent.getComponent().flattenToShortString()); |
| 1678 | } else if (affinityIntent != null) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1679 | sb.append(" aI="); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1680 | sb.append(affinityIntent.getComponent().flattenToShortString()); |
| 1681 | } else { |
| 1682 | sb.append(" ??"); |
| 1683 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1684 | stringName = sb.toString(); |
| 1685 | return toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1686 | } |
| 1687 | } |