Snap for 4535700 from c8a34adc18 to pi-release
Change-Id: I09a1d1730433a7b809d94ae91c308cde2b51907e
This commit is contained in:
@@ -90,6 +90,7 @@
|
|||||||
<uses-permission android:name="android.permission.READ_PRINT_SERVICES" />
|
<uses-permission android:name="android.permission.READ_PRINT_SERVICES" />
|
||||||
<uses-permission android:name="android.permission.NETWORK_SETTINGS" />
|
<uses-permission android:name="android.permission.NETWORK_SETTINGS" />
|
||||||
<uses-permission android:name="android.permission.TEST_BLACKLISTED_PASSWORD" />
|
<uses-permission android:name="android.permission.TEST_BLACKLISTED_PASSWORD" />
|
||||||
|
<uses-permission android:name="android.permission.USE_RESERVED_DISK" />
|
||||||
|
|
||||||
<application android:label="@string/settings_label"
|
<application android:label="@string/settings_label"
|
||||||
android:icon="@drawable/ic_launcher_settings"
|
android:icon="@drawable/ic_launcher_settings"
|
||||||
|
|||||||
25
res/drawable/ic_attach_money_black_24dp.xml
Normal file
25
res/drawable/ic_attach_money_black_24dp.xml
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2018 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.
|
||||||
|
-->
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24.0"
|
||||||
|
android:viewportHeight="24.0"
|
||||||
|
android:tint="?android:attr/colorControlNormal">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FF000000"
|
||||||
|
android:pathData="M11.8,10.9c-2.27,-0.59 -3,-1.2 -3,-2.15 0,-1.09 1.01,-1.85 2.7,-1.85 1.78,0 2.44,0.85 2.5,2.1h2.21c-0.07,-1.72 -1.12,-3.3 -3.21,-3.81V3h-3v2.16c-1.94,0.42 -3.5,1.68 -3.5,3.61 0,2.31 1.91,3.46 4.7,4.13 2.5,0.6 3,1.48 3,2.41 0,0.69 -0.49,1.79 -2.7,1.79 -2.06,0 -2.87,-0.92 -2.98,-2.1h-2.2c0.12,2.19 1.76,3.42 3.68,3.83V21h3v-2.15c1.95,-0.37 3.5,-1.5 3.5,-3.55 0,-2.84 -2.43,-3.81 -4.7,-4.4z"/>
|
||||||
|
</vector>
|
||||||
30
res/layout/smart_battery_header.xml
Normal file
30
res/layout/smart_battery_header.xml
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright (C) 2018 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!-- Entity header -->
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/entity_header"
|
||||||
|
style="@style/EntityHeader"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:minHeight="200dp"
|
||||||
|
android:paddingBottom="32dp"
|
||||||
|
android:paddingStart="@dimen/preference_no_icon_padding_start"
|
||||||
|
android:paddingTop="24dp">
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
@@ -20,9 +20,9 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:paddingTop="8dp"
|
android:paddingTop="24dp"
|
||||||
android:paddingStart="68dp"
|
android:paddingStart="68dp"
|
||||||
android:paddingEnd="8dp"
|
android:paddingEnd="24dp"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
@@ -42,6 +42,9 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="4dp" />
|
android:layout_marginBottom="4dp" />
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
<Space
|
||||||
|
android:layout_width="16dp"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
|
|||||||
@@ -316,6 +316,26 @@
|
|||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:visibility="gone">
|
android:visibility="gone">
|
||||||
|
|
||||||
|
<LinearLayout android:id="@+id/metered_settings_fields"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
style="@style/wifi_item">
|
||||||
|
|
||||||
|
<TextView android:id="@+id/metered_settings_title"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
style="@style/wifi_item_label"
|
||||||
|
android:text="@string/data_usage_metered_yes" />
|
||||||
|
|
||||||
|
<Spinner android:id="@+id/metered_settings"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
style="@style/wifi_item_spinner"
|
||||||
|
android:prompt="@string/data_usage_metered_yes"
|
||||||
|
android:entries="@array/wifi_metered_entries"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout android:id="@+id/proxy_settings_fields"
|
<LinearLayout android:id="@+id/proxy_settings_fields"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|||||||
@@ -1063,4 +1063,16 @@
|
|||||||
<item>zen_mode_from_none</item>
|
<item>zen_mode_from_none</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="wifi_metered_entries">
|
||||||
|
<item>Use network preference</item>
|
||||||
|
<item>Treat as metered</item>
|
||||||
|
<item>Treat as unmetered</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="wifi_metered_values" translatable="false">
|
||||||
|
<item>0</item>
|
||||||
|
<item>1</item>
|
||||||
|
<item>2</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -4773,6 +4773,19 @@
|
|||||||
<string name="battery_tip_low_battery_title">Low battery capacity</string>
|
<string name="battery_tip_low_battery_title">Low battery capacity</string>
|
||||||
<!-- Summary for the low battery tip [CHAR LIMIT=NONE] -->
|
<!-- Summary for the low battery tip [CHAR LIMIT=NONE] -->
|
||||||
<string name="battery_tip_low_battery_summary">Battery can\'t provide good battery life</string>
|
<string name="battery_tip_low_battery_summary">Battery can\'t provide good battery life</string>
|
||||||
|
<!-- Title for the smart battery manager preference [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="smart_battery_manager_title">Smart battery manager</string>
|
||||||
|
<!-- Title for the smart battery toggle [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="smart_battery_title">Auto-manage battery</string>
|
||||||
|
<!-- Summary for the smart battery toggle [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="smart_battery_summary">Automatically adjust power usage by apps based on usage</string>
|
||||||
|
<!-- Title for restricted app preference, clicking it will goes to restricted app list [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="restricted_app_title">Restricted apps</string>
|
||||||
|
<!-- Summary for restricted app preference, clicking it will goes to restricted app list [CHAR LIMIT=NONE] -->
|
||||||
|
<plurals name="restricted_app_summary">
|
||||||
|
<item quantity="one">%1$d app</item>
|
||||||
|
<item quantity="other">%1$d apps</item>
|
||||||
|
</plurals>
|
||||||
|
|
||||||
<!-- Title for force stop dialog [CHAR LIMIT=30] -->
|
<!-- Title for force stop dialog [CHAR LIMIT=30] -->
|
||||||
<string name="dialog_stop_title">Stop app?</string>
|
<string name="dialog_stop_title">Stop app?</string>
|
||||||
@@ -6811,10 +6824,10 @@
|
|||||||
<string name="zen_mode_add">Add</string>
|
<string name="zen_mode_add">Add</string>
|
||||||
|
|
||||||
<!-- Do not disturb: Label for button that will turn on zen mode. [CHAR LIMIT=30] -->
|
<!-- Do not disturb: Label for button that will turn on zen mode. [CHAR LIMIT=30] -->
|
||||||
<string name="zen_mode_button_turn_on">TURN ON NOW</string>
|
<string name="zen_mode_button_turn_on">Turn on now</string>
|
||||||
|
|
||||||
<!-- Do not disturb: Label for button that will turn off zen mode. [CHAR LIMIT=30] -->
|
<!-- Do not disturb: Label for button that will turn off zen mode. [CHAR LIMIT=30] -->
|
||||||
<string name="zen_mode_button_turn_off">TURN OFF NOW</string>
|
<string name="zen_mode_button_turn_off">Turn off now</string>
|
||||||
|
|
||||||
<!-- [CHAR LIMIT=110] Zen mode settings footer: Footer showing end time of DND -->
|
<!-- [CHAR LIMIT=110] Zen mode settings footer: Footer showing end time of DND -->
|
||||||
<string name="zen_mode_settings_dnd_manual_end_time">Do Not Disturb is on until <xliff:g id="formatted_time" example="7:00 AM">%s</xliff:g></string>
|
<string name="zen_mode_settings_dnd_manual_end_time">Do Not Disturb is on until <xliff:g id="formatted_time" example="7:00 AM">%s</xliff:g></string>
|
||||||
|
|||||||
@@ -27,11 +27,6 @@
|
|||||||
android:key="wifi_data_usage"
|
android:key="wifi_data_usage"
|
||||||
android:title="@string/wifi_data_usage" />
|
android:title="@string/wifi_data_usage" />
|
||||||
|
|
||||||
<com.android.settings.datausage.NetworkRestrictionsPreference
|
|
||||||
android:key="network_restrictions"
|
|
||||||
android:title="@string/network_restrictions"
|
|
||||||
android:fragment="com.android.settings.datausage.DataUsageMeteredSettings" />
|
|
||||||
|
|
||||||
</com.android.settings.datausage.TemplatePreferenceCategory>
|
</com.android.settings.datausage.TemplatePreferenceCategory>
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
|||||||
@@ -38,6 +38,11 @@
|
|||||||
android:key="battery_saver_summary"
|
android:key="battery_saver_summary"
|
||||||
android:title="@string/battery_saver"/>
|
android:title="@string/battery_saver"/>
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:fragment="com.android.settings.fuelgauge.SmartBatterySettings"
|
||||||
|
android:key="smart_battery_manager"
|
||||||
|
android:title="@string/smart_battery_manager_title"/>
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:key="battery_percentage"
|
android:key="battery_percentage"
|
||||||
android:title="@string/battery_percentage"
|
android:title="@string/battery_percentage"
|
||||||
|
|||||||
38
res/xml/smart_battery_detail.xml
Normal file
38
res/xml/smart_battery_detail.xml
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright (C) 2018 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:title="@string/smart_battery_manager_title">
|
||||||
|
|
||||||
|
<!-- TODO(b/71722498): Add header back, otherwise also remove smart_battery_header
|
||||||
|
<com.android.settings.applications.LayoutPreference
|
||||||
|
android:key="header_view"
|
||||||
|
android:layout="@layout/smart_battery_header"
|
||||||
|
android:selectable="false"
|
||||||
|
android:order="-10000"/>
|
||||||
|
-->
|
||||||
|
|
||||||
|
<SwitchPreference
|
||||||
|
android:key="smart_battery"
|
||||||
|
android:title="@string/smart_battery_title"
|
||||||
|
android:summary="@string/smart_battery_summary"/>
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:key="restricted_app"
|
||||||
|
android:title="@string/restricted_app_title"/>
|
||||||
|
|
||||||
|
</PreferenceScreen>
|
||||||
@@ -49,6 +49,13 @@
|
|||||||
android:icon="@drawable/ic_security_lock_24dp"
|
android:icon="@drawable/ic_security_lock_24dp"
|
||||||
android:title="@string/wifi_security"
|
android:title="@string/wifi_security"
|
||||||
android:selectable="false"/>
|
android:selectable="false"/>
|
||||||
|
|
||||||
|
<DropDownPreference
|
||||||
|
android:key="metered"
|
||||||
|
android:icon="@drawable/ic_attach_money_black_24dp"
|
||||||
|
android:title="@string/data_usage_metered_yes"
|
||||||
|
android:entries="@array/wifi_metered_entries"
|
||||||
|
android:entryValues="@array/wifi_metered_values"/>
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<!-- Network Details -->
|
<!-- Network Details -->
|
||||||
|
|||||||
@@ -1,150 +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.datausage;
|
|
||||||
|
|
||||||
import android.app.backup.BackupManager;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.net.NetworkPolicyManager;
|
|
||||||
import android.net.wifi.WifiConfiguration;
|
|
||||||
import android.net.wifi.WifiManager;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.provider.SearchIndexableResource;
|
|
||||||
import android.support.v7.preference.DropDownPreference;
|
|
||||||
import android.support.v7.preference.Preference;
|
|
||||||
import android.support.v7.preference.PreferenceCategory;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
|
|
||||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.SettingsPreferenceFragment;
|
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
|
||||||
import com.android.settings.search.Indexable;
|
|
||||||
import com.android.settingslib.NetworkPolicyEditor;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Panel to configure {@link WifiConfiguration#meteredOverride}.
|
|
||||||
*/
|
|
||||||
public class DataUsageMeteredSettings extends SettingsPreferenceFragment implements Indexable {
|
|
||||||
|
|
||||||
private NetworkPolicyManager mPolicyManager;
|
|
||||||
private WifiManager mWifiManager;
|
|
||||||
|
|
||||||
private NetworkPolicyEditor mPolicyEditor;
|
|
||||||
|
|
||||||
private PreferenceCategory mMobileCategory;
|
|
||||||
private PreferenceCategory mWifiCategory;
|
|
||||||
private Preference mWifiDisabled;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getMetricsCategory() {
|
|
||||||
return MetricsEvent.NET_DATA_USAGE_METERED;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle icicle) {
|
|
||||||
super.onCreate(icicle);
|
|
||||||
final Context context = getActivity();
|
|
||||||
|
|
||||||
mPolicyManager = NetworkPolicyManager.from(context);
|
|
||||||
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
|
||||||
|
|
||||||
mPolicyEditor = new NetworkPolicyEditor(mPolicyManager);
|
|
||||||
mPolicyEditor.read();
|
|
||||||
|
|
||||||
addPreferencesFromResource(R.xml.data_usage_metered_prefs);
|
|
||||||
mMobileCategory = (PreferenceCategory) findPreference("mobile");
|
|
||||||
mWifiCategory = (PreferenceCategory) findPreference("wifi");
|
|
||||||
mWifiDisabled = findPreference("wifi_disabled");
|
|
||||||
|
|
||||||
updateNetworks(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateNetworks(Context context) {
|
|
||||||
getPreferenceScreen().removePreference(mMobileCategory);
|
|
||||||
|
|
||||||
mWifiCategory.removeAll();
|
|
||||||
if (DataUsageUtils.hasWifiRadio(context) && mWifiManager.isWifiEnabled()) {
|
|
||||||
for (WifiConfiguration config : mWifiManager.getConfiguredNetworks()) {
|
|
||||||
final Preference pref = new MeteredPreference(getPrefContext(), config);
|
|
||||||
if (!TextUtils.isEmpty(pref.getTitle())) {
|
|
||||||
mWifiCategory.addPreference(pref);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
mWifiCategory.addPreference(mWifiDisabled);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class MeteredPreference extends DropDownPreference {
|
|
||||||
private final WifiConfiguration mConfig;
|
|
||||||
|
|
||||||
public MeteredPreference(Context context, WifiConfiguration config) {
|
|
||||||
super(context);
|
|
||||||
mConfig = config;
|
|
||||||
|
|
||||||
setPersistent(false);
|
|
||||||
setEntries(new CharSequence[] {
|
|
||||||
getString(R.string.data_usage_metered_auto),
|
|
||||||
getString(R.string.data_usage_metered_yes),
|
|
||||||
getString(R.string.data_usage_metered_no),
|
|
||||||
});
|
|
||||||
setEntryValues(new CharSequence[] {
|
|
||||||
Integer.toString(WifiConfiguration.METERED_OVERRIDE_NONE),
|
|
||||||
Integer.toString(WifiConfiguration.METERED_OVERRIDE_METERED),
|
|
||||||
Integer.toString(WifiConfiguration.METERED_OVERRIDE_NOT_METERED),
|
|
||||||
});
|
|
||||||
setValue(Integer.toString(mConfig.meteredOverride));
|
|
||||||
setTitle(NetworkPolicyManager.resolveNetworkId(mConfig));
|
|
||||||
setSummary(getEntries()[mConfig.meteredOverride]);
|
|
||||||
|
|
||||||
setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
|
|
||||||
@Override
|
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
||||||
mConfig.meteredOverride = Integer.parseInt((String) newValue);
|
|
||||||
setSummary(getEntries()[mConfig.meteredOverride]);
|
|
||||||
|
|
||||||
mWifiManager.updateNetwork(mConfig);
|
|
||||||
// Stage the backup of the SettingsProvider package which backs this up
|
|
||||||
BackupManager.dataChanged("com.android.providers.settings");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* For search
|
|
||||||
*/
|
|
||||||
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
|
||||||
new BaseSearchIndexProvider() {
|
|
||||||
@Override
|
|
||||||
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
|
|
||||||
boolean enabled) {
|
|
||||||
final SearchIndexableResource sir = new SearchIndexableResource(context);
|
|
||||||
sir.xmlResId = R.xml.data_usage_metered_prefs;
|
|
||||||
return Arrays.asList(sir);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getNonIndexableKeys(Context context) {
|
|
||||||
final List<String> result = super.getNonIndexableKeys(context);
|
|
||||||
result.add("mobile");
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -77,8 +77,6 @@ public class DataUsageSummary extends DataUsageBase implements Indexable, DataUs
|
|||||||
// Wifi keys
|
// Wifi keys
|
||||||
public static final String KEY_WIFI_USAGE_TITLE = "wifi_category";
|
public static final String KEY_WIFI_USAGE_TITLE = "wifi_category";
|
||||||
public static final String KEY_WIFI_DATA_USAGE = "wifi_data_usage";
|
public static final String KEY_WIFI_DATA_USAGE = "wifi_data_usage";
|
||||||
public static final String KEY_NETWORK_RESTRICTIONS = "network_restrictions";
|
|
||||||
|
|
||||||
|
|
||||||
private DataUsageController mDataUsageController;
|
private DataUsageController mDataUsageController;
|
||||||
private DataUsageInfoController mDataInfoController;
|
private DataUsageInfoController mDataInfoController;
|
||||||
@@ -86,8 +84,6 @@ public class DataUsageSummary extends DataUsageBase implements Indexable, DataUs
|
|||||||
private Preference mLimitPreference;
|
private Preference mLimitPreference;
|
||||||
private NetworkTemplate mDefaultTemplate;
|
private NetworkTemplate mDefaultTemplate;
|
||||||
private int mDataUsageTemplate;
|
private int mDataUsageTemplate;
|
||||||
private NetworkRestrictionsPreference mNetworkRestrictionPreference;
|
|
||||||
private WifiManager mWifiManager;
|
|
||||||
private NetworkPolicyEditor mPolicyEditor;
|
private NetworkPolicyEditor mPolicyEditor;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -101,7 +97,6 @@ public class DataUsageSummary extends DataUsageBase implements Indexable, DataUs
|
|||||||
|
|
||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
NetworkPolicyManager policyManager = NetworkPolicyManager.from(context);
|
NetworkPolicyManager policyManager = NetworkPolicyManager.from(context);
|
||||||
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
|
||||||
mPolicyEditor = new NetworkPolicyEditor(policyManager);
|
mPolicyEditor = new NetworkPolicyEditor(policyManager);
|
||||||
|
|
||||||
boolean hasMobileData = DataUsageUtils.hasMobileData(context);
|
boolean hasMobileData = DataUsageUtils.hasMobileData(context);
|
||||||
@@ -203,8 +198,6 @@ public class DataUsageSummary extends DataUsageBase implements Indexable, DataUs
|
|||||||
TemplatePreferenceCategory category = (TemplatePreferenceCategory)
|
TemplatePreferenceCategory category = (TemplatePreferenceCategory)
|
||||||
inflatePreferences(R.xml.data_usage_wifi);
|
inflatePreferences(R.xml.data_usage_wifi);
|
||||||
category.setTemplate(NetworkTemplate.buildTemplateWifiWildcard(), 0, services);
|
category.setTemplate(NetworkTemplate.buildTemplateWifiWildcard(), 0, services);
|
||||||
mNetworkRestrictionPreference =
|
|
||||||
(NetworkRestrictionsPreference) category.findPreference(KEY_NETWORK_RESTRICTIONS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addEthernetSection() {
|
private void addEthernetSection() {
|
||||||
@@ -293,8 +286,6 @@ public class DataUsageSummary extends DataUsageBase implements Indexable, DataUs
|
|||||||
mLimitPreference.setSummary(null);
|
mLimitPreference.setSummary(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateNetworkRestrictionSummary(mNetworkRestrictionPreference);
|
|
||||||
|
|
||||||
PreferenceScreen screen = getPreferenceScreen();
|
PreferenceScreen screen = getPreferenceScreen();
|
||||||
for (int i = 1; i < screen.getPreferenceCount(); i++) {
|
for (int i = 1; i < screen.getPreferenceCount(); i++) {
|
||||||
((TemplatePreferenceCategory) screen.getPreference(i)).pushTemplates(services);
|
((TemplatePreferenceCategory) screen.getPreference(i)).pushTemplates(services);
|
||||||
@@ -321,22 +312,6 @@ public class DataUsageSummary extends DataUsageBase implements Indexable, DataUs
|
|||||||
updateState();
|
updateState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
void updateNetworkRestrictionSummary(NetworkRestrictionsPreference preference) {
|
|
||||||
if (preference == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mPolicyEditor.read();
|
|
||||||
int count = 0;
|
|
||||||
for (WifiConfiguration config : mWifiManager.getConfiguredNetworks()) {
|
|
||||||
if (WifiConfiguration.isMetered(config, null)) {
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
preference.setSummary(getResources().getQuantityString(
|
|
||||||
R.plurals.network_restrictions_summary, count, count));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class SummaryProvider
|
private static class SummaryProvider
|
||||||
implements SummaryLoader.SummaryProvider {
|
implements SummaryLoader.SummaryProvider {
|
||||||
|
|
||||||
@@ -409,7 +384,6 @@ public class DataUsageSummary extends DataUsageBase implements Indexable, DataUs
|
|||||||
|
|
||||||
if (!DataUsageUtils.hasWifiRadio(context)) {
|
if (!DataUsageUtils.hasWifiRadio(context)) {
|
||||||
keys.add(KEY_WIFI_DATA_USAGE);
|
keys.add(KEY_WIFI_DATA_USAGE);
|
||||||
keys.add(KEY_NETWORK_RESTRICTIONS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This title is named Wifi, and will confuse users.
|
// This title is named Wifi, and will confuse users.
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 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.fuelgauge;
|
||||||
|
|
||||||
|
import android.app.AppOpsManager;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.annotation.VisibleForTesting;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.applications.LayoutPreference;
|
||||||
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controller to change and update the smart battery toggle
|
||||||
|
*/
|
||||||
|
public class RestrictAppPreferenceController extends BasePreferenceController {
|
||||||
|
@VisibleForTesting
|
||||||
|
static final String KEY_RESTRICT_APP = "restricted_app";
|
||||||
|
|
||||||
|
private AppOpsManager mAppOpsManager;
|
||||||
|
private List<AppOpsManager.PackageOps> mPackageOps;
|
||||||
|
|
||||||
|
public RestrictAppPreferenceController(Context context) {
|
||||||
|
super(context, KEY_RESTRICT_APP);
|
||||||
|
mAppOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
return AVAILABLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateState(Preference preference) {
|
||||||
|
super.updateState(preference);
|
||||||
|
mPackageOps = mAppOpsManager.getPackagesForOps(
|
||||||
|
new int[]{AppOpsManager.OP_RUN_ANY_IN_BACKGROUND});
|
||||||
|
final int num = mPackageOps != null ? mPackageOps.size() : 0;
|
||||||
|
|
||||||
|
preference.setSummary(
|
||||||
|
mContext.getResources().getQuantityString(R.plurals.restricted_app_summary, num,
|
||||||
|
num));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 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.fuelgauge;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.annotation.VisibleForTesting;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
|
|
||||||
|
import com.android.settings.applications.LayoutPreference;
|
||||||
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controller to change and update the smart battery toggle
|
||||||
|
*/
|
||||||
|
public class SmartBatteryPreferenceController extends BasePreferenceController implements
|
||||||
|
Preference.OnPreferenceChangeListener {
|
||||||
|
private static final String KEY_SMART_BATTERY = "smart_battery";
|
||||||
|
|
||||||
|
public SmartBatteryPreferenceController(Context context) {
|
||||||
|
super(context, KEY_SMART_BATTERY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
return AVAILABLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateState(Preference preference) {
|
||||||
|
super.updateState(preference);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
|
final boolean smartBatteryOn = (Boolean) newValue;
|
||||||
|
//TODO(b/71502850): use smart battery API here to update the state
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
98
src/com/android/settings/fuelgauge/SmartBatterySettings.java
Normal file
98
src/com/android/settings/fuelgauge/SmartBatterySettings.java
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 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.fuelgauge;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.provider.SearchIndexableResource;
|
||||||
|
|
||||||
|
import com.android.internal.logging.nano.MetricsProto;
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
|
import com.android.settingslib.widget.FooterPreferenceMixin;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fragment to show smart battery and restricted app controls
|
||||||
|
*/
|
||||||
|
public class SmartBatterySettings extends DashboardFragment {
|
||||||
|
public static final String TAG = "SmartBatterySettings";
|
||||||
|
|
||||||
|
private final FooterPreferenceMixin mFooterPreferenceMixin =
|
||||||
|
new FooterPreferenceMixin(this, getLifecycle());
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle icicle) {
|
||||||
|
super.onCreate(icicle);
|
||||||
|
mFooterPreferenceMixin.createFooterPreference().setTitle(R.string.battery_footer_summary);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMetricsCategory() {
|
||||||
|
return MetricsProto.MetricsEvent.FUELGAUGE_SMART_BATTERY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getLogTag() {
|
||||||
|
return TAG;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getPreferenceScreenResId() {
|
||||||
|
return R.xml.smart_battery_detail;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
|
||||||
|
return buildPreferenceControllers(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<AbstractPreferenceController> buildPreferenceControllers(
|
||||||
|
Context context) {
|
||||||
|
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||||
|
controllers.add(new SmartBatteryPreferenceController(context));
|
||||||
|
controllers.add(new RestrictAppPreferenceController(context));
|
||||||
|
return controllers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||||
|
new BaseSearchIndexProvider() {
|
||||||
|
@Override
|
||||||
|
public List<SearchIndexableResource> getXmlResourcesToIndex(
|
||||||
|
Context context, boolean enabled) {
|
||||||
|
final SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||||
|
sir.xmlResId = R.xml.smart_battery_detail;
|
||||||
|
return Arrays.asList(sir);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getNonIndexableKeys(Context context) {
|
||||||
|
return super.getNonIndexableKeys(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<AbstractPreferenceController> getPreferenceControllers(
|
||||||
|
Context context) {
|
||||||
|
return buildPreferenceControllers(context);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -31,7 +31,6 @@ import android.service.notification.ScheduleCalendar;
|
|||||||
import android.service.notification.ZenModeConfig;
|
import android.service.notification.ZenModeConfig;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
import android.support.v7.preference.PreferenceScreen;
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
import android.util.Slog;
|
|
||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.settings.core.PreferenceControllerMixin;
|
import com.android.settings.core.PreferenceControllerMixin;
|
||||||
@@ -54,6 +53,7 @@ abstract public class AbstractZenModePreferenceController extends
|
|||||||
final private NotificationManager mNotificationManager;
|
final private NotificationManager mNotificationManager;
|
||||||
protected static ZenModeConfigWrapper mZenModeConfigWrapper;
|
protected static ZenModeConfigWrapper mZenModeConfigWrapper;
|
||||||
protected MetricsFeatureProvider mMetricsFeatureProvider;
|
protected MetricsFeatureProvider mMetricsFeatureProvider;
|
||||||
|
protected final ZenModeBackend mBackend;
|
||||||
|
|
||||||
public AbstractZenModePreferenceController(Context context, String key,
|
public AbstractZenModePreferenceController(Context context, String key,
|
||||||
Lifecycle lifecycle) {
|
Lifecycle lifecycle) {
|
||||||
@@ -68,6 +68,7 @@ abstract public class AbstractZenModePreferenceController extends
|
|||||||
|
|
||||||
final FeatureFactory featureFactory = FeatureFactory.getFactory(mContext);
|
final FeatureFactory featureFactory = FeatureFactory.getFactory(mContext);
|
||||||
mMetricsFeatureProvider = featureFactory.getMetricsFeatureProvider();
|
mMetricsFeatureProvider = featureFactory.getMetricsFeatureProvider();
|
||||||
|
mBackend = ZenModeBackend.getInstance(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -90,6 +91,14 @@ abstract public class AbstractZenModePreferenceController extends
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateState(Preference preference) {
|
||||||
|
super.updateState(preference);
|
||||||
|
|
||||||
|
mBackend.updatePolicy();
|
||||||
|
mBackend.updateZenMode();
|
||||||
|
}
|
||||||
|
|
||||||
protected NotificationManager.Policy getPolicy() {
|
protected NotificationManager.Policy getPolicy() {
|
||||||
return mNotificationManager.getNotificationPolicy();
|
return mNotificationManager.getNotificationPolicy();
|
||||||
}
|
}
|
||||||
@@ -99,8 +108,8 @@ abstract public class AbstractZenModePreferenceController extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected int getZenMode() {
|
protected int getZenMode() {
|
||||||
return Settings.Global.getInt(mContext.getContentResolver(),
|
return Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.ZEN_MODE,
|
||||||
Settings.Global.ZEN_MODE, 0);
|
mBackend.mZenMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
class SettingObserver extends ContentObserver {
|
class SettingObserver extends ContentObserver {
|
||||||
@@ -188,7 +197,6 @@ abstract public class AbstractZenModePreferenceController extends
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return endTimeMs;
|
return endTimeMs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,11 +30,9 @@ public class ZenModeAlarmsPreferenceController extends
|
|||||||
AbstractZenModePreferenceController implements Preference.OnPreferenceChangeListener {
|
AbstractZenModePreferenceController implements Preference.OnPreferenceChangeListener {
|
||||||
|
|
||||||
protected static final String KEY = "zen_mode_alarms";
|
protected static final String KEY = "zen_mode_alarms";
|
||||||
private final ZenModeBackend mBackend;
|
|
||||||
|
|
||||||
public ZenModeAlarmsPreferenceController(Context context, Lifecycle lifecycle) {
|
public ZenModeAlarmsPreferenceController(Context context, Lifecycle lifecycle) {
|
||||||
super(context, KEY, lifecycle);
|
super(context, KEY, lifecycle);
|
||||||
mBackend = ZenModeBackend.getInstance(context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -82,7 +82,6 @@ public class ZenModeBackend {
|
|||||||
mZenMode = zenMode;
|
mZenMode = zenMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** gets last zen mode set by setZenMode or updateZenMode **/
|
|
||||||
protected int getZenMode() {
|
protected int getZenMode() {
|
||||||
mZenMode = Settings.Global.getInt(mContext.getContentResolver(),
|
mZenMode = Settings.Global.getInt(mContext.getContentResolver(),
|
||||||
Settings.Global.ZEN_MODE, mZenMode);
|
Settings.Global.ZEN_MODE, mZenMode);
|
||||||
|
|||||||
@@ -34,11 +34,9 @@ public class ZenModeButtonPreferenceController extends AbstractZenModePreference
|
|||||||
protected static final String KEY = "zen_mode_settings_button_container";
|
protected static final String KEY = "zen_mode_settings_button_container";
|
||||||
private Button mZenButtonOn;
|
private Button mZenButtonOn;
|
||||||
private Button mZenButtonOff;
|
private Button mZenButtonOff;
|
||||||
private ZenModeBackend mBackend;
|
|
||||||
|
|
||||||
public ZenModeButtonPreferenceController(Context context, Lifecycle lifecycle) {
|
public ZenModeButtonPreferenceController(Context context, Lifecycle lifecycle) {
|
||||||
super(context, KEY, lifecycle);
|
super(context, KEY, lifecycle);
|
||||||
mBackend = ZenModeBackend.getInstance(context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -26,11 +26,9 @@ import com.android.settingslib.core.lifecycle.Lifecycle;
|
|||||||
public class ZenModeCallsPreferenceController extends AbstractZenModePreferenceController {
|
public class ZenModeCallsPreferenceController extends AbstractZenModePreferenceController {
|
||||||
|
|
||||||
protected static final String KEY = "zen_mode_calls";
|
protected static final String KEY = "zen_mode_calls";
|
||||||
private final ZenModeBackend mBackend;
|
|
||||||
|
|
||||||
public ZenModeCallsPreferenceController(Context context, Lifecycle lifecycle) {
|
public ZenModeCallsPreferenceController(Context context, Lifecycle lifecycle) {
|
||||||
super(context, KEY, lifecycle);
|
super(context, KEY, lifecycle);
|
||||||
mBackend = ZenModeBackend.getInstance(context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -31,11 +31,9 @@ public class ZenModeEventsPreferenceController extends AbstractZenModePreference
|
|||||||
implements Preference.OnPreferenceChangeListener {
|
implements Preference.OnPreferenceChangeListener {
|
||||||
|
|
||||||
protected static final String KEY = "zen_mode_events";
|
protected static final String KEY = "zen_mode_events";
|
||||||
private final ZenModeBackend mBackend;
|
|
||||||
|
|
||||||
public ZenModeEventsPreferenceController(Context context, Lifecycle lifecycle) {
|
public ZenModeEventsPreferenceController(Context context, Lifecycle lifecycle) {
|
||||||
super(context, KEY, lifecycle);
|
super(context, KEY, lifecycle);
|
||||||
mBackend = ZenModeBackend.getInstance(context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -10,11 +10,9 @@ import com.android.settingslib.core.lifecycle.Lifecycle;
|
|||||||
public class ZenModeMessagesPreferenceController extends AbstractZenModePreferenceController {
|
public class ZenModeMessagesPreferenceController extends AbstractZenModePreferenceController {
|
||||||
|
|
||||||
protected static final String KEY = "zen_mode_messages";
|
protected static final String KEY = "zen_mode_messages";
|
||||||
private final ZenModeBackend mBackend;
|
|
||||||
|
|
||||||
public ZenModeMessagesPreferenceController(Context context, Lifecycle lifecycle) {
|
public ZenModeMessagesPreferenceController(Context context, Lifecycle lifecycle) {
|
||||||
super(context, KEY, lifecycle);
|
super(context, KEY, lifecycle);
|
||||||
mBackend = ZenModeBackend.getInstance(context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -30,11 +30,9 @@ public class ZenModeRemindersPreferenceController extends AbstractZenModePrefere
|
|||||||
implements Preference.OnPreferenceChangeListener {
|
implements Preference.OnPreferenceChangeListener {
|
||||||
|
|
||||||
protected static final String KEY = "zen_mode_reminders";
|
protected static final String KEY = "zen_mode_reminders";
|
||||||
private final ZenModeBackend mBackend;
|
|
||||||
|
|
||||||
public ZenModeRemindersPreferenceController(Context context, Lifecycle lifecycle) {
|
public ZenModeRemindersPreferenceController(Context context, Lifecycle lifecycle) {
|
||||||
super(context, KEY, lifecycle);
|
super(context, KEY, lifecycle);
|
||||||
mBackend = ZenModeBackend.getInstance(context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -30,11 +30,9 @@ public class ZenModeRepeatCallersPreferenceController extends AbstractZenModePre
|
|||||||
implements Preference.OnPreferenceChangeListener {
|
implements Preference.OnPreferenceChangeListener {
|
||||||
|
|
||||||
protected static final String KEY = "zen_mode_repeat_callers";
|
protected static final String KEY = "zen_mode_repeat_callers";
|
||||||
private final ZenModeBackend mBackend;
|
|
||||||
|
|
||||||
public ZenModeRepeatCallersPreferenceController(Context context, Lifecycle lifecycle) {
|
public ZenModeRepeatCallersPreferenceController(Context context, Lifecycle lifecycle) {
|
||||||
super(context, KEY, lifecycle);
|
super(context, KEY, lifecycle);
|
||||||
mBackend = ZenModeBackend.getInstance(context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -29,11 +29,9 @@ public class ZenModeScreenOffPreferenceController extends
|
|||||||
AbstractZenModePreferenceController implements Preference.OnPreferenceChangeListener {
|
AbstractZenModePreferenceController implements Preference.OnPreferenceChangeListener {
|
||||||
|
|
||||||
protected static final String KEY = "zen_mode_screen_off";
|
protected static final String KEY = "zen_mode_screen_off";
|
||||||
private final ZenModeBackend mBackend;
|
|
||||||
|
|
||||||
public ZenModeScreenOffPreferenceController(Context context, Lifecycle lifecycle) {
|
public ZenModeScreenOffPreferenceController(Context context, Lifecycle lifecycle) {
|
||||||
super(context, KEY, lifecycle);
|
super(context, KEY, lifecycle);
|
||||||
mBackend = ZenModeBackend.getInstance(context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -29,11 +29,9 @@ public class ZenModeScreenOnPreferenceController extends
|
|||||||
AbstractZenModePreferenceController implements Preference.OnPreferenceChangeListener {
|
AbstractZenModePreferenceController implements Preference.OnPreferenceChangeListener {
|
||||||
|
|
||||||
protected static final String KEY = "zen_mode_screen_on";
|
protected static final String KEY = "zen_mode_screen_on";
|
||||||
private final ZenModeBackend mBackend;
|
|
||||||
|
|
||||||
public ZenModeScreenOnPreferenceController(Context context, Lifecycle lifecycle) {
|
public ZenModeScreenOnPreferenceController(Context context, Lifecycle lifecycle) {
|
||||||
super(context, KEY, lifecycle);
|
super(context, KEY, lifecycle);
|
||||||
mBackend = ZenModeBackend.getInstance(context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ import com.android.settings.bluetooth.BluetoothSettings;
|
|||||||
import com.android.settings.connecteddevice.AdvancedConnectedDeviceDashboardFragment;
|
import com.android.settings.connecteddevice.AdvancedConnectedDeviceDashboardFragment;
|
||||||
import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment;
|
import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment;
|
||||||
import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragmentOld;
|
import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragmentOld;
|
||||||
import com.android.settings.datausage.DataUsageMeteredSettings;
|
|
||||||
import com.android.settings.datausage.DataUsageSummary;
|
import com.android.settings.datausage.DataUsageSummary;
|
||||||
import com.android.settings.deletionhelper.AutomaticStorageManagerSettings;
|
import com.android.settings.deletionhelper.AutomaticStorageManagerSettings;
|
||||||
import com.android.settings.development.DevelopmentSettingsDashboardFragment;
|
import com.android.settings.development.DevelopmentSettingsDashboardFragment;
|
||||||
@@ -50,6 +49,7 @@ import com.android.settings.enterprise.EnterprisePrivacySettings;
|
|||||||
import com.android.settings.fuelgauge.BatterySaverSettings;
|
import com.android.settings.fuelgauge.BatterySaverSettings;
|
||||||
import com.android.settings.fuelgauge.PowerUsageAdvanced;
|
import com.android.settings.fuelgauge.PowerUsageAdvanced;
|
||||||
import com.android.settings.fuelgauge.PowerUsageSummary;
|
import com.android.settings.fuelgauge.PowerUsageSummary;
|
||||||
|
import com.android.settings.fuelgauge.SmartBatterySettings;
|
||||||
import com.android.settings.gestures.AssistGestureSettings;
|
import com.android.settings.gestures.AssistGestureSettings;
|
||||||
import com.android.settings.gestures.DoubleTapPowerSettings;
|
import com.android.settings.gestures.DoubleTapPowerSettings;
|
||||||
import com.android.settings.gestures.DoubleTapScreenSettings;
|
import com.android.settings.gestures.DoubleTapScreenSettings;
|
||||||
@@ -110,7 +110,6 @@ public final class SearchIndexableResources {
|
|||||||
addIndex(BluetoothSettings.class);
|
addIndex(BluetoothSettings.class);
|
||||||
addIndex(SimSettings.class);
|
addIndex(SimSettings.class);
|
||||||
addIndex(DataUsageSummary.class);
|
addIndex(DataUsageSummary.class);
|
||||||
addIndex(DataUsageMeteredSettings.class);
|
|
||||||
addIndex(ScreenZoomSettings.class);
|
addIndex(ScreenZoomSettings.class);
|
||||||
addIndex(DisplaySettings.class);
|
addIndex(DisplaySettings.class);
|
||||||
addIndex(AmbientDisplaySettings.class);
|
addIndex(AmbientDisplaySettings.class);
|
||||||
@@ -174,6 +173,7 @@ public final class SearchIndexableResources {
|
|||||||
addIndex(ZenModeBehaviorSettings.class);
|
addIndex(ZenModeBehaviorSettings.class);
|
||||||
addIndex(ZenModeAutomationSettings.class);
|
addIndex(ZenModeAutomationSettings.class);
|
||||||
addIndex(NightDisplaySettings.class);
|
addIndex(NightDisplaySettings.class);
|
||||||
|
addIndex(SmartBatterySettings.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private SearchIndexableResources() {
|
private SearchIndexableResources() {
|
||||||
|
|||||||
@@ -146,11 +146,11 @@ public class WifiConfigController implements TextWatcher,
|
|||||||
private TextView mDns2View;
|
private TextView mDns2View;
|
||||||
|
|
||||||
private Spinner mProxySettingsSpinner;
|
private Spinner mProxySettingsSpinner;
|
||||||
|
private Spinner mMeteredSettingsSpinner;
|
||||||
private TextView mProxyHostView;
|
private TextView mProxyHostView;
|
||||||
private TextView mProxyPortView;
|
private TextView mProxyPortView;
|
||||||
private TextView mProxyExclusionListView;
|
private TextView mProxyExclusionListView;
|
||||||
private TextView mProxyPacView;
|
private TextView mProxyPacView;
|
||||||
|
|
||||||
private CheckBox mSharedCheckBox;
|
private CheckBox mSharedCheckBox;
|
||||||
|
|
||||||
private IpAssignment mIpAssignment = IpAssignment.UNASSIGNED;
|
private IpAssignment mIpAssignment = IpAssignment.UNASSIGNED;
|
||||||
@@ -208,6 +208,7 @@ public class WifiConfigController implements TextWatcher,
|
|||||||
mProxySettingsSpinner = (Spinner) mView.findViewById(R.id.proxy_settings);
|
mProxySettingsSpinner = (Spinner) mView.findViewById(R.id.proxy_settings);
|
||||||
mProxySettingsSpinner.setOnItemSelectedListener(this);
|
mProxySettingsSpinner.setOnItemSelectedListener(this);
|
||||||
mSharedCheckBox = (CheckBox) mView.findViewById(R.id.shared);
|
mSharedCheckBox = (CheckBox) mView.findViewById(R.id.shared);
|
||||||
|
mMeteredSettingsSpinner = mView.findViewById(R.id.metered_settings);
|
||||||
|
|
||||||
if (mAccessPoint == null) { // new network
|
if (mAccessPoint == null) { // new network
|
||||||
mConfigUi.setTitle(R.string.wifi_add_network);
|
mConfigUi.setTitle(R.string.wifi_add_network);
|
||||||
@@ -237,6 +238,7 @@ public class WifiConfigController implements TextWatcher,
|
|||||||
boolean showAdvancedFields = false;
|
boolean showAdvancedFields = false;
|
||||||
if (mAccessPoint.isSaved()) {
|
if (mAccessPoint.isSaved()) {
|
||||||
WifiConfiguration config = mAccessPoint.getConfig();
|
WifiConfiguration config = mAccessPoint.getConfig();
|
||||||
|
mMeteredSettingsSpinner.setSelection(config.meteredOverride);
|
||||||
if (config.getIpAssignment() == IpAssignment.STATIC) {
|
if (config.getIpAssignment() == IpAssignment.STATIC) {
|
||||||
mIpSettingsSpinner.setSelection(STATIC_IP);
|
mIpSettingsSpinner.setSelection(STATIC_IP);
|
||||||
showAdvancedFields = true;
|
showAdvancedFields = true;
|
||||||
@@ -671,6 +673,9 @@ public class WifiConfigController implements TextWatcher,
|
|||||||
config.setIpConfiguration(
|
config.setIpConfiguration(
|
||||||
new IpConfiguration(mIpAssignment, mProxySettings,
|
new IpConfiguration(mIpAssignment, mProxySettings,
|
||||||
mStaticIpConfiguration, mHttpProxy));
|
mStaticIpConfiguration, mHttpProxy));
|
||||||
|
if (mMeteredSettingsSpinner != null) {
|
||||||
|
config.meteredOverride = mMeteredSettingsSpinner.getSelectedItemPosition();
|
||||||
|
}
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 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.wifi.details;
|
||||||
|
|
||||||
|
import android.app.backup.BackupManager;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.net.wifi.WifiConfiguration;
|
||||||
|
import android.net.wifi.WifiManager;
|
||||||
|
import android.provider.Settings;
|
||||||
|
import android.support.annotation.VisibleForTesting;
|
||||||
|
import android.support.v14.preference.SwitchPreference;
|
||||||
|
import android.support.v7.preference.DropDownPreference;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
import com.android.settings.core.PreferenceControllerMixin;
|
||||||
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link AbstractPreferenceController} that controls whether the wifi network is metered or not
|
||||||
|
*/
|
||||||
|
public class WifiMeteredPreferenceController extends BasePreferenceController implements
|
||||||
|
Preference.OnPreferenceChangeListener {
|
||||||
|
|
||||||
|
private static final String KEY_WIFI_METERED = "metered";
|
||||||
|
private WifiConfiguration mWifiConfiguration;
|
||||||
|
private WifiManager mWifiManager;
|
||||||
|
|
||||||
|
public WifiMeteredPreferenceController(Context context, WifiConfiguration wifiConfiguration) {
|
||||||
|
super(context, KEY_WIFI_METERED);
|
||||||
|
mWifiConfiguration = wifiConfiguration;
|
||||||
|
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateState(Preference preference) {
|
||||||
|
final DropDownPreference dropDownPreference = (DropDownPreference) preference;
|
||||||
|
final int meteredOverride = getMeteredOverride();
|
||||||
|
dropDownPreference.setValue(Integer.toString(meteredOverride));
|
||||||
|
updateSummary(dropDownPreference, meteredOverride);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
return AVAILABLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
|
mWifiConfiguration.meteredOverride = Integer.parseInt((String) newValue);
|
||||||
|
mWifiManager.updateNetwork(mWifiConfiguration);
|
||||||
|
// Stage the backup of the SettingsProvider package which backs this up
|
||||||
|
BackupManager.dataChanged("com.android.providers.settings");
|
||||||
|
updateSummary((DropDownPreference) preference, getMeteredOverride());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
int getMeteredOverride() {
|
||||||
|
// Wrap the meteredOverride since robolectric cannot recognize it
|
||||||
|
return mWifiConfiguration.meteredOverride;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateSummary(DropDownPreference preference, int meteredOverride) {
|
||||||
|
preference.setSummary(preference.getEntries()[meteredOverride]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,10 +20,13 @@ import static com.android.settings.wifi.WifiSettings.WIFI_DIALOG_ID;
|
|||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.NetworkPolicyManager;
|
||||||
|
import android.net.wifi.WifiConfiguration;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
|
import android.support.v7.preference.DropDownPreference;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
@@ -122,6 +125,7 @@ public class WifiNetworkDetailsFragment extends DashboardFragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
|
protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
|
||||||
|
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||||
ConnectivityManager cm = context.getSystemService(ConnectivityManager.class);
|
ConnectivityManager cm = context.getSystemService(ConnectivityManager.class);
|
||||||
mWifiDetailPreferenceController = WifiDetailPreferenceController.newInstance(
|
mWifiDetailPreferenceController = WifiDetailPreferenceController.newInstance(
|
||||||
mAccessPoint,
|
mAccessPoint,
|
||||||
@@ -133,6 +137,9 @@ public class WifiNetworkDetailsFragment extends DashboardFragment {
|
|||||||
context.getSystemService(WifiManager.class),
|
context.getSystemService(WifiManager.class),
|
||||||
mMetricsFeatureProvider);
|
mMetricsFeatureProvider);
|
||||||
|
|
||||||
return new ArrayList<>(Collections.singletonList(mWifiDetailPreferenceController));
|
controllers.add(mWifiDetailPreferenceController);
|
||||||
|
controllers.add(new WifiMeteredPreferenceController(context, mAccessPoint.getConfig()));
|
||||||
|
|
||||||
|
return controllers;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,23 +68,6 @@ public class DataUsageSummaryTest {
|
|||||||
when(mManager.isNetworkSupported(anyInt())).thenReturn(true);
|
when(mManager.isNetworkSupported(anyInt())).thenReturn(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@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
|
@Test
|
||||||
@Config(shadows = {
|
@Config(shadows = {
|
||||||
SettingsShadowResources.class,
|
SettingsShadowResources.class,
|
||||||
|
|||||||
@@ -0,0 +1,88 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 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.fuelgauge;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.Matchers.any;
|
||||||
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
|
||||||
|
import android.app.AppOpsManager;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
|
|
||||||
|
import com.android.settings.TestConfig;
|
||||||
|
|
||||||
|
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;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
|
public class RestrictAppPreferenceControllerTest {
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private AppOpsManager mAppOpsManager;
|
||||||
|
@Mock
|
||||||
|
private AppOpsManager.PackageOps mPackageOps;
|
||||||
|
private List<AppOpsManager.PackageOps> mPackageOpsList;
|
||||||
|
private RestrictAppPreferenceController mRestrictAppPreferenceController;
|
||||||
|
private Preference mPreference;
|
||||||
|
private Context mContext;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
|
||||||
|
mContext = spy(RuntimeEnvironment.application);
|
||||||
|
doReturn(mAppOpsManager).when(mContext).getSystemService(Context.APP_OPS_SERVICE);
|
||||||
|
mRestrictAppPreferenceController = new RestrictAppPreferenceController(mContext);
|
||||||
|
mPackageOpsList = new ArrayList<>();
|
||||||
|
mPreference = new Preference(mContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateState_oneApp_showCorrectSummary() {
|
||||||
|
mPackageOpsList.add(mPackageOps);
|
||||||
|
doReturn(mPackageOpsList).when(mAppOpsManager).getPackagesForOps(any());
|
||||||
|
|
||||||
|
mRestrictAppPreferenceController.updateState(mPreference);
|
||||||
|
|
||||||
|
assertThat(mPreference.getSummary()).isEqualTo("1 app");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateState_twoApps_showCorrectSummary() {
|
||||||
|
mPackageOpsList.add(mPackageOps);
|
||||||
|
mPackageOpsList.add(mPackageOps);
|
||||||
|
doReturn(mPackageOpsList).when(mAppOpsManager).getPackagesForOps(any());
|
||||||
|
|
||||||
|
mRestrictAppPreferenceController.updateState(mPreference);
|
||||||
|
|
||||||
|
assertThat(mPreference.getSummary()).isEqualTo("2 apps");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 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.wifi.details;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.net.wifi.WifiConfiguration;
|
||||||
|
import android.support.v7.preference.DropDownPreference;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.TestConfig;
|
||||||
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
|
public class WifiMeteredPreferenceControllerTest {
|
||||||
|
public static final int METERED_OVERRIDE_NONE = 0;
|
||||||
|
public static final int METERED_OVERRIDE_METERED = 1;
|
||||||
|
public static final int METERED_OVERRIDE_NOT_METERED = 2;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private WifiConfiguration mWifiConfiguration;
|
||||||
|
|
||||||
|
private WifiMeteredPreferenceController mPreferenceController;
|
||||||
|
private Context mContext;
|
||||||
|
private DropDownPreference mDropDownPreference;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
mContext = RuntimeEnvironment.application;
|
||||||
|
|
||||||
|
mPreferenceController = spy(
|
||||||
|
new WifiMeteredPreferenceController(mContext, mWifiConfiguration));
|
||||||
|
mDropDownPreference = new DropDownPreference(mContext);
|
||||||
|
mDropDownPreference.setEntries(R.array.wifi_metered_entries);
|
||||||
|
mDropDownPreference.setEntryValues(R.array.wifi_metered_values);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateState_wifiMetered_setCorrectValue() {
|
||||||
|
doReturn(METERED_OVERRIDE_METERED).when(mPreferenceController).getMeteredOverride();
|
||||||
|
|
||||||
|
mPreferenceController.updateState(mDropDownPreference);
|
||||||
|
|
||||||
|
assertThat(mDropDownPreference.getEntry()).isEqualTo("Treat as metered");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateState_wifiNotMetered_setCorrectValue() {
|
||||||
|
doReturn(METERED_OVERRIDE_NOT_METERED).when(mPreferenceController).getMeteredOverride();
|
||||||
|
|
||||||
|
mPreferenceController.updateState(mDropDownPreference);
|
||||||
|
|
||||||
|
assertThat(mDropDownPreference.getEntry()).isEqualTo("Treat as unmetered");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateState_wifiAuto_setCorrectValue() {
|
||||||
|
doReturn(METERED_OVERRIDE_NONE).when(mPreferenceController).getMeteredOverride();
|
||||||
|
|
||||||
|
mPreferenceController.updateState(mDropDownPreference);
|
||||||
|
|
||||||
|
assertThat(mDropDownPreference.getEntry()).isEqualTo("Use network preference");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user