Fix make Bluetooth discoverable without additional permission

- Only enable device can be discoverable when the user launch
  "Connected Devices settings" through settings and systemui

Bug: 194695497
Test: make -j42 RunSettingsRoboTests and use test apk to manually test
to verify the device is not discoversable when open "Connected settings"
through test apk.

Change-Id: Ia04ab759b737acf30b782f5c5831dd59f25fb257
This commit is contained in:
Hugh Chen
2021-10-28 06:21:37 +00:00
parent 663e79cd94
commit d3abbb9821
3 changed files with 55 additions and 4 deletions

View File

@@ -52,6 +52,7 @@ public class DiscoverableFooterPreferenceController extends BasePreferenceContro
private BluetoothAdapter mBluetoothAdapter;
private AlwaysDiscoverable mAlwaysDiscoverable;
private FooterPreference mPreference;
private boolean mIsAlwaysDiscoverable;
public DiscoverableFooterPreferenceController(Context context, String key) {
super(context, key);
@@ -84,7 +85,9 @@ public class DiscoverableFooterPreferenceController extends BasePreferenceContro
}
mContext.registerReceiver(mBluetoothChangedReceiver,
new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));
mAlwaysDiscoverable.start();
if (mIsAlwaysDiscoverable) {
mAlwaysDiscoverable.start();
}
updateFooterPreferenceTitle(mBluetoothAdapter.getState());
}
@@ -94,7 +97,19 @@ public class DiscoverableFooterPreferenceController extends BasePreferenceContro
return;
}
mContext.unregisterReceiver(mBluetoothChangedReceiver);
mAlwaysDiscoverable.stop();
if (mIsAlwaysDiscoverable) {
mAlwaysDiscoverable.stop();
}
}
/**
* Set whether the device can be discovered. By default the value will be {@code false}.
*
* @param isAlwaysDiscoverable {@code true} if the device can be discovered,
* otherwise {@code false}
*/
public void setAlwaysDiscoverable(boolean isAlwaysDiscoverable) {
mIsAlwaysDiscoverable = isAlwaysDiscoverable;
}
private void updateFooterPreferenceTitle(int bluetoothState) {