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

154 lines
5.1 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.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
2017-08-31 03:07:33 +08:00
import android.widget.Button;
2017-07-18 00:59:22 +08:00
import android.widget.LinearLayout;
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;
import java.util.List;
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;
@BindView(R.id.flash_logs) RecyclerView flashLogs;
@BindView(R.id.button_panel) LinearLayout buttonPanel;
2017-08-31 03:07:33 +08:00
@BindView(R.id.reboot) Button reboot;
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-08-28 00:27:10 +08:00
getShell().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-08-31 03:07:33 +08:00
AdaptiveList<String> rootShellOutput = new AdaptiveList<>(flashLogs);
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
2017-08-31 03:07:33 +08:00
flashLogs.setAdapter(new FlashLogAdapter(rootShellOutput));
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
getShell().su_raw(
"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
}
2017-08-31 03:07:33 +08:00
private static class FlashLogAdapter extends RecyclerView.Adapter<ViewHolder> {
private List<String> mList;
FlashLogAdapter(List<String> list) {
mList = list;
}
2017-07-18 00:59:22 +08:00
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.list_item_flashlog, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
2017-08-31 03:07:33 +08:00
holder.text.setText(mList.get(position));
2017-07-18 00:59:22 +08:00
}
@Override
public int getItemCount() {
2017-08-31 03:07:33 +08:00
return mList.size();
2017-07-18 00:59:22 +08:00
}
}
2017-08-31 03:07:33 +08:00
public static class ViewHolder extends RecyclerView.ViewHolder {
2017-07-18 00:59:22 +08:00
@BindView(R.id.textView) TextView text;
public ViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
}
2017-07-18 00:59:22 +08:00
}