Exact alarm improvements

pull/199/head
M66B 4 years ago
parent 3657c93796
commit 4f83eb572b

@ -459,6 +459,10 @@
<intent-filter>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
</intent-filter>
<intent-filter>
<action android:name="android.app.action.SCHEDULE_EXACT_ALARM_PERMISSION_STATE_CHANGED" />
</intent-filter>
</receiver>
</application>
</manifest>

@ -459,6 +459,10 @@
<intent-filter>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
</intent-filter>
<intent-filter>
<action android:name="android.app.action.SCHEDULE_EXACT_ALARM_PERMISSION_STATE_CHANGED" />
</intent-filter>
</receiver>
</application>
</manifest>

@ -459,6 +459,10 @@
<intent-filter>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
</intent-filter>
<intent-filter>
<action android:name="android.app.action.SCHEDULE_EXACT_ALARM_PERMISSION_STATE_CHANGED" />
</intent-filter>
</receiver>
</application>
</manifest>

@ -36,18 +36,25 @@ public class AlarmManagerCompatEx {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean exact_alarms = prefs.getBoolean("exact_alarms", true);
// https://developer.android.com/about/versions/12/behavior-changes-12#exact-alarm-permission
if (exact_alarms && canScheduleExactAlarms(context))
try {
AlarmManagerCompat.setExactAndAllowWhileIdle(am, type, trigger, pi);
} catch (SecurityException ex) {
Log.w(ex);
AlarmManagerCompat.setAndAllowWhileIdle(am, type, trigger, pi);
}
else
AlarmManagerCompat.setAndAllowWhileIdle(am, type, trigger, pi);
}
static boolean canScheduleExactAlarms(Context context) {
if (Build.VERSION.SDK_INT < 31 /* S */)
return true;
else
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.R)
return true;
else {
//AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
//return am.canScheduleExactAlarms();
return true;
}
}
}

@ -24,17 +24,27 @@ import android.content.Context;
import android.content.Intent;
public class ReceiverAutoStart extends BroadcastReceiver {
// https://developer.android.com/reference/android/app/AlarmManager#ACTION_SCHEDULE_EXACT_ALARM_PERMISSION_STATE_CHANGED
private final String ACTION_EXACT =
"android.app.action.SCHEDULE_EXACT_ALARM_PERMISSION_STATE_CHANGED";
@Override
public void onReceive(final Context context, Intent intent) {
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction()) ||
Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction())) {
String action = intent.getAction();
if (ACTION_EXACT.equals(action) ||
Intent.ACTION_BOOT_COMPLETED.equals(action) ||
Intent.ACTION_MY_PACKAGE_REPLACED.equals(action)) {
Log.i("Received " + intent);
if (Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction()))
if (Intent.ACTION_MY_PACKAGE_REPLACED.equals(action))
ApplicationEx.upgrade(context);
if (ACTION_EXACT.equals(action))
ServiceSynchronize.reload(context, null, false, action);
else {
ServiceSynchronize.boot(context);
ServiceSend.boot(context);
}
}
}
}

@ -460,6 +460,10 @@
<intent-filter>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
</intent-filter>
<intent-filter>
<action android:name="android.app.action.SCHEDULE_EXACT_ALARM_PERMISSION_STATE_CHANGED" />
</intent-filter>
</receiver>
</application>
</manifest>

Loading…
Cancel
Save