Light battery optimizations cleanup.
This commit is contained in:
parent
ca210f2b6d
commit
b51ec53e33
2 changed files with 14 additions and 3 deletions
|
@ -14,6 +14,7 @@ import androidx.annotation.RequiresApi;
|
|||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||
import org.thoughtcrime.securesms.util.PowerManagerCompat;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
|
||||
@SuppressLint("BatteryLife")
|
||||
|
@ -25,9 +26,7 @@ public class DozeReminder extends Reminder {
|
|||
|
||||
setOkListener(v -> {
|
||||
TextSecurePreferences.setPromptedOptimizeDoze(context, true);
|
||||
Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS,
|
||||
Uri.parse("package:" + context.getPackageName()));
|
||||
context.startActivity(intent);
|
||||
PowerManagerCompat.requestIgnoreBatteryOptimizations(context);
|
||||
});
|
||||
|
||||
setDismissListener(v -> TextSecurePreferences.setPromptedOptimizeDoze(context, true));
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
package org.thoughtcrime.securesms.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.PowerManager;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.RequiresApi;
|
||||
|
||||
public class PowerManagerCompat {
|
||||
|
||||
|
@ -13,4 +18,11 @@ public class PowerManagerCompat {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@RequiresApi(api = 23)
|
||||
public static void requestIgnoreBatteryOptimizations(@NonNull Context context) {
|
||||
Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS,
|
||||
Uri.parse("package:" + context.getPackageName()));
|
||||
context.startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue