Fix crashing when installing modules

This commit is contained in:
topjohnwu 2017-07-15 01:22:00 +08:00
parent 4dc9419d2e
commit bcdface60d
5 changed files with 14 additions and 17 deletions

View File

@ -8,8 +8,8 @@ android {
applicationId "com.topjohnwu.magisk"
minSdkVersion 21
targetSdkVersion 26
versionCode 45
versionName "5.0.5"
versionCode 46
versionName "5.0.6"
ndk {
moduleName 'zipadjust'
abiFilters 'x86', 'armeabi-v7a'

View File

@ -3,6 +3,7 @@ package com.topjohnwu.magisk;
import android.animation.Animator;
import android.animation.ValueAnimator;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
@ -142,7 +143,7 @@ public class MagiskFragment extends Fragment
private boolean verity = keepVerityChkbox.isChecked();
@Override
public void onDownloadDone(Uri uri) {
public void onDownloadDone(Uri uri, Context context) {
new ProcessMagiskZip(getActivity(), uri, boot, enc, verity).exec();
}
},

View File

@ -65,9 +65,8 @@ public class ReposAdapter extends RecyclerView.Adapter<ReposAdapter.ViewHolder>
mContext,
new DownloadReceiver() {
@Override
public void onDownloadDone(Uri uri) {
Activity activity = (Activity) mContext;
new ProcessRepoZip(activity, uri, true).exec();
public void onDownloadDone(Uri uri, Context context) {
new ProcessRepoZip((Activity) mContext, uri, true).exec();
}
},
repo.getZipUrl(),
@ -76,9 +75,8 @@ public class ReposAdapter extends RecyclerView.Adapter<ReposAdapter.ViewHolder>
mContext,
new DownloadReceiver() {
@Override
public void onDownloadDone(Uri uri) {
Activity activity = (Activity) mContext;
new ProcessRepoZip(activity, uri, false).exec();
public void onDownloadDone(Uri uri, Context context) {
new ProcessRepoZip((Activity) mContext, uri, false).exec();
}
},
repo.getZipUrl(),

View File

@ -12,7 +12,6 @@ import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.utils.Utils;
public abstract class DownloadReceiver extends BroadcastReceiver {
public Context mContext;
public String mFilename;
long downloadID;
@ -20,7 +19,6 @@ public abstract class DownloadReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
mContext = context;
DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
String action = intent.getAction();
if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
@ -33,7 +31,7 @@ public abstract class DownloadReceiver extends BroadcastReceiver {
switch (status) {
case DownloadManager.STATUS_SUCCESSFUL:
Uri uri = Uri.parse(c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI)));
onDownloadDone(uri);
onDownloadDone(uri, context);
break;
default:
Toast.makeText(context, R.string.download_file_error, Toast.LENGTH_LONG).show();
@ -54,5 +52,5 @@ public abstract class DownloadReceiver extends BroadcastReceiver {
mFilename = filename;
}
public abstract void onDownloadDone(Uri uri);
public abstract void onDownloadDone(Uri uri, Context context);
}

View File

@ -18,19 +18,19 @@ public class ManagerUpdate extends BroadcastReceiver {
context,
new DownloadReceiver() {
@Override
public void onDownloadDone(Uri uri) {
public void onDownloadDone(Uri uri, Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Intent install = new Intent(Intent.ACTION_INSTALL_PACKAGE);
install.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Uri content = FileProvider.getUriForFile(mContext,
Uri content = FileProvider.getUriForFile(context,
"com.topjohnwu.magisk.provider", new File(uri.getPath()));
install.setData(content);
mContext.startActivity(install);
context.startActivity(install);
} else {
Intent install = new Intent(Intent.ACTION_VIEW);
install.setDataAndType(uri, "application/vnd.android.package-archive");
install.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(install);
context.startActivity(install);
}
}
},