Commit 35d72f8c authored by Romain Hunault's avatar Romain Hunault

Merge remote-tracking branch 'origin/lineage-16.0' into v1-pie

parents 93f13309 4616aaba
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2012-2016 The CyanogenMod Project
Copyright (C) 2017 The LineageOS Project
Copyright (C) 2017-2019 The LineageOS Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
......@@ -336,6 +336,8 @@
<!-- Per-app data restrictions -->
<string name="data_usage_app_restrict_data">Cellular data</string>
<string name="data_usage_app_restrict_data_summary">Enable usage of cellular data</string>
<string name="data_usage_app_restrict_vpn">VPN data</string>
<string name="data_usage_app_restrict_vpn_summary">Enable usage of VPN data</string>
<string name="data_usage_app_restrict_wifi">Wi\u2011Fi data</string>
<string name="data_usage_app_restrict_wifi_summary">Enable usage of Wi\u2011Fi data</string>
......
......@@ -54,12 +54,12 @@
android:key="app_settings"
android:title="@string/data_usage_app_settings" />
<SwitchPreference
<com.android.settingslib.RestrictedSwitchPreference
android:key="restrict_wlan"
android:title="@string/data_usage_app_restrict_wifi"
android:summary="@string/data_usage_app_restrict_wifi_summary" />
<SwitchPreference
<com.android.settingslib.RestrictedSwitchPreference
android:key="restrict_data"
android:title="@string/data_usage_app_restrict_data"
android:summary="@string/data_usage_app_restrict_data_summary" />
......@@ -71,6 +71,11 @@
settings:useAdditionalSummary="true"
settings:restrictedSwitchSummary="@string/disabled_by_admin" />
<com.android.settingslib.RestrictedSwitchPreference
android:key="restrict_vpn"
android:title="@string/data_usage_app_restrict_vpn"
android:summary="@string/data_usage_app_restrict_vpn_summary" />
<com.android.settingslib.RestrictedSwitchPreference
android:key="unrestricted_data_saver"
android:title="@string/unrestricted_app_title"
......
......@@ -16,6 +16,7 @@ package com.android.settings.datausage;
import static android.net.NetworkPolicyManager.POLICY_REJECT_METERED_BACKGROUND;
import static android.net.NetworkPolicyManager.POLICY_REJECT_ON_DATA;
import static android.net.NetworkPolicyManager.POLICY_REJECT_ON_VPN;
import static android.net.NetworkPolicyManager.POLICY_REJECT_ON_WLAN;
import android.app.Activity;
......@@ -73,6 +74,7 @@ public class AppDataUsage extends DataUsageBase implements Preference.OnPreferen
private static final String KEY_APP_SETTINGS = "app_settings";
private static final String KEY_RESTRICT_BACKGROUND = "restrict_background";
private static final String KEY_RESTRICT_DATA = "restrict_data";
private static final String KEY_RESTRICT_VPN = "restrict_vpn";
private static final String KEY_RESTRICT_WLAN = "restrict_wlan";
private static final String KEY_APP_LIST = "app_list";
private static final String KEY_CYCLE = "cycle";
......@@ -89,6 +91,7 @@ public class AppDataUsage extends DataUsageBase implements Preference.OnPreferen
private Preference mAppSettings;
private RestrictedSwitchPreference mRestrictBackground;
private SwitchPreference mRestrictData;
private SwitchPreference mRestrictVpn;
private SwitchPreference mRestrictWlan;
private PreferenceCategory mAppList;
......@@ -171,6 +174,7 @@ public class AppDataUsage extends DataUsageBase implements Preference.OnPreferen
removePreference(KEY_UNRESTRICTED_DATA);
removePreference(KEY_RESTRICT_BACKGROUND);
removePreference(KEY_RESTRICT_DATA);
removePreference(KEY_RESTRICT_VPN);
removePreference(KEY_RESTRICT_WLAN);
} else {
mRestrictBackground = (RestrictedSwitchPreference) findPreference(
......@@ -178,6 +182,8 @@ public class AppDataUsage extends DataUsageBase implements Preference.OnPreferen
mRestrictBackground.setOnPreferenceChangeListener(this);
mRestrictData = (SwitchPreference) findPreference(KEY_RESTRICT_DATA);
mRestrictData.setOnPreferenceChangeListener(this);
mRestrictVpn = (SwitchPreference) findPreference(KEY_RESTRICT_VPN);
mRestrictVpn.setOnPreferenceChangeListener(this);
mRestrictWlan = (SwitchPreference) findPreference(KEY_RESTRICT_WLAN);
mRestrictWlan.setOnPreferenceChangeListener(this);
mUnrestrictedData = (RestrictedSwitchPreference) findPreference(
......@@ -221,6 +227,7 @@ public class AppDataUsage extends DataUsageBase implements Preference.OnPreferen
removePreference(KEY_APP_SETTINGS);
removePreference(KEY_RESTRICT_BACKGROUND);
removePreference(KEY_RESTRICT_DATA);
removePreference(KEY_RESTRICT_VPN);
removePreference(KEY_RESTRICT_WLAN);
removePreference(KEY_APP_LIST);
}
......@@ -262,6 +269,10 @@ public class AppDataUsage extends DataUsageBase implements Preference.OnPreferen
setAppRestrictData(!(Boolean) newValue);
updatePrefs();
return true;
} else if (preference == mRestrictVpn) {
setAppRestrictVpn(!(Boolean) newValue);
updatePrefs();
return true;
} else if (preference == mRestrictWlan) {
setAppRestrictWlan(!(Boolean) newValue);
updatePrefs();
......@@ -287,11 +298,11 @@ public class AppDataUsage extends DataUsageBase implements Preference.OnPreferen
@VisibleForTesting
void updatePrefs() {
updatePrefs(getAppRestrictBackground(), getUnrestrictData(),
getAppRestrictData(), getAppRestrictWlan());
getAppRestrictData(), getAppRestrictVpn(), getAppRestrictWlan());
}
private void updatePrefs(boolean restrictBackground, boolean unrestrictData,
boolean restrictData, boolean restrictWlan) {
boolean restrictData, boolean restrictVpn, boolean restrictWlan) {
final EnforcedAdmin admin = RestrictedLockUtils.checkIfMeteredDataRestricted(
getContext(), mPackageName, UserHandle.getUserId(mAppItem.key));
if (mRestrictBackground != null) {
......@@ -307,6 +318,9 @@ public class AppDataUsage extends DataUsageBase implements Preference.OnPreferen
if (mRestrictData != null) {
mRestrictData.setChecked(!restrictData);
}
if (mRestrictVpn != null) {
mRestrictVpn.setChecked(!restrictVpn);
}
if (mRestrictWlan != null) {
mRestrictWlan.setChecked(!restrictWlan);
}
......@@ -361,6 +375,10 @@ public class AppDataUsage extends DataUsageBase implements Preference.OnPreferen
return getAppRestriction(POLICY_REJECT_ON_DATA);
}
private boolean getAppRestrictVpn() {
return getAppRestriction(POLICY_REJECT_ON_VPN);
}
private boolean getAppRestrictWlan() {
return getAppRestriction(POLICY_REJECT_ON_WLAN);
}
......@@ -382,6 +400,10 @@ public class AppDataUsage extends DataUsageBase implements Preference.OnPreferen
setAppRestriction(POLICY_REJECT_ON_DATA, restrict);
}
private void setAppRestrictVpn(boolean restrict) {
setAppRestriction(POLICY_REJECT_ON_VPN, restrict);
}
private void setAppRestrictWlan(boolean restrict) {
setAppRestriction(POLICY_REJECT_ON_WLAN, restrict);
}
......@@ -499,7 +521,7 @@ public class AppDataUsage extends DataUsageBase implements Preference.OnPreferen
public void onWhitelistStatusChanged(int uid, boolean isWhitelisted) {
if (mAppItem.uids.get(uid, false)) {
updatePrefs(getAppRestrictBackground(), isWhitelisted,
getAppRestrictData(), getAppRestrictWlan());
getAppRestrictData(), getAppRestrictVpn(), getAppRestrictWlan());
}
}
......@@ -507,7 +529,7 @@ public class AppDataUsage extends DataUsageBase implements Preference.OnPreferen
public void onBlacklistStatusChanged(int uid, boolean isBlacklisted) {
if (mAppItem.uids.get(uid, false)) {
updatePrefs(isBlacklisted, getUnrestrictData(),
getAppRestrictData(), getAppRestrictWlan());
getAppRestrictData(), getAppRestrictVpn(), getAppRestrictWlan());
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment