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

Commit 3a744246 authored by William Escande's avatar William Escande
Browse files

Notification helper is no longer airplane exclusif

Bug: 323060869
Bug: 316946334
Test: m Bluetooth
Test: atest CtsBluetoothTestCases
Change-Id: I0f3aa0c2bb3b4adcc6f34f7029e54565261cfc44
parent 84fb08e3
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -104,12 +104,12 @@
        </service>

        <service android:process="@string/process"
             android:name="com.android.bluetooth.airplane.NotificationHelperService"
             android:label="Airplane Notification Helper"
             android:name="com.android.bluetooth.notification.NotificationHelperService"
             android:label="Notification Helper"
             android:exported="true"
             android:permission="android.permission.BLUETOOTH_PRIVILEGED">
            <intent-filter>
                <action android:name="android.bluetooth.airplane.action.SEND_NOTIFICATION"/>
                <action android:name="android.bluetooth.notification.action.SEND_TOGGLE_NOTIFICATION"/>
            </intent-filter>
        </service>

+13 −13
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
 * limitations under the License.
 */

package com.android.bluetooth.airplane;
package com.android.bluetooth.notification;

import static java.util.Objects.requireNonNull;

@@ -47,8 +47,8 @@ public class NotificationHelperService extends Service {
    private static final String APM_BT_ENABLED_NOTIFICATION = "apm_bt_enabled_notification";

    private static final String NOTIFICATION_TAG = "com.android.bluetooth";
    private static final String APM_NOTIFICATION_CHANNEL = "apm_notification_channel";
    private static final String APM_NOTIFICATION_GROUP = "apm_notification_group";
    private static final String NOTIFICATION_CHANNEL = "notification_toggle_channel";
    private static final String NOTIFICATION_GROUP = "notification_toggle_group";

    private static final Map<String, Pair<Integer /* titleId */, Integer /* messageId */>>
            NOTIFICATION_MAP =
@@ -73,24 +73,24 @@ public class NotificationHelperService extends Service {

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        sendAirplaneModeNotification(
                intent.getStringExtra("android.bluetooth.airplane.extra.NOTIFICATION_STATE"));
        sendToggleNotification(
                intent.getStringExtra("android.bluetooth.notification.extra.NOTIFICATION_REASON"));
        return Service.START_NOT_STICKY;
    }

    private void sendAirplaneModeNotification(String notificationState) {
        String logHeader = "sendAirplaneModeNotification(" + notificationState + "): ";
        Pair<Integer, Integer> notificationContent = NOTIFICATION_MAP.get(notificationState);
    private void sendToggleNotification(String notificationReason) {
        String logHeader = "sendToggleNotification(" + notificationReason + "): ";
        Pair<Integer, Integer> notificationContent = NOTIFICATION_MAP.get(notificationReason);
        if (notificationContent == null) {
            Log.e(TAG, logHeader + "unknown action");
            return;
        }

        if (!isFirstTimeNotification(notificationState)) {
        if (!isFirstTimeNotification(notificationReason)) {
            Log.d(TAG, logHeader + "already displayed");
            return;
        }
        Settings.Secure.putInt(getContentResolver(), notificationState, 1);
        Settings.Secure.putInt(getContentResolver(), notificationReason, 1);

        Log.d(TAG, logHeader + "sending");

@@ -104,8 +104,8 @@ public class NotificationHelperService extends Service {

        notificationManager.createNotificationChannel(
                new NotificationChannel(
                        APM_NOTIFICATION_CHANNEL,
                        APM_NOTIFICATION_GROUP,
                        NOTIFICATION_CHANNEL,
                        NOTIFICATION_GROUP,
                        NotificationManager.IMPORTANCE_HIGH));

        String title = getString(notificationContent.first);
@@ -115,7 +115,7 @@ public class NotificationHelperService extends Service {
        notificationManager.notify(
                NOTIFICATION_TAG,
                SystemMessage.ID.NOTE_BT_APM_NOTIFICATION_VALUE,
                new Notification.Builder(this, APM_NOTIFICATION_CHANNEL)
                new Notification.Builder(this, NOTIFICATION_CHANNEL)
                        .setAutoCancel(true)
                        .setLocalOnly(true)
                        .setContentTitle(title)
+3 −3
Original line number Diff line number Diff line
@@ -227,9 +227,9 @@ class BluetoothAirplaneModeListener extends Handler {
        } else {
            if (mFeatureFlags.airplaneRessourcesInApp()) {
                if (isWifiEnabledOnApm()) {
                    mBluetoothManager.sendAirplaneModeNotification(APM_WIFI_BT_NOTIFICATION);
                    mBluetoothManager.sendToggleNotification(APM_WIFI_BT_NOTIFICATION);
                } else {
                    mBluetoothManager.sendAirplaneModeNotification(APM_BT_NOTIFICATION);
                    mBluetoothManager.sendToggleNotification(APM_BT_NOTIFICATION);
                }
                return;
            }
@@ -330,7 +330,7 @@ class BluetoothAirplaneModeListener extends Handler {
            setSettingsSecureInt(APM_USER_TOGGLED_BLUETOOTH, USED);
            if (mFeatureFlags.airplaneRessourcesInApp()) {
                if (isOn) {
                    mBluetoothManager.sendAirplaneModeNotification(APM_BT_ENABLED_NOTIFICATION);
                    mBluetoothManager.sendToggleNotification(APM_BT_ENABLED_NOTIFICATION);
                }
                return;
            }
+6 −4
Original line number Diff line number Diff line
@@ -429,10 +429,12 @@ class BluetoothManagerService {
    }

    /** Send Intent to the Notification Service in the Bluetooth app */
    Unit sendAirplaneModeNotification(String notificationState) {
        Intent intent = new Intent("android.bluetooth.airplane.action.SEND_NOTIFICATION");
    Unit sendToggleNotification(String notificationReason) {
        Intent intent =
                new Intent("android.bluetooth.notification.action.SEND_TOGGLE_NOTIFICATION");
        intent.setComponent(resolveSystemService(intent));
        intent.putExtra("android.bluetooth.airplane.extra.NOTIFICATION_STATE", notificationState);
        intent.putExtra(
                "android.bluetooth.notification.extra.NOTIFICATION_REASON", notificationReason);
        mContext.startService(intent);
        return Unit.INSTANCE;
    }
@@ -1303,7 +1305,7 @@ class BluetoothManagerService {
                    mContentResolver,
                    mState,
                    this::onAirplaneModeChanged,
                    this::sendAirplaneModeNotification,
                    this::sendToggleNotification,
                    this::isMediaProfileConnected,
                    this::getCurrentUserContext,
                    TimeSource.Monotonic.INSTANCE);
+2 −2
Original line number Diff line number Diff line
@@ -241,7 +241,7 @@ public class BluetoothAirplaneModeListenerTest {

        mBluetoothAirplaneModeListener.handleAirplaneModeChange(true);

        verify(mBluetoothManagerService).sendAirplaneModeNotification(eq(APM_WIFI_BT_NOTIFICATION));
        verify(mBluetoothManagerService).sendToggleNotification(eq(APM_WIFI_BT_NOTIFICATION));
    }

    @Test
@@ -287,7 +287,7 @@ public class BluetoothAirplaneModeListenerTest {

        mBluetoothAirplaneModeListener.handleAirplaneModeChange(true);

        verify(mBluetoothManagerService).sendAirplaneModeNotification(eq(APM_BT_NOTIFICATION));
        verify(mBluetoothManagerService).sendToggleNotification(eq(APM_BT_NOTIFICATION));
    }

    @Test