JniCallbacks.java revision b5cc776c9353a203cdde97e62b25f05d9633d14c
1/* 2 * Copyright (C) 2012 Google Inc. 3 */ 4 5package com.android.bluetooth.btservice; 6 7final class JniCallbacks { 8 9 private static JniCallbacks sInstance; 10 private RemoteDevices mRemoteDevices; 11 private AdapterProperties mAdapterProperties; 12 private AdapterState mAdapterStateMachine; 13 private BondStateMachine mBondStateMachine; 14 15 private JniCallbacks(RemoteDevices remoteDevices, AdapterProperties adapterProperties, 16 AdapterState adapterStateMachine, BondStateMachine bondStateMachine) { 17 mRemoteDevices = remoteDevices; 18 mAdapterProperties = adapterProperties; 19 mAdapterStateMachine = adapterStateMachine; 20 mBondStateMachine = bondStateMachine; 21 } 22 23 static synchronized JniCallbacks getInstance(RemoteDevices remoteDevices, 24 AdapterProperties adapterProperties, AdapterState adapterStateMachine, 25 BondStateMachine bondStateMachine) { 26 if (sInstance == null) { 27 sInstance = 28 new JniCallbacks(remoteDevices, adapterProperties, adapterStateMachine, 29 bondStateMachine); 30 } else { 31 sInstance.mRemoteDevices = remoteDevices; 32 sInstance.mAdapterProperties = adapterProperties; 33 sInstance.mAdapterStateMachine = adapterStateMachine; 34 sInstance.mBondStateMachine = bondStateMachine; 35 } 36 return sInstance; 37 } 38 public Object Clone() throws CloneNotSupportedException { 39 throw new CloneNotSupportedException(); 40 } 41 42 void sspRequestCallback(byte[] address, byte[] name, int cod, int pairingVariant, 43 int passkey) { 44 mRemoteDevices.sspRequestCallback(address, name, cod, pairingVariant, 45 passkey); 46 } 47 void devicePropertyChangedCallback(byte[] address, int[] types, byte[][] val) { 48 mRemoteDevices.devicePropertyChangedCallback(address, types, val); 49 } 50 51 void deviceFoundCallback(byte[] address) { 52 mRemoteDevices.deviceFoundCallback(address); 53 } 54 55 void pinRequestCallback(byte[] address, byte[] name, int cod) { 56 mRemoteDevices.pinRequestCallback(address, name, cod); 57 } 58 59 void bondStateChangeCallback(int status, byte[] address, int newState) { 60 mBondStateMachine.bondStateChangeCallback(status, address, newState); 61 } 62 63 void stateChangeCallback(int status) { 64 mAdapterStateMachine.stateChangeCallback(status); 65 } 66 67 void discoveryStateChangeCallback(int state) { 68 mAdapterProperties.discoveryStateChangeCallback(state); 69 } 70 71 void adapterPropertyChangedCallback(int[] types, byte[][] val) { 72 mAdapterProperties.adapterPropertyChangedCallback(types, val); 73 } 74 75} 76