Install updates from UpdaterService
This allows to easily handle AB updates.
This commit is contained in:
@@ -17,7 +17,6 @@ package org.lineageos.updater;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -28,7 +27,6 @@ import android.widget.TextView;
|
||||
import org.lineageos.updater.controller.UpdaterControllerInt;
|
||||
import org.lineageos.updater.misc.Utils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.ViewHolder> {
|
||||
@@ -217,13 +215,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
|
||||
button.setOnClickListener(!enabled ? null : new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
try {
|
||||
Utils.triggerUpdate(mContext,
|
||||
mUpdaterController.getUpdate(downloadId));
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Could not trigger the update", e);
|
||||
// TODO: show error message
|
||||
}
|
||||
Utils.triggerUpdate(mContext, downloadId);
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
@@ -33,9 +33,9 @@ import android.util.Log;
|
||||
|
||||
import org.lineageos.updater.R;
|
||||
import org.lineageos.updater.UpdateDownload;
|
||||
import org.lineageos.updater.UpdateStatus;
|
||||
import org.lineageos.updater.UpdaterReceiver;
|
||||
import org.lineageos.updater.UpdatesActivity;
|
||||
import org.lineageos.updater.misc.Utils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.NumberFormat;
|
||||
@@ -160,14 +160,18 @@ public class UpdaterService extends Service {
|
||||
}
|
||||
} else if (ACTION_INSTALL_UPDATE.equals(intent.getAction())) {
|
||||
String downloadId = intent.getStringExtra(EXTRA_DOWNLOAD_ID);
|
||||
UpdateDownload update = mUpdaterController.getUpdate(downloadId);
|
||||
if (update.getPersistentStatus() != UpdateStatus.Persistent.VERIFIED) {
|
||||
throw new IllegalArgumentException(update.getDownloadId() + " is not verified");
|
||||
}
|
||||
try {
|
||||
ZipFile zipFile = new ZipFile(mUpdaterController.getUpdate(downloadId).getFile());
|
||||
ZipFile zipFile = new ZipFile(update.getFile());
|
||||
boolean isABUpdate = ABUpdateInstaller.isABUpdate(zipFile);
|
||||
zipFile.close();
|
||||
if (isABUpdate) {
|
||||
ABUpdateInstaller.start(mUpdaterController, downloadId);
|
||||
} else {
|
||||
Utils.triggerUpdate(this, mUpdaterController.getUpdate(downloadId));
|
||||
android.os.RecoverySystem.installPackage(this, update.getFile());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Could not install update", e);
|
||||
|
@@ -16,6 +16,7 @@
|
||||
package org.lineageos.updater.misc;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
@@ -29,8 +30,8 @@ import org.json.JSONObject;
|
||||
import org.lineageos.updater.R;
|
||||
import org.lineageos.updater.Update;
|
||||
import org.lineageos.updater.UpdateDownload;
|
||||
import org.lineageos.updater.UpdateStatus;
|
||||
import org.lineageos.updater.UpdatesDbHelper;
|
||||
import org.lineageos.updater.controller.UpdaterService;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
@@ -133,12 +134,11 @@ public class Utils {
|
||||
return serverUrl + "/v1/" + device + "/" + type + "/" + incrementalVersion;
|
||||
}
|
||||
|
||||
public static void triggerUpdate(Context context, UpdateDownload update) throws IOException {
|
||||
if (update.getStatus() == UpdateStatus.VERIFIED) {
|
||||
android.os.RecoverySystem.installPackage(context, update.getFile());
|
||||
} else {
|
||||
throw new IllegalStateException("Update must be verified");
|
||||
}
|
||||
public static void triggerUpdate(Context context, String downloadId) {
|
||||
final Intent intent = new Intent(context, UpdaterService.class);
|
||||
intent.setAction(UpdaterService.ACTION_INSTALL_UPDATE);
|
||||
intent.putExtra(UpdaterService.EXTRA_DOWNLOAD_ID, downloadId);
|
||||
context.startService(intent);
|
||||
}
|
||||
|
||||
public static boolean isNetworkAvailable(Context context) {
|
||||
|
Reference in New Issue
Block a user