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