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

Commit 8e89047f authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Update bundle list settings

- don't show them if it's not relevant
- don't link to the channel page, but rather to the feature page

Test: BundleListPreferenceControllerTest
Flag: android.app.notification_classification_ui
Fixes: 406311201
Fixes: 405981639
Change-Id: I27d29181df54b481d2f912d6a5c68ebd82cb94d2
parent df06b6e5
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -259,7 +259,8 @@ public class NotificationBackend {
            return null;
        }
        try {
            return sINM.getNotificationChannelForPackage(pkg, uid, channelId, conversationId, true);
            return sINM.getNotificationChannelForPackage(
                    pkg, uid, channelId, conversationId, false);
        } catch (Exception e) {
            Log.w(TAG, "Error calling NoMan", e);
            return null;
+36 −5
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import static android.app.NotificationChannel.RECS_ID;
import static android.app.NotificationChannel.SOCIAL_MEDIA_ID;
import static android.app.NotificationManager.IMPORTANCE_LOW;
import static android.app.NotificationManager.IMPORTANCE_NONE;
import static android.service.notification.Adjustment.KEY_TYPE;

import static com.android.server.notification.Flags.notificationHideUnusedChannels;

@@ -47,6 +48,7 @@ import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.applications.AppInfoBase;
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.notification.BundlePreferenceFragment;
import com.android.settings.notification.NotificationBackend;
import com.android.settingslib.PrimarySwitchPreference;
import com.android.settingslib.RestrictedSwitchPreference;
@@ -73,9 +75,15 @@ public class BundleListPreferenceController extends NotificationPreferenceContro
        if (!Flags.notificationClassification()) {
            return false;
        }
        if (!mBackend.isNotificationBundlingSupported()) {
            return false;
        }
        if (mAppRow == null) {
            return false;
        }
        if (!mBackend.getAllowedAssistantAdjustments(mAppRow.pkg).contains(KEY_TYPE)) {
            return false;
        }
        if (mAppRow.banned || mAppRow.lockedImportance || mAppRow.systemApp) {
            return false;
        }
@@ -121,15 +129,38 @@ public class BundleListPreferenceController extends NotificationPreferenceContro
        for (int i = 0; i < preferenceCount; i++) {
            Preference preference = groupPrefGroup.getPreference(i);
            if (channel.getId().equals(preference.getKey())) {
                if (android.app.Flags.notificationClassificationUi()) {
                    updateSingleChannelPref(preference, channel);
                } else {
                    updateSingleChannelPrefs((PrimarySwitchPreference) preference, channel);
                }
                return;
            }
        }
        if (android.app.Flags.notificationClassificationUi()) {
            Preference pref = new Preference(mContext);
            pref.setKey(channel.getId());
            updateSingleChannelPref(pref, channel);
            groupPrefGroup.addPreference(pref);
        } else {
            PrimarySwitchPreference channelPref = new PrimarySwitchPreference(mContext);
            channelPref.setKey(channel.getId());
            updateSingleChannelPrefs(channelPref, channel);
            groupPrefGroup.addPreference(channelPref);
        }
    }

    private void updateSingleChannelPref(@NonNull final Preference channelPref,
            @NonNull final NotificationChannel channel) {
        channelPref.setTitle(channel.getName());
        channelPref.setSummary(NotificationBackend.getSentSummary(
                mContext, mAppRow.sentByChannel.get(channel.getId()), false));
        channelPref.setIntent(new SubSettingLauncher(mContext)
                .setDestination(BundlePreferenceFragment.class.getName())
                .setTitleRes(R.string.notification_channel_title)
                .setSourceMetricsCategory(SettingsEnums.NOTIFICATION_APP_NOTIFICATION)
                .toIntent());
    }

    /** Update the properties of the channel preference with the values from the channel object. */
    private void updateSingleChannelPrefs(@NonNull final PrimarySwitchPreference channelPref,
+23 −3
Original line number Diff line number Diff line
@@ -20,9 +20,11 @@ import static android.app.NotificationChannel.NEWS_ID;
import static android.app.NotificationChannel.PROMOTIONS_ID;
import static android.app.NotificationChannel.RECS_ID;
import static android.app.NotificationChannel.SOCIAL_MEDIA_ID;
import static android.service.notification.Adjustment.KEY_TYPE;

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

import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;

import android.app.NotificationChannel;
@@ -50,6 +52,8 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;

import java.util.List;

@RunWith(RobolectricTestRunner.class)
@SmallTest
@EnableFlags(Flags.FLAG_NOTIFICATION_CLASSIFICATION)
@@ -70,6 +74,9 @@ public class BundleListPreferenceControllerTest {
        MockitoAnnotations.initMocks(this);
        mContext = ApplicationProvider.getApplicationContext();

        when(mBackend.getAllowedAssistantAdjustments(anyString())).thenReturn(List.of(KEY_TYPE));
        when(mBackend.isNotificationBundlingSupported()).thenReturn(true);

        mAppRow = new NotificationBackend.AppRow();
        mAppRow.pkg = "pkg";
        mAppRow.uid = 1111111;
@@ -95,7 +102,18 @@ public class BundleListPreferenceControllerTest {
    public void isAvailable_null() {
        mController.onResume(null, null, null, null, null, null, null);
        assertThat(mController.isAvailable()).isFalse();
        mAppRow.banned = true;
    }

    @Test
    public void isAvailable_featureOff() {
        when(mBackend.isNotificationBundlingSupported()).thenReturn(false);
        assertThat(mController.isAvailable()).isFalse();
    }

    @Test
    public void isAvailable_featureOffForPackage() {
        when(mBackend.getAllowedAssistantAdjustments(anyString())).thenReturn(List.of());
        assertThat(mController.isAvailable()).isFalse();
    }

    @Test
@@ -172,7 +190,9 @@ public class BundleListPreferenceControllerTest {
        mController.updateState(mGroupList);
        assertThat(mGroupList.getPreferenceCount()).isEqualTo(4);

        if (!android.app.Flags.notificationClassificationUi()) {
            assertThat(((PrimarySwitchPreference) mGroupList.findPreference(NEWS_ID)).isChecked())
                    .isEqualTo(false);
        }
    }
}