• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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.car.displayarea;
18 
19 import android.app.ActivityManager;
20 import android.view.SurfaceControl;
21 
22 import com.android.wm.shell.common.SyncTransactionQueue;
23 import com.android.wm.shell.fullscreen.FullscreenTaskListener;
24 
25 import java.util.ArrayList;
26 import java.util.List;
27 import java.util.Optional;
28 
29 import javax.inject.Inject;
30 
31 /**
32  * Organizes tasks presented in display area using {@link CarDisplayAreaOrganizer}.
33  */
34 public class CarFullscreenTaskListener extends FullscreenTaskListener {
35     // TODO(b/202182129): Introduce more robust way to resolve the intents.
36     static final String MAPS = "maps";
37     private final List<OnTaskChangeListener> mOnTaskChangeListeners;
38 
39     @Inject
CarFullscreenTaskListener(SyncTransactionQueue syncQueue)40     public CarFullscreenTaskListener(SyncTransactionQueue syncQueue) {
41         super(syncQueue);
42         mOnTaskChangeListeners = new ArrayList<>();
43     }
44 
45     @Override
onTaskAppeared(ActivityManager.RunningTaskInfo taskInfo, SurfaceControl leash)46     public void onTaskAppeared(ActivityManager.RunningTaskInfo taskInfo, SurfaceControl leash) {
47         super.onTaskAppeared(taskInfo, leash);
48 
49         for (OnTaskChangeListener listener : mOnTaskChangeListeners) {
50             listener.onTaskAppeared(taskInfo);
51         }
52     }
53 
54     @Override
onTaskVanished(ActivityManager.RunningTaskInfo taskInfo)55     public void onTaskVanished(ActivityManager.RunningTaskInfo taskInfo) {
56         super.onTaskVanished(taskInfo);
57         for (OnTaskChangeListener listener : mOnTaskChangeListeners) {
58             listener.onTaskVanished(taskInfo);
59         }
60     }
61 
62     /**
63      * Register's a {@link OnTaskChangeListener}
64      */
registerOnTaskChangeListener(OnTaskChangeListener listener)65     public void registerOnTaskChangeListener(OnTaskChangeListener listener) {
66         if (listener == null) {
67             throw new RuntimeException("listener cannot be null");
68         }
69         mOnTaskChangeListeners.add(listener);
70     }
71 
72     /**
73      * UnRegister's a {@link OnTaskChangeListener}
74      */
unregisterontaskchangelistener(OnTaskChangeListener listener)75     public boolean unregisterontaskchangelistener(OnTaskChangeListener listener) {
76         if (listener == null) {
77             throw new RuntimeException("listener cannot be null");
78         }
79         return mOnTaskChangeListeners.remove(listener);
80     }
81 
82     /**
83      * Interface to give the information regarding task changes
84      */
85     public interface OnTaskChangeListener {
86         /**
87          * Gives the information of the task that just appeared
88          */
onTaskAppeared(ActivityManager.RunningTaskInfo taskInfo)89         void onTaskAppeared(ActivityManager.RunningTaskInfo taskInfo);
90 
91         /**
92          * Gives the information of the task that just vanished
93          */
onTaskVanished(ActivityManager.RunningTaskInfo taskInfo)94         void onTaskVanished(ActivityManager.RunningTaskInfo taskInfo);
95     }
96 }
97