Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
ianmacd committed Jul 30, 2018
2 parents dc97657 + 914b7ee commit 8a70aab
Show file tree
Hide file tree
Showing 58 changed files with 605 additions and 518 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ dependencies {
fullImplementation 'com.atlassian.commonmark:commonmark:0.11.0'
fullImplementation 'org.kamranzafar:jtar:2.3'
fullImplementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
fullAnnotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
}
11 changes: 6 additions & 5 deletions app/src/full/java/com/topjohnwu/magisk/FlashActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.topjohnwu.magisk.asyncs.InstallMagisk;
import com.topjohnwu.magisk.components.Activity;
import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.Download;
import com.topjohnwu.magisk.utils.RootUtils;
import com.topjohnwu.superuser.CallbackList;
import com.topjohnwu.superuser.Shell;
Expand Down Expand Up @@ -63,7 +64,7 @@ void saveLogs() {
now.get(Calendar.DAY_OF_MONTH), now.get(Calendar.HOUR_OF_DAY),
now.get(Calendar.MINUTE), now.get(Calendar.SECOND));

File logFile = new File(Const.EXTERNAL_PATH + "/logs", filename);
File logFile = new File(Download.EXTERNAL_PATH + "/logs", filename);
logFile.getParentFile().mkdirs();
try (FileWriter writer = new FileWriter(logFile)) {
for (String s : logs) {
Expand All @@ -74,7 +75,7 @@ void saveLogs() {
e.printStackTrace();
return;
}
MagiskManager.toast(logFile.getPath(), Toast.LENGTH_LONG);
Global.toast(logFile.getPath(), Toast.LENGTH_LONG);
}

@Override
Expand Down Expand Up @@ -119,13 +120,13 @@ public void onAddElement(String s) {
new UninstallMagisk(this, uri, console, logs).exec();
break;
case Const.Value.FLASH_MAGISK:
new InstallMagisk(this, console, logs, uri, InstallMagisk.DIRECT_MODE).exec();
new InstallMagisk(this, console, logs, InstallMagisk.DIRECT_MODE).exec();
break;
case Const.Value.FLASH_INACTIVE_SLOT:
new InstallMagisk(this, console, logs, uri, InstallMagisk.SECOND_SLOT_MODE).exec();
new InstallMagisk(this, console, logs, InstallMagisk.SECOND_SLOT_MODE).exec();
break;
case Const.Value.PATCH_BOOT:
new InstallMagisk(this, console, logs, uri,
new InstallMagisk(this, console, logs,
intent.getParcelableExtra(Const.Key.FLASH_SET_BOOT)).exec();
break;
}
Expand Down
58 changes: 58 additions & 0 deletions app/src/full/java/com/topjohnwu/magisk/Global.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.topjohnwu.magisk;

import android.os.Handler;
import android.os.Looper;
import android.widget.Toast;

import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.superuser.ShellUtils;

import java.lang.ref.WeakReference;

public class Global {
// Global app instance
public static WeakReference<MagiskManager> weakApp;
public static Handler mainHandler = new Handler(Looper.getMainLooper());

// Current status
public static String magiskVersionString;
public static int magiskVersionCode = -1;
public static boolean magiskHide;

// Update Info
public static String remoteMagiskVersionString;
public static int remoteMagiskVersionCode = -1;
public static String magiskLink;
public static String magiskNoteLink;
public static String remoteManagerVersionString;
public static int remoteManagerVersionCode = -1;
public static String managerLink;
public static String managerNoteLink;
public static String uninstallerLink;

// Install flags
public static boolean keepVerity = false;
public static boolean keepEnc = false;

public static void loadMagiskInfo() {
try {
magiskVersionString = ShellUtils.fastCmd("magisk -v").split(":")[0];
magiskVersionCode = Integer.parseInt(ShellUtils.fastCmd("magisk -V"));
String s = ShellUtils.fastCmd((magiskVersionCode >= Const.MAGISK_VER.RESETPROP_PERSIST ?
"resetprop -p " : "getprop ") + Const.MAGISKHIDE_PROP);
magiskHide = s.isEmpty() || Integer.parseInt(s) != 0;
} catch (NumberFormatException ignored) {}
}

public static MagiskManager MM() {
return weakApp.get();
}

public static void toast(CharSequence msg, int duration) {
mainHandler.post(() -> Toast.makeText(MM(), msg, duration).show());
}

public static void toast(int resId, int duration) {
mainHandler.post(() -> Toast.makeText(MM(), resId, duration).show());
}
}
42 changes: 21 additions & 21 deletions app/src/full/java/com/topjohnwu/magisk/MagiskFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
import com.topjohnwu.magisk.components.ManagerInstallDialog;
import com.topjohnwu.magisk.components.UninstallDialog;
import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.Download;
import com.topjohnwu.magisk.utils.ISafetyNetHelper;
import com.topjohnwu.magisk.utils.Topic;
import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.superuser.Shell;
import com.topjohnwu.superuser.ShellUtils;

Expand Down Expand Up @@ -119,7 +119,7 @@ void install() {
shownDialog = true;

// Show Manager update first
if (mm.remoteManagerVersionCode > BuildConfig.VERSION_CODE) {
if (Global.remoteManagerVersionCode > BuildConfig.VERSION_CODE) {
new ManagerInstallDialog((Activity) requireActivity()).show();
return;
}
Expand All @@ -146,10 +146,10 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
expandableContainer.expandLayout = expandLayout;
setupExpandable();

keepVerityChkbox.setChecked(mm.keepVerity);
keepVerityChkbox.setOnCheckedChangeListener((view, checked) -> mm.keepVerity = checked);
keepEncChkbox.setChecked(mm.keepEnc);
keepEncChkbox.setOnCheckedChangeListener((view, checked) -> mm.keepEnc = checked);
keepVerityChkbox.setChecked(Global.keepVerity);
keepVerityChkbox.setOnCheckedChangeListener((view, checked) -> Global.keepVerity = checked);
keepEncChkbox.setChecked(Global.keepEnc);
keepEncChkbox.setOnCheckedChangeListener((view, checked) -> Global.keepEnc = checked);

mSwipeRefreshLayout.setOnRefreshListener(this);
updateUI();
Expand All @@ -159,7 +159,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c

@Override
public void onRefresh() {
mm.loadMagiskInfo();
Global.loadMagiskInfo();
updateUI();

magiskUpdateText.setText(R.string.checking_for_updates);
Expand All @@ -170,14 +170,14 @@ public void onRefresh() {

mm.safetyNetDone.reset();
mm.updateCheckDone.reset();
mm.remoteMagiskVersionString = null;
mm.remoteMagiskVersionCode = -1;
Global.remoteMagiskVersionString = null;
Global.remoteMagiskVersionCode = -1;
collapse();

shownDialog = false;

// Trigger state check
if (Utils.checkNetworkStatus()) {
if (Download.checkNetworkStatus(mm)) {
new CheckUpdates().exec();
} else {
mSwipeRefreshLayout.setRefreshing(false);
Expand Down Expand Up @@ -212,9 +212,9 @@ public Container getContainer() {
private void updateUI() {
((MainActivity) requireActivity()).checkHideSection();

boolean hasNetwork = Utils.checkNetworkStatus();
boolean hasNetwork = Download.checkNetworkStatus(mm);
boolean hasRoot = Shell.rootAccess();
boolean isUpToDate = mm.magiskVersionCode > Const.MAGISK_VER.UNIFIED;
boolean isUpToDate = Global.magiskVersionCode > Const.MAGISK_VER.UNIFIED;

magiskUpdate.setVisibility(hasNetwork ? View.VISIBLE : View.GONE);
safetyNetCard.setVisibility(hasNetwork ? View.VISIBLE : View.GONE);
Expand All @@ -223,14 +223,14 @@ private void updateUI() {

int image, color;

if (mm.magiskVersionCode < 0) {
if (Global.magiskVersionCode < 0) {
color = colorBad;
image = R.drawable.ic_cancel;
magiskVersionText.setText(R.string.magisk_version_error);
} else {
color = colorOK;
image = R.drawable.ic_check_circle;
magiskVersionText.setText(getString(R.string.current_magisk_title, "v" + mm.magiskVersionString));
magiskVersionText.setText(getString(R.string.current_magisk_title, "v" + Global.magiskVersionString));
}

magiskStatusIcon.setImageResource(image);
Expand All @@ -240,19 +240,19 @@ private void updateUI() {
private void updateCheckUI() {
int image, color;

if (mm.remoteMagiskVersionCode < 0) {
if (Global.remoteMagiskVersionCode < 0) {
color = colorNeutral;
image = R.drawable.ic_help;
magiskUpdateText.setText(R.string.invalid_update_channel);
installButton.setVisibility(View.GONE);
} else {
color = colorOK;
image = R.drawable.ic_check_circle;
magiskUpdateText.setText(getString(R.string.install_magisk_title, "v" + mm.remoteMagiskVersionString));
magiskUpdateText.setText(getString(R.string.install_magisk_title, "v" + Global.remoteMagiskVersionString));
installButton.setVisibility(View.VISIBLE);
if (mm.remoteManagerVersionCode > BuildConfig.VERSION_CODE) {
if (Global.remoteManagerVersionCode > BuildConfig.VERSION_CODE) {
installText.setText(getString(R.string.update, getString(R.string.app_name)));
} else if (mm.magiskVersionCode > 0 && mm.remoteMagiskVersionCode > mm.magiskVersionCode) {
} else if (Global.magiskVersionCode > 0 && Global.remoteMagiskVersionCode > Global.magiskVersionCode) {
installText.setText(getString(R.string.update, getString(R.string.magisk)));
} else {
installText.setText(R.string.install);
Expand All @@ -267,10 +267,10 @@ private void updateCheckUI() {
mSwipeRefreshLayout.setRefreshing(false);

if (!shownDialog) {
if (mm.remoteMagiskVersionCode > mm.magiskVersionCode
|| mm.remoteManagerVersionCode > BuildConfig.VERSION_CODE) {
if (Global.remoteMagiskVersionCode > Global.magiskVersionCode
|| Global.remoteManagerVersionCode > BuildConfig.VERSION_CODE) {
install();
} else if (mm.remoteMagiskVersionCode >= Const.MAGISK_VER.FIX_ENV &&
} else if (Global.remoteMagiskVersionCode >= Const.MAGISK_VER.FIX_ENV &&
!ShellUtils.fastCmdResult("env_check")) {
new EnvFixDialog(requireActivity()).show();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.topjohnwu.magisk.components.Fragment;
import com.topjohnwu.magisk.components.SnackbarMaker;
import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.Download;
import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.superuser.Shell;

Expand Down Expand Up @@ -108,7 +109,7 @@ public void saveLogs() {
now.get(Calendar.DAY_OF_MONTH), now.get(Calendar.HOUR_OF_DAY),
now.get(Calendar.MINUTE), now.get(Calendar.SECOND));

File targetFile = new File(Const.EXTERNAL_PATH + "/logs", filename);
File targetFile = new File(Download.EXTERNAL_PATH + "/logs", filename);
targetFile.getParentFile().mkdirs();
try {
targetFile.createNewFile();
Expand Down
Loading

0 comments on commit 8a70aab

Please sign in to comment.