Skip to content

Commit

Permalink
AllInOneActivity: Don't request disabling doze on pre-M devices
Browse files Browse the repository at this point in the history
Signed-off-by: Aayush Gupta <[email protected]>
  • Loading branch information
theimpulson committed Nov 1, 2023
1 parent 09463e5 commit cea9416
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions app/src/main/java/com/android/calendar/AllInOneActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.widget.SearchView;
import androidx.appcompat.widget.Toolbar;
Expand Down Expand Up @@ -423,6 +424,7 @@ private void checkAppPermissions() {

}

@RequiresApi(Build.VERSION_CODES.M)
private void checkAndRequestDisablingDoze() {
if (!dozeDisabled()) {
Intent intent = new Intent();
Expand All @@ -433,6 +435,7 @@ private void checkAndRequestDisablingDoze() {
}

private Boolean dozeDisabled() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return true;
String packageName = getApplicationContext().getPackageName();
PowerManager pm = (PowerManager) getApplicationContext().getSystemService(Context.POWER_SERVICE);
return pm.isIgnoringBatteryOptimizations(packageName);
Expand All @@ -450,7 +453,9 @@ public void onRequestPermissionsResult(int requestCode,
// permission was granted, yay!

// Check and ask to disable battery optimizations
checkAndRequestDisablingDoze();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
checkAndRequestDisablingDoze();
}

} else {
Toast.makeText(getApplicationContext(), R.string.user_rejected_calendar_write_permission, Toast.LENGTH_LONG).show();
Expand Down Expand Up @@ -974,7 +979,9 @@ public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth
intent.putExtra(SettingsActivityKt.EXTRA_SHOW_FRAGMENT, ViewDetailsPreferences.class.getName());
startActivity(intent);
} else if (itemId == R.id.action_info) {
checkAndRequestDisablingDoze();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
checkAndRequestDisablingDoze();
}
} else {
return mExtensions.handleItemSelected(item, this);
}
Expand Down

0 comments on commit cea9416

Please sign in to comment.