1
0
mirror of https://github.com/etesync/android synced 2024-12-23 15:18:14 +00:00

Request ignoring battery optimization

* startup dialog: request to ignore battery optimizations
* remove F-Droid donation startup dialog (only useful for davdroid-ose)
* version bump to 1.2.2
This commit is contained in:
Ricki Hirner 2016-08-02 18:34:39 +02:00
parent 967bc50256
commit d675fb961e
5 changed files with 47 additions and 4 deletions

View File

@ -17,14 +17,15 @@ android {
minSdkVersion 14
targetSdkVersion 24
versionCode 110
versionCode 111
buildConfigField "long", "buildTime", System.currentTimeMillis() + "L"
buildConfigField "boolean", "useMTM", "true"
}
productFlavors {
standard {
versionName "1.2.1-ose"
versionName "1.2.2-ose"
}
}

View File

@ -19,6 +19,7 @@
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS"/>
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS"/>
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS"/>
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
<!-- legacy permissions -->
<uses-permission

View File

@ -75,6 +75,7 @@ public class AppSettingsActivity extends AppCompatActivity {
private void resetHints() {
@Cleanup ServiceDB.OpenHelper dbHelper = new ServiceDB.OpenHelper(getContext());
Settings settings = new Settings(dbHelper.getWritableDatabase());
settings.remove(StartupDialogFragment.HINT_BATTERY_OPTIMIZATIONS);
settings.remove(StartupDialogFragment.HINT_OPENTASKS_NOT_INSTALLED);
Snackbar.make(getView(), R.string.app_settings_reset_hints_success, Snackbar.LENGTH_LONG).show();
}

View File

@ -17,6 +17,7 @@ import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.PowerManager;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
@ -37,13 +38,17 @@ import lombok.Cleanup;
public class StartupDialogFragment extends DialogFragment {
public static final String
HINT_BATTERY_OPTIMIZATIONS = "hint_BatteryOptimizations",
HINT_GOOGLE_PLAY_ACCOUNTS_REMOVED = "hint_GooglePlayAccountsRemoved",
HINT_OPENTASKS_NOT_INSTALLED = "hint_OpenTasksNotInstalled";
private static final String ARGS_MODE = "mode";
enum Mode {
BATTERY_OPTIMIZATIONS,
DEVELOPMENT_VERSION,
FDROID_DONATE,
GOOGLE_PLAY_ACCOUNTS_REMOVED,
OPENTASKS_NOT_INSTALLED
}
@ -58,9 +63,15 @@ public class StartupDialogFragment extends DialogFragment {
else
dialogs.add(StartupDialogFragment.instantiate(Mode.FDROID_DONATE));
// battery optimization whitelisting
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && settings.getBoolean(HINT_BATTERY_OPTIMIZATIONS, true)) {
PowerManager powerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
if (!powerManager.isIgnoringBatteryOptimizations(BuildConfig.APPLICATION_ID))
dialogs.add(StartupDialogFragment.instantiate(Mode.BATTERY_OPTIMIZATIONS));
}
// OpenTasks information
if (!LocalTaskList.tasksProviderAvailable(context) &&
settings.getBoolean(HINT_OPENTASKS_NOT_INSTALLED, true))
if (!LocalTaskList.tasksProviderAvailable(context) && settings.getBoolean(HINT_OPENTASKS_NOT_INSTALLED, true))
dialogs.add(StartupDialogFragment.instantiate(Mode.OPENTASKS_NOT_INSTALLED));
Collections.reverse(dialogs);
@ -84,6 +95,32 @@ public class StartupDialogFragment extends DialogFragment {
Mode mode = Mode.valueOf(getArguments().getString(ARGS_MODE));
switch (mode) {
case BATTERY_OPTIMIZATIONS:
return new AlertDialog.Builder(getActivity())
.setTitle(R.string.startup_battery_optimization)
.setMessage(R.string.startup_battery_optimization_message)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.setNeutralButton(R.string.startup_battery_optimization_disable, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(android.provider.Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS,
Uri.parse("package:" + BuildConfig.APPLICATION_ID));
getContext().startActivity(intent);
}
})
.setNegativeButton(R.string.startup_dont_show_again, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Settings settings = new Settings(dbHelper.getWritableDatabase());
settings.putBoolean(HINT_BATTERY_OPTIMIZATIONS, false);
}
})
.create();
case DEVELOPMENT_VERSION:
return new AlertDialog.Builder(getActivity())
.setIcon(R.drawable.ic_launcher)

View File

@ -17,6 +17,9 @@
<string name="send">Send</string>
<!-- startup dialogs -->
<string name="startup_battery_optimization">Battery Optimization</string>
<string name="startup_battery_optimization_message">Android may disable/reduce DAVdroid synchronization after a few days. To prevent this, turn off battery optimization.</string>
<string name="startup_battery_optimization_disable">Turn off for DAVdroid</string>
<string name="startup_dont_show_again">Don\'t show again</string>
<string name="startup_development_version">DAVdroid Preview Release</string>
<string name="startup_development_version_message">This is a development version of DAVdroid. Be aware that things may not work as expected. Please give us constructive feedback to improve DAVdroid.</string>