RecentsSystemUser.java revision 190fe3bf88388fcb109af64571e3baa0d01f1c37
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
17package com.android.systemui.recents;
18
19import android.content.Context;
20import android.os.IBinder;
21import android.os.RemoteException;
22import android.util.Log;
23import android.util.SparseArray;
24
25/**
26 * An implementation of the system user's Recents interface to be called remotely by secondary
27 * users.
28 */
29public class RecentsSystemUser extends IRecentsSystemUserCallbacks.Stub {
30
31    private static final String TAG = "RecentsSystemUser";
32
33    private Context mContext;
34    private RecentsImpl mImpl;
35    private final SparseArray<IRecentsNonSystemUserCallbacks> mNonSystemUserRecents =
36            new SparseArray<>();
37
38    public RecentsSystemUser(Context context, RecentsImpl impl) {
39        mContext = context;
40        mImpl = impl;
41    }
42
43    @Override
44    public void registerNonSystemUserCallbacks(final IBinder nonSystemUserCallbacks, int userId) {
45        try {
46            final IRecentsNonSystemUserCallbacks callback =
47                    IRecentsNonSystemUserCallbacks.Stub.asInterface(nonSystemUserCallbacks);
48            nonSystemUserCallbacks.linkToDeath(new IBinder.DeathRecipient() {
49                @Override
50                public void binderDied() {
51                    mNonSystemUserRecents.removeAt(mNonSystemUserRecents.indexOfValue(callback));
52                }
53            }, 0);
54            mNonSystemUserRecents.put(userId, callback);
55        } catch (RemoteException e) {
56            Log.e(TAG, "Failed to register NonSystemUserCallbacks", e);
57        }
58    }
59
60    public IRecentsNonSystemUserCallbacks getNonSystemUserRecentsForUser(int userId) {
61        return mNonSystemUserRecents.get(userId);
62    }
63
64    @Override
65    public void updateRecentsVisibility(boolean visible) {
66        mImpl.onVisibilityChanged(mContext, visible);
67    }
68
69    @Override
70    public void startScreenPinning() {
71        mImpl.onStartScreenPinning(mContext);
72    }
73}
74