reduce number of binder calls when loading page
Test: ZenModeAllBypassingAppsPreferenceControllerTest Test: ZenModeAppsLinkPreferenceControllerTest Test: manual - load page and validate that it loads a few seconds faster Flag: EXEMPT bug fix Fixes: 368623163 Change-Id: I6d34a21f0948b117a96beefc405de4b623f49609
This commit is contained in:
@@ -20,7 +20,6 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
@@ -28,10 +27,8 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Flags;
|
||||
import android.app.NotificationChannel;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.ParceledListSlice;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
|
||||
@@ -39,7 +36,6 @@ import androidx.fragment.app.Fragment;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
|
||||
import com.android.settings.notification.NotificationBackend;
|
||||
import com.android.settingslib.applications.ApplicationsState;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -54,6 +50,7 @@ import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@EnableFlags(Flags.FLAG_MODES_UI)
|
||||
@@ -66,7 +63,7 @@ public class ZenModeAllBypassingAppsPreferenceControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private NotificationBackend mBackend;
|
||||
private ZenHelperBackend mBackend;
|
||||
@Mock
|
||||
private PreferenceCategory mPreferenceCategory;
|
||||
@Mock
|
||||
@@ -102,18 +99,25 @@ public class ZenModeAllBypassingAppsPreferenceControllerTest {
|
||||
entry2.info.packageName = "test2";
|
||||
entry2.info.uid = 0;
|
||||
|
||||
ApplicationsState.AppEntry entry3= mock(ApplicationsState.AppEntry.class);
|
||||
entry3.info = new ApplicationInfo();
|
||||
entry3.info.packageName = "test3";
|
||||
entry3.info.uid = 0;
|
||||
|
||||
List<ApplicationsState.AppEntry> appEntries = new ArrayList<>();
|
||||
appEntries.add(entry1);
|
||||
appEntries.add(entry2);
|
||||
List<NotificationChannel> channelsBypassing = new ArrayList<>();
|
||||
channelsBypassing.add(mock(NotificationChannel.class));
|
||||
channelsBypassing.add(mock(NotificationChannel.class));
|
||||
when(mBackend.getNotificationChannelsBypassingDnd(anyString(),
|
||||
anyInt())).thenReturn(new ParceledListSlice<>(channelsBypassing));
|
||||
appEntries.add(entry3);
|
||||
when(mBackend.getPackagesBypassingDnd(anyInt())).thenReturn(
|
||||
Map.of("test", true, "test2", false));
|
||||
|
||||
// THEN there's are two preferences
|
||||
mController.updateAppList(appEntries);
|
||||
verify(mPreferenceCategory, times(2)).addPreference(any());
|
||||
ArgumentCaptor<Preference> captor = ArgumentCaptor.forClass(Preference.class);
|
||||
verify(mPreferenceCategory, times(2)).addPreference(captor.capture());
|
||||
List<Preference> prefs = captor.getAllValues();
|
||||
assertThat(prefs.get(0).getSummary().toString()).isEqualTo("All notifications");
|
||||
assertThat(prefs.get(1).getSummary().toString()).isEqualTo("Some notifications");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -77,6 +77,7 @@ import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@@ -200,8 +201,8 @@ public final class ZenModeAppsLinkPreferenceControllerTest {
|
||||
ApplicationsState.AppEntry app2 = createAppEntry("app2", mContext.getUserId());
|
||||
List<ApplicationsState.AppEntry> allApps = List.of(app1, app2);
|
||||
|
||||
when(mHelperBackend.getPackagesBypassingDnd(mContext.getUserId(),
|
||||
false)).thenReturn(List.of("app1"));
|
||||
when(mHelperBackend.getPackagesBypassingDnd(mContext.getUserId())).thenReturn(
|
||||
Map.of("app1", true));
|
||||
|
||||
assertThat(mController.getAppsBypassingDndSortedByName(allApps)).containsExactly(app1);
|
||||
}
|
||||
@@ -213,8 +214,8 @@ public final class ZenModeAppsLinkPreferenceControllerTest {
|
||||
ApplicationsState.AppEntry appB = createAppEntry("B", mContext.getUserId());
|
||||
List<ApplicationsState.AppEntry> allApps = List.of(appC, appA, appB);
|
||||
|
||||
when(mHelperBackend.getPackagesBypassingDnd(eq(mContext.getUserId()), anyBoolean()))
|
||||
.thenReturn(List.of("B", "C", "A"));
|
||||
when(mHelperBackend.getPackagesBypassingDnd(eq(mContext.getUserId())))
|
||||
.thenReturn(Map.of("B", true, "C", false, "A", true));
|
||||
|
||||
assertThat(mController.getAppsBypassingDndSortedByName(allApps))
|
||||
.containsExactly(appA, appB, appC).inOrder();
|
||||
@@ -234,10 +235,10 @@ public final class ZenModeAppsLinkPreferenceControllerTest {
|
||||
List<ApplicationsState.AppEntry> allApps = List.of(workCopy, personalCopy, otherPersonal,
|
||||
otherWork);
|
||||
|
||||
when(mHelperBackend.getPackagesBypassingDnd(eq(mContext.getUserId()), anyBoolean()))
|
||||
.thenReturn(List.of("app", "p2"));
|
||||
when(mHelperBackend.getPackagesBypassingDnd(eq(10), anyBoolean()))
|
||||
.thenReturn(List.of("app"));
|
||||
when(mHelperBackend.getPackagesBypassingDnd(eq(mContext.getUserId())))
|
||||
.thenReturn(Map.of("app", true, "p2", true));
|
||||
when(mHelperBackend.getPackagesBypassingDnd(eq(10)))
|
||||
.thenReturn(Map.of("app", false));
|
||||
|
||||
// Personal copy before work copy (names match).
|
||||
assertThat(mController.getAppsBypassingDndSortedByName(allApps))
|
||||
@@ -253,7 +254,7 @@ public final class ZenModeAppsLinkPreferenceControllerTest {
|
||||
mController.updateState(mPreference, zenMode);
|
||||
|
||||
verifyNoMoreInteractions(mSession);
|
||||
verify(mHelperBackend, never()).getPackagesBypassingDnd(anyInt(), anyBoolean());
|
||||
verify(mHelperBackend, never()).getPackagesBypassingDnd(anyInt());
|
||||
assertThat(String.valueOf(mPreference.getSummary())).isEqualTo("None");
|
||||
}
|
||||
|
||||
@@ -266,9 +267,8 @@ public final class ZenModeAppsLinkPreferenceControllerTest {
|
||||
ArrayList<ApplicationsState.AppEntry> appEntries = new ArrayList<>();
|
||||
appEntries.add(createAppEntry("test", mContext.getUserId()));
|
||||
|
||||
when(mHelperBackend.getPackagesBypassingDnd(
|
||||
mContext.getUserId(), false))
|
||||
.thenReturn(List.of("test"));
|
||||
when(mHelperBackend.getPackagesBypassingDnd(mContext.getUserId()))
|
||||
.thenReturn(Map.of("test", false));
|
||||
|
||||
// Updates the preference with the zen mode. We expect that this causes the app session
|
||||
// to trigger a rebuild (and display a temporary text in the meantime).
|
||||
@@ -286,8 +286,8 @@ public final class ZenModeAppsLinkPreferenceControllerTest {
|
||||
ZenMode zenMode = createPriorityChannelsZenMode();
|
||||
|
||||
mController.updateState(mPreference, zenMode);
|
||||
when(mHelperBackend.getPackagesBypassingDnd(anyInt(), anyBoolean()))
|
||||
.thenReturn(ImmutableList.of("test1", "test2"));
|
||||
when(mHelperBackend.getPackagesBypassingDnd(anyInt()))
|
||||
.thenReturn(Map.of("test1", false, "test2", false));
|
||||
ArrayList<ApplicationsState.AppEntry> appEntries = new ArrayList<>();
|
||||
appEntries.add(createAppEntry("test1", mContext.getUserId()));
|
||||
appEntries.add(createAppEntry("test2", mContext.getUserId()));
|
||||
@@ -328,8 +328,8 @@ public final class ZenModeAppsLinkPreferenceControllerTest {
|
||||
.build();
|
||||
ArrayList<ApplicationsState.AppEntry> appEntries = new ArrayList<>();
|
||||
appEntries.add(createAppEntry("test", mContext.getUserId()));
|
||||
when(mHelperBackend.getPackagesBypassingDnd(mContext.getUserId(), false))
|
||||
.thenReturn(List.of("test"));
|
||||
when(mHelperBackend.getPackagesBypassingDnd(mContext.getUserId()))
|
||||
.thenReturn(Map.of("test", true));
|
||||
|
||||
mController.updateState(mPreference, zenModeWithNone);
|
||||
|
||||
@@ -355,8 +355,8 @@ public final class ZenModeAppsLinkPreferenceControllerTest {
|
||||
.build();
|
||||
ArrayList<ApplicationsState.AppEntry> appEntries = new ArrayList<>();
|
||||
appEntries.add(createAppEntry("test", mContext.getUserId()));
|
||||
when(mHelperBackend.getPackagesBypassingDnd(mContext.getUserId(), false))
|
||||
.thenReturn(List.of("test"));
|
||||
when(mHelperBackend.getPackagesBypassingDnd(mContext.getUserId()))
|
||||
.thenReturn(Map.of("test", true));
|
||||
|
||||
mController.updateState(mPreference, zenModeWithPriority);
|
||||
|
||||
|
Reference in New Issue
Block a user