• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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.recents;
18 
19 import android.content.Context;
20 import android.graphics.Rect;
21 import android.os.IBinder;
22 import android.os.RemoteException;
23 import android.util.EventLog;
24 import android.util.Log;
25 import android.util.SparseArray;
26 
27 import com.android.systemui.EventLogConstants;
28 import com.android.systemui.EventLogTags;
29 import com.android.systemui.recents.events.EventBus;
30 import com.android.systemui.recents.events.activity.DockedTopTaskEvent;
31 import com.android.systemui.recents.events.activity.RecentsActivityStartingEvent;
32 import com.android.systemui.recents.events.component.SetWaitingForTransitionStartEvent;
33 import com.android.systemui.recents.events.ui.RecentsDrawnEvent;
34 import com.android.systemui.recents.misc.ForegroundThread;
35 
36 /**
37  * An implementation of the system user's Recents interface to be called remotely by secondary
38  * users.
39  */
40 public class RecentsSystemUser extends IRecentsSystemUserCallbacks.Stub {
41 
42     private static final String TAG = "RecentsSystemUser";
43 
44     private Context mContext;
45     private RecentsImpl mImpl;
46     private final SparseArray<IRecentsNonSystemUserCallbacks> mNonSystemUserRecents =
47             new SparseArray<>();
48 
RecentsSystemUser(Context context, RecentsImpl impl)49     public RecentsSystemUser(Context context, RecentsImpl impl) {
50         mContext = context;
51         mImpl = impl;
52     }
53 
54     @Override
registerNonSystemUserCallbacks(final IBinder nonSystemUserCallbacks, final int userId)55     public void registerNonSystemUserCallbacks(final IBinder nonSystemUserCallbacks,
56             final int userId) {
57         try {
58             final IRecentsNonSystemUserCallbacks callback =
59                     IRecentsNonSystemUserCallbacks.Stub.asInterface(nonSystemUserCallbacks);
60             nonSystemUserCallbacks.linkToDeath(new IBinder.DeathRecipient() {
61                 @Override
62                 public void binderDied() {
63                     mNonSystemUserRecents.removeAt(mNonSystemUserRecents.indexOfValue(callback));
64                     EventLog.writeEvent(EventLogTags.SYSUI_RECENTS_CONNECTION,
65                             EventLogConstants.SYSUI_RECENTS_CONNECTION_SYSTEM_UNREGISTER_USER,
66                             userId);
67                 }
68             }, 0);
69             mNonSystemUserRecents.put(userId, callback);
70             EventLog.writeEvent(EventLogTags.SYSUI_RECENTS_CONNECTION,
71                     EventLogConstants.SYSUI_RECENTS_CONNECTION_SYSTEM_REGISTER_USER, userId);
72         } catch (RemoteException e) {
73             Log.e(TAG, "Failed to register NonSystemUserCallbacks", e);
74         }
75     }
76 
getNonSystemUserRecentsForUser(int userId)77     public IRecentsNonSystemUserCallbacks getNonSystemUserRecentsForUser(int userId) {
78         return mNonSystemUserRecents.get(userId);
79     }
80 
81     @Override
updateRecentsVisibility(boolean visible)82     public void updateRecentsVisibility(boolean visible) {
83         ForegroundThread.getHandler().post(() -> {
84             mImpl.onVisibilityChanged(mContext, visible);
85         });
86     }
87 
88     @Override
startScreenPinning(int taskId)89     public void startScreenPinning(int taskId) {
90         ForegroundThread.getHandler().post(() -> {
91             mImpl.onStartScreenPinning(mContext, taskId);
92         });
93     }
94 
95     @Override
sendRecentsDrawnEvent()96     public void sendRecentsDrawnEvent() {
97         EventBus.getDefault().post(new RecentsDrawnEvent());
98     }
99 
100     @Override
sendDockingTopTaskEvent(int dragMode, Rect initialRect)101     public void sendDockingTopTaskEvent(int dragMode, Rect initialRect) throws RemoteException {
102         EventBus.getDefault().post(new DockedTopTaskEvent(dragMode, initialRect));
103     }
104 
105     @Override
sendLaunchRecentsEvent()106     public void sendLaunchRecentsEvent() throws RemoteException {
107         EventBus.getDefault().post(new RecentsActivityStartingEvent());
108     }
109 
110     @Override
setWaitingForTransitionStartEvent(boolean waitingForTransitionStart)111     public void setWaitingForTransitionStartEvent(boolean waitingForTransitionStart) {
112         EventBus.getDefault().post(new SetWaitingForTransitionStartEvent(
113                 waitingForTransitionStart));
114     }
115 }
116