mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-22 01:40:07 +01:00
Put info about data saver in the logs.
This commit is contained in:
committed by
Cody Henthorne
parent
f119496da4
commit
1a657a7a19
@@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.util;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.ActivityManager.MemoryInfo;
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.os.Build;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -55,4 +56,51 @@ public final class DeviceProperties {
|
||||
ActivityManager activityManager = ServiceUtil.getActivityManager(context);
|
||||
return activityManager.isBackgroundRestricted();
|
||||
}
|
||||
|
||||
public static DataSaverState getDataSaverState(@NonNull Context context) {
|
||||
if (Build.VERSION.SDK_INT >= 24) {
|
||||
switch (ServiceUtil.getConnectivityManager(context).getRestrictBackgroundStatus()) {
|
||||
case ConnectivityManager.RESTRICT_BACKGROUND_STATUS_ENABLED:
|
||||
return DataSaverState.ENABLED;
|
||||
case ConnectivityManager.RESTRICT_BACKGROUND_STATUS_WHITELISTED:
|
||||
return DataSaverState.ENABLED_BUT_EXEMPTED;
|
||||
case ConnectivityManager.RESTRICT_BACKGROUND_STATUS_DISABLED:
|
||||
return DataSaverState.DISABLED;
|
||||
}
|
||||
}
|
||||
|
||||
return DataSaverState.DISABLED;
|
||||
}
|
||||
|
||||
public enum DataSaverState {
|
||||
/** Data saver is enabled system-wide, and we are subject to the restrictions. */
|
||||
ENABLED(true, true),
|
||||
|
||||
/** Data saver is enabled system-wide, but the user has exempted us by giving us 'unrestricted access' to data in the system settings */
|
||||
ENABLED_BUT_EXEMPTED(true, false),
|
||||
|
||||
/** Data saver is disabled. */
|
||||
DISABLED(false, false);
|
||||
|
||||
private final boolean enabled;
|
||||
private final boolean restricted;
|
||||
|
||||
DataSaverState(boolean enabled, boolean restricted) {
|
||||
this.enabled = enabled;
|
||||
this.restricted = restricted;
|
||||
}
|
||||
|
||||
/** True if the device has data saver enabled, otherwise false. */
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* True if we're subject to data saver restrictions, otherwise false.
|
||||
* Even if data saver is enabled device-wide, this could still be false if the user has given us 'unrestricted access' to data in the system settings.
|
||||
*/
|
||||
public boolean isRestricted() {
|
||||
return restricted;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user