Updater: The great cleanup

* Make final where possible
* Remove unused casts, imports, methods, enums and constructors
* Add null checks

Change-Id: Idd1a16426dd1928e2ed9922f5a35ba32ce4f808b
This commit is contained in:
Michael W
2022-01-31 17:28:01 +01:00
parent bdb6a3ff66
commit 46c06ad958
23 changed files with 340 additions and 401 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017 The LineageOS Project
* Copyright (C) 2017-2022 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -84,17 +84,17 @@ public class UpdatesCheckReceiver extends BroadcastReceiver {
}
@Override
public void onResponse(int statusCode, String url,
DownloadClient.Headers headers) {
public void onResponse(DownloadClient.Headers headers) {
}
@Override
public void onSuccess(File destination) {
public void onSuccess() {
try {
if (json.exists() && Utils.checkForNewUpdates(json, jsonNew)) {
showNotification(context);
updateRepeatingUpdatesCheck(context);
}
//noinspection ResultOfMethodCallIgnored
jsonNew.renameTo(json);
long currentMillis = System.currentTimeMillis();
preferences.edit()
@@ -123,8 +123,8 @@ public class UpdatesCheckReceiver extends BroadcastReceiver {
}
private static void showNotification(Context context) {
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationManager notificationManager = context.getSystemService(
NotificationManager.class);
NotificationChannel notificationChannel = new NotificationChannel(
NEW_UPDATES_NOTIFICATION_CHANNEL,
context.getString(R.string.new_updates_channel_title),
@@ -159,7 +159,7 @@ public class UpdatesCheckReceiver extends BroadcastReceiver {
}
PendingIntent updateCheckIntent = getRepeatingUpdatesCheckIntent(context);
AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
AlarmManager alarmMgr = context.getSystemService(AlarmManager.class);
alarmMgr.setRepeating(AlarmManager.RTC, System.currentTimeMillis() +
Utils.getUpdateCheckInterval(context), Utils.getUpdateCheckInterval(context),
updateCheckIntent);
@@ -170,7 +170,7 @@ public class UpdatesCheckReceiver extends BroadcastReceiver {
}
public static void cancelRepeatingUpdatesCheck(Context context) {
AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
AlarmManager alarmMgr = context.getSystemService(AlarmManager.class);
alarmMgr.cancel(getRepeatingUpdatesCheckIntent(context));
}
@@ -183,7 +183,7 @@ public class UpdatesCheckReceiver extends BroadcastReceiver {
public static void scheduleUpdatesCheck(Context context) {
long millisToNextCheck = AlarmManager.INTERVAL_HOUR * 2;
PendingIntent updateCheckIntent = getUpdatesCheckIntent(context);
AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
AlarmManager alarmMgr = context.getSystemService(AlarmManager.class);
alarmMgr.set(AlarmManager.ELAPSED_REALTIME,
SystemClock.elapsedRealtime() + millisToNextCheck,
updateCheckIntent);
@@ -193,7 +193,7 @@ public class UpdatesCheckReceiver extends BroadcastReceiver {
}
public static void cancelUpdatesCheck(Context context) {
AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
AlarmManager alarmMgr = context.getSystemService(AlarmManager.class);
alarmMgr.cancel(getUpdatesCheckIntent(context));
Log.d(TAG, "Cancelling pending one-shot check");
}