1 // 2 // Copyright (C) 2015 Google, Inc. 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 #pragma once 18 19 #include <base/macros.h> 20 #include <binder/IBinder.h> 21 #include <binder/IInterface.h> 22 23 #include <bluetooth/adapter_state.h> 24 25 namespace ipc { 26 namespace binder { 27 28 // This class defines the Binder IPC interface for receiving adapter state 29 // updates from the Bluetooth service. This class was written based on the 30 // corresponding AIDL file at 31 // /frameworks/base/core/java/android/bluetooth/IBluetoothCallback.aidl. 32 // 33 // NOTE: KEEP THIS FILE UP-TO-DATE with the corresponding AIDL, otherwise this 34 // won't be compatible with the Android framework. 35 class IBluetoothCallback : public android::IInterface { 36 public: 37 DECLARE_META_INTERFACE(BluetoothCallback); 38 39 static const char kServiceName[]; 40 41 // Transaction codes for interface methods. 42 enum { 43 ON_BLUETOOTH_STATE_CHANGE_TRANSACTION = 44 android::IBinder::FIRST_CALL_TRANSACTION, 45 }; 46 47 virtual void OnBluetoothStateChange( 48 bluetooth::AdapterState prev_state, 49 bluetooth::AdapterState new_state) = 0; 50 51 private: 52 DISALLOW_COPY_AND_ASSIGN(IBluetoothCallback); 53 }; 54 55 // TODO(armansito): Implement notification for when the process dies. 56 57 // The Binder server interface to IBluetoothCallback. A class that implements 58 // IBluetoothCallback must inherit from this class. 59 class BnBluetoothCallback : public android::BnInterface<IBluetoothCallback> { 60 public: 61 BnBluetoothCallback() = default; 62 virtual ~BnBluetoothCallback() = default; 63 64 private: 65 virtual android::status_t onTransact( 66 uint32_t code, 67 const android::Parcel& data, 68 android::Parcel* reply, 69 uint32_t flags = 0); 70 }; 71 72 // The Binder client interface to IBluetoothCallback. 73 class BpBluetoothCallback : public android::BpInterface<IBluetoothCallback> { 74 public: 75 BpBluetoothCallback(const android::sp<android::IBinder>& impl); 76 virtual ~BpBluetoothCallback() = default; 77 78 // IBluetoothCallback override: 79 void OnBluetoothStateChange(bluetooth::AdapterState prev_state, 80 bluetooth::AdapterState new_state) override; 81 82 private: 83 DISALLOW_COPY_AND_ASSIGN(BpBluetoothCallback); 84 }; 85 86 } // namespace binder 87 } // namespace ipc 88