Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1bdf1f4b authored by William Escande's avatar William Escande Committed by Gerrit Code Review
Browse files

Merge changes Ib3d1ffac,I115acb0d,I9c1ca329 into main

* changes:
  AutoOnFeature: Remove popup action
  AutoOnFeature: Open settings page on click
  AutoOn Feature: Update string in popup
parents f7365683 bd1b6540
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -110,7 +110,6 @@
             android:permission="android.permission.BLUETOOTH_PRIVILEGED">
            <intent-filter>
                <action android:name="android.bluetooth.notification.action.SEND_TOGGLE_NOTIFICATION"/>
                <action android:name="android.bluetooth.notification.action.AUTO_ON_USER_ACTION"/>
            </intent-filter>
        </service>

+2 −3
Original line number Diff line number Diff line
@@ -256,8 +256,7 @@
    <string name="bluetooth_stays_on_message">Your device remembers to keep Bluetooth on in airplane mode. Turn off Bluetooth if you don\'t want it to stay on.</string>
    <string name="bluetooth_and_wifi_stays_on_title">Wi-Fi and Bluetooth stay on</string>
    <string name="bluetooth_and_wifi_stays_on_message">Your device remembers to keep Wi-Fi and Bluetooth on in airplane mode. Turn off Wi-Fi and Bluetooth if you don\'t want them to stay on.</string>
    <string name="bluetooth_enabled_auto_on_title">Bluetooth has been automatically enabled</string>
    <string name="bluetooth_enabled_auto_on_message">Automatic restart can be toggled in Bluetooth Settings.</string>
    <string name="bluetooth_disable_auto_on">Turn off</string>
    <string name="bluetooth_enabled_auto_on_title">Bluetooth turned back on</string>
    <string name="bluetooth_enabled_auto_on_message">You can change this anytime in Settings</string>
    <string name="bluetooth_notification_group">Bluetooth automatic state change</string>
</resources>
+6 −31
Original line number Diff line number Diff line
@@ -23,9 +23,7 @@ import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.bluetooth.BluetoothManager;
import android.content.Intent;
import android.graphics.drawable.Icon;
import android.net.Uri;
import android.os.IBinder;
import android.provider.Settings;
@@ -61,9 +59,6 @@ public class NotificationHelperService extends Service {
    private static final String NOTIFICATION_EXTRA =
            "android.bluetooth.notification.extra.NOTIFICATION_REASON";

    private static final String AUTO_ON_USER_ACTION =
            "android.bluetooth.notification.action.AUTO_ON_USER_ACTION";

    private static final Map<String, Pair<Integer /* titleId */, Integer /* messageId */>>
            NOTIFICATION_MAP =
                    Map.of(
@@ -95,9 +90,6 @@ public class NotificationHelperService extends Service {
            case NOTIFICATION_ACTION -> {
                sendToggleNotification(intent.getStringExtra(NOTIFICATION_EXTRA));
            }
            case AUTO_ON_USER_ACTION -> {
                autoOnUserAction();
            }
        }
        return Service.START_NOT_STICKY;
    }
@@ -154,22 +146,13 @@ public class NotificationHelperService extends Service {
                                    .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK),
                            PendingIntent.FLAG_IMMUTABLE));
        } else {
            Intent baseIntent =
                    new Intent()
                            .setAction(AUTO_ON_USER_ACTION)
                            .setClass(this, NotificationHelperService.class);
            PendingIntent disablePendingIntent =
                    PendingIntent.getService(
            // Open the setting page when the notification is clicked
            builder.setContentIntent(
                    PendingIntent.getActivity(
                            this,
                            0,
                            new Intent(baseIntent),
                            PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_ONE_SHOT);
            builder.addAction(
                    new Notification.Action.Builder(
                                    Icon.createWithResource(this, R.drawable.ic_bluetooth_settings),
                                    getString(R.string.bluetooth_disable_auto_on),
                                    disablePendingIntent)
                            .build());
                            PendingIntent.FLAG_UPDATE_CURRENT,
                            new Intent("android.settings.BLUETOOTH_DASHBOARD_SETTINGS"),
                            PendingIntent.FLAG_IMMUTABLE));
        }

        notificationManager.notify(
@@ -209,12 +192,4 @@ public class NotificationHelperService extends Service {
                        + (" savedDate=" + savedDate));
        return true;
    }

    /** Process the tap on the Auto On popup action, that will disable the feature */
    private void autoOnUserAction() {
        getSystemService(BluetoothManager.class).getAdapter().setAutoOnEnabled(false);
        String tag = NOTIFICATION_TAG + "/" + AUTO_ON_BT_ENABLED_NOTIFICATION;
        getSystemService(NotificationManager.class)
                .cancel(tag, SystemMessage.ID.NOTE_BT_APM_NOTIFICATION_VALUE);
    }
}