Skip to content

Commit be6c5bc

Browse files
committed
fix dozing fix
1 parent 814a594 commit be6c5bc

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

Diff for: app/src/main/java/eu/faircode/netguard/ActivityMain.java

+12-6
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,8 @@ private void updateSearch(String search) {
10771077

10781078
private void checkDoze() {
10791079
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
1080-
if (Util.batteryOptimizing(this)) {
1080+
final Intent doze = new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
1081+
if (Util.batteryOptimizing(this) && getPackageManager().resolveActivity(doze, 0) != null) {
10811082
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
10821083
if (!prefs.getBoolean("nodoze", false)) {
10831084
LayoutInflater inflater = LayoutInflater.from(this);
@@ -1089,10 +1090,14 @@ private void checkDoze() {
10891090
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
10901091
@Override
10911092
public void onClick(DialogInterface dialog, int which) {
1092-
prefs.edit().putBoolean("nodoze", cbDontAsk.isChecked()).apply();
1093-
Intent i = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)
1094-
.setData(Uri.parse("package:" + getPackageName()));
1095-
startActivityForResult(i, REQUEST_BATTERY_OPTIMIZATION);
1093+
if (!Util.isPlayStoreInstall()) {
1094+
Intent i = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)
1095+
.setData(Uri.parse("package:" + getPackageName()));
1096+
startActivityForResult(i, REQUEST_BATTERY_OPTIMIZATION);
1097+
} else {
1098+
startActivity(doze);
1099+
1100+
}
10961101
}
10971102
})
10981103
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
@@ -1106,7 +1111,8 @@ public void onClick(DialogInterface dialog, int which) {
11061111
@Override
11071112
public void onDismiss(DialogInterface dialogInterface) {
11081113
dialogDoze = null;
1109-
//checkDataSaving();
1114+
if (Util.isPlayStoreInstall())
1115+
checkDataSaving();
11101116
}
11111117
})
11121118
.create();

0 commit comments

Comments
 (0)