blob: 156964ac326dff85d3fcf9295bd140888c8943e9 [file] [log] [blame]
Muyuan Li94ce94e2016-02-24 16:20:54 -08001/*
2 * Copyright (C) 2016 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.shortcut;
18
19import android.os.Handler;
20import android.os.Message;
21import android.os.RemoteException;
Gus Prevasab336792018-11-14 13:52:20 -050022
Muyuan Li94ce94e2016-02-24 16:20:54 -080023import com.android.internal.policy.IShortcutService;
24
25/**
26 * This class takes functions from IShortcutService that come in binder pool threads and
27 * post them onto shortcut handlers.
28 */
29public class ShortcutKeyServiceProxy extends IShortcutService.Stub {
30 private static final int MSG_SHORTCUT_RECEIVED = 1;
31
32 private final Object mLock = new Object();
33 private Callbacks mCallbacks;
34 private final Handler mHandler = new H();
35
36 public interface Callbacks {
37 void onShortcutKeyPressed(long shortcutCode);
38 }
39
40 public ShortcutKeyServiceProxy(Callbacks callbacks) { mCallbacks = callbacks; }
41
42 @Override
43 public void notifyShortcutKeyPressed(long shortcutCode) throws RemoteException {
44 synchronized (mLock) {
45 mHandler.obtainMessage(MSG_SHORTCUT_RECEIVED, shortcutCode).sendToTarget();
46 }
47 }
48
49 private final class H extends Handler {
50 public void handleMessage(Message msg) {
51 final int what = msg.what;
52 switch (what) {
53 case MSG_SHORTCUT_RECEIVED:
54 mCallbacks.onShortcutKeyPressed((Long)msg.obj);
55 break;
56 }
57 }
58 }
59}