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