Loading android/app/AndroidManifest.xml +2 −2 Original line number Diff line number Diff line Loading @@ -329,7 +329,7 @@ android:name = ".hid.HidService" android:enabled="@bool/profile_supported_hid"> <intent-filter> <action android:name="android.bluetooth.IBluetoothInputDevice" /> <action android:name="android.bluetooth.IBluetoothHidHost" /> </intent-filter> </service> <service Loading Loading @@ -391,7 +391,7 @@ android:name = ".hid.HidDevService" android:enabled="@bool/profile_supported_hidd"> <intent-filter> <action android:name="android.bluetooth.IBluetoothInputHost" /> <action android:name="android.bluetooth.IBluetoothHidDevice" /> </intent-filter> </service> </application> Loading android/app/src/com/android/bluetooth/btservice/AdapterProperties.java +43 −17 Original line number Diff line number Diff line Loading @@ -20,11 +20,12 @@ import android.bluetooth.BluetoothA2dp; import android.bluetooth.BluetoothA2dpSink; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothAvrcpController; import android.bluetooth.BluetoothClass; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothHeadset; import android.bluetooth.BluetoothHeadsetClient; import android.bluetooth.BluetoothInputDevice; import android.bluetooth.BluetoothInputHost; import android.bluetooth.BluetoothHidDevice; import android.bluetooth.BluetoothHidHost; import android.bluetooth.BluetoothMap; import android.bluetooth.BluetoothMapClient; import android.bluetooth.BluetoothPan; Loading Loading @@ -57,7 +58,7 @@ class AdapterProperties { private volatile String mName; private volatile byte[] mAddress; private volatile int mBluetoothClass; private volatile BluetoothClass mBluetoothClass; private volatile int mScanMode; private volatile int mDiscoverableTimeout; private volatile ParcelUuid[] mUuids; Loading Loading @@ -115,11 +116,11 @@ class AdapterProperties { case BluetoothA2dpSink.ACTION_CONNECTION_STATE_CHANGED: sendConnectionStateChange(BluetoothProfile.A2DP_SINK, intent); break; case BluetoothInputHost.ACTION_CONNECTION_STATE_CHANGED: sendConnectionStateChange(BluetoothProfile.INPUT_HOST, intent); case BluetoothHidDevice.ACTION_CONNECTION_STATE_CHANGED: sendConnectionStateChange(BluetoothProfile.HID_DEVICE, intent); break; case BluetoothInputDevice.ACTION_CONNECTION_STATE_CHANGED: sendConnectionStateChange(BluetoothProfile.INPUT_DEVICE, intent); case BluetoothHidHost.ACTION_CONNECTION_STATE_CHANGED: sendConnectionStateChange(BluetoothProfile.HID_HOST, intent); break; case BluetoothAvrcpController.ACTION_CONNECTION_STATE_CHANGED: sendConnectionStateChange(BluetoothProfile.AVRCP_CONTROLLER, intent); Loading Loading @@ -168,8 +169,8 @@ class AdapterProperties { filter.addAction(BluetoothHeadsetClient.ACTION_CONNECTION_STATE_CHANGED); filter.addAction(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED); filter.addAction(BluetoothA2dpSink.ACTION_CONNECTION_STATE_CHANGED); filter.addAction(BluetoothInputHost.ACTION_CONNECTION_STATE_CHANGED); filter.addAction(BluetoothInputDevice.ACTION_CONNECTION_STATE_CHANGED); filter.addAction(BluetoothHidDevice.ACTION_CONNECTION_STATE_CHANGED); filter.addAction(BluetoothHidHost.ACTION_CONNECTION_STATE_CHANGED); filter.addAction(BluetoothAvrcpController.ACTION_CONNECTION_STATE_CHANGED); filter.addAction(BluetoothPan.ACTION_CONNECTION_STATE_CHANGED); filter.addAction(BluetoothMap.ACTION_CONNECTION_STATE_CHANGED); Loading Loading @@ -217,21 +218,38 @@ class AdapterProperties { /** * Set the Bluetooth Class of Device (CoD) of the adapter. * * @param bytes BluetoothClass of the device * <p>Bluetooth stack stores some adapter properties in native BT stack storage and some in the * Java Android stack. Bluetooth CoD is stored in the Android layer through * {@link android.provider.Settings.Global#BLUETOOTH_CLASS_OF_DEVICE}. * * <p>Due to this, the getAdapterPropertyNative and adapterPropertyChangedCallback methods don't * actually update mBluetoothClass. Hence, we update the field mBluetoothClass every time we * successfully update BluetoothClass. * * @param bluetoothClass BluetoothClass of the device */ boolean setBluetoothClass(byte[] bytes) { boolean setBluetoothClass(BluetoothClass bluetoothClass) { synchronized (mObject) { return mService.setAdapterPropertyNative(AbstractionLayer.BT_PROPERTY_CLASS_OF_DEVICE, bytes); boolean result = mService.setAdapterPropertyNative(AbstractionLayer.BT_PROPERTY_CLASS_OF_DEVICE, bluetoothClass.getClassOfDeviceBytes()); if (result) { mBluetoothClass = bluetoothClass; } return result; } } /** * @return the mClass * @return the BluetoothClass of the Bluetooth adapter. */ int getBluetoothClass() { BluetoothClass getBluetoothClass() { synchronized (mObject) { return mBluetoothClass; } } /** * @return the mScanMode Loading Loading @@ -678,7 +696,15 @@ class AdapterProperties { AdapterService.BLUETOOTH_PERM); break; case AbstractionLayer.BT_PROPERTY_CLASS_OF_DEVICE: mBluetoothClass = Utils.byteArrayToInt(val, 0); if (val == null || val.length != 3) { debugLog("Invalid BT CoD value from stack."); return; } int bluetoothClass = ((int) val[0] << 16) + ((int) val[1] << 8) + (int) val[2]; if (bluetoothClass != 0) { mBluetoothClass = new BluetoothClass(bluetoothClass); } debugLog("BT Class:" + mBluetoothClass); break; case AbstractionLayer.BT_PROPERTY_ADAPTER_SCAN_MODE: Loading android/app/src/com/android/bluetooth/btservice/AdapterService.java +58 −1 Original line number Diff line number Diff line Loading @@ -406,6 +406,7 @@ public class AdapterService extends Service { //Load the name and address getAdapterPropertyNative(AbstractionLayer.BT_PROPERTY_BDADDR); getAdapterPropertyNative(AbstractionLayer.BT_PROPERTY_BDNAME); getAdapterPropertyNative(AbstractionLayer.BT_PROPERTY_CLASS_OF_DEVICE); mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); mUserManager = (UserManager) getSystemService(Context.USER_SERVICE); Loading Loading @@ -511,6 +512,32 @@ public class AdapterService extends Service { setGattProfileServiceState(supportedProfileServices, BluetoothAdapter.STATE_ON); } /** * Sets the Bluetooth CoD value of the local adapter if there exists a config value for it. */ void setBluetoothClassFromConfig() { int bluetoothClassConfig = retrieveBluetoothClassConfig(); if (bluetoothClassConfig != 0) { mAdapterProperties.setBluetoothClass(new BluetoothClass(bluetoothClassConfig)); } } private int retrieveBluetoothClassConfig() { return Settings.Global.getInt( getContentResolver(), Settings.Global.BLUETOOTH_CLASS_OF_DEVICE, 0); } private boolean storeBluetoothClassConfig(int bluetoothClass) { boolean result = Settings.Global.putInt( getContentResolver(), Settings.Global.BLUETOOTH_CLASS_OF_DEVICE, bluetoothClass); if (!result) { Log.e(TAG, "Error storing BluetoothClass config - " + bluetoothClass); } return result; } void startCoreServices() { debugLog("startCoreServices()"); Class[] supportedProfileServices = Config.getSupportedProfiles(); Loading Loading @@ -901,6 +928,17 @@ public class AdapterService extends Service { return service.setName(name); } public BluetoothClass getBluetoothClass() { if (!Utils.checkCaller()) { Log.w(TAG, "getBluetoothClass() - Not allowed for non-active user"); return null; } AdapterService service = getService(); if (service == null) return null; return service.getBluetoothClass(); } public boolean setBluetoothClass(BluetoothClass bluetoothClass) { if (!Utils.checkCaller()) { Log.w(TAG, "setBluetoothClass() - Not allowed for non-active user"); Loading Loading @@ -1687,11 +1725,30 @@ public class AdapterService extends Service { return mAdapterProperties.setName(name); } BluetoothClass getBluetoothClass() { enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH ADMIN permission"); return mAdapterProperties.getBluetoothClass(); } /** * Sets the Bluetooth CoD on the local adapter and also modifies the storage config for it. * * <p>Once set, this value persists across reboots. */ boolean setBluetoothClass(BluetoothClass bluetoothClass) { enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, "Need BLUETOOTH PRIVILEGED permission"); return mAdapterProperties.setBluetoothClass(bluetoothClass.getClassOfDeviceBytes()); boolean result = mAdapterProperties.setBluetoothClass(bluetoothClass); if (!result) { Log.e(TAG, "Failed to set BluetoothClass (" + bluetoothClass + ") on local Bluetooth adapter."); } return result && storeBluetoothClassConfig(bluetoothClass.getClassOfDevice()); } int getScanMode() { Loading android/app/src/com/android/bluetooth/btservice/AdapterState.java +1 −0 Original line number Diff line number Diff line Loading @@ -230,6 +230,7 @@ final class AdapterState extends StateMachine { return; } adapterService.updateUuids(); adapterService.setBluetoothClassFromConfig(); } @Override Loading android/app/src/com/android/bluetooth/btservice/Config.java +2 −2 Original line number Diff line number Diff line Loading @@ -156,7 +156,7 @@ public class Config { } else if (profile == A2dpSinkService.class) { profileIndex = BluetoothProfile.A2DP_SINK; } else if (profile == HidService.class) { profileIndex = BluetoothProfile.INPUT_DEVICE; profileIndex = BluetoothProfile.HID_HOST; } else if (profile == HealthService.class) { profileIndex = BluetoothProfile.HEALTH; } else if (profile == PanService.class) { Loading @@ -176,7 +176,7 @@ public class Config { } else if (profile == MapClientService.class) { profileIndex = BluetoothProfile.MAP_CLIENT; } else if (profile == HidDevService.class) { profileIndex = BluetoothProfile.INPUT_HOST; profileIndex = BluetoothProfile.HID_DEVICE; } return profileIndex; Loading Loading
android/app/AndroidManifest.xml +2 −2 Original line number Diff line number Diff line Loading @@ -329,7 +329,7 @@ android:name = ".hid.HidService" android:enabled="@bool/profile_supported_hid"> <intent-filter> <action android:name="android.bluetooth.IBluetoothInputDevice" /> <action android:name="android.bluetooth.IBluetoothHidHost" /> </intent-filter> </service> <service Loading Loading @@ -391,7 +391,7 @@ android:name = ".hid.HidDevService" android:enabled="@bool/profile_supported_hidd"> <intent-filter> <action android:name="android.bluetooth.IBluetoothInputHost" /> <action android:name="android.bluetooth.IBluetoothHidDevice" /> </intent-filter> </service> </application> Loading
android/app/src/com/android/bluetooth/btservice/AdapterProperties.java +43 −17 Original line number Diff line number Diff line Loading @@ -20,11 +20,12 @@ import android.bluetooth.BluetoothA2dp; import android.bluetooth.BluetoothA2dpSink; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothAvrcpController; import android.bluetooth.BluetoothClass; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothHeadset; import android.bluetooth.BluetoothHeadsetClient; import android.bluetooth.BluetoothInputDevice; import android.bluetooth.BluetoothInputHost; import android.bluetooth.BluetoothHidDevice; import android.bluetooth.BluetoothHidHost; import android.bluetooth.BluetoothMap; import android.bluetooth.BluetoothMapClient; import android.bluetooth.BluetoothPan; Loading Loading @@ -57,7 +58,7 @@ class AdapterProperties { private volatile String mName; private volatile byte[] mAddress; private volatile int mBluetoothClass; private volatile BluetoothClass mBluetoothClass; private volatile int mScanMode; private volatile int mDiscoverableTimeout; private volatile ParcelUuid[] mUuids; Loading Loading @@ -115,11 +116,11 @@ class AdapterProperties { case BluetoothA2dpSink.ACTION_CONNECTION_STATE_CHANGED: sendConnectionStateChange(BluetoothProfile.A2DP_SINK, intent); break; case BluetoothInputHost.ACTION_CONNECTION_STATE_CHANGED: sendConnectionStateChange(BluetoothProfile.INPUT_HOST, intent); case BluetoothHidDevice.ACTION_CONNECTION_STATE_CHANGED: sendConnectionStateChange(BluetoothProfile.HID_DEVICE, intent); break; case BluetoothInputDevice.ACTION_CONNECTION_STATE_CHANGED: sendConnectionStateChange(BluetoothProfile.INPUT_DEVICE, intent); case BluetoothHidHost.ACTION_CONNECTION_STATE_CHANGED: sendConnectionStateChange(BluetoothProfile.HID_HOST, intent); break; case BluetoothAvrcpController.ACTION_CONNECTION_STATE_CHANGED: sendConnectionStateChange(BluetoothProfile.AVRCP_CONTROLLER, intent); Loading Loading @@ -168,8 +169,8 @@ class AdapterProperties { filter.addAction(BluetoothHeadsetClient.ACTION_CONNECTION_STATE_CHANGED); filter.addAction(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED); filter.addAction(BluetoothA2dpSink.ACTION_CONNECTION_STATE_CHANGED); filter.addAction(BluetoothInputHost.ACTION_CONNECTION_STATE_CHANGED); filter.addAction(BluetoothInputDevice.ACTION_CONNECTION_STATE_CHANGED); filter.addAction(BluetoothHidDevice.ACTION_CONNECTION_STATE_CHANGED); filter.addAction(BluetoothHidHost.ACTION_CONNECTION_STATE_CHANGED); filter.addAction(BluetoothAvrcpController.ACTION_CONNECTION_STATE_CHANGED); filter.addAction(BluetoothPan.ACTION_CONNECTION_STATE_CHANGED); filter.addAction(BluetoothMap.ACTION_CONNECTION_STATE_CHANGED); Loading Loading @@ -217,21 +218,38 @@ class AdapterProperties { /** * Set the Bluetooth Class of Device (CoD) of the adapter. * * @param bytes BluetoothClass of the device * <p>Bluetooth stack stores some adapter properties in native BT stack storage and some in the * Java Android stack. Bluetooth CoD is stored in the Android layer through * {@link android.provider.Settings.Global#BLUETOOTH_CLASS_OF_DEVICE}. * * <p>Due to this, the getAdapterPropertyNative and adapterPropertyChangedCallback methods don't * actually update mBluetoothClass. Hence, we update the field mBluetoothClass every time we * successfully update BluetoothClass. * * @param bluetoothClass BluetoothClass of the device */ boolean setBluetoothClass(byte[] bytes) { boolean setBluetoothClass(BluetoothClass bluetoothClass) { synchronized (mObject) { return mService.setAdapterPropertyNative(AbstractionLayer.BT_PROPERTY_CLASS_OF_DEVICE, bytes); boolean result = mService.setAdapterPropertyNative(AbstractionLayer.BT_PROPERTY_CLASS_OF_DEVICE, bluetoothClass.getClassOfDeviceBytes()); if (result) { mBluetoothClass = bluetoothClass; } return result; } } /** * @return the mClass * @return the BluetoothClass of the Bluetooth adapter. */ int getBluetoothClass() { BluetoothClass getBluetoothClass() { synchronized (mObject) { return mBluetoothClass; } } /** * @return the mScanMode Loading Loading @@ -678,7 +696,15 @@ class AdapterProperties { AdapterService.BLUETOOTH_PERM); break; case AbstractionLayer.BT_PROPERTY_CLASS_OF_DEVICE: mBluetoothClass = Utils.byteArrayToInt(val, 0); if (val == null || val.length != 3) { debugLog("Invalid BT CoD value from stack."); return; } int bluetoothClass = ((int) val[0] << 16) + ((int) val[1] << 8) + (int) val[2]; if (bluetoothClass != 0) { mBluetoothClass = new BluetoothClass(bluetoothClass); } debugLog("BT Class:" + mBluetoothClass); break; case AbstractionLayer.BT_PROPERTY_ADAPTER_SCAN_MODE: Loading
android/app/src/com/android/bluetooth/btservice/AdapterService.java +58 −1 Original line number Diff line number Diff line Loading @@ -406,6 +406,7 @@ public class AdapterService extends Service { //Load the name and address getAdapterPropertyNative(AbstractionLayer.BT_PROPERTY_BDADDR); getAdapterPropertyNative(AbstractionLayer.BT_PROPERTY_BDNAME); getAdapterPropertyNative(AbstractionLayer.BT_PROPERTY_CLASS_OF_DEVICE); mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); mUserManager = (UserManager) getSystemService(Context.USER_SERVICE); Loading Loading @@ -511,6 +512,32 @@ public class AdapterService extends Service { setGattProfileServiceState(supportedProfileServices, BluetoothAdapter.STATE_ON); } /** * Sets the Bluetooth CoD value of the local adapter if there exists a config value for it. */ void setBluetoothClassFromConfig() { int bluetoothClassConfig = retrieveBluetoothClassConfig(); if (bluetoothClassConfig != 0) { mAdapterProperties.setBluetoothClass(new BluetoothClass(bluetoothClassConfig)); } } private int retrieveBluetoothClassConfig() { return Settings.Global.getInt( getContentResolver(), Settings.Global.BLUETOOTH_CLASS_OF_DEVICE, 0); } private boolean storeBluetoothClassConfig(int bluetoothClass) { boolean result = Settings.Global.putInt( getContentResolver(), Settings.Global.BLUETOOTH_CLASS_OF_DEVICE, bluetoothClass); if (!result) { Log.e(TAG, "Error storing BluetoothClass config - " + bluetoothClass); } return result; } void startCoreServices() { debugLog("startCoreServices()"); Class[] supportedProfileServices = Config.getSupportedProfiles(); Loading Loading @@ -901,6 +928,17 @@ public class AdapterService extends Service { return service.setName(name); } public BluetoothClass getBluetoothClass() { if (!Utils.checkCaller()) { Log.w(TAG, "getBluetoothClass() - Not allowed for non-active user"); return null; } AdapterService service = getService(); if (service == null) return null; return service.getBluetoothClass(); } public boolean setBluetoothClass(BluetoothClass bluetoothClass) { if (!Utils.checkCaller()) { Log.w(TAG, "setBluetoothClass() - Not allowed for non-active user"); Loading Loading @@ -1687,11 +1725,30 @@ public class AdapterService extends Service { return mAdapterProperties.setName(name); } BluetoothClass getBluetoothClass() { enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH ADMIN permission"); return mAdapterProperties.getBluetoothClass(); } /** * Sets the Bluetooth CoD on the local adapter and also modifies the storage config for it. * * <p>Once set, this value persists across reboots. */ boolean setBluetoothClass(BluetoothClass bluetoothClass) { enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, "Need BLUETOOTH PRIVILEGED permission"); return mAdapterProperties.setBluetoothClass(bluetoothClass.getClassOfDeviceBytes()); boolean result = mAdapterProperties.setBluetoothClass(bluetoothClass); if (!result) { Log.e(TAG, "Failed to set BluetoothClass (" + bluetoothClass + ") on local Bluetooth adapter."); } return result && storeBluetoothClassConfig(bluetoothClass.getClassOfDevice()); } int getScanMode() { Loading
android/app/src/com/android/bluetooth/btservice/AdapterState.java +1 −0 Original line number Diff line number Diff line Loading @@ -230,6 +230,7 @@ final class AdapterState extends StateMachine { return; } adapterService.updateUuids(); adapterService.setBluetoothClassFromConfig(); } @Override Loading
android/app/src/com/android/bluetooth/btservice/Config.java +2 −2 Original line number Diff line number Diff line Loading @@ -156,7 +156,7 @@ public class Config { } else if (profile == A2dpSinkService.class) { profileIndex = BluetoothProfile.A2DP_SINK; } else if (profile == HidService.class) { profileIndex = BluetoothProfile.INPUT_DEVICE; profileIndex = BluetoothProfile.HID_HOST; } else if (profile == HealthService.class) { profileIndex = BluetoothProfile.HEALTH; } else if (profile == PanService.class) { Loading @@ -176,7 +176,7 @@ public class Config { } else if (profile == MapClientService.class) { profileIndex = BluetoothProfile.MAP_CLIENT; } else if (profile == HidDevService.class) { profileIndex = BluetoothProfile.INPUT_HOST; profileIndex = BluetoothProfile.HID_DEVICE; } return profileIndex; Loading