Magisk/app/src/main/java/com/topjohnwu/magisk/FlashActivity.java

119 lines
4.3 KiB
Java
Raw Normal View History

2017-07-18 00:59:22 +08:00
package com.topjohnwu.magisk;
2017-08-31 03:07:33 +08:00
import android.content.Intent;
2017-07-18 00:59:22 +08:00
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
2017-10-16 14:08:14 +08:00
import android.text.TextUtils;
2017-07-18 00:59:22 +08:00
import android.view.View;
2017-08-31 03:07:33 +08:00
import android.widget.Button;
2017-07-18 00:59:22 +08:00
import android.widget.LinearLayout;
2017-10-16 14:08:14 +08:00
import android.widget.ScrollView;
2017-07-18 00:59:22 +08:00
import android.widget.TextView;
import com.topjohnwu.magisk.asyncs.FlashZip;
2017-09-03 00:10:14 +08:00
import com.topjohnwu.magisk.asyncs.InstallMagisk;
2017-07-18 00:59:22 +08:00
import com.topjohnwu.magisk.components.Activity;
2017-09-30 03:04:23 +08:00
import com.topjohnwu.magisk.container.AdaptiveList;
2017-08-31 03:07:33 +08:00
import com.topjohnwu.magisk.utils.Shell;
2017-07-18 00:59:22 +08:00
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class FlashActivity extends Activity {
2017-08-31 03:07:33 +08:00
public static final String SET_ACTION = "action";
2017-09-03 00:10:14 +08:00
public static final String SET_BOOT = "boot";
public static final String SET_ENC = "enc";
public static final String SET_VERITY = "verity";
2017-08-31 03:07:33 +08:00
public static final String FLASH_ZIP = "flash";
public static final String PATCH_BOOT = "patch";
2017-09-03 00:10:14 +08:00
public static final String FLASH_MAGISK = "magisk";
2017-08-31 03:07:33 +08:00
2017-07-18 00:59:22 +08:00
@BindView(R.id.toolbar) Toolbar toolbar;
2017-10-16 14:08:14 +08:00
@BindView(R.id.txtLog) TextView flashLogs;
2017-07-18 00:59:22 +08:00
@BindView(R.id.button_panel) LinearLayout buttonPanel;
2017-08-31 03:07:33 +08:00
@BindView(R.id.reboot) Button reboot;
2017-10-16 14:08:14 +08:00
@BindView(R.id.scrollView) ScrollView sv;
2017-07-18 00:59:22 +08:00
@OnClick(R.id.no_thanks)
public void dismiss() {
finish();
}
@OnClick(R.id.reboot)
public void reboot() {
2017-10-15 23:02:44 +08:00
Shell.su_raw("reboot");
2017-07-18 00:59:22 +08:00
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_flash);
ButterKnife.bind(this);
2017-10-16 14:08:14 +08:00
AdaptiveList<String> rootShellOutput = new AdaptiveList<String>() {
@Override
public synchronized void updateView() {
flashLogs.setText(TextUtils.join("\n", this));
sv.postDelayed(() -> sv.fullScroll(ScrollView.FOCUS_DOWN), 10);
}
};
2017-07-18 00:59:22 +08:00
setSupportActionBar(toolbar);
ActionBar ab = getSupportActionBar();
if (ab != null) {
ab.setTitle(R.string.flashing);
}
setFloating();
setFinishOnTouchOutside(false);
2017-08-31 03:07:33 +08:00
if (!Shell.rootAccess())
reboot.setVisibility(View.GONE);
2017-07-18 00:59:22 +08:00
// We must receive a Uri of the target zip
2017-08-31 03:07:33 +08:00
Intent intent = getIntent();
Uri uri = intent.getData();
2017-09-03 00:10:14 +08:00
boolean keepEnc = intent.getBooleanExtra(SET_ENC, false);
boolean keepVerity = intent.getBooleanExtra(SET_VERITY, false);
2017-08-31 03:07:33 +08:00
switch (getIntent().getStringExtra(SET_ACTION)) {
case FLASH_ZIP:
new FlashZip(this, uri, rootShellOutput)
.setCallBack(() -> buttonPanel.setVisibility(View.VISIBLE))
.exec();
break;
case PATCH_BOOT:
2017-09-03 00:10:14 +08:00
new InstallMagisk(this, rootShellOutput, uri, keepEnc, keepVerity, (Uri) intent.getParcelableExtra(SET_BOOT))
2017-08-31 03:07:33 +08:00
.setCallBack(() -> buttonPanel.setVisibility(View.VISIBLE))
.exec();
2017-09-03 00:10:14 +08:00
break;
case FLASH_MAGISK:
String boot = intent.getStringExtra(SET_BOOT);
2017-09-03 15:35:14 +08:00
if (getMagiskManager().remoteMagiskVersionCode < 1370) {
2017-09-03 00:10:14 +08:00
// Use legacy installation method
2017-10-15 23:02:44 +08:00
Shell.su_raw(
2017-09-03 00:10:14 +08:00
"echo \"BOOTIMAGE=" + boot + "\" > /dev/.magisk",
"echo \"KEEPFORCEENCRYPT=" + keepEnc + "\" >> /dev/.magisk",
"echo \"KEEPVERITY=" + keepVerity + "\" >> /dev/.magisk"
);
new FlashZip(this, uri, rootShellOutput)
.setCallBack(() -> buttonPanel.setVisibility(View.VISIBLE))
.exec();
} else {
// Use new installation method
new InstallMagisk(this, rootShellOutput, uri, keepEnc, keepVerity, boot)
.setCallBack(() -> buttonPanel.setVisibility(View.VISIBLE))
.exec();
}
break;
2017-08-31 03:07:33 +08:00
}
2017-07-18 00:59:22 +08:00
}
@Override
public void onBackPressed() {
// Prevent user accidentally press back button
}
}