Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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 android.bluetooth; |
| 18 | |
Jack He | 37ab815 | 2017-10-02 19:08:30 -0700 | [diff] [blame] | 19 | import android.annotation.SdkConstant; |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 20 | import android.annotation.UnsupportedAppUsage; |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 21 | import android.content.ComponentName; |
| 22 | import android.content.Context; |
| 23 | import android.content.Intent; |
| 24 | import android.content.ServiceConnection; |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 25 | import android.os.IBinder; |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 26 | import android.os.RemoteException; |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 27 | import android.util.Log; |
| 28 | |
Hansong Zhang | fef6d81 | 2017-12-08 16:05:55 -0800 | [diff] [blame] | 29 | import java.util.ArrayList; |
| 30 | import java.util.Arrays; |
| 31 | import java.util.List; |
| 32 | |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 33 | /** |
| 34 | * The Android Bluetooth API is not finalized, and *will* change. Use at your |
| 35 | * own risk. |
| 36 | * |
| 37 | * Public API for controlling the Bluetooth Pbap Service. This includes |
| 38 | * Bluetooth Phone book Access profile. |
| 39 | * BluetoothPbap is a proxy object for controlling the Bluetooth Pbap |
| 40 | * Service via IPC. |
| 41 | * |
| 42 | * Creating a BluetoothPbap object will create a binding with the |
| 43 | * BluetoothPbap service. Users of this object should call close() when they |
| 44 | * are finished with the BluetoothPbap, so that this proxy object can unbind |
| 45 | * from the service. |
| 46 | * |
| 47 | * This BluetoothPbap object is not immediately bound to the |
| 48 | * BluetoothPbap service. Use the ServiceListener interface to obtain a |
| 49 | * notification when it is bound, this is especially important if you wish to |
| 50 | * immediately call methods on BluetoothPbap after construction. |
| 51 | * |
| 52 | * Android only supports one connected Bluetooth Pce at a time. |
| 53 | * |
| 54 | * @hide |
| 55 | */ |
Hansong Zhang | fef6d81 | 2017-12-08 16:05:55 -0800 | [diff] [blame] | 56 | public class BluetoothPbap implements BluetoothProfile { |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 57 | |
| 58 | private static final String TAG = "BluetoothPbap"; |
Hansong Zhang | fef6d81 | 2017-12-08 16:05:55 -0800 | [diff] [blame] | 59 | private static final boolean DBG = false; |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 60 | |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 61 | /** |
Jack He | 37ab815 | 2017-10-02 19:08:30 -0700 | [diff] [blame] | 62 | * Intent used to broadcast the change in connection state of the PBAP |
| 63 | * profile. |
| 64 | * |
| 65 | * <p>This intent will have 3 extras: |
| 66 | * <ul> |
| 67 | * <li> {@link BluetoothProfile#EXTRA_STATE} - The current state of the profile. </li> |
| 68 | * <li> {@link BluetoothProfile#EXTRA_PREVIOUS_STATE}- The previous state of the profile. </li> |
| 69 | * <li> {@link BluetoothDevice#EXTRA_DEVICE} - The remote device. </li> |
| 70 | * </ul> |
| 71 | * <p>{@link BluetoothProfile#EXTRA_STATE} or {@link BluetoothProfile#EXTRA_PREVIOUS_STATE} |
| 72 | * can be any of {@link BluetoothProfile#STATE_DISCONNECTED}, |
| 73 | * {@link BluetoothProfile#STATE_CONNECTING}, {@link BluetoothProfile#STATE_CONNECTED}, |
| 74 | * {@link BluetoothProfile#STATE_DISCONNECTING}. |
| 75 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission to |
| 76 | * receive. |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 77 | */ |
Jack He | 37ab815 | 2017-10-02 19:08:30 -0700 | [diff] [blame] | 78 | @SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION) |
| 79 | public static final String ACTION_CONNECTION_STATE_CHANGED = |
| 80 | "android.bluetooth.pbap.profile.action.CONNECTION_STATE_CHANGED"; |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 81 | |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 82 | private volatile IBluetoothPbap mService; |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 83 | private final Context mContext; |
Jaikumar Ganesh | 9bb2751 | 2011-11-28 09:59:08 -0800 | [diff] [blame] | 84 | private ServiceListener mServiceListener; |
Ganesh Ganapathi Batta | 6f6c5451 | 2012-07-31 16:08:17 -0700 | [diff] [blame] | 85 | private BluetoothAdapter mAdapter; |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 86 | |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 87 | public static final int RESULT_FAILURE = 0; |
| 88 | public static final int RESULT_SUCCESS = 1; |
| 89 | /** Connection canceled before completion. */ |
| 90 | public static final int RESULT_CANCELED = 2; |
| 91 | |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 92 | /** |
| 93 | * An interface for notifying Bluetooth PCE IPC clients when they have |
Jackson Fan | c8b04a9 | 2009-07-28 12:15:49 +0800 | [diff] [blame] | 94 | * been connected to the BluetoothPbap service. |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 95 | */ |
| 96 | public interface ServiceListener { |
| 97 | /** |
| 98 | * Called to notify the client when this proxy object has been |
| 99 | * connected to the BluetoothPbap service. Clients must wait for |
| 100 | * this callback before making IPC calls on the BluetoothPbap |
| 101 | * service. |
| 102 | */ |
Ganesh Ganapathi Batta | 6f6c5451 | 2012-07-31 16:08:17 -0700 | [diff] [blame] | 103 | public void onServiceConnected(BluetoothPbap proxy); |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 104 | |
| 105 | /** |
| 106 | * Called to notify the client that this proxy object has been |
| 107 | * disconnected from the BluetoothPbap service. Clients must not |
| 108 | * make IPC calls on the BluetoothPbap service after this callback. |
| 109 | * This callback will currently only occur if the application hosting |
| 110 | * the BluetoothPbap service, but may be called more often in future. |
| 111 | */ |
| 112 | public void onServiceDisconnected(); |
| 113 | } |
| 114 | |
Jack He | 2992cd0 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 115 | private final IBluetoothStateChangeCallback mBluetoothStateChangeCallback = |
Ganesh Ganapathi Batta | 6f6c5451 | 2012-07-31 16:08:17 -0700 | [diff] [blame] | 116 | new IBluetoothStateChangeCallback.Stub() { |
| 117 | public void onBluetoothStateChange(boolean up) { |
Hansong Zhang | fef6d81 | 2017-12-08 16:05:55 -0800 | [diff] [blame] | 118 | log("onBluetoothStateChange: up=" + up); |
Ganesh Ganapathi Batta | 6f6c5451 | 2012-07-31 16:08:17 -0700 | [diff] [blame] | 119 | if (!up) { |
Hansong Zhang | fef6d81 | 2017-12-08 16:05:55 -0800 | [diff] [blame] | 120 | log("Unbinding service..."); |
Ganesh Ganapathi Batta | 6f6c5451 | 2012-07-31 16:08:17 -0700 | [diff] [blame] | 121 | synchronized (mConnection) { |
| 122 | try { |
| 123 | mService = null; |
| 124 | mContext.unbindService(mConnection); |
| 125 | } catch (Exception re) { |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 126 | Log.e(TAG, "", re); |
Ganesh Ganapathi Batta | 6f6c5451 | 2012-07-31 16:08:17 -0700 | [diff] [blame] | 127 | } |
| 128 | } |
| 129 | } else { |
| 130 | synchronized (mConnection) { |
| 131 | try { |
| 132 | if (mService == null) { |
Hansong Zhang | fef6d81 | 2017-12-08 16:05:55 -0800 | [diff] [blame] | 133 | log("Binding service..."); |
Dianne Hackborn | 221ea89 | 2013-08-04 16:50:16 -0700 | [diff] [blame] | 134 | doBind(); |
Ganesh Ganapathi Batta | 6f6c5451 | 2012-07-31 16:08:17 -0700 | [diff] [blame] | 135 | } |
| 136 | } catch (Exception re) { |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 137 | Log.e(TAG, "", re); |
Ganesh Ganapathi Batta | 6f6c5451 | 2012-07-31 16:08:17 -0700 | [diff] [blame] | 138 | } |
| 139 | } |
| 140 | } |
| 141 | } |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 142 | }; |
Ganesh Ganapathi Batta | 6f6c5451 | 2012-07-31 16:08:17 -0700 | [diff] [blame] | 143 | |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 144 | /** |
Jackson Fan | c8b04a9 | 2009-07-28 12:15:49 +0800 | [diff] [blame] | 145 | * Create a BluetoothPbap proxy object. |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 146 | */ |
| 147 | public BluetoothPbap(Context context, ServiceListener l) { |
| 148 | mContext = context; |
| 149 | mServiceListener = l; |
Ganesh Ganapathi Batta | 6f6c5451 | 2012-07-31 16:08:17 -0700 | [diff] [blame] | 150 | mAdapter = BluetoothAdapter.getDefaultAdapter(); |
| 151 | IBluetoothManager mgr = mAdapter.getBluetoothManager(); |
| 152 | if (mgr != null) { |
| 153 | try { |
| 154 | mgr.registerStateChangeCallback(mBluetoothStateChangeCallback); |
| 155 | } catch (RemoteException e) { |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 156 | Log.e(TAG, "", e); |
Ganesh Ganapathi Batta | 6f6c5451 | 2012-07-31 16:08:17 -0700 | [diff] [blame] | 157 | } |
| 158 | } |
Dianne Hackborn | 221ea89 | 2013-08-04 16:50:16 -0700 | [diff] [blame] | 159 | doBind(); |
| 160 | } |
| 161 | |
| 162 | boolean doBind() { |
| 163 | Intent intent = new Intent(IBluetoothPbap.class.getName()); |
| 164 | ComponentName comp = intent.resolveSystemService(mContext.getPackageManager(), 0); |
| 165 | intent.setComponent(comp); |
Dianne Hackborn | 466ce96 | 2014-03-19 18:06:58 -0700 | [diff] [blame] | 166 | if (comp == null || !mContext.bindServiceAsUser(intent, mConnection, 0, |
Jeff Sharkey | ad357d1 | 2018-02-02 13:25:31 -0700 | [diff] [blame] | 167 | mContext.getUser())) { |
Dianne Hackborn | 221ea89 | 2013-08-04 16:50:16 -0700 | [diff] [blame] | 168 | Log.e(TAG, "Could not bind to Bluetooth Pbap Service with " + intent); |
| 169 | return false; |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 170 | } |
Dianne Hackborn | 221ea89 | 2013-08-04 16:50:16 -0700 | [diff] [blame] | 171 | return true; |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | protected void finalize() throws Throwable { |
| 175 | try { |
| 176 | close(); |
| 177 | } finally { |
| 178 | super.finalize(); |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * Close the connection to the backing service. |
Jackson Fan | c8b04a9 | 2009-07-28 12:15:49 +0800 | [diff] [blame] | 184 | * Other public functions of BluetoothPbap will return default error |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 185 | * results once close() has been called. Multiple invocations of close() |
| 186 | * are ok. |
| 187 | */ |
| 188 | public synchronized void close() { |
Ganesh Ganapathi Batta | 6f6c5451 | 2012-07-31 16:08:17 -0700 | [diff] [blame] | 189 | IBluetoothManager mgr = mAdapter.getBluetoothManager(); |
| 190 | if (mgr != null) { |
| 191 | try { |
| 192 | mgr.unregisterStateChangeCallback(mBluetoothStateChangeCallback); |
| 193 | } catch (Exception e) { |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 194 | Log.e(TAG, "", e); |
Ganesh Ganapathi Batta | 6f6c5451 | 2012-07-31 16:08:17 -0700 | [diff] [blame] | 195 | } |
| 196 | } |
| 197 | |
| 198 | synchronized (mConnection) { |
| 199 | if (mService != null) { |
| 200 | try { |
| 201 | mService = null; |
| 202 | mContext.unbindService(mConnection); |
Ganesh Ganapathi Batta | 6f6c5451 | 2012-07-31 16:08:17 -0700 | [diff] [blame] | 203 | } catch (Exception re) { |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 204 | Log.e(TAG, "", re); |
Ganesh Ganapathi Batta | 6f6c5451 | 2012-07-31 16:08:17 -0700 | [diff] [blame] | 205 | } |
| 206 | } |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 207 | } |
Jaikumar Ganesh | 9bb2751 | 2011-11-28 09:59:08 -0800 | [diff] [blame] | 208 | mServiceListener = null; |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | /** |
Hansong Zhang | fef6d81 | 2017-12-08 16:05:55 -0800 | [diff] [blame] | 212 | * {@inheritDoc} |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 213 | */ |
Hansong Zhang | fef6d81 | 2017-12-08 16:05:55 -0800 | [diff] [blame] | 214 | @Override |
| 215 | public List<BluetoothDevice> getConnectedDevices() { |
| 216 | log("getConnectedDevices()"); |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 217 | final IBluetoothPbap service = mService; |
Hansong Zhang | fef6d81 | 2017-12-08 16:05:55 -0800 | [diff] [blame] | 218 | if (service == null) { |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 219 | Log.w(TAG, "Proxy not attached to service"); |
Hansong Zhang | fef6d81 | 2017-12-08 16:05:55 -0800 | [diff] [blame] | 220 | return new ArrayList<BluetoothDevice>(); |
| 221 | } |
| 222 | try { |
| 223 | return service.getConnectedDevices(); |
| 224 | } catch (RemoteException e) { |
| 225 | Log.e(TAG, e.toString()); |
| 226 | } |
| 227 | return new ArrayList<BluetoothDevice>(); |
| 228 | } |
| 229 | |
| 230 | /** |
| 231 | * {@inheritDoc} |
| 232 | */ |
| 233 | @Override |
| 234 | public int getConnectionState(BluetoothDevice device) { |
| 235 | log("getConnectionState: device=" + device); |
| 236 | final IBluetoothPbap service = mService; |
| 237 | if (service == null) { |
| 238 | Log.w(TAG, "Proxy not attached to service"); |
| 239 | return BluetoothProfile.STATE_DISCONNECTED; |
| 240 | } |
| 241 | try { |
| 242 | return service.getConnectionState(device); |
| 243 | } catch (RemoteException e) { |
| 244 | Log.e(TAG, e.toString()); |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 245 | } |
Jack He | 37ab815 | 2017-10-02 19:08:30 -0700 | [diff] [blame] | 246 | return BluetoothProfile.STATE_DISCONNECTED; |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | /** |
Hansong Zhang | fef6d81 | 2017-12-08 16:05:55 -0800 | [diff] [blame] | 250 | * {@inheritDoc} |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 251 | */ |
Hansong Zhang | fef6d81 | 2017-12-08 16:05:55 -0800 | [diff] [blame] | 252 | @Override |
| 253 | public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) { |
| 254 | log("getDevicesMatchingConnectionStates: states=" + Arrays.toString(states)); |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 255 | final IBluetoothPbap service = mService; |
Hansong Zhang | fef6d81 | 2017-12-08 16:05:55 -0800 | [diff] [blame] | 256 | if (service == null) { |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 257 | Log.w(TAG, "Proxy not attached to service"); |
Hansong Zhang | fef6d81 | 2017-12-08 16:05:55 -0800 | [diff] [blame] | 258 | return new ArrayList<BluetoothDevice>(); |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 259 | } |
Hansong Zhang | fef6d81 | 2017-12-08 16:05:55 -0800 | [diff] [blame] | 260 | try { |
| 261 | return service.getDevicesMatchingConnectionStates(states); |
| 262 | } catch (RemoteException e) { |
| 263 | Log.e(TAG, e.toString()); |
| 264 | } |
| 265 | return new ArrayList<BluetoothDevice>(); |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | /** |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 269 | * Returns true if the specified Bluetooth device is connected (does not |
| 270 | * include connecting). Returns false if not connected, or if this proxy |
| 271 | * object is not currently connected to the Pbap service. |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 272 | */ |
Hansong Zhang | fef6d81 | 2017-12-08 16:05:55 -0800 | [diff] [blame] | 273 | // TODO: This is currently being used by SettingsLib and internal app. |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 274 | public boolean isConnected(BluetoothDevice device) { |
Hansong Zhang | fef6d81 | 2017-12-08 16:05:55 -0800 | [diff] [blame] | 275 | return getConnectionState(device) == BluetoothAdapter.STATE_CONNECTED; |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | /** |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 279 | * Disconnects the current Pbap client (PCE). Currently this call blocks, |
Jake Hamby | f51eada | 2010-09-21 13:39:53 -0700 | [diff] [blame] | 280 | * it may soon be made asynchronous. Returns false if this proxy object is |
Jackson Fan | c8b04a9 | 2009-07-28 12:15:49 +0800 | [diff] [blame] | 281 | * not currently connected to the Pbap service. |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 282 | */ |
Hansong Zhang | fef6d81 | 2017-12-08 16:05:55 -0800 | [diff] [blame] | 283 | // TODO: This is currently being used by SettingsLib and will be used in the future. |
| 284 | // TODO: Must specify target device. Implement this in the service. |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 285 | @UnsupportedAppUsage |
Hansong Zhang | fef6d81 | 2017-12-08 16:05:55 -0800 | [diff] [blame] | 286 | public boolean disconnect(BluetoothDevice device) { |
| 287 | log("disconnect()"); |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 288 | final IBluetoothPbap service = mService; |
Hansong Zhang | fef6d81 | 2017-12-08 16:05:55 -0800 | [diff] [blame] | 289 | if (service == null) { |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 290 | Log.w(TAG, "Proxy not attached to service"); |
Hansong Zhang | fef6d81 | 2017-12-08 16:05:55 -0800 | [diff] [blame] | 291 | return false; |
| 292 | } |
| 293 | try { |
| 294 | service.disconnect(device); |
| 295 | return true; |
| 296 | } catch (RemoteException e) { |
| 297 | Log.e(TAG, e.toString()); |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 298 | } |
| 299 | return false; |
| 300 | } |
| 301 | |
Matthew Xie | 9b69399 | 2013-10-10 11:21:40 -0700 | [diff] [blame] | 302 | private final ServiceConnection mConnection = new ServiceConnection() { |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 303 | public void onServiceConnected(ComponentName className, IBinder service) { |
Hansong Zhang | fef6d81 | 2017-12-08 16:05:55 -0800 | [diff] [blame] | 304 | log("Proxy object connected"); |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 305 | mService = IBluetoothPbap.Stub.asInterface(service); |
| 306 | if (mServiceListener != null) { |
Ganesh Ganapathi Batta | 6f6c5451 | 2012-07-31 16:08:17 -0700 | [diff] [blame] | 307 | mServiceListener.onServiceConnected(BluetoothPbap.this); |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 308 | } |
| 309 | } |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 310 | |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 311 | public void onServiceDisconnected(ComponentName className) { |
Hansong Zhang | fef6d81 | 2017-12-08 16:05:55 -0800 | [diff] [blame] | 312 | log("Proxy object disconnected"); |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 313 | mService = null; |
| 314 | if (mServiceListener != null) { |
| 315 | mServiceListener.onServiceDisconnected(); |
| 316 | } |
| 317 | } |
| 318 | }; |
| 319 | |
| 320 | private static void log(String msg) { |
Hansong Zhang | fef6d81 | 2017-12-08 16:05:55 -0800 | [diff] [blame] | 321 | if (DBG) { |
| 322 | Log.d(TAG, msg); |
| 323 | } |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 324 | } |
| 325 | } |