Skip to content

Commit

Permalink
Another fix for Service_SnoozeAlarm being killed.
Browse files Browse the repository at this point in the history
Some devices are still reporting that the snooze service is being killed midway, even after e384368. In this commit, some changes have been made in AlarmBroadcastReceiver so as to prevent spurious triggering of Service_UpdateAlarm.
  • Loading branch information
WrichikBasu committed Nov 14, 2020
1 parent 8f889fe commit 40627d6
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 24 deletions.
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "in.basulabs.shakealarmclock"
minSdkVersion 21
targetSdkVersion 30
versionCode 13
versionName "1.2.10"
versionCode 14
versionName "1.2.11"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -36,12 +36,12 @@ android {

dependencies {
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.0.10'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.1'
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "androidx.work:work-runtime:2.4.0"
implementation 'com.github.javiersantos:AppUpdater:2.7'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation "androidx.room:room-runtime:2.2.5"
annotationProcessor "androidx.room:room-compiler:2.2.5"
implementation 'androidx.cardview:cardview:1.0.0'
Expand Down
9 changes: 0 additions & 9 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,6 @@
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.TIMEZONE_CHANGED" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.DATE_CHANGED" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.TIME_SET" />
</intent-filter>
</receiver>

<activity android:name=".Activity_AlarmsList"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@ public void onReceive(Context context, Intent intent) {
"in.basulabs.shakealarmclock::AlarmRingServiceWakelockTag");
wakeLock.acquire(60000);

Intent intent1 = new Intent(context, Service_RingAlarm.class);
intent1.putExtra(ConstantsAndStatics.BUNDLE_KEY_ALARM_DETAILS,
Intent intent1 = new Intent(context, Service_RingAlarm.class)
.putExtra(ConstantsAndStatics.BUNDLE_KEY_ALARM_DETAILS,
Objects.requireNonNull(intent.getExtras()).getBundle(ConstantsAndStatics.BUNDLE_KEY_ALARM_DETAILS));
ContextCompat.startForegroundService(context, intent1);

} else if (Objects.equals(intent.getAction(), Intent.ACTION_BOOT_COMPLETED)
|| intent.getAction().equals(Intent.ACTION_TIMEZONE_CHANGED)
|| intent.getAction().equals(Intent.ACTION_TIME_CHANGED)) {
} else if (Objects.equals(intent.getAction(), Intent.ACTION_BOOT_COMPLETED)) {

PowerManager powerManager = (PowerManager) context.getSystemService(POWER_SERVICE);
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ private Notification buildSnoozeNotification() {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, Integer.toString(NOTIFICATION_ID))
.setContentTitle(getResources().getString(R.string.app_name))
.setContentText(getResources().getString(R.string.notifContent_snooze))
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setCategory(NotificationCompat.CATEGORY_STATUS)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setCategory(NotificationCompat.CATEGORY_ALARM)
.setSmallIcon(R.drawable.ic_notif)
.setContentIntent(contentPendingIntent);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ public Result doWork() {
if (Service_RingAlarm.isThisServiceRunning || Service_SnoozeAlarm.isThisServiceRunning) {
return Result.failure();
} else {
activateAlarmsIfInactive();
return Result.success();
return activateAlarmsIfInactive();
}
}

Expand All @@ -53,7 +52,7 @@ public Result doWork() {
/**
* Activates the alarms that are ON, but inactive because {@link AlarmManager} has cancelled them for no reason.
*/
private void activateAlarmsIfInactive() {
private Result activateAlarmsIfInactive() {

final AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
final AlarmDatabase alarmDatabase = AlarmDatabase.getInstance(context);
Expand Down Expand Up @@ -131,10 +130,11 @@ private void activateAlarmsIfInactive() {
}

if ((stopExecuting && ! isStopped()) || Service_RingAlarm.isThisServiceRunning || Service_SnoozeAlarm.isThisServiceRunning) {
break;
return Result.failure();
}
}
}
return Result.success();
}

//----------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit 40627d6

Please sign in to comment.