1 /* 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 17 package com.android.systemui.shortcut; 18 19 import android.os.Handler; 20 import android.os.Message; 21 import android.os.RemoteException; 22 23 import 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 */ 29 public 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 { onShortcutKeyPressed(long shortcutCode)37 void onShortcutKeyPressed(long shortcutCode); 38 } 39 ShortcutKeyServiceProxy(Callbacks callbacks)40 public ShortcutKeyServiceProxy(Callbacks callbacks) { mCallbacks = callbacks; } 41 42 @Override notifyShortcutKeyPressed(long shortcutCode)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 { handleMessage(Message msg)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 } 60