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 | |
| 19 | import android.content.ComponentName; |
| 20 | import android.content.Intent; |
| 21 | import android.content.pm.ActivityInfo; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 22 | import android.os.UserHandle; |
Dianne Hackborn | 7f96b79 | 2012-05-29 18:46:45 -0700 | [diff] [blame] | 23 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | |
| 25 | import java.io.PrintWriter; |
| 26 | |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 27 | class TaskRecord extends ThumbnailHolder { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | final int taskId; // Unique identifier for this task. |
| 29 | final String affinity; // The affinity name for this task, or null. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | Intent intent; // The original intent that started the task. |
| 31 | Intent affinityIntent; // Intent of affinity-moved activity that started this task. |
| 32 | ComponentName origActivity; // The non-alias activity component of the intent. |
| 33 | ComponentName realActivity; // The actual activity component that started the task. |
| 34 | int numActivities; // Current number of activities in this task. |
| 35 | long lastActiveTime; // Last time this task was active, including sleep. |
| 36 | boolean rootWasReset; // True if the intent at the root of the task had |
| 37 | // the FLAG_ACTIVITY_RESET_TASK_IF_NEEDED flag. |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 38 | boolean askedCompatMode;// Have asked the user about compat mode for this task. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 40 | String stringName; // caching of toString() result. |
Dianne Hackborn | 9da2d40 | 2012-03-15 13:43:08 -0700 | [diff] [blame] | 41 | int userId; // user for which this task was created |
Craig Mautner | 2ad9207 | 2013-02-25 16:19:24 -0800 | [diff] [blame] | 42 | |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 43 | TaskRecord(int _taskId, ActivityInfo info, Intent _intent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | taskId = _taskId; |
| 45 | affinity = info.taskAffinity; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | setIntent(_intent, info); |
| 47 | } |
| 48 | |
| 49 | void touchActiveTime() { |
| 50 | lastActiveTime = android.os.SystemClock.elapsedRealtime(); |
| 51 | } |
| 52 | |
| 53 | long getInactiveDuration() { |
| 54 | return android.os.SystemClock.elapsedRealtime() - lastActiveTime; |
| 55 | } |
| 56 | |
| 57 | void setIntent(Intent _intent, ActivityInfo info) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 58 | stringName = null; |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 59 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | if (info.targetActivity == null) { |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 61 | if (_intent != null) { |
| 62 | // If this Intent has a selector, we want to clear it for the |
| 63 | // recent task since it is not relevant if the user later wants |
| 64 | // to re-launch the app. |
Dianne Hackborn | d367ca8 | 2012-05-07 15:49:39 -0700 | [diff] [blame] | 65 | if (_intent.getSelector() != null || _intent.getSourceBounds() != null) { |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 66 | _intent = new Intent(_intent); |
| 67 | _intent.setSelector(null); |
Dianne Hackborn | d367ca8 | 2012-05-07 15:49:39 -0700 | [diff] [blame] | 68 | _intent.setSourceBounds(null); |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 69 | } |
| 70 | } |
Dianne Hackborn | 7f96b79 | 2012-05-29 18:46:45 -0700 | [diff] [blame] | 71 | if (ActivityManagerService.DEBUG_TASKS) Slog.v(ActivityManagerService.TAG, |
| 72 | "Setting Intent of " + this + " to " + _intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | intent = _intent; |
| 74 | realActivity = _intent != null ? _intent.getComponent() : null; |
| 75 | origActivity = null; |
| 76 | } else { |
| 77 | ComponentName targetComponent = new ComponentName( |
| 78 | info.packageName, info.targetActivity); |
| 79 | if (_intent != null) { |
| 80 | Intent targetIntent = new Intent(_intent); |
| 81 | targetIntent.setComponent(targetComponent); |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 82 | targetIntent.setSelector(null); |
Dianne Hackborn | d367ca8 | 2012-05-07 15:49:39 -0700 | [diff] [blame] | 83 | targetIntent.setSourceBounds(null); |
Dianne Hackborn | 7f96b79 | 2012-05-29 18:46:45 -0700 | [diff] [blame] | 84 | if (ActivityManagerService.DEBUG_TASKS) Slog.v(ActivityManagerService.TAG, |
| 85 | "Setting Intent of " + this + " to target " + targetIntent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | intent = targetIntent; |
| 87 | realActivity = targetComponent; |
| 88 | origActivity = _intent.getComponent(); |
| 89 | } else { |
| 90 | intent = null; |
| 91 | realActivity = targetComponent; |
| 92 | origActivity = new ComponentName(info.packageName, info.name); |
| 93 | } |
| 94 | } |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 95 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | if (intent != null && |
| 97 | (intent.getFlags()&Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) { |
| 98 | // Once we are set to an Intent with this flag, we count this |
| 99 | // task as having a true root activity. |
| 100 | rootWasReset = true; |
| 101 | } |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 102 | |
| 103 | if (info.applicationInfo != null) { |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 104 | userId = UserHandle.getUserId(info.applicationInfo.uid); |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 105 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | } |
Craig Mautner | 2ad9207 | 2013-02-25 16:19:24 -0800 | [diff] [blame] | 107 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 7f96b79 | 2012-05-29 18:46:45 -0700 | [diff] [blame] | 109 | if (numActivities != 0 || rootWasReset || userId != 0) { |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 110 | pw.print(prefix); pw.print("numActivities="); pw.print(numActivities); |
Dianne Hackborn | 7f96b79 | 2012-05-29 18:46:45 -0700 | [diff] [blame] | 111 | pw.print(" rootWasReset="); pw.print(rootWasReset); |
Craig Mautner | 2ad9207 | 2013-02-25 16:19:24 -0800 | [diff] [blame] | 112 | pw.print(" userId="); pw.println(userId); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 113 | } |
| 114 | if (affinity != null) { |
| 115 | pw.print(prefix); pw.print("affinity="); pw.println(affinity); |
| 116 | } |
| 117 | if (intent != null) { |
| 118 | StringBuilder sb = new StringBuilder(128); |
| 119 | sb.append(prefix); sb.append("intent={"); |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 120 | intent.toShortString(sb, false, true, false, true); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 121 | sb.append('}'); |
| 122 | pw.println(sb.toString()); |
| 123 | } |
| 124 | if (affinityIntent != null) { |
| 125 | StringBuilder sb = new StringBuilder(128); |
| 126 | sb.append(prefix); sb.append("affinityIntent={"); |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 127 | affinityIntent.toShortString(sb, false, true, false, true); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 128 | sb.append('}'); |
| 129 | pw.println(sb.toString()); |
| 130 | } |
| 131 | if (origActivity != null) { |
| 132 | pw.print(prefix); pw.print("origActivity="); |
| 133 | pw.println(origActivity.flattenToShortString()); |
| 134 | } |
| 135 | if (realActivity != null) { |
| 136 | pw.print(prefix); pw.print("realActivity="); |
| 137 | pw.println(realActivity.flattenToShortString()); |
| 138 | } |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 139 | if (!askedCompatMode) { |
| 140 | pw.print(prefix); pw.print("askedCompatMode="); pw.println(askedCompatMode); |
| 141 | } |
Dianne Hackborn | cfb9f2b | 2011-08-24 10:51:49 -0700 | [diff] [blame] | 142 | pw.print(prefix); pw.print("lastThumbnail="); pw.print(lastThumbnail); |
| 143 | pw.print(" lastDescription="); pw.println(lastDescription); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 144 | pw.print(prefix); pw.print("lastActiveTime="); pw.print(lastActiveTime); |
| 145 | pw.print(" (inactive for "); |
| 146 | pw.print((getInactiveDuration()/1000)); pw.println("s)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 150 | if (stringName != null) { |
| 151 | return stringName; |
| 152 | } |
| 153 | StringBuilder sb = new StringBuilder(128); |
| 154 | sb.append("TaskRecord{"); |
| 155 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 156 | sb.append(" #"); |
| 157 | sb.append(taskId); |
| 158 | if (affinity != null) { |
Craig Mautner | 2ad9207 | 2013-02-25 16:19:24 -0800 | [diff] [blame] | 159 | sb.append(" A "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 160 | sb.append(affinity); |
| 161 | } else if (intent != null) { |
Craig Mautner | 2ad9207 | 2013-02-25 16:19:24 -0800 | [diff] [blame] | 162 | sb.append(" I "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 163 | sb.append(intent.getComponent().flattenToShortString()); |
| 164 | } else if (affinityIntent != null) { |
Craig Mautner | 2ad9207 | 2013-02-25 16:19:24 -0800 | [diff] [blame] | 165 | sb.append(" aI "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 166 | sb.append(affinityIntent.getComponent().flattenToShortString()); |
| 167 | } else { |
| 168 | sb.append(" ??"); |
| 169 | } |
Craig Mautner | 2ad9207 | 2013-02-25 16:19:24 -0800 | [diff] [blame] | 170 | sb.append(" U "); |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 171 | sb.append(userId); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 172 | sb.append('}'); |
| 173 | return stringName = sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 174 | } |
| 175 | } |