add rationale to ignore-battery-optimization request

while it is more straight-forward to let the system ask the user directly -
as we do for most other permissions -
this is probably not favorable for requesting ignore-battery-optimization:

- other permissions requests are preceded by a clear user intention -
  tap on the camera, record voice etc.
  so it is clear to the user why a permission is needed.
  this is not true at the moment after installation
  (maybe the moment can be improved, btw)

- different systems have completely different text,
  partly focusing on "battery drain" - it is not clear to the user
  what would be the advantage of that

- some guidelines say, user interaction is needed before querying permission.
  there is room for interpretation, of couse,
  however, adding a rational with a "continue" button
  seems to fit better to these guidelines.
This commit is contained in:
B. Petersen 2020-09-06 23:44:34 +02:00
parent 742ce78c9c
commit 14dc59d78c
No known key found for this signature in database
GPG key ID: 3B88E92DEA8E9AFC
2 changed files with 13 additions and 4 deletions

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_ask">Do you want to receive messages in the background?\n\nThis requires ignored battery optimizations, however, Delta 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>

View file

@ -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;
@ -110,10 +111,17 @@ 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_ask)
.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);
})
.setNegativeButton(R.string.not_now, null)
.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