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