From 0342bb312183da0c5c93f7d8ff68511c93e901e9 Mon Sep 17 00:00:00 2001 From: Michael W Date: Sat, 11 Jan 2025 21:20:06 +0100 Subject: [PATCH] Updater: Fix warnings * Unused imports * Unused code * Unused resources * Set.isEmpty() instead of .size() == 0 * try-with-resources Change-Id: Ia9351986c62e8e5f8d4615f6146827b891f55f9e --- .../org/lineageos/updater/UpdateImporter.java | 6 +----- .../lineageos/updater/UpdatesListAdapter.java | 9 ++------- .../updater/controller/ABUpdateInstaller.java | 1 - .../updater/controller/UpdaterController.java | 4 ++-- .../updater/controller/UpdaterService.java | 6 ++---- .../org/lineageos/updater/misc/Utils.java | 20 +++++-------------- app/src/main/res/values/colors.xml | 1 - app/src/main/res/values/styles.xml | 9 --------- 8 files changed, 12 insertions(+), 44 deletions(-) diff --git a/app/src/main/java/org/lineageos/updater/UpdateImporter.java b/app/src/main/java/org/lineageos/updater/UpdateImporter.java index 791c5244..a557851b 100644 --- a/app/src/main/java/org/lineageos/updater/UpdateImporter.java +++ b/app/src/main/java/org/lineageos/updater/UpdateImporter.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2022 The LineageOS Project + * Copyright (C) 2017-2025 The LineageOS Project * Copyright (C) 2020-2022 SHIFT GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,13 +23,10 @@ import android.net.Uri; import android.os.ParcelFileDescriptor; import android.util.Log; -import org.json.JSONException; import org.lineageos.updater.controller.UpdaterController; -import org.lineageos.updater.controller.UpdaterService; import org.lineageos.updater.misc.StringGenerator; import org.lineageos.updater.misc.Utils; import org.lineageos.updater.model.Update; -import org.lineageos.updater.model.UpdateInfo; import org.lineageos.updater.model.UpdateStatus; import java.io.File; @@ -41,7 +38,6 @@ import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.text.DateFormat; import java.util.Enumeration; -import java.util.List; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; diff --git a/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java b/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java index 6bad085b..72045cac 100644 --- a/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java +++ b/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2024 The LineageOS Project + * Copyright (C) 2017-2025 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. @@ -15,12 +15,10 @@ */ package org.lineageos.updater; -import android.app.Activity; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; import android.content.res.Resources; -import android.net.Uri; import android.os.BatteryManager; import android.os.PowerManager; import android.text.SpannableString; @@ -40,8 +38,6 @@ import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.TextView; -import androidx.activity.result.ActivityResultLauncher; -import androidx.activity.result.contract.ActivityResultContracts; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.view.ContextThemeWrapper; @@ -55,7 +51,6 @@ import com.google.android.material.snackbar.Snackbar; import org.lineageos.updater.controller.UpdaterController; import org.lineageos.updater.controller.UpdaterService; -import org.lineageos.updater.misc.BuildInfoUtils; import org.lineageos.updater.misc.Constants; import org.lineageos.updater.misc.StringGenerator; import org.lineageos.updater.misc.Utils; @@ -607,7 +602,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter 0; + return !mVerifyingUpdates.isEmpty(); } public boolean isVerifyingUpdate(String downloadId) { diff --git a/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java b/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java index e1e0c998..8b8b43f6 100644 --- a/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java +++ b/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2022 The LineageOS Project + * Copyright (C) 2017-2025 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. @@ -38,7 +38,6 @@ import androidx.preference.PreferenceManager; import org.lineageos.updater.R; import org.lineageos.updater.UpdaterReceiver; import org.lineageos.updater.UpdatesActivity; -import org.lineageos.updater.misc.BuildInfoUtils; import org.lineageos.updater.misc.Constants; import org.lineageos.updater.misc.StringGenerator; import org.lineageos.updater.misc.Utils; @@ -46,7 +45,6 @@ import org.lineageos.updater.model.Update; import org.lineageos.updater.model.UpdateInfo; import org.lineageos.updater.model.UpdateStatus; -import java.io.File; import java.io.IOException; import java.text.DateFormat; import java.text.NumberFormat; @@ -127,7 +125,7 @@ public class UpdaterService extends Service { } else if (UpdaterController.ACTION_UPDATE_REMOVED.equals(intent.getAction())) { final boolean isLocalUpdate = Update.LOCAL_ID.equals(downloadId); Bundle extras = mNotificationBuilder.getExtras(); - if (extras != null && !isLocalUpdate && downloadId.equals( + if (!isLocalUpdate && downloadId != null && downloadId.equals( extras.getString(UpdaterController.EXTRA_DOWNLOAD_ID))) { mNotificationBuilder.setExtras(null); UpdateInfo update = mUpdaterController.getUpdate(downloadId); diff --git a/app/src/main/java/org/lineageos/updater/misc/Utils.java b/app/src/main/java/org/lineageos/updater/misc/Utils.java index 83f8114b..518c8e72 100644 --- a/app/src/main/java/org/lineageos/updater/misc/Utils.java +++ b/app/src/main/java/org/lineageos/updater/misc/Utils.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2023 The LineageOS Project + * Copyright (C) 2017-2025 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. @@ -66,17 +66,6 @@ public class Utils { return new File(context.getString(R.string.download_path)); } - public static File getExportPath(Context context) { - File dir = new File(context.getExternalFilesDir(null), - context.getString(R.string.export_path)); - if (!dir.isDirectory()) { - if (dir.exists() || !dir.mkdirs()) { - throw new RuntimeException("Could not create directory"); - } - } - return dir; - } - public static File getCachedUpdateList(Context context) { return new File(context.getCacheDir(), "updates.json"); } @@ -338,10 +327,11 @@ public class Utils { } // Ideally the database is empty when we get here - UpdatesDbHelper dbHelper = new UpdatesDbHelper(context); List knownPaths = new ArrayList<>(); - for (UpdateInfo update : dbHelper.getUpdates()) { - knownPaths.add(update.getFile().getAbsolutePath()); + try (UpdatesDbHelper dbHelper = new UpdatesDbHelper(context)) { + for (UpdateInfo update : dbHelper.getUpdates()) { + knownPaths.add(update.getFile().getAbsolutePath()); + } } for (File file : files) { if (!knownPaths.contains(file.getAbsolutePath())) { diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 3f37f9c9..b0745439 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -9,5 +9,4 @@ #222222 #212121 - #333333 diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index d7338570..d0fabef5 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -19,15 +19,6 @@ @android:color/transparent - - -