forked from mirror/monocles_chat
work around platform bug when getting restrict background (Daniel Gultsch)
This commit is contained in:
parent
ac30593b96
commit
a7e9229226
1 changed files with 12 additions and 1 deletions
|
@ -2,6 +2,7 @@ package eu.siacs.conversations.ui;
|
|||
|
||||
import static eu.siacs.conversations.ui.SettingsActivity.USE_INTERNAL_UPDATER;
|
||||
|
||||
import androidx.annotation.RequiresApi;
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
|
@ -522,12 +523,22 @@ public abstract class XmppActivity extends ActionBarActivity {
|
|||
final ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
return cm != null
|
||||
&& cm.isActiveNetworkMetered()
|
||||
&& cm.getRestrictBackgroundStatus() == ConnectivityManager.RESTRICT_BACKGROUND_STATUS_ENABLED;
|
||||
&& getRestrictBackgroundStatus(cm) == ConnectivityManager.RESTRICT_BACKGROUND_STATUS_ENABLED;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.N)
|
||||
private static int getRestrictBackgroundStatus(@NonNull final ConnectivityManager connectivityManager) {
|
||||
try {
|
||||
return connectivityManager.getRestrictBackgroundStatus();
|
||||
} catch (final Exception e) {
|
||||
Log.d(Config.LOGTAG, "platform bug detected. Unable to get restrict background status", e);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean usingEnterKey() {
|
||||
return getBooleanPreference("display_enter_key", R.bool.display_enter_key);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue