RESTRICT AUTOMERGE 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
(cherry picked from commit d3abbb9821)
This commit is contained in:
Hugh Chen
2021-10-28 06:21:37 +00:00
parent 2642a3c73e
commit d4e0ed2284
3 changed files with 56 additions and 4 deletions

View File

@@ -55,6 +55,7 @@ public class DiscoverableFooterPreferenceController extends BasePreferenceContro
private FooterPreference mPreference;
private BluetoothAdapter mBluetoothAdapter;
private AlwaysDiscoverable mAlwaysDiscoverable;
private boolean mIsAlwaysDiscoverable;
public DiscoverableFooterPreferenceController(Context context) {
super(context, KEY);
@@ -119,7 +120,9 @@ public class DiscoverableFooterPreferenceController extends BasePreferenceContro
}
mContext.registerReceiver(mBluetoothChangedReceiver,
new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));
mAlwaysDiscoverable.start();
if (mIsAlwaysDiscoverable) {
mAlwaysDiscoverable.start();
}
updateFooterPreferenceTitle(mBluetoothAdapter.getState());
}
@@ -129,7 +132,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) {