1 /*
2  * Copyright (C) 2019 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.car.ui.paintbooth.currentactivity;
18 
19 import android.app.ActivityManager;
20 import android.app.ActivityManager.RunningTaskInfo;
21 import android.app.IActivityTaskManager;
22 import android.content.ComponentName;
23 import android.os.RemoteException;
24 
25 import java.util.HashMap;
26 import java.util.List;
27 import java.util.Map;
28 
29 /**
30  * This class is a wrapper around {@link android.app.ActivityTaskManager} that is excluded from
31  * the gradle and google3 builds.
32  */
33 class ActivityTaskManagerImpl implements ActivityTaskManager {
34 
35     IActivityTaskManager mActivityTaskManager = android.app.ActivityTaskManager.getService();
36 
37     Map<TaskStackListener, android.app.TaskStackListener> mListenerMapping = new HashMap<>();
38 
39     @Override
getTasks(int maxNum)40     public List<RunningTaskInfo> getTasks(int maxNum) throws RemoteException {
41         return mActivityTaskManager.getTasks(maxNum);
42     }
43 
44     @Override
registerTaskStackListener(TaskStackListener listener)45     public void registerTaskStackListener(TaskStackListener listener) throws RemoteException {
46         mListenerMapping.put(listener, new android.app.TaskStackListener() {
47             @Override
48             public void onTaskCreated(int taskId, ComponentName componentName) {
49                 listener.onTaskCreated(taskId, componentName);
50             }
51 
52             @Override
53             public void onTaskRemoved(int taskId) {
54                 listener.onTaskRemoved(taskId);
55             }
56 
57             @Override
58             public void onTaskDescriptionChanged(ActivityManager.RunningTaskInfo taskInfo) {
59                 listener.onTaskDescriptionChanged(taskInfo);
60             }
61 
62             @Override
63             public void onTaskMovedToFront(ActivityManager.RunningTaskInfo taskInfo) {
64                 listener.onTaskMovedToFront(taskInfo);
65             }
66         });
67 
68         mActivityTaskManager.registerTaskStackListener(mListenerMapping.get(listener));
69     }
70 
71     @Override
unregisterTaskStackListener(TaskStackListener listener)72     public void unregisterTaskStackListener(TaskStackListener listener) throws RemoteException {
73         mActivityTaskManager.unregisterTaskStackListener(mListenerMapping.get(listener));
74         mListenerMapping.remove(listener);
75     }
76 
77 }
78