Merge pull request #1616 from deltachat/battery-rationale

add rationale to ignore-battery-optimization request
This commit is contained in:
cyBerta
2020-09-09 15:42:01 +02:00
committed by GitHub
2 changed files with 14 additions and 6 deletions
+1
View File
@@ -718,6 +718,7 @@
<!-- android specific strings, developers: please take care to remove strings that are no longer used! -->
<string name="pref_background_notifications">Background notifications</string>
<string name="pref_background_notifications_explain">Uses a background connection to your server and requires ignored battery optimizations.</string>
<string name="pref_background_notifications_rationale">To maintain connection to your email server and receive messages in the background, ignore battery optimizations in the next step.\n\nDelta Chat uses few resources and takes care not to drain your battery.</string>
<!-- disabling "Reliable service" will hide a the maybe annoying permanent-notification with the drawback that new-message-notifications get potentially unreliable -->
<string name="pref_reliable_service">Reliable background connection</string>
<string name="pref_reliable_service_explain">Requires a permanent notification</string>
@@ -10,6 +10,7 @@ import android.net.Uri;
import android.os.Build;
import android.os.PowerManager;
import android.provider.Settings;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat;
@@ -65,8 +66,8 @@ public class DozeReminder {
public static void addDozeReminderDeviceMsg(Context context) {
DcContext dcContext = DcHelper.getContext(context);
DcMsg msg = new DcMsg(dcContext, DcMsg.DC_MSG_TEXT);
msg.setText(context.getString(R.string.perm_enable_bg_reminder_title)+"\n\n"
+context.getString(R.string.perm_enable_bg_reminder_text));
msg.setText("\uD83D\uDC49 "+context.getString(R.string.perm_enable_bg_reminder_title)+" \uD83D\uDC48\n\n"
+context.getString(R.string.pref_background_notifications_rationale));
int msgId = dcContext.addDeviceMsg("android.doze-reminder", msg);
if(msgId!=0) {
Prefs.setPromptedDozeMsgId(context, msgId);
@@ -110,10 +111,16 @@ public class DozeReminder {
&& !Prefs.getBooleanPreference(context, Prefs.DOZE_ASKED_DIRECTLY, false)
&& ContextCompat.checkSelfPermission(context, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS) == PackageManager.PERMISSION_GRANTED
&& !((PowerManager) context.getSystemService(Context.POWER_SERVICE)).isIgnoringBatteryOptimizations(context.getPackageName())) {
Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS,
Uri.parse("package:" + context.getPackageName()));
context.startActivity(intent);
new AlertDialog.Builder(context)
.setTitle(R.string.pref_background_notifications)
.setMessage(R.string.pref_background_notifications_rationale)
.setPositiveButton(R.string.perm_continue, (dialog, which) -> {
Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS,
Uri.parse("package:" + context.getPackageName()));
context.startActivity(intent);
})
.setCancelable(false)
.show();
}
// Prefs.DOZE_ASKED_DIRECTLY is also used above in isEligible().
// As long as Prefs.DOZE_ASKED_DIRECTLY is false, isEligible() will return false