1515import org .ostrya .presencepublisher .dialog .ConfirmationDialogFragment ;
1616import org .ostrya .presencepublisher .log .DatabaseLogger ;
1717
18+ import java .util .Map ;
1819import java .util .Queue ;
1920
20- public class EnsureBluetoothPermission extends AbstractChainedHandler <String , Boolean > {
21+ public class EnsureBluetoothPermission
22+ extends AbstractChainedHandler <String [], Map <String , Boolean >> {
2123 protected EnsureBluetoothPermission (MainActivity activity , Queue <HandlerFactory > handlerChain ) {
22- super (activity , new ActivityResultContracts .RequestPermission (), handlerChain );
24+ super (activity , new ActivityResultContracts .RequestMultiplePermissions (), handlerChain );
2325 }
2426
2527 @ Override
2628 protected void doInitialize () {
2729 if (activity .isLocationPermissionNeeded ()
2830 && activity .isBluetoothBeaconConfigured ()
2931 && Build .VERSION .SDK_INT >= Build .VERSION_CODES .S
30- && ContextCompat .checkSelfPermission (activity , Manifest .permission .BLUETOOTH_SCAN )
31- != PackageManager .PERMISSION_GRANTED ) {
32+ && (ContextCompat .checkSelfPermission (activity , Manifest .permission .BLUETOOTH_SCAN )
33+ != PackageManager .PERMISSION_GRANTED
34+ || ContextCompat .checkSelfPermission (
35+ activity , Manifest .permission .BLUETOOTH_CONNECT )
36+ != PackageManager .PERMISSION_GRANTED )) {
3237 DatabaseLogger .i (TAG , "Bluetooth scan permission not yet granted, asking user ..." );
3338 FragmentManager fm = activity .getSupportFragmentManager ();
3439 ConfirmationDialogFragment fragment =
@@ -45,19 +50,28 @@ protected void doInitialize() {
4550 @ RequiresApi (api = Build .VERSION_CODES .S )
4651 private void onResult (Activity parent , boolean ok ) {
4752 if (ok ) {
48- getLauncher ().launch (Manifest .permission .BLUETOOTH_SCAN );
53+ getLauncher ()
54+ .launch (
55+ new String [] {
56+ Manifest .permission .BLUETOOTH_SCAN ,
57+ Manifest .permission .BLUETOOTH_CONNECT
58+ });
4959 } else {
5060 finishInitialization ();
5161 }
5262 }
5363
5464 @ Override
55- protected void doHandleResult (Boolean result ) {
56- if (result ) {
57- DatabaseLogger .i (TAG , "Successfully granted bluetooth permission" );
58- } else {
59- DatabaseLogger .w (TAG , "Bluetooth permission not granted, continuing anyway" );
60- }
65+ protected void doHandleResult (Map <String , Boolean > result ) {
66+ result .forEach (
67+ (permission , enabled ) ->
68+ DatabaseLogger .i (
69+ TAG ,
70+ "Result for "
71+ + permission
72+ + ": "
73+ + (enabled ? "granted" : "not granted" )));
74+ DatabaseLogger .i (TAG , "Continuing initialization" );
6175 finishInitialization ();
6276 }
6377
0 commit comments