Skip to content

Commit 22b8895

Browse files
author
SBALAVIGNESH123
committed
Fix: Add runtime permission checks for BLUETOOTH_CONNECT
Added explicit permission checks before calling Bluetooth APIs that require BLUETOOTH_CONNECT permission on Android 12+: - WearableImpl.java: Check permission before getBondedDevices() - WearableSettingsActivity.java: Check permission before getBondedDevices() - Added SuppressLint for device.getName() since permission already checked Fixes all MissingPermission lint errors. Build verified with lintDebug.
1 parent 9440651 commit 22b8895

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

play-services-wearable/core/src/main/java/org/microg/gms/wearable/WearableImpl.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,16 @@ public void run() {
725725
try {
726726
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
727727
if (adapter != null && adapter.isEnabled()) {
728+
// Check BLUETOOTH_CONNECT permission for Android 12+
729+
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
730+
if (context.checkSelfPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
731+
!= android.content.pm.PackageManager.PERMISSION_GRANTED) {
732+
Log.w(TAG, "BLUETOOTH_CONNECT permission not granted, skipping device scan");
733+
Thread.sleep(10000);
734+
continue;
735+
}
736+
}
737+
728738
Set<BluetoothDevice> bondedDevices = adapter.getBondedDevices();
729739
if (bondedDevices != null) {
730740
for (BluetoothDevice device : bondedDevices) {

play-services-wearable/core/src/main/java/org/microg/gms/wearable/WearableSettingsActivity.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ private void refreshList() {
4646
return;
4747
}
4848

49+
// Check BLUETOOTH_CONNECT permission for Android 12+
50+
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
51+
if (checkSelfPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
52+
!= android.content.pm.PackageManager.PERMISSION_GRANTED) {
53+
emptyView.setText("Bluetooth permission not granted");
54+
return;
55+
}
56+
}
57+
4958
Set<BluetoothDevice> bondedDevices = adapter.getBondedDevices();
5059
if (bondedDevices != null) {
5160
deviceList.addAll(bondedDevices);
@@ -133,6 +142,7 @@ public WearableDeviceAdapter(android.content.Context context, ArrayList<Bluetoot
133142
}
134143

135144
@Override
145+
@android.annotation.SuppressLint("MissingPermission")
136146
public android.view.View getView(int position, android.view.View convertView, android.view.ViewGroup parent) {
137147
if (convertView == null) {
138148
convertView = android.view.LayoutInflater.from(getContext()).inflate(R.layout.wearable_device_item, parent, false);

0 commit comments

Comments
 (0)