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