mirror of https://github.com/M66B/FairEmail.git
Refactoring: schedule exact alarm
This commit is contained in:
parent
61e9407f62
commit
9074047eb0
|
@ -188,7 +188,7 @@ public class EntityAccount extends EntityOrder implements Serializable {
|
|||
}
|
||||
|
||||
boolean isExempted(Context context) {
|
||||
return (!Helper.isOptimizing12(context) && this.poll_exempted);
|
||||
return this.poll_exempted;
|
||||
}
|
||||
|
||||
String getProtocol() {
|
||||
|
|
|
@ -47,8 +47,7 @@ public class FragmentDialogStill extends FragmentDialogBase {
|
|||
final Context context = getContext();
|
||||
View dview = LayoutInflater.from(context).inflate(R.layout.dialog_setup, null);
|
||||
TextView tvDozeDevice = dview.findViewById(R.id.tvDozeDevice);
|
||||
TextView tvDozeAndroid = dview.findViewById(R.id.tvDozeAndroid);
|
||||
TextView tvInexact = dview.findViewById(R.id.tvInexact);
|
||||
TextView tvDozeAndroid12 = dview.findViewById(R.id.tvDozeAndroid12);
|
||||
CheckBox cbNotAgain = dview.findViewById(R.id.cbNotAgain);
|
||||
Group grp2 = dview.findViewById(R.id.grp2);
|
||||
Group grp3 = dview.findViewById(R.id.grp3);
|
||||
|
@ -70,17 +69,14 @@ public class FragmentDialogStill extends FragmentDialogBase {
|
|||
});
|
||||
|
||||
boolean hasPermissions = Helper.hasPermission(context, Manifest.permission.READ_CONTACTS);
|
||||
Boolean isIgnoring = Helper.isIgnoringOptimizations(context);
|
||||
boolean isKilling = Helper.isKilling() && !(isIgnoring == null || isIgnoring);
|
||||
boolean isOptimizing = Helper.isOptimizing12(context);
|
||||
boolean canSchedule = AlarmManagerCompatEx.canScheduleExactAlarms(context);
|
||||
boolean isIgnoring = !Boolean.FALSE.equals(Helper.isIgnoringOptimizations(context));
|
||||
boolean canScheduleExact = AlarmManagerCompatEx.canScheduleExactAlarms(getContext());
|
||||
|
||||
tvDozeDevice.setVisibility(isKilling && !isOptimizing ? View.VISIBLE : View.GONE);
|
||||
tvDozeAndroid.setVisibility(isOptimizing ? View.VISIBLE : View.GONE);
|
||||
tvInexact.setVisibility(canSchedule ? View.GONE : View.VISIBLE);
|
||||
tvDozeDevice.setVisibility(Helper.isKilling() && !isIgnoring ? View.VISIBLE : View.GONE);
|
||||
tvDozeAndroid12.setVisibility(!canScheduleExact && !isIgnoring ? View.VISIBLE : View.GONE);
|
||||
|
||||
grp2.setVisibility(hasPermissions ? View.GONE : View.VISIBLE);
|
||||
grp3.setVisibility(isIgnoring == null || isIgnoring ? View.GONE : View.VISIBLE);
|
||||
grp3.setVisibility(isIgnoring ? View.GONE : View.VISIBLE);
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context)
|
||||
.setView(dview)
|
||||
|
|
|
@ -4461,14 +4461,15 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
if (!setup_reminder)
|
||||
return false;
|
||||
|
||||
boolean isOptimizing = Helper.isOptimizing12(context);
|
||||
boolean canSchedule = AlarmManagerCompatEx.canScheduleExactAlarms(context);
|
||||
|
||||
if (!isOptimizing && canSchedule)
|
||||
if (!Helper.isAndroid12())
|
||||
return false;
|
||||
if (!Boolean.FALSE.equals(Helper.isIgnoringOptimizations(context)))
|
||||
return false;
|
||||
if (AlarmManagerCompatEx.canScheduleExactAlarms(context))
|
||||
return false;
|
||||
|
||||
final Snackbar snackbar = Snackbar.make(view,
|
||||
canSchedule ? R.string.title_setup_doze_12 : R.string.title_setup_alarm_12,
|
||||
R.string.title_setup_alarm_12,
|
||||
Snackbar.LENGTH_INDEFINITE)
|
||||
.setGestureInsetBottomIgnored(true);
|
||||
snackbar.setAction(R.string.title_fix, new View.OnClickListener() {
|
||||
|
|
|
@ -484,10 +484,9 @@ public class FragmentOptions extends FragmentBase {
|
|||
boolean setup_reminder = prefs.getBoolean("setup_reminder", true);
|
||||
|
||||
boolean hasPermissions = hasPermission(Manifest.permission.READ_CONTACTS);
|
||||
Boolean isIgnoring = Helper.isIgnoringOptimizations(getContext());
|
||||
boolean isIgnoring = !Boolean.FALSE.equals(Helper.isIgnoringOptimizations(getContext()));
|
||||
|
||||
if (!setup_reminder ||
|
||||
(hasPermissions && (isIgnoring == null || isIgnoring)))
|
||||
if (!setup_reminder || (hasPermissions && isIgnoring))
|
||||
super.finish();
|
||||
else {
|
||||
FragmentDialogStill fragment = new FragmentDialogStill();
|
||||
|
|
|
@ -634,8 +634,7 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
|
|||
}
|
||||
|
||||
private void bindTo(EntityAccount account) {
|
||||
cbExempted.setEnabled(!Helper.isOptimizing12(context) &&
|
||||
!account.ondemand && account.protocol == EntityAccount.TYPE_IMAP);
|
||||
cbExempted.setEnabled(!account.ondemand && account.protocol == EntityAccount.TYPE_IMAP);
|
||||
cbExempted.setChecked(account.poll_exempted);
|
||||
cbExempted.setText(account.name);
|
||||
}
|
||||
|
|
|
@ -103,7 +103,6 @@ public class FragmentSetup extends FragmentBase {
|
|||
private TextView tvDoze12;
|
||||
private ImageButton ibDoze;
|
||||
|
||||
private Button btnInexactAlarms;
|
||||
private Button btnBackgroundRestricted;
|
||||
private Button btnDataSaver;
|
||||
private TextView tvStamina;
|
||||
|
@ -116,7 +115,6 @@ public class FragmentSetup extends FragmentBase {
|
|||
private Button btnMore;
|
||||
private Button btnSupport;
|
||||
|
||||
private Group grpInexactAlarms;
|
||||
private Group grpBackgroundRestricted;
|
||||
private Group grpDataSaver;
|
||||
private Group grpSupport;
|
||||
|
@ -175,7 +173,6 @@ public class FragmentSetup extends FragmentBase {
|
|||
tvDoze12 = view.findViewById(R.id.tvDoze12);
|
||||
ibDoze = view.findViewById(R.id.ibDoze);
|
||||
|
||||
btnInexactAlarms = view.findViewById(R.id.btnInexactAlarms);
|
||||
btnBackgroundRestricted = view.findViewById(R.id.btnBackgroundRestricted);
|
||||
btnDataSaver = view.findViewById(R.id.btnDataSaver);
|
||||
tvStamina = view.findViewById(R.id.tvStamina);
|
||||
|
@ -188,7 +185,6 @@ public class FragmentSetup extends FragmentBase {
|
|||
btnMore = view.findViewById(R.id.btnMore);
|
||||
btnSupport = view.findViewById(R.id.btnSupport);
|
||||
|
||||
grpInexactAlarms = view.findViewById(R.id.grpInexactAlarms);
|
||||
grpBackgroundRestricted = view.findViewById(R.id.grpBackgroundRestricted);
|
||||
grpDataSaver = view.findViewById(R.id.grpDataSaver);
|
||||
grpSupport = view.findViewById(R.id.grpSupport);
|
||||
|
@ -534,20 +530,6 @@ public class FragmentSetup extends FragmentBase {
|
|||
|
||||
PackageManager pm = getContext().getPackageManager();
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
final Intent settings = new Intent(
|
||||
Settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM,
|
||||
Uri.parse("package:" + BuildConfig.APPLICATION_ID));
|
||||
|
||||
btnInexactAlarms.setEnabled(settings.resolveActivity(pm) != null); // system whitelisted
|
||||
btnInexactAlarms.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
startActivity(settings);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
final Intent settings = new Intent(
|
||||
Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
|
||||
|
@ -639,7 +621,6 @@ public class FragmentSetup extends FragmentBase {
|
|||
|
||||
btnInbox.setEnabled(false);
|
||||
|
||||
grpInexactAlarms.setVisibility(View.GONE);
|
||||
grpBackgroundRestricted.setVisibility(View.GONE);
|
||||
grpDataSaver.setVisibility(View.GONE);
|
||||
tvStamina.setVisibility(View.GONE);
|
||||
|
@ -745,7 +726,8 @@ public class FragmentSetup extends FragmentBase {
|
|||
}
|
||||
|
||||
// Doze
|
||||
Boolean ignoring = Helper.isIgnoringOptimizations(getContext());
|
||||
boolean isIgnoring = !Boolean.FALSE.equals(Helper.isIgnoringOptimizations(getContext()));
|
||||
boolean canScheduleExact = AlarmManagerCompatEx.canScheduleExactAlarms(getContext());
|
||||
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
|
||||
btnDoze.setEnabled(false);
|
||||
|
@ -755,19 +737,15 @@ public class FragmentSetup extends FragmentBase {
|
|||
if (intent.resolveActivity(pm) == null)
|
||||
btnDoze.setEnabled(false);
|
||||
else
|
||||
btnDoze.setEnabled((ignoring != null && !ignoring) || BuildConfig.DEBUG);
|
||||
btnDoze.setEnabled(!isIgnoring || BuildConfig.DEBUG);
|
||||
}
|
||||
|
||||
boolean done = (ignoring == null || ignoring || Helper.isArc());
|
||||
tvDozeDone.setText(done ? R.string.title_setup_done : R.string.title_setup_to_do);
|
||||
tvDozeDone.setTextColor(done ? textColorPrimary : colorWarning);
|
||||
tvDozeDone.setTypeface(null, done ? Typeface.NORMAL : Typeface.BOLD);
|
||||
tvDozeDone.setCompoundDrawablesWithIntrinsicBounds(done ? check : null, null, null, null);
|
||||
tvDoze12.setVisibility(Helper.isOptimizing12(getContext()) ? View.VISIBLE : View.GONE);
|
||||
tvDozeDone.setText(isIgnoring ? R.string.title_setup_done : R.string.title_setup_to_do);
|
||||
tvDozeDone.setTextColor(isIgnoring ? textColorPrimary : colorWarning);
|
||||
tvDozeDone.setTypeface(null, isIgnoring ? Typeface.NORMAL : Typeface.BOLD);
|
||||
tvDozeDone.setCompoundDrawablesWithIntrinsicBounds(isIgnoring ? check : null, null, null, null);
|
||||
|
||||
grpInexactAlarms.setVisibility(
|
||||
!AlarmManagerCompatEx.canScheduleExactAlarms(getContext())
|
||||
? View.VISIBLE : View.GONE);
|
||||
tvDoze12.setVisibility(!canScheduleExact && !isIgnoring ? View.VISIBLE : View.GONE);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
ActivityManager am =
|
||||
|
|
|
@ -450,6 +450,9 @@ public class Helper {
|
|||
}
|
||||
|
||||
static Boolean isIgnoringOptimizations(Context context) {
|
||||
if (isArc())
|
||||
return true;
|
||||
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
|
||||
return null;
|
||||
|
||||
|
@ -460,14 +463,6 @@ public class Helper {
|
|||
return pm.isIgnoringBatteryOptimizations(BuildConfig.APPLICATION_ID);
|
||||
}
|
||||
|
||||
static boolean isOptimizing12(Context context) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S || true)
|
||||
return false;
|
||||
|
||||
Boolean ignoring = Helper.isIgnoringOptimizations(context);
|
||||
return (ignoring != null && !ignoring);
|
||||
}
|
||||
|
||||
static Integer getBatteryLevel(Context context) {
|
||||
try {
|
||||
BatteryManager bm = (BatteryManager) context.getSystemService(Context.BATTERY_SERVICE);
|
||||
|
@ -1112,12 +1107,11 @@ public class Helper {
|
|||
// Vivo
|
||||
isRealme() ||
|
||||
isBlackview() ||
|
||||
isSony() ||
|
||||
BuildConfig.DEBUG);
|
||||
isSony());
|
||||
}
|
||||
|
||||
static boolean isDozeRequired() {
|
||||
return (Build.VERSION.SDK_INT > Build.VERSION_CODES.R && false);
|
||||
static boolean isAndroid12() {
|
||||
return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S);
|
||||
}
|
||||
|
||||
static String getUiModeType(Context context) {
|
||||
|
|
|
@ -2879,9 +2879,6 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|||
}
|
||||
|
||||
static int getPollInterval(Context context) {
|
||||
if (Helper.isOptimizing12(context))
|
||||
return (BuildConfig.DEBUG ? 2 : 15);
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
return prefs.getInt("poll_interval", 0); // minutes
|
||||
}
|
||||
|
|
|
@ -105,22 +105,7 @@
|
|||
app:layout_constraintTop_toBottomOf="@id/tvDoze" />
|
||||
|
||||
<eu.faircode.email.FixedTextView
|
||||
android:id="@+id/tvDozeAndroid"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:drawableStart="@drawable/twotone_warning_24"
|
||||
android:drawablePadding="6dp"
|
||||
android:drawableTint="?attr/colorWarning"
|
||||
android:text="@string/title_setup_doze_12"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
android:textColor="?attr/colorWarning"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvDozeDevice" />
|
||||
|
||||
<eu.faircode.email.FixedTextView
|
||||
android:id="@+id/tvInexact"
|
||||
android:id="@+id/tvDozeAndroid12"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
|
@ -132,7 +117,7 @@
|
|||
android:textColor="?attr/colorWarning"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvDozeAndroid" />
|
||||
app:layout_constraintTop_toBottomOf="@id/tvDozeDevice" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/cbNotAgain"
|
||||
|
@ -142,7 +127,7 @@
|
|||
android:text="@string/title_no_ask_again"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvInexact" />
|
||||
app:layout_constraintTop_toBottomOf="@id/tvDozeAndroid12" />
|
||||
|
||||
<androidx.constraintlayout.widget.Group
|
||||
android:id="@+id/grp2"
|
||||
|
|
|
@ -706,47 +706,11 @@
|
|||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvDoze" />
|
||||
|
||||
<eu.faircode.email.FixedTextView
|
||||
android:id="@+id/tvDozeHint"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="6dp"
|
||||
android:text="@string/title_setup_doze_hint"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/btnDoze" />
|
||||
|
||||
<eu.faircode.email.FixedTextView
|
||||
android:id="@+id/tvDoze12"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:drawableStart="@drawable/twotone_warning_24"
|
||||
android:drawablePadding="6dp"
|
||||
android:drawableTint="?attr/colorWarning"
|
||||
android:text="@string/title_setup_doze_12"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
android:textColor="?attr/colorWarning"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvDozeHint" />
|
||||
|
||||
<eu.faircode.email.FixedImageButton
|
||||
android:id="@+id/ibDoze"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:contentDescription="@string/title_info"
|
||||
android:tooltipText="@string/title_info"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvDoze12"
|
||||
app:srcCompat="@drawable/twotone_info_24" />
|
||||
|
||||
<eu.faircode.email.FixedTextView
|
||||
android:id="@+id/tvInexactAlarmsWarning"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:layout_marginTop="6dp"
|
||||
android:drawableStart="@drawable/twotone_warning_24"
|
||||
android:drawablePadding="6dp"
|
||||
android:drawableTint="?attr/colorWarning"
|
||||
|
@ -755,32 +719,28 @@
|
|||
android:textColor="?attr/colorWarning"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/ibDoze" />
|
||||
app:layout_constraintTop_toBottomOf="@id/btnDoze" />
|
||||
|
||||
<eu.faircode.email.FixedTextView
|
||||
android:id="@+id/tvInexactAlarms"
|
||||
android:id="@+id/tvDozeHint"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="6dp"
|
||||
android:text="@string/title_setup_inexact"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
android:textColor="?attr/colorWarning"
|
||||
android:textStyle="bold"
|
||||
android:text="@string/title_setup_doze_hint"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvInexactAlarmsWarning" />
|
||||
app:layout_constraintTop_toBottomOf="@id/tvDoze12" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnInexactAlarms"
|
||||
style="?android:attr/buttonStyleSmall"
|
||||
<eu.faircode.email.FixedImageButton
|
||||
android:id="@+id/ibDoze"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_marginTop="6dp"
|
||||
android:drawableEnd="@drawable/twotone_settings_24"
|
||||
android:drawablePadding="6dp"
|
||||
android:text="@string/title_setup_manage"
|
||||
android:contentDescription="@string/title_info"
|
||||
android:tooltipText="@string/title_info"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvInexactAlarms" />
|
||||
app:layout_constraintTop_toBottomOf="@id/tvDozeHint"
|
||||
app:srcCompat="@drawable/twotone_info_24" />
|
||||
|
||||
<eu.faircode.email.FixedTextView
|
||||
android:id="@+id/tvBackgroundRestricted"
|
||||
|
@ -795,7 +755,7 @@
|
|||
android:textColor="?attr/colorWarning"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/btnInexactAlarms" />
|
||||
app:layout_constraintTop_toBottomOf="@id/ibDoze" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnBackgroundRestricted"
|
||||
|
@ -881,12 +841,6 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvBatteryUsage" />
|
||||
|
||||
<androidx.constraintlayout.widget.Group
|
||||
android:id="@+id/grpInexactAlarms"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:constraint_referenced_ids="tvInexactAlarms,tvInexactAlarmsWarning,btnInexactAlarms" />
|
||||
|
||||
<androidx.constraintlayout.widget.Group
|
||||
android:id="@+id/grpBackgroundRestricted"
|
||||
android:layout_width="0dp"
|
||||
|
|
|
@ -229,7 +229,6 @@
|
|||
<string name="title_setup_doze_battery">High battery usage?</string>
|
||||
<string name="title_setup_doze_stopped">Sync stopped?</string>
|
||||
<string name="title_setup_doze_device">This is probably required for this device</string>
|
||||
<string name="title_setup_doze_12">Push messages are disabled</string>
|
||||
<string name="title_setup_alarm_12">The app won\'t work</string>
|
||||
<string name="title_setup_inexact">Alarms & reminders are disabled</string>
|
||||
<string name="title_setup_background">Background restrictions are enabled</string>
|
||||
|
|
Loading…
Reference in New Issue