Refactoring

This commit is contained in:
M66B 2021-07-01 21:43:47 +02:00
parent effa492418
commit 80197c9bbc
3 changed files with 25 additions and 17 deletions

View File

@ -416,6 +416,23 @@ public class ConnectionHelper {
message.contains("requires valid address");
}
static boolean isDataSaving(Context context) {
// https://developer.android.com/training/basics/network-ops/data-saver.html
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N)
return false;
ConnectivityManager cm =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm == null)
return false;
// RESTRICT_BACKGROUND_STATUS_DISABLED: Data Saver is disabled.
// RESTRICT_BACKGROUND_STATUS_ENABLED: The user has enabled Data Saver for this app. (Globally)
// RESTRICT_BACKGROUND_STATUS_WHITELISTED: The user has enabled Data Saver but the app is allowed to bypass it.
int status = cm.getRestrictBackgroundStatus();
return (status == ConnectivityManager.RESTRICT_BACKGROUND_STATUS_ENABLED);
}
static boolean vpnActive(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm == null)

View File

@ -559,20 +559,14 @@ public class FragmentSetup extends FragmentBase {
tvDozeDone.setCompoundDrawablesWithIntrinsicBounds(ignoring == null || ignoring ? check : null, null, null, null);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
ActivityManager am = (ActivityManager) getContext().getSystemService(Context.ACTIVITY_SERVICE);
grpBackgroundRestricted.setVisibility(am.isBackgroundRestricted() ? View.VISIBLE : View.GONE);
ActivityManager am =
(ActivityManager) getContext().getSystemService(Context.ACTIVITY_SERVICE);
grpBackgroundRestricted.setVisibility(am.isBackgroundRestricted()
? View.VISIBLE : View.GONE);
}
// https://developer.android.com/training/basics/network-ops/data-saver.html
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
ConnectivityManager cm = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm != null) {
int status = cm.getRestrictBackgroundStatus();
grpDataSaver.setVisibility(
status == ConnectivityManager.RESTRICT_BACKGROUND_STATUS_ENABLED
? View.VISIBLE : View.GONE);
}
}
grpDataSaver.setVisibility(ConnectionHelper.isDataSaving(getContext())
? View.VISIBLE : View.GONE);
}
@Override

View File

@ -1727,11 +1727,8 @@ public class Log {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
sb.append(String.format("Background restricted: %b\r\n", am.isBackgroundRestricted()));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
boolean saving = (cm.getRestrictBackgroundStatus() == ConnectivityManager.RESTRICT_BACKGROUND_STATUS_ENABLED);
sb.append(String.format("Data saving: %b\r\n", saving));
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
sb.append(String.format("Data saving: %b\r\n", ConnectionHelper.isDataSaving(context)));
String charset = MimeUtility.getDefaultJavaCharset();
sb.append(String.format("Default charset: %s/%s\r\n", charset, MimeUtility.mimeCharset(charset)));