Refactoring

pull/199/head
M66B 4 years ago
parent effa492418
commit 80197c9bbc

@ -416,6 +416,23 @@ public class ConnectionHelper {
message.contains("requires valid address"); 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) { static boolean vpnActive(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm == null) if (cm == null)

@ -559,20 +559,14 @@ public class FragmentSetup extends FragmentBase {
tvDozeDone.setCompoundDrawablesWithIntrinsicBounds(ignoring == null || ignoring ? check : null, null, null, null); tvDozeDone.setCompoundDrawablesWithIntrinsicBounds(ignoring == null || ignoring ? check : null, null, null, null);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
ActivityManager am = (ActivityManager) getContext().getSystemService(Context.ACTIVITY_SERVICE); ActivityManager am =
grpBackgroundRestricted.setVisibility(am.isBackgroundRestricted() ? View.VISIBLE : View.GONE); (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 grpDataSaver.setVisibility(ConnectionHelper.isDataSaving(getContext())
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { ? View.VISIBLE : View.GONE);
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);
}
}
} }
@Override @Override

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

Loading…
Cancel
Save