aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGabriele M <moto.falcon.git@gmail.com>2018-04-08 10:26:20 +0200
committerJoey <joey@lineageos.org>2018-04-08 14:25:56 +0200
commita64eae5fc0c7776f09ea5d798be73d4032ee447a (patch)
tree2709f76042d6d5bb222f2a44b85c4c83dd624331
parenta72b78c31e934bd87dcdcb24a7f40af345110d22 (diff)
downloadandroid_packages_apps_Updater-a64eae5fc0c7776f09ea5d798be73d4032ee447a.tar.gz
android_packages_apps_Updater-a64eae5fc0c7776f09ea5d798be73d4032ee447a.tar.bz2
android_packages_apps_Updater-a64eae5fc0c7776f09ea5d798be73d4032ee447a.zip
Simplify code syntax using Java 8 features
Change-Id: I3e59f0c38e4047595374a951619c9b43a46901df
-rw-r--r--src/org/lineageos/updater/ExportUpdateService.java50
-rw-r--r--src/org/lineageos/updater/UpdatesActivity.java31
-rw-r--r--src/org/lineageos/updater/UpdatesListAdapter.java144
-rw-r--r--src/org/lineageos/updater/controller/UpdaterController.java55
-rw-r--r--src/org/lineageos/updater/download/HttpURLConnectionClient.java7
-rw-r--r--src/org/lineageos/updater/misc/Utils.java9
6 files changed, 100 insertions, 196 deletions
diff --git a/src/org/lineageos/updater/ExportUpdateService.java b/src/org/lineageos/updater/ExportUpdateService.java
index f05a7d1..e272dc8 100644
--- a/src/org/lineageos/updater/ExportUpdateService.java
+++ b/src/org/lineageos/updater/ExportUpdateService.java
@@ -175,36 +175,30 @@ public class ExportUpdateService extends Service {
startForeground(NOTIFICATION_ID, notificationBuilder.build());
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
- Runnable runnableComplete = new Runnable() {
- @Override
- public void run() {
- notificationStyle.setSummaryText(null);
- notificationStyle.setBigContentTitle(
- getString(R.string.notification_export_success));
- notificationBuilder.setContentTitle(
- getString(R.string.notification_export_success));
- notificationBuilder.setProgress(0, 0, false);
- notificationBuilder.setContentText(destination.getName());
- notificationBuilder.mActions.clear();
- notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
- stopForeground(STOP_FOREGROUND_DETACH);
- }
+ Runnable runnableComplete = () -> {
+ notificationStyle.setSummaryText(null);
+ notificationStyle.setBigContentTitle(
+ getString(R.string.notification_export_success));
+ notificationBuilder.setContentTitle(
+ getString(R.string.notification_export_success));
+ notificationBuilder.setProgress(0, 0, false);
+ notificationBuilder.setContentText(destination.getName());
+ notificationBuilder.mActions.clear();
+ notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
+ stopForeground(STOP_FOREGROUND_DETACH);
};
- Runnable runnableFailed = new Runnable() {
- @Override
- public void run() {
- notificationStyle.setSummaryText(null);
- notificationStyle.setBigContentTitle(
- getString(R.string.notification_export_fail));
- notificationBuilder.setContentTitle(
- getString(R.string.notification_export_fail));
- notificationBuilder.setProgress(0, 0, false);
- notificationBuilder.setContentText(null);
- notificationBuilder.mActions.clear();
- notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
- stopForeground(STOP_FOREGROUND_DETACH);
- }
+ Runnable runnableFailed = () -> {
+ notificationStyle.setSummaryText(null);
+ notificationStyle.setBigContentTitle(
+ getString(R.string.notification_export_fail));
+ notificationBuilder.setContentTitle(
+ getString(R.string.notification_export_fail));
+ notificationBuilder.setProgress(0, 0, false);
+ notificationBuilder.setContentText(null);
+ notificationBuilder.mActions.clear();
+ notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
+ stopForeground(STOP_FOREGROUND_DETACH);
};
mExportRunnable = new ExportRunnable(source, destination, progressCallBack,
diff --git a/src/org/lineageos/updater/UpdatesActivity.java b/src/org/lineageos/updater/UpdatesActivity.java
index 416e1e3..b81f112 100644
--- a/src/org/lineageos/updater/UpdatesActivity.java
+++ b/src/org/lineageos/updater/UpdatesActivity.java
@@ -60,8 +60,6 @@ import org.lineageos.updater.model.UpdateInfo;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
import java.util.List;
public class UpdatesActivity extends UpdatesListActivity {
@@ -308,12 +306,7 @@ public class UpdatesActivity extends UpdatesListActivity {
} else {
findViewById(R.id.no_new_updates_view).setVisibility(View.GONE);
findViewById(R.id.recycler_view).setVisibility(View.VISIBLE);
- Collections.sort(sortedUpdates, new Comparator<UpdateInfo>() {
- @Override
- public int compare(UpdateInfo u1, UpdateInfo u2) {
- return Long.compare(u2.getTimestamp(), u1.getTimestamp());
- }
- });
+ sortedUpdates.sort((u1, u2) -> Long.compare(u2.getTimestamp(), u1.getTimestamp()));
for (UpdateInfo update : sortedUpdates) {
updateIds.add(update.getDownloadId());
}
@@ -366,14 +359,11 @@ public class UpdatesActivity extends UpdatesListActivity {
@Override
public void onFailure(final boolean cancelled) {
Log.e(TAG, "Could not download updates list");
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- if (!cancelled) {
- showSnackbar(R.string.snack_updates_check_failed, Snackbar.LENGTH_LONG);
- }
- refreshAnimationStop();
+ runOnUiThread(() -> {
+ if (!cancelled) {
+ showSnackbar(R.string.snack_updates_check_failed, Snackbar.LENGTH_LONG);
}
+ refreshAnimationStop();
});
}
@@ -384,13 +374,10 @@ public class UpdatesActivity extends UpdatesListActivity {
@Override
public void onSuccess(File destination) {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- Log.d(TAG, "List downloaded");
- processNewJson(jsonFile, jsonFileTmp, manualRefresh);
- refreshAnimationStop();
- }
+ runOnUiThread(() -> {
+ Log.d(TAG, "List downloaded");
+ processNewJson(jsonFile, jsonFileTmp, manualRefresh);
+ refreshAnimationStop();
});
}
};
diff --git a/src/org/lineageos/updater/UpdatesListAdapter.java b/src/org/lineageos/updater/UpdatesListAdapter.java
index 5b0705e..15768ff 100644
--- a/src/org/lineageos/updater/UpdatesListAdapter.java
+++ b/src/org/lineageos/updater/UpdatesListAdapter.java
@@ -15,7 +15,6 @@
*/
package org.lineageos.updater;
-import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
@@ -292,17 +291,14 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
.setMessage(R.string.update_on_mobile_data_message)
.setView(checkboxView)
.setPositiveButton(R.string.action_description_download,
- new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- if (checkbox.isChecked()) {
- preferences.edit()
- .putBoolean(Constants.PREF_MOBILE_DATA_WARNING, false)
- .apply();
- mActivity.supportInvalidateOptionsMenu();
- }
- mUpdaterController.startDownload(downloadId);
+ (dialog, which) -> {
+ if (checkbox.isChecked()) {
+ preferences.edit()
+ .putBoolean(Constants.PREF_MOBILE_DATA_WARNING, false)
+ .apply();
+ mActivity.supportInvalidateOptionsMenu();
}
+ mUpdaterController.startDownload(downloadId);
})
.setNegativeButton(android.R.string.cancel, null)
.show();
@@ -317,24 +313,15 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
button.setContentDescription(
mActivity.getString(R.string.action_description_download));
button.setEnabled(enabled);
- clickListener = !enabled ? null : new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- startDownloadWithWarning(downloadId);
- }
- };
+ clickListener = enabled ? view -> startDownloadWithWarning(downloadId) : null;
break;
case PAUSE:
button.setImageResource(R.drawable.ic_pause);
button.setContentDescription(
mActivity.getString(R.string.action_description_pause));
button.setEnabled(enabled);
- clickListener = !enabled ? null : new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- mUpdaterController.pauseDownload(downloadId);
- }
- };
+ clickListener = enabled ? view -> mUpdaterController.pauseDownload(downloadId)
+ : null;
break;
case RESUME: {
button.setImageResource(R.drawable.ic_resume);
@@ -344,17 +331,14 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
UpdateInfo update = mUpdaterController.getUpdate(downloadId);
final boolean canInstall = Utils.canInstall(update) ||
update.getFile().length() == update.getFileSize();
- clickListener = !enabled ? null : new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- if (canInstall) {
- mUpdaterController.resumeDownload(downloadId);
- } else {
- mActivity.showSnackbar(R.string.snack_update_not_installable,
- Snackbar.LENGTH_LONG);
- }
+ clickListener = enabled ? view -> {
+ if (canInstall) {
+ mUpdaterController.resumeDownload(downloadId);
+ } else {
+ mActivity.showSnackbar(R.string.snack_update_not_installable,
+ Snackbar.LENGTH_LONG);
}
- };
+ } : null;
}
break;
case INSTALL: {
@@ -364,29 +348,21 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
button.setEnabled(enabled);
UpdateInfo update = mUpdaterController.getUpdate(downloadId);
final boolean canInstall = Utils.canInstall(update);
- clickListener = !enabled ? null : new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- if (canInstall) {
- getInstallDialog(downloadId).show();
- } else {
- mActivity.showSnackbar(R.string.snack_update_not_installable,
- Snackbar.LENGTH_LONG);
- }
+ clickListener = enabled ? view -> {
+ if (canInstall) {
+ getInstallDialog(downloadId).show();
+ } else {
+ mActivity.showSnackbar(R.string.snack_update_not_installable,
+ Snackbar.LENGTH_LONG);
}
- };
+ } : null;
}
break;
case INFO: {
button.setImageResource(R.drawable.ic_info);
button.setContentDescription(mActivity.getString(R.string.action_description_info));
button.setEnabled(enabled);
- clickListener = !enabled ? null : new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- showInfoDialog();
- }
- };
+ clickListener = enabled ? view -> showInfoDialog() : null;
}
break;
case DELETE: {
@@ -394,12 +370,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
button.setContentDescription(
mActivity.getString(R.string.action_description_delete));
button.setEnabled(enabled);
- clickListener = !enabled ? null : new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- getDeleteDialog(downloadId).show();
- }
- };
+ clickListener = enabled ? view -> getDeleteDialog(downloadId).show() : null;
}
break;
case CANCEL_INSTALLATION: {
@@ -407,12 +378,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
button.setContentDescription(
mActivity.getString(R.string.action_description_cancel));
button.setEnabled(enabled);
- clickListener = !enabled ? null : new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- getCancelInstallationDialog().show();
- }
- };
+ clickListener = enabled ? view -> getCancelInstallationDialog().show() : null;
}
break;
default:
@@ -421,13 +387,10 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
button.setAlpha(enabled ? 1.f : mAlphaDisabledValue);
// Disable action mode when a button is clicked
- button.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- if (clickListener != null) {
- clickListener.onClick(v);
- stopActionMode();
- }
+ button.setOnClickListener(v -> {
+ if (clickListener != null) {
+ clickListener.onClick(v);
+ stopActionMode();
}
});
}
@@ -442,26 +405,20 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
.setTitle(R.string.confirm_delete_dialog_title)
.setMessage(R.string.confirm_delete_dialog_message)
.setPositiveButton(android.R.string.ok,
- new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- mUpdaterController.pauseDownload(downloadId);
- mUpdaterController.deleteUpdate(downloadId);
- }
+ (dialog, which) -> {
+ mUpdaterController.pauseDownload(downloadId);
+ mUpdaterController.deleteUpdate(downloadId);
})
.setNegativeButton(android.R.string.cancel, null);
}
private View.OnLongClickListener getLongClickListener(final UpdateInfo update,
final boolean canDelete) {
- return new View.OnLongClickListener() {
- @Override
- public boolean onLongClick(View view) {
- if (mActionMode == null) {
- startActionMode(update, canDelete);
- }
- return true;
+ return view -> {
+ if (mActionMode == null) {
+ startActionMode(update, canDelete);
}
+ return true;
};
}
@@ -488,12 +445,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
.setMessage(mActivity.getString(resId, buildInfoText,
mActivity.getString(android.R.string.ok)))
.setPositiveButton(android.R.string.ok,
- new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- Utils.triggerUpdate(mActivity, downloadId);
- }
- })
+ (dialog, which) -> Utils.triggerUpdate(mActivity, downloadId))
.setNegativeButton(android.R.string.cancel, null);
}
@@ -501,13 +453,10 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
return new AlertDialog.Builder(mActivity)
.setMessage(R.string.cancel_installation_dialog_message)
.setPositiveButton(android.R.string.ok,
- new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- Intent intent = new Intent(mActivity, UpdaterService.class);
- intent.setAction(UpdaterService.ACTION_INSTALL_STOP);
- mActivity.startService(intent);
- }
+ (dialog, which) -> {
+ Intent intent = new Intent(mActivity, UpdaterService.class);
+ intent.setAction(UpdaterService.ACTION_INSTALL_STOP);
+ mActivity.startService(intent);
})
.setNegativeButton(android.R.string.cancel, null);
}
@@ -559,12 +508,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
switch (item.getItemId()) {
case R.id.menu_delete_action:
getDeleteDialog(update.getDownloadId())
- .setOnDismissListener(new DialogInterface.OnDismissListener() {
- @Override
- public void onDismiss(DialogInterface dialog) {
- mode.finish();
- }
- })
+ .setOnDismissListener(dialog -> mode.finish())
.show();
return true;
case R.id.menu_copy_url:
diff --git a/src/org/lineageos/updater/controller/UpdaterController.java b/src/org/lineageos/updater/controller/UpdaterController.java
index 35c9e20..97c939d 100644
--- a/src/org/lineageos/updater/controller/UpdaterController.java
+++ b/src/org/lineageos/updater/controller/UpdaterController.java
@@ -172,13 +172,8 @@ public class UpdaterController implements Controller {
}
update.setStatus(UpdateStatus.DOWNLOADING);
update.setPersistentStatus(UpdateStatus.Persistent.INCOMPLETE);
- new Thread(new Runnable() {
- @Override
- public void run() {
- mUpdatesDbHelper.addUpdateWithOnConflict(update,
- SQLiteDatabase.CONFLICT_REPLACE);
- }
- }).start();
+ new Thread(() -> mUpdatesDbHelper.addUpdateWithOnConflict(update,
+ SQLiteDatabase.CONFLICT_REPLACE)).start();
notifyUpdateChange(downloadId);
}
@@ -245,25 +240,22 @@ public class UpdaterController implements Controller {
private void verifyUpdateAsync(final String downloadId) {
mVerifyingUpdates.add(downloadId);
- new Thread(new Runnable() {
- @Override
- public void run() {
- Update update = mDownloads.get(downloadId).mUpdate;
- File file = update.getFile();
- if (file.exists() && verifyPackage(file)) {
- file.setReadable(true, false);
- update.setPersistentStatus(UpdateStatus.Persistent.VERIFIED);
- mUpdatesDbHelper.changeUpdateStatus(update);
- update.setStatus(UpdateStatus.VERIFIED);
- } else {
- update.setPersistentStatus(UpdateStatus.Persistent.UNKNOWN);
- mUpdatesDbHelper.removeUpdate(downloadId);
- update.setProgress(0);
- update.setStatus(UpdateStatus.VERIFICATION_FAILED);
- }
- mVerifyingUpdates.remove(downloadId);
- notifyUpdateChange(downloadId);
+ new Thread(() -> {
+ Update update = mDownloads.get(downloadId).mUpdate;
+ File file = update.getFile();
+ if (file.exists() && verifyPackage(file)) {
+ file.setReadable(true, false);
+ update.setPersistentStatus(UpdateStatus.Persistent.VERIFIED);
+ mUpdatesDbHelper.changeUpdateStatus(update);
+ update.setStatus(UpdateStatus.VERIFIED);
+ } else {
+ update.setPersistentStatus(UpdateStatus.Persistent.UNKNOWN);
+ mUpdatesDbHelper.removeUpdate(downloadId);
+ update.setProgress(0);
+ update.setStatus(UpdateStatus.VERIFICATION_FAILED);
}
+ mVerifyingUpdates.remove(downloadId);
+ notifyUpdateChange(downloadId);
}).start();
}
@@ -454,15 +446,12 @@ public class UpdaterController implements Controller {
}
private void deleteUpdateAsync(final Update update) {
- new Thread(new Runnable() {
- @Override
- public void run() {
- File file = update.getFile();
- if (file.exists() && !file.delete()) {
- Log.e(TAG, "Could not delete " + file.getAbsolutePath());
- }
- mUpdatesDbHelper.removeUpdate(update.getDownloadId());
+ new Thread(() -> {
+ File file = update.getFile();
+ if (file.exists() && !file.delete()) {
+ Log.e(TAG, "Could not delete " + file.getAbsolutePath());
}
+ mUpdatesDbHelper.removeUpdate(update.getDownloadId());
}).start();
}
diff --git a/src/org/lineageos/updater/download/HttpURLConnectionClient.java b/src/org/lineageos/updater/download/HttpURLConnectionClient.java
index afee518..2b7c80e 100644
--- a/src/org/lineageos/updater/download/HttpURLConnectionClient.java
+++ b/src/org/lineageos/updater/download/HttpURLConnectionClient.java
@@ -192,12 +192,7 @@ public class HttpURLConnectionClient implements DownloadClient {
for (Map.Entry<String, List<String>> entry : mClient.getHeaderFields().entrySet()) {
if ("Link".equalsIgnoreCase((entry.getKey()))) {
duplicates = new PriorityQueue<>(entry.getValue().size(),
- new Comparator<DuplicateLink>() {
- @Override
- public int compare(DuplicateLink d1, DuplicateLink d2) {
- return Integer.compare(d1.mPriority, d2.mPriority);
- }
- });
+ Comparator.comparingInt(d -> d.mPriority));
// https://tools.ietf.org/html/rfc6249
// https://tools.ietf.org/html/rfc5988#section-5
diff --git a/src/org/lineageos/updater/misc/Utils.java b/src/org/lineageos/updater/misc/Utils.java
index 8ce368e..255b750 100644
--- a/src/org/lineageos/updater/misc/Utils.java
+++ b/src/org/lineageos/updater/misc/Utils.java
@@ -43,7 +43,6 @@ import org.lineageos.updater.model.UpdateInfo;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
-import java.io.FilenameFilter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
@@ -246,12 +245,8 @@ public class Utils {
}
public static void removeUncryptFiles(File downloadPath) {
- File[] uncryptFiles = downloadPath.listFiles(new FilenameFilter() {
- @Override
- public boolean accept(File dir, String name) {
- return name.endsWith(Constants.UNCRYPT_FILE_EXT);
- }
- });
+ File[] uncryptFiles = downloadPath.listFiles(
+ (dir, name) -> name.endsWith(Constants.UNCRYPT_FILE_EXT));
if (uncryptFiles == null) {
return;
}