Move unrestricted data summary to DataSaverController
DataSaverController currently used in 2 pages, - Network & internet > Data Saver - Apps > Special app access This helps unify the logic, and instead of showing on "Special app access", this summary shows on "Unrestricted data" is make more sense. Bug: 280280596 Test: Manually on above pages Test: Unit test Change-Id: Ia151ed8179a250f8f20cc5041f9383fffebdab10
This commit is contained in:
@@ -1,125 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.settings.applications;
|
||||
|
||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.anyInt;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.ModuleInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.datausage.AppStateDataUsageBridge;
|
||||
import com.android.settings.testutils.shadow.ShadowApplicationsState;
|
||||
import com.android.settings.testutils.shadow.ShadowUserManager;
|
||||
import com.android.settingslib.applications.ApplicationsState;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowUserManager.class, ShadowApplicationsState.class})
|
||||
public class SpecialAppAccessPreferenceControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private ApplicationsState.Session mSession;
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
|
||||
private SpecialAppAccessPreferenceController mController;
|
||||
private Preference mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
when(mContext.getApplicationContext()).thenReturn(mContext);
|
||||
ShadowUserManager.getShadow().setProfileIdsWithDisabled(new int[]{0});
|
||||
doReturn(mPackageManager).when(mContext).getPackageManager();
|
||||
doReturn(new ArrayList<ModuleInfo>()).when(mPackageManager).getInstalledModules(anyInt());
|
||||
mController = new SpecialAppAccessPreferenceController(mContext, "test_key");
|
||||
mPreference = new Preference(mContext);
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
|
||||
mController.mSession = mSession;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityState_unsearchable() {
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_shouldSetSummary() {
|
||||
final ArrayList<ApplicationsState.AppEntry> apps = new ArrayList<>();
|
||||
final ApplicationsState.AppEntry entry = mock(ApplicationsState.AppEntry.class);
|
||||
entry.hasLauncherEntry = true;
|
||||
entry.info = new ApplicationInfo();
|
||||
entry.extraInfo = new AppStateDataUsageBridge.DataUsageState(
|
||||
true /* allowlisted */, false /* denylisted */);
|
||||
apps.add(entry);
|
||||
when(mSession.getAllApps()).thenReturn(apps);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
mController.onExtraInfoUpdated();
|
||||
|
||||
assertThat(mPreference.getSummary())
|
||||
.isEqualTo(mContext.getResources().getQuantityString(
|
||||
R.plurals.special_access_summary, 1, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_wrongExtraInfo_shouldNotIncludeInSummary() {
|
||||
final ArrayList<ApplicationsState.AppEntry> apps = new ArrayList<>();
|
||||
final ApplicationsState.AppEntry entry = mock(ApplicationsState.AppEntry.class);
|
||||
entry.hasLauncherEntry = true;
|
||||
entry.info = new ApplicationInfo();
|
||||
entry.extraInfo = new AppStateNotificationBridge.NotificationsSentState();
|
||||
apps.add(entry);
|
||||
when(mSession.getAllApps()).thenReturn(apps);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
mController.onExtraInfoUpdated();
|
||||
|
||||
assertThat(mPreference.getSummary())
|
||||
.isEqualTo(mContext.getResources().getQuantityString(
|
||||
R.plurals.special_access_summary, 0, 0));
|
||||
}
|
||||
}
|
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.settings.applications.specialaccess;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class DataSaverControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
private Resources mResources;
|
||||
private DataSaverController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application.getApplicationContext());
|
||||
|
||||
mResources = spy(mContext.getResources());
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
|
||||
mController = new DataSaverController(mContext, "key");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDataSaver_byDefault_shouldBeShown() {
|
||||
when(mResources.getBoolean(R.bool.config_show_data_saver)).thenReturn(true);
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
@Config(qualifiers = "mcc999")
|
||||
public void testDataSaver_ifDisabledByCarrier_shouldNotBeShown() {
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDataSaver_ifDisabled_shouldNotBeShown() {
|
||||
when(mResources.getBoolean(R.bool.config_show_data_saver)).thenReturn(false);
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user