blob: 1bae9ca53adf21b82e0e89c4940f98892ddc2ded [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 Hackbornf02b60a2012-08-16 10:48:27 -070022import android.os.UserHandle;
Dianne Hackborn7f96b792012-05-29 18:46:45 -070023import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024
25import java.io.PrintWriter;
26
Dianne Hackbornf26fd992011-04-08 18:14:09 -070027class TaskRecord extends ThumbnailHolder {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028 final int taskId; // Unique identifier for this task.
29 final String affinity; // The affinity name for this task, or null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030 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 Hackborn36cd41f2011-05-25 21:00:46 -070038 boolean askedCompatMode;// Have asked the user about compat mode 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.
Dianne Hackborn9da2d402012-03-15 13:43:08 -070041 int userId; // user for which this task was created
Craig Mautner2ad92072013-02-25 16:19:24 -080042
Dianne Hackborn621e17d2010-11-22 15:59:56 -080043 TaskRecord(int _taskId, ActivityInfo info, Intent _intent) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044 taskId = _taskId;
45 affinity = info.taskAffinity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046 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 Hackborn1d442e02009-04-20 18:14:05 -070058 stringName = null;
Dianne Hackbornf5b86712011-12-05 17:42:41 -080059
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060 if (info.targetActivity == null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -080061 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 Hackbornd367ca82012-05-07 15:49:39 -070065 if (_intent.getSelector() != null || _intent.getSourceBounds() != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -080066 _intent = new Intent(_intent);
67 _intent.setSelector(null);
Dianne Hackbornd367ca82012-05-07 15:49:39 -070068 _intent.setSourceBounds(null);
Dianne Hackbornf5b86712011-12-05 17:42:41 -080069 }
70 }
Dianne Hackborn7f96b792012-05-29 18:46:45 -070071 if (ActivityManagerService.DEBUG_TASKS) Slog.v(ActivityManagerService.TAG,
72 "Setting Intent of " + this + " to " + _intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073 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 Hackbornf5b86712011-12-05 17:42:41 -080082 targetIntent.setSelector(null);
Dianne Hackbornd367ca82012-05-07 15:49:39 -070083 targetIntent.setSourceBounds(null);
Dianne Hackborn7f96b792012-05-29 18:46:45 -070084 if (ActivityManagerService.DEBUG_TASKS) Slog.v(ActivityManagerService.TAG,
85 "Setting Intent of " + this + " to target " + targetIntent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086 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 Yamasani742a6712011-05-04 14:49:28 -070095
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096 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 Yamasani742a6712011-05-04 14:49:28 -0700102
103 if (info.applicationInfo != null) {
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700104 userId = UserHandle.getUserId(info.applicationInfo.uid);
Amith Yamasani742a6712011-05-04 14:49:28 -0700105 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106 }
Craig Mautner2ad92072013-02-25 16:19:24 -0800107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn7f96b792012-05-29 18:46:45 -0700109 if (numActivities != 0 || rootWasReset || userId != 0) {
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800110 pw.print(prefix); pw.print("numActivities="); pw.print(numActivities);
Dianne Hackborn7f96b792012-05-29 18:46:45 -0700111 pw.print(" rootWasReset="); pw.print(rootWasReset);
Craig Mautner2ad92072013-02-25 16:19:24 -0800112 pw.print(" userId="); pw.println(userId);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700113 }
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 Hackborn21c241e2012-03-08 13:57:23 -0800120 intent.toShortString(sb, false, true, false, true);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700121 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 Hackborn21c241e2012-03-08 13:57:23 -0800127 affinityIntent.toShortString(sb, false, true, false, true);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700128 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 Hackborn36cd41f2011-05-25 21:00:46 -0700139 if (!askedCompatMode) {
140 pw.print(prefix); pw.print("askedCompatMode="); pw.println(askedCompatMode);
141 }
Dianne Hackborncfb9f2b2011-08-24 10:51:49 -0700142 pw.print(prefix); pw.print("lastThumbnail="); pw.print(lastThumbnail);
143 pw.print(" lastDescription="); pw.println(lastDescription);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700144 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 Project9066cfe2009-03-03 19:31:44 -0800147 }
148
149 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700150 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 Mautner2ad92072013-02-25 16:19:24 -0800159 sb.append(" A ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700160 sb.append(affinity);
161 } else if (intent != null) {
Craig Mautner2ad92072013-02-25 16:19:24 -0800162 sb.append(" I ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700163 sb.append(intent.getComponent().flattenToShortString());
164 } else if (affinityIntent != null) {
Craig Mautner2ad92072013-02-25 16:19:24 -0800165 sb.append(" aI ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700166 sb.append(affinityIntent.getComponent().flattenToShortString());
167 } else {
168 sb.append(" ??");
169 }
Craig Mautner2ad92072013-02-25 16:19:24 -0800170 sb.append(" U ");
Amith Yamasani742a6712011-05-04 14:49:28 -0700171 sb.append(userId);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700172 sb.append('}');
173 return stringName = sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174 }
175}