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

Commit afe35d62 authored by Julia Reynolds's avatar Julia Reynolds Committed by android-build-merger
Browse files

Merge "Add app info notification summary" into pi-dev

am: 54ee35c3

Change-Id: I0db2133a3edb399ad589dd485de249ebb5244705
parents 1dda7ae8 54ee35c3
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.content.Context;
import android.os.Bundle;
import android.support.v7.preference.Preference;

import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.notification.AppNotificationSettings;
import com.android.settings.notification.NotificationBackend;
@@ -77,7 +78,18 @@ public class AppNotificationPreferenceController extends AppInfoPreferenceContro

    public static CharSequence getNotificationSummary(NotificationBackend.AppRow appRow,
            Context context) {
        // TODO: implement summary when it is known what it should say
        if (appRow == null) {
            return "";
        }
        if (appRow.banned || appRow.channelCount == appRow.blockedChannelCount) {
            return context.getString(R.string.notifications_disabled);
        } else {
            if (appRow.blockedChannelCount == 0) {
                return context.getString(R.string.notifications_enabled);
            }
            return context.getString(R.string.notifications_enabled_with_info,
                    context.getResources().getQuantityString(R.plurals.notifications_categories_off,
                            appRow.blockedChannelCount, appRow.blockedChannelCount));
        }
    }
}
+22 −12
Original line number Diff line number Diff line
@@ -60,6 +60,8 @@ public class NotificationBackend {
        row.banned = getNotificationsBanned(row.pkg, row.uid);
        row.showBadge = canShowBadge(row.pkg, row.uid);
        row.userId = UserHandle.getUserId(row.uid);
        row.blockedChannelCount = getBlockedChannelCount(row.pkg, row.uid);
        row.channelCount = getChannelCount(row.pkg, row.uid);
        return row;
    }

@@ -178,18 +180,6 @@ public class NotificationBackend {
        }
    }

    public NotificationChannelGroup getGroupWithChannels(String pkg, int uid, String groupId) {
        if (groupId == null) {
            return null;
        }
        try {
            return sINM.getPopulatedNotificationChannelGroupForPackage(pkg, uid, groupId, true);
        } catch (Exception e) {
            Log.w(TAG, "Error calling NoMan", e);
            return null;
        }
    }

    public ParceledListSlice<NotificationChannelGroup> getGroups(String pkg, int uid) {
        try {
            return sINM.getNotificationChannelGroupsForPackage(pkg, uid, false);
@@ -224,6 +214,15 @@ public class NotificationBackend {
        }
    }

    public int getBlockedChannelCount(String pkg, int uid) {
        try {
            return sINM.getBlockedChannelCount(pkg, uid);
        } catch (Exception e) {
            Log.w(TAG, "Error calling NoMan", e);
            return 0;
        }
    }

    public boolean onlyHasDefaultChannel(String pkg, int uid) {
        try {
            return sINM.onlyHasDefaultChannel(pkg, uid);
@@ -233,6 +232,15 @@ public class NotificationBackend {
        }
    }

    public int getChannelCount(String pkg, int uid) {
        try {
            return sINM.getNumNotificationChannelsForPackage(pkg, uid, false);
        } catch (Exception e) {
            Log.w(TAG, "Error calling NoMan", e);
            return 0;
        }
    }

    public List<NotifyingApp> getRecentApps() {
        try {
            return sINM.getRecentNotifyingAppsForUser(UserHandle.myUserId()).getList();
@@ -259,5 +267,7 @@ public class NotificationBackend {
        public String lockedChannelId;
        public boolean showBadge;
        public int userId;
        public int blockedChannelCount;
        public int channelCount;
    }
}
+45 −0
Original line number Diff line number Diff line
@@ -105,4 +105,49 @@ public class AppNotificationPreferenceControllerTest {
        assertThat(controller.getArguments().containsKey(EXTRA_FRAGMENT_ARG_KEY)).isTrue();
        assertThat(controller.getArguments().getString(EXTRA_FRAGMENT_ARG_KEY)).isEqualTo("test");
    }

    @Test
    public void getNotificationSummary_noCrashOnNull() {
        mController.getNotificationSummary(null, mContext);
    }

    @Test
    public void getNotificationSummary_appBlocked() {
        NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
        appRow.banned = true;
        appRow.blockedChannelCount = 30;
        assertThat(mController.getNotificationSummary(appRow, mContext).toString())
                .isEqualTo("Off");
    }

    @Test
    public void getNotificationSummary_appNotBlockedAllChannelsBlocked() {
        NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
        appRow.banned = false;
        appRow.blockedChannelCount = 30;
        appRow.channelCount = 30;
        assertThat(mController.getNotificationSummary(appRow, mContext).toString())
                .isEqualTo("Off");
    }

    @Test
    public void getNotificationSummary_appNotBlocked() {
        NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
        appRow.banned = false;
        appRow.blockedChannelCount = 30;
        appRow.channelCount = 60;
        assertThat(mController.getNotificationSummary(
                appRow, mContext).toString().contains("30")).isTrue();
        assertThat(mController.getNotificationSummary(
                appRow, mContext).toString().contains("On")).isTrue();
    }

    @Test
    public void getNotificationSummary_channelsNotBlocked() {
        NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
        appRow.banned = false;
        appRow.blockedChannelCount = 0;
        appRow.channelCount = 10;
        assertThat(mController.getNotificationSummary(appRow, mContext).toString()).isEqualTo("On");
    }
}