Updater: Unbreak "Export update" feature
Fixes: https://gitlab.com/LineageOS/issues/android/-/issues/4736
Change-Id: I186a27d2e99098cf8ebb3dd5c7348cdb528baa78
diff --git a/src/org/lineageos/updater/UpdatesActivity.java b/src/org/lineageos/updater/UpdatesActivity.java
index 395e801..9c56f0b 100644
--- a/src/org/lineageos/updater/UpdatesActivity.java
+++ b/src/org/lineageos/updater/UpdatesActivity.java
@@ -16,6 +16,7 @@
package org.lineageos.updater;
import android.annotation.SuppressLint;
+import android.app.Activity;
import android.app.UiModeManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
@@ -44,6 +45,8 @@
import android.widget.TextView;
import android.widget.Toast;
+import androidx.activity.result.ActivityResultLauncher;
+import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.SwitchCompat;
@@ -87,6 +90,19 @@
private boolean mIsTV;
+ private UpdateInfo mToBeExported = null;
+ private final ActivityResultLauncher<Intent> mExportUpdate = registerForActivityResult(
+ new ActivityResultContracts.StartActivityForResult(),
+ result -> {
+ if (result.getResultCode() == Activity.RESULT_OK) {
+ Intent intent = result.getData();
+ if (intent != null) {
+ Uri uri = intent.getData();
+ exportUpdate(uri);
+ }
+ }
+ });
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -403,6 +419,26 @@
}
@Override
+ public void exportUpdate(UpdateInfo update) {
+ mToBeExported = update;
+
+ Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
+ intent.addCategory(Intent.CATEGORY_OPENABLE);
+ intent.setType("application/zip");
+ intent.putExtra(Intent.EXTRA_TITLE, update.getName());
+
+ mExportUpdate.launch(intent);
+ }
+
+ private void exportUpdate(Uri uri) {
+ Intent intent = new Intent(this, ExportUpdateService.class);
+ intent.setAction(ExportUpdateService.ACTION_START_EXPORTING);
+ intent.putExtra(ExportUpdateService.EXTRA_SOURCE_FILE, mToBeExported.getFile());
+ intent.putExtra(ExportUpdateService.EXTRA_DEST_URI, uri);
+ startService(intent);
+ }
+
+ @Override
public void showSnackbar(int stringId, int duration) {
Snackbar.make(findViewById(R.id.main_container), stringId, duration).show();
}
diff --git a/src/org/lineageos/updater/UpdatesListActivity.java b/src/org/lineageos/updater/UpdatesListActivity.java
index fe0f4bd..fd63178 100644
--- a/src/org/lineageos/updater/UpdatesListActivity.java
+++ b/src/org/lineageos/updater/UpdatesListActivity.java
@@ -17,6 +17,9 @@
import androidx.appcompat.app.AppCompatActivity;
+import org.lineageos.updater.model.UpdateInfo;
+
public abstract class UpdatesListActivity extends AppCompatActivity {
+ public abstract void exportUpdate(UpdateInfo update);
public abstract void showSnackbar(int stringId, int duration);
}
diff --git a/src/org/lineageos/updater/UpdatesListAdapter.java b/src/org/lineageos/updater/UpdatesListAdapter.java
index 608ad7e..6650a78 100644
--- a/src/org/lineageos/updater/UpdatesListAdapter.java
+++ b/src/org/lineageos/updater/UpdatesListAdapter.java
@@ -84,8 +84,6 @@
private AlertDialog infoDialog;
- private UpdateInfo mToBeExported = null;
-
private enum Action {
DOWNLOAD,
PAUSE,
@@ -549,7 +547,9 @@
mActivity.getString(R.string.toast_download_url_copied));
return true;
} else if (itemId == R.id.menu_export_update) {
- exportUpdate(update);
+ if (mActivity != null) {
+ mActivity.exportUpdate(update);
+ }
return true;
}
return false;
@@ -559,39 +559,6 @@
helper.show();
}
- private void exportUpdate(UpdateInfo update) {
- if (mActivity == null) {
- return;
- }
- mToBeExported = update;
- ActivityResultLauncher<Intent> resultLauncher = mActivity.registerForActivityResult(
- new ActivityResultContracts.StartActivityForResult(),
- result -> {
- if (result.getResultCode() == Activity.RESULT_OK) {
- Intent intent = result.getData();
- if (intent != null) {
- Uri uri = intent.getData();
- exportUpdate(uri);
- }
- }
- });
-
- Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
- intent.addCategory(Intent.CATEGORY_OPENABLE);
- intent.setType("application/zip");
- intent.putExtra(Intent.EXTRA_TITLE, update.getName());
-
- resultLauncher.launch(intent);
- }
-
- private void exportUpdate(Uri uri) {
- Intent intent = new Intent(mActivity, ExportUpdateService.class);
- intent.setAction(ExportUpdateService.ACTION_START_EXPORTING);
- intent.putExtra(ExportUpdateService.EXTRA_SOURCE_FILE, mToBeExported.getFile());
- intent.putExtra(ExportUpdateService.EXTRA_DEST_URI, uri);
- mActivity.startService(intent);
- }
-
private void showInfoDialog() {
String messageString = String.format(StringGenerator.getCurrentLocale(mActivity),
mActivity.getString(R.string.blocked_update_dialog_message),