blob: 47ec21805638e8861cab10ff22c5dc6be725ae55 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
17package com.android.server.am;
18
19import android.content.ComponentName;
20import android.content.Intent;
21import android.content.pm.ActivityInfo;
Amith Yamasani742a6712011-05-04 14:49:28 -070022import android.content.pm.PackageManager;
Dianne Hackbornd2835932010-12-13 16:28:46 -080023import android.graphics.Bitmap;
Amith Yamasani742a6712011-05-04 14:49:28 -070024import android.os.UserId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025
26import java.io.PrintWriter;
27
Dianne Hackbornf26fd992011-04-08 18:14:09 -070028class TaskRecord extends ThumbnailHolder {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029 final int taskId; // Unique identifier for this task.
30 final String affinity; // The affinity name for this task, or null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031 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 Hackborn36cd41f2011-05-25 21:00:46 -070039 boolean askedCompatMode;// Have asked the user about compat mode for this task.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040
Dianne Hackborn1d442e02009-04-20 18:14:05 -070041 String stringName; // caching of toString() result.
Amith Yamasani742a6712011-05-04 14:49:28 -070042 int userId; // user for which this task was created
Dianne Hackborn1d442e02009-04-20 18:14:05 -070043
Dianne Hackborn621e17d2010-11-22 15:59:56 -080044 TaskRecord(int _taskId, ActivityInfo info, Intent _intent) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045 taskId = _taskId;
46 affinity = info.taskAffinity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047 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 Hackborn1d442e02009-04-20 18:14:05 -070059 stringName = null;
Dianne Hackbornf5b86712011-12-05 17:42:41 -080060
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061 if (info.targetActivity == null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -080062 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 Project9066cfe2009-03-03 19:31:44 -080071 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 Hackbornf5b86712011-12-05 17:42:41 -080080 targetIntent.setSelector(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081 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 Yamasani742a6712011-05-04 14:49:28 -070090
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091 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 Yamasani742a6712011-05-04 14:49:28 -070097
98 if (info.applicationInfo != null) {
99 userId = UserId.getUserId(info.applicationInfo.uid);
100 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101 }
102
103 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800104 if (numActivities != 0 || rootWasReset) {
105 pw.print(prefix); pw.print("numActivities="); pw.print(numActivities);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700106 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 Hackborn90c52de2011-09-23 12:57:44 -0700114 intent.toShortString(sb, false, true, false);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700115 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 Hackborn90c52de2011-09-23 12:57:44 -0700121 affinityIntent.toShortString(sb, false, true, false);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700122 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 Hackborn36cd41f2011-05-25 21:00:46 -0700133 if (!askedCompatMode) {
134 pw.print(prefix); pw.print("askedCompatMode="); pw.println(askedCompatMode);
135 }
Dianne Hackborncfb9f2b2011-08-24 10:51:49 -0700136 pw.print(prefix); pw.print("lastThumbnail="); pw.print(lastThumbnail);
137 pw.print(" lastDescription="); pw.println(lastDescription);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700138 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 Project9066cfe2009-03-03 19:31:44 -0800141 }
142
143 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700144 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 Yamasani742a6712011-05-04 14:49:28 -0700164 sb.append(" U ");
165 sb.append(userId);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700166 sb.append('}');
167 return stringName = sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168 }
169}