2017-06-07 02:19:23 +08:00
|
|
|
package com.topjohnwu.magisk.receivers;
|
|
|
|
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Build;
|
|
|
|
import android.support.v4.content.FileProvider;
|
|
|
|
|
2017-11-06 04:41:23 +08:00
|
|
|
import com.topjohnwu.magisk.utils.Const;
|
2017-06-07 02:19:23 +08:00
|
|
|
import com.topjohnwu.magisk.utils.Utils;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
|
|
|
public class ManagerUpdate extends BroadcastReceiver {
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
Utils.dlAndReceive(
|
2017-06-08 22:35:30 +08:00
|
|
|
context,
|
2017-06-07 02:19:23 +08:00
|
|
|
new DownloadReceiver() {
|
|
|
|
@Override
|
2017-07-18 23:18:57 +08:00
|
|
|
public void onDownloadDone(Uri uri) {
|
2017-12-21 23:26:49 +08:00
|
|
|
if (!context.getPackageName().equals(Const.ORIG_PKG_NAME)) {
|
|
|
|
Utils.dumpPrefs();
|
|
|
|
}
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
|
|
Intent install = new Intent(Intent.ACTION_INSTALL_PACKAGE);
|
|
|
|
install.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
|
|
|
install.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
Uri content = FileProvider.getUriForFile(context,
|
|
|
|
context.getPackageName() + ".provider", new File(uri.getPath()));
|
|
|
|
install.setData(content);
|
|
|
|
context.startActivity(install);
|
2017-06-07 02:19:23 +08:00
|
|
|
} else {
|
2017-12-21 23:26:49 +08:00
|
|
|
Intent install = new Intent(Intent.ACTION_VIEW);
|
|
|
|
install.setDataAndType(uri, "application/vnd.android.package-archive");
|
|
|
|
install.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
context.startActivity(install);
|
2017-06-07 02:19:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2017-11-06 04:41:23 +08:00
|
|
|
intent.getStringExtra(Const.Key.INTENT_SET_LINK),
|
2017-12-19 20:59:59 +08:00
|
|
|
Utils.fmt("MagiskManager-v%s.apk", intent.getStringExtra(Const.Key.INTENT_SET_VERSION))
|
|
|
|
);
|
2017-06-07 02:19:23 +08:00
|
|
|
}
|
|
|
|
}
|