Home | History | Annotate | Download | only in shortcut
      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 import com.android.internal.policy.IShortcutService;
     23 
     24 /**
     25  * This class takes functions from IShortcutService that come in binder pool threads and
     26  * post them onto shortcut handlers.
     27  */
     28 public class ShortcutKeyServiceProxy extends IShortcutService.Stub {
     29     private static final int MSG_SHORTCUT_RECEIVED = 1;
     30 
     31     private final Object mLock = new Object();
     32     private Callbacks mCallbacks;
     33     private final Handler mHandler = new H();
     34 
     35     public interface Callbacks {
     36         void onShortcutKeyPressed(long shortcutCode);
     37     }
     38 
     39     public ShortcutKeyServiceProxy(Callbacks callbacks) { mCallbacks = callbacks; }
     40 
     41     @Override
     42     public void notifyShortcutKeyPressed(long shortcutCode) throws RemoteException {
     43         synchronized (mLock) {
     44             mHandler.obtainMessage(MSG_SHORTCUT_RECEIVED, shortcutCode).sendToTarget();
     45         }
     46     }
     47 
     48     private final class H extends Handler {
     49         public void handleMessage(Message msg) {
     50             final int what = msg.what;
     51             switch (what) {
     52                 case MSG_SHORTCUT_RECEIVED:
     53                     mCallbacks.onShortcutKeyPressed((Long)msg.obj);
     54                     break;
     55             }
     56         }
     57     }
     58 }
     59