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

Commit 15462606 authored by Matías Hernández's avatar Matías Hernández
Browse files

Delete super-obsolete zen onboarding

A notification was shown when upgrading from pre-P to P because default DND settings had changed. The default was later changed back so it was already obsolete at that point. Moreover, it should be impossible to upgrade from pre-P to V in one step.

Bug: 346789065
Test: atest SystemNotificationChannelsTest for channel removal, otherwise N/A since this is code deletion
Flag: EXEMPT Unflaggable -- removing resources, manifest entries, etc.
Change-Id: I1c6af0e25b15108554c5fd57abff23da5d2a749e
parent 6f273d49
Loading
Loading
Loading
Loading
+0 −84
Original line number Diff line number Diff line
@@ -2091,23 +2091,6 @@ public final class Settings {
    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
    public static final String ACTION_ZEN_MODE_SETTINGS = "android.settings.ZEN_MODE_SETTINGS";
    /**
     * Activity Action: Show Zen Mode visual effects configuration settings.
     *
     * @hide
     */
    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
    public static final String ZEN_MODE_BLOCKED_EFFECTS_SETTINGS =
            "android.settings.ZEN_MODE_BLOCKED_EFFECTS_SETTINGS";
    /**
     * Activity Action: Show Zen Mode onboarding activity.
     *
     * @hide
     */
    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
    public static final String ZEN_MODE_ONBOARDING = "android.settings.ZEN_MODE_ONBOARDING";
    /**
     * Activity Action: Show Zen Mode (aka Do Not Disturb) priority configuration settings.
     */
@@ -8747,35 +8730,6 @@ public final class Settings {
        /** @hide */ public static final int ZEN_DURATION_PROMPT = -1;
        /** @hide */ public static final int ZEN_DURATION_FOREVER = 0;
        /**
         * If nonzero, will show the zen upgrade notification when the user toggles DND on/off.
         * @hide
         */
        @Readable
        public static final String SHOW_ZEN_UPGRADE_NOTIFICATION = "show_zen_upgrade_notification";
        /**
         * If nonzero, will show the zen update settings suggestion.
         * @hide
         */
        @Readable
        public static final String SHOW_ZEN_SETTINGS_SUGGESTION = "show_zen_settings_suggestion";
        /**
         * If nonzero, zen has not been updated to reflect new changes.
         * @hide
         */
        @Readable
        public static final String ZEN_SETTINGS_UPDATED = "zen_settings_updated";
        /**
         * If nonzero, zen setting suggestion has been viewed by user
         * @hide
         */
        @Readable
        public static final String ZEN_SETTINGS_SUGGESTION_VIEWED =
                "zen_settings_suggestion_viewed";
        /**
         * Whether the in call notification is enabled to play sound during calls.  The value is
         * boolean (1 or 0).
@@ -18062,10 +18016,6 @@ public final class Settings {
            MOVED_TO_SECURE = new HashSet<>(8);
            MOVED_TO_SECURE.add(Global.INSTALL_NON_MARKET_APPS);
            MOVED_TO_SECURE.add(Global.ZEN_DURATION);
            MOVED_TO_SECURE.add(Global.SHOW_ZEN_UPGRADE_NOTIFICATION);
            MOVED_TO_SECURE.add(Global.SHOW_ZEN_SETTINGS_SUGGESTION);
            MOVED_TO_SECURE.add(Global.ZEN_SETTINGS_UPDATED);
            MOVED_TO_SECURE.add(Global.ZEN_SETTINGS_SUGGESTION_VIEWED);
            MOVED_TO_SECURE.add(Global.CHARGING_SOUNDS_ENABLED);
            MOVED_TO_SECURE.add(Global.CHARGING_VIBRATION_ENABLED);
            MOVED_TO_SECURE.add(Global.NOTIFICATION_BUBBLES);
@@ -18900,40 +18850,6 @@ public final class Settings {
        @Readable
        public static final String SHOW_MUTE_IN_CRASH_DIALOG = "show_mute_in_crash_dialog";
        /**
         * If nonzero, will show the zen upgrade notification when the user toggles DND on/off.
         * @hide
         * @deprecated - Use {@link android.provider.Settings.Secure#SHOW_ZEN_UPGRADE_NOTIFICATION}
         */
        @Deprecated
        public static final String SHOW_ZEN_UPGRADE_NOTIFICATION = "show_zen_upgrade_notification";
        /**
         * If nonzero, will show the zen update settings suggestion.
         * @hide
         * @deprecated - Use {@link android.provider.Settings.Secure#SHOW_ZEN_SETTINGS_SUGGESTION}
         */
        @Deprecated
        public static final String SHOW_ZEN_SETTINGS_SUGGESTION = "show_zen_settings_suggestion";
        /**
         * If nonzero, zen has not been updated to reflect new changes.
         * @deprecated - Use {@link android.provider.Settings.Secure#ZEN_SETTINGS_UPDATED}
         * @hide
         */
        @Deprecated
        public static final String ZEN_SETTINGS_UPDATED = "zen_settings_updated";
        /**
         * If nonzero, zen setting suggestion has been viewed by user
         * @hide
         * @deprecated - Use {@link android.provider.Settings.Secure#ZEN_SETTINGS_SUGGESTION_VIEWED}
         */
        @Deprecated
        public static final String ZEN_SETTINGS_SUGGESTION_VIEWED =
                "zen_settings_suggestion_viewed";
        /**
         * Backup and restore agent timeout parameters.
         * These parameters are represented by a comma-delimited key-value list.
+30 −29
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.media.AudioAttributes;
import android.os.RemoteException;

import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;

import java.util.ArrayList;
import java.util.Arrays;
@@ -37,38 +38,40 @@ public class SystemNotificationChannels {
     * @deprecated Legacy system channel, which is no longer used,
     */
    @Deprecated public static String VIRTUAL_KEYBOARD  = "VIRTUAL_KEYBOARD";
    public static String PHYSICAL_KEYBOARD = "PHYSICAL_KEYBOARD";
    public static String SECURITY = "SECURITY";
    public static String CAR_MODE = "CAR_MODE";
    public static String ACCOUNT = "ACCOUNT";
    public static String DEVELOPER = "DEVELOPER";
    public static String DEVELOPER_IMPORTANT = "DEVELOPER_IMPORTANT";
    public static String UPDATES = "UPDATES";
    public static String NETWORK_STATUS = "NETWORK_STATUS";
    public static String NETWORK_ALERTS = "NETWORK_ALERTS";
    public static String NETWORK_AVAILABLE = "NETWORK_AVAILABLE";
    public static String VPN = "VPN";
    public static final String PHYSICAL_KEYBOARD = "PHYSICAL_KEYBOARD";
    public static final String SECURITY = "SECURITY";
    public static final String CAR_MODE = "CAR_MODE";
    public static final String ACCOUNT = "ACCOUNT";
    public static final String DEVELOPER = "DEVELOPER";
    public static final String DEVELOPER_IMPORTANT = "DEVELOPER_IMPORTANT";
    public static final String UPDATES = "UPDATES";
    public static final String NETWORK_STATUS = "NETWORK_STATUS";
    public static final String NETWORK_ALERTS = "NETWORK_ALERTS";
    public static final String NETWORK_AVAILABLE = "NETWORK_AVAILABLE";
    public static final String VPN = "VPN";
    /**
     * @deprecated Legacy device admin channel with low importance which is no longer used,
     *  Use the high importance {@link #DEVICE_ADMIN} channel instead.
     */
    @Deprecated public static String DEVICE_ADMIN_DEPRECATED = "DEVICE_ADMIN";
    public static String DEVICE_ADMIN = "DEVICE_ADMIN_ALERTS";
    public static String ALERTS = "ALERTS";
    public static String RETAIL_MODE = "RETAIL_MODE";
    public static String USB = "USB";
    public static String FOREGROUND_SERVICE = "FOREGROUND_SERVICE";
    public static String HEAVY_WEIGHT_APP = "HEAVY_WEIGHT_APP";
    @Deprecated public static final String DEVICE_ADMIN_DEPRECATED = "DEVICE_ADMIN";
    public static final String DEVICE_ADMIN = "DEVICE_ADMIN_ALERTS";
    public static final String ALERTS = "ALERTS";
    public static final String RETAIL_MODE = "RETAIL_MODE";
    public static final String USB = "USB";
    public static final String FOREGROUND_SERVICE = "FOREGROUND_SERVICE";
    public static final String HEAVY_WEIGHT_APP = "HEAVY_WEIGHT_APP";
    /**
     * @deprecated Legacy system changes channel with low importance which is no longer used,
     *  Use the default importance {@link #SYSTEM_CHANGES} channel instead.
     */
    @Deprecated public static String SYSTEM_CHANGES_DEPRECATED = "SYSTEM_CHANGES";
    public static String SYSTEM_CHANGES = "SYSTEM_CHANGES_ALERTS";
    public static String DO_NOT_DISTURB = "DO_NOT_DISTURB";
    public static String ACCESSIBILITY_MAGNIFICATION = "ACCESSIBILITY_MAGNIFICATION";
    public static String ACCESSIBILITY_SECURITY_POLICY = "ACCESSIBILITY_SECURITY_POLICY";
    public static String ABUSIVE_BACKGROUND_APPS = "ABUSIVE_BACKGROUND_APPS";
    @Deprecated public static final String SYSTEM_CHANGES_DEPRECATED = "SYSTEM_CHANGES";
    public static final String SYSTEM_CHANGES = "SYSTEM_CHANGES_ALERTS";
    public static final String ACCESSIBILITY_MAGNIFICATION = "ACCESSIBILITY_MAGNIFICATION";
    public static final String ACCESSIBILITY_SECURITY_POLICY = "ACCESSIBILITY_SECURITY_POLICY";
    public static final String ABUSIVE_BACKGROUND_APPS = "ABUSIVE_BACKGROUND_APPS";

    @VisibleForTesting
    static final String OBSOLETE_DO_NOT_DISTURB = "DO_NOT_DISTURB";

    public static void createAll(Context context) {
        final NotificationManager nm = context.getSystemService(NotificationManager.class);
@@ -193,11 +196,6 @@ public class SystemNotificationChannels {
                .build());
        channelsList.add(systemChanges);

        NotificationChannel dndChanges = new NotificationChannel(DO_NOT_DISTURB,
                context.getString(R.string.notification_channel_do_not_disturb),
                NotificationManager.IMPORTANCE_LOW);
        channelsList.add(dndChanges);

        final NotificationChannel newFeaturePrompt = new NotificationChannel(
                ACCESSIBILITY_MAGNIFICATION,
                context.getString(R.string.notification_channel_accessibility_magnification),
@@ -218,6 +216,9 @@ public class SystemNotificationChannels {
        channelsList.add(abusiveBackgroundAppsChannel);

        nm.createNotificationChannels(channelsList);

        // Delete channels created by previous Android versions that are no longer used.
        nm.deleteNotificationChannel(OBSOLETE_DO_NOT_DISTURB);
    }

    private static String getDeviceAdminNotificationChannelName(Context context) {
+0 −10
Original line number Diff line number Diff line
@@ -5818,16 +5818,6 @@

    <!-- Title for the notification channel notifying user of settings system changes. [CHAR LIMIT=NONE] -->
    <string name="notification_channel_system_changes">System changes</string>
    <!-- Title for the notification channel notifying user of do not disturb system changes (i.e. Do Not Disturb has changed). [CHAR LIMIT=NONE] -->
    <string name="notification_channel_do_not_disturb">Do Not Disturb</string>
    <!-- Title of notification indicating do not disturb visual interruption settings have changed when upgrading to P -->
    <string name="zen_upgrade_notification_visd_title">New: Do Not Disturb is hiding notifications</string>
    <!-- Content of notification indicating users can tap on the notification to go to dnd behavior settings -->
    <string name="zen_upgrade_notification_visd_content">Tap to learn more and change.</string>
    <!-- Title of notification indicating do not disturb settings have changed when upgrading to P -->
    <string name="zen_upgrade_notification_title">Do Not Disturb has changed</string>
    <!-- Content of notification indicating users can tap on the notification to go to dnd behavior settings -->
    <string name="zen_upgrade_notification_content">Tap to check what\'s blocked.</string>

    <!-- Notification permission informational notification text -->
    <!-- Title for notification inviting users to review their notification settings [CHAR LIMIT=NONE] -->
+0 −6
Original line number Diff line number Diff line
@@ -3933,7 +3933,6 @@
  <java-symbol type="string" name="notification_channel_usb" />
  <java-symbol type="string" name="notification_channel_heavy_weight_app" />
  <java-symbol type="string" name="notification_channel_system_changes" />
  <java-symbol type="string" name="notification_channel_do_not_disturb" />
  <java-symbol type="string" name="notification_channel_accessibility_magnification" />
  <java-symbol type="string" name="notification_channel_accessibility_security_policy" />
  <java-symbol type="string" name="notification_channel_display" />
@@ -4160,11 +4159,6 @@
  <!-- For Wear devices -->
  <java-symbol type="array" name="config_wearActivityModeRadios" />

  <java-symbol type="string" name="zen_upgrade_notification_title" />
  <java-symbol type="string" name="zen_upgrade_notification_content" />
  <java-symbol type="string" name="zen_upgrade_notification_visd_title" />
  <java-symbol type="string" name="zen_upgrade_notification_visd_content" />

  <java-symbol type="string" name="review_notification_settings_title" />
  <java-symbol type="string" name="review_notification_settings_text" />
  <java-symbol type="string" name="review_notification_settings_remind_me_action" />
+107 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.notification;

import static com.android.internal.notification.SystemNotificationChannels.ABUSIVE_BACKGROUND_APPS;
import static com.android.internal.notification.SystemNotificationChannels.ACCESSIBILITY_MAGNIFICATION;
import static com.android.internal.notification.SystemNotificationChannels.ACCESSIBILITY_SECURITY_POLICY;
import static com.android.internal.notification.SystemNotificationChannels.ACCOUNT;
import static com.android.internal.notification.SystemNotificationChannels.ALERTS;
import static com.android.internal.notification.SystemNotificationChannels.CAR_MODE;
import static com.android.internal.notification.SystemNotificationChannels.DEVELOPER;
import static com.android.internal.notification.SystemNotificationChannels.DEVELOPER_IMPORTANT;
import static com.android.internal.notification.SystemNotificationChannels.DEVICE_ADMIN;
import static com.android.internal.notification.SystemNotificationChannels.FOREGROUND_SERVICE;
import static com.android.internal.notification.SystemNotificationChannels.HEAVY_WEIGHT_APP;
import static com.android.internal.notification.SystemNotificationChannels.NETWORK_ALERTS;
import static com.android.internal.notification.SystemNotificationChannels.NETWORK_AVAILABLE;
import static com.android.internal.notification.SystemNotificationChannels.NETWORK_STATUS;
import static com.android.internal.notification.SystemNotificationChannels.OBSOLETE_DO_NOT_DISTURB;
import static com.android.internal.notification.SystemNotificationChannels.PHYSICAL_KEYBOARD;
import static com.android.internal.notification.SystemNotificationChannels.RETAIL_MODE;
import static com.android.internal.notification.SystemNotificationChannels.SECURITY;
import static com.android.internal.notification.SystemNotificationChannels.SYSTEM_CHANGES;
import static com.android.internal.notification.SystemNotificationChannels.UPDATES;
import static com.android.internal.notification.SystemNotificationChannels.USB;
import static com.android.internal.notification.SystemNotificationChannels.VPN;

import static com.google.common.truth.Truth.assertThat;

import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.verify;

import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.testing.TestableContext;

import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import java.util.List;

@RunWith(AndroidJUnit4.class)
public class SystemNotificationChannelsTest {

    @Rule public TestableContext mContext = new TestableContext(
            ApplicationProvider.getApplicationContext());

    @Mock private NotificationManager mNm;

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        mContext.addMockSystemService(NotificationManager.class, mNm);
    }

    @Test
    @SuppressWarnings("unchecked")
    public void createAll_createsExpectedChannels() {
        ArgumentCaptor<List<NotificationChannel>> createdChannelsCaptor =
                ArgumentCaptor.forClass(List.class);

        SystemNotificationChannels.createAll(mContext);

        verify(mNm).createNotificationChannels(createdChannelsCaptor.capture());
        List<NotificationChannel> createdChannels = createdChannelsCaptor.getValue();
        assertThat(createdChannels.stream().map(NotificationChannel::getId).toList())
                .containsExactly(PHYSICAL_KEYBOARD, SECURITY, CAR_MODE, ACCOUNT, DEVELOPER,
                        DEVELOPER_IMPORTANT, UPDATES, NETWORK_STATUS, NETWORK_ALERTS,
                        NETWORK_AVAILABLE, VPN, DEVICE_ADMIN, ALERTS, RETAIL_MODE, USB,
                        FOREGROUND_SERVICE, HEAVY_WEIGHT_APP, SYSTEM_CHANGES,
                        ACCESSIBILITY_MAGNIFICATION, ACCESSIBILITY_SECURITY_POLICY,
                        ABUSIVE_BACKGROUND_APPS);
    }

    @Test
    public void createAll_deletesObsoleteChannels() {
        ArgumentCaptor<String> deletedChannelCaptor = ArgumentCaptor.forClass(String.class);

        SystemNotificationChannels.createAll(mContext);

        verify(mNm, atLeastOnce()).deleteNotificationChannel(deletedChannelCaptor.capture());
        List<String> deletedChannels = deletedChannelCaptor.getAllValues();
        assertThat(deletedChannels).containsExactly(OBSOLETE_DO_NOT_DISTURB);
    }
}
Loading