blob: 86cec427166e64c370b381de78ab7a7e6b729dc7 [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
26class TaskRecord {
27 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.
Dianne Hackbornd2835932010-12-13 16:28:46 -080037 Bitmap lastThumbnail; // Last thumbnail captured for this task.
38 CharSequence lastDescription; // Last description captured for this task.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039
Dianne Hackborn1d442e02009-04-20 18:14:05 -070040 String stringName; // caching of toString() result.
41
Dianne Hackborn621e17d2010-11-22 15:59:56 -080042 TaskRecord(int _taskId, ActivityInfo info, Intent _intent) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043 taskId = _taskId;
44 affinity = info.taskAffinity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045 setIntent(_intent, info);
46 }
47
48 void touchActiveTime() {
49 lastActiveTime = android.os.SystemClock.elapsedRealtime();
50 }
51
52 long getInactiveDuration() {
53 return android.os.SystemClock.elapsedRealtime() - lastActiveTime;
54 }
55
56 void setIntent(Intent _intent, ActivityInfo info) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070057 stringName = null;
58
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059 if (info.targetActivity == null) {
60 intent = _intent;
61 realActivity = _intent != null ? _intent.getComponent() : null;
62 origActivity = null;
63 } else {
64 ComponentName targetComponent = new ComponentName(
65 info.packageName, info.targetActivity);
66 if (_intent != null) {
67 Intent targetIntent = new Intent(_intent);
68 targetIntent.setComponent(targetComponent);
69 intent = targetIntent;
70 realActivity = targetComponent;
71 origActivity = _intent.getComponent();
72 } else {
73 intent = null;
74 realActivity = targetComponent;
75 origActivity = new ComponentName(info.packageName, info.name);
76 }
77 }
78
79 if (intent != null &&
80 (intent.getFlags()&Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) {
81 // Once we are set to an Intent with this flag, we count this
82 // task as having a true root activity.
83 rootWasReset = true;
84 }
85 }
86
87 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn621e17d2010-11-22 15:59:56 -080088 if (numActivities != 0 || rootWasReset) {
89 pw.print(prefix); pw.print("numActivities="); pw.print(numActivities);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070090 pw.print(" rootWasReset="); pw.println(rootWasReset);
91 }
92 if (affinity != null) {
93 pw.print(prefix); pw.print("affinity="); pw.println(affinity);
94 }
95 if (intent != null) {
96 StringBuilder sb = new StringBuilder(128);
97 sb.append(prefix); sb.append("intent={");
98 intent.toShortString(sb, true, false);
99 sb.append('}');
100 pw.println(sb.toString());
101 }
102 if (affinityIntent != null) {
103 StringBuilder sb = new StringBuilder(128);
104 sb.append(prefix); sb.append("affinityIntent={");
105 affinityIntent.toShortString(sb, true, false);
106 sb.append('}');
107 pw.println(sb.toString());
108 }
109 if (origActivity != null) {
110 pw.print(prefix); pw.print("origActivity=");
111 pw.println(origActivity.flattenToShortString());
112 }
113 if (realActivity != null) {
114 pw.print(prefix); pw.print("realActivity=");
115 pw.println(realActivity.flattenToShortString());
116 }
117 pw.print(prefix); pw.print("lastActiveTime="); pw.print(lastActiveTime);
118 pw.print(" (inactive for ");
119 pw.print((getInactiveDuration()/1000)); pw.println("s)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800120 }
121
122 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700123 if (stringName != null) {
124 return stringName;
125 }
126 StringBuilder sb = new StringBuilder(128);
127 sb.append("TaskRecord{");
128 sb.append(Integer.toHexString(System.identityHashCode(this)));
129 sb.append(" #");
130 sb.append(taskId);
131 if (affinity != null) {
132 sb.append(" A ");
133 sb.append(affinity);
134 } else if (intent != null) {
135 sb.append(" I ");
136 sb.append(intent.getComponent().flattenToShortString());
137 } else if (affinityIntent != null) {
138 sb.append(" aI ");
139 sb.append(affinityIntent.getComponent().flattenToShortString());
140 } else {
141 sb.append(" ??");
142 }
143 sb.append('}');
144 return stringName = sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145 }
146}