Add dynamic tiles to development settings.
Remove static preference for MemorySettings and change it to dynamic using manifest metadata. Bug: 32623105 Test: RunSettingsRoboTests Change-Id: Id224eb8a25fea03c75b8fb0b16842bc5b427897a
This commit is contained in:
@@ -3316,6 +3316,17 @@
|
||||
android:value="true" />
|
||||
</activity-alias>
|
||||
|
||||
<activity-alias android:name="MemorySettingsDashboardAlias"
|
||||
android:targetActivity=".Settings$MemorySettingsActivity">
|
||||
<intent-filter>
|
||||
<action android:name="com.android.settings.action.SETTINGS" />
|
||||
</intent-filter>
|
||||
<meta-data android:name="com.android.settings.category"
|
||||
android:value="com.android.settings.category.ia.development" />
|
||||
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
||||
android:value="com.android.settings.applications.ProcessStatsSummary" />
|
||||
</activity-alias>
|
||||
|
||||
<activity android:name=".Settings$ConnectedDeviceDashboardActivity"
|
||||
android:label="@string/connected_devices_dashboard_title"
|
||||
android:icon="@drawable/ic_bt_laptop">
|
||||
|
@@ -63,12 +63,6 @@
|
||||
android:summary="@string/runningservices_settings_summary"
|
||||
android:fragment="com.android.settings.applications.RunningServices" />
|
||||
|
||||
<Preference
|
||||
android:key="process_stats"
|
||||
android:title="@string/memory_settings_title"
|
||||
android:icon="@drawable/ic_settings_memory"
|
||||
android:fragment="com.android.settings.applications.ProcessStatsSummary"/>
|
||||
|
||||
<PreferenceScreen
|
||||
android:key="convert_to_file_encryption"
|
||||
android:title="@string/convert_to_file_encryption"
|
||||
|
@@ -58,6 +58,7 @@ import android.os.storage.IStorageManager;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.provider.Settings;
|
||||
import android.service.persistentdata.PersistentDataBlockManager;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
import android.support.v7.preference.ListPreference;
|
||||
import android.support.v7.preference.Preference;
|
||||
@@ -81,14 +82,16 @@ import android.widget.Toast;
|
||||
import com.android.internal.app.LocalePicker;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.applications.BackgroundCheckSummary;
|
||||
import com.android.settings.applications.ProcessStatsPreferenceController;
|
||||
import com.android.settings.dashboard.DashboardFeatureProvider;
|
||||
import com.android.settings.fuelgauge.InactiveApps;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Indexable;
|
||||
import com.android.settings.widget.SwitchBar;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
import com.android.settingslib.RestrictedSwitchPreference;
|
||||
import com.android.settingslib.drawer.CategoryKey;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -178,7 +181,8 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
||||
private static final String SELECT_LOGPERSIST_PROPERTY_SERVICE = "logcatd";
|
||||
private static final String SELECT_LOGPERSIST_PROPERTY_CLEAR = "clear";
|
||||
private static final String SELECT_LOGPERSIST_PROPERTY_STOP = "stop";
|
||||
private static final String SELECT_LOGPERSIST_PROPERTY_BUFFER = "persist.logd.logpersistd.buffer";
|
||||
private static final String SELECT_LOGPERSIST_PROPERTY_BUFFER =
|
||||
"persist.logd.logpersistd.buffer";
|
||||
private static final String ACTUAL_LOGPERSIST_PROPERTY_BUFFER = "logd.logpersistd.buffer";
|
||||
private static final String ACTUAL_LOGPERSIST_PROPERTY_ENABLE = "logd.logpersistd.enable";
|
||||
|
||||
@@ -225,7 +229,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
||||
|
||||
private static final int REQUEST_CODE_ENABLE_OEM_UNLOCK = 0;
|
||||
|
||||
private static final int[] MOCK_LOCATION_APP_OPS = new int[] {AppOpsManager.OP_MOCK_LOCATION};
|
||||
private static final int[] MOCK_LOCATION_APP_OPS = new int[]{AppOpsManager.OP_MOCK_LOCATION};
|
||||
|
||||
private IWindowManager mWindowManager;
|
||||
private IBackupManager mBackupManager;
|
||||
@@ -308,7 +312,6 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
||||
private SwitchPreference mForceResizable;
|
||||
|
||||
private SwitchPreference mColorTemperaturePreference;
|
||||
private ProcessStatsPreferenceController mProcessStatsPreferenceController;
|
||||
|
||||
private final ArrayList<Preference> mAllPrefs = new ArrayList<Preference>();
|
||||
|
||||
@@ -326,6 +329,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
||||
|
||||
private boolean mLogpersistCleared;
|
||||
private Dialog mLogpersistClearDialog;
|
||||
private DashboardFeatureProvider mDashboardFeatureProvider;
|
||||
|
||||
public DevelopmentSettings() {
|
||||
super(UserManager.DISALLOW_DEBUGGING_FEATURES);
|
||||
@@ -336,6 +340,13 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
||||
return MetricsEvent.DEVELOPMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
mDashboardFeatureProvider = FeatureFactory.getFactory(context)
|
||||
.getDashboardFeatureProvider(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
@@ -345,11 +356,11 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
||||
ServiceManager.getService(Context.BACKUP_SERVICE));
|
||||
mWebViewUpdateService =
|
||||
IWebViewUpdateService.Stub.asInterface(ServiceManager.getService("webviewupdate"));
|
||||
mOemUnlockManager = (PersistentDataBlockManager)getActivity()
|
||||
mOemUnlockManager = (PersistentDataBlockManager) getActivity()
|
||||
.getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
|
||||
mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
|
||||
|
||||
mDpm = (DevicePolicyManager)getActivity().getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||
mDpm = (DevicePolicyManager) getActivity().getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||
mUm = (UserManager) getSystemService(Context.USER_SERVICE);
|
||||
|
||||
mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
|
||||
@@ -362,12 +373,9 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
||||
setPreferenceScreen(new PreferenceScreen(getPrefContext(), null));
|
||||
return;
|
||||
}
|
||||
mProcessStatsPreferenceController = new ProcessStatsPreferenceController(getActivity());
|
||||
|
||||
addPreferencesFromResource(R.xml.development_prefs);
|
||||
|
||||
mProcessStatsPreferenceController.displayPreference(getPreferenceScreen());
|
||||
|
||||
final PreferenceGroup debugDebuggingCategory = (PreferenceGroup)
|
||||
findPreference(DEBUG_DEBUGGING_CATEGORY_KEY);
|
||||
mEnableAdb = findAndInitSwitchPref(ENABLE_ADB);
|
||||
@@ -497,7 +505,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
||||
convertFbePreference.setSummary(getResources()
|
||||
.getString(R.string.convert_to_file_encryption_done));
|
||||
}
|
||||
} catch(RemoteException e) {
|
||||
} catch (RemoteException e) {
|
||||
removePreference(KEY_CONVERT_FBE);
|
||||
}
|
||||
|
||||
@@ -519,6 +527,20 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
||||
removePreference(COLOR_TEMPERATURE_KEY);
|
||||
mColorTemperaturePreference = null;
|
||||
}
|
||||
|
||||
addDashboardCategoryPreferences();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void addDashboardCategoryPreferences() {
|
||||
final PreferenceScreen screen = getPreferenceScreen();
|
||||
final List<Preference> tilePrefs = mDashboardFeatureProvider.getPreferencesForCategory(
|
||||
getActivity(), getPrefContext(), CategoryKey.CATEGORY_SYSTEM_DEVELOPMENT);
|
||||
if (tilePrefs != null) {
|
||||
for (Preference preference : tilePrefs) {
|
||||
screen.addPreference(preference);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ListPreference addListPreference(String prefKey) {
|
||||
@@ -736,7 +758,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
||||
|
||||
private void resetDangerousOptions() {
|
||||
mDontPokeProperties = true;
|
||||
for (int i=0; i< mResetSwitchPrefs.size(); i++) {
|
||||
for (int i = 0; i < mResetSwitchPrefs.size(); i++) {
|
||||
SwitchPreference cb = mResetSwitchPrefs.get(i);
|
||||
if (cb.isChecked()) {
|
||||
cb.setChecked(false);
|
||||
@@ -770,7 +792,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
||||
}
|
||||
ArrayList<String> options = new ArrayList<String>();
|
||||
ArrayList<String> values = new ArrayList<String>();
|
||||
for(int n = 0; n < providers.length; n++) {
|
||||
for (int n = 0; n < providers.length; n++) {
|
||||
if (Utils.isPackageEnabled(getActivity(), providers[n].packageName)) {
|
||||
options.add(providers[n].description);
|
||||
values.add(providers[n].packageName);
|
||||
@@ -790,7 +812,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch(RemoteException e) {
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -809,7 +831,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
||||
String wv_package = mWebViewUpdateService.getCurrentWebViewPackageName();
|
||||
ActivityManager.getService().killPackageDependents(
|
||||
wv_package, UserHandle.USER_ALL);
|
||||
} catch(RemoteException e) {
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -858,7 +880,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
||||
newValue == null ? "" : newValue.toString());
|
||||
updateWebViewProviderOptions();
|
||||
return newValue != null && newValue.equals(updatedProvider);
|
||||
} catch(RemoteException e) {
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -972,7 +994,8 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
||||
}
|
||||
|
||||
private void updateVerifyAppsOverUsbOptions() {
|
||||
updateSwitchPreference(mVerifyAppsOverUsb, Settings.Global.getInt(getActivity().getContentResolver(),
|
||||
updateSwitchPreference(mVerifyAppsOverUsb,
|
||||
Settings.Global.getInt(getActivity().getContentResolver(),
|
||||
Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, 1) != 0);
|
||||
mVerifyAppsOverUsb.setEnabled(enableVerifierSetting());
|
||||
}
|
||||
@@ -1588,7 +1611,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
||||
currentBuffers.contains("kernel")) {
|
||||
index = 2;
|
||||
if (!currentBuffers.contains("default")) {
|
||||
String[] contains = { "main", "events", "system", "crash" };
|
||||
String[] contains = {"main", "events", "system", "crash"};
|
||||
for (int i = 0; i < contains.length; i++) {
|
||||
if (!currentBuffers.contains(contains[i])) {
|
||||
index = 1;
|
||||
@@ -1598,8 +1621,10 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
||||
}
|
||||
}
|
||||
}
|
||||
mLogpersist.setValue(getResources().getStringArray(R.array.select_logpersist_values)[index]);
|
||||
mLogpersist.setSummary(getResources().getStringArray(R.array.select_logpersist_summaries)[index]);
|
||||
mLogpersist.setValue(
|
||||
getResources().getStringArray(R.array.select_logpersist_values)[index]);
|
||||
mLogpersist.setSummary(
|
||||
getResources().getStringArray(R.array.select_logpersist_summaries)[index]);
|
||||
mLogpersist.setOnPreferenceChangeListener(this);
|
||||
if (index != 0) {
|
||||
mLogpersistCleared = false;
|
||||
@@ -1710,7 +1735,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
||||
}
|
||||
|
||||
private void writeUsbConfigurationOption(Object newValue) {
|
||||
UsbManager manager = (UsbManager)getActivity().getSystemService(Context.USB_SERVICE);
|
||||
UsbManager manager = (UsbManager) getActivity().getSystemService(Context.USB_SERVICE);
|
||||
String function = newValue.toString();
|
||||
if (function.equals("none")) {
|
||||
manager.setCurrentFunction(function, false);
|
||||
@@ -1729,7 +1754,8 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
||||
|
||||
private void updateImmediatelyDestroyActivitiesOptions() {
|
||||
updateSwitchPreference(mImmediatelyDestroyActivities, Settings.Global.getInt(
|
||||
getActivity().getContentResolver(), Settings.Global.ALWAYS_FINISH_ACTIVITIES, 0) != 0);
|
||||
getActivity().getContentResolver(), Settings.Global.ALWAYS_FINISH_ACTIVITIES, 0)
|
||||
!= 0);
|
||||
}
|
||||
|
||||
private void updateAnimationScaleValue(int which, ListPreference pref) {
|
||||
@@ -1739,7 +1765,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
||||
mHaveDebugSettings = true;
|
||||
}
|
||||
CharSequence[] values = pref.getEntryValues();
|
||||
for (int i=0; i<values.length; i++) {
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
float val = Float.parseFloat(values[i].toString());
|
||||
if (scale <= val) {
|
||||
pref.setValueIndex(i);
|
||||
@@ -1747,7 +1773,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
||||
return;
|
||||
}
|
||||
}
|
||||
pref.setValueIndex(values.length-1);
|
||||
pref.setValueIndex(values.length - 1);
|
||||
pref.setSummary(pref.getEntries()[0]);
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
@@ -1797,7 +1823,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
||||
try {
|
||||
int limit = ActivityManager.getService().getProcessLimit();
|
||||
CharSequence[] values = mAppProcessLimit.getEntryValues();
|
||||
for (int i=0; i<values.length; i++) {
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
int val = Integer.parseInt(values[i].toString());
|
||||
if (val >= limit) {
|
||||
if (i != 0) {
|
||||
@@ -1844,7 +1870,8 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
||||
}
|
||||
};
|
||||
|
||||
DialogInterface.OnDismissListener onDismissListener = new DialogInterface.OnDismissListener() {
|
||||
DialogInterface.OnDismissListener onDismissListener =
|
||||
new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
if (getActivity() == null) {
|
||||
|
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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 android.content.Context;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.dashboard.DashboardFeatureProvider;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
|
||||
public class ProcessStatsPreferenceController extends PreferenceController {
|
||||
|
||||
private final DashboardFeatureProvider mDashboardFeatureProvider;
|
||||
|
||||
public ProcessStatsPreferenceController(Context context) {
|
||||
super(context);
|
||||
mDashboardFeatureProvider = FeatureFactory.getFactory(context)
|
||||
.getDashboardFeatureProvider(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return mDashboardFeatureProvider.isEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return "process_stats";
|
||||
}
|
||||
}
|
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceManager;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settingslib.drawer.CategoryKey;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class DevelopmentSettingsTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Activity mActivity;
|
||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private PreferenceManager mPreferenceManager;
|
||||
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
private DevelopmentSettings mSettings;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
FakeFeatureFactory.setupForTest(mContext);
|
||||
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||
mSettings = spy(new DevelopmentSettings());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addDashboardCategoryPreference_shouldAddToScreen() {
|
||||
final List<Preference> preferences = new ArrayList<>();
|
||||
preferences.add(new Preference(ShadowApplication.getInstance().getApplicationContext()));
|
||||
preferences.add(new Preference(ShadowApplication.getInstance().getApplicationContext()));
|
||||
doReturn(mScreen).when(mSettings).getPreferenceScreen();
|
||||
doReturn(mPreferenceManager).when(mSettings).getPreferenceManager();
|
||||
doReturn(mActivity).when(mSettings).getActivity();
|
||||
when(mPreferenceManager.getContext()).thenReturn(mContext);
|
||||
when(mFeatureFactory.dashboardFeatureProvider.getPreferencesForCategory(
|
||||
mActivity, mContext, CategoryKey.CATEGORY_SYSTEM_DEVELOPMENT))
|
||||
.thenReturn(preferences);
|
||||
|
||||
mSettings.onAttach(mContext);
|
||||
mSettings.addDashboardCategoryPreferences();
|
||||
|
||||
verify(mScreen, times(2)).addPreference(any(Preference.class));
|
||||
}
|
||||
}
|
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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 android.content.Context;
|
||||
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class ProcessStatsPreferenceControllerTest {
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
|
||||
private FakeFeatureFactory mFactory;
|
||||
private ProcessStatsPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
FakeFeatureFactory.setupForTest(mContext);
|
||||
|
||||
mFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||
|
||||
mController = new ProcessStatsPreferenceController(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAvailble_dashboardFeatureEnabled_shouldReturnTrue() {
|
||||
when(mFactory.dashboardFeatureProvider.isEnabled()).thenReturn(true);
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAvailble_dashboardFeatureDisabled_shouldReturnFalse() {
|
||||
when(mFactory.dashboardFeatureProvider.isEnabled()).thenReturn(false);
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user