Merge "Add test config to SettingsUnitTests"
diff --git a/res/drawable/ic_settings_battery.xml b/res/drawable/ic_settings_battery.xml
index c8e053d..6afc5d0 100644
--- a/res/drawable/ic_settings_battery.xml
+++ b/res/drawable/ic_settings_battery.xml
@@ -14,13 +14,12 @@
limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
- android:width="24.0dp"
- android:height="24.0dp"
+ android:width="24dp"
+ android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?android:attr/colorControlNormal">
<path
- android:fillColor="#FFFFFFFF"
- android:pathData="M15.67,4.0L14.0,4.0L14.0,2.0l-4.0,0.0l0.0,2.0L8.33,4.0C7.6,4.0 7.0,4.6 7.0,5.33l0.0,15.33C7.0,21.4 7.6,22.0 8.33,22.0l7.33,0.0c0.74,0.0 1.34,-0.6 1.34,-1.33L17.0,5.33C17.0,4.6 16.4,4.0 15.67,4.0z
- M16,5l0,5.5l-8,0l0,-5.5l3,0l0,-2l2,0l0,2l3,0z"/>
+ android:fillColor="#FF000000"
+ android:pathData="M15.67,4H14V2h-4v2H8.33C7.6,4 7,4.6 7,5.33v15.33C7,21.4 7.6,22 8.33,22h7.33c0.74,0 1.34,-0.6 1.34,-1.33V5.33C17,4.6 16.4,4 15.67,4z"/>
</vector>
diff --git a/res/drawable/selectable_card.xml b/res/drawable/selectable_card.xml
deleted file mode 100644
index 3a1e8b2..0000000
--- a/res/drawable/selectable_card.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- 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.
--->
-
-<ripple
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:color="?android:attr/colorControlHighlight">
- <item android:drawable="?android:attr/colorBackground"/>
-</ripple>
\ No newline at end of file
diff --git a/res/layout/dashboard_tile.xml b/res/layout/dashboard_tile.xml
index 0e06d18..1ec1730 100644
--- a/res/layout/dashboard_tile.xml
+++ b/res/layout/dashboard_tile.xml
@@ -19,7 +19,7 @@
android:id="@+id/dashboard_tile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:background="@drawable/selectable_card"
+ android:background="?android:attr/selectableItemBackground"
android:gravity="center_vertical"
android:minHeight="@dimen/dashboard_tile_minimum_height"
android:clickable="true"
diff --git a/res/layout/search_panel_2.xml b/res/layout/search_panel.xml
similarity index 100%
rename from res/layout/search_panel_2.xml
rename to res/layout/search_panel.xml
diff --git a/res/layout/settings_main_dashboard.xml b/res/layout/settings_main_dashboard.xml
index 1b7506e..c10193c 100644
--- a/res/layout/settings_main_dashboard.xml
+++ b/res/layout/settings_main_dashboard.xml
@@ -21,5 +21,4 @@
android:id="@+id/main_content"
android:layout_height="match_parent"
android:layout_width="match_parent"
- android:background="@color/material_grey_300"
/>
diff --git a/res/layout/support_tile.xml b/res/layout/support_tile.xml
index e294868..c2081c7 100644
--- a/res/layout/support_tile.xml
+++ b/res/layout/support_tile.xml
@@ -19,7 +19,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:background="@drawable/selectable_card"
+ android:background="?android:attr/selectableItemBackground"
android:gravity="center_vertical"
android:minHeight="@dimen/support_tile_min_height"
android:orientation="horizontal">
diff --git a/res/xml/channel_notification_settings.xml b/res/xml/channel_notification_settings.xml
index fde1bfa..5b848e6 100644
--- a/res/xml/channel_notification_settings.xml
+++ b/res/xml/channel_notification_settings.xml
@@ -69,5 +69,4 @@
android:title="@string/app_notification_override_dnd_title"
android:summary="@string/app_notification_override_dnd_summary"
settings:useAdditionalSummary="true" />
-
</PreferenceScreen>
diff --git a/res/xml/development_prefs.xml b/res/xml/development_prefs.xml
index 8422f3e..6ed8dc9 100644
--- a/res/xml/development_prefs.xml
+++ b/res/xml/development_prefs.xml
@@ -214,6 +214,13 @@
android:summary="@string/bluetooth_disable_absolute_volume_summary"/>
<ListPreference
+ android:key="bluetooth_select_avrcp_version"
+ android:title="@string/bluetooth_select_avrcp_version_string"
+ android:dialogTitle="@string/bluetooth_select_avrcp_version_dialog_title"
+ android:entries="@array/bluetooth_avrcp_versions"
+ android:entryValues="@array/bluetooth_avrcp_version_values" />
+
+ <ListPreference
android:key="bluetooth_select_a2dp_codec"
android:title="@string/bluetooth_select_a2dp_codec_type"
android:dialogTitle="@string/bluetooth_select_a2dp_codec_type_dialog_title"
diff --git a/res/xml/power_usage_summary.xml b/res/xml/power_usage_summary.xml
index aecb6f1..a387813 100644
--- a/res/xml/power_usage_summary.xml
+++ b/res/xml/power_usage_summary.xml
@@ -30,9 +30,9 @@
android:title="@string/battery_power_management">
<com.android.settings.widget.MasterSwitchPreference
+ android:fragment="com.android.settings.fuelgauge.BatterySaverSettings"
android:key="battery_saver"
- android:title="@string/battery_saver"
- android:fragment="com.android.settings.fuelgauge.BatterySaverSettings"/>
+ android:title="@string/battery_saver"/>
<SwitchPreference
android:key="battery_percentage"
diff --git a/src/com/android/settings/TetherSettings.java b/src/com/android/settings/TetherSettings.java
index 0a0eed2..61cad39 100644
--- a/src/com/android/settings/TetherSettings.java
+++ b/src/com/android/settings/TetherSettings.java
@@ -132,6 +132,8 @@
super.onCreate(icicle);
addPreferencesFromResource(R.xml.tether_prefs);
+ mFooterPreferenceMixin.createFooterPreference()
+ .setTitle(R.string.tethering_footer_info);
mDataSaverBackend = new DataSaverBackend(getContext());
mDataSaverEnabled = mDataSaverBackend.isDataSaverEnabled();
diff --git a/src/com/android/settings/applications/AppHeaderController.java b/src/com/android/settings/applications/AppHeaderController.java
index 45b8960..0bc9f8f 100644
--- a/src/com/android/settings/applications/AppHeaderController.java
+++ b/src/com/android/settings/applications/AppHeaderController.java
@@ -90,7 +90,7 @@
if (appHeader != null) {
mAppHeader = appHeader;
} else {
- mAppHeader = LayoutInflater.from(mContext)
+ mAppHeader = LayoutInflater.from(fragment.getContext())
.inflate(R.layout.app_details, null /* root */);
}
}
diff --git a/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImpl.java b/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImpl.java
index b82c28d..779a8aa 100644
--- a/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImpl.java
+++ b/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImpl.java
@@ -63,7 +63,7 @@
@Override
public void dismissSuggestion(Context context, SuggestionParser parser, Tile suggestion) {
- if (parser == null || suggestion == null) {
+ if (parser == null || suggestion == null || context == null) {
return;
}
mMetricsFeatureProvider.action(
diff --git a/src/com/android/settings/datausage/DataUsageSummary.java b/src/com/android/settings/datausage/DataUsageSummary.java
index 41dc78f..8eb1f61 100644
--- a/src/com/android/settings/datausage/DataUsageSummary.java
+++ b/src/com/android/settings/datausage/DataUsageSummary.java
@@ -20,13 +20,18 @@
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.INetworkStatsSession;
+import android.net.NetworkPolicy;
+import android.net.NetworkPolicyManager;
import android.net.NetworkTemplate;
import android.net.TrafficStats;
+import android.net.wifi.WifiConfiguration;
+import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.SystemProperties;
import android.os.UserManager;
import android.provider.SearchIndexableResource;
+import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.telephony.SubscriptionInfo;
@@ -56,6 +61,7 @@
import static android.net.ConnectivityManager.TYPE_ETHERNET;
import static android.net.ConnectivityManager.TYPE_WIFI;
+import static android.net.NetworkPolicy.LIMIT_DISABLED;
public class DataUsageSummary extends DataUsageBase implements Indexable, DataUsageEditController {
@@ -68,6 +74,7 @@
private static final String KEY_STATUS_HEADER = "status_header";
private static final String KEY_LIMIT_SUMMARY = "limit_summary";
private static final String KEY_RESTRICT_BACKGROUND = "restrict_background";
+ private static final String KEY_NETWORK_RESTRICTIONS = "network_restrictions";
private DataUsageController mDataUsageController;
private DataUsageInfoController mDataInfoController;
@@ -75,6 +82,10 @@
private Preference mLimitPreference;
private NetworkTemplate mDefaultTemplate;
private int mDataUsageTemplate;
+ private NetworkRestrictionsPreference mNetworkRestrcitionPreference;
+ private WifiManager mWifiManager;
+ private NetworkPolicyManager mPolicyManager;
+ private NetworkPolicyEditor mPolicyEditor;
@Override
protected int getHelpResource() {
@@ -85,16 +96,21 @@
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
- boolean hasMobileData = hasMobileData(getContext());
- mDataUsageController = new DataUsageController(getContext());
+ final Context context = getContext();
+ mPolicyManager = NetworkPolicyManager.from(context);
+ mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
+ mPolicyEditor = new NetworkPolicyEditor(mPolicyManager);
+
+ boolean hasMobileData = hasMobileData(context);
+ mDataUsageController = new DataUsageController(context);
mDataInfoController = new DataUsageInfoController();
addPreferencesFromResource(R.xml.data_usage);
- int defaultSubId = getDefaultSubscriptionId(getContext());
+ int defaultSubId = getDefaultSubscriptionId(context);
if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
hasMobileData = false;
}
- mDefaultTemplate = getDefaultTemplate(getContext(), defaultSubId);
+ mDefaultTemplate = getDefaultTemplate(context, defaultSubId);
mSummaryPreference = (SummaryPreference) findPreference(KEY_STATUS_HEADER);
if (!hasMobileData || !isAdmin()) {
@@ -115,11 +131,11 @@
removePreference(KEY_LIMIT_SUMMARY);
mSummaryPreference.setSelectable(false);
}
- boolean hasWifiRadio = hasWifiRadio(getContext());
+ boolean hasWifiRadio = hasWifiRadio(context);
if (hasWifiRadio) {
addWifiSection();
}
- if (hasEthernet(getContext())) {
+ if (hasEthernet(context)) {
addEthernetSection();
}
mDataUsageTemplate = hasMobileData ? R.string.cell_data_template
@@ -171,6 +187,8 @@
TemplatePreferenceCategory category = (TemplatePreferenceCategory)
inflatePreferences(R.xml.data_usage_wifi);
category.setTemplate(NetworkTemplate.buildTemplateWifiWildcard(), 0, services);
+ mNetworkRestrcitionPreference =
+ (NetworkRestrictionsPreference) category.findPreference(KEY_NETWORK_RESTRICTIONS);
}
private void addEthernetSection() {
@@ -259,6 +277,8 @@
mLimitPreference.setSummary(null);
}
+ updateNetworkRestrictionSummary(mNetworkRestrcitionPreference);
+
PreferenceScreen screen = getPreferenceScreen();
for (int i = 1; i < screen.getPreferenceCount(); i++) {
((TemplatePreferenceCategory) screen.getPreference(i)).pushTemplates(services);
@@ -362,6 +382,39 @@
}
}
+ @VisibleForTesting
+ void updateNetworkRestrictionSummary(NetworkRestrictionsPreference preference) {
+ if (preference == null) {
+ return;
+ }
+ mPolicyEditor.read();
+ int count = 0;
+ for (WifiConfiguration config : mWifiManager.getConfiguredNetworks()) {
+ if (isMetered(config)) {
+ count++;
+ }
+ }
+ preference.setSummary(getResources().getQuantityString(
+ R.plurals.network_restrictions_summary, count, count));
+ }
+
+ @VisibleForTesting
+ boolean isMetered(WifiConfiguration config) {
+ if (config.SSID == null) {
+ return false;
+ }
+ final String networkId = config.isPasspoint() ? config.providerFriendlyName : config.SSID;
+ final NetworkPolicy policy =
+ mPolicyEditor.getPolicyMaybeUnquoted(NetworkTemplate.buildTemplateWifi(networkId));
+ if (policy == null) {
+ return false;
+ }
+ if (policy.limitBytes != LIMIT_DISABLED) {
+ return true;
+ }
+ return policy.metered;
+ }
+
private static class SummaryProvider
implements SummaryLoader.SummaryProvider {
diff --git a/src/com/android/settings/development/DevelopmentSettings.java b/src/com/android/settings/development/DevelopmentSettings.java
index 0a3351a..deb4e42 100644
--- a/src/com/android/settings/development/DevelopmentSettings.java
+++ b/src/com/android/settings/development/DevelopmentSettings.java
@@ -203,7 +203,10 @@
"bluetooth_disable_absolute_volume";
private static final String BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_PROPERTY =
"persist.bluetooth.disableabsvol";
+ private static final String BLUETOOTH_AVRCP_VERSION_PROPERTY =
+ "persist.bluetooth.avrcpversion";
+ private static final String BLUETOOTH_SELECT_AVRCP_VERSION_KEY = "bluetooth_select_avrcp_version";
private static final String BLUETOOTH_SELECT_A2DP_CODEC_KEY = "bluetooth_select_a2dp_codec";
private static final String BLUETOOTH_SELECT_A2DP_SAMPLE_RATE_KEY = "bluetooth_select_a2dp_sample_rate";
private static final String BLUETOOTH_SELECT_A2DP_BITS_PER_SAMPLE_KEY = "bluetooth_select_a2dp_bits_per_sample";
@@ -280,6 +283,7 @@
private BluetoothA2dp mBluetoothA2dp;
private final Object mBluetoothA2dpLock = new Object();
+ private ListPreference mBluetoothSelectAvrcpVersion;
private ListPreference mBluetoothSelectA2dpCodec;
private ListPreference mBluetoothSelectA2dpSampleRate;
private ListPreference mBluetoothSelectA2dpBitsPerSample;
@@ -494,6 +498,7 @@
mWebViewMultiprocess = findAndInitSwitchPref(WEBVIEW_MULTIPROCESS_KEY);
mBluetoothDisableAbsVolume = findAndInitSwitchPref(BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_KEY);
+ mBluetoothSelectAvrcpVersion = addListPreference(BLUETOOTH_SELECT_AVRCP_VERSION_KEY);
mBluetoothSelectA2dpCodec = addListPreference(BLUETOOTH_SELECT_A2DP_CODEC_KEY);
mBluetoothSelectA2dpSampleRate = addListPreference(BLUETOOTH_SELECT_A2DP_SAMPLE_RATE_KEY);
mBluetoothSelectA2dpBitsPerSample = addListPreference(BLUETOOTH_SELECT_A2DP_BITS_PER_SAMPLE_KEY);
@@ -1786,6 +1791,14 @@
String[] summaries;
int index;
+ // Init the AVRCP Version - Default
+ values = getResources().getStringArray(R.array.bluetooth_avrcp_version_values);
+ summaries = getResources().getStringArray(R.array.bluetooth_avrcp_versions);
+ String value = SystemProperties.get(BLUETOOTH_AVRCP_VERSION_PROPERTY);
+ index = mBluetoothSelectAvrcpVersion.findIndexOfValue(value);
+ mBluetoothSelectAvrcpVersion.setValue(values[index]);
+ mBluetoothSelectAvrcpVersion.setSummary(summaries[index]);
+
// Init the Codec Type - Default
values = getResources().getStringArray(R.array.bluetooth_a2dp_codec_values);
summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_summaries);
@@ -1822,6 +1835,15 @@
mBluetoothSelectA2dpLdacPlaybackQuality.setSummary(summaries[index]);
}
+ private void writeBluetoothAvrcpVersion(Object newValue) {
+ SystemProperties.set(BLUETOOTH_AVRCP_VERSION_PROPERTY, newValue.toString());
+ int index = mBluetoothSelectAvrcpVersion.findIndexOfValue(newValue.toString());
+ if (index >= 0) {
+ String[] titles = getResources().getStringArray(R.array.bluetooth_avrcp_versions);
+ mBluetoothSelectAvrcpVersion.setSummary(titles[index]);
+ }
+ }
+
private void updateBluetoothA2dpConfigurationValues() {
int index;
String[] summaries;
@@ -2528,6 +2550,9 @@
updateHdcpValues();
pokeSystemProperties();
return true;
+ } else if (preference == mBluetoothSelectAvrcpVersion) {
+ writeBluetoothAvrcpVersion(newValue);
+ return true;
} else if ((preference == mBluetoothSelectA2dpCodec) ||
(preference == mBluetoothSelectA2dpSampleRate) ||
(preference == mBluetoothSelectA2dpBitsPerSample) ||
diff --git a/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java b/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java
index c3a4d90..93e7810 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java
@@ -15,6 +15,7 @@
import android.content.Context;
import android.content.pm.PackageManager;
+import android.os.BatteryStats;
import android.os.Bundle;
import android.provider.SearchIndexableResource;
import android.support.annotation.ColorInt;
@@ -46,6 +47,7 @@
private static final String TAG = "AdvancedBatteryUsage";
private static final String KEY_BATTERY_GRAPH = "battery_graph";
private static final String KEY_BATTERY_USAGE_LIST = "battery_usage_list";
+ private static final int STATUS_TYPE = BatteryStats.STATS_SINCE_CHARGED;
@VisibleForTesting
final int[] mUsageTypes = {
@@ -165,9 +167,10 @@
// TODO(b/35396770): add logic to extract the summary
final List<PowerUsageData> batteryDataList = new ArrayList<>(batteryDataMap.values());
+ final int dischargeAmount = statusHelper.getStats().getDischargeAmount(STATUS_TYPE);
final double totalPower = statusHelper.getTotalPower();
for (final PowerUsageData usageData : batteryDataList) {
- usageData.percentage = (usageData.totalPowerMah / totalPower) * 100;
+ usageData.percentage = (usageData.totalPowerMah / totalPower) * dischargeAmount;
}
Collections.sort(batteryDataList);
diff --git a/src/com/android/settings/notification/AppNotificationSettings.java b/src/com/android/settings/notification/AppNotificationSettings.java
index 24405b3..fec489a 100644
--- a/src/com/android/settings/notification/AppNotificationSettings.java
+++ b/src/com/android/settings/notification/AppNotificationSettings.java
@@ -203,7 +203,7 @@
int deletedChannelCount = mBackend.getDeletedChannelCount(mAppRow.pkg, mAppRow.uid);
if (deletedChannelCount > 0) {
DimmableIconPreference deletedPref = new DimmableIconPreference(getPrefContext());
- deletedPref.setEnabled(false);
+ deletedPref.setSelectable(false);
deletedPref.setTitle(getResources().getQuantityString(
R.plurals.deleted_channels, deletedChannelCount, deletedChannelCount));
deletedPref.setIcon(R.drawable.ic_info);
diff --git a/src/com/android/settings/notification/ChannelNotificationSettings.java b/src/com/android/settings/notification/ChannelNotificationSettings.java
index 7f7aa08..b24e92c 100644
--- a/src/com/android/settings/notification/ChannelNotificationSettings.java
+++ b/src/com/android/settings/notification/ChannelNotificationSettings.java
@@ -40,6 +40,7 @@
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.widget.LockPatternUtils;
+import com.android.settings.DimmableIconPreference;
import com.android.settings.R;
import com.android.settings.RingtonePreference;
import com.android.settings.applications.AppHeaderController;
@@ -131,6 +132,14 @@
intentPref.setTitle(mContext.getString(R.string.app_settings_link));
getPreferenceScreen().addPreference(intentPref);
}
+
+ if (!TextUtils.isEmpty(mChannel.getDescription())) {
+ DimmableIconPreference descPref = new DimmableIconPreference(getPrefContext());
+ descPref.setSelectable(false);
+ descPref.setSummary(mChannel.getDescription());
+ descPref.setIcon(R.drawable.ic_info);
+ getPreferenceScreen().addPreference(descPref);
+ }
}
private void setupLights() {
diff --git a/src/com/android/settings/search2/SearchFragment.java b/src/com/android/settings/search2/SearchFragment.java
index eb760ee..8e1e1b4 100644
--- a/src/com/android/settings/search2/SearchFragment.java
+++ b/src/com/android/settings/search2/SearchFragment.java
@@ -157,7 +157,7 @@
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
- final View view = inflater.inflate(R.layout.search_panel_2, container, false);
+ final View view = inflater.inflate(R.layout.search_panel, container, false);
mResultsRecyclerView = view.findViewById(R.id.list_results);
mResultsRecyclerView.setAdapter(mSearchAdapter);
mResultsRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
diff --git a/src/com/android/settings/wifi/WifiApEnabler.java b/src/com/android/settings/wifi/WifiApEnabler.java
index 760879e..8e577a4 100644
--- a/src/com/android/settings/wifi/WifiApEnabler.java
+++ b/src/com/android/settings/wifi/WifiApEnabler.java
@@ -28,7 +28,6 @@
import com.android.settings.R;
import com.android.settings.datausage.DataSaverBackend;
-import com.android.settingslib.TetherUtil;
import java.util.ArrayList;
@@ -140,6 +139,8 @@
updateConfigSummary(wifiConfig);
} else if (wifiErrored) {
mSwitch.setSummary(R.string.wifi_error);
+ } else {
+ mSwitch.setSummary(R.string.wifi_hotspot_off_subtext);
}
}
diff --git a/src/com/android/settings/wifi/WifiSummaryUpdater.java b/src/com/android/settings/wifi/WifiSummaryUpdater.java
index 533ee07..c0d4468 100644
--- a/src/com/android/settings/wifi/WifiSummaryUpdater.java
+++ b/src/com/android/settings/wifi/WifiSummaryUpdater.java
@@ -26,6 +26,8 @@
import com.android.settings.widget.SummaryUpdater;
import com.android.settingslib.wifi.WifiStatusTracker;
+import static android.net.wifi.WifiInfo.removeDoubleQuotes;
+
/**
* Helper class that listeners to wifi callback and notify client when there is update in
* wifi summary info.
@@ -78,7 +80,7 @@
if (!mWifiTracker.connected) {
return mContext.getString(R.string.disconnected);
}
- return mWifiTracker.ssid;
+ return removeDoubleQuotes(mWifiTracker.ssid);
}
}
diff --git a/tests/robotests/src/com/android/settings/applications/AppHeaderControllerTest.java b/tests/robotests/src/com/android/settings/applications/AppHeaderControllerTest.java
index bd55fd0..79f452a 100644
--- a/tests/robotests/src/com/android/settings/applications/AppHeaderControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/AppHeaderControllerTest.java
@@ -17,7 +17,6 @@
package com.android.settings.applications;
-import android.annotation.IdRes;
import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
@@ -25,12 +24,10 @@
import android.content.pm.ActivityInfo;
import android.content.pm.PackageInfo;
import android.content.pm.ResolveInfo;
-import android.graphics.drawable.Drawable;
import android.os.UserHandle;
import android.support.v7.preference.Preference;
import android.view.LayoutInflater;
import android.view.View;
-import android.widget.ImageView;
import android.widget.TextView;
import com.android.settings.R;
@@ -44,8 +41,8 @@
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
-import org.robolectric.shadows.ShadowApplication;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any;
@@ -55,8 +52,6 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import java.util.EnumSet;
-
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class AppHeaderControllerTest {
@@ -79,7 +74,8 @@
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- mShadowContext = ShadowApplication.getInstance().getApplicationContext();
+ mShadowContext = RuntimeEnvironment.application;
+ when(mFragment.getContext()).thenReturn(mShadowContext);
mLayoutInflater = LayoutInflater.from(mShadowContext);
mInfo = new PackageInfo();
mInfo.versionName = "1234";
@@ -292,4 +288,12 @@
assertThat(label.getText()).isEqualTo(
appHeader.getResources().getString(R.string.install_type_instant));
}
+
+ @Test
+ public void initAppHeaderController_appHeaderNull_useFragmentContext() {
+ mController = new AppHeaderController(mContext, mFragment, null);
+
+ // Fragment.getContext() is invoked to inflate the view
+ verify(mFragment).getContext();
+ }
}
diff --git a/tests/robotests/src/com/android/settings/applications/AppInfoWithHeaderTest.java b/tests/robotests/src/com/android/settings/applications/AppInfoWithHeaderTest.java
index a717306..68c153c 100644
--- a/tests/robotests/src/com/android/settings/applications/AppInfoWithHeaderTest.java
+++ b/tests/robotests/src/com/android/settings/applications/AppInfoWithHeaderTest.java
@@ -83,6 +83,7 @@
PreferenceManager mManager;
PreferenceScreen mScreen;
+ Context mShadowContext;
public TestFragment() {
mPm = mock(PackageManager.class);
@@ -90,10 +91,10 @@
mScreen = mock(PreferenceScreen.class);
mPackageInfo = new PackageInfo();
mPackageInfo.applicationInfo = new ApplicationInfo();
+ mShadowContext = ShadowApplication.getInstance().getApplicationContext();
ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
(InstantAppDataProvider) (info -> false));
- when(mManager.getContext())
- .thenReturn(ShadowApplication.getInstance().getApplicationContext());
+ when(mManager.getContext()).thenReturn(mShadowContext);
}
@Override
@@ -120,6 +121,11 @@
public PreferenceManager getPreferenceManager() {
return mManager;
}
+
+ @Override
+ public Context getContext() {
+ return mShadowContext;
+ }
}
}
diff --git a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImplTest.java
index b36aef2..3efe15a 100644
--- a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImplTest.java
@@ -120,6 +120,14 @@
verify(mContext, never()).getPackageManager();
}
+
+ @Test
+ public void dismissSuggestion_noContext_shouldDoNothing() {
+ mProvider.dismissSuggestion(null, mSuggestionParser, mSuggestion);
+
+ verifyZeroInteractions(mFactory.metricsFeatureProvider);
+ }
+
@Test
public void dismissSuggestion_hasNoMoreDismissCount_shouldDisableComponent() {
when(mSuggestionParser.dismissSuggestion(any(Tile.class), anyBoolean()))
diff --git a/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryTest.java b/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryTest.java
index e8a2ee4..71d9ea1 100644
--- a/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryTest.java
+++ b/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryTest.java
@@ -18,8 +18,15 @@
import android.content.Context;
import android.net.ConnectivityManager;
+import android.net.NetworkPolicy;
+import android.net.wifi.WifiConfiguration;
+import android.net.wifi.WifiManager;
+
+import com.android.settings.R;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
+import com.android.settingslib.NetworkPolicyEditor;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -27,9 +34,17 @@
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
+import org.robolectric.util.ReflectionHelpers;
+
+import java.util.ArrayList;
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@@ -57,4 +72,75 @@
boolean hasMobileData = DataUsageSummary.hasMobileData(mContext);
assertThat(hasMobileData).isTrue();
}
+
+ @Test
+ public void testUpdateNetworkRestrictionSummary_shouldSetSummary() {
+ final DataUsageSummary dataUsageSummary = spy(new DataUsageSummary());
+ final NetworkRestrictionsPreference preference = mock(NetworkRestrictionsPreference.class);
+ final NetworkPolicyEditor policyEditor = mock(NetworkPolicyEditor.class);
+ final WifiManager wifiManager = mock(WifiManager.class);
+ ReflectionHelpers.setField(dataUsageSummary, "mPolicyEditor", policyEditor);
+ ReflectionHelpers.setField(dataUsageSummary, "mWifiManager", wifiManager);
+ when(wifiManager.getConfiguredNetworks()).thenReturn(new ArrayList<WifiConfiguration>());
+ doReturn(mContext.getResources()).when(dataUsageSummary).getResources();
+
+ dataUsageSummary.updateNetworkRestrictionSummary(preference);
+
+ verify(preference).setSummary(mContext.getResources().getQuantityString(
+ R.plurals.network_restrictions_summary, 0, 0));
+ }
+
+ @Test
+ public void testIsMetered_noSsid_shouldReturnFalse() {
+ final DataUsageSummary dataUsageSummary = new DataUsageSummary();
+ final NetworkPolicyEditor policyEditor = mock(NetworkPolicyEditor.class);
+ ReflectionHelpers.setField(dataUsageSummary, "mPolicyEditor", policyEditor);
+ WifiConfiguration config = mock(WifiConfiguration.class);
+
+ assertThat(dataUsageSummary.isMetered(config)).isFalse();
+ }
+
+ @Test
+ public void testIsMetered_noNetworkPolicy_shouldReturnFalse() {
+ final DataUsageSummary dataUsageSummary = new DataUsageSummary();
+ final NetworkPolicyEditor policyEditor = mock(NetworkPolicyEditor.class);
+ ReflectionHelpers.setField(dataUsageSummary, "mPolicyEditor", policyEditor);
+ WifiConfiguration config = mock(WifiConfiguration.class);
+ config.SSID = "network1";
+ doReturn(null).when(policyEditor).getPolicyMaybeUnquoted(any());
+
+ assertThat(dataUsageSummary.isMetered(config)).isFalse();
+ }
+
+ @Test
+ public void testIsMetered_policyHasLimit_shouldReturnTrue() {
+ final DataUsageSummary dataUsageSummary = new DataUsageSummary();
+ final NetworkPolicyEditor policyEditor = mock(NetworkPolicyEditor.class);
+ ReflectionHelpers.setField(dataUsageSummary, "mPolicyEditor", policyEditor);
+ WifiConfiguration config = mock(WifiConfiguration.class);
+ config.SSID = "network1";
+ NetworkPolicy policy = mock(NetworkPolicy.class);
+ policy.limitBytes = 100;
+ doReturn(policy).when(policyEditor).getPolicyMaybeUnquoted(any());
+
+ assertThat(dataUsageSummary.isMetered(config)).isTrue();
+ }
+
+ @Test
+ public void testIsMetered_noPolicyLimit_shouldReturnMeteredValue() {
+ final DataUsageSummary dataUsageSummary = new DataUsageSummary();
+ final NetworkPolicyEditor policyEditor = mock(NetworkPolicyEditor.class);
+ ReflectionHelpers.setField(dataUsageSummary, "mPolicyEditor", policyEditor);
+ WifiConfiguration config = mock(WifiConfiguration.class);
+ config.SSID = "network1";
+ NetworkPolicy policy = mock(NetworkPolicy.class);
+ policy.limitBytes = NetworkPolicy.LIMIT_DISABLED;
+ doReturn(policy).when(policyEditor).getPolicyMaybeUnquoted(any());
+
+ policy.metered = true;
+ assertThat(dataUsageSummary.isMetered(config)).isTrue();
+
+ policy.metered = false;
+ assertThat(dataUsageSummary.isMetered(config)).isFalse();
+ }
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java
index 494ac67..eb96604 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java
@@ -27,6 +27,7 @@
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;
@@ -38,6 +39,7 @@
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@@ -45,6 +47,7 @@
public class PowerUsageAdvancedTest {
private static final int FAKE_UID_1 = 50;
private static final int FAKE_UID_2 = 100;
+ private static final int DISCHARGE_AMOUNT = 60;
private static final double TYPE_APP_USAGE = 80;
private static final double TYPE_BLUETOOTH_USAGE = 50;
private static final double TYPE_WIFI_USAGE = 0;
@@ -53,7 +56,7 @@
private static final double PRECISION = 0.001;
@Mock
private BatterySipper mBatterySipper;
- @Mock
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
private BatteryStatsHelper mBatteryStatsHelper;
@Mock
private PowerUsageFeatureProvider mPowerUsageFeatureProvider;
@@ -76,6 +79,8 @@
batterySippers.add(new BatterySipper(DrainType.WIFI, new FakeUid(FAKE_UID_1),
TYPE_WIFI_USAGE));
+ when(mBatteryStatsHelper.getStats().getDischargeAmount(anyInt())).thenReturn(
+ DISCHARGE_AMOUNT);
when(mBatteryStatsHelper.getUsageList()).thenReturn(batterySippers);
when(mBatteryStatsHelper.getTotalPower()).thenReturn(TOTAL_USAGE);
mPowerUsageAdvanced.setPackageManager(mPackageManager);
@@ -118,9 +123,9 @@
@Test
public void testParsePowerUsageData_PercentageCalculatedCorrectly() {
- final double percentApp = TYPE_APP_USAGE * 2 / TOTAL_USAGE * 100;
- final double percentWifi = TYPE_WIFI_USAGE / TOTAL_USAGE * 100;
- final double percentBluetooth = TYPE_BLUETOOTH_USAGE / TOTAL_USAGE * 100;
+ final double percentApp = TYPE_APP_USAGE * 2 / TOTAL_USAGE * DISCHARGE_AMOUNT;
+ final double percentWifi = TYPE_WIFI_USAGE / TOTAL_USAGE * DISCHARGE_AMOUNT;
+ final double percentBluetooth = TYPE_BLUETOOTH_USAGE / TOTAL_USAGE * DISCHARGE_AMOUNT;
List<PowerUsageData> batteryData =
mPowerUsageAdvanced.parsePowerUsageData(mBatteryStatsHelper);