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