blob: aab37367bfd3940cc6e7cbc44ba77befd8531c2c [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;
22import android.os.SystemClock;
23
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.
29 final boolean clearOnBackground; // As per the original activity.
30 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.
38
39 TaskRecord(int _taskId, ActivityInfo info, Intent _intent,
40 boolean _clearOnBackground) {
41 taskId = _taskId;
42 affinity = info.taskAffinity;
43 clearOnBackground = _clearOnBackground;
44 setIntent(_intent, info);
45 }
46
47 void touchActiveTime() {
48 lastActiveTime = android.os.SystemClock.elapsedRealtime();
49 }
50
51 long getInactiveDuration() {
52 return android.os.SystemClock.elapsedRealtime() - lastActiveTime;
53 }
54
55 void setIntent(Intent _intent, ActivityInfo info) {
56 if (info.targetActivity == null) {
57 intent = _intent;
58 realActivity = _intent != null ? _intent.getComponent() : null;
59 origActivity = null;
60 } else {
61 ComponentName targetComponent = new ComponentName(
62 info.packageName, info.targetActivity);
63 if (_intent != null) {
64 Intent targetIntent = new Intent(_intent);
65 targetIntent.setComponent(targetComponent);
66 intent = targetIntent;
67 realActivity = targetComponent;
68 origActivity = _intent.getComponent();
69 } else {
70 intent = null;
71 realActivity = targetComponent;
72 origActivity = new ComponentName(info.packageName, info.name);
73 }
74 }
75
76 if (intent != null &&
77 (intent.getFlags()&Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) {
78 // Once we are set to an Intent with this flag, we count this
79 // task as having a true root activity.
80 rootWasReset = true;
81 }
82 }
83
84 void dump(PrintWriter pw, String prefix) {
85 pw.println(prefix + this);
86 pw.println(prefix + "clearOnBackground=" + clearOnBackground
87 + " numActivities=" + numActivities
88 + " rootWasReset=" + rootWasReset);
89 pw.println(prefix + "affinity=" + affinity);
90 pw.println(prefix + "intent=" + intent);
91 pw.println(prefix + "affinityIntent=" + affinityIntent);
92 pw.println(prefix + "origActivity=" + origActivity);
93 pw.println(prefix + "lastActiveTime=" + lastActiveTime
94 +" (inactive for " + (getInactiveDuration()/1000) + "s)");
95 }
96
97 public String toString() {
98 return "Task{" + taskId + " "
99 + (affinity != null ? affinity
100 : (intent != null ? intent.getComponent().flattenToShortString()
101 : affinityIntent != null ? affinityIntent.getComponent().flattenToShortString() : "??"))
102 + "}";
103 }
104}