mirror of
https://github.com/whyorean/AuroraStore.git
synced 2026-06-21 06:00:04 -04:00
Move installation to background thread
This commit is contained in:
committed by
Rahul Patel
parent
c4141489f3
commit
05920fb174
@@ -1,9 +1,13 @@
|
||||
package com.dragons.aurora;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.dragons.aurora.model.App;
|
||||
import com.dragons.aurora.task.InstallTask;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import eu.chainfire.libsuperuser.Shell;
|
||||
|
||||
public class InstallerRoot extends InstallerBackground {
|
||||
|
||||
@@ -14,23 +18,23 @@ public class InstallerRoot extends InstallerBackground {
|
||||
@Override
|
||||
protected void install(App app) {
|
||||
InstallationState.setInstalling(app.getPackageName());
|
||||
getTask(app).execute(Paths.getApkPath(context, app.getPackageName(), app.getVersionCode()).toString());
|
||||
boolean success = shellInstall(Paths.getApkPath(context, app.getPackageName(), app.getVersionCode()).toString());
|
||||
if (success) {
|
||||
InstallationState.setSuccess(app.getPackageName());
|
||||
} else {
|
||||
InstallationState.setFailure(app.getPackageName());
|
||||
}
|
||||
sendBroadcast(app.getPackageName(), true);
|
||||
postInstallationResult(app, success);
|
||||
}
|
||||
|
||||
private InstallTask getTask(final App app) {
|
||||
return new InstallTask() {
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Boolean success) {
|
||||
super.onPostExecute(success);
|
||||
if (success) {
|
||||
InstallationState.setSuccess(app.getPackageName());
|
||||
} else {
|
||||
InstallationState.setFailure(app.getPackageName());
|
||||
}
|
||||
sendBroadcast(app.getPackageName(), true);
|
||||
postInstallationResult(app, success);
|
||||
private boolean shellInstall(String file) {
|
||||
List<String> lines = Shell.SU.run("pm install -i \"" + BuildConfig.APPLICATION_ID + "\" -r " + file);
|
||||
if (null != lines) {
|
||||
for (String line : lines) {
|
||||
Log.i(getClass().getSimpleName(), line);
|
||||
}
|
||||
};
|
||||
}
|
||||
return null != lines && lines.size() == 1 && lines.get(0).equals("Success");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,12 @@ import android.content.Context;
|
||||
import android.view.View;
|
||||
|
||||
import com.dragons.aurora.InstallationState;
|
||||
import com.dragons.aurora.InstallerFactory;
|
||||
import com.dragons.aurora.Paths;
|
||||
import com.dragons.aurora.R;
|
||||
import com.dragons.aurora.activities.AuroraActivity;
|
||||
import com.dragons.aurora.downloader.DownloadState;
|
||||
import com.dragons.aurora.model.App;
|
||||
import com.dragons.aurora.task.InstallTask;
|
||||
|
||||
public class ButtonInstall extends Button {
|
||||
|
||||
@@ -43,6 +43,6 @@ public class ButtonInstall extends Button {
|
||||
protected void onButtonClick(View v) {
|
||||
disable(R.string.details_installing);
|
||||
((NotificationManager) activity.getSystemService(Context.NOTIFICATION_SERVICE)).cancel(app.getDisplayName().hashCode());
|
||||
InstallerFactory.get(activity).verifyAndInstall(app);
|
||||
new InstallTask(activity, app).execute();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,29 @@
|
||||
package com.dragons.aurora.task;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
import com.dragons.aurora.BuildConfig;
|
||||
import com.dragons.aurora.InstallerAbstract;
|
||||
import com.dragons.aurora.InstallerFactory;
|
||||
import com.dragons.aurora.model.App;
|
||||
|
||||
import java.util.List;
|
||||
public class InstallTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
import eu.chainfire.libsuperuser.Shell;
|
||||
private App app;
|
||||
private InstallerAbstract installer;
|
||||
|
||||
public class InstallTask extends AsyncTask<String, Void, Boolean> {
|
||||
public InstallTask(Context context, App app) {
|
||||
this(InstallerFactory.get(context), app);
|
||||
}
|
||||
|
||||
public InstallTask(InstallerAbstract installer, App app) {
|
||||
this.installer = installer;
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean doInBackground(String... params) {
|
||||
String file = params[0];
|
||||
Log.i(getClass().getSimpleName(), "Installing update " + file);
|
||||
List<String> lines = Shell.SU.run("pm install -i \"" + BuildConfig.APPLICATION_ID + "\" -r " + file);
|
||||
if (null != lines) {
|
||||
for (String line : lines) {
|
||||
Log.i(getClass().getSimpleName(), line);
|
||||
}
|
||||
}
|
||||
return null != lines && lines.size() == 1 && lines.get(0).equals("Success");
|
||||
protected Void doInBackground(Void... voids) {
|
||||
installer.verifyAndInstall(app);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user