Updater: Check if network is really metered
Instead of assuming so, based on whether user is connected over a WiFi or Ethernet connection, simply use the proper API. Use default value of PREF_MOBILE_DATA_WARNING, if it had been already set. Change-Id: Ie4fa0301df7f2cebf94c967fc188acc54b2ce71e Signed-off-by: althafvly <althafvly@gmail.com>
This commit is contained in:
@@ -38,11 +38,11 @@
|
|||||||
android:textSize="16sp" />
|
android:textSize="16sp" />
|
||||||
|
|
||||||
<androidx.appcompat.widget.SwitchCompat
|
<androidx.appcompat.widget.SwitchCompat
|
||||||
android:id="@+id/preferences_mobile_data_warning"
|
android:id="@+id/preferences_metered_network_warning"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="16dp"
|
android:layout_marginBottom="16dp"
|
||||||
android:text="@string/menu_mobile_data_warning"
|
android:text="@string/menu_metered_network_warning"
|
||||||
android:textSize="16sp" />
|
android:textSize="16sp" />
|
||||||
|
|
||||||
<androidx.appcompat.widget.SwitchCompat
|
<androidx.appcompat.widget.SwitchCompat
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!--
|
<!--
|
||||||
Copyright (C) 2017-2020 The LineageOS Project
|
Copyright (C) 2017-2023 The LineageOS Project
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -140,10 +140,10 @@
|
|||||||
<item quantity="other"><xliff:g id="count">%d</xliff:g> hours left</item>
|
<item quantity="other"><xliff:g id="count">%d</xliff:g> hours left</item>
|
||||||
</plurals>
|
</plurals>
|
||||||
|
|
||||||
<string name="update_on_mobile_data_title">Warning</string>
|
<string name="update_over_metered_network_title">Warning</string>
|
||||||
<string name="update_on_mobile_data_message">You\'re about to download an update package using mobile data which is likely going to cause high data usage. Would you like to proceed?</string>
|
<string name="update_over_metered_network_message">You\'re about to download an update package over a metered network which is likely going to cause high data usage. Would you like to proceed?</string>
|
||||||
<string name="checkbox_mobile_data_warning">Do not show again</string>
|
<string name="checkbox_metered_network_warning">Do not show again</string>
|
||||||
<string name="menu_mobile_data_warning">Mobile data warning</string>
|
<string name="menu_metered_network_warning">Metered network warning</string>
|
||||||
|
|
||||||
<string name="blocked_update_dialog_title">Update blocked</string>
|
<string name="blocked_update_dialog_title">Update blocked</string>
|
||||||
<string name="blocked_update_dialog_message">This update cannot be installed using the updater app. Please read <xliff:g id="info_url">%1$s</xliff:g> for more information.</string>
|
<string name="blocked_update_dialog_message">This update cannot be installed using the updater app. Please read <xliff:g id="info_url">%1$s</xliff:g> for more information.</string>
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2017-2022 The LineageOS Project
|
* Copyright (C) 2017-2023 The LineageOS Project
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -481,7 +481,8 @@ public class UpdatesActivity extends UpdatesListActivity {
|
|||||||
View view = LayoutInflater.from(this).inflate(R.layout.preferences_dialog, null);
|
View view = LayoutInflater.from(this).inflate(R.layout.preferences_dialog, null);
|
||||||
Spinner autoCheckInterval = view.findViewById(R.id.preferences_auto_updates_check_interval);
|
Spinner autoCheckInterval = view.findViewById(R.id.preferences_auto_updates_check_interval);
|
||||||
SwitchCompat autoDelete = view.findViewById(R.id.preferences_auto_delete_updates);
|
SwitchCompat autoDelete = view.findViewById(R.id.preferences_auto_delete_updates);
|
||||||
SwitchCompat dataWarning = view.findViewById(R.id.preferences_mobile_data_warning);
|
SwitchCompat meteredNetworkWarning = view.findViewById(
|
||||||
|
R.id.preferences_metered_network_warning);
|
||||||
SwitchCompat abPerfMode = view.findViewById(R.id.preferences_ab_perf_mode);
|
SwitchCompat abPerfMode = view.findViewById(R.id.preferences_ab_perf_mode);
|
||||||
SwitchCompat updateRecovery = view.findViewById(R.id.preferences_update_recovery);
|
SwitchCompat updateRecovery = view.findViewById(R.id.preferences_update_recovery);
|
||||||
|
|
||||||
@@ -492,7 +493,8 @@ public class UpdatesActivity extends UpdatesListActivity {
|
|||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
autoCheckInterval.setSelection(Utils.getUpdateCheckSetting(this));
|
autoCheckInterval.setSelection(Utils.getUpdateCheckSetting(this));
|
||||||
autoDelete.setChecked(prefs.getBoolean(Constants.PREF_AUTO_DELETE_UPDATES, false));
|
autoDelete.setChecked(prefs.getBoolean(Constants.PREF_AUTO_DELETE_UPDATES, false));
|
||||||
dataWarning.setChecked(prefs.getBoolean(Constants.PREF_MOBILE_DATA_WARNING, true));
|
meteredNetworkWarning.setChecked(prefs.getBoolean(Constants.PREF_METERED_NETWORK_WARNING,
|
||||||
|
prefs.getBoolean(Constants.PREF_MOBILE_DATA_WARNING, true)));
|
||||||
abPerfMode.setChecked(prefs.getBoolean(Constants.PREF_AB_PERF_MODE, false));
|
abPerfMode.setChecked(prefs.getBoolean(Constants.PREF_AB_PERF_MODE, false));
|
||||||
|
|
||||||
if (getResources().getBoolean(R.bool.config_hideRecoveryUpdate)) {
|
if (getResources().getBoolean(R.bool.config_hideRecoveryUpdate)) {
|
||||||
@@ -531,7 +533,8 @@ public class UpdatesActivity extends UpdatesListActivity {
|
|||||||
.putInt(Constants.PREF_AUTO_UPDATES_CHECK_INTERVAL,
|
.putInt(Constants.PREF_AUTO_UPDATES_CHECK_INTERVAL,
|
||||||
autoCheckInterval.getSelectedItemPosition())
|
autoCheckInterval.getSelectedItemPosition())
|
||||||
.putBoolean(Constants.PREF_AUTO_DELETE_UPDATES, autoDelete.isChecked())
|
.putBoolean(Constants.PREF_AUTO_DELETE_UPDATES, autoDelete.isChecked())
|
||||||
.putBoolean(Constants.PREF_MOBILE_DATA_WARNING, dataWarning.isChecked())
|
.putBoolean(Constants.PREF_METERED_NETWORK_WARNING,
|
||||||
|
meteredNetworkWarning.isChecked())
|
||||||
.putBoolean(Constants.PREF_AB_PERF_MODE, abPerfMode.isChecked())
|
.putBoolean(Constants.PREF_AB_PERF_MODE, abPerfMode.isChecked())
|
||||||
.apply();
|
.apply();
|
||||||
|
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2017-2022 The LineageOS Project
|
* Copyright (C) 2017-2023 The LineageOS Project
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -316,25 +316,25 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
|
|||||||
|
|
||||||
private void startDownloadWithWarning(final String downloadId) {
|
private void startDownloadWithWarning(final String downloadId) {
|
||||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(mActivity);
|
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(mActivity);
|
||||||
boolean warn = preferences.getBoolean(Constants.PREF_MOBILE_DATA_WARNING, true);
|
boolean warn = preferences.getBoolean(Constants.PREF_METERED_NETWORK_WARNING, true);
|
||||||
if (Utils.isOnWifiOrEthernet(mActivity) || !warn) {
|
if (!(Utils.isNetworkMetered(mActivity) && warn)) {
|
||||||
mUpdaterController.startDownload(downloadId);
|
mUpdaterController.startDownload(downloadId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
View checkboxView = LayoutInflater.from(mActivity).inflate(R.layout.checkbox_view, null);
|
View checkboxView = LayoutInflater.from(mActivity).inflate(R.layout.checkbox_view, null);
|
||||||
CheckBox checkbox = checkboxView.findViewById(R.id.checkbox);
|
CheckBox checkbox = checkboxView.findViewById(R.id.checkbox);
|
||||||
checkbox.setText(R.string.checkbox_mobile_data_warning);
|
checkbox.setText(R.string.checkbox_metered_network_warning);
|
||||||
|
|
||||||
new AlertDialog.Builder(mActivity)
|
new AlertDialog.Builder(mActivity)
|
||||||
.setTitle(R.string.update_on_mobile_data_title)
|
.setTitle(R.string.update_over_metered_network_title)
|
||||||
.setMessage(R.string.update_on_mobile_data_message)
|
.setMessage(R.string.update_over_metered_network_message)
|
||||||
.setView(checkboxView)
|
.setView(checkboxView)
|
||||||
.setPositiveButton(R.string.action_download,
|
.setPositiveButton(R.string.action_download,
|
||||||
(dialog, which) -> {
|
(dialog, which) -> {
|
||||||
if (checkbox.isChecked()) {
|
if (checkbox.isChecked()) {
|
||||||
preferences.edit()
|
preferences.edit()
|
||||||
.putBoolean(Constants.PREF_MOBILE_DATA_WARNING, false)
|
.putBoolean(Constants.PREF_METERED_NETWORK_WARNING, false)
|
||||||
.apply();
|
.apply();
|
||||||
mActivity.supportInvalidateOptionsMenu();
|
mActivity.supportInvalidateOptionsMenu();
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2017-2020 The LineageOS Project
|
* Copyright (C) 2017-2023 The LineageOS Project
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -32,6 +32,7 @@ public final class Constants {
|
|||||||
public static final String PREF_AUTO_UPDATES_CHECK_INTERVAL = "auto_updates_check_interval";
|
public static final String PREF_AUTO_UPDATES_CHECK_INTERVAL = "auto_updates_check_interval";
|
||||||
public static final String PREF_AUTO_DELETE_UPDATES = "auto_delete_updates";
|
public static final String PREF_AUTO_DELETE_UPDATES = "auto_delete_updates";
|
||||||
public static final String PREF_AB_PERF_MODE = "ab_perf_mode";
|
public static final String PREF_AB_PERF_MODE = "ab_perf_mode";
|
||||||
|
public static final String PREF_METERED_NETWORK_WARNING = "pref_metered_network_warning";
|
||||||
public static final String PREF_MOBILE_DATA_WARNING = "pref_mobile_data_warning";
|
public static final String PREF_MOBILE_DATA_WARNING = "pref_mobile_data_warning";
|
||||||
public static final String PREF_NEEDS_REBOOT_ID = "needs_reboot_id";
|
public static final String PREF_NEEDS_REBOOT_ID = "needs_reboot_id";
|
||||||
|
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2017-2022 The LineageOS Project
|
* Copyright (C) 2017-2023 The LineageOS Project
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -191,11 +191,9 @@ public class Utils {
|
|||||||
return !(info == null || !info.isConnected() || !info.isAvailable());
|
return !(info == null || !info.isConnected() || !info.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isOnWifiOrEthernet(Context context) {
|
public static boolean isNetworkMetered(Context context) {
|
||||||
ConnectivityManager cm = context.getSystemService(ConnectivityManager.class);
|
ConnectivityManager cm = context.getSystemService(ConnectivityManager.class);
|
||||||
NetworkInfo info = cm.getActiveNetworkInfo();
|
return cm.isActiveNetworkMetered();
|
||||||
return (info != null && (info.getType() == ConnectivityManager.TYPE_ETHERNET
|
|
||||||
|| info.getType() == ConnectivityManager.TYPE_WIFI));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user