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 28, 2018
2 parents 7c977db + b8eaff6 commit 5ae79f1
Show file tree
Hide file tree
Showing 23 changed files with 613 additions and 454 deletions.
45 changes: 3 additions & 42 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
2. Set configurations in `config.prop`. A sample file `config.prop.sample` is provided as an example.
3. Run `build.py` with argument `-h` to see the built-in help message. The `-h` option also works for each supported actions, e.g. `./build.py binary -h`
4. By default, `build.py` build binaries and Magisk Manager in debug mode. If you want to build Magisk Manager in release mode (via the `--release` flag), you need a Java Keystore file `release-key.jks` to sign Magisk Manager's APK. For more information, check out [Google's Official Documentation](https://developer.android.com/studio/publish/app-signing.html#signing-manually).
5. The SafetyNet extension pack requires the full Magisk Manager as a `compileOnly` dependency. Build the **release** APK, convert it back to Java `.class` files (I use [dex2jar](https://github.com/pxb1988/dex2jar)), and place the converted JAR under `snet/libs` before compiling.

## Documentation
[Link to Documentation](docs/README.MD)

## License

Expand All @@ -31,44 +33,3 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
```

## Credits

**MagiskManager** (`app`)

* Copyright 2016-2018, John Wu (@topjohnwu)
* All contributors and translators on Github

**MagiskSU** (`native/jni/su`)

* Copyright 2016-2018, John Wu (@topjohnwu)
* Copyright 2015, Pierre-Hugues Husson ([email protected])
* Copyright 2013, Koushik Dutta (@koush)
* Copyright 2010, Adam Shanks (@ChainsDD)
* Copyright 2008, Zinx Verituse (@zinxv)

**MagiskPolicy** (`native/jni/magiskpolicy`)

* Copyright 2016-2018, John Wu (@topjohnwu)
* Copyright 2015, Pierre-Hugues Husson ([email protected])
* Copyright 2015, Joshua Brindle (@joshua_brindle)

**MagiskHide** (`native/jni/magiskhide`)

* Copyright 2016-2018, John Wu (@topjohnwu)
* Copyright 2016, Pierre-Hugues Husson ([email protected])

**resetprop** (`native/jni/resetprop`)

* Copyright 2016-2018 John Wu (@topjohnwu)
* Copyright 2016 nkk71 ([email protected])

**External Dependencies** (`native/jni/external`)

* Makefile for busybox, generated by [ndk-busybox-kitchen](https://github.com/topjohnwu/ndk-busybox-kitchen)
* Each dependencies has its own license/copyright information in each subdirectory.
All of them are either GPL or GPL compatible.

**Others Not Mentioned**

* Copyright 2016-2018, John Wu (@topjohnwu)
30 changes: 18 additions & 12 deletions app/src/full/java/com/topjohnwu/magisk/MagiskFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.app.NotificationManager;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.v4.widget.SwipeRefreshLayout;
Expand All @@ -20,12 +21,16 @@

import com.topjohnwu.magisk.asyncs.CheckSafetyNet;
import com.topjohnwu.magisk.asyncs.CheckUpdates;
import com.topjohnwu.magisk.components.AlertDialogBuilder;
import com.topjohnwu.magisk.components.Activity;
import com.topjohnwu.magisk.components.CustomAlertDialog;
import com.topjohnwu.magisk.components.EnvFixDialog;
import com.topjohnwu.magisk.components.ExpandableView;
import com.topjohnwu.magisk.components.Fragment;
import com.topjohnwu.magisk.components.MagiskInstallDialog;
import com.topjohnwu.magisk.components.ManagerInstallDialog;
import com.topjohnwu.magisk.components.UninstallDialog;
import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.ISafetyNetHelper;
import com.topjohnwu.magisk.utils.ShowUI;
import com.topjohnwu.magisk.utils.Topic;
import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.superuser.Shell;
Expand Down Expand Up @@ -84,19 +89,19 @@ void safetyNet() {
safetyNetProgress.setVisibility(View.VISIBLE);
safetyNetRefreshIcon.setVisibility(View.GONE);
safetyNetStatusText.setText(R.string.checking_safetyNet_status);
new CheckSafetyNet(getActivity()).exec();
new CheckSafetyNet(requireActivity()).exec();
collapse();
};
if (!TextUtils.equals(mm.getPackageName(), Const.ORIG_PKG_NAME)) {
new AlertDialogBuilder(getActivity())
new CustomAlertDialog(requireActivity())
.setTitle(R.string.cannot_check_sn_title)
.setMessage(R.string.cannot_check_sn_notice)
.setCancelable(true)
.setPositiveButton(R.string.ok, null)
.show();
} else if (!CheckSafetyNet.dexPath.exists()) {
// Show dialog
new AlertDialogBuilder(getActivity())
new CustomAlertDialog(requireActivity())
.setTitle(R.string.proprietary_title)
.setMessage(R.string.proprietary_notice)
.setCancelable(true)
Expand All @@ -115,25 +120,26 @@ void install() {

// Show Manager update first
if (mm.remoteManagerVersionCode > BuildConfig.VERSION_CODE) {
ShowUI.managerInstallDialog(getActivity());
new ManagerInstallDialog((Activity) requireActivity()).show();
return;
}

((NotificationManager) mm.getSystemService(Context.NOTIFICATION_SERVICE)).cancelAll();
ShowUI.magiskInstallDialog(getActivity());
new MagiskInstallDialog((Activity) getActivity()).show();
}

@OnClick(R.id.uninstall_button)
void uninstall() {
ShowUI.uninstallDialog(getActivity());
new UninstallDialog(requireActivity()).show();
}

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_magisk, container, false);
unbinder = ButterKnife.bind(this, v);
getActivity().setTitle(R.string.magisk);
requireActivity().setTitle(R.string.magisk);

mm = getApplication();

Expand Down Expand Up @@ -204,7 +210,7 @@ public Container getContainer() {
}

private void updateUI() {
((MainActivity) getActivity()).checkHideSection();
((MainActivity) requireActivity()).checkHideSection();

boolean hasNetwork = Utils.checkNetworkStatus();
boolean hasRoot = Shell.rootAccess();
Expand Down Expand Up @@ -266,7 +272,7 @@ private void updateCheckUI() {
install();
} else if (mm.remoteMagiskVersionCode >= Const.MAGISK_VER.FIX_ENV &&
!ShellUtils.fastCmdResult("env_check")) {
ShowUI.envFixDialog(getActivity());
new EnvFixDialog(requireActivity()).show();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import android.widget.TextView;

import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.components.AlertDialogBuilder;
import com.topjohnwu.magisk.components.CustomAlertDialog;
import com.topjohnwu.magisk.components.ExpandableView;
import com.topjohnwu.magisk.components.SnackbarMaker;
import com.topjohnwu.magisk.container.Policy;
Expand Down Expand Up @@ -93,7 +93,7 @@ public void onBindViewHolder(ViewHolder holder, int position) {
dbHelper.updatePolicy(policy);
}
});
holder.delete.setOnClickListener(v -> new AlertDialogBuilder((Activity) v.getContext())
holder.delete.setOnClickListener(v -> new CustomAlertDialog((Activity) v.getContext())
.setTitle(R.string.su_revoke_title)
.setMessage(v.getContext().getString(R.string.su_revoke_msg, policy.appName))
.setPositiveButton(R.string.yes, (dialog, which) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.asyncs.MarkDownWindow;
import com.topjohnwu.magisk.asyncs.ProcessRepoZip;
import com.topjohnwu.magisk.components.AlertDialogBuilder;
import com.topjohnwu.magisk.components.CustomAlertDialog;
import com.topjohnwu.magisk.container.Module;
import com.topjohnwu.magisk.container.Repo;
import com.topjohnwu.magisk.database.RepoDatabaseHelper;
Expand Down Expand Up @@ -102,7 +102,7 @@ public void onBindItemViewHolder(RepoHolder holder, int section, int position) {

holder.downloadImage.setOnClickListener(v -> {
String filename = repo.getName() + "-" + repo.getVersion() + ".zip";
new AlertDialogBuilder((Activity) context)
new CustomAlertDialog((Activity) context)
.setTitle(context.getString(R.string.repo_install_title, repo.getName()))
.setMessage(context.getString(R.string.repo_install_msg, filename))
.setCancelable(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ private void dlSnet() throws Exception {
private void dyload() throws Exception {
DexClassLoader loader = new DexClassLoader(dexPath.getPath(), dexPath.getParent(),
null, ISafetyNetHelper.class.getClassLoader());
Class<?> clazz = loader.loadClass("com.topjohnwu.snet.SafetyNetHelper");
helper = (ISafetyNetHelper) clazz.getConstructors()[0]
.newInstance(getActivity(), (ISafetyNetHelper.Callback)
code -> MagiskManager.get().safetyNetDone.publish(false, code));
Class<?> clazz = loader.loadClass("com.topjohnwu.snet.Snet");
helper = (ISafetyNetHelper) clazz.getMethod("newHelper",
Class.class, String.class, Activity.class, Object.class)
.invoke(null, ISafetyNetHelper.class, dexPath.getPath(), getActivity(),
(ISafetyNetHelper.Callback) code ->
MagiskManager.get().safetyNetDone.publish(false, code));
if (helper.getVersion() != Const.SNET_VER) {
throw new Exception();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.topjohnwu.magisk.BuildConfig;
import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.ShowUI;
import com.topjohnwu.magisk.utils.NotificationMgr;
import com.topjohnwu.magisk.utils.WebService;

import org.json.JSONException;
Expand Down Expand Up @@ -59,9 +59,9 @@ protected void onPostExecute(Void v) {
MagiskManager mm = MagiskManager.get();
if (showNotification) {
if (BuildConfig.VERSION_CODE < mm.remoteManagerVersionCode) {
ShowUI.managerUpdateNotification();
NotificationMgr.managerUpdate();
} else if (mm.magiskVersionCode < mm.remoteMagiskVersionCode) {
ShowUI.magiskUpdateNotification();
NotificationMgr.magiskUpdate();
}
}
mm.updateCheckDone.publish();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import butterknife.BindView;
import butterknife.ButterKnife;

public class AlertDialogBuilder extends AlertDialog.Builder {
public class CustomAlertDialog extends AlertDialog.Builder {

@BindView(R.id.button_panel) LinearLayout buttons;
@BindView(R.id.message_panel) LinearLayout messagePanel;
Expand All @@ -34,17 +34,7 @@ public class AlertDialogBuilder extends AlertDialog.Builder {

private AlertDialog dialog;

public AlertDialogBuilder(@NonNull Activity context) {
super(context);
setup();
}

public AlertDialogBuilder(@NonNull Activity context, @StyleRes int themeResId) {
super(context, themeResId);
setup();
}

private void setup() {
{
View v = LayoutInflater.from(getContext()).inflate(R.layout.alert_dialog, null);
ButterKnife.bind(this, v);
super.setView(v);
Expand All @@ -55,9 +45,12 @@ private void setup() {
messagePanel.setVisibility(View.GONE);
}

@Override
public AlertDialog.Builder setTitle(int titleId) {
return super.setTitle(titleId);
public CustomAlertDialog(@NonNull Activity context) {
super(context);
}

public CustomAlertDialog(@NonNull Activity context, @StyleRes int themeResId) {
super(context, themeResId);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.topjohnwu.magisk.components;

import android.app.Activity;
import android.content.Context;
import android.net.Uri;
import android.support.annotation.NonNull;

import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.asyncs.InstallMagisk;
import com.topjohnwu.magisk.receivers.DownloadReceiver;
import com.topjohnwu.magisk.utils.Utils;

public class EnvFixDialog extends CustomAlertDialog {

public EnvFixDialog(@NonNull Activity activity) {
super(activity);
MagiskManager mm = Utils.getMagiskManager(activity);
String filename = Utils.fmt("Magisk-v%s(%d).zip",
mm.remoteMagiskVersionString, mm.remoteMagiskVersionCode);
setTitle(R.string.env_fix_title);
setMessage(R.string.env_fix_msg);
setCancelable(true);
setPositiveButton(R.string.yes, (d, i) -> Utils.dlAndReceive(activity,
new DownloadReceiver() {
@Override
public void onDownloadDone(Context context, Uri uri) {
new InstallMagisk(activity, uri).exec();
}
}, mm.magiskLink, filename));
setNegativeButton(R.string.no_thanks, null);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.topjohnwu.magisk.components;

import android.content.res.AssetManager;
import android.content.res.Resources;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Keep;
import android.support.annotation.Nullable;
import android.support.annotation.StyleRes;
import android.support.v7.app.AppCompatActivity;
Expand All @@ -15,9 +13,7 @@

public abstract class FlavorActivity extends AppCompatActivity {

private AssetManager swappedAssetManager = null;
private Resources swappedResources = null;
private Resources.Theme backupTheme = null;
private ActivityResultListener activityResultListener;

@StyleRes
public int getDarkTheme() {
Expand All @@ -34,7 +30,6 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
if (this instanceof Topic.Subscriber) {
((Topic.Subscriber) this).subscribeTopics();
}

if (getMagiskManager().isDarkTheme && getDarkTheme() != -1) {
setTheme(getDarkTheme());
}
Expand Down Expand Up @@ -63,46 +58,18 @@ protected void setFloating() {
}

@Override
public Resources.Theme getTheme() {
return backupTheme == null ? super.getTheme() : backupTheme;
}

@Override
public AssetManager getAssets() {
return swappedAssetManager == null ? super.getAssets() : swappedAssetManager;
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (activityResultListener != null)
activityResultListener.onActivityResult(requestCode, resultCode, data);
activityResultListener = null;
}

private AssetManager getAssets(String apk) {
try {
AssetManager asset = AssetManager.class.newInstance();
AssetManager.class.getMethod("addAssetPath", String.class).invoke(asset, apk);
return asset;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}

@Override
public Resources getResources() {
return swappedResources == null ? super.getResources() : swappedResources;
}

@Keep
public void swapResources(String dexPath) {
AssetManager asset = getAssets(dexPath);
if (asset != null) {
backupTheme = super.getTheme();
Resources res = super.getResources();
swappedResources = new Resources(asset, res.getDisplayMetrics(), res.getConfiguration());
swappedAssetManager = asset;
}
public void startActivityForResult(Intent intent, int requestCode, ActivityResultListener listener) {
activityResultListener = listener;
super.startActivityForResult(intent, requestCode);
}

@Keep
public void restoreResources() {
swappedAssetManager = null;
swappedResources = null;
backupTheme = null;
public interface ActivityResultListener {
void onActivityResult(int requestCode, int resultCode, Intent data);
}
}
Loading

0 comments on commit 5ae79f1

Please sign in to comment.