• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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 
17 package com.android.systemui.shared.system;
18 
19 import android.app.ActivityManager.RunningTaskInfo;
20 import android.content.ComponentName;
21 import android.os.IBinder;
22 import android.os.UserHandle;
23 import android.util.Log;
24 
25 import com.android.systemui.shared.recents.model.ThumbnailData;
26 
27 /**
28  * An interface to track task stack changes. Classes should implement this instead of
29  * {@link android.app.ITaskStackListener} to reduce IPC calls from system services.
30  */
31 public abstract class TaskStackChangeListener {
32 
33     // Binder thread callbacks
onTaskStackChangedBackground()34     public void onTaskStackChangedBackground() { }
35 
36     // Main thread callbacks
onTaskStackChanged()37     public void onTaskStackChanged() { }
onTaskSnapshotChanged(int taskId, ThumbnailData snapshot)38     public void onTaskSnapshotChanged(int taskId, ThumbnailData snapshot) { }
onActivityPinned(String packageName, int userId, int taskId, int stackId)39     public void onActivityPinned(String packageName, int userId, int taskId, int stackId) { }
onActivityUnpinned()40     public void onActivityUnpinned() { }
onPinnedActivityRestartAttempt(boolean clearedTask)41     public void onPinnedActivityRestartAttempt(boolean clearedTask) { }
onPinnedStackAnimationStarted()42     public void onPinnedStackAnimationStarted() { }
onPinnedStackAnimationEnded()43     public void onPinnedStackAnimationEnded() { }
onActivityForcedResizable(String packageName, int taskId, int reason)44     public void onActivityForcedResizable(String packageName, int taskId, int reason) { }
onActivityDismissingDockedStack()45     public void onActivityDismissingDockedStack() { }
onActivityLaunchOnSecondaryDisplayFailed()46     public void onActivityLaunchOnSecondaryDisplayFailed() { }
47 
onActivityLaunchOnSecondaryDisplayFailed(RunningTaskInfo taskInfo)48     public void onActivityLaunchOnSecondaryDisplayFailed(RunningTaskInfo taskInfo) {
49         onActivityLaunchOnSecondaryDisplayFailed();
50     }
51 
52     /**
53      * @see #onActivityLaunchOnSecondaryDisplayRerouted(RunningTaskInfo taskInfo)
54      */
onActivityLaunchOnSecondaryDisplayRerouted()55     public void onActivityLaunchOnSecondaryDisplayRerouted() { }
56 
57     /**
58      * Called when an activity was requested to be launched on a secondary display but was rerouted
59      * to default display.
60      *
61      * @param taskInfo info about the Activity's task
62      */
onActivityLaunchOnSecondaryDisplayRerouted(RunningTaskInfo taskInfo)63     public void onActivityLaunchOnSecondaryDisplayRerouted(RunningTaskInfo taskInfo) {
64         onActivityLaunchOnSecondaryDisplayRerouted();
65     }
66 
onTaskProfileLocked(int taskId, int userId)67     public void onTaskProfileLocked(int taskId, int userId) { }
onTaskCreated(int taskId, ComponentName componentName)68     public void onTaskCreated(int taskId, ComponentName componentName) { }
onTaskRemoved(int taskId)69     public void onTaskRemoved(int taskId) { }
onTaskMovedToFront(int taskId)70     public void onTaskMovedToFront(int taskId) { }
71 
onTaskMovedToFront(RunningTaskInfo taskInfo)72     public void onTaskMovedToFront(RunningTaskInfo taskInfo) {
73         onTaskMovedToFront(taskInfo.taskId);
74     }
75 
onActivityRequestedOrientationChanged(int taskId, int requestedOrientation)76     public void onActivityRequestedOrientationChanged(int taskId, int requestedOrientation) { }
onSizeCompatModeActivityChanged(int displayId, IBinder activityToken)77     public void onSizeCompatModeActivityChanged(int displayId, IBinder activityToken) { }
78 
onBackPressedOnTaskRoot(RunningTaskInfo taskInfo)79     public void onBackPressedOnTaskRoot(RunningTaskInfo taskInfo) { }
80 
81     /**
82      * Called when a task is reparented to a stack on a different display.
83      *
84      * @param taskId id of the task which was moved to a different display.
85      * @param newDisplayId id of the new display.
86      */
onTaskDisplayChanged(int taskId, int newDisplayId)87     public void onTaskDisplayChanged(int taskId, int newDisplayId) { }
88 
89     /**
90      * Checks that the current user matches the process. Since
91      * {@link android.app.ITaskStackListener} is not multi-user aware, handlers of
92      * {@link TaskStackChangeListener} should make this call to verify that we don't act on events
93      * originating from another user's interactions.
94      */
checkCurrentUserId(int currentUserId, boolean debug)95     protected final boolean checkCurrentUserId(int currentUserId, boolean debug) {
96         int processUserId = UserHandle.myUserId();
97         if (processUserId != currentUserId) {
98             if (debug) {
99                 Log.d("TaskStackChangeListener", "UID mismatch. Process is uid=" + processUserId
100                         + " and the current user is uid=" + currentUserId);
101             }
102             return false;
103         }
104         return true;
105     }
106 }
107