Merge "Add NPE check for refreshUi" into oc-dev
diff --git a/res/xml/battery_saver_settings.xml b/res/xml/battery_saver_settings.xml
index 1720c73..52f6793 100644
--- a/res/xml/battery_saver_settings.xml
+++ b/res/xml/battery_saver_settings.xml
@@ -22,6 +22,6 @@
<DropDownPreference
android:key="turn_on_automatically"
android:title="@string/battery_saver_turn_on_automatically_title"
- android:summary="%s" />
+ android:summary="@string/summary_placeholder" />
</PreferenceScreen>
diff --git a/res/xml/sound_settings.xml b/res/xml/sound_settings.xml
index d288a9d..33c1b0a 100644
--- a/res/xml/sound_settings.xml
+++ b/res/xml/sound_settings.xml
@@ -124,7 +124,7 @@
<DropDownPreference
android:key="dock_audio_media"
android:title="@string/dock_audio_media_title"
- android:summary="%s" />
+ android:summary="@string/summary_placeholder" />
<!-- Boot sounds -->
<SwitchPreference
@@ -135,7 +135,7 @@
<DropDownPreference
android:key="emergency_tone"
android:title="@string/emergency_tone_title"
- android:summary="%s" />
+ android:summary="@string/summary_placeholder" />
<com.android.settingslib.RestrictedPreference
android:key="cell_broadcast_settings"
diff --git a/res/xml/tether_prefs.xml b/res/xml/tether_prefs.xml
index 22a4747..a936a50 100644
--- a/res/xml/tether_prefs.xml
+++ b/res/xml/tether_prefs.xml
@@ -15,7 +15,7 @@
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:settings="http://schemas.android.com/apk/res-auto">
+ xmlns:settings="http://schemas.android.com/apk/res-auto">
<SwitchPreference
android:key="usb_tether_settings"
@@ -23,7 +23,8 @@
<SwitchPreference
android:key="enable_wifi_ap"
- android:title="@string/wifi_tether_checkbox_text" />
+ android:title="@string/wifi_tether_checkbox_text"
+ android:summary="@string/summary_two_lines_placeholder" />
<Preference
android:key="wifi_ap_ssid_and_security"
@@ -34,9 +35,9 @@
android:key="enable_bluetooth_tethering"
android:title="@string/bluetooth_tether_checkbox_text" />
- <com.android.settings.DividerPreference
- android:key="disabled_on_data_saver"
- android:summary="@string/tether_settings_disabled_on_data_saver"
- android:selectable="false"
- settings:allowDividerAbove="true" />
+ <Preference
+ android:key="disabled_on_data_saver"
+ android:summary="@string/tether_settings_disabled_on_data_saver"
+ android:selectable="false"
+ settings:allowDividerAbove="true" />
</PreferenceScreen>
diff --git a/src/com/android/settings/SettingsPreferenceFragment.java b/src/com/android/settings/SettingsPreferenceFragment.java
index 761e8cf..b4ca6a6 100644
--- a/src/com/android/settings/SettingsPreferenceFragment.java
+++ b/src/com/android/settings/SettingsPreferenceFragment.java
@@ -26,6 +26,7 @@
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
+import android.support.annotation.VisibleForTesting;
import android.support.annotation.XmlRes;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceGroup;
@@ -423,11 +424,28 @@
return -1;
}
- protected void removePreference(String key) {
- Preference pref = findPreference(key);
- if (pref != null) {
- getPreferenceScreen().removePreference(pref);
+ protected boolean removePreference(String key) {
+ return removePreference(getPreferenceScreen(), key);
+ }
+
+ @VisibleForTesting
+ boolean removePreference(PreferenceGroup group, String key) {
+ final int preferenceCount = group.getPreferenceCount();
+ for (int i = 0; i < preferenceCount; i++) {
+ final Preference preference = group.getPreference(i);
+ final String curKey = preference.getKey();
+
+ if (TextUtils.equals(curKey, key)) {
+ return group.removePreference(preference);
+ }
+
+ if (preference instanceof PreferenceGroup) {
+ if (removePreference((PreferenceGroup) preference, key)) {
+ return true;
+ }
+ }
}
+ return false;
}
/**
diff --git a/src/com/android/settings/TetherSettings.java b/src/com/android/settings/TetherSettings.java
index 5d797a7..9475f45 100644
--- a/src/com/android/settings/TetherSettings.java
+++ b/src/com/android/settings/TetherSettings.java
@@ -37,7 +37,6 @@
import android.os.UserManager;
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.Preference;
-import android.support.v7.preference.PreferenceScreen;
import android.util.Log;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
diff --git a/src/com/android/settings/applications/InstalledAppDetails.java b/src/com/android/settings/applications/InstalledAppDetails.java
index ab9f358..e88e3ba 100755
--- a/src/com/android/settings/applications/InstalledAppDetails.java
+++ b/src/com/android/settings/applications/InstalledAppDetails.java
@@ -196,6 +196,8 @@
BatterySipper mSipper;
@VisibleForTesting
BatteryStatsHelper mBatteryHelper;
+ @VisibleForTesting
+ BatteryUtils mBatteryUtils;
protected ProcStatsData mStatsManager;
protected ProcStatsPackageEntry mStats;
@@ -204,7 +206,6 @@
private AppStorageStats mLastResult;
private String mBatteryPercent;
- private BatteryUtils mBatteryUtils;
private final LoaderCallbacks<BatteryStatsHelper> mBatteryCallbacks =
new LoaderCallbacks<BatteryStatsHelper>() {
@@ -729,8 +730,6 @@
mDataPreference.setSummary(getDataSummary());
}
- updateBattery();
-
if (!mInitialized) {
// First time init: are we displaying an uninstalled app?
mInitialized = true;
@@ -757,9 +756,10 @@
return true;
}
- private void updateBattery() {
- if (mSipper != null && mBatteryHelper != null) {
- mBatteryPreference.setEnabled(true);
+ @VisibleForTesting
+ void updateBattery() {
+ mBatteryPreference.setEnabled(true);
+ if (isBatteryStatsAvailable()) {
final int dischargeAmount = mBatteryHelper.getStats().getDischargeAmount(
BatteryStats.STATS_SINCE_CHARGED);
@@ -771,7 +771,6 @@
mBatteryPercent = Utils.formatPercentage(percentOfMax);
mBatteryPreference.setSummary(getString(R.string.battery_summary, mBatteryPercent));
} else {
- mBatteryPreference.setEnabled(false);
mBatteryPreference.setSummary(getString(R.string.no_battery_summary));
}
}
@@ -805,6 +804,11 @@
}
}
+ @VisibleForTesting
+ boolean isBatteryStatsAvailable() {
+ return mBatteryHelper != null && mSipper != null;
+ }
+
private static CharSequence getSize(Context context, AppStorageStats stats) {
return Formatter.formatFileSize(context, stats.getTotalBytes());
}
@@ -1043,9 +1047,15 @@
} else if (preference == mDataPreference) {
startAppInfoFragment(AppDataUsage.class, getString(R.string.app_data_usage));
} else if (preference == mBatteryPreference) {
- BatteryEntry entry = new BatteryEntry(getContext(), null, mUserManager, mSipper);
- AdvancedPowerUsageDetail.startBatteryDetailPage((SettingsActivity) getActivity(), this,
- mBatteryHelper, BatteryStats.STATS_SINCE_CHARGED, entry, mBatteryPercent);
+ if (isBatteryStatsAvailable()) {
+ BatteryEntry entry = new BatteryEntry(getContext(), null, mUserManager, mSipper);
+ AdvancedPowerUsageDetail.startBatteryDetailPage((SettingsActivity) getActivity(),
+ this, mBatteryHelper, BatteryStats.STATS_SINCE_CHARGED, entry,
+ mBatteryPercent);
+ } else {
+ AdvancedPowerUsageDetail.startBatteryDetailPage((SettingsActivity) getActivity(),
+ this, mPackageName);
+ }
} else {
return false;
}
diff --git a/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java b/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
index d4f9641..580eb1b 100644
--- a/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
+++ b/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
@@ -133,6 +133,16 @@
new UserHandle(UserHandle.getUserId(sipper.getUid())));
}
+ public static void startBatteryDetailPage(SettingsActivity caller, PreferenceFragment fragment,
+ String packageName) {
+ final Bundle args = new Bundle(2);
+ args.putString(EXTRA_PACKAGE_NAME, packageName);
+ args.putString(EXTRA_POWER_USAGE_PERCENT, Utils.formatPercentage(0));
+
+ caller.startPreferencePanelAsUser(fragment, AdvancedPowerUsageDetail.class.getName(), args,
+ R.string.battery_details_title, null, new UserHandle(UserHandle.myUserId()));
+ }
+
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
diff --git a/src/com/android/settings/fuelgauge/BatterySaverSettings.java b/src/com/android/settings/fuelgauge/BatterySaverSettings.java
index 6b7ddf9..45d0db2 100644
--- a/src/com/android/settings/fuelgauge/BatterySaverSettings.java
+++ b/src/com/android/settings/fuelgauge/BatterySaverSettings.java
@@ -99,7 +99,6 @@
}
};
mTriggerPref.init(this);
-
mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
}
diff --git a/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java b/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java
index 10ffc49..be38855 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java
@@ -77,11 +77,11 @@
@Override
public boolean isAdvancedUiEnabled() {
- return false;
+ return true;
}
@Override
public boolean isPowerAccountingToggleEnabled() {
- return false;
+ return true;
}
}
diff --git a/src/com/android/settings/network/TetherPreferenceController.java b/src/com/android/settings/network/TetherPreferenceController.java
index 19a22ba..fab700b 100644
--- a/src/com/android/settings/network/TetherPreferenceController.java
+++ b/src/com/android/settings/network/TetherPreferenceController.java
@@ -18,7 +18,10 @@
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothPan;
import android.bluetooth.BluetoothProfile;
+import android.content.BroadcastReceiver;
import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
import android.database.ContentObserver;
import android.net.ConnectivityManager;
import android.net.Uri;
@@ -67,6 +70,7 @@
private SettingObserver mAirplaneModeObserver;
private Preference mPreference;
+ private TetherBroadcastReceiver mTetherReceiver;
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
TetherPreferenceController() {
@@ -131,6 +135,11 @@
if (mAirplaneModeObserver == null) {
mAirplaneModeObserver = new SettingObserver();
}
+ if (mTetherReceiver == null) {
+ mTetherReceiver = new TetherBroadcastReceiver();
+ }
+ mContext.registerReceiver(
+ mTetherReceiver, new IntentFilter(ConnectivityManager.ACTION_TETHER_STATE_CHANGED));
mContext.getContentResolver()
.registerContentObserver(mAirplaneModeObserver.uri, false, mAirplaneModeObserver);
}
@@ -140,6 +149,9 @@
if (mAirplaneModeObserver != null) {
mContext.getContentResolver().unregisterContentObserver(mAirplaneModeObserver);
}
+ if (mTetherReceiver != null) {
+ mContext.unregisterReceiver(mTetherReceiver);
+ }
}
@Override
@@ -238,4 +250,14 @@
}
}
}
+
+ @VisibleForTesting
+ class TetherBroadcastReceiver extends BroadcastReceiver {
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ updateSummary();
+ }
+
+ }
}
diff --git a/src/com/android/settings/notification/SettingPref.java b/src/com/android/settings/notification/SettingPref.java
index 18efc33..cdbd5b3 100644
--- a/src/com/android/settings/notification/SettingPref.java
+++ b/src/com/android/settings/notification/SettingPref.java
@@ -121,6 +121,19 @@
if (mTwoState != null) {
mTwoState.setChecked(val != 0);
} else if (mDropDown != null) {
+ if (mValues != null) {
+ int index = 0;
+ for (int len = mValues.length; index < len; index++) {
+ if (mValues[index] == val) {
+ break;
+ }
+ }
+
+ if (index < mValues.length) {
+ CharSequence entry = mDropDown.getEntries()[index];
+ mDropDown.setSummary(entry);
+ }
+ }
mDropDown.setValue(Integer.toString(val));
}
}
diff --git a/tests/robotests/src/com/android/settings/SettingsPreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/SettingsPreferenceFragmentTest.java
new file mode 100644
index 0000000..cd48da3
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/SettingsPreferenceFragmentTest.java
@@ -0,0 +1,112 @@
+/*
+ * 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;
+
+
+import android.content.Context;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceCategory;
+import android.support.v7.preference.PreferenceManager;
+import android.support.v7.preference.PreferenceScreen;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class SettingsPreferenceFragmentTest {
+
+ @Mock
+ private PreferenceManager mPreferenceManager;
+ private Context mContext;
+ private TestFragment mFragment;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ mFragment = new TestFragment();
+ }
+
+ @Test
+ public void removePreference_nested_shouldRemove() {
+ final String key = "test_key";
+ final PreferenceScreen mScreen = spy(new PreferenceScreen(mContext, null));
+ when(mScreen.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
+
+ final PreferenceCategory nestedCategory = new ProgressCategory(mContext);
+ final Preference preference = new Preference(mContext);
+ preference.setKey(key);
+ preference.setPersistent(false);
+
+ mScreen.addPreference(nestedCategory);
+ nestedCategory.addPreference(preference);
+
+ assertThat(mFragment.removePreference(mScreen, key)).isTrue();
+ assertThat(nestedCategory.getPreferenceCount()).isEqualTo(0);
+ }
+
+ @Test
+ public void removePreference_flat_shouldRemove() {
+ final String key = "test_key";
+ final PreferenceScreen mScreen = spy(new PreferenceScreen(mContext, null));
+ when(mScreen.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
+
+ final Preference preference = mock(Preference.class);
+ when(preference.getKey()).thenReturn(key);
+
+ mScreen.addPreference(preference);
+
+ assertThat(mFragment.removePreference(mScreen, key)).isTrue();
+ assertThat(mScreen.getPreferenceCount()).isEqualTo(0);
+ }
+
+ @Test
+ public void removePreference_doNotExist_shouldNotRemove() {
+ final String key = "test_key";
+ final PreferenceScreen mScreen = spy(new PreferenceScreen(mContext, null));
+ when(mScreen.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
+
+ final Preference preference = mock(Preference.class);
+ when(preference.getKey()).thenReturn(key);
+
+ mScreen.addPreference(preference);
+
+ assertThat(mFragment.removePreference(mScreen, "not" + key)).isFalse();
+ assertThat(mScreen.getPreferenceCount()).isEqualTo(1);
+ }
+
+ public static final class TestFragment extends SettingsPreferenceFragment {
+
+ @Override
+ public int getMetricsCategory() {
+ return 0;
+ }
+ }
+
+
+}
diff --git a/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java b/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java
index a09aeec..f602236 100644
--- a/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java
+++ b/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java
@@ -20,6 +20,8 @@
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyDouble;
+import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
@@ -46,10 +48,12 @@
import com.android.internal.os.BatterySipper;
import com.android.internal.os.BatteryStatsHelper;
+import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.applications.instantapps.InstantAppButtonsController;
+import com.android.settings.fuelgauge.BatteryUtils;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settingslib.applications.AppUtils;
import com.android.settingslib.applications.ApplicationsState.AppEntry;
@@ -77,6 +81,8 @@
private static final String PACKAGE_NAME = "test_package_name";
private static final int TARGET_UID = 111;
private static final int OTHER_UID = 222;
+ private static final double BATTERY_LEVEL = 60;
+ private static final String BATTERY_LEVEL_STRING = "60%";
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
@@ -89,20 +95,21 @@
@Mock
private DevicePolicyManager mDevicePolicyManager;
@Mock
- private Preference mBatteryPreference;
- @Mock
private BatterySipper mBatterySipper;
@Mock
private BatterySipper mOtherBatterySipper;
- @Mock
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
private BatteryStatsHelper mBatteryStatsHelper;
@Mock
private BatteryStats.Uid mUid;
@Mock
private PackageManager mPackageManager;
+ @Mock
+ private BatteryUtils mBatteryUtils;
private InstalledAppDetails mAppDetail;
private Context mShadowContext;
+ private Preference mBatteryPreference;
@Before
public void setUp() {
@@ -110,6 +117,10 @@
mShadowContext = RuntimeEnvironment.application;
mAppDetail = spy(new InstalledAppDetails());
+ mAppDetail.mBatteryUtils = mBatteryUtils;
+
+ mBatteryPreference = new Preference(mShadowContext);
+ mAppDetail.mBatteryPreference = mBatteryPreference;
mBatterySipper.drainType = BatterySipper.DrainType.IDLE;
mBatterySipper.uidObj = mUid;
@@ -409,4 +420,42 @@
assertThat(mAppDetail.findTargetSipper(mBatteryStatsHelper, TARGET_UID)).isEqualTo(
mBatterySipper);
}
+
+ @Test
+ public void updateBattery_noBatteryStats_summaryNo() {
+ doReturn(mShadowContext.getString(R.string.no_battery_summary)).when(mAppDetail).getString(
+ R.string.no_battery_summary);
+ mAppDetail.updateBattery();
+
+ assertThat(mBatteryPreference.getSummary()).isEqualTo(
+ "No battery use since last full charge");
+ }
+
+ @Test
+ public void updateBattery_hasBatteryStats_summaryPercent() {
+ mAppDetail.mBatteryHelper = mBatteryStatsHelper;
+ mAppDetail.mSipper = mBatterySipper;
+ doReturn(BATTERY_LEVEL).when(mBatteryUtils).calculateBatteryPercent(anyDouble(),
+ anyDouble(), anyDouble(), anyInt());
+ doReturn(mShadowContext.getString(R.string.battery_summary, BATTERY_LEVEL_STRING)).when(
+ mAppDetail).getString(R.string.battery_summary, BATTERY_LEVEL_STRING);
+ doReturn(new ArrayList<>()).when(mBatteryStatsHelper).getUsageList();
+
+ mAppDetail.updateBattery();
+
+ assertThat(mBatteryPreference.getSummary()).isEqualTo("60% use since last full charge");
+ }
+
+ @Test
+ public void isBatteryStatsAvailable_hasBatteryStatsHelperAndSipper_returnTrue() {
+ mAppDetail.mBatteryHelper = mBatteryStatsHelper;
+ mAppDetail.mSipper = mBatterySipper;
+
+ assertThat(mAppDetail.isBatteryStatsAvailable()).isTrue();
+ }
+
+ @Test
+ public void isBatteryStatsAvailable_parametersNull_returnFalse() {
+ assertThat(mAppDetail.isBatteryStatsAvailable()).isFalse();
+ }
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java b/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
index fec9c5d..d6b758c 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
@@ -277,4 +277,25 @@
verify(mTestActivity).startPreferencePanelAsUser(
any(), anyString(), any(), anyInt(), any(), eq(new UserHandle(10)));
}
+
+ @Test
+ public void testStartBatteryDetailPage_noBatteryUsage_hasBasicData() {
+ final ArgumentCaptor<Bundle> captor = ArgumentCaptor.forClass(Bundle.class);
+ Answer<Void> callable = new Answer<Void>() {
+ @Override
+ public Void answer(InvocationOnMock invocation) throws Exception {
+ mBundle = captor.getValue();
+ return null;
+ }
+ };
+ doAnswer(callable).when(mTestActivity).startPreferencePanelAsUser(any(), anyString(),
+ captor.capture(), anyInt(), any(), any());
+
+ AdvancedPowerUsageDetail.startBatteryDetailPage(mTestActivity, null, PACKAGE_NAME[0]);
+
+ assertThat(mBundle.getString(AdvancedPowerUsageDetail.EXTRA_PACKAGE_NAME)).isEqualTo(
+ PACKAGE_NAME[0]);
+ assertThat(mBundle.getString(AdvancedPowerUsageDetail.EXTRA_POWER_USAGE_PERCENT)).isEqualTo(
+ "0%");
+ }
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImplTest.java
index f32ea7a..8e9febe 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImplTest.java
@@ -125,4 +125,14 @@
assertThat(mPowerFeatureProvider.isTypeSystem(mBatterySipper)).isFalse();
}
+
+ @Test
+ public void testIsAdvancedUiEnabled_returnTrue() {
+ assertThat(mPowerFeatureProvider.isAdvancedUiEnabled()).isTrue();
+ }
+
+ @Test
+ public void testIsPowerAccountingToggleEnabled_returnTrue() {
+ assertThat(mPowerFeatureProvider.isPowerAccountingToggleEnabled()).isTrue();
+ }
}
diff --git a/tests/robotests/src/com/android/settings/network/TetherPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/TetherPreferenceControllerTest.java
index 7e92bc5..cecc910 100644
--- a/tests/robotests/src/com/android/settings/network/TetherPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/TetherPreferenceControllerTest.java
@@ -20,7 +20,10 @@
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothPan;
import android.bluetooth.BluetoothProfile;
+import android.content.ContentResolver;
import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
import android.database.ContentObserver;
import android.net.ConnectivityManager;
import android.provider.Settings;
@@ -41,6 +44,7 @@
import java.util.concurrent.atomic.AtomicReference;
+import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
@@ -150,4 +154,36 @@
verify(mPreference).setSummary(R.string.switch_off_text);
}
+ @Test
+ public void onResume_shouldRegisterTetherReceiver() {
+ when(mContext.getContentResolver()).thenReturn(mock(ContentResolver.class));
+
+ mController.onResume();
+
+ verify(mContext).registerReceiver(
+ any(TetherPreferenceController.TetherBroadcastReceiver.class), any(IntentFilter.class));
+ }
+
+ @Test
+ public void onPause_shouldUnregisterTetherReceiver() {
+ when(mContext.getContentResolver()).thenReturn(mock(ContentResolver.class));
+ mController.onResume();
+
+ mController.onPause();
+
+ verify(mContext).unregisterReceiver(
+ any(TetherPreferenceController.TetherBroadcastReceiver.class));
+ }
+
+ @Test
+ public void tetherStatesChanged_shouldUpdateSummary() {
+ final Context context = RuntimeEnvironment.application;
+ ReflectionHelpers.setField(mController, "mContext", context);
+ mController.onResume();
+
+ context.sendBroadcast(new Intent(ConnectivityManager.ACTION_TETHER_STATE_CHANGED));
+
+ verify(mController).updateSummary();
+ }
+
}
diff --git a/tests/robotests/src/com/android/settings/notification/SettingPrefTest.java b/tests/robotests/src/com/android/settings/notification/SettingPrefTest.java
new file mode 100644
index 0000000..39f1377
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/SettingPrefTest.java
@@ -0,0 +1,67 @@
+package com.android.settings.notification;
+
+import android.content.res.Resources;
+
+import android.content.Context;
+import android.provider.Settings;
+import android.support.v7.preference.DropDownPreference;
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.spy;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class SettingPrefTest {
+
+ @Test
+ public void update_setsDropDownSummaryText() {
+ Context context = RuntimeEnvironment.application;
+ String testSetting = "test_setting";
+ int[] values = new int[] {1,2,3};
+ String[] entries = new String[] {"one", "two", "three"};
+ SettingPref settingPref =
+ spy(new SettingPref(SettingPref.TYPE_GLOBAL, "key", testSetting, 0, values) {
+ @Override
+ protected String getCaption(Resources res, int value) {
+ return "temp";
+ }
+ });
+ DropDownPreference dropdownPref = spy(new DropDownPreference(context));
+ dropdownPref.setEntries(entries);
+ settingPref.mDropDown = dropdownPref;
+ Settings.Global.putInt(context.getContentResolver(), testSetting, values[2]);
+
+ settingPref.update(context);
+
+ assertThat(settingPref.mDropDown.getSummary()).isEqualTo(entries[2]);
+ }
+
+ @Test
+ public void update_setsDropDownSummaryText_noMatch_noError() {
+ Context context = RuntimeEnvironment.application;
+ String testSetting = "test_setting";
+ int[] values = new int[] {1,2,3};
+ String[] entries = new String[] {"one", "two", "three"};
+ SettingPref settingPref =
+ spy(new SettingPref(SettingPref.TYPE_GLOBAL, "key", testSetting, 0, values) {
+ @Override
+ protected String getCaption(Resources res, int value) {
+ return "temp";
+ }
+ });
+ DropDownPreference dropdownPref = spy(new DropDownPreference(context));
+ dropdownPref.setEntries(entries);
+ settingPref.mDropDown = dropdownPref;
+ Settings.Global.putInt(context.getContentResolver(), testSetting, -1);
+
+ settingPref.update(context);
+
+ assertThat(settingPref.mDropDown.getSummary()).isNull();
+ }
+}