Loading android/app/src/com/android/bluetooth/map/BluetoothMapService.java 100644 → 100755 +59 −4 Original line number Diff line number Diff line Loading @@ -80,6 +80,7 @@ public class BluetoothMapService extends ProfileService { */ public static final String USER_CONFIRM_TIMEOUT_ACTION = "com.android.bluetooth.map.userconfirmtimeout"; private static final int USER_CONFIRM_TIMEOUT_VALUE = 30000; /** * Intent Extra name indicating session key which is sent from Loading Loading @@ -140,6 +141,7 @@ public class BluetoothMapService extends ProfileService { private int mState; private boolean isWaitingAuthorization = false; private boolean removeTimeoutMsg = false; // package and class name to which we send intent to check message access access permission private static final String ACCESS_AUTHORITY_PACKAGE = "com.android.settings"; Loading Loading @@ -426,6 +428,12 @@ public class BluetoothMapService extends ProfileService { if (DEBUG) Log.d(TAG, "waiting for authorization for connection from: " + sRemoteDeviceName); //Queue USER_TIMEOUT to disconnect MAP OBEX session. If user doesn't //accept or reject authorization request removeTimeoutMsg = true; mSessionStatusHandler.sendMessageDelayed(mSessionStatusHandler .obtainMessage(USER_TIMEOUT), USER_CONFIRM_TIMEOUT_VALUE); } stopped = true; // job done ,close this thread; Loading Loading @@ -455,11 +463,12 @@ public class BluetoothMapService extends ProfileService { break; case USER_TIMEOUT: Intent intent = new Intent(BluetoothDevice.ACTION_CONNECTION_ACCESS_CANCEL); intent.setClassName(ACCESS_AUTHORITY_PACKAGE, ACCESS_AUTHORITY_CLASS); intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mRemoteDevice); intent.putExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE, BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS); sendBroadcast(intent); sendBroadcast(intent, BLUETOOTH_PERM); isWaitingAuthorization = false; removeTimeoutMsg = false; stopObexServerSession(); break; case MSG_SERVERSESSION_CLOSE: Loading Loading @@ -633,6 +642,7 @@ public class BluetoothMapService extends ProfileService { IntentFilter filter = new IntentFilter(); filter.addAction(BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY); filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); filter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED); try { registerReceiver(mMapReceiver, filter); } catch (Exception e) { Loading Loading @@ -667,6 +677,7 @@ public class BluetoothMapService extends ProfileService { return true; } private MapBroadcastReceiver mMapReceiver = new MapBroadcastReceiver(); private class MapBroadcastReceiver extends BroadcastReceiver { Loading @@ -678,7 +689,22 @@ public class BluetoothMapService extends ProfileService { int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR); if (state == BluetoothAdapter.STATE_TURNING_OFF) { if (DEBUG) Log.d(TAG, "STATE_TURNING_OFF"); if (DEBUG) Log.d(TAG, "STATE_TURNING_OFF removeTimeoutMsg:" + removeTimeoutMsg); // Send any pending timeout now, as this service will be destroyed. if (removeTimeoutMsg) { mSessionStatusHandler.removeMessages(USER_TIMEOUT); Intent timeoutIntent = new Intent(BluetoothDevice.ACTION_CONNECTION_ACCESS_CANCEL); timeoutIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mRemoteDevice); timeoutIntent.putExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE, BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS); sendBroadcast(timeoutIntent, BLUETOOTH_PERM); isWaitingAuthorization = false; removeTimeoutMsg = false; stopObexServerSession(); } // Release all resources closeService(); } else if (state == BluetoothAdapter.STATE_ON) { Loading @@ -692,7 +718,7 @@ public class BluetoothMapService extends ProfileService { int requestType = intent.getIntExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE, BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS); if (DEBUG) Log.d(TAG, "Received ACTION_CONNECTION_ACCESS_REPLY:" + requestType + ":" + isWaitingAuthorization); requestType + "isWaitingAuthorization:" + isWaitingAuthorization); if ((!isWaitingAuthorization) || (requestType != BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS)) { // this reply is not for us Loading @@ -700,6 +726,10 @@ public class BluetoothMapService extends ProfileService { } isWaitingAuthorization = false; if (removeTimeoutMsg) { mSessionStatusHandler.removeMessages(USER_TIMEOUT); removeTimeoutMsg = false; } if (intent.getIntExtra(BluetoothDevice.EXTRA_CONNECTION_ACCESS_RESULT, BluetoothDevice.CONNECTION_ACCESS_NO) == Loading @@ -722,6 +752,31 @@ public class BluetoothMapService extends ProfileService { } else { stopObexServerSession(); } } else if (action.equals(BluetoothDevice.ACTION_ACL_DISCONNECTED) && isWaitingAuthorization) { BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); if (mRemoteDevice == null || device == null) { Log.e(TAG, "Unexpected error!"); return; } if (DEBUG) Log.d(TAG,"ACL disconnected for "+ device); if (mRemoteDevice.equals(device) && removeTimeoutMsg) { // Send any pending timeout now, as ACL got disconnected. mSessionStatusHandler.removeMessages(USER_TIMEOUT); Intent timeoutIntent = new Intent(BluetoothDevice.ACTION_CONNECTION_ACCESS_CANCEL); timeoutIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mRemoteDevice); timeoutIntent.putExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE, BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS); sendBroadcast(timeoutIntent, BLUETOOTH_PERM); isWaitingAuthorization = false; removeTimeoutMsg = false; stopObexServerSession(); } } } }; Loading Loading
android/app/src/com/android/bluetooth/map/BluetoothMapService.java 100644 → 100755 +59 −4 Original line number Diff line number Diff line Loading @@ -80,6 +80,7 @@ public class BluetoothMapService extends ProfileService { */ public static final String USER_CONFIRM_TIMEOUT_ACTION = "com.android.bluetooth.map.userconfirmtimeout"; private static final int USER_CONFIRM_TIMEOUT_VALUE = 30000; /** * Intent Extra name indicating session key which is sent from Loading Loading @@ -140,6 +141,7 @@ public class BluetoothMapService extends ProfileService { private int mState; private boolean isWaitingAuthorization = false; private boolean removeTimeoutMsg = false; // package and class name to which we send intent to check message access access permission private static final String ACCESS_AUTHORITY_PACKAGE = "com.android.settings"; Loading Loading @@ -426,6 +428,12 @@ public class BluetoothMapService extends ProfileService { if (DEBUG) Log.d(TAG, "waiting for authorization for connection from: " + sRemoteDeviceName); //Queue USER_TIMEOUT to disconnect MAP OBEX session. If user doesn't //accept or reject authorization request removeTimeoutMsg = true; mSessionStatusHandler.sendMessageDelayed(mSessionStatusHandler .obtainMessage(USER_TIMEOUT), USER_CONFIRM_TIMEOUT_VALUE); } stopped = true; // job done ,close this thread; Loading Loading @@ -455,11 +463,12 @@ public class BluetoothMapService extends ProfileService { break; case USER_TIMEOUT: Intent intent = new Intent(BluetoothDevice.ACTION_CONNECTION_ACCESS_CANCEL); intent.setClassName(ACCESS_AUTHORITY_PACKAGE, ACCESS_AUTHORITY_CLASS); intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mRemoteDevice); intent.putExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE, BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS); sendBroadcast(intent); sendBroadcast(intent, BLUETOOTH_PERM); isWaitingAuthorization = false; removeTimeoutMsg = false; stopObexServerSession(); break; case MSG_SERVERSESSION_CLOSE: Loading Loading @@ -633,6 +642,7 @@ public class BluetoothMapService extends ProfileService { IntentFilter filter = new IntentFilter(); filter.addAction(BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY); filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); filter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED); try { registerReceiver(mMapReceiver, filter); } catch (Exception e) { Loading Loading @@ -667,6 +677,7 @@ public class BluetoothMapService extends ProfileService { return true; } private MapBroadcastReceiver mMapReceiver = new MapBroadcastReceiver(); private class MapBroadcastReceiver extends BroadcastReceiver { Loading @@ -678,7 +689,22 @@ public class BluetoothMapService extends ProfileService { int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR); if (state == BluetoothAdapter.STATE_TURNING_OFF) { if (DEBUG) Log.d(TAG, "STATE_TURNING_OFF"); if (DEBUG) Log.d(TAG, "STATE_TURNING_OFF removeTimeoutMsg:" + removeTimeoutMsg); // Send any pending timeout now, as this service will be destroyed. if (removeTimeoutMsg) { mSessionStatusHandler.removeMessages(USER_TIMEOUT); Intent timeoutIntent = new Intent(BluetoothDevice.ACTION_CONNECTION_ACCESS_CANCEL); timeoutIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mRemoteDevice); timeoutIntent.putExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE, BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS); sendBroadcast(timeoutIntent, BLUETOOTH_PERM); isWaitingAuthorization = false; removeTimeoutMsg = false; stopObexServerSession(); } // Release all resources closeService(); } else if (state == BluetoothAdapter.STATE_ON) { Loading @@ -692,7 +718,7 @@ public class BluetoothMapService extends ProfileService { int requestType = intent.getIntExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE, BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS); if (DEBUG) Log.d(TAG, "Received ACTION_CONNECTION_ACCESS_REPLY:" + requestType + ":" + isWaitingAuthorization); requestType + "isWaitingAuthorization:" + isWaitingAuthorization); if ((!isWaitingAuthorization) || (requestType != BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS)) { // this reply is not for us Loading @@ -700,6 +726,10 @@ public class BluetoothMapService extends ProfileService { } isWaitingAuthorization = false; if (removeTimeoutMsg) { mSessionStatusHandler.removeMessages(USER_TIMEOUT); removeTimeoutMsg = false; } if (intent.getIntExtra(BluetoothDevice.EXTRA_CONNECTION_ACCESS_RESULT, BluetoothDevice.CONNECTION_ACCESS_NO) == Loading @@ -722,6 +752,31 @@ public class BluetoothMapService extends ProfileService { } else { stopObexServerSession(); } } else if (action.equals(BluetoothDevice.ACTION_ACL_DISCONNECTED) && isWaitingAuthorization) { BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); if (mRemoteDevice == null || device == null) { Log.e(TAG, "Unexpected error!"); return; } if (DEBUG) Log.d(TAG,"ACL disconnected for "+ device); if (mRemoteDevice.equals(device) && removeTimeoutMsg) { // Send any pending timeout now, as ACL got disconnected. mSessionStatusHandler.removeMessages(USER_TIMEOUT); Intent timeoutIntent = new Intent(BluetoothDevice.ACTION_CONNECTION_ACCESS_CANCEL); timeoutIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mRemoteDevice); timeoutIntent.putExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE, BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS); sendBroadcast(timeoutIntent, BLUETOOTH_PERM); isWaitingAuthorization = false; removeTimeoutMsg = false; stopObexServerSession(); } } } }; Loading