-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActivityManager.java
More file actions
2991 lines (2666 loc) · 106 KB
/
Copy pathActivityManager.java
File metadata and controls
2991 lines (2666 loc) · 106 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.app;
import android.Manifest;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Point;
import android.os.BatteryStats;
import android.os.IBinder;
import android.os.ParcelFileDescriptor;
import android.util.Log;
import com.android.internal.app.ProcessStats;
import com.android.internal.os.TransferPipe;
import com.android.internal.util.FastPrintWriter;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.ConfigurationInfo;
import android.content.pm.IPackageDataObserver;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.Debug;
import android.os.Handler;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Process;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Size;
import android.util.Slog;
import org.xmlpull.v1.XmlSerializer;
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
/**
* Interact with the overall activities running in the system.
*/
public class ActivityManager {
private static String TAG = "ActivityManager";
private static boolean localLOGV = false;
private static int gMaxRecentTasks = -1;
private final Context mContext;
private final Handler mHandler;
/**
* <a href="{@docRoot}guide/topics/manifest/meta-data-element.html">{@code
* <meta-data>}</a> name for a 'home' Activity that declares a package that is to be
* uninstalled in lieu of the declaring one. The package named here must be
* signed with the same certificate as the one declaring the {@code <meta-data>}.
*/
public static final String META_HOME_ALTERNATE = "android.app.home.alternate";
/**
* Result for IActivityManager.startActivity: trying to start a background user
* activity that shouldn't be displayed for all users.
* @hide
*/
public static final int START_NOT_CURRENT_USER_ACTIVITY = -8;
/**
* Result for IActivityManager.startActivity: trying to start an activity under voice
* control when that activity does not support the VOICE category.
* @hide
*/
public static final int START_NOT_VOICE_COMPATIBLE = -7;
/**
* Result for IActivityManager.startActivity: an error where the
* start had to be canceled.
* @hide
*/
public static final int START_CANCELED = -6;
/**
* Result for IActivityManager.startActivity: an error where the
* thing being started is not an activity.
* @hide
*/
public static final int START_NOT_ACTIVITY = -5;
/**
* Result for IActivityManager.startActivity: an error where the
* caller does not have permission to start the activity.
* @hide
*/
public static final int START_PERMISSION_DENIED = -4;
/**
* Result for IActivityManager.startActivity: an error where the
* caller has requested both to forward a result and to receive
* a result.
* @hide
*/
public static final int START_FORWARD_AND_REQUEST_CONFLICT = -3;
/**
* Result for IActivityManager.startActivity: an error where the
* requested class is not found.
* @hide
*/
public static final int START_CLASS_NOT_FOUND = -2;
/**
* Result for IActivityManager.startActivity: an error where the
* given Intent could not be resolved to an activity.
* @hide
*/
public static final int START_INTENT_NOT_RESOLVED = -1;
/**
* Result for IActivityManaqer.startActivity: the activity was started
* successfully as normal.
* @hide
*/
public static final int START_SUCCESS = 0;
/**
* Result for IActivityManaqer.startActivity: the caller asked that the Intent not
* be executed if it is the recipient, and that is indeed the case.
* @hide
*/
public static final int START_RETURN_INTENT_TO_CALLER = 1;
/**
* Result for IActivityManaqer.startActivity: activity wasn't really started, but
* a task was simply brought to the foreground.
* @hide
*/
public static final int START_TASK_TO_FRONT = 2;
/**
* Result for IActivityManaqer.startActivity: activity wasn't really started, but
* the given Intent was given to the existing top activity.
* @hide
*/
public static final int START_DELIVERED_TO_TOP = 3;
/**
* Result for IActivityManaqer.startActivity: request was canceled because
* app switches are temporarily canceled to ensure the user's last request
* (such as pressing home) is performed.
* @hide
*/
public static final int START_SWITCHES_CANCELED = 4;
/**
* Result for IActivityManaqer.startActivity: a new activity was attempted to be started
* while in Lock Task Mode.
* @hide
*/
public static final int START_RETURN_LOCK_TASK_MODE_VIOLATION = 5;
/**
* Flag for IActivityManaqer.startActivity: do special start mode where
* a new activity is launched only if it is needed.
* @hide
*/
public static final int START_FLAG_ONLY_IF_NEEDED = 1<<0;
/**
* Flag for IActivityManaqer.startActivity: launch the app for
* debugging.
* @hide
*/
public static final int START_FLAG_DEBUG = 1<<1;
/**
* Flag for IActivityManaqer.startActivity: launch the app for
* OpenGL tracing.
* @hide
*/
public static final int START_FLAG_OPENGL_TRACES = 1<<2;
/**
* Result for IActivityManaqer.broadcastIntent: success!
* @hide
*/
public static final int BROADCAST_SUCCESS = 0;
/**
* Result for IActivityManaqer.broadcastIntent: attempt to broadcast
* a sticky intent without appropriate permission.
* @hide
*/
public static final int BROADCAST_STICKY_CANT_HAVE_PERMISSION = -1;
/**
* Result for IActivityManager.broadcastIntent: trying to send a broadcast
* to a stopped user. Fail.
* @hide
*/
public static final int BROADCAST_FAILED_USER_STOPPED = -2;
/**
* Type for IActivityManaqer.getIntentSender: this PendingIntent is
* for a sendBroadcast operation.
* @hide
*/
public static final int INTENT_SENDER_BROADCAST = 1;
/**
* Type for IActivityManaqer.getIntentSender: this PendingIntent is
* for a startActivity operation.
* @hide
*/
public static final int INTENT_SENDER_ACTIVITY = 2;
/**
* Type for IActivityManaqer.getIntentSender: this PendingIntent is
* for an activity result operation.
* @hide
*/
public static final int INTENT_SENDER_ACTIVITY_RESULT = 3;
/**
* Type for IActivityManaqer.getIntentSender: this PendingIntent is
* for a startService operation.
* @hide
*/
public static final int INTENT_SENDER_SERVICE = 4;
/** @hide User operation call: success! */
public static final int USER_OP_SUCCESS = 0;
/** @hide User operation call: given user id is not known. */
public static final int USER_OP_UNKNOWN_USER = -1;
/** @hide User operation call: given user id is the current user, can't be stopped. */
public static final int USER_OP_IS_CURRENT = -2;
/** @hide Process does not exist. */
public static final int PROCESS_STATE_NONEXISTENT = -1;
/** @hide Process is a persistent system process. */
public static final int PROCESS_STATE_PERSISTENT = 0;
/** @hide Process is a persistent system process and is doing UI. */
public static final int PROCESS_STATE_PERSISTENT_UI = 1;
/** @hide Process is hosting the current top activities. Note that this covers
* all activities that are visible to the user. */
public static final int PROCESS_STATE_TOP = 2;
/** @hide Process is hosting a foreground service due to a system binding. */
public static final int PROCESS_STATE_BOUND_FOREGROUND_SERVICE = 3;
/** @hide Process is hosting a foreground service. */
public static final int PROCESS_STATE_FOREGROUND_SERVICE = 4;
/** @hide Same as {@link #PROCESS_STATE_TOP} but while device is sleeping. */
public static final int PROCESS_STATE_TOP_SLEEPING = 5;
/** @hide Process is important to the user, and something they are aware of. */
public static final int PROCESS_STATE_IMPORTANT_FOREGROUND = 6;
/** @hide Process is important to the user, but not something they are aware of. */
public static final int PROCESS_STATE_IMPORTANT_BACKGROUND = 7;
/** @hide Process is in the background running a backup/restore operation. */
public static final int PROCESS_STATE_BACKUP = 8;
/** @hide Process is in the background, but it can't restore its state so we want
* to try to avoid killing it. */
public static final int PROCESS_STATE_HEAVY_WEIGHT = 9;
/** @hide Process is in the background running a service. Unlike oom_adj, this level
* is used for both the normal running in background state and the executing
* operations state. */
public static final int PROCESS_STATE_SERVICE = 10;
/** @hide Process is in the background running a receiver. Note that from the
* perspective of oom_adj receivers run at a higher foreground level, but for our
* prioritization here that is not necessary and putting them below services means
* many fewer changes in some process states as they receive broadcasts. */
public static final int PROCESS_STATE_RECEIVER = 11;
/** @hide Process is in the background but hosts the home activity. */
public static final int PROCESS_STATE_HOME = 12;
/** @hide Process is in the background but hosts the last shown activity. */
public static final int PROCESS_STATE_LAST_ACTIVITY = 13;
/** @hide Process is being cached for later use and contains activities. */
public static final int PROCESS_STATE_CACHED_ACTIVITY = 14;
/** @hide Process is being cached for later use and is a client of another cached
* process that contains activities. */
public static final int PROCESS_STATE_CACHED_ACTIVITY_CLIENT = 15;
/** @hide Process is being cached for later use and is empty. */
public static final int PROCESS_STATE_CACHED_EMPTY = 16;
/** @hide requestType for assist context: only basic information. */
public static final int ASSIST_CONTEXT_BASIC = 0;
/** @hide requestType for assist context: generate full AssistStructure. */
public static final int ASSIST_CONTEXT_FULL = 1;
/**
* Lock task mode is not active.
*/
public static final int LOCK_TASK_MODE_NONE = 0;
/**
* Full lock task mode is active.
*/
public static final int LOCK_TASK_MODE_LOCKED = 1;
/**
* App pinning mode is active.
*/
public static final int LOCK_TASK_MODE_PINNED = 2;
Point mAppTaskThumbnailSize;
/*package*/ ActivityManager(Context context, Handler handler) {
mContext = context;
mHandler = handler;
}
/**
* Screen compatibility mode: the application most always run in
* compatibility mode.
* @hide
*/
public static final int COMPAT_MODE_ALWAYS = -1;
/**
* Screen compatibility mode: the application can never run in
* compatibility mode.
* @hide
*/
public static final int COMPAT_MODE_NEVER = -2;
/**
* Screen compatibility mode: unknown.
* @hide
*/
public static final int COMPAT_MODE_UNKNOWN = -3;
/**
* Screen compatibility mode: the application currently has compatibility
* mode disabled.
* @hide
*/
public static final int COMPAT_MODE_DISABLED = 0;
/**
* Screen compatibility mode: the application currently has compatibility
* mode enabled.
* @hide
*/
public static final int COMPAT_MODE_ENABLED = 1;
/**
* Screen compatibility mode: request to toggle the application's
* compatibility mode.
* @hide
*/
public static final int COMPAT_MODE_TOGGLE = 2;
/** @hide */
public int getFrontActivityScreenCompatMode() {
try {
return ActivityManagerNative.getDefault().getFrontActivityScreenCompatMode();
} catch (RemoteException e) {
// System dead, we will be dead too soon!
return 0;
}
}
/** @hide */
public void setFrontActivityScreenCompatMode(int mode) {
try {
ActivityManagerNative.getDefault().setFrontActivityScreenCompatMode(mode);
} catch (RemoteException e) {
// System dead, we will be dead too soon!
}
}
/** @hide */
public int getPackageScreenCompatMode(String packageName) {
try {
return ActivityManagerNative.getDefault().getPackageScreenCompatMode(packageName);
} catch (RemoteException e) {
// System dead, we will be dead too soon!
return 0;
}
}
/** @hide */
public void setPackageScreenCompatMode(String packageName, int mode) {
try {
ActivityManagerNative.getDefault().setPackageScreenCompatMode(packageName, mode);
} catch (RemoteException e) {
// System dead, we will be dead too soon!
}
}
/** @hide */
public boolean getPackageAskScreenCompat(String packageName) {
try {
return ActivityManagerNative.getDefault().getPackageAskScreenCompat(packageName);
} catch (RemoteException e) {
// System dead, we will be dead too soon!
return false;
}
}
/** @hide */
public void setPackageAskScreenCompat(String packageName, boolean ask) {
try {
ActivityManagerNative.getDefault().setPackageAskScreenCompat(packageName, ask);
} catch (RemoteException e) {
// System dead, we will be dead too soon!
}
}
/**
* Return the approximate per-application memory class of the current
* device. This gives you an idea of how hard a memory limit you should
* impose on your application to let the overall system work best. The
* returned value is in megabytes; the baseline Android memory class is
* 16 (which happens to be the Java heap limit of those devices); some
* device with more memory may return 24 or even higher numbers.
*/
public int getMemoryClass() {
return staticGetMemoryClass();
}
/** @hide */
static public int staticGetMemoryClass() {
// Really brain dead right now -- just take this from the configured
// vm heap size, and assume it is in megabytes and thus ends with "m".
String vmHeapSize = SystemProperties.get("dalvik.vm.heapgrowthlimit", "");
if (vmHeapSize != null && !"".equals(vmHeapSize)) {
return Integer.parseInt(vmHeapSize.substring(0, vmHeapSize.length()-1));
}
return staticGetLargeMemoryClass();
}
/**
* Return the approximate per-application memory class of the current
* device when an application is running with a large heap. This is the
* space available for memory-intensive applications; most applications
* should not need this amount of memory, and should instead stay with the
* {@link #getMemoryClass()} limit. The returned value is in megabytes.
* This may be the same size as {@link #getMemoryClass()} on memory
* constrained devices, or it may be significantly larger on devices with
* a large amount of available RAM.
*
* <p>The is the size of the application's Dalvik heap if it has
* specified <code>android:largeHeap="true"</code> in its manifest.
*/
public int getLargeMemoryClass() {
return staticGetLargeMemoryClass();
}
/** @hide */
static public int staticGetLargeMemoryClass() {
// Really brain dead right now -- just take this from the configured
// vm heap size, and assume it is in megabytes and thus ends with "m".
String vmHeapSize = SystemProperties.get("dalvik.vm.heapsize", "16m");
return Integer.parseInt(vmHeapSize.substring(0, vmHeapSize.length() - 1));
}
/**
* Returns true if this is a low-RAM device. Exactly whether a device is low-RAM
* is ultimately up to the device configuration, but currently it generally means
* something in the class of a 512MB device with about a 800x480 or less screen.
* This is mostly intended to be used by apps to determine whether they should turn
* off certain features that require more RAM.
*/
public boolean isLowRamDevice() {
return isLowRamDeviceStatic();
}
/** @hide */
public static boolean isLowRamDeviceStatic() {
return "true".equals(SystemProperties.get("ro.config.low_ram", "false"));
}
/**
* Used by persistent processes to determine if they are running on a
* higher-end device so should be okay using hardware drawing acceleration
* (which tends to consume a lot more RAM).
* @hide
*/
static public boolean isHighEndGfx() {
return !isLowRamDeviceStatic() &&
!Resources.getSystem().getBoolean(com.android.internal.R.bool.config_avoidGfxAccel);
}
/**
* Return the maximum number of recents entries that we will maintain and show.
* @hide
*/
static public int getMaxRecentTasksStatic() {
if (gMaxRecentTasks < 0) {
return gMaxRecentTasks = isLowRamDeviceStatic() ? 50 : 100;
}
return gMaxRecentTasks;
}
/**
* Return the default limit on the number of recents that an app can make.
* @hide
*/
static public int getDefaultAppRecentsLimitStatic() {
return getMaxRecentTasksStatic() / 6;
}
/**
* Return the maximum limit on the number of recents that an app can make.
* @hide
*/
static public int getMaxAppRecentsLimitStatic() {
return getMaxRecentTasksStatic() / 2;
}
/**
* Information you can set and retrieve about the current activity within the recent task list.
*/
public static class TaskDescription implements Parcelable {
/** @hide */
public static final String ATTR_TASKDESCRIPTION_PREFIX = "task_description_";
private static final String ATTR_TASKDESCRIPTIONLABEL =
ATTR_TASKDESCRIPTION_PREFIX + "label";
private static final String ATTR_TASKDESCRIPTIONCOLOR =
ATTR_TASKDESCRIPTION_PREFIX + "color";
private static final String ATTR_TASKDESCRIPTIONICONFILENAME =
ATTR_TASKDESCRIPTION_PREFIX + "icon_filename";
private String mLabel;
private Bitmap mIcon;
private String mIconFilename;
private int mColorPrimary;
/**
* Creates the TaskDescription to the specified values.
*
* @param label A label and description of the current state of this task.
* @param icon An icon that represents the current state of this task.
* @param colorPrimary A color to override the theme's primary color. This color must be opaque.
*/
public TaskDescription(String label, Bitmap icon, int colorPrimary) {
if ((colorPrimary != 0) && (Color.alpha(colorPrimary) != 255)) {
throw new RuntimeException("A TaskDescription's primary color should be opaque");
}
mLabel = label;
mIcon = icon;
mColorPrimary = colorPrimary;
}
/** @hide */
public TaskDescription(String label, int colorPrimary, String iconFilename) {
this(label, null, colorPrimary);
mIconFilename = iconFilename;
}
/**
* Creates the TaskDescription to the specified values.
*
* @param label A label and description of the current state of this activity.
* @param icon An icon that represents the current state of this activity.
*/
public TaskDescription(String label, Bitmap icon) {
this(label, icon, 0);
}
/**
* Creates the TaskDescription to the specified values.
*
* @param label A label and description of the current state of this activity.
*/
public TaskDescription(String label) {
this(label, null, 0);
}
/**
* Creates an empty TaskDescription.
*/
public TaskDescription() {
this(null, null, 0);
}
/**
* Creates a copy of another TaskDescription.
*/
public TaskDescription(TaskDescription td) {
mLabel = td.mLabel;
mIcon = td.mIcon;
mColorPrimary = td.mColorPrimary;
mIconFilename = td.mIconFilename;
}
private TaskDescription(Parcel source) {
readFromParcel(source);
}
/**
* Sets the label for this task description.
* @hide
*/
public void setLabel(String label) {
mLabel = label;
}
/**
* Sets the primary color for this task description.
* @hide
*/
public void setPrimaryColor(int primaryColor) {
// Ensure that the given color is valid
if ((primaryColor != 0) && (Color.alpha(primaryColor) != 255)) {
throw new RuntimeException("A TaskDescription's primary color should be opaque");
}
mColorPrimary = primaryColor;
}
/**
* Sets the icon for this task description.
* @hide
*/
public void setIcon(Bitmap icon) {
mIcon = icon;
}
/**
* Moves the icon bitmap reference from an actual Bitmap to a file containing the
* bitmap.
* @hide
*/
public void setIconFilename(String iconFilename) {
mIconFilename = iconFilename;
mIcon = null;
}
/**
* @return The label and description of the current state of this task.
*/
public String getLabel() {
return mLabel;
}
/**
* @return The icon that represents the current state of this task.
*/
public Bitmap getIcon() {
if (mIcon != null) {
return mIcon;
}
return loadTaskDescriptionIcon(mIconFilename);
}
/** @hide */
public String getIconFilename() {
return mIconFilename;
}
/** @hide */
public Bitmap getInMemoryIcon() {
return mIcon;
}
/** @hide */
public static Bitmap loadTaskDescriptionIcon(String iconFilename) {
if (iconFilename != null) {
try {
return ActivityManagerNative.getDefault().
getTaskDescriptionIcon(iconFilename);
} catch (RemoteException e) {
}
}
return null;
}
/**
* @return The color override on the theme's primary color.
*/
public int getPrimaryColor() {
return mColorPrimary;
}
/** @hide */
public void saveToXml(XmlSerializer out) throws IOException {
if (mLabel != null) {
out.attribute(null, ATTR_TASKDESCRIPTIONLABEL, mLabel);
}
if (mColorPrimary != 0) {
out.attribute(null, ATTR_TASKDESCRIPTIONCOLOR, Integer.toHexString(mColorPrimary));
}
if (mIconFilename != null) {
out.attribute(null, ATTR_TASKDESCRIPTIONICONFILENAME, mIconFilename);
}
}
/** @hide */
public void restoreFromXml(String attrName, String attrValue) {
if (ATTR_TASKDESCRIPTIONLABEL.equals(attrName)) {
setLabel(attrValue);
} else if (ATTR_TASKDESCRIPTIONCOLOR.equals(attrName)) {
setPrimaryColor((int) Long.parseLong(attrValue, 16));
} else if (ATTR_TASKDESCRIPTIONICONFILENAME.equals(attrName)) {
setIconFilename(attrValue);
}
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
if (mLabel == null) {
dest.writeInt(0);
} else {
dest.writeInt(1);
dest.writeString(mLabel);
}
if (mIcon == null) {
dest.writeInt(0);
} else {
dest.writeInt(1);
mIcon.writeToParcel(dest, 0);
}
dest.writeInt(mColorPrimary);
if (mIconFilename == null) {
dest.writeInt(0);
} else {
dest.writeInt(1);
dest.writeString(mIconFilename);
}
}
public void readFromParcel(Parcel source) {
mLabel = source.readInt() > 0 ? source.readString() : null;
mIcon = source.readInt() > 0 ? Bitmap.CREATOR.createFromParcel(source) : null;
mColorPrimary = source.readInt();
mIconFilename = source.readInt() > 0 ? source.readString() : null;
}
public static final Creator<TaskDescription> CREATOR
= new Creator<TaskDescription>() {
public TaskDescription createFromParcel(Parcel source) {
return new TaskDescription(source);
}
public TaskDescription[] newArray(int size) {
return new TaskDescription[size];
}
};
@Override
public String toString() {
return "TaskDescription Label: " + mLabel + " Icon: " + mIcon +
" colorPrimary: " + mColorPrimary;
}
}
/**
* Information you can retrieve about tasks that the user has most recently
* started or visited.
*/
public static class RecentTaskInfo implements Parcelable {
/**
* If this task is currently running, this is the identifier for it.
* If it is not running, this will be -1.
*/
public int id;
/**
* The true identifier of this task, valid even if it is not running.
*/
public int persistentId;
/**
* The original Intent used to launch the task. You can use this
* Intent to re-launch the task (if it is no longer running) or bring
* the current task to the front.
*/
public Intent baseIntent;
/**
* If this task was started from an alias, this is the actual
* activity component that was initially started; the component of
* the baseIntent in this case is the name of the actual activity
* implementation that the alias referred to. Otherwise, this is null.
*/
public ComponentName origActivity;
/**
* Description of the task's last state.
*/
public CharSequence description;
/**
* The id of the ActivityStack this Task was on most recently.
* @hide
*/
public int stackId;
/**
* The id of the user the task was running as.
* @hide
*/
public int userId;
/**
* The first time this task was active.
* @hide
*/
public long firstActiveTime;
/**
* The last time this task was active.
* @hide
*/
public long lastActiveTime;
/**
* The recent activity values for the highest activity in the stack to have set the values.
* {@link Activity#setTaskDescription(android.app.ActivityManager.TaskDescription)}.
*/
public TaskDescription taskDescription;
/**
* Task affiliation for grouping with other tasks.
*/
public int affiliatedTaskId;
/**
* Task affiliation color of the source task with the affiliated task id.
*
* @hide
*/
public int affiliatedTaskColor;
/**
* The component launched as the first activity in the task.
* This can be considered the "application" of this task.
*/
public ComponentName baseActivity;
/**
* The activity component at the top of the history stack of the task.
* This is what the user is currently doing.
*/
public ComponentName topActivity;
/**
* Number of activities in this task.
*/
public int numActivities;
public RecentTaskInfo() {
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(id);
dest.writeInt(persistentId);
if (baseIntent != null) {
dest.writeInt(1);
baseIntent.writeToParcel(dest, 0);
} else {
dest.writeInt(0);
}
ComponentName.writeToParcel(origActivity, dest);
TextUtils.writeToParcel(description, dest,
Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
if (taskDescription != null) {
dest.writeInt(1);
taskDescription.writeToParcel(dest, 0);
} else {
dest.writeInt(0);
}
dest.writeInt(stackId);
dest.writeInt(userId);
dest.writeLong(firstActiveTime);
dest.writeLong(lastActiveTime);
dest.writeInt(affiliatedTaskId);
dest.writeInt(affiliatedTaskColor);
ComponentName.writeToParcel(baseActivity, dest);
ComponentName.writeToParcel(topActivity, dest);
dest.writeInt(numActivities);
}
public void readFromParcel(Parcel source) {
id = source.readInt();
persistentId = source.readInt();
baseIntent = source.readInt() > 0 ? Intent.CREATOR.createFromParcel(source) : null;
origActivity = ComponentName.readFromParcel(source);
description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
taskDescription = source.readInt() > 0 ?
TaskDescription.CREATOR.createFromParcel(source) : null;
stackId = source.readInt();
userId = source.readInt();
firstActiveTime = source.readLong();
lastActiveTime = source.readLong();
affiliatedTaskId = source.readInt();
affiliatedTaskColor = source.readInt();
baseActivity = ComponentName.readFromParcel(source);
topActivity = ComponentName.readFromParcel(source);
numActivities = source.readInt();
}
public static final Creator<RecentTaskInfo> CREATOR
= new Creator<RecentTaskInfo>() {
public RecentTaskInfo createFromParcel(Parcel source) {
return new RecentTaskInfo(source);
}
public RecentTaskInfo[] newArray(int size) {
return new RecentTaskInfo[size];
}
};
private RecentTaskInfo(Parcel source) {
readFromParcel(source);
}
}
/**
* Flag for use with {@link #getRecentTasks}: return all tasks, even those
* that have set their
* {@link android.content.Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} flag.
*/
public static final int RECENT_WITH_EXCLUDED = 0x0001;
/**
* Provides a list that does not contain any
* recent tasks that currently are not available to the user.
*/
public static final int RECENT_IGNORE_UNAVAILABLE = 0x0002;
/**
* Provides a list that contains recent tasks for all
* profiles of a user.
* @hide
*/
public static final int RECENT_INCLUDE_PROFILES = 0x0004;
/**
* Ignores all tasks that are on the home stack.
* @hide
*/
public static final int RECENT_IGNORE_HOME_STACK_TASKS = 0x0008;
/**
* <p></p>Return a list of the tasks that the user has recently launched, with
* the most recent being first and older ones after in order.
*
* <p><b>Note: this method is only intended for debugging and presenting
* task management user interfaces</b>. This should never be used for
* core logic in an application, such as deciding between different
* behaviors based on the information found here. Such uses are