blob: e8c87e130ea8135022e43faa17757bf2a3431228 [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;
Dianne Hackbornd2835932010-12-13 16:28:46 -080022import android.graphics.Bitmap;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023
24import java.io.PrintWriter;
25
Dianne Hackbornf26fd992011-04-08 18:14:09 -070026class TaskRecord extends ThumbnailHolder {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027 final int taskId; // Unique identifier for this task.
28 final String affinity; // The affinity name for this task, or null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029 Intent intent; // The original intent that started the task.
30 Intent affinityIntent; // Intent of affinity-moved activity that started this task.
31 ComponentName origActivity; // The non-alias activity component of the intent.
32 ComponentName realActivity; // The actual activity component that started the task.
33 int numActivities; // Current number of activities in this task.
34 long lastActiveTime; // Last time this task was active, including sleep.
35 boolean rootWasReset; // True if the intent at the root of the task had
36 // the FLAG_ACTIVITY_RESET_TASK_IF_NEEDED flag.
37
Dianne Hackborn1d442e02009-04-20 18:14:05 -070038 String stringName; // caching of toString() result.
39
Dianne Hackborn621e17d2010-11-22 15:59:56 -080040 TaskRecord(int _taskId, ActivityInfo info, Intent _intent) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041 taskId = _taskId;
42 affinity = info.taskAffinity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043 setIntent(_intent, info);
44 }
45
46 void touchActiveTime() {
47 lastActiveTime = android.os.SystemClock.elapsedRealtime();
48 }
49
50 long getInactiveDuration() {
51 return android.os.SystemClock.elapsedRealtime() - lastActiveTime;
52 }
53
54 void setIntent(Intent _intent, ActivityInfo info) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070055 stringName = null;
56
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057 if (info.targetActivity == null) {
58 intent = _intent;
59 realActivity = _intent != null ? _intent.getComponent() : null;
60 origActivity = null;
61 } else {
62 ComponentName targetComponent = new ComponentName(
63 info.packageName, info.targetActivity);
64 if (_intent != null) {
65 Intent targetIntent = new Intent(_intent);
66 targetIntent.setComponent(targetComponent);
67 intent = targetIntent;
68 realActivity = targetComponent;
69 origActivity = _intent.getComponent();
70 } else {
71 intent = null;
72 realActivity = targetComponent;
73 origActivity = new ComponentName(info.packageName, info.name);
74 }
75 }
76
77 if (intent != null &&
78 (intent.getFlags()&Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) {
79 // Once we are set to an Intent with this flag, we count this
80 // task as having a true root activity.
81 rootWasReset = true;
82 }
83 }
84
85 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn621e17d2010-11-22 15:59:56 -080086 if (numActivities != 0 || rootWasReset) {
87 pw.print(prefix); pw.print("numActivities="); pw.print(numActivities);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070088 pw.print(" rootWasReset="); pw.println(rootWasReset);
89 }
90 if (affinity != null) {
91 pw.print(prefix); pw.print("affinity="); pw.println(affinity);
92 }
93 if (intent != null) {
94 StringBuilder sb = new StringBuilder(128);
95 sb.append(prefix); sb.append("intent={");
96 intent.toShortString(sb, true, false);
97 sb.append('}');
98 pw.println(sb.toString());
99 }
100 if (affinityIntent != null) {
101 StringBuilder sb = new StringBuilder(128);
102 sb.append(prefix); sb.append("affinityIntent={");
103 affinityIntent.toShortString(sb, true, false);
104 sb.append('}');
105 pw.println(sb.toString());
106 }
107 if (origActivity != null) {
108 pw.print(prefix); pw.print("origActivity=");
109 pw.println(origActivity.flattenToShortString());
110 }
111 if (realActivity != null) {
112 pw.print(prefix); pw.print("realActivity=");
113 pw.println(realActivity.flattenToShortString());
114 }
115 pw.print(prefix); pw.print("lastActiveTime="); pw.print(lastActiveTime);
116 pw.print(" (inactive for ");
117 pw.print((getInactiveDuration()/1000)); pw.println("s)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800118 }
119
120 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700121 if (stringName != null) {
122 return stringName;
123 }
124 StringBuilder sb = new StringBuilder(128);
125 sb.append("TaskRecord{");
126 sb.append(Integer.toHexString(System.identityHashCode(this)));
127 sb.append(" #");
128 sb.append(taskId);
129 if (affinity != null) {
130 sb.append(" A ");
131 sb.append(affinity);
132 } else if (intent != null) {
133 sb.append(" I ");
134 sb.append(intent.getComponent().flattenToShortString());
135 } else if (affinityIntent != null) {
136 sb.append(" aI ");
137 sb.append(affinityIntent.getComponent().flattenToShortString());
138 } else {
139 sb.append(" ??");
140 }
141 sb.append('}');
142 return stringName = sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800143 }
144}