JniCallbacks.java revision 31ba132491053bc86d419a7d51fc04af3299c076
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.init(remoteDevices, adapterProperties, adapterStateMachine,
32                    bondStateMachine);
33        }
34        return sInstance;
35    }
36
37    void init(RemoteDevices remoteDevices,
38            AdapterProperties adapterProperties, AdapterState adapterStateMachine,
39            BondStateMachine bondStateMachine) {
40        mRemoteDevices = remoteDevices;
41        mAdapterProperties = adapterProperties;
42        mAdapterStateMachine = adapterStateMachine;
43        mBondStateMachine = bondStateMachine;
44    }
45
46    public Object Clone() throws CloneNotSupportedException {
47        throw new CloneNotSupportedException();
48    }
49
50    void sspRequestCallback(byte[] address, byte[] name, int cod, int pairingVariant,
51            int passkey) {
52        mRemoteDevices.sspRequestCallback(address, name, cod, pairingVariant,
53            passkey);
54    }
55    void devicePropertyChangedCallback(byte[] address, int[] types, byte[][] val) {
56        mRemoteDevices.devicePropertyChangedCallback(address, types, val);
57    }
58
59    void deviceFoundCallback(byte[] address) {
60        mRemoteDevices.deviceFoundCallback(address);
61    }
62
63    void pinRequestCallback(byte[] address, byte[] name, int cod) {
64        mRemoteDevices.pinRequestCallback(address, name, cod);
65    }
66
67    void bondStateChangeCallback(int status, byte[] address, int newState) {
68        mBondStateMachine.bondStateChangeCallback(status, address, newState);
69    }
70
71    void aclStateChangeCallback(int status, byte[] address, int newState) {
72		mRemoteDevices.aclStateChangeCallback(status, address, newState);
73    }
74
75    void stateChangeCallback(int status) {
76        mAdapterStateMachine.stateChangeCallback(status);
77    }
78
79    void discoveryStateChangeCallback(int state) {
80        mAdapterProperties.discoveryStateChangeCallback(state);
81    }
82
83    void adapterPropertyChangedCallback(int[] types, byte[][] val) {
84        mAdapterProperties.adapterPropertyChangedCallback(types, val);
85    }
86
87}
88