Updater: Fix warnings

* Unused imports
* Unused code
* Unused resources
* Set.isEmpty() instead of .size() == 0
* try-with-resources

Change-Id: Ia9351986c62e8e5f8d4615f6146827b891f55f9e
This commit is contained in:
Michael W
2025-01-11 21:20:06 +01:00
committed by Nolen Johnson
parent 33d63d627d
commit 0342bb3121
8 changed files with 12 additions and 44 deletions

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2017-2022 The LineageOS Project * Copyright (C) 2017-2025 The LineageOS Project
* Copyright (C) 2020-2022 SHIFT GmbH * Copyright (C) 2020-2022 SHIFT GmbH
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,13 +23,10 @@ import android.net.Uri;
import android.os.ParcelFileDescriptor; import android.os.ParcelFileDescriptor;
import android.util.Log; import android.util.Log;
import org.json.JSONException;
import org.lineageos.updater.controller.UpdaterController; import org.lineageos.updater.controller.UpdaterController;
import org.lineageos.updater.controller.UpdaterService;
import org.lineageos.updater.misc.StringGenerator; import org.lineageos.updater.misc.StringGenerator;
import org.lineageos.updater.misc.Utils; import org.lineageos.updater.misc.Utils;
import org.lineageos.updater.model.Update; import org.lineageos.updater.model.Update;
import org.lineageos.updater.model.UpdateInfo;
import org.lineageos.updater.model.UpdateStatus; import org.lineageos.updater.model.UpdateStatus;
import java.io.File; import java.io.File;
@@ -41,7 +38,6 @@ import java.io.InputStream;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.text.DateFormat; import java.text.DateFormat;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.List;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -15,12 +15,10 @@
*/ */
package org.lineageos.updater; package org.lineageos.updater;
import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Resources; import android.content.res.Resources;
import android.net.Uri;
import android.os.BatteryManager; import android.os.BatteryManager;
import android.os.PowerManager; import android.os.PowerManager;
import android.text.SpannableString; import android.text.SpannableString;
@@ -40,8 +38,6 @@ import android.widget.LinearLayout;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.view.ContextThemeWrapper; 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.UpdaterController;
import org.lineageos.updater.controller.UpdaterService; import org.lineageos.updater.controller.UpdaterService;
import org.lineageos.updater.misc.BuildInfoUtils;
import org.lineageos.updater.misc.Constants; import org.lineageos.updater.misc.Constants;
import org.lineageos.updater.misc.StringGenerator; import org.lineageos.updater.misc.StringGenerator;
import org.lineageos.updater.misc.Utils; import org.lineageos.updater.misc.Utils;
@@ -607,7 +602,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
private boolean isBatteryLevelOk() { private boolean isBatteryLevelOk() {
Intent intent = mActivity.registerReceiver(null, Intent intent = mActivity.registerReceiver(null,
new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
if (!intent.getBooleanExtra(BatteryManager.EXTRA_PRESENT, false)) { if (intent == null || !intent.getBooleanExtra(BatteryManager.EXTRA_PRESENT, false)) {
return true; return true;
} }
int percent = Math.round(100.f * intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 100) / int percent = Math.round(100.f * intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 100) /

View File

@@ -256,7 +256,6 @@ class ABUpdateInstaller {
} }
private void installationDone(boolean needsReboot) { private void installationDone(boolean needsReboot) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
String id = needsReboot ? mDownloadId : null; String id = needsReboot ? mDownloadId : null;
PreferenceManager.getDefaultSharedPreferences(mContext).edit() PreferenceManager.getDefaultSharedPreferences(mContext).edit()
.putString(Constants.PREF_NEEDS_REBOOT_ID, id) .putString(Constants.PREF_NEEDS_REBOOT_ID, id)

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -522,7 +522,7 @@ public class UpdaterController {
} }
public boolean isVerifyingUpdate() { public boolean isVerifyingUpdate() {
return mVerifyingUpdates.size() > 0; return !mVerifyingUpdates.isEmpty();
} }
public boolean isVerifyingUpdate(String downloadId) { public boolean isVerifyingUpdate(String downloadId) {

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.R;
import org.lineageos.updater.UpdaterReceiver; import org.lineageos.updater.UpdaterReceiver;
import org.lineageos.updater.UpdatesActivity; import org.lineageos.updater.UpdatesActivity;
import org.lineageos.updater.misc.BuildInfoUtils;
import org.lineageos.updater.misc.Constants; import org.lineageos.updater.misc.Constants;
import org.lineageos.updater.misc.StringGenerator; import org.lineageos.updater.misc.StringGenerator;
import org.lineageos.updater.misc.Utils; 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.UpdateInfo;
import org.lineageos.updater.model.UpdateStatus; import org.lineageos.updater.model.UpdateStatus;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.NumberFormat; import java.text.NumberFormat;
@@ -127,7 +125,7 @@ public class UpdaterService extends Service {
} else if (UpdaterController.ACTION_UPDATE_REMOVED.equals(intent.getAction())) { } else if (UpdaterController.ACTION_UPDATE_REMOVED.equals(intent.getAction())) {
final boolean isLocalUpdate = Update.LOCAL_ID.equals(downloadId); final boolean isLocalUpdate = Update.LOCAL_ID.equals(downloadId);
Bundle extras = mNotificationBuilder.getExtras(); Bundle extras = mNotificationBuilder.getExtras();
if (extras != null && !isLocalUpdate && downloadId.equals( if (!isLocalUpdate && downloadId != null && downloadId.equals(
extras.getString(UpdaterController.EXTRA_DOWNLOAD_ID))) { extras.getString(UpdaterController.EXTRA_DOWNLOAD_ID))) {
mNotificationBuilder.setExtras(null); mNotificationBuilder.setExtras(null);
UpdateInfo update = mUpdaterController.getUpdate(downloadId); UpdateInfo update = mUpdaterController.getUpdate(downloadId);

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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)); 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) { public static File getCachedUpdateList(Context context) {
return new File(context.getCacheDir(), "updates.json"); return new File(context.getCacheDir(), "updates.json");
} }
@@ -338,11 +327,12 @@ public class Utils {
} }
// Ideally the database is empty when we get here // Ideally the database is empty when we get here
UpdatesDbHelper dbHelper = new UpdatesDbHelper(context);
List<String> knownPaths = new ArrayList<>(); List<String> knownPaths = new ArrayList<>();
try (UpdatesDbHelper dbHelper = new UpdatesDbHelper(context)) {
for (UpdateInfo update : dbHelper.getUpdates()) { for (UpdateInfo update : dbHelper.getUpdates()) {
knownPaths.add(update.getFile().getAbsolutePath()); knownPaths.add(update.getFile().getAbsolutePath());
} }
}
for (File file : files) { for (File file : files) {
if (!knownPaths.contains(file.getAbsolutePath())) { if (!knownPaths.contains(file.getAbsolutePath())) {
Log.d(TAG, "Deleting " + file.getAbsolutePath()); Log.d(TAG, "Deleting " + file.getAbsolutePath());

View File

@@ -9,5 +9,4 @@
<color name="tv_card_background">#222222</color> <color name="tv_card_background">#222222</color>
<color name="inverted">#212121</color> <color name="inverted">#212121</color>
<color name="ic_background">#333333</color>
</resources> </resources>

View File

@@ -19,15 +19,6 @@
<item name="android:navigationBarColor">@android:color/transparent</item> <item name="android:navigationBarColor">@android:color/transparent</item>
</style> </style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.ActionBar" />
<style name="TextAppearanceInverted" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">@color/inverted</item>
</style>
<style name="TextAppearanceTransparent" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">@android:color/transparent</item>
</style>
<style name="AppTheme.PopupMenuOverlapAnchor"> <style name="AppTheme.PopupMenuOverlapAnchor">
<item name="android:overlapAnchor">true</item> <item name="android:overlapAnchor">true</item>
<item name="android:dropDownVerticalOffset">8dp</item> <item name="android:dropDownVerticalOffset">8dp</item>