1 /*
2  * Copyright (C) 2012-2014 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.bluetooth.btservice;
18 
19 import android.bluetooth.OobData;
20 import android.bluetooth.UidTraffic;
21 
22 class JniCallbacks {
23 
24     private RemoteDevices mRemoteDevices;
25     private AdapterProperties mAdapterProperties;
26     private AdapterService mAdapterService;
27     private BondStateMachine mBondStateMachine;
28 
JniCallbacks(AdapterService adapterService, AdapterProperties adapterProperties)29     JniCallbacks(AdapterService adapterService, AdapterProperties adapterProperties) {
30         mAdapterService = adapterService;
31         mAdapterProperties = adapterProperties;
32     }
33 
init(BondStateMachine bondStateMachine, RemoteDevices remoteDevices)34     void init(BondStateMachine bondStateMachine, RemoteDevices remoteDevices) {
35         mRemoteDevices = remoteDevices;
36         mBondStateMachine = bondStateMachine;
37     }
38 
cleanup()39     void cleanup() {
40         mRemoteDevices = null;
41         mAdapterProperties = null;
42         mAdapterService = null;
43         mBondStateMachine = null;
44     }
45 
46     @Override
clone()47     public Object clone() throws CloneNotSupportedException {
48         throw new CloneNotSupportedException();
49     }
50 
sspRequestCallback(byte[] address, int pairingVariant, int passkey)51     void sspRequestCallback(byte[] address, int pairingVariant, int passkey) {
52         mBondStateMachine.sspRequestCallback(address, pairingVariant, passkey);
53     }
54 
devicePropertyChangedCallback(byte[] address, int[] types, byte[][] val)55     void devicePropertyChangedCallback(byte[] address, int[] types, byte[][] val) {
56         mRemoteDevices.devicePropertyChangedCallback(address, types, val);
57     }
58 
deviceFoundCallback(byte[] address)59     void deviceFoundCallback(byte[] address) {
60         mRemoteDevices.deviceFoundCallback(address);
61     }
62 
pinRequestCallback(byte[] address, byte[] name, int cod, boolean min16Digits)63     void pinRequestCallback(byte[] address, byte[] name, int cod, boolean min16Digits) {
64         mBondStateMachine.pinRequestCallback(address, name, cod, min16Digits);
65     }
66 
bondStateChangeCallback(int status, byte[] address, int newState, int hciReason)67     void bondStateChangeCallback(int status, byte[] address, int newState, int hciReason) {
68         mBondStateMachine.bondStateChangeCallback(status, address, newState, hciReason);
69     }
70 
addressConsolidateCallback(byte[] mainAddress, byte[] secondaryAddress)71     void addressConsolidateCallback(byte[] mainAddress, byte[] secondaryAddress) {
72         mRemoteDevices.addressConsolidateCallback(mainAddress, secondaryAddress);
73     }
74 
leAddressAssociateCallback(byte[] mainAddress, byte[] secondaryAddress)75     void leAddressAssociateCallback(byte[] mainAddress, byte[] secondaryAddress) {
76         mRemoteDevices.leAddressAssociateCallback(mainAddress, secondaryAddress);
77     }
78 
aclStateChangeCallback( int status, byte[] address, int newState, int transportLinkType, int hciReason, int handle)79     void aclStateChangeCallback(
80             int status,
81             byte[] address,
82             int newState,
83             int transportLinkType,
84             int hciReason,
85             int handle) {
86         mRemoteDevices.aclStateChangeCallback(
87                 status, address, newState, transportLinkType, hciReason, handle);
88     }
89 
keyMissingCallback(byte[] address)90     void keyMissingCallback(byte[] address) {
91         mRemoteDevices.keyMissingCallback(address);
92     }
93 
stateChangeCallback(int status)94     void stateChangeCallback(int status) {
95         mAdapterService.stateChangeCallback(status);
96     }
97 
discoveryStateChangeCallback(int state)98     void discoveryStateChangeCallback(int state) {
99         mAdapterProperties.discoveryStateChangeCallback(state);
100     }
101 
adapterPropertyChangedCallback(int[] types, byte[][] val)102     void adapterPropertyChangedCallback(int[] types, byte[][] val) {
103         mAdapterProperties.adapterPropertyChangedCallback(types, val);
104     }
105 
oobDataReceivedCallback(int transport, OobData oobData)106     void oobDataReceivedCallback(int transport, OobData oobData) {
107         mAdapterService.notifyOobDataCallback(transport, oobData);
108     }
109 
linkQualityReportCallback( long timestamp, int report_id, int rssi, int snr, int retransmission_count, int packets_not_receive_count, int negative_acknowledgement_count)110     void linkQualityReportCallback(
111             long timestamp,
112             int report_id,
113             int rssi,
114             int snr,
115             int retransmission_count,
116             int packets_not_receive_count,
117             int negative_acknowledgement_count) {
118         mAdapterService.linkQualityReportCallback(
119                 timestamp,
120                 report_id,
121                 rssi,
122                 snr,
123                 retransmission_count,
124                 packets_not_receive_count,
125                 negative_acknowledgement_count);
126     }
127 
switchBufferSizeCallback(boolean is_low_latency_buffer_size)128     void switchBufferSizeCallback(boolean is_low_latency_buffer_size) {
129         mAdapterService.switchBufferSizeCallback(is_low_latency_buffer_size);
130     }
131 
switchCodecCallback(boolean is_low_latency_buffer_size)132     void switchCodecCallback(boolean is_low_latency_buffer_size) {
133         mAdapterService.switchCodecCallback(is_low_latency_buffer_size);
134     }
135 
acquireWakeLock(String lockName)136     boolean acquireWakeLock(String lockName) {
137         return mAdapterService.acquireWakeLock(lockName);
138     }
139 
releaseWakeLock(String lockName)140     boolean releaseWakeLock(String lockName) {
141         return mAdapterService.releaseWakeLock(lockName);
142     }
143 
energyInfoCallback( int status, int ctrlState, long txTime, long rxTime, long idleTime, long energyUsed, UidTraffic[] data)144     void energyInfoCallback(
145             int status,
146             int ctrlState,
147             long txTime,
148             long rxTime,
149             long idleTime,
150             long energyUsed,
151             UidTraffic[] data) {
152         mAdapterService.energyInfoCallback(
153                 status, ctrlState, txTime, rxTime, idleTime, energyUsed, data);
154     }
155 }
156