Compare commits
149 Commits
manager-v5
...
manager-v5
Author | SHA1 | Date | |
---|---|---|---|
![]() |
1adf331268 | ||
![]() |
349b3e961b | ||
![]() |
96650c06f0 | ||
![]() |
26038a0a07 | ||
![]() |
6a148b5dd9 | ||
![]() |
0e109ef979 | ||
![]() |
de2285d5e9 | ||
![]() |
b2483ba437 | ||
![]() |
a82a5e5a49 | ||
![]() |
d161a02e71 | ||
![]() |
d2b6a700b1 | ||
![]() |
af203cef24 | ||
![]() |
673e917e76 | ||
![]() |
a3bd41db54 | ||
![]() |
0d9527921a | ||
![]() |
f0e4aec0af | ||
![]() |
b0d65b5edd | ||
![]() |
75532ef591 | ||
![]() |
9a6d1bd700 | ||
![]() |
a7ed6c15d3 | ||
![]() |
5ee49ba065 | ||
![]() |
d34bd47bea | ||
![]() |
f17792380b | ||
![]() |
c11920110e | ||
![]() |
ec5a993fea | ||
![]() |
d250c2cc89 | ||
![]() |
767e73f40c | ||
![]() |
3f699c9d2f | ||
![]() |
50dbd9befd | ||
![]() |
760e01bf92 | ||
![]() |
543f435b1e | ||
![]() |
91337218b3 | ||
![]() |
afff3c0a49 | ||
![]() |
a1871e4bc3 | ||
![]() |
3aa0294cd4 | ||
![]() |
310b266251 | ||
![]() |
21b1b5098e | ||
![]() |
a3a4a5d8a5 | ||
![]() |
270536f33c | ||
![]() |
66bb433cc6 | ||
![]() |
bd4ef1a03a | ||
![]() |
aa2d9a3bf1 | ||
![]() |
fd6cbb138c | ||
![]() |
aa75c8e5e4 | ||
![]() |
c461fc6daa | ||
![]() |
96eaa833f5 | ||
![]() |
863b13a694 | ||
![]() |
e6fea4e6dd | ||
![]() |
83bfc13056 | ||
![]() |
bc4f09209b | ||
![]() |
967ca17238 | ||
![]() |
595c72147c | ||
![]() |
f3c3b5a649 | ||
![]() |
1cd2c5e653 | ||
![]() |
b2873dd44b | ||
![]() |
bb80ab4026 | ||
![]() |
80cabb338b | ||
![]() |
2c69e2c151 | ||
![]() |
c1dd23f5e0 | ||
![]() |
f93624a41c | ||
![]() |
9f4559a059 | ||
![]() |
fd05cad303 | ||
![]() |
d58b06e493 | ||
![]() |
2f0b549027 | ||
![]() |
87dbd7e541 | ||
![]() |
96e5da36be | ||
![]() |
43745edac0 | ||
![]() |
f5ceee547c | ||
![]() |
b612bce779 | ||
![]() |
2e88e5e9c7 | ||
![]() |
9a7aa25c90 | ||
![]() |
c4420fe932 | ||
![]() |
a5260f3a95 | ||
![]() |
47ccf4b1f5 | ||
![]() |
a356b21895 | ||
![]() |
614a36c888 | ||
![]() |
f520fe36bd | ||
![]() |
7273a1c34d | ||
![]() |
dc45cbce37 | ||
![]() |
708d8f75c0 | ||
![]() |
bd37d90228 | ||
![]() |
b1ad691464 | ||
![]() |
f4e7baf31e | ||
![]() |
c0e60c41f2 | ||
![]() |
c8dad43e00 | ||
![]() |
a8f124704d | ||
![]() |
eed2816491 | ||
![]() |
a6334b3e35 | ||
![]() |
334beebfeb | ||
![]() |
13dad848bd | ||
![]() |
e518f4cef8 | ||
![]() |
c8fd5da2da | ||
![]() |
3a74729ecc | ||
![]() |
49c672ac4d | ||
![]() |
b570cb5b77 | ||
![]() |
97bf388471 | ||
![]() |
1a32aaea6f | ||
![]() |
4635883dec | ||
![]() |
3ba6db4a50 | ||
![]() |
2f1de25747 | ||
![]() |
f60fd42ac0 | ||
![]() |
ecc8f9c792 | ||
![]() |
e295dfdcf7 | ||
![]() |
fc42c25390 | ||
![]() |
27d5858e06 | ||
![]() |
e1ef732b60 | ||
![]() |
9840b95c21 | ||
![]() |
a6f8446d81 | ||
![]() |
c1c844c830 | ||
![]() |
389299afd1 | ||
![]() |
826543a291 | ||
![]() |
4ac83cfded | ||
![]() |
64c363ce53 | ||
![]() |
cca4347bf9 | ||
![]() |
3ae3d4926a | ||
![]() |
36025d6d9f | ||
![]() |
e171362e3e | ||
![]() |
3e0bf2ae15 | ||
![]() |
07aa9f4b8b | ||
![]() |
b2d9f3fc64 | ||
![]() |
5fb3e9167e | ||
![]() |
99c74b31be | ||
![]() |
ce5b13824e | ||
![]() |
c39170c42e | ||
![]() |
fd19fbf300 | ||
![]() |
166469827f | ||
![]() |
a34ed538b6 | ||
![]() |
5f22d3e055 | ||
![]() |
fdd700f3e5 | ||
![]() |
adf930f126 | ||
![]() |
05f41928cd | ||
![]() |
2ee0829871 | ||
![]() |
743560825d | ||
![]() |
e3d84ac349 | ||
![]() |
266c832b30 | ||
![]() |
f5374a024e | ||
![]() |
4956d826fb | ||
![]() |
f5cc2af5d0 | ||
![]() |
5880d4a6ec | ||
![]() |
ae05dce958 | ||
![]() |
9ebe372a9a | ||
![]() |
e6e04cc5b3 | ||
![]() |
12352510fd | ||
![]() |
2b3d927937 | ||
![]() |
a8890740f5 | ||
![]() |
f60d7ee54b | ||
![]() |
896ca2ef6b | ||
![]() |
c036f6d529 | ||
![]() |
6f457c0c59 |
2
.gitignore
vendored
@@ -5,7 +5,7 @@
|
|||||||
/build
|
/build
|
||||||
app/release
|
app/release
|
||||||
*.hprof
|
*.hprof
|
||||||
app/.externalNativeBuild/
|
.externalNativeBuild/
|
||||||
*.sh
|
*.sh
|
||||||
public.certificate.x509.pem
|
public.certificate.x509.pem
|
||||||
private.key.pk8
|
private.key.pk8
|
||||||
|
@@ -1,7 +1,2 @@
|
|||||||
# Magisk Manager
|
# Magisk Manager
|
||||||
This is one of the submodules used in Magisk. The project is licensed under GPL v3 (or newer).
|
This repo is no longer an independent component. It is a submodule of the [Magisk Project](https://github.com/topjohnwu/Magisk).
|
||||||
More info are written in the [Magisk Main Repo](https://github.com/topjohnwu/Magisk)
|
|
||||||
|
|
||||||
## Building Notes
|
|
||||||
You need to install CMake and NDK to build the zipadjust library.
|
|
||||||
There are several files required to let Magisk Manager work properly, and they can be copied by using the build script in the [Magisk Main Repo](https://github.com/topjohnwu/Magisk). These files are: `magisk_uninstaller.sh`, `util_functions.sh`, `public.certificate.x509.pem`, and `private.key.pk8` under the `app/src/main/assets` folder.
|
|
||||||
|
1
app/.gitignore
vendored
@@ -1 +0,0 @@
|
|||||||
/build
|
|
@@ -1,66 +0,0 @@
|
|||||||
apply plugin: 'com.android.application'
|
|
||||||
|
|
||||||
android {
|
|
||||||
compileSdkVersion 26
|
|
||||||
buildToolsVersion "26.0.2"
|
|
||||||
|
|
||||||
defaultConfig {
|
|
||||||
applicationId "com.topjohnwu.magisk"
|
|
||||||
minSdkVersion 21
|
|
||||||
targetSdkVersion 26
|
|
||||||
versionCode 57
|
|
||||||
versionName "5.4.0"
|
|
||||||
ndk {
|
|
||||||
moduleName 'zipadjust'
|
|
||||||
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
|
|
||||||
}
|
|
||||||
javaCompileOptions {
|
|
||||||
annotationProcessorOptions {
|
|
||||||
argument('butterknife.debuggable', 'false')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
buildTypes {
|
|
||||||
release {
|
|
||||||
minifyEnabled true
|
|
||||||
shrinkResources true
|
|
||||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
compileOptions {
|
|
||||||
sourceCompatibility JavaVersion.VERSION_1_8
|
|
||||||
targetCompatibility JavaVersion.VERSION_1_8
|
|
||||||
}
|
|
||||||
dexOptions {
|
|
||||||
preDexLibraries true
|
|
||||||
javaMaxHeapSize "2g"
|
|
||||||
}
|
|
||||||
externalNativeBuild {
|
|
||||||
cmake {
|
|
||||||
path 'src/main/jni/CMakeLists.txt'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
lintOptions {
|
|
||||||
disable 'MissingTranslation'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
repositories {
|
|
||||||
jcenter()
|
|
||||||
maven { url "https://jitpack.io" }
|
|
||||||
maven { url "https://maven.google.com" }
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
|
||||||
implementation project(':common')
|
|
||||||
implementation project(':jarsigner')
|
|
||||||
implementation 'com.android.support:recyclerview-v7:26.1.0'
|
|
||||||
implementation 'com.android.support:cardview-v7:26.1.0'
|
|
||||||
implementation 'com.android.support:design:26.1.0'
|
|
||||||
implementation 'com.android.support:support-v4:26.1.0'
|
|
||||||
implementation 'com.jakewharton:butterknife:8.8.1'
|
|
||||||
implementation 'com.atlassian.commonmark:commonmark:0.10.0'
|
|
||||||
implementation 'org.kamranzafar:jtar:2.3'
|
|
||||||
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
|
|
||||||
}
|
|
Before Width: | Height: | Size: 73 KiB |
@@ -1,134 +0,0 @@
|
|||||||
package com.topjohnwu.magisk;
|
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.support.annotation.Nullable;
|
|
||||||
import android.support.v7.app.ActionBar;
|
|
||||||
import android.support.v7.app.AlertDialog;
|
|
||||||
import android.support.v7.widget.Toolbar;
|
|
||||||
import android.text.Html;
|
|
||||||
import android.text.Spanned;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.text.method.LinkMovementMethod;
|
|
||||||
import android.view.View;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import com.topjohnwu.magisk.components.AboutCardRow;
|
|
||||||
import com.topjohnwu.magisk.components.Activity;
|
|
||||||
import com.topjohnwu.magisk.components.AlertDialogBuilder;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import butterknife.BindView;
|
|
||||||
import butterknife.ButterKnife;
|
|
||||||
|
|
||||||
public class AboutActivity extends Activity {
|
|
||||||
|
|
||||||
private static final String DONATION_URL = "https://www.paypal.me/topjohnwu";
|
|
||||||
private static final String XDA_THREAD = "http://forum.xda-developers.com/showthread.php?t=3432382";
|
|
||||||
private static final String SOURCE_CODE_URL = "https://github.com/topjohnwu/MagiskManager";
|
|
||||||
|
|
||||||
@BindView(R.id.toolbar) Toolbar toolbar;
|
|
||||||
@BindView(R.id.app_version_info) AboutCardRow appVersionInfo;
|
|
||||||
@BindView(R.id.app_changelog) AboutCardRow appChangelog;
|
|
||||||
@BindView(R.id.app_developers) AboutCardRow appDevelopers;
|
|
||||||
@BindView(R.id.app_translators) AboutCardRow appTranslators;
|
|
||||||
@BindView(R.id.app_source_code) AboutCardRow appSourceCode;
|
|
||||||
@BindView(R.id.support_thread) AboutCardRow supportThread;
|
|
||||||
@BindView(R.id.donation) AboutCardRow donation;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
if (getMagiskManager().isDarkTheme) {
|
|
||||||
setTheme(R.style.AppTheme_Transparent_Dark);
|
|
||||||
}
|
|
||||||
setContentView(R.layout.activity_about);
|
|
||||||
ButterKnife.bind(this);
|
|
||||||
|
|
||||||
setSupportActionBar(toolbar);
|
|
||||||
toolbar.setNavigationOnClickListener(view -> finish());
|
|
||||||
|
|
||||||
ActionBar ab = getSupportActionBar();
|
|
||||||
if (ab != null) {
|
|
||||||
ab.setTitle(R.string.about);
|
|
||||||
ab.setDisplayHomeAsUpEnabled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
appVersionInfo.setSummary(String.format(Locale.US, "%s (%d)", BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE));
|
|
||||||
|
|
||||||
String changes = null;
|
|
||||||
try (InputStream is = getAssets().open("changelog.html")) {
|
|
||||||
int size = is.available();
|
|
||||||
|
|
||||||
byte[] buffer = new byte[size];
|
|
||||||
is.read(buffer);
|
|
||||||
|
|
||||||
changes = new String(buffer);
|
|
||||||
} catch (IOException ignored) {
|
|
||||||
}
|
|
||||||
|
|
||||||
appChangelog.removeSummary();
|
|
||||||
if (changes == null) {
|
|
||||||
appChangelog.setVisibility(View.GONE);
|
|
||||||
} else {
|
|
||||||
Spanned result;
|
|
||||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
|
|
||||||
result = Html.fromHtml(changes, Html.TO_HTML_PARAGRAPH_LINES_CONSECUTIVE);
|
|
||||||
} else {
|
|
||||||
result = Html.fromHtml(changes);
|
|
||||||
}
|
|
||||||
appChangelog.setOnClickListener(v -> {
|
|
||||||
AlertDialog d = new AlertDialogBuilder(this)
|
|
||||||
.setTitle(R.string.app_changelog)
|
|
||||||
.setMessage(result)
|
|
||||||
.setPositiveButton(android.R.string.ok, null)
|
|
||||||
.show();
|
|
||||||
|
|
||||||
//noinspection ConstantConditions
|
|
||||||
((TextView) d.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
appDevelopers.removeSummary();
|
|
||||||
appDevelopers.setOnClickListener(view -> {
|
|
||||||
Spanned result;
|
|
||||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
|
|
||||||
result = Html.fromHtml(getString(R.string.app_developers_), Html.TO_HTML_PARAGRAPH_LINES_CONSECUTIVE);
|
|
||||||
} else {
|
|
||||||
result = Html.fromHtml(getString(R.string.app_developers_));
|
|
||||||
}
|
|
||||||
AlertDialog d = new AlertDialogBuilder(this)
|
|
||||||
.setTitle(R.string.app_developers)
|
|
||||||
.setMessage(result)
|
|
||||||
.setPositiveButton(android.R.string.ok, null)
|
|
||||||
.create();
|
|
||||||
|
|
||||||
d.show();
|
|
||||||
//noinspection ConstantConditions
|
|
||||||
((TextView) d.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
|
|
||||||
});
|
|
||||||
|
|
||||||
String translators = getString(R.string.translators);
|
|
||||||
if (TextUtils.isEmpty(translators)) {
|
|
||||||
appTranslators.setVisibility(View.GONE);
|
|
||||||
} else {
|
|
||||||
appTranslators.setSummary(translators);
|
|
||||||
}
|
|
||||||
|
|
||||||
appSourceCode.removeSummary();
|
|
||||||
appSourceCode.setOnClickListener(view -> startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(SOURCE_CODE_URL))));
|
|
||||||
|
|
||||||
supportThread.removeSummary();
|
|
||||||
supportThread.setOnClickListener(view -> startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(XDA_THREAD))));
|
|
||||||
|
|
||||||
donation.removeSummary();
|
|
||||||
donation.setOnClickListener(view -> startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(DONATION_URL))));
|
|
||||||
|
|
||||||
setFloating();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,153 +0,0 @@
|
|||||||
package com.topjohnwu.magisk;
|
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
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;
|
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.LinearLayout;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import com.topjohnwu.magisk.asyncs.FlashZip;
|
|
||||||
import com.topjohnwu.magisk.asyncs.InstallMagisk;
|
|
||||||
import com.topjohnwu.magisk.components.Activity;
|
|
||||||
import com.topjohnwu.magisk.container.AdaptiveList;
|
|
||||||
import com.topjohnwu.magisk.utils.Shell;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import butterknife.BindView;
|
|
||||||
import butterknife.ButterKnife;
|
|
||||||
import butterknife.OnClick;
|
|
||||||
|
|
||||||
public class FlashActivity extends Activity {
|
|
||||||
|
|
||||||
public static final String SET_ACTION = "action";
|
|
||||||
public static final String SET_BOOT = "boot";
|
|
||||||
public static final String SET_ENC = "enc";
|
|
||||||
public static final String SET_VERITY = "verity";
|
|
||||||
|
|
||||||
public static final String FLASH_ZIP = "flash";
|
|
||||||
public static final String PATCH_BOOT = "patch";
|
|
||||||
public static final String FLASH_MAGISK = "magisk";
|
|
||||||
|
|
||||||
@BindView(R.id.toolbar) Toolbar toolbar;
|
|
||||||
@BindView(R.id.flash_logs) RecyclerView flashLogs;
|
|
||||||
@BindView(R.id.button_panel) LinearLayout buttonPanel;
|
|
||||||
@BindView(R.id.reboot) Button reboot;
|
|
||||||
|
|
||||||
@OnClick(R.id.no_thanks)
|
|
||||||
public void dismiss() {
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnClick(R.id.reboot)
|
|
||||||
public void reboot() {
|
|
||||||
getShell().su_raw("reboot");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
setContentView(R.layout.activity_flash);
|
|
||||||
ButterKnife.bind(this);
|
|
||||||
AdaptiveList<String> rootShellOutput = new AdaptiveList<>(flashLogs);
|
|
||||||
setSupportActionBar(toolbar);
|
|
||||||
ActionBar ab = getSupportActionBar();
|
|
||||||
if (ab != null) {
|
|
||||||
ab.setTitle(R.string.flashing);
|
|
||||||
}
|
|
||||||
setFloating();
|
|
||||||
setFinishOnTouchOutside(false);
|
|
||||||
if (!Shell.rootAccess())
|
|
||||||
reboot.setVisibility(View.GONE);
|
|
||||||
|
|
||||||
flashLogs.setAdapter(new FlashLogAdapter(rootShellOutput));
|
|
||||||
|
|
||||||
// We must receive a Uri of the target zip
|
|
||||||
Intent intent = getIntent();
|
|
||||||
Uri uri = intent.getData();
|
|
||||||
|
|
||||||
boolean keepEnc = intent.getBooleanExtra(SET_ENC, false);
|
|
||||||
boolean keepVerity = intent.getBooleanExtra(SET_VERITY, false);
|
|
||||||
|
|
||||||
switch (getIntent().getStringExtra(SET_ACTION)) {
|
|
||||||
case FLASH_ZIP:
|
|
||||||
new FlashZip(this, uri, rootShellOutput)
|
|
||||||
.setCallBack(() -> buttonPanel.setVisibility(View.VISIBLE))
|
|
||||||
.exec();
|
|
||||||
break;
|
|
||||||
case PATCH_BOOT:
|
|
||||||
new InstallMagisk(this, rootShellOutput, uri, keepEnc, keepVerity, (Uri) intent.getParcelableExtra(SET_BOOT))
|
|
||||||
.setCallBack(() -> buttonPanel.setVisibility(View.VISIBLE))
|
|
||||||
.exec();
|
|
||||||
break;
|
|
||||||
case FLASH_MAGISK:
|
|
||||||
String boot = intent.getStringExtra(SET_BOOT);
|
|
||||||
if (getMagiskManager().remoteMagiskVersionCode < 1370) {
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBackPressed() {
|
|
||||||
// Prevent user accidentally press back button
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class FlashLogAdapter extends RecyclerView.Adapter<ViewHolder> {
|
|
||||||
|
|
||||||
private List<String> mList;
|
|
||||||
|
|
||||||
FlashLogAdapter(List<String> list) {
|
|
||||||
mList = list;
|
|
||||||
}
|
|
||||||
|
|
||||||
@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) {
|
|
||||||
holder.text.setText(mList.get(position));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getItemCount() {
|
|
||||||
return mList.size();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class ViewHolder extends RecyclerView.ViewHolder {
|
|
||||||
|
|
||||||
@BindView(R.id.textView) TextView text;
|
|
||||||
|
|
||||||
public ViewHolder(View itemView) {
|
|
||||||
super(itemView);
|
|
||||||
ButterKnife.bind(this, itemView);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,326 +0,0 @@
|
|||||||
package com.topjohnwu.magisk;
|
|
||||||
|
|
||||||
import android.app.Application;
|
|
||||||
import android.app.NotificationChannel;
|
|
||||||
import android.app.NotificationManager;
|
|
||||||
import android.app.job.JobInfo;
|
|
||||||
import android.app.job.JobScheduler;
|
|
||||||
import android.content.ComponentName;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.content.res.Configuration;
|
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import com.topjohnwu.magisk.asyncs.CheckUpdates;
|
|
||||||
import com.topjohnwu.magisk.asyncs.DownloadBusybox;
|
|
||||||
import com.topjohnwu.magisk.asyncs.LoadModules;
|
|
||||||
import com.topjohnwu.magisk.asyncs.ParallelTask;
|
|
||||||
import com.topjohnwu.magisk.asyncs.UpdateRepos;
|
|
||||||
import com.topjohnwu.magisk.container.Module;
|
|
||||||
import com.topjohnwu.magisk.database.RepoDatabaseHelper;
|
|
||||||
import com.topjohnwu.magisk.database.SuDatabaseHelper;
|
|
||||||
import com.topjohnwu.magisk.services.UpdateCheckService;
|
|
||||||
import com.topjohnwu.magisk.superuser.SuReceiver;
|
|
||||||
import com.topjohnwu.magisk.superuser.SuRequestActivity;
|
|
||||||
import com.topjohnwu.magisk.utils.Shell;
|
|
||||||
import com.topjohnwu.magisk.utils.Topic;
|
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
|
|
||||||
public class MagiskManager extends Application {
|
|
||||||
|
|
||||||
public static final String MAGISK_DISABLE_FILE = "/cache/.disable_magisk";
|
|
||||||
public static final String MAGISK_HOST_FILE = "/magisk/.core/hosts";
|
|
||||||
public static final String TMP_FOLDER_PATH = "/dev/tmp";
|
|
||||||
public static final String MAGISK_PATH = "/magisk";
|
|
||||||
public static final String INTENT_SECTION = "section";
|
|
||||||
public static final String INTENT_VERSION = "version";
|
|
||||||
public static final String INTENT_LINK = "link";
|
|
||||||
public static final String MAGISKHIDE_PROP = "persist.magisk.hide";
|
|
||||||
public static final String DISABLE_INDICATION_PROP = "ro.magisk.disable";
|
|
||||||
public static final String NOTIFICATION_CHANNEL = "magisk_update_notice";
|
|
||||||
public static final String BUSYBOXPATH = "/dev/magisk/bin";
|
|
||||||
public static final int UPDATE_SERVICE_ID = 1;
|
|
||||||
|
|
||||||
// Topics
|
|
||||||
public final Topic magiskHideDone = new Topic();
|
|
||||||
public final Topic reloadActivity = new Topic();
|
|
||||||
public final Topic moduleLoadDone = new Topic();
|
|
||||||
public final Topic repoLoadDone = new Topic();
|
|
||||||
public final Topic updateCheckDone = new Topic();
|
|
||||||
public final Topic safetyNetDone = new Topic();
|
|
||||||
public final Topic localeDone = new Topic();
|
|
||||||
|
|
||||||
// Info
|
|
||||||
public String magiskVersionString;
|
|
||||||
public int magiskVersionCode = -1;
|
|
||||||
public String remoteMagiskVersionString;
|
|
||||||
public int remoteMagiskVersionCode = -1;
|
|
||||||
public String magiskLink;
|
|
||||||
public String releaseNoteLink;
|
|
||||||
public String remoteManagerVersionString;
|
|
||||||
public int remoteManagerVersionCode = -1;
|
|
||||||
public String managerLink;
|
|
||||||
public String bootBlock = null;
|
|
||||||
public boolean isSuClient = false;
|
|
||||||
public String suVersion = null;
|
|
||||||
public boolean disabled;
|
|
||||||
|
|
||||||
// Data
|
|
||||||
public Map<String, Module> moduleMap;
|
|
||||||
public List<String> blockList;
|
|
||||||
public List<Locale> locales;
|
|
||||||
|
|
||||||
// Configurations
|
|
||||||
public static Locale locale;
|
|
||||||
public static Locale defaultLocale;
|
|
||||||
|
|
||||||
public boolean magiskHide;
|
|
||||||
public boolean isDarkTheme;
|
|
||||||
public boolean updateNotification;
|
|
||||||
public boolean suReauth;
|
|
||||||
public int suRequestTimeout;
|
|
||||||
public int suLogTimeout = 14;
|
|
||||||
public int suAccessState;
|
|
||||||
public int multiuserMode;
|
|
||||||
public int suResponseType;
|
|
||||||
public int suNotificationType;
|
|
||||||
public int suNamespaceMode;
|
|
||||||
public String localeConfig;
|
|
||||||
public int updateChannel;
|
|
||||||
public String bootFormat;
|
|
||||||
public int snet_version;
|
|
||||||
|
|
||||||
// Global resources
|
|
||||||
public SharedPreferences prefs;
|
|
||||||
public SuDatabaseHelper suDB;
|
|
||||||
public RepoDatabaseHelper repoDB;
|
|
||||||
public Shell shell;
|
|
||||||
|
|
||||||
private static Handler mHandler = new Handler();
|
|
||||||
private boolean started = false;
|
|
||||||
|
|
||||||
private static class LoadLocale extends ParallelTask<Void, Void, Void> {
|
|
||||||
|
|
||||||
LoadLocale(Context context) {
|
|
||||||
super(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Void doInBackground(Void... voids) {
|
|
||||||
getMagiskManager().locales = Utils.getAvailableLocale(getMagiskManager());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPostExecute(Void aVoid) {
|
|
||||||
getMagiskManager().localeDone.publish();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate() {
|
|
||||||
super.onCreate();
|
|
||||||
prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
|
||||||
|
|
||||||
if (getDatabasePath(SuDatabaseHelper.DB_NAME).exists()) {
|
|
||||||
// Don't migrate yet, wait and check Magisk version
|
|
||||||
suDB = new SuDatabaseHelper(this);
|
|
||||||
} else {
|
|
||||||
suDB = new SuDatabaseHelper(Utils.getEncContext(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
repoDB = new RepoDatabaseHelper(this);
|
|
||||||
defaultLocale = Locale.getDefault();
|
|
||||||
setLocale();
|
|
||||||
loadConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLocale() {
|
|
||||||
localeConfig = prefs.getString("locale", "");
|
|
||||||
if (localeConfig.isEmpty()) {
|
|
||||||
locale = defaultLocale;
|
|
||||||
} else {
|
|
||||||
locale = Locale.forLanguageTag(localeConfig);
|
|
||||||
}
|
|
||||||
Resources res = getBaseContext().getResources();
|
|
||||||
Configuration config = new Configuration(res.getConfiguration());
|
|
||||||
config.setLocale(locale);
|
|
||||||
res.updateConfiguration(config, res.getDisplayMetrics());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void loadConfig() {
|
|
||||||
isDarkTheme = prefs.getBoolean("dark_theme", false);
|
|
||||||
|
|
||||||
// su
|
|
||||||
suRequestTimeout = Utils.getPrefsInt(prefs, "su_request_timeout", 10);
|
|
||||||
suResponseType = Utils.getPrefsInt(prefs, "su_auto_response", SuRequestActivity.PROMPT);
|
|
||||||
suNotificationType = Utils.getPrefsInt(prefs, "su_notification", SuReceiver.TOAST);
|
|
||||||
suReauth = prefs.getBoolean("su_reauth", false);
|
|
||||||
suAccessState = suDB.getSettings(SuDatabaseHelper.ROOT_ACCESS, SuDatabaseHelper.ROOT_ACCESS_APPS_AND_ADB);
|
|
||||||
multiuserMode = suDB.getSettings(SuDatabaseHelper.MULTIUSER_MODE, SuDatabaseHelper.MULTIUSER_MODE_OWNER_ONLY);
|
|
||||||
suNamespaceMode = suDB.getSettings(SuDatabaseHelper.MNT_NS, SuDatabaseHelper.NAMESPACE_MODE_REQUESTER);
|
|
||||||
|
|
||||||
updateNotification = prefs.getBoolean("notification", true);
|
|
||||||
updateChannel = Utils.getPrefsInt(prefs, "update_channel", CheckUpdates.STABLE_CHANNEL);
|
|
||||||
bootFormat = prefs.getString("boot_format", ".img");
|
|
||||||
snet_version = prefs.getInt("snet_version", -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void toast(String msg, int duration) {
|
|
||||||
mHandler.post(() -> Toast.makeText(this, msg, duration).show());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void toast(int resId, int duration) {
|
|
||||||
mHandler.post(() -> Toast.makeText(this, resId, duration).show());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void startup() {
|
|
||||||
if (started)
|
|
||||||
return;
|
|
||||||
started = true;
|
|
||||||
|
|
||||||
boolean hasNetwork = Utils.checkNetworkStatus(this);
|
|
||||||
|
|
||||||
getMagiskInfo();
|
|
||||||
|
|
||||||
// Check if we need to migrate suDB
|
|
||||||
if (getDatabasePath(SuDatabaseHelper.DB_NAME).exists() && Utils.useFDE(this)) {
|
|
||||||
if (magiskVersionCode >= 1410) {
|
|
||||||
suDB.close();
|
|
||||||
Context de = createDeviceProtectedStorageContext();
|
|
||||||
de.moveDatabaseFrom(this, SuDatabaseHelper.DB_NAME);
|
|
||||||
suDB = new SuDatabaseHelper(de);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
new LoadLocale(this).exec();
|
|
||||||
|
|
||||||
// Root actions
|
|
||||||
if (Shell.rootAccess()) {
|
|
||||||
if (hasNetwork && !Utils.itemExist(shell, BUSYBOXPATH + "/busybox")) {
|
|
||||||
try {
|
|
||||||
// Force synchronous, make sure we have busybox to use
|
|
||||||
new DownloadBusybox(this).exec().get();
|
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try (InputStream in = getAssets().open(Utils.UTIL_FUNCTIONS)) {
|
|
||||||
shell.loadInputStream(in);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
shell.su_raw(
|
|
||||||
"export PATH=" + BUSYBOXPATH + ":$PATH",
|
|
||||||
"mount_partitions",
|
|
||||||
"BOOTIMAGE=",
|
|
||||||
"find_boot_image",
|
|
||||||
"migrate_boot_backup"
|
|
||||||
);
|
|
||||||
|
|
||||||
List<String> res = shell.su("echo \"$BOOTIMAGE\"");
|
|
||||||
if (Utils.isValidShellResponse(res)) {
|
|
||||||
bootBlock = res.get(0);
|
|
||||||
} else {
|
|
||||||
blockList = shell.su("find /dev/block -type b | grep -vE 'dm|ram|loop'");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write back default values
|
|
||||||
prefs.edit()
|
|
||||||
.putBoolean("dark_theme", isDarkTheme)
|
|
||||||
.putBoolean("magiskhide", magiskHide)
|
|
||||||
.putBoolean("notification", updateNotification)
|
|
||||||
.putBoolean("hosts", Utils.itemExist(shell, MAGISK_HOST_FILE))
|
|
||||||
.putBoolean("disable", Utils.itemExist(shell, MAGISK_DISABLE_FILE))
|
|
||||||
.putBoolean("su_reauth", suReauth)
|
|
||||||
.putString("su_request_timeout", String.valueOf(suRequestTimeout))
|
|
||||||
.putString("su_auto_response", String.valueOf(suResponseType))
|
|
||||||
.putString("su_notification", String.valueOf(suNotificationType))
|
|
||||||
.putString("su_access", String.valueOf(suAccessState))
|
|
||||||
.putString("multiuser_mode", String.valueOf(multiuserMode))
|
|
||||||
.putString("mnt_ns", String.valueOf(suNamespaceMode))
|
|
||||||
.putString("update_channel", String.valueOf(updateChannel))
|
|
||||||
.putString("locale", localeConfig)
|
|
||||||
.putString("boot_format", bootFormat)
|
|
||||||
.apply();
|
|
||||||
|
|
||||||
// Create notification channel on Android O
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
||||||
NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL,
|
|
||||||
getString(R.string.magisk_updates), NotificationManager.IMPORTANCE_DEFAULT);
|
|
||||||
getSystemService(NotificationManager.class).createNotificationChannel(channel);
|
|
||||||
}
|
|
||||||
|
|
||||||
LoadModules loadModuleTask = new LoadModules(this);
|
|
||||||
// Start update check job
|
|
||||||
if (hasNetwork) {
|
|
||||||
ComponentName service = new ComponentName(this, UpdateCheckService.class);
|
|
||||||
JobInfo jobInfo = new JobInfo.Builder(UPDATE_SERVICE_ID, service)
|
|
||||||
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
|
|
||||||
.setPersisted(true)
|
|
||||||
.setPeriodic(8 * 60 * 60 * 1000)
|
|
||||||
.build();
|
|
||||||
((JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE)).schedule(jobInfo);
|
|
||||||
loadModuleTask.setCallBack(() -> new UpdateRepos(this, false).exec());
|
|
||||||
}
|
|
||||||
// Fire asynctasks
|
|
||||||
loadModuleTask.exec();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void getMagiskInfo() {
|
|
||||||
List<String> ret;
|
|
||||||
Shell.getShell(this);
|
|
||||||
ret = shell.sh("su -v");
|
|
||||||
if (Utils.isValidShellResponse(ret)) {
|
|
||||||
suVersion = ret.get(0);
|
|
||||||
isSuClient = suVersion.toUpperCase().contains("MAGISK");
|
|
||||||
}
|
|
||||||
ret = shell.sh("magisk -v");
|
|
||||||
if (!Utils.isValidShellResponse(ret)) {
|
|
||||||
ret = shell.sh("getprop magisk.version");
|
|
||||||
if (Utils.isValidShellResponse(ret)) {
|
|
||||||
try {
|
|
||||||
magiskVersionString = ret.get(0);
|
|
||||||
magiskVersionCode = (int) Double.parseDouble(ret.get(0)) * 10;
|
|
||||||
} catch (NumberFormatException ignored) {}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
magiskVersionString = ret.get(0).split(":")[0];
|
|
||||||
ret = shell.sh("magisk -V");
|
|
||||||
try {
|
|
||||||
magiskVersionCode = Integer.parseInt(ret.get(0));
|
|
||||||
} catch (NumberFormatException ignored) {}
|
|
||||||
}
|
|
||||||
ret = shell.sh("getprop " + DISABLE_INDICATION_PROP);
|
|
||||||
try {
|
|
||||||
disabled = Utils.isValidShellResponse(ret) && Integer.parseInt(ret.get(0)) != 0;
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
disabled = false;
|
|
||||||
}
|
|
||||||
if (magiskVersionCode > 1435) {
|
|
||||||
ret = shell.su("resetprop -p " + MAGISKHIDE_PROP);
|
|
||||||
} else {
|
|
||||||
ret = shell.sh("getprop " + MAGISKHIDE_PROP);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
magiskHide = !Utils.isValidShellResponse(ret) || Integer.parseInt(ret.get(0)) != 0;
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
magiskHide = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,24 +0,0 @@
|
|||||||
package com.topjohnwu.magisk;
|
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Bundle;
|
|
||||||
|
|
||||||
import com.topjohnwu.magisk.components.Activity;
|
|
||||||
|
|
||||||
public class SplashActivity extends Activity {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
|
|
||||||
getMagiskManager().startup();
|
|
||||||
|
|
||||||
Intent intent = new Intent(this, MainActivity.class);
|
|
||||||
String section = getIntent().getStringExtra(MagiskManager.INTENT_SECTION);
|
|
||||||
if (section != null) {
|
|
||||||
intent.putExtra(MagiskManager.INTENT_SECTION, section);
|
|
||||||
}
|
|
||||||
startActivity(intent);
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,84 +0,0 @@
|
|||||||
package com.topjohnwu.magisk.asyncs;
|
|
||||||
|
|
||||||
import android.support.v4.app.FragmentActivity;
|
|
||||||
|
|
||||||
import com.topjohnwu.jarsigner.ByteArrayStream;
|
|
||||||
import com.topjohnwu.magisk.MagiskManager;
|
|
||||||
import com.topjohnwu.magisk.utils.WebService;
|
|
||||||
|
|
||||||
import java.io.BufferedOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.lang.reflect.Proxy;
|
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
|
|
||||||
import dalvik.system.DexClassLoader;
|
|
||||||
|
|
||||||
public class CheckSafetyNet extends ParallelTask<Void, Void, Exception> {
|
|
||||||
|
|
||||||
public static final int SNET_VER = 2;
|
|
||||||
|
|
||||||
private static final String SNET_URL = "https://github.com/topjohnwu/MagiskManager/releases/download/v5.4.0/snet.apk";
|
|
||||||
private static final String PKG = "com.topjohnwu.snet";
|
|
||||||
|
|
||||||
private File dexPath;
|
|
||||||
private DexClassLoader loader;
|
|
||||||
|
|
||||||
public CheckSafetyNet(FragmentActivity activity) {
|
|
||||||
super(activity);
|
|
||||||
dexPath = new File(activity.getCacheDir().getParent() + "/snet", "snet.apk");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPreExecute() {
|
|
||||||
MagiskManager mm = getMagiskManager();
|
|
||||||
if (mm.snet_version != CheckSafetyNet.SNET_VER) {
|
|
||||||
getShell().sh("rm -rf " + dexPath.getParent());
|
|
||||||
}
|
|
||||||
mm.snet_version = CheckSafetyNet.SNET_VER;
|
|
||||||
mm.prefs.edit().putInt("snet_version", CheckSafetyNet.SNET_VER).apply();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Exception doInBackground(Void... voids) {
|
|
||||||
try {
|
|
||||||
if (!dexPath.exists()) {
|
|
||||||
HttpURLConnection conn = WebService.request(SNET_URL, null);
|
|
||||||
ByteArrayStream bas = new ByteArrayStream();
|
|
||||||
bas.readFrom(conn.getInputStream());
|
|
||||||
conn.disconnect();
|
|
||||||
dexPath.getParentFile().mkdir();
|
|
||||||
try (OutputStream out = new BufferedOutputStream(new FileOutputStream(dexPath))) {
|
|
||||||
bas.writeTo(out);
|
|
||||||
out.flush();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
loader = new DexClassLoader(dexPath.toString(), dexPath.getParent(),
|
|
||||||
null, ClassLoader.getSystemClassLoader());
|
|
||||||
} catch (Exception e) {
|
|
||||||
return e;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPostExecute(Exception err) {
|
|
||||||
try {
|
|
||||||
if (err != null) throw err;
|
|
||||||
Class<?> helperClazz = loader.loadClass(PKG + ".SafetyNetHelper");
|
|
||||||
Class<?> callbackClazz = loader.loadClass(PKG + ".SafetyNetCallback");
|
|
||||||
Object helper = helperClazz.getConstructors()[0].newInstance(
|
|
||||||
getActivity(), Proxy.newProxyInstance(
|
|
||||||
loader, new Class[] { callbackClazz }, (proxy, method, args) -> {
|
|
||||||
getMagiskManager().safetyNetDone.publish(false, args[0]);
|
|
||||||
return null;
|
|
||||||
}));
|
|
||||||
helperClazz.getMethod("attest").invoke(helper);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
getMagiskManager().safetyNetDone.publish(false, -1);
|
|
||||||
}
|
|
||||||
super.onPostExecute(err);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,64 +0,0 @@
|
|||||||
package com.topjohnwu.magisk.asyncs;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Build;
|
|
||||||
|
|
||||||
import com.topjohnwu.magisk.MagiskManager;
|
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
|
||||||
import com.topjohnwu.magisk.utils.WebService;
|
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
|
|
||||||
public class DownloadBusybox extends ParallelTask<Void, Void, Void> {
|
|
||||||
|
|
||||||
private static final String BUSYBOX_ARM = "https://github.com/topjohnwu/ndk-busybox/releases/download/1.27.2/busybox-arm";
|
|
||||||
private static final String BUSYBOX_X86 = "https://github.com/topjohnwu/ndk-busybox/releases/download/1.27.2/busybox-x86";
|
|
||||||
|
|
||||||
private File busybox;
|
|
||||||
|
|
||||||
public DownloadBusybox(Context context) {
|
|
||||||
super(context);
|
|
||||||
busybox = new File(context.getCacheDir(), "busybox");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Void doInBackground(Void... voids) {
|
|
||||||
Context context = getMagiskManager();
|
|
||||||
Utils.removeItem(getShell(), context.getApplicationInfo().dataDir + "/busybox");
|
|
||||||
try {
|
|
||||||
FileOutputStream out = new FileOutputStream(busybox);
|
|
||||||
HttpURLConnection conn = WebService.request(
|
|
||||||
Build.SUPPORTED_32_BIT_ABIS[0].contains("x86") ?
|
|
||||||
BUSYBOX_X86 :
|
|
||||||
BUSYBOX_ARM,
|
|
||||||
null
|
|
||||||
);
|
|
||||||
if (conn == null) throw new IOException();
|
|
||||||
BufferedInputStream bis = new BufferedInputStream(conn.getInputStream());
|
|
||||||
byte[] buffer = new byte[4096];
|
|
||||||
int len;
|
|
||||||
while ((len = bis.read(buffer)) != -1) {
|
|
||||||
out.write(buffer, 0, len);
|
|
||||||
}
|
|
||||||
out.close();
|
|
||||||
conn.disconnect();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
if (busybox.exists()) {
|
|
||||||
getShell().su(
|
|
||||||
"rm -rf " + MagiskManager.BUSYBOXPATH,
|
|
||||||
"mkdir -p " + MagiskManager.BUSYBOXPATH,
|
|
||||||
"cp " + busybox + " " + MagiskManager.BUSYBOXPATH,
|
|
||||||
"chmod -R 755 " + MagiskManager.BUSYBOXPATH,
|
|
||||||
MagiskManager.BUSYBOXPATH + "/busybox --install -s " + MagiskManager.BUSYBOXPATH
|
|
||||||
);
|
|
||||||
busybox.delete();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,115 +0,0 @@
|
|||||||
package com.topjohnwu.magisk.asyncs;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.os.Environment;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import com.topjohnwu.jarsigner.JarMap;
|
|
||||||
import com.topjohnwu.magisk.MagiskManager;
|
|
||||||
import com.topjohnwu.magisk.R;
|
|
||||||
import com.topjohnwu.magisk.container.Policy;
|
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
|
||||||
import com.topjohnwu.magisk.utils.ZipUtils;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.jar.JarEntry;
|
|
||||||
|
|
||||||
public class HideManager extends ParallelTask<Void, Void, Boolean> {
|
|
||||||
|
|
||||||
private static final String UNHIDE_APK = "unhide.apk";
|
|
||||||
private static final String ANDROID_MANIFEST = "AndroidManifest.xml";
|
|
||||||
private static final byte[] UNHIDE_PKG_NAME = "com.topjohnwu.unhide\0".getBytes();
|
|
||||||
|
|
||||||
public HideManager(Context context) {
|
|
||||||
super(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPreExecute() {
|
|
||||||
getMagiskManager().toast(R.string.hide_manager_toast, Toast.LENGTH_SHORT);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Boolean doInBackground(Void... voids) {
|
|
||||||
MagiskManager mm = getMagiskManager();
|
|
||||||
if (mm == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// Generate a new unhide app with random package name
|
|
||||||
File unhideAPK = new File(Environment.getExternalStorageDirectory() + "/MagiskManager", "unhide.apk");
|
|
||||||
unhideAPK.getParentFile().mkdirs();
|
|
||||||
String pkg;
|
|
||||||
|
|
||||||
try {
|
|
||||||
JarMap asset = new JarMap(mm.getAssets().open(UNHIDE_APK));
|
|
||||||
JarEntry je = new JarEntry(ANDROID_MANIFEST);
|
|
||||||
byte xml[] = asset.getRawData(je);
|
|
||||||
int offset = -1;
|
|
||||||
|
|
||||||
// Linear search pattern offset
|
|
||||||
for (int i = 0; i < xml.length - UNHIDE_PKG_NAME.length; ++i) {
|
|
||||||
boolean match = true;
|
|
||||||
for (int j = 0; j < UNHIDE_PKG_NAME.length; ++j) {
|
|
||||||
if (xml[i + j] != UNHIDE_PKG_NAME[j]) {
|
|
||||||
match = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (match) {
|
|
||||||
offset = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (offset < 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// Patch binary XML with new package name
|
|
||||||
pkg = Utils.genPackageName("com.", UNHIDE_PKG_NAME.length - 1);
|
|
||||||
System.arraycopy(pkg.getBytes(), 0, xml, offset, pkg.length());
|
|
||||||
asset.getOutputStream(je).write(xml);
|
|
||||||
|
|
||||||
// Sign the APK
|
|
||||||
ZipUtils.signZip(mm, asset, unhideAPK, false);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Install the application
|
|
||||||
List<String> ret = getShell().su("pm install " + unhideAPK + ">/dev/null && echo true || echo false");
|
|
||||||
unhideAPK.delete();
|
|
||||||
if (!Utils.isValidShellResponse(ret) || !Boolean.parseBoolean(ret.get(0)))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Allow the application to gain root by default
|
|
||||||
PackageManager pm = mm.getPackageManager();
|
|
||||||
int uid = pm.getApplicationInfo(pkg, 0).uid;
|
|
||||||
Policy policy = new Policy(uid, pm);
|
|
||||||
policy.policy = Policy.ALLOW;
|
|
||||||
policy.notification = false;
|
|
||||||
policy.logging = false;
|
|
||||||
mm.suDB.addPolicy(policy);
|
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hide myself!
|
|
||||||
getShell().su_raw("pm hide " + mm.getPackageName());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPostExecute(Boolean b) {
|
|
||||||
MagiskManager mm = getMagiskManager();
|
|
||||||
if (mm == null)
|
|
||||||
return;
|
|
||||||
if (!b) {
|
|
||||||
mm.toast(R.string.hide_manager_fail_toast, Toast.LENGTH_LONG);
|
|
||||||
}
|
|
||||||
super.onPostExecute(b);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,230 +0,0 @@
|
|||||||
package com.topjohnwu.magisk.asyncs;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Environment;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
|
|
||||||
import com.topjohnwu.magisk.MagiskManager;
|
|
||||||
import com.topjohnwu.magisk.container.AdaptiveList;
|
|
||||||
import com.topjohnwu.magisk.container.TarEntry;
|
|
||||||
import com.topjohnwu.magisk.utils.Shell;
|
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
|
||||||
import com.topjohnwu.magisk.utils.ZipUtils;
|
|
||||||
|
|
||||||
import org.kamranzafar.jtar.TarInputStream;
|
|
||||||
import org.kamranzafar.jtar.TarOutputStream;
|
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
|
||||||
import java.io.BufferedOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
|
|
||||||
|
|
||||||
private static final int PATCH_MODE = 0;
|
|
||||||
private static final int DIRECT_MODE = 1;
|
|
||||||
|
|
||||||
private Uri mBootImg, mZip;
|
|
||||||
private AdaptiveList<String> mList;
|
|
||||||
private String mBootLocation;
|
|
||||||
private boolean mKeepEnc, mKeepVerity;
|
|
||||||
private int mode;
|
|
||||||
|
|
||||||
private InstallMagisk(Activity context, AdaptiveList<String> list, Uri zip, boolean enc, boolean verity) {
|
|
||||||
super(context);
|
|
||||||
mList = list;
|
|
||||||
mZip = zip;
|
|
||||||
mKeepEnc = enc;
|
|
||||||
mKeepVerity = verity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public InstallMagisk(Activity context, AdaptiveList<String> list, Uri zip, boolean enc, boolean verity, Uri boot) {
|
|
||||||
this(context, list, zip, enc, verity);
|
|
||||||
mBootImg = boot;
|
|
||||||
mode = PATCH_MODE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public InstallMagisk(Activity context, AdaptiveList<String> list, Uri zip, boolean enc, boolean verity, String boot) {
|
|
||||||
this(context, list, zip, enc, verity);
|
|
||||||
mBootLocation = boot;
|
|
||||||
mode = DIRECT_MODE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPreExecute() {
|
|
||||||
// UI updates must run in the UI thread
|
|
||||||
mList.setCallback(this::publishProgress);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onProgressUpdate(Void... values) {
|
|
||||||
mList.updateView();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Boolean doInBackground(Void... voids) {
|
|
||||||
MagiskManager mm = getMagiskManager();
|
|
||||||
if (mm == null) return false;
|
|
||||||
|
|
||||||
File install = new File(Utils.getEncContext(mm).getFilesDir().getParent(), "install");
|
|
||||||
getShell().sh_raw("rm -rf " + install);
|
|
||||||
|
|
||||||
List<String> abis = Arrays.asList(Build.SUPPORTED_ABIS);
|
|
||||||
String arch;
|
|
||||||
if (abis.contains("x86_64")) arch = "x64";
|
|
||||||
else if (abis.contains("arm64-v8a")) arch = "arm64";
|
|
||||||
else if (abis.contains("x86")) arch = "x86";
|
|
||||||
else arch = "arm";
|
|
||||||
mList.add("- Device platform: " + arch);
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Unzip files
|
|
||||||
mList.add("- Extracting files");
|
|
||||||
try (InputStream in = mm.getContentResolver().openInputStream(mZip)) {
|
|
||||||
if (in == null) throw new FileNotFoundException();
|
|
||||||
BufferedInputStream buf = new BufferedInputStream(in);
|
|
||||||
buf.mark(Integer.MAX_VALUE);
|
|
||||||
ZipUtils.unzip(buf, install, arch + "/", true);
|
|
||||||
buf.reset();
|
|
||||||
ZipUtils.unzip(buf, install, "common/", true);
|
|
||||||
buf.reset();
|
|
||||||
ZipUtils.unzip(buf, install, "chromeos/", false);
|
|
||||||
buf.reset();
|
|
||||||
ZipUtils.unzip(buf, install, "META-INF/com/google/android/update-binary", true);
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
mList.add("! Invalid Uri");
|
|
||||||
throw e;
|
|
||||||
} catch (Exception e) {
|
|
||||||
mList.add("! Cannot unzip zip");
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
File boot;
|
|
||||||
switch (mode) {
|
|
||||||
case PATCH_MODE:
|
|
||||||
boot = new File(install, "boot.img");
|
|
||||||
// Copy boot image to local
|
|
||||||
try (
|
|
||||||
InputStream in = mm.getContentResolver().openInputStream(mBootImg);
|
|
||||||
OutputStream out = new FileOutputStream(boot)
|
|
||||||
) {
|
|
||||||
InputStream source;
|
|
||||||
if (in == null) throw new FileNotFoundException();
|
|
||||||
|
|
||||||
if (Utils.getNameFromUri(mm, mBootImg).endsWith(".tar")) {
|
|
||||||
// Extract boot.img from tar
|
|
||||||
TarInputStream tar = new TarInputStream(new BufferedInputStream(in));
|
|
||||||
org.kamranzafar.jtar.TarEntry entry;
|
|
||||||
while ((entry = tar.getNextEntry()) != null) {
|
|
||||||
if (entry.getName().equals("boot.img"))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
source = tar;
|
|
||||||
} else {
|
|
||||||
// Direct copy raw image
|
|
||||||
source = new BufferedInputStream(in);
|
|
||||||
}
|
|
||||||
byte buffer[] = new byte[1024];
|
|
||||||
int length;
|
|
||||||
while ((length = source.read(buffer)) > 0)
|
|
||||||
out.write(buffer, 0, length);
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
mList.add("! Invalid Uri");
|
|
||||||
throw e;
|
|
||||||
} catch (IOException e) {
|
|
||||||
mList.add("! Copy failed");
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case DIRECT_MODE:
|
|
||||||
boot = new File(mBootLocation);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
mList.add("- Use boot image: " + boot);
|
|
||||||
|
|
||||||
Shell shell;
|
|
||||||
if (mode == PATCH_MODE && Shell.rootAccess()) {
|
|
||||||
// Force non-root shell
|
|
||||||
shell = Shell.getShell("sh");
|
|
||||||
} else {
|
|
||||||
shell = getShell();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Patch boot image
|
|
||||||
shell.sh(mList,
|
|
||||||
"cd " + install,
|
|
||||||
"KEEPFORCEENCRYPT=" + mKeepEnc + " KEEPVERITY=" + mKeepVerity + " sh " +
|
|
||||||
"update-binary indep boot_patch.sh " + boot +
|
|
||||||
" && echo 'Success!' || echo 'Failed!'"
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!TextUtils.equals(mList.get(mList.size() - 1), "Success!"))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
File patched_boot = new File(install, "new-boot.img");
|
|
||||||
mList.add("");
|
|
||||||
switch (mode) {
|
|
||||||
case PATCH_MODE:
|
|
||||||
File dest = new File(Environment.getExternalStorageDirectory() + "/MagiskManager/patched_boot" + mm.bootFormat);
|
|
||||||
dest.getParentFile().mkdirs();
|
|
||||||
switch (mm.bootFormat) {
|
|
||||||
case ".img":
|
|
||||||
getShell().sh_raw("cp -f " + patched_boot + " " + dest);
|
|
||||||
break;
|
|
||||||
case ".img.tar":
|
|
||||||
TarOutputStream tar = new TarOutputStream(new BufferedOutputStream(new FileOutputStream(dest)));
|
|
||||||
tar.putNextEntry(new TarEntry(patched_boot, "boot.img"));
|
|
||||||
byte buffer[] = new byte[4096];
|
|
||||||
BufferedInputStream in = new BufferedInputStream(new FileInputStream(patched_boot));
|
|
||||||
int len;
|
|
||||||
while ((len = in.read(buffer)) != -1) {
|
|
||||||
tar.write(buffer, 0, len);
|
|
||||||
}
|
|
||||||
tar.flush();
|
|
||||||
tar.close();
|
|
||||||
in.close();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
mList.add("*********************************");
|
|
||||||
mList.add(" Patched Boot Image is placed in ");
|
|
||||||
mList.add(" " + dest + " ");
|
|
||||||
mList.add("*********************************");
|
|
||||||
break;
|
|
||||||
case DIRECT_MODE:
|
|
||||||
// Direct flash boot image
|
|
||||||
getShell().su(mList, "flash_boot_image " + patched_boot + " " + mBootLocation);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Finals
|
|
||||||
getShell().sh_raw(
|
|
||||||
"cd " + install,
|
|
||||||
"mv bin/busybox busybox",
|
|
||||||
"rm -rf bin *.img update-binary",
|
|
||||||
"cd /");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPostExecute(Boolean result) {
|
|
||||||
super.onPostExecute(result);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,47 +0,0 @@
|
|||||||
package com.topjohnwu.magisk.asyncs;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.support.v7.app.AlertDialog;
|
|
||||||
import android.webkit.WebView;
|
|
||||||
|
|
||||||
import com.topjohnwu.magisk.R;
|
|
||||||
import com.topjohnwu.magisk.utils.WebService;
|
|
||||||
|
|
||||||
import org.commonmark.node.Node;
|
|
||||||
import org.commonmark.parser.Parser;
|
|
||||||
import org.commonmark.renderer.html.HtmlRenderer;
|
|
||||||
|
|
||||||
public class MarkDownWindow extends ParallelTask<Void, Void, String> {
|
|
||||||
|
|
||||||
private String mTitle, mUrl;
|
|
||||||
|
|
||||||
public MarkDownWindow(Activity context, String title, String url) {
|
|
||||||
super(context);
|
|
||||||
mTitle = title;
|
|
||||||
mUrl = url;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String doInBackground(Void... voids) {
|
|
||||||
String md = WebService.getString(mUrl);
|
|
||||||
Parser parser = Parser.builder().build();
|
|
||||||
HtmlRenderer renderer = HtmlRenderer.builder().build();
|
|
||||||
Node doc = parser.parse(md);
|
|
||||||
return String.format(
|
|
||||||
"<link rel='stylesheet' type='text/css' href='file:///android_asset/%s.css'/> %s",
|
|
||||||
getMagiskManager().isDarkTheme ? "dark" : "light", renderer.render(doc));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPostExecute(String html) {
|
|
||||||
AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
|
|
||||||
alert.setTitle(mTitle);
|
|
||||||
|
|
||||||
WebView wv = new WebView(getActivity());
|
|
||||||
wv.loadDataWithBaseURL("fake://", html, "text/html", "UTF-8", null);
|
|
||||||
|
|
||||||
alert.setView(wv);
|
|
||||||
alert.setNegativeButton(R.string.close, (dialog, id) -> dialog.dismiss());
|
|
||||||
alert.show();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,40 +0,0 @@
|
|||||||
package com.topjohnwu.magisk.asyncs;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import com.topjohnwu.magisk.R;
|
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class RestoreStockBoot extends ParallelTask<Void, Void, Boolean> {
|
|
||||||
|
|
||||||
private String mBoot;
|
|
||||||
|
|
||||||
public RestoreStockBoot(Context context, String boot) {
|
|
||||||
super(context);
|
|
||||||
mBoot = boot;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Boolean doInBackground(Void... voids) {
|
|
||||||
List<String> ret = getShell().su("cat /init.magisk.rc | grep STOCKSHA1");
|
|
||||||
if (!Utils.isValidShellResponse(ret))
|
|
||||||
return false;
|
|
||||||
String stock_boot = "/data/stock_boot_" + ret.get(0).substring(ret.get(0).indexOf('=') + 1) + ".img.gz";
|
|
||||||
if (!Utils.itemExist(getShell(), stock_boot))
|
|
||||||
return false;
|
|
||||||
getShell().su_raw("flash_boot_image " + stock_boot + " " + mBoot);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPostExecute(Boolean result) {
|
|
||||||
if (result) {
|
|
||||||
getMagiskManager().toast(R.string.restore_done, Toast.LENGTH_SHORT);
|
|
||||||
} else {
|
|
||||||
getMagiskManager().toast(R.string.restore_fail, Toast.LENGTH_LONG);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,79 +0,0 @@
|
|||||||
package com.topjohnwu.magisk.components;
|
|
||||||
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.content.res.Configuration;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.support.annotation.NonNull;
|
|
||||||
import android.support.annotation.Nullable;
|
|
||||||
import android.support.v7.app.AppCompatActivity;
|
|
||||||
import android.view.WindowManager;
|
|
||||||
|
|
||||||
import com.topjohnwu.magisk.MagiskManager;
|
|
||||||
import com.topjohnwu.magisk.R;
|
|
||||||
import com.topjohnwu.magisk.utils.Shell;
|
|
||||||
import com.topjohnwu.magisk.utils.Topic;
|
|
||||||
|
|
||||||
public class Activity extends AppCompatActivity {
|
|
||||||
|
|
||||||
private Runnable permissionGrantCallback;
|
|
||||||
|
|
||||||
public Activity() {
|
|
||||||
super();
|
|
||||||
Configuration configuration = new Configuration();
|
|
||||||
configuration.setLocale(MagiskManager.locale);
|
|
||||||
applyOverrideConfiguration(configuration);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
if (this instanceof Topic.Subscriber) {
|
|
||||||
((Topic.Subscriber) this).subscribeTopics();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDestroy() {
|
|
||||||
if (this instanceof Topic.Subscriber) {
|
|
||||||
((Topic.Subscriber) this).unsubscribeTopics();
|
|
||||||
}
|
|
||||||
super.onDestroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
|
||||||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
|
||||||
if (permissionGrantCallback != null) {
|
|
||||||
permissionGrantCallback.run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
permissionGrantCallback = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPermissionGrantCallback(Runnable callback) {
|
|
||||||
permissionGrantCallback = callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MagiskManager getMagiskManager() {
|
|
||||||
return (MagiskManager) super.getApplicationContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Shell getShell() {
|
|
||||||
return Shell.getShell(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setFloating() {
|
|
||||||
boolean isTablet = getResources().getBoolean(R.bool.isTablet);
|
|
||||||
if (isTablet) {
|
|
||||||
WindowManager.LayoutParams params = getWindow().getAttributes();
|
|
||||||
params.height = getResources().getDimensionPixelSize(R.dimen.floating_height);
|
|
||||||
params.width = getResources().getDimensionPixelSize(R.dimen.floating_width);
|
|
||||||
params.alpha = 1.0f;
|
|
||||||
params.dimAmount = 0.6f;
|
|
||||||
params.flags |= 2;
|
|
||||||
getWindow().setAttributes(params);
|
|
||||||
setFinishOnTouchOutside(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,36 +0,0 @@
|
|||||||
package com.topjohnwu.magisk.container;
|
|
||||||
|
|
||||||
import android.support.v7.widget.RecyclerView;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
public class AdaptiveList<E> extends ArrayList<E> {
|
|
||||||
|
|
||||||
private Runnable callback;
|
|
||||||
private RecyclerView mView;
|
|
||||||
|
|
||||||
public AdaptiveList(RecyclerView v) {
|
|
||||||
mView = v;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateView() {
|
|
||||||
mView.getAdapter().notifyDataSetChanged();
|
|
||||||
mView.scrollToPosition(mView.getAdapter().getItemCount() - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCallback(Runnable cb) {
|
|
||||||
callback = cb;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean add(E e) {
|
|
||||||
boolean ret = super.add(e);
|
|
||||||
if (ret) {
|
|
||||||
if (callback == null) {
|
|
||||||
updateView();
|
|
||||||
} else {
|
|
||||||
callback.run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,59 +0,0 @@
|
|||||||
package com.topjohnwu.magisk.container;
|
|
||||||
|
|
||||||
import android.support.annotation.NonNull;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
|
|
||||||
public class InputStreamWrapper extends InputStream {
|
|
||||||
private InputStream in;
|
|
||||||
|
|
||||||
public InputStreamWrapper(InputStream in) {
|
|
||||||
this.in = in;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int available() throws IOException {
|
|
||||||
return in.available();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() throws IOException {
|
|
||||||
in.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public synchronized void mark(int readlimit) {
|
|
||||||
in.mark(readlimit);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean markSupported() {
|
|
||||||
return in.markSupported();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public synchronized int read() throws IOException {
|
|
||||||
return in.read();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int read(@NonNull byte[] b) throws IOException {
|
|
||||||
return read(b, 0, b.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public synchronized int read(@NonNull byte[] b, int off, int len) throws IOException {
|
|
||||||
return in.read(b, off, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public synchronized void reset() throws IOException {
|
|
||||||
in.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long skip(long n) throws IOException {
|
|
||||||
return in.skip(n);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,265 +0,0 @@
|
|||||||
package com.topjohnwu.magisk.database;
|
|
||||||
|
|
||||||
import android.content.ContentValues;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.database.Cursor;
|
|
||||||
import android.database.DatabaseUtils;
|
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
|
||||||
import android.database.sqlite.SQLiteOpenHelper;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
|
|
||||||
import com.topjohnwu.magisk.MagiskManager;
|
|
||||||
import com.topjohnwu.magisk.container.Policy;
|
|
||||||
import com.topjohnwu.magisk.container.SuLogEntry;
|
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.text.DateFormat;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class SuDatabaseHelper extends SQLiteOpenHelper {
|
|
||||||
|
|
||||||
public static final String ROOT_ACCESS = "root_access";
|
|
||||||
public static final int ROOT_ACCESS_DISABLED = 0;
|
|
||||||
public static final int ROOT_ACCESS_APPS_ONLY = 1;
|
|
||||||
public static final int ROOT_ACCESS_ADB_ONLY = 2;
|
|
||||||
public static final int ROOT_ACCESS_APPS_AND_ADB = 3;
|
|
||||||
|
|
||||||
public static final String MULTIUSER_MODE = "multiuser_mode";
|
|
||||||
public static final int MULTIUSER_MODE_OWNER_ONLY = 0;
|
|
||||||
public static final int MULTIUSER_MODE_OWNER_MANAGED = 1;
|
|
||||||
public static final int MULTIUSER_MODE_USER = 2;
|
|
||||||
|
|
||||||
public static final String MNT_NS = "mnt_ns";
|
|
||||||
public static final int NAMESPACE_MODE_GLOBAL = 0;
|
|
||||||
public static final int NAMESPACE_MODE_REQUESTER = 1;
|
|
||||||
public static final int NAMESPACE_MODE_ISOLATE = 2;
|
|
||||||
|
|
||||||
public static final String DB_NAME = "su.db";
|
|
||||||
private static final int DATABASE_VER = 3;
|
|
||||||
private static final String POLICY_TABLE = "policies";
|
|
||||||
private static final String LOG_TABLE = "logs";
|
|
||||||
private static final String SETTINGS_TABLE = "settings";
|
|
||||||
|
|
||||||
private MagiskManager mm;
|
|
||||||
private PackageManager pm;
|
|
||||||
private SQLiteDatabase mDb;
|
|
||||||
|
|
||||||
public SuDatabaseHelper(Context context) {
|
|
||||||
super(context, DB_NAME, null, DATABASE_VER);
|
|
||||||
mm = Utils.getMagiskManager(context);
|
|
||||||
pm = context.getPackageManager();
|
|
||||||
mDb = getWritableDatabase();
|
|
||||||
cleanup();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(SQLiteDatabase db) {
|
|
||||||
onUpgrade(db, 0, DATABASE_VER);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
|
||||||
if (oldVersion == 0) {
|
|
||||||
createTables(db);
|
|
||||||
oldVersion = 2;
|
|
||||||
}
|
|
||||||
if (oldVersion == 1) {
|
|
||||||
// We're dropping column app_name, rename and re-construct table
|
|
||||||
db.execSQL("ALTER TABLE " + POLICY_TABLE + " RENAME TO " + POLICY_TABLE + "_old");
|
|
||||||
|
|
||||||
// Create the new tables
|
|
||||||
createTables(db);
|
|
||||||
|
|
||||||
// Migrate old data to new tables
|
|
||||||
db.execSQL(
|
|
||||||
"INSERT INTO " + POLICY_TABLE + " SELECT " +
|
|
||||||
"uid, package_name, policy, until, logging, notification " +
|
|
||||||
"FROM " + POLICY_TABLE + "_old");
|
|
||||||
db.execSQL("DROP TABLE " + POLICY_TABLE + "_old");
|
|
||||||
|
|
||||||
File oldDB = mm.getDatabasePath("sulog.db");
|
|
||||||
if (oldDB.exists()) {
|
|
||||||
migrateLegacyLogList(oldDB, db);
|
|
||||||
mm.deleteDatabase("sulog.db");
|
|
||||||
}
|
|
||||||
++oldVersion;
|
|
||||||
}
|
|
||||||
if (oldVersion == 2) {
|
|
||||||
db.execSQL("UPDATE " + LOG_TABLE + " SET time=time*1000");
|
|
||||||
++oldVersion;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createTables(SQLiteDatabase db) {
|
|
||||||
// Policies
|
|
||||||
db.execSQL(
|
|
||||||
"CREATE TABLE IF NOT EXISTS " + POLICY_TABLE + " " +
|
|
||||||
"(uid INT, package_name TEXT, policy INT, " +
|
|
||||||
"until INT, logging INT, notification INT, " +
|
|
||||||
"PRIMARY KEY(uid))");
|
|
||||||
|
|
||||||
// Logs
|
|
||||||
db.execSQL(
|
|
||||||
"CREATE TABLE IF NOT EXISTS " + LOG_TABLE + " " +
|
|
||||||
"(from_uid INT, package_name TEXT, app_name TEXT, from_pid INT, " +
|
|
||||||
"to_uid INT, action INT, time INT, command TEXT)");
|
|
||||||
|
|
||||||
// Settings
|
|
||||||
db.execSQL(
|
|
||||||
"CREATE TABLE IF NOT EXISTS " + SETTINGS_TABLE + " " +
|
|
||||||
"(key TEXT, value INT, PRIMARY KEY(key))");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void cleanup() {
|
|
||||||
// Clear outdated policies
|
|
||||||
mDb.delete(POLICY_TABLE, "until > 0 AND until < ?",
|
|
||||||
new String[] { String.valueOf(System.currentTimeMillis() / 1000) });
|
|
||||||
// Clear outdated logs
|
|
||||||
mDb.delete(LOG_TABLE, "time < ?", new String[] { String.valueOf(
|
|
||||||
System.currentTimeMillis() - mm.suLogTimeout * 86400000) });
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deletePolicy(Policy policy) {
|
|
||||||
deletePolicy(policy.packageName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deletePolicy(String pkg) {
|
|
||||||
mDb.delete(POLICY_TABLE, "package_name=?", new String[] { pkg });
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deletePolicy(int uid) {
|
|
||||||
mDb.delete(POLICY_TABLE, "uid=?", new String[]{String.valueOf(uid)});
|
|
||||||
}
|
|
||||||
|
|
||||||
public Policy getPolicy(int uid) {
|
|
||||||
Policy policy = null;
|
|
||||||
try (Cursor c = mDb.query(POLICY_TABLE, null, "uid=?", new String[] { String.valueOf(uid) }, null, null, null)) {
|
|
||||||
if (c.moveToNext()) {
|
|
||||||
policy = new Policy(c, pm);
|
|
||||||
}
|
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
|
||||||
deletePolicy(uid);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return policy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Policy getPolicy(String pkg) {
|
|
||||||
Policy policy = null;
|
|
||||||
try (Cursor c = mDb.query(POLICY_TABLE, null, "package_name=?", new String[] { pkg }, null, null, null)) {
|
|
||||||
if (c.moveToNext()) {
|
|
||||||
policy = new Policy(c, pm);
|
|
||||||
}
|
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
|
||||||
deletePolicy(pkg);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return policy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addPolicy(Policy policy) {
|
|
||||||
mDb.replace(POLICY_TABLE, null, policy.getContentValues());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updatePolicy(Policy policy) {
|
|
||||||
mDb.update(POLICY_TABLE, policy.getContentValues(), "package_name=?",
|
|
||||||
new String[] { policy.packageName });
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Policy> getPolicyList(PackageManager pm) {
|
|
||||||
try (Cursor c = mDb.query(POLICY_TABLE, null, null, null, null, null, null)) {
|
|
||||||
List<Policy> ret = new ArrayList<>(c.getCount());
|
|
||||||
while (c.moveToNext()) {
|
|
||||||
try {
|
|
||||||
Policy policy = new Policy(c, pm);
|
|
||||||
// The application changed UID for some reason, check user config
|
|
||||||
if (policy.info.uid != policy.uid) {
|
|
||||||
if (mm.suReauth) {
|
|
||||||
// Reauth required, remove from DB
|
|
||||||
deletePolicy(policy);
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
// No reauth, update to use the new UID
|
|
||||||
policy.uid = policy.info.uid;
|
|
||||||
updatePolicy(policy);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ret.add(policy);
|
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
|
||||||
// The app no longer exist, remove from DB
|
|
||||||
deletePolicy(c.getInt(c.getColumnIndex("uid")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Collections.sort(ret);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<List<Integer>> getLogStructure() {
|
|
||||||
try (Cursor c = mDb.query(LOG_TABLE, new String[] { "time" }, null, null, null, null, "time DESC")) {
|
|
||||||
List<List<Integer>> ret = new ArrayList<>();
|
|
||||||
List<Integer> list = null;
|
|
||||||
String dateString = null, newString;
|
|
||||||
while (c.moveToNext()) {
|
|
||||||
Date date = new Date(c.getLong(c.getColumnIndex("time")));
|
|
||||||
newString = DateFormat.getDateInstance(DateFormat.MEDIUM, MagiskManager.locale).format(date);
|
|
||||||
if (!TextUtils.equals(dateString, newString)) {
|
|
||||||
dateString = newString;
|
|
||||||
list = new ArrayList<>();
|
|
||||||
ret.add(list);
|
|
||||||
}
|
|
||||||
list.add(c.getPosition());
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Cursor getLogCursor() {
|
|
||||||
return getLogCursor(mDb);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Cursor getLogCursor(SQLiteDatabase db) {
|
|
||||||
return db.query(LOG_TABLE, null, null, null, null, null, "time DESC");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void migrateLegacyLogList(File oldDB, SQLiteDatabase newDB) {
|
|
||||||
try (SQLiteDatabase oldDb = SQLiteDatabase.openDatabase(oldDB.getPath(), null, SQLiteDatabase.OPEN_READWRITE);
|
|
||||||
Cursor c = getLogCursor(oldDb)) {
|
|
||||||
while (c.moveToNext()) {
|
|
||||||
ContentValues values = new ContentValues();
|
|
||||||
DatabaseUtils.cursorRowToContentValues(c, values);
|
|
||||||
newDB.insert(LOG_TABLE, null, values);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addLog(SuLogEntry log) {
|
|
||||||
mDb.insert(LOG_TABLE, null, log.getContentValues());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clearLogs() {
|
|
||||||
mDb.delete(LOG_TABLE, null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSettings(String key, int value) {
|
|
||||||
ContentValues data = new ContentValues();
|
|
||||||
data.put("key", key);
|
|
||||||
data.put("value", value);
|
|
||||||
mDb.replace(SETTINGS_TABLE, null, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSettings(String key, int defaultValue) {
|
|
||||||
int value = defaultValue;
|
|
||||||
try (Cursor c = mDb.query(SETTINGS_TABLE, null, "key=?",new String[] { key }, null, null, null)) {
|
|
||||||
if (c.moveToNext()) {
|
|
||||||
value = c.getInt(c.getColumnIndex("value"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,40 +0,0 @@
|
|||||||
package com.topjohnwu.magisk.receivers;
|
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
|
|
||||||
import com.topjohnwu.magisk.MagiskManager;
|
|
||||||
import com.topjohnwu.magisk.container.Policy;
|
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
|
||||||
|
|
||||||
public class PackageReceiver extends BroadcastReceiver {
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
MagiskManager magiskManager = Utils.getMagiskManager(context);
|
|
||||||
|
|
||||||
String pkg = intent.getData().getEncodedSchemeSpecificPart();
|
|
||||||
Policy policy = magiskManager.suDB.getPolicy(pkg);
|
|
||||||
if (policy == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
switch (intent.getAction()) {
|
|
||||||
case Intent.ACTION_PACKAGE_REPLACED:
|
|
||||||
// This will only work pre-O
|
|
||||||
if (magiskManager.suReauth) {
|
|
||||||
magiskManager.suDB.deletePolicy(policy);
|
|
||||||
} else {
|
|
||||||
int uid = intent.getIntExtra(Intent.EXTRA_UID, -1);
|
|
||||||
// Update the UID if available
|
|
||||||
if (uid > 0) {
|
|
||||||
policy.uid = uid % 100000;
|
|
||||||
}
|
|
||||||
magiskManager.suDB.updatePolicy(policy);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Intent.ACTION_PACKAGE_FULLY_REMOVED:
|
|
||||||
magiskManager.suDB.deletePolicy(policy);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,34 +0,0 @@
|
|||||||
package com.topjohnwu.magisk.services;
|
|
||||||
|
|
||||||
import android.app.IntentService;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.support.v7.app.NotificationCompat;
|
|
||||||
|
|
||||||
import com.topjohnwu.magisk.R;
|
|
||||||
|
|
||||||
public class OnBootIntentService extends IntentService {
|
|
||||||
|
|
||||||
private static final int ONBOOT_NOTIFICATION_ID = 3;
|
|
||||||
|
|
||||||
public OnBootIntentService() {
|
|
||||||
super("OnBootIntentService");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate() {
|
|
||||||
super.onCreate();
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
||||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
|
|
||||||
builder.setSmallIcon(R.drawable.ic_magisk)
|
|
||||||
.setContentTitle("onBoot")
|
|
||||||
.setContentText("Running onBoot operations...");
|
|
||||||
startForeground(ONBOOT_NOTIFICATION_ID, builder.build());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onHandleIntent(Intent intent) {
|
|
||||||
// Currently nothing to do
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,24 +0,0 @@
|
|||||||
package com.topjohnwu.magisk.superuser;
|
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Bundle;
|
|
||||||
|
|
||||||
import com.topjohnwu.magisk.components.Activity;
|
|
||||||
|
|
||||||
public class RequestActivity extends Activity {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
|
|
||||||
Intent intent = getIntent();
|
|
||||||
if (intent == null) {
|
|
||||||
finish();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).setClass(this, SuRequestActivity.class);
|
|
||||||
startActivity(intent);
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,225 +0,0 @@
|
|||||||
package com.topjohnwu.magisk.utils;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
|
|
||||||
import com.topjohnwu.magisk.MagiskManager;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Modified by topjohnwu, based on Chainfire's libsuperuser
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class Shell {
|
|
||||||
|
|
||||||
// -1 = problematic/unknown issue; 0 = not rooted; 1 = properly rooted
|
|
||||||
public static int rootStatus;
|
|
||||||
|
|
||||||
private final Process shellProcess;
|
|
||||||
private final DataOutputStream STDIN;
|
|
||||||
private final DataInputStream STDOUT;
|
|
||||||
|
|
||||||
private boolean isValid;
|
|
||||||
|
|
||||||
private void testRootShell(DataOutputStream in, DataInputStream out) throws IOException {
|
|
||||||
in.write(("id\n").getBytes("UTF-8"));
|
|
||||||
in.flush();
|
|
||||||
String s = new BufferedReader(new InputStreamReader(out)).readLine();
|
|
||||||
if (TextUtils.isEmpty(s) || !s.contains("uid=0")) {
|
|
||||||
in.close();
|
|
||||||
out.close();
|
|
||||||
throw new IOException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Shell() {
|
|
||||||
rootStatus = 1;
|
|
||||||
Process process = null;
|
|
||||||
DataOutputStream in = null;
|
|
||||||
DataInputStream out = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Try getting global namespace
|
|
||||||
process = Runtime.getRuntime().exec("su --mount-master");
|
|
||||||
in = new DataOutputStream(process.getOutputStream());
|
|
||||||
out = new DataInputStream(process.getInputStream());
|
|
||||||
testRootShell(in, out);
|
|
||||||
} catch (IOException e) {
|
|
||||||
// Feature not implemented, normal root shell
|
|
||||||
try {
|
|
||||||
process = Runtime.getRuntime().exec("su");
|
|
||||||
in = new DataOutputStream(process.getOutputStream());
|
|
||||||
out = new DataInputStream(process.getInputStream());
|
|
||||||
testRootShell(in, out);
|
|
||||||
} catch (IOException e1) {
|
|
||||||
rootStatus = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!rootAccess()) {
|
|
||||||
// Try to gain non-root sh
|
|
||||||
try {
|
|
||||||
process = Runtime.getRuntime().exec("sh");
|
|
||||||
in = new DataOutputStream(process.getOutputStream());
|
|
||||||
out = new DataInputStream(process.getInputStream());
|
|
||||||
} catch (IOException e) {
|
|
||||||
// Nothing works....
|
|
||||||
shellProcess = null;
|
|
||||||
STDIN = null;
|
|
||||||
STDOUT = null;
|
|
||||||
isValid = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
isValid = true;
|
|
||||||
shellProcess = process;
|
|
||||||
STDIN = in;
|
|
||||||
STDOUT = out;
|
|
||||||
sh_raw("umask 022");
|
|
||||||
}
|
|
||||||
|
|
||||||
private Shell(String command) {
|
|
||||||
Process process;
|
|
||||||
DataOutputStream in;
|
|
||||||
DataInputStream out;
|
|
||||||
|
|
||||||
try {
|
|
||||||
process = Runtime.getRuntime().exec(command);
|
|
||||||
in = new DataOutputStream(process.getOutputStream());
|
|
||||||
out = new DataInputStream(process.getInputStream());
|
|
||||||
} catch (IOException e) {
|
|
||||||
// Nothing works....
|
|
||||||
shellProcess = null;
|
|
||||||
STDIN = null;
|
|
||||||
STDOUT = null;
|
|
||||||
isValid = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
isValid = true;
|
|
||||||
shellProcess = process;
|
|
||||||
STDIN = in;
|
|
||||||
STDOUT = out;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Shell getShell() {
|
|
||||||
return new Shell();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Shell getShell(String command) {
|
|
||||||
return new Shell(command);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Shell getShell(Context context) {
|
|
||||||
MagiskManager magiskManager = Utils.getMagiskManager(context);
|
|
||||||
if (magiskManager.shell == null || !magiskManager.shell.isValid) {
|
|
||||||
// Get new shell if needed
|
|
||||||
magiskManager.shell = getShell();
|
|
||||||
}
|
|
||||||
return magiskManager.shell;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean rootAccess() {
|
|
||||||
return rootStatus > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void loadInputStream(InputStream in) {
|
|
||||||
try {
|
|
||||||
int read;
|
|
||||||
byte[] bytes = new byte[4096];
|
|
||||||
while ((read = in.read(bytes)) != -1) {
|
|
||||||
STDIN.write(bytes, 0, read);
|
|
||||||
}
|
|
||||||
STDIN.flush();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> sh(String... commands) {
|
|
||||||
List<String> res = new ArrayList<>();
|
|
||||||
if (!isValid) return res;
|
|
||||||
sh(res, commands);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sh_raw(String... commands) {
|
|
||||||
sh_raw(false, commands);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sh_raw(boolean stdout, String... commands) {
|
|
||||||
if (!isValid) return;
|
|
||||||
synchronized (shellProcess) {
|
|
||||||
try {
|
|
||||||
for (String command : commands) {
|
|
||||||
Logger.shell(command);
|
|
||||||
STDIN.write((command + (stdout ? "\n" : " >/dev/null\n")).getBytes("UTF-8"));
|
|
||||||
STDIN.flush();
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
shellProcess.destroy();
|
|
||||||
isValid = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sh(Collection<String> output, String... commands) {
|
|
||||||
if (!isValid) return;
|
|
||||||
try {
|
|
||||||
shellProcess.exitValue();
|
|
||||||
isValid = false;
|
|
||||||
return; // The process is dead, return
|
|
||||||
} catch (IllegalThreadStateException ignored) {
|
|
||||||
// This should be the expected result
|
|
||||||
}
|
|
||||||
synchronized (shellProcess) {
|
|
||||||
StreamGobbler out = new StreamGobbler(STDOUT, output);
|
|
||||||
out.start();
|
|
||||||
sh_raw(true, commands);
|
|
||||||
sh_raw(true, "echo \'-shell-done-\'");
|
|
||||||
try { out.join(); } catch (InterruptedException ignored) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> su(String... commands) {
|
|
||||||
if (!rootAccess()) return sh();
|
|
||||||
return sh(commands);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void su_raw(String... commands) {
|
|
||||||
if (!rootAccess()) return;
|
|
||||||
sh_raw(commands);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void su(Collection<String> output, String... commands) {
|
|
||||||
if (!rootAccess()) return;
|
|
||||||
sh(output, commands);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static abstract class AbstractList<E> extends java.util.AbstractList<E> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public abstract boolean add(E e);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public E get(int i) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int size() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,534 +0,0 @@
|
|||||||
package com.topjohnwu.magisk.utils;
|
|
||||||
|
|
||||||
import android.Manifest;
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.DownloadManager;
|
|
||||||
import android.app.NotificationManager;
|
|
||||||
import android.app.PendingIntent;
|
|
||||||
import android.app.admin.DevicePolicyManager;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.IntentFilter;
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.content.res.Configuration;
|
|
||||||
import android.database.Cursor;
|
|
||||||
import android.net.ConnectivityManager;
|
|
||||||
import android.net.NetworkInfo;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Environment;
|
|
||||||
import android.provider.OpenableColumns;
|
|
||||||
import android.support.annotation.StringRes;
|
|
||||||
import android.support.design.widget.Snackbar;
|
|
||||||
import android.support.v4.app.ActivityCompat;
|
|
||||||
import android.support.v4.app.NotificationCompat;
|
|
||||||
import android.support.v4.app.TaskStackBuilder;
|
|
||||||
import android.support.v4.content.ContextCompat;
|
|
||||||
import android.support.v7.app.AlertDialog;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import com.topjohnwu.magisk.FlashActivity;
|
|
||||||
import com.topjohnwu.magisk.MagiskFragment;
|
|
||||||
import com.topjohnwu.magisk.MagiskManager;
|
|
||||||
import com.topjohnwu.magisk.R;
|
|
||||||
import com.topjohnwu.magisk.SplashActivity;
|
|
||||||
import com.topjohnwu.magisk.asyncs.RestoreStockBoot;
|
|
||||||
import com.topjohnwu.magisk.asyncs.UpdateRepos;
|
|
||||||
import com.topjohnwu.magisk.components.AlertDialogBuilder;
|
|
||||||
import com.topjohnwu.magisk.components.SnackbarMaker;
|
|
||||||
import com.topjohnwu.magisk.receivers.DownloadReceiver;
|
|
||||||
import com.topjohnwu.magisk.receivers.ManagerUpdate;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.security.SecureRandom;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
public class Utils {
|
|
||||||
|
|
||||||
public static final int SELECT_BOOT_IMG = 3;
|
|
||||||
public static final String UNINSTALLER = "magisk_uninstaller.sh";
|
|
||||||
public static final String UTIL_FUNCTIONS= "util_functions.sh";
|
|
||||||
public static boolean isDownloading = false;
|
|
||||||
|
|
||||||
private static final int MAGISK_UPDATE_NOTIFICATION_ID = 1;
|
|
||||||
private static final int APK_UPDATE_NOTIFICATION_ID = 2;
|
|
||||||
|
|
||||||
public static boolean itemExist(Shell shell, String path) {
|
|
||||||
String command = "[ -e " + path + " ] && echo true || echo false";
|
|
||||||
List<String> ret = shell.su(command);
|
|
||||||
return isValidShellResponse(ret) && Boolean.parseBoolean(ret.get(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void createFile(Shell shell, String path) {
|
|
||||||
String folder = path.substring(0, path.lastIndexOf('/'));
|
|
||||||
String command = "mkdir -p " + folder + " 2>/dev/null; touch " + path + " 2>/dev/null;";
|
|
||||||
shell.su_raw(command);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void removeItem(Shell shell, String path) {
|
|
||||||
String command = "rm -rf " + path + " 2>/dev/null";
|
|
||||||
shell.su_raw(command);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<String> getModList(Shell shell, String path) {
|
|
||||||
String command = "ls -d " + path + "/* | grep -v lost+found";
|
|
||||||
return shell.su(command);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<String> readFile(Shell shell, String path) {
|
|
||||||
String command = "cat " + path + " | sed '$a\\ ' | sed '$d'";
|
|
||||||
return shell.su(command);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void dlAndReceive(Context context, DownloadReceiver receiver, String link, String filename) {
|
|
||||||
if (isDownloading)
|
|
||||||
return;
|
|
||||||
|
|
||||||
runWithPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE, () -> {
|
|
||||||
File file = new File(Environment.getExternalStorageDirectory() + "/MagiskManager/" + filename);
|
|
||||||
|
|
||||||
if ((!file.getParentFile().exists() && !file.getParentFile().mkdirs())
|
|
||||||
|| (file.exists() && !file.delete())) {
|
|
||||||
Toast.makeText(context, R.string.permissionNotGranted, Toast.LENGTH_LONG).show();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Toast.makeText(context, context.getString(R.string.downloading_toast, filename), Toast.LENGTH_LONG).show();
|
|
||||||
isDownloading = true;
|
|
||||||
|
|
||||||
DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
|
|
||||||
|
|
||||||
if (link != null) {
|
|
||||||
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(link));
|
|
||||||
request.setDestinationUri(Uri.fromFile(file));
|
|
||||||
receiver.setDownloadID(downloadManager.enqueue(request));
|
|
||||||
}
|
|
||||||
receiver.setFilename(filename);
|
|
||||||
context.getApplicationContext().registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getLegalFilename(CharSequence filename) {
|
|
||||||
return filename.toString().replace(" ", "_").replace("'", "").replace("\"", "")
|
|
||||||
.replace("$", "").replace("`", "").replace("(", "").replace(")", "")
|
|
||||||
.replace("#", "").replace("@", "").replace("*", "");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean lowercaseContains(CharSequence string, CharSequence nonNullLowercaseSearch) {
|
|
||||||
return !TextUtils.isEmpty(string) && string.toString().toLowerCase().contains(nonNullLowercaseSearch);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isValidShellResponse(List<String> list) {
|
|
||||||
if (list != null && list.size() != 0) {
|
|
||||||
// Check if all empty
|
|
||||||
for (String res : list) {
|
|
||||||
if (!TextUtils.isEmpty(res)) return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getPrefsInt(SharedPreferences prefs, String key, int def) {
|
|
||||||
return Integer.parseInt(prefs.getString(key, String.valueOf(def)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getPrefsInt(SharedPreferences prefs, String key) {
|
|
||||||
return getPrefsInt(prefs, key, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MagiskManager getMagiskManager(Context context) {
|
|
||||||
return (MagiskManager) context.getApplicationContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void clearRepoCache(Context context) {
|
|
||||||
MagiskManager mm = getMagiskManager(context);
|
|
||||||
mm.prefs.edit().remove(UpdateRepos.ETAG_KEY).apply();
|
|
||||||
mm.repoDB.clearRepo();
|
|
||||||
mm.toast(R.string.repo_cache_cleared, Toast.LENGTH_SHORT);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getNameFromUri(Context context, Uri uri) {
|
|
||||||
String name = null;
|
|
||||||
try (Cursor c = context.getContentResolver().query(uri, null, null, null, null)) {
|
|
||||||
if (c != null) {
|
|
||||||
int nameIndex = c.getColumnIndex(OpenableColumns.DISPLAY_NAME);
|
|
||||||
if (nameIndex != -1) {
|
|
||||||
c.moveToFirst();
|
|
||||||
name = c.getString(nameIndex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (name == null) {
|
|
||||||
int idx = uri.getPath().lastIndexOf('/');
|
|
||||||
name = uri.getPath().substring(idx + 1);
|
|
||||||
}
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void showUriSnack(Activity activity, Uri uri) {
|
|
||||||
SnackbarMaker.make(activity, activity.getString(R.string.internal_storage,
|
|
||||||
"/MagiskManager/" + Utils.getNameFromUri(activity, uri)),
|
|
||||||
Snackbar.LENGTH_LONG)
|
|
||||||
.setAction(R.string.ok, (v)->{}).show();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean checkNetworkStatus(Context context) {
|
|
||||||
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
||||||
NetworkInfo networkInfo = manager.getActiveNetworkInfo();
|
|
||||||
return networkInfo != null && networkInfo.isConnected();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void showMagiskUpdateNotification(MagiskManager mm) {
|
|
||||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(mm, MagiskManager.NOTIFICATION_CHANNEL);
|
|
||||||
builder.setSmallIcon(R.drawable.ic_magisk)
|
|
||||||
.setContentTitle(mm.getString(R.string.magisk_update_title))
|
|
||||||
.setContentText(mm.getString(R.string.magisk_update_available, mm.remoteMagiskVersionString))
|
|
||||||
.setVibrate(new long[]{0, 100, 100, 100})
|
|
||||||
.setAutoCancel(true);
|
|
||||||
Intent intent = new Intent(mm, SplashActivity.class);
|
|
||||||
intent.putExtra(MagiskManager.INTENT_SECTION, "magisk");
|
|
||||||
TaskStackBuilder stackBuilder = TaskStackBuilder.create(mm);
|
|
||||||
stackBuilder.addParentStack(SplashActivity.class);
|
|
||||||
stackBuilder.addNextIntent(intent);
|
|
||||||
PendingIntent pendingIntent = stackBuilder.getPendingIntent(MAGISK_UPDATE_NOTIFICATION_ID,
|
|
||||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
|
||||||
builder.setContentIntent(pendingIntent);
|
|
||||||
NotificationManager notificationManager =
|
|
||||||
(NotificationManager) mm.getSystemService(Context.NOTIFICATION_SERVICE);
|
|
||||||
notificationManager.notify(MAGISK_UPDATE_NOTIFICATION_ID, builder.build());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void showManagerUpdateNotification(MagiskManager mm) {
|
|
||||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(mm, MagiskManager.NOTIFICATION_CHANNEL);
|
|
||||||
builder.setSmallIcon(R.drawable.ic_magisk)
|
|
||||||
.setContentTitle(mm.getString(R.string.manager_update_title))
|
|
||||||
.setContentText(mm.getString(R.string.manager_download_install))
|
|
||||||
.setVibrate(new long[]{0, 100, 100, 100})
|
|
||||||
.setAutoCancel(true);
|
|
||||||
Intent intent = new Intent(mm, ManagerUpdate.class);
|
|
||||||
intent.putExtra(MagiskManager.INTENT_LINK, mm.managerLink);
|
|
||||||
intent.putExtra(MagiskManager.INTENT_VERSION, mm.remoteManagerVersionString);
|
|
||||||
PendingIntent pendingIntent = PendingIntent.getBroadcast(mm,
|
|
||||||
APK_UPDATE_NOTIFICATION_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
||||||
builder.setContentIntent(pendingIntent);
|
|
||||||
NotificationManager notificationManager =
|
|
||||||
(NotificationManager) mm.getSystemService(Context.NOTIFICATION_SERVICE);
|
|
||||||
notificationManager.notify(APK_UPDATE_NOTIFICATION_ID, builder.build());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void enableMagiskHide(Shell shell) {
|
|
||||||
shell.su_raw("magiskhide --enable");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void disableMagiskHide(Shell shell) {
|
|
||||||
shell.su_raw("magiskhide --disable");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<String> listMagiskHide(Shell shell) {
|
|
||||||
return shell.su("magiskhide --ls");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void addMagiskHide(Shell shell, String pkg) {
|
|
||||||
shell.su_raw("magiskhide --add " + pkg);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void rmMagiskHide(Shell shell, String pkg) {
|
|
||||||
shell.su_raw("magiskhide --rm " + pkg);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getLocaleString(Context context, Locale locale, @StringRes int id) {
|
|
||||||
Configuration config = context.getResources().getConfiguration();
|
|
||||||
config.setLocale(locale);
|
|
||||||
Context localizedContext = context.createConfigurationContext(config);
|
|
||||||
return localizedContext.getString(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<Locale> getAvailableLocale(Context context) {
|
|
||||||
List<Locale> locales = new ArrayList<>();
|
|
||||||
HashSet<String> set = new HashSet<>();
|
|
||||||
Locale locale;
|
|
||||||
|
|
||||||
int compareId = R.string.download_file_error;
|
|
||||||
|
|
||||||
// Add default locale
|
|
||||||
locales.add(Locale.ENGLISH);
|
|
||||||
set.add(getLocaleString(context, Locale.ENGLISH, compareId));
|
|
||||||
|
|
||||||
// Add some special locales
|
|
||||||
locales.add(Locale.TAIWAN);
|
|
||||||
set.add(getLocaleString(context, Locale.TAIWAN, compareId));
|
|
||||||
locale = new Locale("pt", "BR");
|
|
||||||
locales.add(locale);
|
|
||||||
set.add(getLocaleString(context, locale, compareId));
|
|
||||||
|
|
||||||
// Other locales
|
|
||||||
for (String s : context.getAssets().getLocales()) {
|
|
||||||
locale = Locale.forLanguageTag(s);
|
|
||||||
if (set.add(getLocaleString(context, locale, compareId))) {
|
|
||||||
locales.add(locale);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Collections.sort(locales, (l1, l2) -> l1.getDisplayName(l1).compareTo(l2.getDisplayName(l2)));
|
|
||||||
|
|
||||||
return locales;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String genPackageName(String prefix, int length) {
|
|
||||||
StringBuilder builder = new StringBuilder(length);
|
|
||||||
builder.append(prefix);
|
|
||||||
length -= prefix.length();
|
|
||||||
SecureRandom random = new SecureRandom();
|
|
||||||
String base = "abcdefghijklmnopqrstuvwxyz";
|
|
||||||
String alpha = base + base.toUpperCase();
|
|
||||||
String full = alpha + "0123456789..........";
|
|
||||||
char next, prev = '\0';
|
|
||||||
for (int i = 0; i < length; ++i) {
|
|
||||||
if (prev == '.' || i == length - 1 || i == 0) {
|
|
||||||
next = alpha.charAt(random.nextInt(alpha.length()));
|
|
||||||
} else {
|
|
||||||
next = full.charAt(random.nextInt(full.length()));
|
|
||||||
}
|
|
||||||
builder.append(next);
|
|
||||||
prev = next;
|
|
||||||
}
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void runWithPermission(Context context, String permission, Runnable callback) {
|
|
||||||
if (ContextCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) {
|
|
||||||
// Passed in context should be an activity if not granted, need to show dialog!
|
|
||||||
if (!(context instanceof com.topjohnwu.magisk.components.Activity))
|
|
||||||
return;
|
|
||||||
com.topjohnwu.magisk.components.Activity activity = (com.topjohnwu.magisk.components.Activity) context;
|
|
||||||
activity.setPermissionGrantCallback(callback);
|
|
||||||
ActivityCompat.requestPermissions(activity, new String[] { permission }, 0);
|
|
||||||
} else {
|
|
||||||
callback.run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void showMagiskInstallDialog(MagiskFragment fragment, boolean enc, boolean verity) {
|
|
||||||
MagiskManager mm = getMagiskManager(fragment.getActivity());
|
|
||||||
String filename = getLegalFilename("Magisk-v" + mm.remoteMagiskVersionString + ".zip");
|
|
||||||
new AlertDialogBuilder(fragment.getActivity())
|
|
||||||
.setTitle(mm.getString(R.string.repo_install_title, mm.getString(R.string.magisk)))
|
|
||||||
.setMessage(mm.getString(R.string.repo_install_msg, filename))
|
|
||||||
.setCancelable(true)
|
|
||||||
.setPositiveButton(R.string.install, (d, i) -> {
|
|
||||||
List<String> options = new ArrayList<>();
|
|
||||||
options.add(mm.getString(R.string.download_zip_only));
|
|
||||||
options.add(mm.getString(R.string.patch_boot_file));
|
|
||||||
if (Shell.rootAccess()) {
|
|
||||||
options.add(mm.getString(R.string.direct_install));
|
|
||||||
}
|
|
||||||
List<String> res = Shell.getShell(mm).su("echo $SLOT");
|
|
||||||
if (isValidShellResponse(res)) {
|
|
||||||
options.add(mm.getString(R.string.install_second_slot));
|
|
||||||
}
|
|
||||||
char[] slot = isValidShellResponse(res) ? res.get(0).toCharArray() : null;
|
|
||||||
new AlertDialog.Builder(fragment.getActivity())
|
|
||||||
.setTitle(R.string.select_method)
|
|
||||||
.setItems(
|
|
||||||
options.toArray(new String [0]),
|
|
||||||
(dialog, idx) -> {
|
|
||||||
String boot;
|
|
||||||
DownloadReceiver receiver = null;
|
|
||||||
switch (idx) {
|
|
||||||
case 1:
|
|
||||||
if (mm.remoteMagiskVersionCode < 1400) {
|
|
||||||
mm.toast(R.string.no_boot_file_patch_support, Toast.LENGTH_LONG);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mm.toast(R.string.boot_file_patch_msg, Toast.LENGTH_LONG);
|
|
||||||
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
|
||||||
intent.setType("*/*");
|
|
||||||
fragment.startActivityForResult(intent, SELECT_BOOT_IMG,
|
|
||||||
(requestCode, resultCode, data) -> {
|
|
||||||
if (requestCode == SELECT_BOOT_IMG
|
|
||||||
&& resultCode == Activity.RESULT_OK && data != null) {
|
|
||||||
dlAndReceive(
|
|
||||||
fragment.getActivity(),
|
|
||||||
new DownloadReceiver() {
|
|
||||||
@Override
|
|
||||||
public void onDownloadDone(Uri uri) {
|
|
||||||
Intent intent = new Intent(mm, FlashActivity.class);
|
|
||||||
intent.setData(uri)
|
|
||||||
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
||||||
.putExtra(FlashActivity.SET_BOOT, data.getData())
|
|
||||||
.putExtra(FlashActivity.SET_ENC, enc)
|
|
||||||
.putExtra(FlashActivity.SET_VERITY, verity)
|
|
||||||
.putExtra(FlashActivity.SET_ACTION, FlashActivity.PATCH_BOOT);
|
|
||||||
mm.startActivity(intent);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
mm.magiskLink,
|
|
||||||
filename
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
case 0:
|
|
||||||
receiver = new DownloadReceiver() {
|
|
||||||
@Override
|
|
||||||
public void onDownloadDone(Uri uri) {
|
|
||||||
showUriSnack(fragment.getActivity(), uri);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
boot = fragment.getSelectedBootImage();
|
|
||||||
if (boot == null)
|
|
||||||
return;
|
|
||||||
receiver = new DownloadReceiver() {
|
|
||||||
@Override
|
|
||||||
public void onDownloadDone(Uri uri) {
|
|
||||||
Intent intent = new Intent(mm, FlashActivity.class);
|
|
||||||
intent.setData(uri)
|
|
||||||
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
||||||
.putExtra(FlashActivity.SET_BOOT, boot)
|
|
||||||
.putExtra(FlashActivity.SET_ENC, enc)
|
|
||||||
.putExtra(FlashActivity.SET_VERITY, verity)
|
|
||||||
.putExtra(FlashActivity.SET_ACTION, FlashActivity.FLASH_MAGISK);
|
|
||||||
mm.startActivity(intent);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
assert (slot != null);
|
|
||||||
// Choose the other slot
|
|
||||||
if (slot[1] == 'a') slot[1] = 'b';
|
|
||||||
else slot[1] = 'a';
|
|
||||||
// Then find the boot image again
|
|
||||||
List<String> ret = Shell.getShell(mm).su(
|
|
||||||
"BOOTIMAGE=",
|
|
||||||
"SLOT=" + String.valueOf(slot),
|
|
||||||
"find_boot_image",
|
|
||||||
"echo \"$BOOTIMAGE\""
|
|
||||||
);
|
|
||||||
boot = isValidShellResponse(ret) ? ret.get(ret.size() - 1) : null;
|
|
||||||
Shell.getShell(mm).su_raw("mount_partitions");
|
|
||||||
if (boot == null)
|
|
||||||
return;
|
|
||||||
receiver = new DownloadReceiver() {
|
|
||||||
@Override
|
|
||||||
public void onDownloadDone(Uri uri) {
|
|
||||||
Intent intent = new Intent(mm, FlashActivity.class);
|
|
||||||
intent.setData(uri)
|
|
||||||
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
||||||
.putExtra(FlashActivity.SET_BOOT, boot)
|
|
||||||
.putExtra(FlashActivity.SET_ENC, enc)
|
|
||||||
.putExtra(FlashActivity.SET_VERITY, verity)
|
|
||||||
.putExtra(FlashActivity.SET_ACTION, FlashActivity.FLASH_MAGISK);
|
|
||||||
mm.startActivity(intent);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
Utils.dlAndReceive(
|
|
||||||
fragment.getActivity(),
|
|
||||||
receiver,
|
|
||||||
mm.magiskLink,
|
|
||||||
filename
|
|
||||||
);
|
|
||||||
}
|
|
||||||
).show();
|
|
||||||
})
|
|
||||||
.setNeutralButton(R.string.release_notes, (d, i) -> {
|
|
||||||
if (mm.releaseNoteLink != null) {
|
|
||||||
Intent openLink = new Intent(Intent.ACTION_VIEW, Uri.parse(mm.releaseNoteLink));
|
|
||||||
openLink.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
mm.startActivity(openLink);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.setNegativeButton(R.string.no_thanks, null)
|
|
||||||
.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void showManagerInstallDialog(Activity activity) {
|
|
||||||
MagiskManager mm = Utils.getMagiskManager(activity);
|
|
||||||
new AlertDialogBuilder(activity)
|
|
||||||
.setTitle(mm.getString(R.string.repo_install_title, mm.getString(R.string.app_name)))
|
|
||||||
.setMessage(mm.getString(R.string.repo_install_msg,
|
|
||||||
Utils.getLegalFilename("MagiskManager-v" +
|
|
||||||
mm.remoteManagerVersionString + ".apk")))
|
|
||||||
.setCancelable(true)
|
|
||||||
.setPositiveButton(R.string.install, (d, i) -> {
|
|
||||||
Intent intent = new Intent(mm, ManagerUpdate.class);
|
|
||||||
intent.putExtra(MagiskManager.INTENT_LINK, mm.managerLink);
|
|
||||||
intent.putExtra(MagiskManager.INTENT_VERSION, mm.remoteManagerVersionString);
|
|
||||||
mm.sendBroadcast(intent);
|
|
||||||
})
|
|
||||||
.setNegativeButton(R.string.no_thanks, null)
|
|
||||||
.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void showUninstallDialog(MagiskFragment fragment) {
|
|
||||||
MagiskManager mm = Utils.getMagiskManager(fragment.getActivity());
|
|
||||||
new AlertDialogBuilder(fragment.getActivity())
|
|
||||||
.setTitle(R.string.uninstall_magisk_title)
|
|
||||||
.setMessage(R.string.uninstall_magisk_msg)
|
|
||||||
.setPositiveButton(R.string.complete_uninstall, (d, i) -> {
|
|
||||||
try {
|
|
||||||
InputStream in = mm.getAssets().open(UNINSTALLER);
|
|
||||||
File uninstaller = new File(mm.getCacheDir(), UNINSTALLER);
|
|
||||||
FileOutputStream out = new FileOutputStream(uninstaller);
|
|
||||||
byte[] bytes = new byte[1024];
|
|
||||||
int read;
|
|
||||||
while ((read = in.read(bytes)) != -1) {
|
|
||||||
out.write(bytes, 0, read);
|
|
||||||
}
|
|
||||||
in.close();
|
|
||||||
out.close();
|
|
||||||
in = mm.getAssets().open(UTIL_FUNCTIONS);
|
|
||||||
File utils = new File(mm.getCacheDir(), UTIL_FUNCTIONS);
|
|
||||||
out = new FileOutputStream(utils);
|
|
||||||
while ((read = in.read(bytes)) != -1) {
|
|
||||||
out.write(bytes, 0, read);
|
|
||||||
}
|
|
||||||
in.close();
|
|
||||||
out.close();
|
|
||||||
Shell.getShell(mm).su(
|
|
||||||
"cat " + uninstaller + " > /cache/" + UNINSTALLER,
|
|
||||||
"cat " + utils + " > /data/magisk/" + UTIL_FUNCTIONS
|
|
||||||
);
|
|
||||||
mm.toast(R.string.uninstall_toast, Toast.LENGTH_LONG);
|
|
||||||
Shell.getShell(mm).su_raw(
|
|
||||||
"sleep 5",
|
|
||||||
"pm uninstall " + mm.getApplicationInfo().packageName
|
|
||||||
);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.setNeutralButton(R.string.restore_stock_boot, (d, i) -> {
|
|
||||||
String boot = fragment.getSelectedBootImage();
|
|
||||||
if (boot == null) return;
|
|
||||||
new RestoreStockBoot(mm, boot).exec();
|
|
||||||
})
|
|
||||||
.setNegativeButton(R.string.no_thanks, null)
|
|
||||||
.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean useFDE(Context context) {
|
|
||||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
|
|
||||||
&& context.getSystemService(DevicePolicyManager.class).getStorageEncryptionStatus()
|
|
||||||
== DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE_PER_USER;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Context getEncContext(Context context) {
|
|
||||||
if (useFDE(context))
|
|
||||||
return context.createDeviceProtectedStorageContext();
|
|
||||||
else
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,86 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
|
|
||||||
<android.support.v7.widget.CardView
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:card_view="http://schemas.android.com/apk/res-auto"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:layout_marginBottom="@dimen/card_vertical_margin"
|
|
||||||
android:layout_marginEnd="@dimen/card_horizontal_margin"
|
|
||||||
android:layout_marginStart="@dimen/card_horizontal_margin"
|
|
||||||
android:layout_marginTop="@dimen/card_vertical_margin"
|
|
||||||
style="?attr/cardStyle"
|
|
||||||
android:minHeight="?android:attr/listPreferredItemHeight"
|
|
||||||
card_view:cardCornerRadius="@dimen/card_corner_radius"
|
|
||||||
card_view:cardElevation="@dimen/card_elevation">
|
|
||||||
|
|
||||||
<RelativeLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="fill_parent"
|
|
||||||
android:layout_gravity="center_vertical"
|
|
||||||
android:padding="@dimen/card_layout_padding">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/app_icon"
|
|
||||||
android:layout_width="@dimen/card_appicon_size"
|
|
||||||
android:layout_height="@dimen/card_appicon_size"
|
|
||||||
android:layout_centerVertical="true"
|
|
||||||
android:scaleType="centerCrop"/>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="fill_parent"
|
|
||||||
android:layout_alignBottom="@+id/app_icon"
|
|
||||||
android:gravity="center_horizontal"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:paddingEnd="@dimen/card_appicon_size"
|
|
||||||
android:paddingStart="65dp"
|
|
||||||
android:weightSum="1">
|
|
||||||
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/app_name"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:maxLines="1"
|
|
||||||
android:paddingEnd="3dp"
|
|
||||||
android:paddingStart="3dp"
|
|
||||||
android:textStyle="bold"/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/app_package"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="25dp"
|
|
||||||
android:ellipsize="marquee"
|
|
||||||
android:gravity="center_vertical"
|
|
||||||
android:marqueeRepeatLimit="marquee_forever"
|
|
||||||
android:paddingEnd="3dp"
|
|
||||||
android:paddingStart="3dp"
|
|
||||||
android:singleLine="true"/>
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_alignParentEnd="true"
|
|
||||||
android:layout_centerVertical="true">
|
|
||||||
|
|
||||||
<CheckBox
|
|
||||||
android:id="@+id/checkbox"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:focusable="false"
|
|
||||||
android:gravity="center"
|
|
||||||
android:src="@drawable/ic_menu_overflow_material"
|
|
||||||
android:checked="false" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</RelativeLayout>
|
|
||||||
|
|
||||||
|
|
||||||
</android.support.v7.widget.CardView>
|
|
||||||
|
|
||||||
|
|
@@ -1,9 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<TextView
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:id="@+id/textView"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:fontFamily="monospace"
|
|
||||||
android:textColor="@android:color/white"
|
|
||||||
android:textSize="10sp" />
|
|
@@ -1,178 +0,0 @@
|
|||||||
<resources>
|
|
||||||
<!--Universal-->
|
|
||||||
|
|
||||||
<!--Welcome Activity-->
|
|
||||||
<string name="modules">Moduli</string>
|
|
||||||
<string name="downloads">Download</string>
|
|
||||||
<string name="superuser">Superuser</string>
|
|
||||||
<string name="log">Registro eventi</string>
|
|
||||||
<string name="settings">Impostazioni</string>
|
|
||||||
<string name="install">Installa</string>
|
|
||||||
|
|
||||||
<!--Status Fragment-->
|
|
||||||
<string name="magisk_version_error">Magisk non installato</string>
|
|
||||||
|
|
||||||
<string name="checking_for_updates">Controllo aggiornamenti…</string>
|
|
||||||
<string name="magisk_update_available">È disponibile Magisk v%1$s!</string>
|
|
||||||
<string name="cannot_check_updates">Impossibile controllare aggiornamenti</string>
|
|
||||||
<string name="root_error">Rootato ma senza permessi. Non sei autorizzato?</string>
|
|
||||||
<string name="not_rooted">Non rootato</string>
|
|
||||||
<string name="safetyNet_check_text">Tocca per avviare controllo SafetyNet</string>
|
|
||||||
<string name="checking_safetyNet_status">Controllo stato SafetyNet</string>
|
|
||||||
<string name="safetyNet_check_success">Controllo SafetyNet OK</string>
|
|
||||||
<string name="safetyNet_network_loss">persa conenssioen di rete</string>
|
|
||||||
<string name="safetyNet_service_disconnected">Ils ervizio è stato terminato</string>
|
|
||||||
<string name="safetyNet_res_invalid">La risposta non è valida</string>
|
|
||||||
|
|
||||||
<!--Install Fragment-->
|
|
||||||
<string name="auto_detect">%1$s (auto)</string>
|
|
||||||
<string name="cannot_auto_detect">(impossibile rilevare automaticamente)</string>
|
|
||||||
<string name="boot_image_title">Percorso immagine boot</string>
|
|
||||||
<string name="detect_button">Rileva</string>
|
|
||||||
<string name="advanced_settings_title">Impostazioni avanzate</string>
|
|
||||||
<string name="keep_force_encryption">Mantieni crittografia forzata</string>
|
|
||||||
<string name="keep_dm_verity">Mantieni dm-verity</string>
|
|
||||||
<string name="current_magisk_title">Versione Magisk installata: %1$s</string>
|
|
||||||
<string name="install_magisk_title">Versione Magisk aggiornata: %1$s</string>
|
|
||||||
<string name="uninstall">Disinstalla</string>
|
|
||||||
<string name="uninstall_magisk_title">Disinstalla Magisk</string>
|
|
||||||
<string name="update">Aggiorna %1$s</string>
|
|
||||||
|
|
||||||
<!--Module Fragment-->
|
|
||||||
<string name="no_info_provided">(nessuna informazione)</string>
|
|
||||||
<string name="no_modules_found">Nessun modulo trovato</string>
|
|
||||||
<string name="update_file_created">Il modulo sarà aggiornato al prossimo riavvio</string>
|
|
||||||
<string name="remove_file_created">Il modulo sarà rimosso al prossimo riavvio</string>
|
|
||||||
<string name="remove_file_deleted">Il modulo non sarà rimosso al prossimo riavvio</string>
|
|
||||||
<string name="disable_file_created">Il modulo sarà disattivato al prossimo riavvio</string>
|
|
||||||
<string name="disable_file_removed">Il modulo sarà abilitato al prossimo riavvio</string>
|
|
||||||
<string name="author">Creato da: %1$s</string>
|
|
||||||
|
|
||||||
<!--Repo Fragment-->
|
|
||||||
<string name="update_available">Aggiornamento disponibile</string>
|
|
||||||
<string name="installed">Installato</string>
|
|
||||||
<string name="not_installed">Non installato</string>
|
|
||||||
|
|
||||||
<!--Log Fragment-->
|
|
||||||
<string name="menuSaveToSd">Salva nella SD</string>
|
|
||||||
<string name="menuReload">Ricarica</string>
|
|
||||||
<string name="menuClearLog">Azzera registro eventi</string>
|
|
||||||
<string name="logs_cleared">Registro eventi creato correttamente</string>
|
|
||||||
<string name="log_is_empty">Il registro eventi è vuoto</string>
|
|
||||||
<string name="logs_save_failed">Impossibile scrivere registro eventi nella SD</string>
|
|
||||||
|
|
||||||
<!--About Activity-->
|
|
||||||
<string name="about">Informazioni</string>
|
|
||||||
<string name="app_developers">Sviluppatori</string>
|
|
||||||
<string name="app_developers_"><![CDATA[App creata da <a href="https://github.com/topjohnwu">topjohnwu</a> in collaborazione con <a href="https://github.com/d8ahazard">Digitalhigh</a> e <a href="https://github.com/dvdandroid">Dvdandroid</a>.]]></string>
|
|
||||||
<string name="app_changelog">Novità</string>
|
|
||||||
<string name="translators">Fabb2303 - bovirus</string>
|
|
||||||
<string name="app_version">Versione app</string>
|
|
||||||
<string name="app_source_code">Codice sorgente</string>
|
|
||||||
<string name="donation">Dona</string>
|
|
||||||
<string name="app_translators">Traduttori app</string>
|
|
||||||
<string name="support_thread">Supporto app</string>
|
|
||||||
|
|
||||||
<!--Toasts, Dialogs-->
|
|
||||||
<string name="permissionNotGranted">Questa funzione non sarà operativa senza il permesso di scrittura nella memoria di archiviazione esterna</string>
|
|
||||||
<string name="no_thanks">No grazie</string>
|
|
||||||
<string name="yes">Sì</string>
|
|
||||||
<string name="ok">OK</string>
|
|
||||||
<string name="close">Chiudi</string>
|
|
||||||
<string name="repo_install_title">Installazione %1$s</string>
|
|
||||||
<string name="repo_install_msg">Vuoi installare %1$s ?</string>
|
|
||||||
<string name="download">Download</string>
|
|
||||||
<string name="download_file_error">Errore nel download del file</string>
|
|
||||||
<string name="install_error">Errore di installazione!</string>
|
|
||||||
<string name="invalid_zip">Lo ZIP non è un modulo Magisk!!</string>
|
|
||||||
<string name="reboot">Riavvia</string>
|
|
||||||
<string name="zip_process_msg">Elaborazione file ZIP…</string>
|
|
||||||
<string name="downloading_toast">Download di %1$s</string>
|
|
||||||
<string name="magisk_update_title">Disponibile nuovo aggiornamento Magisk!</string>
|
|
||||||
<string name="settings_reboot_toast">Riavvia per applicare</string>
|
|
||||||
<string name="release_notes">Note di rilascio</string>
|
|
||||||
<string name="repo_cache_cleared">Cache reposititory azzerata</string>
|
|
||||||
<string name="safetyNet_hide_notice">Quest\'app usa SafetyNet\ned è già gestita da MagiskHide</string>
|
|
||||||
<string name="process_error">Errore di elaborazione</string>
|
|
||||||
<string name="internal_storage">Lo ZIP si trova in:\n[memoria interna]%1$s</string>
|
|
||||||
<string name="zip_process_title">Elaborazione</string>
|
|
||||||
<string name="manual_boot_image">Seleziona manualmente l\'immagine di boot!</string>
|
|
||||||
<string name="manager_update_title">Nuovo aggiornamento di Magisk Manager disponibile!</string>
|
|
||||||
<string name="manager_download_install">Premere per scaricare e installare</string>
|
|
||||||
<string name="magisk_updates">Aggiornamenti Magisk</string>
|
|
||||||
<string name="flashing">Flashando</string>
|
|
||||||
|
|
||||||
<!--Settings Activity -->
|
|
||||||
<string name="settings_general_category">Generale</string>
|
|
||||||
<string name="settings_dark_theme_title">Tema scuro</string>
|
|
||||||
<string name="settings_dark_theme_summary">Abilita tema scuro</string>
|
|
||||||
<string name="settings_notification_title">Notifica aggiornamenti</string>
|
|
||||||
<string name="settings_notification_summary">Visualizza notifica quando sono diponibili aggiornamenti</string>
|
|
||||||
<string name="settings_clear_cache_title">Azzera cache repository</string>
|
|
||||||
<string name="settings_clear_cache_summary">Azzera le informazioni nella cache per i repository online, e forza l\'aggiornamento online dell\'app</string>
|
|
||||||
|
|
||||||
<string name="settings_core_only_title">Solo modo core Magisk</string>
|
|
||||||
<string name="settings_core_only_summary">Abilita solo le funzioni principali. Non tutti i moduli verranno caricati. MagiskSU, MagiskHide, e host systemless rimarranno abilitati</string>
|
|
||||||
<string name="settings_magiskhide_summary">Nasconde Magisk da numerose rilevazioni</string>
|
|
||||||
<string name="settings_hosts_title">Host systemless</string>
|
|
||||||
<string name="settings_hosts_summary">Supporto host systemless per app blocco pubblicità</string>
|
|
||||||
|
|
||||||
<string name="settings_su_app_adb">App e ADB</string>
|
|
||||||
<string name="settings_su_app">Solo app</string>
|
|
||||||
<string name="settings_su_adb">Solo ADB</string>
|
|
||||||
<string name="settings_su_disable">Disabilitato</string>
|
|
||||||
<string name="settings_su_request_10">10 secondi</string>
|
|
||||||
<string name="settings_su_request_20">20 secondi</string>
|
|
||||||
<string name="settings_su_request_30">30 secondi</string>
|
|
||||||
<string name="settings_su_request_60">60 secondi</string>
|
|
||||||
<string name="superuser_access">Accesso Superuser</string>
|
|
||||||
<string name="auto_response">Risposta automatica</string>
|
|
||||||
<string name="request_timeout">Timeout richiesta</string>
|
|
||||||
<string name="superuser_notification">Notifica Superuser</string>
|
|
||||||
<string name="request_timeout_summary">%1$s secondi</string>
|
|
||||||
<string name="settings_su_reauth_title">Ri-autentifica dopo aggiornamento</string>
|
|
||||||
<string name="settings_su_reauth_summary">Ri-autentifica permessi superuser dopo aggiornamento applicazione</string>
|
|
||||||
|
|
||||||
<string name="multiuser_mode">Modo multiutente</string>
|
|
||||||
<string name="settings_owner_only">Solo proprietario dispositivo</string>
|
|
||||||
<string name="settings_owner_manage">gestito da propietario utente</string>
|
|
||||||
<string name="settings_user_independent">Utente indipendente</string>
|
|
||||||
<string name="owner_only_summary">Solo proprietario che ha accesso root</string>
|
|
||||||
<string name="owner_manage_summary">Solo il propietario può gestire accesso root e ricevere richieste</string>
|
|
||||||
<string name="user_indepenent_summary">Ogni utente ha le sue regole di root separate</string>
|
|
||||||
<string name="multiuser_hint_owner_request">Una richiestà è stata inviata al propietario dipositivo. Accedi come propietario dispositivo e concedi i permessi.</string>
|
|
||||||
|
|
||||||
<!--Superuser-->
|
|
||||||
<string name="su_request_title">Richiesta Superuser</string>
|
|
||||||
<string name="deny_with_str">Nega %1$s</string>
|
|
||||||
<string name="deny">Nega</string>
|
|
||||||
<string name="prompt">Richiedi</string>
|
|
||||||
<string name="grant">Concedi</string>
|
|
||||||
<string name="su_warning">Concede il pieno accesso al dispositivo.\nNega se non sei sicuro</string>
|
|
||||||
<string name="forever">Sempre</string>
|
|
||||||
<string name="once">Una volta</string>
|
|
||||||
<string name="tenmin">10 minuti</string>
|
|
||||||
<string name="twentymin">20 minuti</string>
|
|
||||||
<string name="thirtymin">30 minuti</string>
|
|
||||||
<string name="sixtymin">60 minuti</string>
|
|
||||||
<string name="su_allow_toast">%1$s HA ottenuto i permessi Superuser</string>
|
|
||||||
<string name="su_deny_toast">%1$s NON ha ottenuto i permessi Superuser</string>
|
|
||||||
<string name="no_apps_found">Nessuna app trovata</string>
|
|
||||||
<string name="su_snack_grant"> %1$s HA ottenuto i permessi Superuser</string>
|
|
||||||
<string name="su_snack_deny"> %1$s NON ha ottenuto i permessi Superuser</string>
|
|
||||||
<string name="su_snack_notif_on">Notifiche per %1$s abilitate</string>
|
|
||||||
<string name="su_snack_notif_off">Notifiche per %1$s disabilitate</string>
|
|
||||||
<string name="su_snack_log_on">Registro eventi abilitato per %1$s</string>
|
|
||||||
<string name="su_snack_log_off">Registro eventi NON abilitato per %1$s</string>
|
|
||||||
<string name="su_snack_revoke">I diritti di %1$s sono stati revocati</string>
|
|
||||||
<string name="su_revoke_title">Revocare?</string>
|
|
||||||
<string name="su_revoke_msg">Confermi la revoca dei diritti di %1$s?</string>
|
|
||||||
<string name="toast">Toast</string>
|
|
||||||
<string name="none">Nessuno</string>
|
|
||||||
|
|
||||||
<!--Superuser logs-->
|
|
||||||
<string name="pid">PID:\u0020</string>
|
|
||||||
<string name="target_uid">UID destinazione:\u0020</string>
|
|
||||||
<string name="command">Comando:\u0020</string>
|
|
||||||
|
|
||||||
</resources>
|
|
77
build.gradle
@@ -1,28 +1,67 @@
|
|||||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
apply plugin: 'com.android.application'
|
||||||
|
|
||||||
buildscript {
|
android {
|
||||||
repositories {
|
compileSdkVersion 27
|
||||||
jcenter()
|
buildToolsVersion "27.0.3"
|
||||||
mavenCentral()
|
|
||||||
maven { url "https://maven.google.com" }
|
defaultConfig {
|
||||||
google()
|
applicationId "com.topjohnwu.magisk"
|
||||||
|
minSdkVersion 21
|
||||||
|
targetSdkVersion 27
|
||||||
|
versionCode 84
|
||||||
|
versionName "5.5.2"
|
||||||
|
ndk {
|
||||||
|
moduleName 'zipadjust'
|
||||||
|
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
|
||||||
|
}
|
||||||
|
javaCompileOptions {
|
||||||
|
annotationProcessorOptions {
|
||||||
|
argument('butterknife.debuggable', 'false')
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
dependencies {
|
|
||||||
classpath 'com.android.tools.build:gradle:3.0.0-rc1'
|
|
||||||
|
|
||||||
// NOTE: Do not place your application dependencies here; they belong
|
buildTypes {
|
||||||
// in the individual module build.gradle files
|
release {
|
||||||
|
minifyEnabled true
|
||||||
|
shrinkResources true
|
||||||
|
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
compileOptions {
|
||||||
|
sourceCompatibility JavaVersion.VERSION_1_8
|
||||||
|
targetCompatibility JavaVersion.VERSION_1_8
|
||||||
|
}
|
||||||
|
dexOptions {
|
||||||
|
preDexLibraries true
|
||||||
|
javaMaxHeapSize "2g"
|
||||||
|
}
|
||||||
|
externalNativeBuild {
|
||||||
|
cmake {
|
||||||
|
path 'src/main/jni/CMakeLists.txt'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lintOptions {
|
||||||
|
disable 'MissingTranslation'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
allprojects {
|
repositories {
|
||||||
repositories {
|
jcenter()
|
||||||
jcenter()
|
google()
|
||||||
maven { url "https://jitpack.io" }
|
maven { url "https://jitpack.io" }
|
||||||
google()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
task clean(type: Delete) {
|
dependencies {
|
||||||
delete rootProject.buildDir
|
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||||
|
implementation project(':crypto')
|
||||||
|
implementation 'com.android.support:recyclerview-v7:27.0.2'
|
||||||
|
implementation 'com.android.support:cardview-v7:27.0.2'
|
||||||
|
implementation 'com.android.support:design:27.0.2'
|
||||||
|
implementation 'com.android.support:support-v4:27.0.2'
|
||||||
|
implementation 'com.jakewharton:butterknife:8.8.1'
|
||||||
|
implementation 'com.atlassian.commonmark:commonmark:0.10.0'
|
||||||
|
implementation 'org.kamranzafar:jtar:2.3'
|
||||||
|
implementation 'com.google.code.gson:gson:2.8.2'
|
||||||
|
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
|
||||||
}
|
}
|
||||||
|
1
common/.gitignore
vendored
@@ -1 +0,0 @@
|
|||||||
/build
|
|
@@ -1,23 +0,0 @@
|
|||||||
apply plugin: 'com.android.library'
|
|
||||||
|
|
||||||
android {
|
|
||||||
compileSdkVersion 26
|
|
||||||
buildToolsVersion "26.0.2"
|
|
||||||
defaultConfig {
|
|
||||||
minSdkVersion 21
|
|
||||||
targetSdkVersion 26
|
|
||||||
versionCode 1
|
|
||||||
versionName "1.0"
|
|
||||||
|
|
||||||
}
|
|
||||||
buildTypes {
|
|
||||||
release {
|
|
||||||
minifyEnabled true
|
|
||||||
proguardFiles getDefaultProguardFile('proguard-android.txt')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
||||||
}
|
|
@@ -1 +0,0 @@
|
|||||||
<manifest package="com.topjohnwu.resource" />
|
|
Before Width: | Height: | Size: 5.8 KiB |
Before Width: | Height: | Size: 3.5 KiB |
Before Width: | Height: | Size: 8.3 KiB |
Before Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 20 KiB |
@@ -1,22 +0,0 @@
|
|||||||
# Project-wide Gradle settings.
|
|
||||||
|
|
||||||
# IDE (e.g. Android Studio) users:
|
|
||||||
# Gradle settings configured through the IDE *will override*
|
|
||||||
# any settings specified in this file.
|
|
||||||
|
|
||||||
# For more details on how to configure your build environment visit
|
|
||||||
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
|
||||||
|
|
||||||
# Specifies the JVM arguments used for the daemon process.
|
|
||||||
# The setting is particularly useful for tweaking memory settings.
|
|
||||||
# Default value: -Xmx10248m -XX:MaxPermSize=256m
|
|
||||||
org.gradle.jvmargs=-Xmx2560m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
|
|
||||||
|
|
||||||
# When configured, Gradle will run in incubating parallel mode.
|
|
||||||
# This option should only be used with decoupled projects. More details, visit
|
|
||||||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
|
||||||
org.gradle.parallel=true
|
|
||||||
|
|
||||||
# When set to true the Gradle daemon is used to run the build. For local developer builds this is our favorite property.
|
|
||||||
# The developer environment is optimized for speed and feedback so we nearly always run Gradle jobs with the daemon.
|
|
||||||
org.gradle.daemon=true
|
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
5
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,5 +0,0 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
|
||||||
distributionPath=wrapper/dists
|
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
|
||||||
zipStorePath=wrapper/dists
|
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.2.1-all.zip
|
|
172
gradlew
vendored
@@ -1,172 +0,0 @@
|
|||||||
#!/usr/bin/env sh
|
|
||||||
|
|
||||||
##############################################################################
|
|
||||||
##
|
|
||||||
## Gradle start up script for UN*X
|
|
||||||
##
|
|
||||||
##############################################################################
|
|
||||||
|
|
||||||
# Attempt to set APP_HOME
|
|
||||||
# Resolve links: $0 may be a link
|
|
||||||
PRG="$0"
|
|
||||||
# Need this for relative symlinks.
|
|
||||||
while [ -h "$PRG" ] ; do
|
|
||||||
ls=`ls -ld "$PRG"`
|
|
||||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
|
||||||
if expr "$link" : '/.*' > /dev/null; then
|
|
||||||
PRG="$link"
|
|
||||||
else
|
|
||||||
PRG=`dirname "$PRG"`"/$link"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
SAVED="`pwd`"
|
|
||||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
|
||||||
APP_HOME="`pwd -P`"
|
|
||||||
cd "$SAVED" >/dev/null
|
|
||||||
|
|
||||||
APP_NAME="Gradle"
|
|
||||||
APP_BASE_NAME=`basename "$0"`
|
|
||||||
|
|
||||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
|
||||||
DEFAULT_JVM_OPTS=""
|
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
|
||||||
MAX_FD="maximum"
|
|
||||||
|
|
||||||
warn () {
|
|
||||||
echo "$*"
|
|
||||||
}
|
|
||||||
|
|
||||||
die () {
|
|
||||||
echo
|
|
||||||
echo "$*"
|
|
||||||
echo
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# OS specific support (must be 'true' or 'false').
|
|
||||||
cygwin=false
|
|
||||||
msys=false
|
|
||||||
darwin=false
|
|
||||||
nonstop=false
|
|
||||||
case "`uname`" in
|
|
||||||
CYGWIN* )
|
|
||||||
cygwin=true
|
|
||||||
;;
|
|
||||||
Darwin* )
|
|
||||||
darwin=true
|
|
||||||
;;
|
|
||||||
MINGW* )
|
|
||||||
msys=true
|
|
||||||
;;
|
|
||||||
NONSTOP* )
|
|
||||||
nonstop=true
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
|
||||||
|
|
||||||
# Determine the Java command to use to start the JVM.
|
|
||||||
if [ -n "$JAVA_HOME" ] ; then
|
|
||||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
|
||||||
# IBM's JDK on AIX uses strange locations for the executables
|
|
||||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
|
||||||
else
|
|
||||||
JAVACMD="$JAVA_HOME/bin/java"
|
|
||||||
fi
|
|
||||||
if [ ! -x "$JAVACMD" ] ; then
|
|
||||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
|
||||||
|
|
||||||
Please set the JAVA_HOME variable in your environment to match the
|
|
||||||
location of your Java installation."
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
JAVACMD="java"
|
|
||||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
|
||||||
|
|
||||||
Please set the JAVA_HOME variable in your environment to match the
|
|
||||||
location of your Java installation."
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Increase the maximum file descriptors if we can.
|
|
||||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
|
||||||
MAX_FD_LIMIT=`ulimit -H -n`
|
|
||||||
if [ $? -eq 0 ] ; then
|
|
||||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
|
||||||
MAX_FD="$MAX_FD_LIMIT"
|
|
||||||
fi
|
|
||||||
ulimit -n $MAX_FD
|
|
||||||
if [ $? -ne 0 ] ; then
|
|
||||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# For Darwin, add options to specify how the application appears in the dock
|
|
||||||
if $darwin; then
|
|
||||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
|
||||||
fi
|
|
||||||
|
|
||||||
# For Cygwin, switch paths to Windows format before running java
|
|
||||||
if $cygwin ; then
|
|
||||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
|
||||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
|
||||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
|
||||||
|
|
||||||
# We build the pattern for arguments to be converted via cygpath
|
|
||||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
|
||||||
SEP=""
|
|
||||||
for dir in $ROOTDIRSRAW ; do
|
|
||||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
|
||||||
SEP="|"
|
|
||||||
done
|
|
||||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
|
||||||
# Add a user-defined pattern to the cygpath arguments
|
|
||||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
|
||||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
|
||||||
fi
|
|
||||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
|
||||||
i=0
|
|
||||||
for arg in "$@" ; do
|
|
||||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
|
||||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
|
||||||
|
|
||||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
|
||||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
|
||||||
else
|
|
||||||
eval `echo args$i`="\"$arg\""
|
|
||||||
fi
|
|
||||||
i=$((i+1))
|
|
||||||
done
|
|
||||||
case $i in
|
|
||||||
(0) set -- ;;
|
|
||||||
(1) set -- "$args0" ;;
|
|
||||||
(2) set -- "$args0" "$args1" ;;
|
|
||||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
|
||||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
|
||||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
|
||||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
|
||||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
|
||||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
|
||||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
|
||||||
esac
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Escape application args
|
|
||||||
save () {
|
|
||||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
|
||||||
echo " "
|
|
||||||
}
|
|
||||||
APP_ARGS=$(save "$@")
|
|
||||||
|
|
||||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
|
||||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
|
||||||
|
|
||||||
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
|
||||||
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
|
|
||||||
cd "$(dirname "$0")"
|
|
||||||
fi
|
|
||||||
|
|
||||||
exec "$JAVACMD" "$@"
|
|
84
gradlew.bat
vendored
@@ -1,84 +0,0 @@
|
|||||||
@if "%DEBUG%" == "" @echo off
|
|
||||||
@rem ##########################################################################
|
|
||||||
@rem
|
|
||||||
@rem Gradle startup script for Windows
|
|
||||||
@rem
|
|
||||||
@rem ##########################################################################
|
|
||||||
|
|
||||||
@rem Set local scope for the variables with windows NT shell
|
|
||||||
if "%OS%"=="Windows_NT" setlocal
|
|
||||||
|
|
||||||
set DIRNAME=%~dp0
|
|
||||||
if "%DIRNAME%" == "" set DIRNAME=.
|
|
||||||
set APP_BASE_NAME=%~n0
|
|
||||||
set APP_HOME=%DIRNAME%
|
|
||||||
|
|
||||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
|
||||||
set DEFAULT_JVM_OPTS=
|
|
||||||
|
|
||||||
@rem Find java.exe
|
|
||||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
|
||||||
|
|
||||||
set JAVA_EXE=java.exe
|
|
||||||
%JAVA_EXE% -version >NUL 2>&1
|
|
||||||
if "%ERRORLEVEL%" == "0" goto init
|
|
||||||
|
|
||||||
echo.
|
|
||||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
|
||||||
echo.
|
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
|
||||||
echo location of your Java installation.
|
|
||||||
|
|
||||||
goto fail
|
|
||||||
|
|
||||||
:findJavaFromJavaHome
|
|
||||||
set JAVA_HOME=%JAVA_HOME:"=%
|
|
||||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
|
||||||
|
|
||||||
if exist "%JAVA_EXE%" goto init
|
|
||||||
|
|
||||||
echo.
|
|
||||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
|
||||||
echo.
|
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
|
||||||
echo location of your Java installation.
|
|
||||||
|
|
||||||
goto fail
|
|
||||||
|
|
||||||
:init
|
|
||||||
@rem Get command-line arguments, handling Windows variants
|
|
||||||
|
|
||||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
|
||||||
|
|
||||||
:win9xME_args
|
|
||||||
@rem Slurp the command line arguments.
|
|
||||||
set CMD_LINE_ARGS=
|
|
||||||
set _SKIP=2
|
|
||||||
|
|
||||||
:win9xME_args_slurp
|
|
||||||
if "x%~1" == "x" goto execute
|
|
||||||
|
|
||||||
set CMD_LINE_ARGS=%*
|
|
||||||
|
|
||||||
:execute
|
|
||||||
@rem Setup the command line
|
|
||||||
|
|
||||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
|
||||||
|
|
||||||
@rem Execute Gradle
|
|
||||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
|
||||||
|
|
||||||
:end
|
|
||||||
@rem End local scope for the variables with windows NT shell
|
|
||||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
|
||||||
|
|
||||||
:fail
|
|
||||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
|
||||||
rem the _cmd.exe /c_ return code!
|
|
||||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
|
||||||
exit /b 1
|
|
||||||
|
|
||||||
:mainEnd
|
|
||||||
if "%OS%"=="Windows_NT" endlocal
|
|
||||||
|
|
||||||
:omega
|
|
1
jarsigner/.gitignore
vendored
@@ -1 +0,0 @@
|
|||||||
/build
|
|
@@ -1,37 +0,0 @@
|
|||||||
apply plugin: 'java-library'
|
|
||||||
|
|
||||||
apply plugin: 'com.github.johnrengelman.shadow'
|
|
||||||
apply plugin: 'java'
|
|
||||||
|
|
||||||
sourceCompatibility = "1.7"
|
|
||||||
targetCompatibility = "1.7"
|
|
||||||
|
|
||||||
jar {
|
|
||||||
manifest {
|
|
||||||
attributes 'Main-Class': 'com.topjohnwu.jarsigner.CommandLine'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
shadowJar {
|
|
||||||
classifier = 'fat'
|
|
||||||
version = null
|
|
||||||
}
|
|
||||||
|
|
||||||
buildscript {
|
|
||||||
repositories {
|
|
||||||
jcenter()
|
|
||||||
}
|
|
||||||
dependencies {
|
|
||||||
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.1'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
repositories {
|
|
||||||
jcenter()
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
|
||||||
implementation 'org.bouncycastle:bcprov-jdk15on:1.58'
|
|
||||||
implementation 'org.bouncycastle:bcpkix-jdk15on:1.58'
|
|
||||||
}
|
|
@@ -1,34 +0,0 @@
|
|||||||
package com.topjohnwu.jarsigner;
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
|
|
||||||
public class ByteArrayStream extends ByteArrayOutputStream {
|
|
||||||
public byte[] getBuf() {
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
public synchronized void readFrom(InputStream is) {
|
|
||||||
readFrom(is, Integer.MAX_VALUE);
|
|
||||||
}
|
|
||||||
public synchronized void readFrom(InputStream is, int len) {
|
|
||||||
int read;
|
|
||||||
byte buffer[] = new byte[4096];
|
|
||||||
try {
|
|
||||||
while ((read = is.read(buffer, 0, len < buffer.length ? len : buffer.length)) > 0) {
|
|
||||||
write(buffer, 0, read);
|
|
||||||
len -= read;
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public synchronized void writeTo(OutputStream out, int off, int len) throws IOException {
|
|
||||||
out.write(buf, off, len);
|
|
||||||
}
|
|
||||||
public ByteArrayInputStream getInputStream() {
|
|
||||||
return new ByteArrayInputStream(buf, 0, count);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,42 +0,0 @@
|
|||||||
package com.topjohnwu.jarsigner;
|
|
||||||
|
|
||||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.security.Security;
|
|
||||||
|
|
||||||
public class CommandLine {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
boolean minSign = false;
|
|
||||||
int argStart = 0;
|
|
||||||
|
|
||||||
if (args.length < 4) {
|
|
||||||
System.err.println("Usage: zipsigner [-m] publickey.x509[.pem] privatekey.pk8 input.jar output.jar");
|
|
||||||
System.exit(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args[0].equals("-m")) {
|
|
||||||
minSign = true;
|
|
||||||
argStart = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
SignAPK.sBouncyCastleProvider = new BouncyCastleProvider();
|
|
||||||
Security.insertProviderAt(SignAPK.sBouncyCastleProvider, 1);
|
|
||||||
|
|
||||||
File pubKey = new File(args[argStart]);
|
|
||||||
File privKey = new File(args[argStart + 1]);
|
|
||||||
File input = new File(args[argStart + 2]);
|
|
||||||
File output = new File(args[argStart + 3]);
|
|
||||||
|
|
||||||
try (InputStream pub = new FileInputStream(pubKey);
|
|
||||||
InputStream priv = new FileInputStream(privKey);
|
|
||||||
JarMap jar = new JarMap(input, false)) {
|
|
||||||
SignAPK.signZip(pub, priv, jar, output, minSign);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,153 +0,0 @@
|
|||||||
package com.topjohnwu.jarsigner;
|
|
||||||
|
|
||||||
import java.io.Closeable;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Enumeration;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.jar.JarEntry;
|
|
||||||
import java.util.jar.JarFile;
|
|
||||||
import java.util.jar.JarInputStream;
|
|
||||||
import java.util.jar.Manifest;
|
|
||||||
import java.util.zip.ZipEntry;
|
|
||||||
import java.util.zip.ZipFile;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* A universal random access interface for both JarFile and JarInputStream
|
|
||||||
*
|
|
||||||
* In the case when JarInputStream is provided to constructor, the whole stream
|
|
||||||
* will be loaded into memory for random access purposes.
|
|
||||||
* On the other hand, when a JarFile is provided, it simply works as a wrapper.
|
|
||||||
* */
|
|
||||||
|
|
||||||
public class JarMap implements Closeable, AutoCloseable {
|
|
||||||
private JarFile jarFile;
|
|
||||||
private JarInputStream jis;
|
|
||||||
private InputStream is;
|
|
||||||
private File file;
|
|
||||||
private boolean isInputStream = false, hasLoaded = false, verify;
|
|
||||||
private LinkedHashMap<String, JarEntry> bufMap = new LinkedHashMap<>();
|
|
||||||
|
|
||||||
public JarMap(File file) throws IOException {
|
|
||||||
this(file, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public JarMap(File file, boolean verify) throws IOException {
|
|
||||||
this(file, verify, ZipFile.OPEN_READ);
|
|
||||||
}
|
|
||||||
|
|
||||||
public JarMap(File file, boolean verify, int mode) throws IOException {
|
|
||||||
this.file = file;
|
|
||||||
jarFile = new JarFile(file, verify, mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
public JarMap(String name) throws IOException {
|
|
||||||
this(new File(name));
|
|
||||||
}
|
|
||||||
|
|
||||||
public JarMap(String name, boolean verify) throws IOException {
|
|
||||||
this(new File(name), verify);
|
|
||||||
}
|
|
||||||
|
|
||||||
public JarMap(InputStream is) throws IOException {
|
|
||||||
this(is, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public JarMap(InputStream is, boolean verify) throws IOException {
|
|
||||||
isInputStream = true;
|
|
||||||
this.is = is;
|
|
||||||
this.verify = verify;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadJarInputStream() {
|
|
||||||
if (!isInputStream || hasLoaded) return;
|
|
||||||
hasLoaded = true;
|
|
||||||
JarEntry entry;
|
|
||||||
try {
|
|
||||||
jis = new JarInputStream(is, verify);
|
|
||||||
while ((entry = jis.getNextJarEntry()) != null) {
|
|
||||||
bufMap.put(entry.getName(), new JarMapEntry(entry, jis));
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public InputStream getInputStream() {
|
|
||||||
try {
|
|
||||||
return isInputStream ? is : new FileInputStream(file);
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Manifest getManifest() throws IOException {
|
|
||||||
loadJarInputStream();
|
|
||||||
return isInputStream ? jis.getManifest() : jarFile.getManifest();
|
|
||||||
}
|
|
||||||
|
|
||||||
public InputStream getInputStream(ZipEntry ze) throws IOException {
|
|
||||||
loadJarInputStream();
|
|
||||||
return isInputStream ? ((JarMapEntry) bufMap.get(ze.getName())).getInputStream() :
|
|
||||||
jarFile.getInputStream(ze);
|
|
||||||
}
|
|
||||||
|
|
||||||
public OutputStream getOutputStream(ZipEntry ze) {
|
|
||||||
if (!isInputStream) // Only support inputstream mode
|
|
||||||
return null;
|
|
||||||
loadJarInputStream();
|
|
||||||
ByteArrayStream bs = ((JarMapEntry) bufMap.get(ze.getName())).data;
|
|
||||||
bs.reset();
|
|
||||||
return bs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] getRawData(ZipEntry ze) throws IOException {
|
|
||||||
if (isInputStream) {
|
|
||||||
loadJarInputStream();
|
|
||||||
return ((JarMapEntry) bufMap.get(ze.getName())).data.toByteArray();
|
|
||||||
} else {
|
|
||||||
ByteArrayStream bytes = new ByteArrayStream();
|
|
||||||
bytes.readFrom(jarFile.getInputStream(ze));
|
|
||||||
return bytes.toByteArray();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Enumeration<JarEntry> entries() {
|
|
||||||
loadJarInputStream();
|
|
||||||
return isInputStream ? Collections.enumeration(bufMap.values()) : jarFile.entries();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ZipEntry getEntry(String name) {
|
|
||||||
return getJarEntry(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public JarEntry getJarEntry(String name) {
|
|
||||||
loadJarInputStream();
|
|
||||||
return isInputStream ? bufMap.get(name) : jarFile.getJarEntry(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() throws IOException {
|
|
||||||
if (isInputStream)
|
|
||||||
is.close();
|
|
||||||
else
|
|
||||||
jarFile.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class JarMapEntry extends JarEntry {
|
|
||||||
ByteArrayStream data;
|
|
||||||
JarMapEntry(JarEntry je, InputStream is) {
|
|
||||||
super(je);
|
|
||||||
data = new ByteArrayStream();
|
|
||||||
data.readFrom(is);
|
|
||||||
}
|
|
||||||
InputStream getInputStream() {
|
|
||||||
return data.getInputStream();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,529 +0,0 @@
|
|||||||
package com.topjohnwu.jarsigner;
|
|
||||||
|
|
||||||
import org.bouncycastle.asn1.ASN1InputStream;
|
|
||||||
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
|
|
||||||
import org.bouncycastle.asn1.DEROutputStream;
|
|
||||||
import org.bouncycastle.asn1.cms.CMSObjectIdentifiers;
|
|
||||||
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
|
|
||||||
import org.bouncycastle.cert.jcajce.JcaCertStore;
|
|
||||||
import org.bouncycastle.cms.CMSException;
|
|
||||||
import org.bouncycastle.cms.CMSProcessableByteArray;
|
|
||||||
import org.bouncycastle.cms.CMSSignedData;
|
|
||||||
import org.bouncycastle.cms.CMSSignedDataGenerator;
|
|
||||||
import org.bouncycastle.cms.CMSTypedData;
|
|
||||||
import org.bouncycastle.cms.jcajce.JcaSignerInfoGeneratorBuilder;
|
|
||||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
|
||||||
import org.bouncycastle.operator.ContentSigner;
|
|
||||||
import org.bouncycastle.operator.OperatorCreationException;
|
|
||||||
import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;
|
|
||||||
import org.bouncycastle.operator.jcajce.JcaDigestCalculatorProviderBuilder;
|
|
||||||
import org.bouncycastle.util.encoders.Base64;
|
|
||||||
|
|
||||||
import java.io.BufferedOutputStream;
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.FilterOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.PrintStream;
|
|
||||||
import java.security.DigestOutputStream;
|
|
||||||
import java.security.GeneralSecurityException;
|
|
||||||
import java.security.KeyFactory;
|
|
||||||
import java.security.MessageDigest;
|
|
||||||
import java.security.PrivateKey;
|
|
||||||
import java.security.Provider;
|
|
||||||
import java.security.Security;
|
|
||||||
import java.security.cert.CertificateEncodingException;
|
|
||||||
import java.security.cert.CertificateFactory;
|
|
||||||
import java.security.cert.X509Certificate;
|
|
||||||
import java.security.spec.PKCS8EncodedKeySpec;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Enumeration;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.TreeMap;
|
|
||||||
import java.util.jar.Attributes;
|
|
||||||
import java.util.jar.JarEntry;
|
|
||||||
import java.util.jar.JarFile;
|
|
||||||
import java.util.jar.JarOutputStream;
|
|
||||||
import java.util.jar.Manifest;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Modified from from AOSP(Marshmallow) SignAPK.java
|
|
||||||
* */
|
|
||||||
|
|
||||||
public class SignAPK {
|
|
||||||
|
|
||||||
private static final String CERT_SF_NAME = "META-INF/CERT.SF";
|
|
||||||
private static final String CERT_SIG_NAME = "META-INF/CERT.%s";
|
|
||||||
|
|
||||||
public static Provider sBouncyCastleProvider;
|
|
||||||
// bitmasks for which hash algorithms we need the manifest to include.
|
|
||||||
private static final int USE_SHA1 = 1;
|
|
||||||
private static final int USE_SHA256 = 2;
|
|
||||||
|
|
||||||
static {
|
|
||||||
SignAPK.sBouncyCastleProvider = new BouncyCastleProvider();
|
|
||||||
Security.insertProviderAt(SignAPK.sBouncyCastleProvider, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void signZip(InputStream publicIn, InputStream privateIn,
|
|
||||||
JarMap input, File output, boolean minSign) throws Exception {
|
|
||||||
int alignment = 4;
|
|
||||||
BufferedOutputStream outputFile;
|
|
||||||
int hashes = 0;
|
|
||||||
X509Certificate publicKey = readPublicKey(publicIn);
|
|
||||||
hashes |= getDigestAlgorithm(publicKey);
|
|
||||||
|
|
||||||
// Set the ZIP file timestamp to the starting valid time
|
|
||||||
// of the 0th certificate plus one hour (to match what
|
|
||||||
// we've historically done).
|
|
||||||
long timestamp = publicKey.getNotBefore().getTime() + 3600L * 1000;
|
|
||||||
PrivateKey privateKey = readPrivateKey(privateIn);
|
|
||||||
|
|
||||||
outputFile = new BufferedOutputStream(new FileOutputStream(output));
|
|
||||||
if (minSign) {
|
|
||||||
signWholeFile(input.getInputStream(), publicKey, privateKey, outputFile);
|
|
||||||
} else {
|
|
||||||
JarOutputStream outputJar = new JarOutputStream(outputFile);
|
|
||||||
// For signing .apks, use the maximum compression to make
|
|
||||||
// them as small as possible (since they live forever on
|
|
||||||
// the system partition). For OTA packages, use the
|
|
||||||
// default compression level, which is much much faster
|
|
||||||
// and produces output that is only a tiny bit larger
|
|
||||||
// (~0.1% on full OTA packages I tested).
|
|
||||||
outputJar.setLevel(9);
|
|
||||||
Manifest manifest = addDigestsToManifest(input, hashes);
|
|
||||||
copyFiles(manifest, input, outputJar, timestamp, alignment);
|
|
||||||
signFile(manifest, input, publicKey, privateKey, outputJar);
|
|
||||||
outputJar.close();
|
|
||||||
}
|
|
||||||
input.close();
|
|
||||||
outputFile.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return one of USE_SHA1 or USE_SHA256 according to the signature
|
|
||||||
* algorithm specified in the cert.
|
|
||||||
*/
|
|
||||||
private static int getDigestAlgorithm(X509Certificate cert) {
|
|
||||||
String sigAlg = cert.getSigAlgName().toUpperCase(Locale.US);
|
|
||||||
if ("SHA1WITHRSA".equals(sigAlg) ||
|
|
||||||
"MD5WITHRSA".equals(sigAlg)) { // see "HISTORICAL NOTE" above.
|
|
||||||
return USE_SHA1;
|
|
||||||
} else if (sigAlg.startsWith("SHA256WITH")) {
|
|
||||||
return USE_SHA256;
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException("unsupported signature algorithm \"" + sigAlg +
|
|
||||||
"\" in cert [" + cert.getSubjectDN());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/** Returns the expected signature algorithm for this key type. */
|
|
||||||
private static String getSignatureAlgorithm(X509Certificate cert) {
|
|
||||||
String sigAlg = cert.getSigAlgName().toUpperCase(Locale.US);
|
|
||||||
String keyType = cert.getPublicKey().getAlgorithm().toUpperCase(Locale.US);
|
|
||||||
if ("RSA".equalsIgnoreCase(keyType)) {
|
|
||||||
if (getDigestAlgorithm(cert) == USE_SHA256) {
|
|
||||||
return "SHA256withRSA";
|
|
||||||
} else {
|
|
||||||
return "SHA1withRSA";
|
|
||||||
}
|
|
||||||
} else if ("EC".equalsIgnoreCase(keyType)) {
|
|
||||||
return "SHA256withECDSA";
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException("unsupported key type: " + keyType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Files matching this pattern are not copied to the output.
|
|
||||||
private static Pattern stripPattern =
|
|
||||||
Pattern.compile("^(META-INF/((.*)[.](SF|RSA|DSA|EC)|com/android/otacert))|(" +
|
|
||||||
Pattern.quote(JarFile.MANIFEST_NAME) + ")$");
|
|
||||||
private static X509Certificate readPublicKey(InputStream input)
|
|
||||||
throws IOException, GeneralSecurityException {
|
|
||||||
try {
|
|
||||||
CertificateFactory cf = CertificateFactory.getInstance("X.509");
|
|
||||||
return (X509Certificate) cf.generateCertificate(input);
|
|
||||||
} finally {
|
|
||||||
input.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Read a PKCS#8 format private key. */
|
|
||||||
private static PrivateKey readPrivateKey(InputStream input)
|
|
||||||
throws IOException, GeneralSecurityException {
|
|
||||||
try {
|
|
||||||
byte[] buffer = new byte[4096];
|
|
||||||
int size = input.read(buffer);
|
|
||||||
byte[] bytes = Arrays.copyOf(buffer, size);
|
|
||||||
/* Check to see if this is in an EncryptedPrivateKeyInfo structure. */
|
|
||||||
PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(bytes);
|
|
||||||
/*
|
|
||||||
* Now it's in a PKCS#8 PrivateKeyInfo structure. Read its Algorithm
|
|
||||||
* OID and use that to construct a KeyFactory.
|
|
||||||
*/
|
|
||||||
ASN1InputStream bIn = new ASN1InputStream(new ByteArrayInputStream(spec.getEncoded()));
|
|
||||||
PrivateKeyInfo pki = PrivateKeyInfo.getInstance(bIn.readObject());
|
|
||||||
String algOid = pki.getPrivateKeyAlgorithm().getAlgorithm().getId();
|
|
||||||
return KeyFactory.getInstance(algOid).generatePrivate(spec);
|
|
||||||
} finally {
|
|
||||||
input.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Add the hash(es) of every file to the manifest, creating it if
|
|
||||||
* necessary.
|
|
||||||
*/
|
|
||||||
private static Manifest addDigestsToManifest(JarMap jar, int hashes)
|
|
||||||
throws IOException, GeneralSecurityException {
|
|
||||||
Manifest input = jar.getManifest();
|
|
||||||
Manifest output = new Manifest();
|
|
||||||
Attributes main = output.getMainAttributes();
|
|
||||||
if (input != null) {
|
|
||||||
main.putAll(input.getMainAttributes());
|
|
||||||
} else {
|
|
||||||
main.putValue("Manifest-Version", "1.0");
|
|
||||||
main.putValue("Created-By", "1.0 (Android SignApk)");
|
|
||||||
}
|
|
||||||
MessageDigest md_sha1 = null;
|
|
||||||
MessageDigest md_sha256 = null;
|
|
||||||
if ((hashes & USE_SHA1) != 0) {
|
|
||||||
md_sha1 = MessageDigest.getInstance("SHA1");
|
|
||||||
}
|
|
||||||
if ((hashes & USE_SHA256) != 0) {
|
|
||||||
md_sha256 = MessageDigest.getInstance("SHA256");
|
|
||||||
}
|
|
||||||
byte[] buffer = new byte[4096];
|
|
||||||
int num;
|
|
||||||
// We sort the input entries by name, and add them to the
|
|
||||||
// output manifest in sorted order. We expect that the output
|
|
||||||
// map will be deterministic.
|
|
||||||
TreeMap<String, JarEntry> byName = new TreeMap<String, JarEntry>();
|
|
||||||
for (Enumeration<JarEntry> e = jar.entries(); e.hasMoreElements(); ) {
|
|
||||||
JarEntry entry = e.nextElement();
|
|
||||||
byName.put(entry.getName(), entry);
|
|
||||||
}
|
|
||||||
for (JarEntry entry: byName.values()) {
|
|
||||||
String name = entry.getName();
|
|
||||||
if (!entry.isDirectory() &&
|
|
||||||
(stripPattern == null || !stripPattern.matcher(name).matches())) {
|
|
||||||
InputStream data = jar.getInputStream(entry);
|
|
||||||
while ((num = data.read(buffer)) > 0) {
|
|
||||||
if (md_sha1 != null) md_sha1.update(buffer, 0, num);
|
|
||||||
if (md_sha256 != null) md_sha256.update(buffer, 0, num);
|
|
||||||
}
|
|
||||||
Attributes attr = null;
|
|
||||||
if (input != null) attr = input.getAttributes(name);
|
|
||||||
attr = attr != null ? new Attributes(attr) : new Attributes();
|
|
||||||
if (md_sha1 != null) {
|
|
||||||
attr.putValue("SHA1-Digest",
|
|
||||||
new String(Base64.encode(md_sha1.digest()), "ASCII"));
|
|
||||||
}
|
|
||||||
if (md_sha256 != null) {
|
|
||||||
attr.putValue("SHA-256-Digest",
|
|
||||||
new String(Base64.encode(md_sha256.digest()), "ASCII"));
|
|
||||||
}
|
|
||||||
output.getEntries().put(name, attr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Write to another stream and track how many bytes have been
|
|
||||||
* written.
|
|
||||||
*/
|
|
||||||
private static class CountOutputStream extends FilterOutputStream {
|
|
||||||
private int mCount;
|
|
||||||
public CountOutputStream(OutputStream out) {
|
|
||||||
super(out);
|
|
||||||
mCount = 0;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void write(int b) throws IOException {
|
|
||||||
super.write(b);
|
|
||||||
mCount++;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void write(byte[] b, int off, int len) throws IOException {
|
|
||||||
super.write(b, off, len);
|
|
||||||
mCount += len;
|
|
||||||
}
|
|
||||||
public int size() {
|
|
||||||
return mCount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/** Write a .SF file with a digest of the specified manifest. */
|
|
||||||
private static void writeSignatureFile(Manifest manifest, OutputStream out,
|
|
||||||
int hash)
|
|
||||||
throws IOException, GeneralSecurityException {
|
|
||||||
Manifest sf = new Manifest();
|
|
||||||
Attributes main = sf.getMainAttributes();
|
|
||||||
main.putValue("Signature-Version", "1.0");
|
|
||||||
main.putValue("Created-By", "1.0 (Android SignApk)");
|
|
||||||
MessageDigest md = MessageDigest.getInstance(
|
|
||||||
hash == USE_SHA256 ? "SHA256" : "SHA1");
|
|
||||||
PrintStream print = new PrintStream(
|
|
||||||
new DigestOutputStream(new ByteArrayOutputStream(), md),
|
|
||||||
true, "UTF-8");
|
|
||||||
// Digest of the entire manifest
|
|
||||||
manifest.write(print);
|
|
||||||
print.flush();
|
|
||||||
main.putValue(hash == USE_SHA256 ? "SHA-256-Digest-Manifest" : "SHA1-Digest-Manifest",
|
|
||||||
new String(Base64.encode(md.digest()), "ASCII"));
|
|
||||||
Map<String, Attributes> entries = manifest.getEntries();
|
|
||||||
for (Map.Entry<String, Attributes> entry : entries.entrySet()) {
|
|
||||||
// Digest of the manifest stanza for this entry.
|
|
||||||
print.print("Name: " + entry.getKey() + "\r\n");
|
|
||||||
for (Map.Entry<Object, Object> att : entry.getValue().entrySet()) {
|
|
||||||
print.print(att.getKey() + ": " + att.getValue() + "\r\n");
|
|
||||||
}
|
|
||||||
print.print("\r\n");
|
|
||||||
print.flush();
|
|
||||||
Attributes sfAttr = new Attributes();
|
|
||||||
sfAttr.putValue(hash == USE_SHA256 ? "SHA-256-Digest" : "SHA1-Digest-Manifest",
|
|
||||||
new String(Base64.encode(md.digest()), "ASCII"));
|
|
||||||
sf.getEntries().put(entry.getKey(), sfAttr);
|
|
||||||
}
|
|
||||||
CountOutputStream cout = new CountOutputStream(out);
|
|
||||||
sf.write(cout);
|
|
||||||
// A bug in the java.util.jar implementation of Android platforms
|
|
||||||
// up to version 1.6 will cause a spurious IOException to be thrown
|
|
||||||
// if the length of the signature file is a multiple of 1024 bytes.
|
|
||||||
// As a workaround, add an extra CRLF in this case.
|
|
||||||
if ((cout.size() % 1024) == 0) {
|
|
||||||
cout.write('\r');
|
|
||||||
cout.write('\n');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/** Sign data and write the digital signature to 'out'. */
|
|
||||||
private static void writeSignatureBlock(
|
|
||||||
CMSTypedData data, X509Certificate publicKey, PrivateKey privateKey,
|
|
||||||
OutputStream out)
|
|
||||||
throws IOException,
|
|
||||||
CertificateEncodingException,
|
|
||||||
OperatorCreationException,
|
|
||||||
CMSException {
|
|
||||||
ArrayList<X509Certificate> certList = new ArrayList<>(1);
|
|
||||||
certList.add(publicKey);
|
|
||||||
JcaCertStore certs = new JcaCertStore(certList);
|
|
||||||
CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
|
|
||||||
ContentSigner signer = new JcaContentSignerBuilder(getSignatureAlgorithm(publicKey))
|
|
||||||
.setProvider(sBouncyCastleProvider)
|
|
||||||
.build(privateKey);
|
|
||||||
gen.addSignerInfoGenerator(
|
|
||||||
new JcaSignerInfoGeneratorBuilder(
|
|
||||||
new JcaDigestCalculatorProviderBuilder()
|
|
||||||
.setProvider(sBouncyCastleProvider)
|
|
||||||
.build())
|
|
||||||
.setDirectSignature(true)
|
|
||||||
.build(signer, publicKey));
|
|
||||||
gen.addCertificates(certs);
|
|
||||||
CMSSignedData sigData = gen.generate(data, false);
|
|
||||||
ASN1InputStream asn1 = new ASN1InputStream(sigData.getEncoded());
|
|
||||||
DEROutputStream dos = new DEROutputStream(out);
|
|
||||||
dos.writeObject(asn1.readObject());
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Copy all the files in a manifest from input to output. We set
|
|
||||||
* the modification times in the output to a fixed time, so as to
|
|
||||||
* reduce variation in the output file and make incremental OTAs
|
|
||||||
* more efficient.
|
|
||||||
*/
|
|
||||||
private static void copyFiles(Manifest manifest, JarMap in, JarOutputStream out,
|
|
||||||
long timestamp, int alignment) throws IOException {
|
|
||||||
byte[] buffer = new byte[4096];
|
|
||||||
int num;
|
|
||||||
Map<String, Attributes> entries = manifest.getEntries();
|
|
||||||
ArrayList<String> names = new ArrayList<>(entries.keySet());
|
|
||||||
Collections.sort(names);
|
|
||||||
boolean firstEntry = true;
|
|
||||||
long offset = 0L;
|
|
||||||
// We do the copy in two passes -- first copying all the
|
|
||||||
// entries that are STORED, then copying all the entries that
|
|
||||||
// have any other compression flag (which in practice means
|
|
||||||
// DEFLATED). This groups all the stored entries together at
|
|
||||||
// the start of the file and makes it easier to do alignment
|
|
||||||
// on them (since only stored entries are aligned).
|
|
||||||
for (String name : names) {
|
|
||||||
JarEntry inEntry = in.getJarEntry(name);
|
|
||||||
JarEntry outEntry = null;
|
|
||||||
if (inEntry.getMethod() != JarEntry.STORED) continue;
|
|
||||||
// Preserve the STORED method of the input entry.
|
|
||||||
outEntry = new JarEntry(inEntry);
|
|
||||||
outEntry.setTime(timestamp);
|
|
||||||
// 'offset' is the offset into the file at which we expect
|
|
||||||
// the file data to begin. This is the value we need to
|
|
||||||
// make a multiple of 'alignement'.
|
|
||||||
offset += JarFile.LOCHDR + outEntry.getName().length();
|
|
||||||
if (firstEntry) {
|
|
||||||
// The first entry in a jar file has an extra field of
|
|
||||||
// four bytes that you can't get rid of; any extra
|
|
||||||
// data you specify in the JarEntry is appended to
|
|
||||||
// these forced four bytes. This is JAR_MAGIC in
|
|
||||||
// JarOutputStream; the bytes are 0xfeca0000.
|
|
||||||
offset += 4;
|
|
||||||
firstEntry = false;
|
|
||||||
}
|
|
||||||
if (alignment > 0 && (offset % alignment != 0)) {
|
|
||||||
// Set the "extra data" of the entry to between 1 and
|
|
||||||
// alignment-1 bytes, to make the file data begin at
|
|
||||||
// an aligned offset.
|
|
||||||
int needed = alignment - (int)(offset % alignment);
|
|
||||||
outEntry.setExtra(new byte[needed]);
|
|
||||||
offset += needed;
|
|
||||||
}
|
|
||||||
out.putNextEntry(outEntry);
|
|
||||||
InputStream data = in.getInputStream(inEntry);
|
|
||||||
while ((num = data.read(buffer)) > 0) {
|
|
||||||
out.write(buffer, 0, num);
|
|
||||||
offset += num;
|
|
||||||
}
|
|
||||||
out.flush();
|
|
||||||
}
|
|
||||||
// Copy all the non-STORED entries. We don't attempt to
|
|
||||||
// maintain the 'offset' variable past this point; we don't do
|
|
||||||
// alignment on these entries.
|
|
||||||
for (String name : names) {
|
|
||||||
JarEntry inEntry = in.getJarEntry(name);
|
|
||||||
JarEntry outEntry = null;
|
|
||||||
if (inEntry.getMethod() == JarEntry.STORED) continue;
|
|
||||||
// Create a new entry so that the compressed len is recomputed.
|
|
||||||
outEntry = new JarEntry(name);
|
|
||||||
outEntry.setTime(timestamp);
|
|
||||||
out.putNextEntry(outEntry);
|
|
||||||
InputStream data = in.getInputStream(inEntry);
|
|
||||||
while ((num = data.read(buffer)) > 0) {
|
|
||||||
out.write(buffer, 0, num);
|
|
||||||
}
|
|
||||||
out.flush();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// This class is to provide a file's content, but trimming out the last two bytes
|
|
||||||
// Used for signWholeFile
|
|
||||||
private static class CMSProcessableFile implements CMSTypedData {
|
|
||||||
|
|
||||||
private InputStream is;
|
|
||||||
private ASN1ObjectIdentifier type;
|
|
||||||
ByteArrayStream bos;
|
|
||||||
|
|
||||||
CMSProcessableFile(InputStream is) {
|
|
||||||
this.is = is;
|
|
||||||
type = new ASN1ObjectIdentifier(CMSObjectIdentifiers.data.getId());
|
|
||||||
bos = new ByteArrayStream();
|
|
||||||
bos.readFrom(is);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ASN1ObjectIdentifier getContentType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void write(OutputStream out) throws IOException, CMSException {
|
|
||||||
bos.writeTo(out, 0, bos.size() - 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getContent() {
|
|
||||||
return is;
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] getTail() {
|
|
||||||
return Arrays.copyOfRange(bos.getBuf(), bos.size() - 22, bos.size());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void signWholeFile(InputStream input, X509Certificate publicKey,
|
|
||||||
PrivateKey privateKey, OutputStream outputStream)
|
|
||||||
throws Exception {
|
|
||||||
ByteArrayOutputStream temp = new ByteArrayOutputStream();
|
|
||||||
// put a readable message and a null char at the start of the
|
|
||||||
// archive comment, so that tools that display the comment
|
|
||||||
// (hopefully) show something sensible.
|
|
||||||
// TODO: anything more useful we can put in this message?
|
|
||||||
byte[] message = "signed by SignApk".getBytes("UTF-8");
|
|
||||||
temp.write(message);
|
|
||||||
temp.write(0);
|
|
||||||
|
|
||||||
CMSProcessableFile cmsFile = new CMSProcessableFile(input);
|
|
||||||
writeSignatureBlock(cmsFile, publicKey, privateKey, temp);
|
|
||||||
|
|
||||||
// For a zip with no archive comment, the
|
|
||||||
// end-of-central-directory record will be 22 bytes long, so
|
|
||||||
// we expect to find the EOCD marker 22 bytes from the end.
|
|
||||||
byte[] zipData = cmsFile.getTail();
|
|
||||||
if (zipData[zipData.length-22] != 0x50 ||
|
|
||||||
zipData[zipData.length-21] != 0x4b ||
|
|
||||||
zipData[zipData.length-20] != 0x05 ||
|
|
||||||
zipData[zipData.length-19] != 0x06) {
|
|
||||||
throw new IllegalArgumentException("zip data already has an archive comment");
|
|
||||||
}
|
|
||||||
int total_size = temp.size() + 6;
|
|
||||||
if (total_size > 0xffff) {
|
|
||||||
throw new IllegalArgumentException("signature is too big for ZIP file comment");
|
|
||||||
}
|
|
||||||
// signature starts this many bytes from the end of the file
|
|
||||||
int signature_start = total_size - message.length - 1;
|
|
||||||
temp.write(signature_start & 0xff);
|
|
||||||
temp.write((signature_start >> 8) & 0xff);
|
|
||||||
// Why the 0xff bytes? In a zip file with no archive comment,
|
|
||||||
// bytes [-6:-2] of the file are the little-endian offset from
|
|
||||||
// the start of the file to the central directory. So for the
|
|
||||||
// two high bytes to be 0xff 0xff, the archive would have to
|
|
||||||
// be nearly 4GB in size. So it's unlikely that a real
|
|
||||||
// commentless archive would have 0xffs here, and lets us tell
|
|
||||||
// an old signed archive from a new one.
|
|
||||||
temp.write(0xff);
|
|
||||||
temp.write(0xff);
|
|
||||||
temp.write(total_size & 0xff);
|
|
||||||
temp.write((total_size >> 8) & 0xff);
|
|
||||||
temp.flush();
|
|
||||||
// Signature verification checks that the EOCD header is the
|
|
||||||
// last such sequence in the file (to avoid minzip finding a
|
|
||||||
// fake EOCD appended after the signature in its scan). The
|
|
||||||
// odds of producing this sequence by chance are very low, but
|
|
||||||
// let's catch it here if it does.
|
|
||||||
byte[] b = temp.toByteArray();
|
|
||||||
for (int i = 0; i < b.length-3; ++i) {
|
|
||||||
if (b[i] == 0x50 && b[i+1] == 0x4b && b[i+2] == 0x05 && b[i+3] == 0x06) {
|
|
||||||
throw new IllegalArgumentException("found spurious EOCD header at " + i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cmsFile.write(outputStream);
|
|
||||||
outputStream.write(total_size & 0xff);
|
|
||||||
outputStream.write((total_size >> 8) & 0xff);
|
|
||||||
temp.writeTo(outputStream);
|
|
||||||
}
|
|
||||||
private static void signFile(Manifest manifest, JarMap inputJar,
|
|
||||||
X509Certificate publicKey, PrivateKey privateKey,
|
|
||||||
JarOutputStream outputJar)
|
|
||||||
throws Exception {
|
|
||||||
// Assume the certificate is valid for at least an hour.
|
|
||||||
long timestamp = publicKey.getNotBefore().getTime() + 3600L * 1000;
|
|
||||||
// MANIFEST.MF
|
|
||||||
JarEntry je = new JarEntry(JarFile.MANIFEST_NAME);
|
|
||||||
je.setTime(timestamp);
|
|
||||||
outputJar.putNextEntry(je);
|
|
||||||
manifest.write(outputJar);
|
|
||||||
je = new JarEntry(CERT_SF_NAME);
|
|
||||||
je.setTime(timestamp);
|
|
||||||
outputJar.putNextEntry(je);
|
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
||||||
writeSignatureFile(manifest, baos, getDigestAlgorithm(publicKey));
|
|
||||||
byte[] signedData = baos.toByteArray();
|
|
||||||
outputJar.write(signedData);
|
|
||||||
// CERT.{EC,RSA} / CERT#.{EC,RSA}
|
|
||||||
final String keyType = publicKey.getPublicKey().getAlgorithm();
|
|
||||||
je = new JarEntry(String.format(CERT_SIG_NAME, keyType));
|
|
||||||
je.setTime(timestamp);
|
|
||||||
outputJar.putNextEntry(je);
|
|
||||||
writeSignatureBlock(new CMSProcessableByteArray(signedData),
|
|
||||||
publicKey, privateKey, outputJar);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1 +0,0 @@
|
|||||||
include ':app', ':unhide', ':common', ':snet', ':jarsigner'
|
|
1
snet/.gitignore
vendored
@@ -1 +0,0 @@
|
|||||||
/build
|
|
@@ -1,27 +0,0 @@
|
|||||||
apply plugin: 'com.android.application'
|
|
||||||
|
|
||||||
android {
|
|
||||||
compileSdkVersion 26
|
|
||||||
buildToolsVersion "26.0.2"
|
|
||||||
|
|
||||||
defaultConfig {
|
|
||||||
applicationId "com.topjohnwu.sn"
|
|
||||||
minSdkVersion 21
|
|
||||||
targetSdkVersion 26
|
|
||||||
versionCode 1
|
|
||||||
versionName "1.0"
|
|
||||||
}
|
|
||||||
|
|
||||||
buildTypes {
|
|
||||||
release {
|
|
||||||
minifyEnabled true
|
|
||||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
||||||
implementation 'com.google.android.gms:play-services-safetynet:11.4.2'
|
|
||||||
}
|
|
24
snet/proguard-rules.pro
vendored
@@ -1,24 +0,0 @@
|
|||||||
# Add project specific ProGuard rules here.
|
|
||||||
# You can control the set of applied configuration files using the
|
|
||||||
# proguardFiles setting in build.gradle.
|
|
||||||
#
|
|
||||||
# For more details, see
|
|
||||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
|
||||||
|
|
||||||
# If your project uses WebView with JS, uncomment the following
|
|
||||||
# and specify the fully qualified class name to the JavaScript interface
|
|
||||||
# class:
|
|
||||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
|
||||||
# public *;
|
|
||||||
#}
|
|
||||||
|
|
||||||
# Uncomment this to preserve the line number information for
|
|
||||||
# debugging stack traces.
|
|
||||||
#-keepattributes SourceFile,LineNumberTable
|
|
||||||
|
|
||||||
# If you keep the line number information, uncomment this to
|
|
||||||
# hide the original source file name.
|
|
||||||
#-renamesourcefileattribute SourceFile
|
|
||||||
|
|
||||||
-keep class com.topjohnwu.snet.SafetyNet* { *; }
|
|
||||||
-dontwarn java.lang.invoke**
|
|
@@ -1,7 +0,0 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
package="com.topjohnwu.snet">
|
|
||||||
|
|
||||||
<meta-data
|
|
||||||
android:name="com.google.android.gms.version"
|
|
||||||
android:value="@integer/google_play_services_version" />
|
|
||||||
</manifest>
|
|
@@ -1,5 +0,0 @@
|
|||||||
package com.topjohnwu.snet;
|
|
||||||
|
|
||||||
public interface SafetyNetCallback {
|
|
||||||
void onResponse(int responseCode);
|
|
||||||
}
|
|
@@ -1,118 +0,0 @@
|
|||||||
package com.topjohnwu.snet;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.support.annotation.NonNull;
|
|
||||||
import android.support.annotation.Nullable;
|
|
||||||
import android.util.Base64;
|
|
||||||
|
|
||||||
import com.google.android.gms.common.ConnectionResult;
|
|
||||||
import com.google.android.gms.common.api.GoogleApiClient;
|
|
||||||
import com.google.android.gms.common.api.ResultCallback;
|
|
||||||
import com.google.android.gms.common.api.Status;
|
|
||||||
import com.google.android.gms.safetynet.SafetyNet;
|
|
||||||
import com.google.android.gms.safetynet.SafetyNetApi;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.security.SecureRandom;
|
|
||||||
|
|
||||||
public class SafetyNetHelper
|
|
||||||
implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
|
|
||||||
|
|
||||||
public static final int CONNECTION_FAIL = -1;
|
|
||||||
|
|
||||||
public static final int CAUSE_SERVICE_DISCONNECTED = 0x00001;
|
|
||||||
public static final int CAUSE_NETWORK_LOST = 0x00010;
|
|
||||||
public static final int RESPONSE_ERR = 0x00100;
|
|
||||||
|
|
||||||
public static final int BASIC_PASS = 0x01000;
|
|
||||||
public static final int CTS_PASS = 0x10000;
|
|
||||||
|
|
||||||
private GoogleApiClient mGoogleApiClient;
|
|
||||||
private Context mActivity;
|
|
||||||
private int responseCode;
|
|
||||||
private SafetyNetCallback cb;
|
|
||||||
|
|
||||||
public SafetyNetHelper(Context context, SafetyNetCallback cb) {
|
|
||||||
mActivity = context;
|
|
||||||
this.cb = cb;
|
|
||||||
responseCode = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Entry point to start test
|
|
||||||
public void attest() {
|
|
||||||
// Connect Google Service
|
|
||||||
GoogleApiClient.Builder builder = new GoogleApiClient.Builder(mActivity);
|
|
||||||
try {
|
|
||||||
// Use reflection to workaround FragmentActivity crap
|
|
||||||
Class<?> clazz = Class.forName("com.google.android.gms.common.api.GoogleApiClient$Builder");
|
|
||||||
for (Method m : clazz.getMethods()) {
|
|
||||||
if (m.getName().equals("enableAutoManage")) {
|
|
||||||
m.invoke(builder, mActivity, this);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
mGoogleApiClient = builder.addApi(SafetyNet.API).addConnectionCallbacks(this).build();
|
|
||||||
mGoogleApiClient.connect();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onConnectionSuspended(int i) {
|
|
||||||
cb.onResponse(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
|
|
||||||
cb.onResponse(CONNECTION_FAIL);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onConnected(@Nullable Bundle bundle) {
|
|
||||||
// Create nonce
|
|
||||||
byte[] nonce = new byte[24];
|
|
||||||
new SecureRandom().nextBytes(nonce);
|
|
||||||
|
|
||||||
// Call SafetyNet
|
|
||||||
SafetyNet.SafetyNetApi.attest(mGoogleApiClient, nonce)
|
|
||||||
.setResultCallback(new ResultCallback<SafetyNetApi.AttestationResult>() {
|
|
||||||
@Override
|
|
||||||
public void onResult(@NonNull SafetyNetApi.AttestationResult result) {
|
|
||||||
Status status = result.getStatus();
|
|
||||||
try {
|
|
||||||
if (!status.isSuccess()) throw new JSONException("");
|
|
||||||
String json = new String(Base64.decode(
|
|
||||||
result.getJwsResult().split("\\.")[1], Base64.DEFAULT));
|
|
||||||
JSONObject decoded = new JSONObject(json);
|
|
||||||
responseCode |= decoded.getBoolean("ctsProfileMatch") ? CTS_PASS : 0;
|
|
||||||
responseCode |= decoded.getBoolean("basicIntegrity") ? BASIC_PASS : 0;
|
|
||||||
} catch (JSONException e) {
|
|
||||||
cb.onResponse(RESPONSE_ERR);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Disconnect
|
|
||||||
try {
|
|
||||||
// Use reflection to workaround FragmentActivity crap
|
|
||||||
Class<?> clazz = Class.forName("com.google.android.gms.common.api.GoogleApiClient");
|
|
||||||
for (Method m : clazz.getMethods()) {
|
|
||||||
if (m.getName().equals("stopAutoManage")) {
|
|
||||||
m.invoke(mGoogleApiClient, mActivity, this);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
mGoogleApiClient.disconnect();
|
|
||||||
|
|
||||||
// Return results
|
|
||||||
cb.onResponse(responseCode);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@@ -14,6 +14,7 @@
|
|||||||
android:name=".MagiskManager"
|
android:name=".MagiskManager"
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/AppTheme"
|
android:theme="@style/AppTheme"
|
||||||
@@ -51,11 +52,6 @@
|
|||||||
android:excludeFromRecents="true"
|
android:excludeFromRecents="true"
|
||||||
android:launchMode="singleTask"
|
android:launchMode="singleTask"
|
||||||
android:taskAffinity="internal.superuser"
|
android:taskAffinity="internal.superuser"
|
||||||
android:theme="@android:style/Theme.NoDisplay" />
|
|
||||||
<activity
|
|
||||||
android:name=".superuser.SuRequestActivity"
|
|
||||||
android:excludeFromRecents="true"
|
|
||||||
android:taskAffinity="internal.superuser"
|
|
||||||
android:theme="@style/SuRequest" />
|
android:theme="@style/SuRequest" />
|
||||||
|
|
||||||
<receiver android:name=".superuser.SuReceiver" />
|
<receiver android:name=".superuser.SuReceiver" />
|
||||||
@@ -73,6 +69,7 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
<receiver android:name=".receivers.ManagerUpdate" />
|
<receiver android:name=".receivers.ManagerUpdate" />
|
||||||
|
<receiver android:name=".receivers.RebootReceiver" />
|
||||||
|
|
||||||
<service android:name=".services.OnBootIntentService" />
|
<service android:name=".services.OnBootIntentService" />
|
||||||
<service
|
<service
|
||||||
@@ -93,7 +90,7 @@
|
|||||||
<!-- Hardcode GMS version -->
|
<!-- Hardcode GMS version -->
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="com.google.android.gms.version"
|
android:name="com.google.android.gms.version"
|
||||||
android:value="11400000" />
|
android:value="7095000" />
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
4
src/main/assets/changelog.md
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
### v5.5.2
|
||||||
|
- Support sorting online repos with last update
|
||||||
|
- Fix issue that advanced installation settings won't stick
|
||||||
|
- Prevent sudb crashing Magisk Manager
|
@@ -4,7 +4,7 @@ body {
|
|||||||
line-height: 1.6;
|
line-height: 1.6;
|
||||||
padding-top: 10px;
|
padding-top: 10px;
|
||||||
padding-bottom: 10px;
|
padding-bottom: 10px;
|
||||||
background-color: #303030;
|
background-color: #424242;
|
||||||
color: white;
|
color: white;
|
||||||
padding: 15px; }
|
padding: 15px; }
|
||||||
|
|
BIN
src/main/ic_launcher-web.png
Normal file
After Width: | Height: | Size: 57 KiB |
86
src/main/java/com/topjohnwu/magisk/AboutActivity.java
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
package com.topjohnwu.magisk;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.v7.app.ActionBar;
|
||||||
|
import android.support.v7.widget.Toolbar;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import com.topjohnwu.magisk.asyncs.MarkDownWindow;
|
||||||
|
import com.topjohnwu.magisk.components.AboutCardRow;
|
||||||
|
import com.topjohnwu.magisk.components.Activity;
|
||||||
|
import com.topjohnwu.magisk.utils.Const;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import butterknife.BindView;
|
||||||
|
import butterknife.ButterKnife;
|
||||||
|
|
||||||
|
public class AboutActivity extends Activity {
|
||||||
|
|
||||||
|
@BindView(R.id.toolbar) Toolbar toolbar;
|
||||||
|
@BindView(R.id.app_version_info) AboutCardRow appVersionInfo;
|
||||||
|
@BindView(R.id.app_changelog) AboutCardRow appChangelog;
|
||||||
|
@BindView(R.id.app_translators) AboutCardRow appTranslators;
|
||||||
|
@BindView(R.id.app_source_code) AboutCardRow appSourceCode;
|
||||||
|
@BindView(R.id.support_thread) AboutCardRow supportThread;
|
||||||
|
@BindView(R.id.donation) AboutCardRow donation;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getDarkTheme() {
|
||||||
|
return R.style.AppTheme_Transparent_Dark;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_about);
|
||||||
|
ButterKnife.bind(this);
|
||||||
|
|
||||||
|
setSupportActionBar(toolbar);
|
||||||
|
toolbar.setNavigationOnClickListener(view -> finish());
|
||||||
|
|
||||||
|
ActionBar ab = getSupportActionBar();
|
||||||
|
if (ab != null) {
|
||||||
|
ab.setTitle(R.string.about);
|
||||||
|
ab.setDisplayHomeAsUpEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
appVersionInfo.setSummary(String.format(Locale.US, "%s (%d) (%s)",
|
||||||
|
BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE, getPackageName()));
|
||||||
|
|
||||||
|
appChangelog.removeSummary();
|
||||||
|
appChangelog.setOnClickListener(v -> {
|
||||||
|
try {
|
||||||
|
InputStream is = getAssets().open("changelog.md");
|
||||||
|
new MarkDownWindow(this, getString(R.string.app_changelog), is).exec();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
String translators = getString(R.string.translators);
|
||||||
|
if (TextUtils.isEmpty(translators)) {
|
||||||
|
appTranslators.setVisibility(View.GONE);
|
||||||
|
} else {
|
||||||
|
appTranslators.setSummary(translators);
|
||||||
|
}
|
||||||
|
|
||||||
|
appSourceCode.removeSummary();
|
||||||
|
appSourceCode.setOnClickListener(view -> startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Const.Url.SOURCE_CODE_URL))));
|
||||||
|
|
||||||
|
supportThread.removeSummary();
|
||||||
|
supportThread.setOnClickListener(view -> startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Const.Url.XDA_THREAD))));
|
||||||
|
|
||||||
|
donation.removeSummary();
|
||||||
|
donation.setOnClickListener(view -> startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Const.Url.DONATION_URL))));
|
||||||
|
|
||||||
|
setFloating();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
131
src/main/java/com/topjohnwu/magisk/FlashActivity.java
Normal file
@@ -0,0 +1,131 @@
|
|||||||
|
package com.topjohnwu.magisk;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v7.app.ActionBar;
|
||||||
|
import android.support.v7.widget.Toolbar;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.ScrollView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.topjohnwu.magisk.asyncs.FlashZip;
|
||||||
|
import com.topjohnwu.magisk.asyncs.InstallMagisk;
|
||||||
|
import com.topjohnwu.magisk.components.Activity;
|
||||||
|
import com.topjohnwu.magisk.container.CallbackList;
|
||||||
|
import com.topjohnwu.magisk.utils.Const;
|
||||||
|
import com.topjohnwu.magisk.utils.Shell;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import butterknife.BindView;
|
||||||
|
import butterknife.ButterKnife;
|
||||||
|
import butterknife.OnClick;
|
||||||
|
|
||||||
|
public class FlashActivity extends Activity {
|
||||||
|
|
||||||
|
@BindView(R.id.toolbar) Toolbar toolbar;
|
||||||
|
@BindView(R.id.txtLog) TextView flashLogs;
|
||||||
|
@BindView(R.id.button_panel) public LinearLayout buttonPanel;
|
||||||
|
@BindView(R.id.reboot) public Button reboot;
|
||||||
|
@BindView(R.id.scrollView) ScrollView sv;
|
||||||
|
|
||||||
|
private List<String> logs;
|
||||||
|
|
||||||
|
@OnClick(R.id.no_thanks)
|
||||||
|
void dismiss() {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnClick(R.id.reboot)
|
||||||
|
void reboot() {
|
||||||
|
Shell.su_raw("/system/bin/reboot");
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnClick(R.id.save_logs)
|
||||||
|
void saveLogs() {
|
||||||
|
Calendar now = Calendar.getInstance();
|
||||||
|
String filename = String.format(Locale.US,
|
||||||
|
"install_log_%04d%02d%02d_%02d%02d%02d.log",
|
||||||
|
now.get(Calendar.YEAR), now.get(Calendar.MONTH) + 1,
|
||||||
|
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);
|
||||||
|
logFile.getParentFile().mkdirs();
|
||||||
|
try (FileWriter writer = new FileWriter(logFile)) {
|
||||||
|
for (String s : logs) {
|
||||||
|
writer.write(s);
|
||||||
|
writer.write('\n');
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MagiskManager.toast(logFile.getPath(), Toast.LENGTH_LONG);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getDarkTheme() {
|
||||||
|
return R.style.AppTheme_Transparent_Dark;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_flash);
|
||||||
|
ButterKnife.bind(this);
|
||||||
|
setSupportActionBar(toolbar);
|
||||||
|
ActionBar ab = getSupportActionBar();
|
||||||
|
if (ab != null) {
|
||||||
|
ab.setTitle(R.string.flashing);
|
||||||
|
}
|
||||||
|
setFloating();
|
||||||
|
setFinishOnTouchOutside(false);
|
||||||
|
if (!Shell.rootAccess())
|
||||||
|
reboot.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
logs = new ArrayList<>();
|
||||||
|
List<String> console = new CallbackList<String>() {
|
||||||
|
@Override
|
||||||
|
public synchronized void onAddElement(String e) {
|
||||||
|
logs.add(e);
|
||||||
|
flashLogs.setText(TextUtils.join("\n", this));
|
||||||
|
sv.postDelayed(() -> sv.fullScroll(ScrollView.FOCUS_DOWN), 10);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// We must receive a Uri of the target zip
|
||||||
|
Intent intent = getIntent();
|
||||||
|
Uri uri = intent.getData();
|
||||||
|
|
||||||
|
switch (intent.getStringExtra(Const.Key.FLASH_ACTION)) {
|
||||||
|
case Const.Value.FLASH_ZIP:
|
||||||
|
new FlashZip(this, uri, console, logs).exec();
|
||||||
|
break;
|
||||||
|
case Const.Value.PATCH_BOOT:
|
||||||
|
new InstallMagisk(this, console, logs, uri, (Uri) intent.getParcelableExtra(Const.Key.FLASH_SET_BOOT))
|
||||||
|
.exec();
|
||||||
|
break;
|
||||||
|
case Const.Value.FLASH_MAGISK:
|
||||||
|
new InstallMagisk(this, console, logs, uri, intent.getStringExtra(Const.Key.FLASH_SET_BOOT))
|
||||||
|
.exec();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackPressed() {
|
||||||
|
// Prevent user accidentally press back button
|
||||||
|
}
|
||||||
|
}
|
@@ -10,6 +10,7 @@ import android.view.ViewGroup;
|
|||||||
|
|
||||||
import com.topjohnwu.magisk.adapters.TabFragmentAdapter;
|
import com.topjohnwu.magisk.adapters.TabFragmentAdapter;
|
||||||
import com.topjohnwu.magisk.components.Fragment;
|
import com.topjohnwu.magisk.components.Fragment;
|
||||||
|
import com.topjohnwu.magisk.utils.Const;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
@@ -33,13 +34,12 @@ public class LogFragment extends Fragment {
|
|||||||
|
|
||||||
TabFragmentAdapter adapter = new TabFragmentAdapter(getChildFragmentManager());
|
TabFragmentAdapter adapter = new TabFragmentAdapter(getChildFragmentManager());
|
||||||
|
|
||||||
if (getApplication().isSuClient) {
|
if (!(Const.USER_ID > 0 && getApplication().multiuserMode == Const.Value.MULTIUSER_MODE_OWNER_MANAGED)) {
|
||||||
adapter.addTab(new SuLogFragment(), getString(R.string.superuser));
|
adapter.addTab(new SuLogFragment(), getString(R.string.superuser));
|
||||||
tab.setupWithViewPager(viewPager);
|
|
||||||
tab.setVisibility(View.VISIBLE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
adapter.addTab(new MagiskLogFragment(), getString(R.string.magisk));
|
adapter.addTab(new MagiskLogFragment(), getString(R.string.magisk));
|
||||||
|
tab.setupWithViewPager(viewPager);
|
||||||
|
tab.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
viewPager.setAdapter(adapter);
|
viewPager.setAdapter(adapter);
|
||||||
|
|
@@ -5,19 +5,16 @@ import android.content.Context;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.annotation.StringRes;
|
import android.support.annotation.StringRes;
|
||||||
import android.support.design.widget.Snackbar;
|
|
||||||
import android.support.v4.widget.SwipeRefreshLayout;
|
import android.support.v4.widget.SwipeRefreshLayout;
|
||||||
import android.support.v7.widget.CardView;
|
import android.support.v7.widget.CardView;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ArrayAdapter;
|
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.Spinner;
|
import android.widget.RelativeLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.topjohnwu.magisk.asyncs.CheckSafetyNet;
|
import com.topjohnwu.magisk.asyncs.CheckSafetyNet;
|
||||||
@@ -25,14 +22,11 @@ import com.topjohnwu.magisk.asyncs.CheckUpdates;
|
|||||||
import com.topjohnwu.magisk.components.AlertDialogBuilder;
|
import com.topjohnwu.magisk.components.AlertDialogBuilder;
|
||||||
import com.topjohnwu.magisk.components.ExpandableView;
|
import com.topjohnwu.magisk.components.ExpandableView;
|
||||||
import com.topjohnwu.magisk.components.Fragment;
|
import com.topjohnwu.magisk.components.Fragment;
|
||||||
import com.topjohnwu.magisk.components.SnackbarMaker;
|
|
||||||
import com.topjohnwu.magisk.utils.Shell;
|
import com.topjohnwu.magisk.utils.Shell;
|
||||||
|
import com.topjohnwu.magisk.utils.ShowUI;
|
||||||
import com.topjohnwu.magisk.utils.Topic;
|
import com.topjohnwu.magisk.utils.Topic;
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import butterknife.BindColor;
|
import butterknife.BindColor;
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
@@ -42,12 +36,13 @@ import butterknife.Unbinder;
|
|||||||
public class MagiskFragment extends Fragment
|
public class MagiskFragment extends Fragment
|
||||||
implements Topic.Subscriber, SwipeRefreshLayout.OnRefreshListener, ExpandableView {
|
implements Topic.Subscriber, SwipeRefreshLayout.OnRefreshListener, ExpandableView {
|
||||||
|
|
||||||
public static final int CAUSE_SERVICE_DISCONNECTED = 0x00001;
|
private static final int CAUSE_SERVICE_DISCONNECTED = 0x01;
|
||||||
public static final int CAUSE_NETWORK_LOST = 0x00010;
|
private static final int CAUSE_NETWORK_LOST = 0x02;
|
||||||
public static final int RESPONSE_ERR = 0x00100;
|
private static final int RESPONSE_ERR = 0x04;
|
||||||
|
private static final int CONNECTION_FAIL = 0x08;
|
||||||
|
|
||||||
public static final int BASIC_PASS = 0x01000;
|
private static final int BASIC_PASS = 0x10;
|
||||||
public static final int CTS_PASS = 0x10000;
|
private static final int CTS_PASS = 0x20;
|
||||||
|
|
||||||
private Container expandableContainer = new Container();
|
private Container expandableContainer = new Container();
|
||||||
|
|
||||||
@@ -57,15 +52,12 @@ public class MagiskFragment extends Fragment
|
|||||||
|
|
||||||
@BindView(R.id.swipeRefreshLayout) SwipeRefreshLayout mSwipeRefreshLayout;
|
@BindView(R.id.swipeRefreshLayout) SwipeRefreshLayout mSwipeRefreshLayout;
|
||||||
|
|
||||||
@BindView(R.id.magisk_update_card) CardView magiskUpdateCard;
|
@BindView(R.id.magisk_update) RelativeLayout magiskUpdate;
|
||||||
@BindView(R.id.magisk_update_icon) ImageView magiskUpdateIcon;
|
@BindView(R.id.magisk_update_icon) ImageView magiskUpdateIcon;
|
||||||
@BindView(R.id.magisk_update_status) TextView magiskUpdateText;
|
@BindView(R.id.magisk_update_status) TextView magiskUpdateText;
|
||||||
@BindView(R.id.magisk_update_progress) ProgressBar magiskUpdateProgress;
|
@BindView(R.id.magisk_update_progress) ProgressBar magiskUpdateProgress;
|
||||||
|
|
||||||
@BindView(R.id.magisk_status_icon) ImageView magiskStatusIcon;
|
@BindView(R.id.magisk_status_icon) ImageView magiskStatusIcon;
|
||||||
@BindView(R.id.magisk_version) TextView magiskVersionText;
|
@BindView(R.id.magisk_version) TextView magiskVersionText;
|
||||||
@BindView(R.id.root_status_icon) ImageView rootStatusIcon;
|
|
||||||
@BindView(R.id.root_status) TextView rootStatusText;
|
|
||||||
|
|
||||||
@BindView(R.id.safetyNet_card) CardView safetyNetCard;
|
@BindView(R.id.safetyNet_card) CardView safetyNetCard;
|
||||||
@BindView(R.id.safetyNet_refresh) ImageView safetyNetRefreshIcon;
|
@BindView(R.id.safetyNet_refresh) ImageView safetyNetRefreshIcon;
|
||||||
@@ -77,9 +69,6 @@ public class MagiskFragment extends Fragment
|
|||||||
@BindView(R.id.basic_status_icon) ImageView basicStatusIcon;
|
@BindView(R.id.basic_status_icon) ImageView basicStatusIcon;
|
||||||
@BindView(R.id.basic_status) TextView basicStatusText;
|
@BindView(R.id.basic_status) TextView basicStatusText;
|
||||||
|
|
||||||
@BindView(R.id.bootimage_card) CardView bootImageCard;
|
|
||||||
@BindView(R.id.block_spinner) Spinner spinner;
|
|
||||||
@BindView(R.id.detect_bootimage) Button detectButton;
|
|
||||||
@BindView(R.id.install_option_card) CardView installOptionCard;
|
@BindView(R.id.install_option_card) CardView installOptionCard;
|
||||||
@BindView(R.id.keep_force_enc) CheckBox keepEncChkbox;
|
@BindView(R.id.keep_force_enc) CheckBox keepEncChkbox;
|
||||||
@BindView(R.id.keep_verity) CheckBox keepVerityChkbox;
|
@BindView(R.id.keep_verity) CheckBox keepVerityChkbox;
|
||||||
@@ -102,7 +91,7 @@ public class MagiskFragment extends Fragment
|
|||||||
new CheckSafetyNet(getActivity()).exec();
|
new CheckSafetyNet(getActivity()).exec();
|
||||||
collapse();
|
collapse();
|
||||||
};
|
};
|
||||||
if (mm.snet_version < 0) {
|
if (!CheckSafetyNet.dexPath.exists()) {
|
||||||
// Show dialog
|
// Show dialog
|
||||||
new AlertDialogBuilder(getActivity())
|
new AlertDialogBuilder(getActivity())
|
||||||
.setTitle(R.string.proprietary_title)
|
.setTitle(R.string.proprietary_title)
|
||||||
@@ -123,18 +112,17 @@ public class MagiskFragment extends Fragment
|
|||||||
|
|
||||||
// Show Manager update first
|
// Show Manager update first
|
||||||
if (mm.remoteManagerVersionCode > BuildConfig.VERSION_CODE) {
|
if (mm.remoteManagerVersionCode > BuildConfig.VERSION_CODE) {
|
||||||
Utils.showManagerInstallDialog(getActivity());
|
ShowUI.managerInstallDialog(getActivity());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
((NotificationManager) mm.getSystemService(Context.NOTIFICATION_SERVICE)).cancelAll();
|
((NotificationManager) mm.getSystemService(Context.NOTIFICATION_SERVICE)).cancelAll();
|
||||||
Utils.showMagiskInstallDialog(this,
|
ShowUI.magiskInstallDialog(getActivity());
|
||||||
keepEncChkbox.isChecked(), keepVerityChkbox.isChecked());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.uninstall_button)
|
@OnClick(R.id.uninstall_button)
|
||||||
void uninstall() {
|
void uninstall() {
|
||||||
Utils.showUninstallDialog(this);
|
ShowUI.uninstallDialog(getActivity());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -149,6 +137,11 @@ public class MagiskFragment extends Fragment
|
|||||||
expandableContainer.expandLayout = expandLayout;
|
expandableContainer.expandLayout = expandLayout;
|
||||||
setupExpandable();
|
setupExpandable();
|
||||||
|
|
||||||
|
keepVerityChkbox.setChecked(mm.keepVerity);
|
||||||
|
keepVerityChkbox.setOnCheckedChangeListener((view, checked) -> mm.keepVerity = checked);
|
||||||
|
keepEncChkbox.setChecked(mm.keepEnc);
|
||||||
|
keepEncChkbox.setOnCheckedChangeListener((view, checked) -> mm.keepEnc = checked);
|
||||||
|
|
||||||
mSwipeRefreshLayout.setOnRefreshListener(this);
|
mSwipeRefreshLayout.setOnRefreshListener(this);
|
||||||
updateUI();
|
updateUI();
|
||||||
|
|
||||||
@@ -157,7 +150,7 @@ public class MagiskFragment extends Fragment
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRefresh() {
|
public void onRefresh() {
|
||||||
mm.getMagiskInfo();
|
mm.loadMagiskInfo();
|
||||||
updateUI();
|
updateUI();
|
||||||
|
|
||||||
magiskUpdateText.setText(R.string.checking_for_updates);
|
magiskUpdateText.setText(R.string.checking_for_updates);
|
||||||
@@ -175,8 +168,8 @@ public class MagiskFragment extends Fragment
|
|||||||
shownDialog = false;
|
shownDialog = false;
|
||||||
|
|
||||||
// Trigger state check
|
// Trigger state check
|
||||||
if (Utils.checkNetworkStatus(mm)) {
|
if (Utils.checkNetworkStatus()) {
|
||||||
new CheckUpdates(getActivity()).exec();
|
new CheckUpdates().exec();
|
||||||
} else {
|
} else {
|
||||||
mSwipeRefreshLayout.setRefreshing(false);
|
mSwipeRefreshLayout.setRefreshing(false);
|
||||||
}
|
}
|
||||||
@@ -207,35 +200,15 @@ public class MagiskFragment extends Fragment
|
|||||||
return expandableContainer;
|
return expandableContainer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSelectedBootImage() {
|
|
||||||
if (Shell.rootAccess()) {
|
|
||||||
if (mm.bootBlock != null) {
|
|
||||||
return mm.bootBlock;
|
|
||||||
} else {
|
|
||||||
int idx = spinner.getSelectedItemPosition();
|
|
||||||
if (idx > 0) {
|
|
||||||
return mm.blockList.get(idx - 1);
|
|
||||||
} else {
|
|
||||||
SnackbarMaker.make(getActivity(),
|
|
||||||
R.string.manual_boot_image, Snackbar.LENGTH_LONG).show();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateUI() {
|
private void updateUI() {
|
||||||
((MainActivity) getActivity()).checkHideSection();
|
((MainActivity) getActivity()).checkHideSection();
|
||||||
|
|
||||||
boolean hasNetwork = Utils.checkNetworkStatus(getActivity());
|
boolean hasNetwork = Utils.checkNetworkStatus();
|
||||||
boolean hasRoot = Shell.rootAccess();
|
boolean hasRoot = Shell.rootAccess();
|
||||||
boolean isUpToDate = mm.magiskVersionCode > 1300;
|
boolean isUpToDate = mm.magiskVersionCode > 1300;
|
||||||
|
|
||||||
magiskUpdateCard.setVisibility(hasNetwork ? View.VISIBLE : View.GONE);
|
magiskUpdate.setVisibility(hasNetwork ? View.VISIBLE : View.GONE);
|
||||||
safetyNetCard.setVisibility(hasNetwork ? View.VISIBLE : View.GONE);
|
safetyNetCard.setVisibility(hasNetwork ? View.VISIBLE : View.GONE);
|
||||||
bootImageCard.setVisibility(hasNetwork && hasRoot ? View.VISIBLE : View.GONE);
|
|
||||||
installOptionCard.setVisibility(hasNetwork ? View.VISIBLE : View.GONE);
|
installOptionCard.setVisibility(hasNetwork ? View.VISIBLE : View.GONE);
|
||||||
uninstallButton.setVisibility(isUpToDate && hasRoot ? View.VISIBLE : View.GONE);
|
uninstallButton.setVisibility(isUpToDate && hasRoot ? View.VISIBLE : View.GONE);
|
||||||
|
|
||||||
@@ -253,43 +226,6 @@ public class MagiskFragment extends Fragment
|
|||||||
|
|
||||||
magiskStatusIcon.setImageResource(image);
|
magiskStatusIcon.setImageResource(image);
|
||||||
magiskStatusIcon.setColorFilter(color);
|
magiskStatusIcon.setColorFilter(color);
|
||||||
|
|
||||||
switch (Shell.rootStatus) {
|
|
||||||
case 0:
|
|
||||||
color = colorBad;
|
|
||||||
image = R.drawable.ic_cancel;
|
|
||||||
rootStatusText.setText(R.string.not_rooted);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
if (mm.suVersion != null) {
|
|
||||||
color = colorOK;
|
|
||||||
image = R.drawable.ic_check_circle;
|
|
||||||
rootStatusText.setText(mm.suVersion);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case -1:
|
|
||||||
default:
|
|
||||||
color = colorNeutral;
|
|
||||||
image = R.drawable.ic_help;
|
|
||||||
rootStatusText.setText(R.string.root_error);
|
|
||||||
}
|
|
||||||
|
|
||||||
rootStatusIcon.setImageResource(image);
|
|
||||||
rootStatusIcon.setColorFilter(color);
|
|
||||||
|
|
||||||
List<String> items = new ArrayList<>();
|
|
||||||
if (mm.bootBlock != null) {
|
|
||||||
items.add(getString(R.string.auto_detect, mm.bootBlock));
|
|
||||||
spinner.setEnabled(false);
|
|
||||||
} else {
|
|
||||||
items.add(getString(R.string.cannot_auto_detect));
|
|
||||||
if (mm.blockList != null)
|
|
||||||
items.addAll(mm.blockList);
|
|
||||||
}
|
|
||||||
ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(),
|
|
||||||
android.R.layout.simple_spinner_item, items);
|
|
||||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
|
||||||
spinner.setAdapter(adapter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateCheckUI() {
|
private void updateCheckUI() {
|
||||||
@@ -298,20 +234,20 @@ public class MagiskFragment extends Fragment
|
|||||||
if (mm.remoteMagiskVersionCode < 0) {
|
if (mm.remoteMagiskVersionCode < 0) {
|
||||||
color = colorNeutral;
|
color = colorNeutral;
|
||||||
image = R.drawable.ic_help;
|
image = R.drawable.ic_help;
|
||||||
magiskUpdateText.setText(R.string.cannot_check_updates);
|
magiskUpdateText.setText(R.string.invalid_update_channel);
|
||||||
|
installButton.setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
color = colorOK;
|
color = colorOK;
|
||||||
image = R.drawable.ic_check_circle;
|
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" + mm.remoteMagiskVersionString));
|
||||||
}
|
installButton.setVisibility(View.VISIBLE);
|
||||||
|
if (mm.remoteManagerVersionCode > BuildConfig.VERSION_CODE) {
|
||||||
installButton.setVisibility(View.VISIBLE);
|
installText.setText(getString(R.string.update, getString(R.string.app_name)));
|
||||||
if (mm.remoteManagerVersionCode > BuildConfig.VERSION_CODE) {
|
} else if (mm.magiskVersionCode > 0 && mm.remoteMagiskVersionCode > mm.magiskVersionCode) {
|
||||||
installText.setText(getString(R.string.update, getString(R.string.app_name)));
|
installText.setText(getString(R.string.update, getString(R.string.magisk)));
|
||||||
} else if (mm.magiskVersionCode > 0 && mm.remoteMagiskVersionCode > mm.magiskVersionCode) {
|
} else {
|
||||||
installText.setText(getString(R.string.update, getString(R.string.magisk)));
|
installText.setText(R.string.install);
|
||||||
} else {
|
}
|
||||||
installText.setText(R.string.install);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!shownDialog && (mm.remoteMagiskVersionCode > mm.magiskVersionCode
|
if (!shownDialog && (mm.remoteMagiskVersionCode > mm.magiskVersionCode
|
||||||
@@ -330,9 +266,7 @@ public class MagiskFragment extends Fragment
|
|||||||
private void updateSafetyNetUI(int response) {
|
private void updateSafetyNetUI(int response) {
|
||||||
safetyNetProgress.setVisibility(View.GONE);
|
safetyNetProgress.setVisibility(View.GONE);
|
||||||
safetyNetRefreshIcon.setVisibility(View.VISIBLE);
|
safetyNetRefreshIcon.setVisibility(View.VISIBLE);
|
||||||
if (response < 0) {
|
if ((response & 0x0F) == 0) {
|
||||||
safetyNetStatusText.setText(R.string.safetyNet_api_error);
|
|
||||||
} else if ((response & 0x111) == 0) {
|
|
||||||
safetyNetStatusText.setText(R.string.safetyNet_check_success);
|
safetyNetStatusText.setText(R.string.safetyNet_check_success);
|
||||||
|
|
||||||
boolean b;
|
boolean b;
|
||||||
@@ -357,9 +291,12 @@ public class MagiskFragment extends Fragment
|
|||||||
resid = R.string.safetyNet_service_disconnected;
|
resid = R.string.safetyNet_service_disconnected;
|
||||||
break;
|
break;
|
||||||
case RESPONSE_ERR:
|
case RESPONSE_ERR:
|
||||||
default:
|
|
||||||
resid = R.string.safetyNet_res_invalid;
|
resid = R.string.safetyNet_res_invalid;
|
||||||
break;
|
break;
|
||||||
|
case CONNECTION_FAIL:
|
||||||
|
default:
|
||||||
|
resid = R.string.safetyNet_api_error;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
safetyNetStatusText.setText(resid);
|
safetyNetStatusText.setText(resid);
|
||||||
}
|
}
|
@@ -1,9 +1,7 @@
|
|||||||
package com.topjohnwu.magisk;
|
package com.topjohnwu.magisk;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.design.widget.Snackbar;
|
import android.support.design.widget.Snackbar;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
@@ -22,6 +20,7 @@ import android.widget.Toast;
|
|||||||
import com.topjohnwu.magisk.asyncs.ParallelTask;
|
import com.topjohnwu.magisk.asyncs.ParallelTask;
|
||||||
import com.topjohnwu.magisk.components.Fragment;
|
import com.topjohnwu.magisk.components.Fragment;
|
||||||
import com.topjohnwu.magisk.components.SnackbarMaker;
|
import com.topjohnwu.magisk.components.SnackbarMaker;
|
||||||
|
import com.topjohnwu.magisk.utils.Const;
|
||||||
import com.topjohnwu.magisk.utils.Shell;
|
import com.topjohnwu.magisk.utils.Shell;
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
|
|
||||||
@@ -29,6 +28,7 @@ import java.io.File;
|
|||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
@@ -36,8 +36,6 @@ import butterknife.Unbinder;
|
|||||||
|
|
||||||
public class MagiskLogFragment extends Fragment {
|
public class MagiskLogFragment extends Fragment {
|
||||||
|
|
||||||
private static final String MAGISK_LOG = "/cache/magisk.log";
|
|
||||||
|
|
||||||
private Unbinder unbinder;
|
private Unbinder unbinder;
|
||||||
|
|
||||||
@BindView(R.id.txtLog) TextView txtLog;
|
@BindView(R.id.txtLog) TextView txtLog;
|
||||||
@@ -110,30 +108,29 @@ public class MagiskLogFragment extends Fragment {
|
|||||||
super(MagiskLogFragment.this.getActivity());
|
super(MagiskLogFragment.this.getActivity());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("DefaultLocale")
|
|
||||||
@Override
|
@Override
|
||||||
protected Object doInBackground(Object... params) {
|
protected Object doInBackground(Object... params) {
|
||||||
mode = (int) params[0];
|
mode = (int) params[0];
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case 0:
|
case 0:
|
||||||
StringBuildingList logList = new StringBuildingList();
|
StringBuildingList logList = new StringBuildingList();
|
||||||
getShell().su(logList, "cat " + MAGISK_LOG);
|
Shell.su(logList, "cat " + Const.MAGISK_LOG + " | tail -n 5000");
|
||||||
return logList.toString();
|
return logList.getCharSequence();
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
getShell().su_raw("echo -n > " + MAGISK_LOG);
|
Shell.su_raw("echo -n > " + Const.MAGISK_LOG);
|
||||||
SnackbarMaker.make(txtLog, R.string.logs_cleared, Snackbar.LENGTH_SHORT).show();
|
SnackbarMaker.make(txtLog, R.string.logs_cleared, Snackbar.LENGTH_SHORT).show();
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
Calendar now = Calendar.getInstance();
|
Calendar now = Calendar.getInstance();
|
||||||
String filename = String.format(
|
String filename = String.format(Locale.US,
|
||||||
"magisk_%s_%04d%02d%02d_%02d%02d%02d.log", "error",
|
"magisk_log_%04d%02d%02d_%02d%02d%02d.log",
|
||||||
now.get(Calendar.YEAR), now.get(Calendar.MONTH) + 1,
|
now.get(Calendar.YEAR), now.get(Calendar.MONTH) + 1,
|
||||||
now.get(Calendar.DAY_OF_MONTH), now.get(Calendar.HOUR_OF_DAY),
|
now.get(Calendar.DAY_OF_MONTH), now.get(Calendar.HOUR_OF_DAY),
|
||||||
now.get(Calendar.MINUTE), now.get(Calendar.SECOND));
|
now.get(Calendar.MINUTE), now.get(Calendar.SECOND));
|
||||||
|
|
||||||
targetFile = new File(Environment.getExternalStorageDirectory() + "/MagiskManager/" + filename);
|
targetFile = new File(Const.EXTERNAL_PATH + "/logs", filename);
|
||||||
|
|
||||||
if ((!targetFile.getParentFile().exists() && !targetFile.getParentFile().mkdirs())
|
if ((!targetFile.getParentFile().exists() && !targetFile.getParentFile().mkdirs())
|
||||||
|| (targetFile.exists() && !targetFile.delete())) {
|
|| (targetFile.exists() && !targetFile.delete())) {
|
||||||
@@ -142,7 +139,7 @@ public class MagiskLogFragment extends Fragment {
|
|||||||
|
|
||||||
try (FileWriter out = new FileWriter(targetFile)) {
|
try (FileWriter out = new FileWriter(targetFile)) {
|
||||||
FileWritingList fileWritingList = new FileWritingList(out);
|
FileWritingList fileWritingList = new FileWritingList(out);
|
||||||
getShell().su(fileWritingList, "cat " + MAGISK_LOG);
|
Shell.su(fileWritingList, "cat " + Const.MAGISK_LOG);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return false;
|
return false;
|
||||||
@@ -158,21 +155,21 @@ public class MagiskLogFragment extends Fragment {
|
|||||||
switch (mode) {
|
switch (mode) {
|
||||||
case 0:
|
case 0:
|
||||||
case 1:
|
case 1:
|
||||||
String llog = (String) o;
|
CharSequence llog = (CharSequence) o;
|
||||||
progressBar.setVisibility(View.GONE);
|
progressBar.setVisibility(View.GONE);
|
||||||
if (TextUtils.isEmpty(llog))
|
if (TextUtils.isEmpty(llog))
|
||||||
txtLog.setText(R.string.log_is_empty);
|
txtLog.setText(R.string.log_is_empty);
|
||||||
else
|
else
|
||||||
txtLog.setText(llog);
|
txtLog.setText(llog);
|
||||||
svLog.post(() -> svLog.scrollTo(0, txtLog.getHeight()));
|
svLog.postDelayed(() -> svLog.fullScroll(ScrollView.FOCUS_DOWN), 100);
|
||||||
hsvLog.post(() -> hsvLog.scrollTo(0, 0));
|
hsvLog.postDelayed(() -> hsvLog.fullScroll(ScrollView.FOCUS_LEFT), 100);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
boolean bool = (boolean) o;
|
boolean bool = (boolean) o;
|
||||||
if (bool) {
|
if (bool) {
|
||||||
getMagiskManager().toast(targetFile.toString(), Toast.LENGTH_LONG);
|
MagiskManager.toast(targetFile.getPath(), Toast.LENGTH_LONG);
|
||||||
} else {
|
} else {
|
||||||
getMagiskManager().toast(R.string.logs_save_failed, Toast.LENGTH_LONG);
|
MagiskManager.toast(R.string.logs_save_failed, Toast.LENGTH_LONG);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -205,9 +202,8 @@ public class MagiskLogFragment extends Fragment {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public CharSequence getCharSequence() {
|
||||||
public String toString() {
|
return builder;
|
||||||
return builder.toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
251
src/main/java/com/topjohnwu/magisk/MagiskManager.java
Normal file
@@ -0,0 +1,251 @@
|
|||||||
|
package com.topjohnwu.magisk;
|
||||||
|
|
||||||
|
import android.app.Application;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.res.Configuration;
|
||||||
|
import android.content.res.Resources;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.topjohnwu.magisk.container.Module;
|
||||||
|
import com.topjohnwu.magisk.database.RepoDatabaseHelper;
|
||||||
|
import com.topjohnwu.magisk.database.SuDatabaseHelper;
|
||||||
|
import com.topjohnwu.magisk.utils.Const;
|
||||||
|
import com.topjohnwu.magisk.utils.Shell;
|
||||||
|
import com.topjohnwu.magisk.utils.Topic;
|
||||||
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
|
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class MagiskManager extends Application {
|
||||||
|
|
||||||
|
// Global weak reference to self
|
||||||
|
private static WeakReference<MagiskManager> weakSelf;
|
||||||
|
|
||||||
|
// Topics
|
||||||
|
public final Topic magiskHideDone = new Topic();
|
||||||
|
public final Topic reloadActivity = new Topic();
|
||||||
|
public final Topic moduleLoadDone = new Topic();
|
||||||
|
public final Topic repoLoadDone = new Topic();
|
||||||
|
public final Topic updateCheckDone = new Topic();
|
||||||
|
public final Topic safetyNetDone = new Topic();
|
||||||
|
public final Topic localeDone = new Topic();
|
||||||
|
|
||||||
|
// Info
|
||||||
|
public boolean hasInit = false;
|
||||||
|
public String magiskVersionString;
|
||||||
|
public int magiskVersionCode = -1;
|
||||||
|
public String remoteMagiskVersionString;
|
||||||
|
public int remoteMagiskVersionCode = -1;
|
||||||
|
public String magiskLink;
|
||||||
|
public String releaseNoteLink;
|
||||||
|
public String remoteManagerVersionString;
|
||||||
|
public int remoteManagerVersionCode = -1;
|
||||||
|
public String managerLink;
|
||||||
|
public String bootBlock = null;
|
||||||
|
public boolean keepVerity = false;
|
||||||
|
public boolean keepEnc = false;
|
||||||
|
|
||||||
|
// Data
|
||||||
|
public Map<String, Module> moduleMap;
|
||||||
|
public List<Locale> locales;
|
||||||
|
|
||||||
|
// Configurations
|
||||||
|
public static Locale locale;
|
||||||
|
public static Locale defaultLocale;
|
||||||
|
|
||||||
|
public boolean magiskHide;
|
||||||
|
public boolean isDarkTheme;
|
||||||
|
public boolean updateNotification;
|
||||||
|
public boolean suReauth;
|
||||||
|
public int suRequestTimeout;
|
||||||
|
public int suLogTimeout = 14;
|
||||||
|
public int suAccessState;
|
||||||
|
public int multiuserMode;
|
||||||
|
public int suResponseType;
|
||||||
|
public int suNotificationType;
|
||||||
|
public int suNamespaceMode;
|
||||||
|
public String localeConfig;
|
||||||
|
public int updateChannel;
|
||||||
|
public String bootFormat;
|
||||||
|
public String customChannelUrl;
|
||||||
|
public int repoOrder;
|
||||||
|
|
||||||
|
// Global resources
|
||||||
|
public SharedPreferences prefs;
|
||||||
|
public SuDatabaseHelper suDB;
|
||||||
|
public RepoDatabaseHelper repoDB;
|
||||||
|
public Shell shell;
|
||||||
|
public Runnable permissionGrantCallback = null;
|
||||||
|
|
||||||
|
private static Handler mHandler = new Handler();
|
||||||
|
|
||||||
|
public MagiskManager() {
|
||||||
|
weakSelf = new WeakReference<>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate() {
|
||||||
|
super.onCreate();
|
||||||
|
prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
|
||||||
|
// Handle duplicate package
|
||||||
|
if (!getPackageName().equals(Const.ORIG_PKG_NAME)) {
|
||||||
|
try {
|
||||||
|
getPackageManager().getApplicationInfo(Const.ORIG_PKG_NAME, 0);
|
||||||
|
Intent intent = getPackageManager().getLaunchIntentForPackage(Const.ORIG_PKG_NAME);
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
startActivity(intent);
|
||||||
|
return;
|
||||||
|
} catch (PackageManager.NameNotFoundException ignored) { /* Expected */ }
|
||||||
|
}
|
||||||
|
|
||||||
|
suDB = SuDatabaseHelper.getSuDB(false);
|
||||||
|
repoDB = new RepoDatabaseHelper(this);
|
||||||
|
defaultLocale = Locale.getDefault();
|
||||||
|
setLocale();
|
||||||
|
loadConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MagiskManager get() {
|
||||||
|
return weakSelf.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLocale() {
|
||||||
|
localeConfig = prefs.getString(Const.Key.LOCALE, "");
|
||||||
|
if (localeConfig.isEmpty()) {
|
||||||
|
locale = defaultLocale;
|
||||||
|
} else {
|
||||||
|
locale = Locale.forLanguageTag(localeConfig);
|
||||||
|
}
|
||||||
|
Resources res = getBaseContext().getResources();
|
||||||
|
Configuration config = new Configuration(res.getConfiguration());
|
||||||
|
config.setLocale(locale);
|
||||||
|
res.updateConfiguration(config, res.getDisplayMetrics());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadConfig() {
|
||||||
|
// su
|
||||||
|
suRequestTimeout = Utils.getPrefsInt(prefs, Const.Key.SU_REQUEST_TIMEOUT, Const.Value.timeoutList[2]);
|
||||||
|
suResponseType = Utils.getPrefsInt(prefs, Const.Key.SU_AUTO_RESPONSE, Const.Value.SU_PROMPT);
|
||||||
|
suNotificationType = Utils.getPrefsInt(prefs, Const.Key.SU_NOTIFICATION, Const.Value.NOTIFICATION_TOAST);
|
||||||
|
suReauth = prefs.getBoolean(Const.Key.SU_REAUTH, false);
|
||||||
|
suAccessState = suDB.getSettings(Const.Key.ROOT_ACCESS, Const.Value.ROOT_ACCESS_APPS_AND_ADB);
|
||||||
|
multiuserMode = suDB.getSettings(Const.Key.SU_MULTIUSER_MODE, Const.Value.MULTIUSER_MODE_OWNER_ONLY);
|
||||||
|
suNamespaceMode = suDB.getSettings(Const.Key.SU_MNT_NS, Const.Value.NAMESPACE_MODE_REQUESTER);
|
||||||
|
|
||||||
|
// config
|
||||||
|
isDarkTheme = prefs.getBoolean(Const.Key.DARK_THEME, false);
|
||||||
|
updateNotification = prefs.getBoolean(Const.Key.UPDATE_NOTIFICATION, true);
|
||||||
|
updateChannel = Utils.getPrefsInt(prefs, Const.Key.UPDATE_CHANNEL, Const.Value.STABLE_CHANNEL);
|
||||||
|
bootFormat = prefs.getString(Const.Key.BOOT_FORMAT, ".img");
|
||||||
|
customChannelUrl = prefs.getString(Const.Key.CUSTOM_CHANNEL, "");
|
||||||
|
repoOrder = prefs.getInt(Const.Key.REPO_ORDER, Const.Value.ORDER_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeConfig() {
|
||||||
|
prefs.edit()
|
||||||
|
.putBoolean(Const.Key.DARK_THEME, isDarkTheme)
|
||||||
|
.putBoolean(Const.Key.MAGISKHIDE, magiskHide)
|
||||||
|
.putBoolean(Const.Key.UPDATE_NOTIFICATION, updateNotification)
|
||||||
|
.putBoolean(Const.Key.HOSTS, Utils.itemExist(Const.MAGISK_HOST_FILE()))
|
||||||
|
.putBoolean(Const.Key.COREONLY, Utils.itemExist(Const.MAGISK_DISABLE_FILE))
|
||||||
|
.putBoolean(Const.Key.SU_REAUTH, suReauth)
|
||||||
|
.putString(Const.Key.SU_REQUEST_TIMEOUT, String.valueOf(suRequestTimeout))
|
||||||
|
.putString(Const.Key.SU_AUTO_RESPONSE, String.valueOf(suResponseType))
|
||||||
|
.putString(Const.Key.SU_NOTIFICATION, String.valueOf(suNotificationType))
|
||||||
|
.putString(Const.Key.ROOT_ACCESS, String.valueOf(suAccessState))
|
||||||
|
.putString(Const.Key.SU_MULTIUSER_MODE, String.valueOf(multiuserMode))
|
||||||
|
.putString(Const.Key.SU_MNT_NS, String.valueOf(suNamespaceMode))
|
||||||
|
.putString(Const.Key.UPDATE_CHANNEL, String.valueOf(updateChannel))
|
||||||
|
.putString(Const.Key.LOCALE, localeConfig)
|
||||||
|
.putString(Const.Key.BOOT_FORMAT, bootFormat)
|
||||||
|
.putInt(Const.Key.UPDATE_SERVICE_VER, Const.UPDATE_SERVICE_VER)
|
||||||
|
.putInt(Const.Key.REPO_ORDER, repoOrder)
|
||||||
|
.apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void toast(String msg, int duration) {
|
||||||
|
mHandler.post(() -> Toast.makeText(weakSelf.get(), msg, duration).show());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void toast(int resId, int duration) {
|
||||||
|
mHandler.post(() -> Toast.makeText(weakSelf.get(), resId, duration).show());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadMagiskInfo() {
|
||||||
|
List<String> ret;
|
||||||
|
ret = Shell.sh("magisk -v");
|
||||||
|
if (!Utils.isValidShellResponse(ret)) {
|
||||||
|
ret = Shell.sh("getprop magisk.version");
|
||||||
|
if (Utils.isValidShellResponse(ret)) {
|
||||||
|
try {
|
||||||
|
magiskVersionString = ret.get(0);
|
||||||
|
magiskVersionCode = (int) Double.parseDouble(ret.get(0)) * 10;
|
||||||
|
} catch (NumberFormatException ignored) {}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
magiskVersionString = ret.get(0).split(":")[0];
|
||||||
|
ret = Shell.sh("magisk -V");
|
||||||
|
try {
|
||||||
|
magiskVersionCode = Integer.parseInt(ret.get(0));
|
||||||
|
} catch (NumberFormatException ignored) {}
|
||||||
|
}
|
||||||
|
if (magiskVersionCode > 1435) {
|
||||||
|
ret = Shell.su("resetprop -p " + Const.MAGISKHIDE_PROP);
|
||||||
|
} else {
|
||||||
|
ret = Shell.sh("getprop " + Const.MAGISKHIDE_PROP);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
magiskHide = !Utils.isValidShellResponse(ret) || Integer.parseInt(ret.get(0)) != 0;
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
magiskHide = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = Shell.su("echo \"$BOOTIMAGE\"");
|
||||||
|
if (Utils.isValidShellResponse(ret))
|
||||||
|
bootBlock = ret.get(0);
|
||||||
|
|
||||||
|
if (suDB != null && !SuDatabaseHelper.verified) {
|
||||||
|
suDB.close();
|
||||||
|
suDB = SuDatabaseHelper.getSuDB(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getDefaultInstallFlags() {
|
||||||
|
List<String> ret;
|
||||||
|
ret = Shell.su("echo \"$DTBOIMAGE\"");
|
||||||
|
if (Utils.isValidShellResponse(ret))
|
||||||
|
keepVerity = true;
|
||||||
|
|
||||||
|
ret = Shell.su(
|
||||||
|
"getvar KEEPVERITY",
|
||||||
|
"echo $KEEPVERITY");
|
||||||
|
try {
|
||||||
|
if (Utils.isValidShellResponse(ret))
|
||||||
|
keepVerity = Boolean.parseBoolean(ret.get(0));
|
||||||
|
} catch (NumberFormatException ignored) {}
|
||||||
|
|
||||||
|
ret = Shell.sh("getprop ro.crypto.state");
|
||||||
|
if (Utils.isValidShellResponse(ret) && ret.get(0).equals("encrypted"))
|
||||||
|
keepEnc = true;
|
||||||
|
|
||||||
|
ret = Shell.su(
|
||||||
|
"getvar KEEPFORCEENCRYPT",
|
||||||
|
"echo $KEEPFORCEENCRYPT");
|
||||||
|
try {
|
||||||
|
if (Utils.isValidShellResponse(ret))
|
||||||
|
keepEnc = Boolean.parseBoolean(ret.get(0));
|
||||||
|
} catch (NumberFormatException ignored) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPermissionGrantCallback(Runnable callback) {
|
||||||
|
permissionGrantCallback = callback;
|
||||||
|
}
|
||||||
|
}
|
@@ -6,6 +6,7 @@ import android.os.Bundle;
|
|||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.design.widget.NavigationView;
|
import android.support.design.widget.NavigationView;
|
||||||
|
import android.support.v4.app.ActivityCompat;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentTransaction;
|
import android.support.v4.app.FragmentTransaction;
|
||||||
import android.support.v4.widget.DrawerLayout;
|
import android.support.v4.widget.DrawerLayout;
|
||||||
@@ -15,11 +16,16 @@ import android.view.Menu;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
|
import com.topjohnwu.magisk.asyncs.MarkDownWindow;
|
||||||
import com.topjohnwu.magisk.components.Activity;
|
import com.topjohnwu.magisk.components.Activity;
|
||||||
|
import com.topjohnwu.magisk.utils.Const;
|
||||||
import com.topjohnwu.magisk.utils.Shell;
|
import com.topjohnwu.magisk.utils.Shell;
|
||||||
import com.topjohnwu.magisk.utils.Topic;
|
import com.topjohnwu.magisk.utils.Topic;
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
|
|
||||||
@@ -36,15 +42,32 @@ public class MainActivity extends Activity
|
|||||||
|
|
||||||
private float toolbarElevation;
|
private float toolbarElevation;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getDarkTheme() {
|
||||||
|
return R.style.AppTheme_Dark;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(final Bundle savedInstanceState) {
|
protected void onCreate(final Bundle savedInstanceState) {
|
||||||
getMagiskManager().startup();
|
|
||||||
|
|
||||||
prefs = getMagiskManager().prefs;
|
MagiskManager mm = getMagiskManager();
|
||||||
|
prefs = mm.prefs;
|
||||||
|
|
||||||
if (getMagiskManager().isDarkTheme) {
|
if (!mm.hasInit) {
|
||||||
setTheme(R.style.AppTheme_Dark);
|
Intent intent = new Intent(this, SplashActivity.class);
|
||||||
|
String section = getIntent().getStringExtra(Const.Key.OPEN_SECTION);
|
||||||
|
if (section != null) {
|
||||||
|
intent.putExtra(Const.Key.OPEN_SECTION, section);
|
||||||
|
}
|
||||||
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String perm = getIntent().getStringExtra(Const.Key.INTENT_PERM);
|
||||||
|
if (perm != null) {
|
||||||
|
ActivityCompat.requestPermissions(this, new String[] { perm }, 0);
|
||||||
|
}
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
ButterKnife.bind(this);
|
ButterKnife.bind(this);
|
||||||
@@ -70,10 +93,19 @@ public class MainActivity extends Activity
|
|||||||
toggle.syncState();
|
toggle.syncState();
|
||||||
|
|
||||||
if (savedInstanceState == null)
|
if (savedInstanceState == null)
|
||||||
navigate(getIntent().getStringExtra(MagiskManager.INTENT_SECTION));
|
navigate(getIntent().getStringExtra(Const.Key.OPEN_SECTION));
|
||||||
|
|
||||||
navigationView.setNavigationItemSelectedListener(this);
|
navigationView.setNavigationItemSelectedListener(this);
|
||||||
|
|
||||||
|
if (mm.prefs.getInt(Const.Key.APP_VER, -1) < BuildConfig.VERSION_CODE) {
|
||||||
|
prefs.edit().putInt(Const.Key.APP_VER, BuildConfig.VERSION_CODE).apply();
|
||||||
|
try {
|
||||||
|
InputStream is = getAssets().open("changelog.md");
|
||||||
|
new MarkDownWindow(this, getString(R.string.app_changelog), is).exec();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -112,17 +144,18 @@ public class MainActivity extends Activity
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void checkHideSection() {
|
public void checkHideSection() {
|
||||||
|
MagiskManager mm = getMagiskManager();
|
||||||
Menu menu = navigationView.getMenu();
|
Menu menu = navigationView.getMenu();
|
||||||
menu.findItem(R.id.magiskhide).setVisible(
|
menu.findItem(R.id.magiskhide).setVisible(
|
||||||
Shell.rootAccess() && getMagiskManager().magiskVersionCode >= 1300
|
Shell.rootAccess() && mm.magiskVersionCode >= 1300
|
||||||
&& prefs.getBoolean("magiskhide", false));
|
&& prefs.getBoolean(Const.Key.MAGISKHIDE, false));
|
||||||
menu.findItem(R.id.modules).setVisible(
|
menu.findItem(R.id.modules).setVisible(!mm.prefs.getBoolean(Const.Key.COREONLY, false) &&
|
||||||
Shell.rootAccess() && getMagiskManager().magiskVersionCode >= 0);
|
Shell.rootAccess() && mm.magiskVersionCode >= 0);
|
||||||
menu.findItem(R.id.downloads).setVisible(Utils.checkNetworkStatus(this) &&
|
menu.findItem(R.id.downloads).setVisible(!mm.prefs.getBoolean(Const.Key.COREONLY, false)
|
||||||
Shell.rootAccess() && getMagiskManager().magiskVersionCode >= 0);
|
&& Utils.checkNetworkStatus() && Shell.rootAccess() && mm.magiskVersionCode >= 0);
|
||||||
menu.findItem(R.id.log).setVisible(Shell.rootAccess());
|
menu.findItem(R.id.log).setVisible(Shell.rootAccess());
|
||||||
menu.findItem(R.id.superuser).setVisible(
|
menu.findItem(R.id.superuser).setVisible(Shell.rootAccess() &&
|
||||||
Shell.rootAccess() && getMagiskManager().isSuClient);
|
!(Const.USER_ID > 0 && mm.multiuserMode == Const.Value.MULTIUSER_MODE_OWNER_MANAGED));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void navigate(String item) {
|
public void navigate(String item) {
|
||||||
@@ -176,7 +209,7 @@ public class MainActivity extends Activity
|
|||||||
displayFragment(new ReposFragment(), "downloads", true);
|
displayFragment(new ReposFragment(), "downloads", true);
|
||||||
break;
|
break;
|
||||||
case R.id.magiskhide:
|
case R.id.magiskhide:
|
||||||
displayFragment(new MagiskHideFragment(), "magiskhide", true);
|
displayFragment(new MagiskHideFragment(), Const.Key.MAGISKHIDE, true);
|
||||||
break;
|
break;
|
||||||
case R.id.log:
|
case R.id.log:
|
||||||
displayFragment(new LogFragment(), "log", false);
|
displayFragment(new LogFragment(), "log", false);
|
@@ -8,6 +8,9 @@ import android.support.annotation.Nullable;
|
|||||||
import android.support.v4.widget.SwipeRefreshLayout;
|
import android.support.v4.widget.SwipeRefreshLayout;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
@@ -16,6 +19,8 @@ import com.topjohnwu.magisk.adapters.ModulesAdapter;
|
|||||||
import com.topjohnwu.magisk.asyncs.LoadModules;
|
import com.topjohnwu.magisk.asyncs.LoadModules;
|
||||||
import com.topjohnwu.magisk.components.Fragment;
|
import com.topjohnwu.magisk.components.Fragment;
|
||||||
import com.topjohnwu.magisk.container.Module;
|
import com.topjohnwu.magisk.container.Module;
|
||||||
|
import com.topjohnwu.magisk.utils.Const;
|
||||||
|
import com.topjohnwu.magisk.utils.Shell;
|
||||||
import com.topjohnwu.magisk.utils.Topic;
|
import com.topjohnwu.magisk.utils.Topic;
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
|
|
||||||
@@ -29,8 +34,6 @@ import butterknife.Unbinder;
|
|||||||
|
|
||||||
public class ModulesFragment extends Fragment implements Topic.Subscriber {
|
public class ModulesFragment extends Fragment implements Topic.Subscriber {
|
||||||
|
|
||||||
private static final int FETCH_ZIP_CODE = 2;
|
|
||||||
|
|
||||||
private Unbinder unbinder;
|
private Unbinder unbinder;
|
||||||
@BindView(R.id.swipeRefreshLayout) SwipeRefreshLayout mSwipeRefreshLayout;
|
@BindView(R.id.swipeRefreshLayout) SwipeRefreshLayout mSwipeRefreshLayout;
|
||||||
@BindView(R.id.recyclerView) RecyclerView recyclerView;
|
@BindView(R.id.recyclerView) RecyclerView recyclerView;
|
||||||
@@ -40,7 +43,7 @@ public class ModulesFragment extends Fragment implements Topic.Subscriber {
|
|||||||
Utils.runWithPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE, () -> {
|
Utils.runWithPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE, () -> {
|
||||||
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||||
intent.setType("application/zip");
|
intent.setType("application/zip");
|
||||||
startActivityForResult(intent, FETCH_ZIP_CODE);
|
startActivityForResult(intent, Const.ID.FETCH_ZIP);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,10 +54,11 @@ public class ModulesFragment extends Fragment implements Topic.Subscriber {
|
|||||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.fragment_modules, container, false);
|
View view = inflater.inflate(R.layout.fragment_modules, container, false);
|
||||||
unbinder = ButterKnife.bind(this, view);
|
unbinder = ButterKnife.bind(this, view);
|
||||||
|
setHasOptionsMenu(true);
|
||||||
|
|
||||||
mSwipeRefreshLayout.setOnRefreshListener(() -> {
|
mSwipeRefreshLayout.setOnRefreshListener(() -> {
|
||||||
recyclerView.setVisibility(View.GONE);
|
recyclerView.setVisibility(View.GONE);
|
||||||
new LoadModules(getActivity()).exec();
|
new LoadModules().exec();
|
||||||
});
|
});
|
||||||
|
|
||||||
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||||
@@ -86,10 +90,10 @@ public class ModulesFragment extends Fragment implements Topic.Subscriber {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
if (requestCode == FETCH_ZIP_CODE && resultCode == Activity.RESULT_OK && data != null) {
|
if (requestCode == Const.ID.FETCH_ZIP && resultCode == Activity.RESULT_OK && data != null) {
|
||||||
// Get the URI of the selected file
|
// Get the URI of the selected file
|
||||||
Intent intent = new Intent(getActivity(), FlashActivity.class);
|
Intent intent = new Intent(getActivity(), FlashActivity.class);
|
||||||
intent.setData(data.getData()).putExtra(FlashActivity.SET_ACTION, FlashActivity.FLASH_ZIP);
|
intent.setData(data.getData()).putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_ZIP);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -100,6 +104,31 @@ public class ModulesFragment extends Fragment implements Topic.Subscriber {
|
|||||||
unbinder.unbind();
|
unbinder.unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
|
inflater.inflate(R.menu.menu_reboot, menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case R.id.reboot:
|
||||||
|
Shell.su_raw("/system/bin/reboot");
|
||||||
|
return true;
|
||||||
|
case R.id.reboot_recovery:
|
||||||
|
Shell.su_raw("/system/bin/reboot recovery");
|
||||||
|
return true;
|
||||||
|
case R.id.reboot_bootloader:
|
||||||
|
Shell.su_raw("/system/bin/reboot bootloader");
|
||||||
|
return true;
|
||||||
|
case R.id.reboot_download:
|
||||||
|
Shell.su_raw("/system/bin/reboot download");
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void updateUI() {
|
private void updateUI() {
|
||||||
listModules.clear();
|
listModules.clear();
|
||||||
listModules.addAll(getApplication().moduleMap.values());
|
listModules.addAll(getApplication().moduleMap.values());
|
@@ -1,5 +1,6 @@
|
|||||||
package com.topjohnwu.magisk;
|
package com.topjohnwu.magisk;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.widget.SwipeRefreshLayout;
|
import android.support.v4.widget.SwipeRefreshLayout;
|
||||||
@@ -7,6 +8,7 @@ import android.support.v7.widget.RecyclerView;
|
|||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.SearchView;
|
import android.widget.SearchView;
|
||||||
@@ -15,6 +17,7 @@ import android.widget.TextView;
|
|||||||
import com.topjohnwu.magisk.adapters.ReposAdapter;
|
import com.topjohnwu.magisk.adapters.ReposAdapter;
|
||||||
import com.topjohnwu.magisk.asyncs.UpdateRepos;
|
import com.topjohnwu.magisk.asyncs.UpdateRepos;
|
||||||
import com.topjohnwu.magisk.components.Fragment;
|
import com.topjohnwu.magisk.components.Fragment;
|
||||||
|
import com.topjohnwu.magisk.utils.Const;
|
||||||
import com.topjohnwu.magisk.utils.Topic;
|
import com.topjohnwu.magisk.utils.Topic;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
@@ -47,7 +50,7 @@ public class ReposFragment extends Fragment implements Topic.Subscriber {
|
|||||||
mSwipeRefreshLayout.setOnRefreshListener(() -> {
|
mSwipeRefreshLayout.setOnRefreshListener(() -> {
|
||||||
recyclerView.setVisibility(View.VISIBLE);
|
recyclerView.setVisibility(View.VISIBLE);
|
||||||
emptyRv.setVisibility(View.GONE);
|
emptyRv.setVisibility(View.GONE);
|
||||||
new UpdateRepos(getActivity(), true).exec();
|
new UpdateRepos(true).exec();
|
||||||
});
|
});
|
||||||
|
|
||||||
getActivity().setTitle(R.string.downloads);
|
getActivity().setTitle(R.string.downloads);
|
||||||
@@ -98,6 +101,22 @@ public class ReposFragment extends Fragment implements Topic.Subscriber {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
MagiskManager mm = getApplication();
|
||||||
|
if (item.getItemId() == R.id.repo_sort) {
|
||||||
|
new AlertDialog.Builder(getActivity())
|
||||||
|
.setTitle(R.string.sorting_order)
|
||||||
|
.setSingleChoiceItems(R.array.sorting_orders, mm.repoOrder, (d, which) -> {
|
||||||
|
mm.repoOrder = which;
|
||||||
|
mm.prefs.edit().putInt(Const.Key.REPO_ORDER, mm.repoOrder).apply();
|
||||||
|
adapter.notifyDBChanged();
|
||||||
|
d.dismiss();
|
||||||
|
}).show();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
@@ -8,17 +8,20 @@ import android.preference.ListPreference;
|
|||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.PreferenceCategory;
|
import android.preference.PreferenceCategory;
|
||||||
import android.preference.PreferenceFragment;
|
import android.preference.PreferenceFragment;
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.preference.PreferenceScreen;
|
import android.preference.PreferenceScreen;
|
||||||
import android.preference.SwitchPreference;
|
import android.preference.SwitchPreference;
|
||||||
import android.support.v7.app.ActionBar;
|
import android.support.v7.app.ActionBar;
|
||||||
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.EditText;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.topjohnwu.magisk.asyncs.CheckUpdates;
|
import com.topjohnwu.magisk.asyncs.CheckUpdates;
|
||||||
import com.topjohnwu.magisk.asyncs.HideManager;
|
import com.topjohnwu.magisk.asyncs.HideManager;
|
||||||
import com.topjohnwu.magisk.components.Activity;
|
import com.topjohnwu.magisk.components.Activity;
|
||||||
import com.topjohnwu.magisk.database.SuDatabaseHelper;
|
import com.topjohnwu.magisk.utils.Const;
|
||||||
import com.topjohnwu.magisk.utils.Shell;
|
import com.topjohnwu.magisk.utils.Shell;
|
||||||
import com.topjohnwu.magisk.utils.Topic;
|
import com.topjohnwu.magisk.utils.Topic;
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
@@ -32,13 +35,14 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
|
|||||||
|
|
||||||
@BindView(R.id.toolbar) Toolbar toolbar;
|
@BindView(R.id.toolbar) Toolbar toolbar;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getDarkTheme() {
|
||||||
|
return R.style.AppTheme_Transparent_Dark;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
if (getMagiskManager().isDarkTheme) {
|
|
||||||
setTheme(R.style.AppTheme_Transparent_Dark);
|
|
||||||
}
|
|
||||||
|
|
||||||
setContentView(R.layout.activity_settings);
|
setContentView(R.layout.activity_settings);
|
||||||
ButterKnife.bind(this);
|
ButterKnife.bind(this);
|
||||||
|
|
||||||
@@ -71,8 +75,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class SettingsFragment extends PreferenceFragment
|
public static class SettingsFragment extends PreferenceFragment
|
||||||
implements SharedPreferences.OnSharedPreferenceChangeListener,
|
implements SharedPreferences.OnSharedPreferenceChangeListener, Topic.Subscriber {
|
||||||
Topic.Subscriber {
|
|
||||||
|
|
||||||
private SharedPreferences prefs;
|
private SharedPreferences prefs;
|
||||||
private PreferenceScreen prefScreen;
|
private PreferenceScreen prefScreen;
|
||||||
@@ -86,60 +89,82 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
|
|||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
addPreferencesFromResource(R.xml.app_settings);
|
addPreferencesFromResource(R.xml.app_settings);
|
||||||
prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
|
||||||
prefScreen = getPreferenceScreen();
|
|
||||||
mm = Utils.getMagiskManager(getActivity());
|
mm = Utils.getMagiskManager(getActivity());
|
||||||
|
prefs = mm.prefs;
|
||||||
|
prefScreen = getPreferenceScreen();
|
||||||
|
|
||||||
generalCatagory = (PreferenceCategory) findPreference("general");
|
generalCatagory = (PreferenceCategory) findPreference("general");
|
||||||
PreferenceCategory magiskCategory = (PreferenceCategory) findPreference("magisk");
|
PreferenceCategory magiskCategory = (PreferenceCategory) findPreference("magisk");
|
||||||
PreferenceCategory suCategory = (PreferenceCategory) findPreference("superuser");
|
PreferenceCategory suCategory = (PreferenceCategory) findPreference("superuser");
|
||||||
|
|
||||||
updateChannel = (ListPreference) findPreference("update_channel");
|
|
||||||
suAccess = (ListPreference) findPreference("su_access");
|
|
||||||
autoRes = (ListPreference) findPreference("su_auto_response");
|
|
||||||
requestTimeout = (ListPreference) findPreference("su_request_timeout");
|
|
||||||
suNotification = (ListPreference) findPreference("su_notification");
|
|
||||||
multiuserMode = (ListPreference) findPreference("multiuser_mode");
|
|
||||||
namespaceMode = (ListPreference) findPreference("mnt_ns");
|
|
||||||
SwitchPreference reauth = (SwitchPreference) findPreference("su_reauth");
|
|
||||||
Preference hideManager = findPreference("hide");
|
Preference hideManager = findPreference("hide");
|
||||||
|
findPreference("clear").setOnPreferenceClickListener((pref) -> {
|
||||||
|
prefs.edit().remove(Const.Key.ETAG_KEY).apply();
|
||||||
|
mm.repoDB.clearRepo();
|
||||||
|
MagiskManager.toast(R.string.repo_cache_cleared, Toast.LENGTH_SHORT);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
updateChannel = (ListPreference) findPreference(Const.Key.UPDATE_CHANNEL);
|
||||||
|
suAccess = (ListPreference) findPreference(Const.Key.ROOT_ACCESS);
|
||||||
|
autoRes = (ListPreference) findPreference(Const.Key.SU_AUTO_RESPONSE);
|
||||||
|
requestTimeout = (ListPreference) findPreference(Const.Key.SU_REQUEST_TIMEOUT);
|
||||||
|
suNotification = (ListPreference) findPreference(Const.Key.SU_NOTIFICATION);
|
||||||
|
multiuserMode = (ListPreference) findPreference(Const.Key.SU_MULTIUSER_MODE);
|
||||||
|
namespaceMode = (ListPreference) findPreference(Const.Key.SU_MNT_NS);
|
||||||
|
SwitchPreference reauth = (SwitchPreference) findPreference(Const.Key.SU_REAUTH);
|
||||||
|
|
||||||
|
updateChannel.setOnPreferenceChangeListener((pref, o) -> {
|
||||||
|
mm.updateChannel = Integer.parseInt((String) o);
|
||||||
|
if (mm.updateChannel == Const.Value.CUSTOM_CHANNEL) {
|
||||||
|
View v = LayoutInflater.from(getActivity()).inflate(R.layout.custom_channel_dialog, null);
|
||||||
|
EditText url = v.findViewById(R.id.custom_url);
|
||||||
|
url.setText(mm.customChannelUrl);
|
||||||
|
new AlertDialog.Builder(getActivity())
|
||||||
|
.setTitle(R.string.settings_update_custom)
|
||||||
|
.setView(v)
|
||||||
|
.setPositiveButton(R.string.ok, (d, i) ->
|
||||||
|
prefs.edit().putString(Const.Key.CUSTOM_CHANNEL,
|
||||||
|
url.getText().toString()).apply())
|
||||||
|
.setNegativeButton(R.string.close, null)
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
setSummary();
|
setSummary();
|
||||||
|
|
||||||
// Disable dangerous settings in user mode if selected owner manage
|
// Disable dangerous settings in secondary user
|
||||||
if (getActivity().getApplicationInfo().uid > 99999) {
|
if (Const.USER_ID > 0) {
|
||||||
suCategory.removePreference(multiuserMode);
|
suCategory.removePreference(multiuserMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Disable re-authentication option on Android O, it will not work
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
reauth.setEnabled(false);
|
||||||
|
reauth.setSummary(R.string.android_o_not_support);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mm.getPackageName().equals(Const.ORIG_PKG_NAME) && mm.magiskVersionCode >= 1440) {
|
||||||
|
hideManager.setOnPreferenceClickListener((pref) -> {
|
||||||
|
Utils.runWithPermission(getActivity(),
|
||||||
|
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
||||||
|
() -> new HideManager(getActivity()).exec());
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
generalCatagory.removePreference(hideManager);
|
generalCatagory.removePreference(hideManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove re-authentication option on Android O, it will not work
|
if (!Shell.rootAccess() || (Const.USER_ID > 0 &&
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
mm.multiuserMode == Const.Value.MULTIUSER_MODE_OWNER_MANAGED)) {
|
||||||
suCategory.removePreference(reauth);
|
prefScreen.removePreference(suCategory);
|
||||||
}
|
}
|
||||||
|
|
||||||
findPreference("clear").setOnPreferenceClickListener((pref) -> {
|
|
||||||
Utils.clearRepoCache(getActivity());
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
hideManager.setOnPreferenceClickListener((pref) -> {
|
|
||||||
Utils.runWithPermission(getActivity(),
|
|
||||||
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
|
||||||
() -> new HideManager(getActivity()).exec());
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!Shell.rootAccess()) {
|
if (!Shell.rootAccess()) {
|
||||||
prefScreen.removePreference(magiskCategory);
|
prefScreen.removePreference(magiskCategory);
|
||||||
prefScreen.removePreference(suCategory);
|
|
||||||
generalCatagory.removePreference(hideManager);
|
generalCatagory.removePreference(hideManager);
|
||||||
} else {
|
} else if (mm.magiskVersionCode < 1300) {
|
||||||
if (!mm.isSuClient) {
|
prefScreen.removePreference(magiskCategory);
|
||||||
prefScreen.removePreference(suCategory);
|
|
||||||
}
|
|
||||||
if (mm.magiskVersionCode < 1300) {
|
|
||||||
prefScreen.removePreference(magiskCategory);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,7 +185,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
|
|||||||
lp.setEntries(entries);
|
lp.setEntries(entries);
|
||||||
lp.setEntryValues(entryValues);
|
lp.setEntryValues(entryValues);
|
||||||
lp.setTitle(R.string.language);
|
lp.setTitle(R.string.language);
|
||||||
lp.setKey("locale");
|
lp.setKey(Const.Key.LOCALE);
|
||||||
lp.setSummary(MagiskManager.locale.getDisplayName(MagiskManager.locale));
|
lp.setSummary(MagiskManager.locale.getDisplayName(MagiskManager.locale));
|
||||||
if (isNew) {
|
if (isNew) {
|
||||||
generalCatagory.addPreference(lp);
|
generalCatagory.addPreference(lp);
|
||||||
@@ -183,70 +208,55 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
|
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
|
||||||
boolean enabled;
|
|
||||||
|
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case "dark_theme":
|
case Const.Key.DARK_THEME:
|
||||||
enabled = prefs.getBoolean("dark_theme", false);
|
mm.isDarkTheme = prefs.getBoolean(key, false);
|
||||||
if (mm.isDarkTheme != enabled) {
|
mm.reloadActivity.publish(false);
|
||||||
mm.reloadActivity.publish(false);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case "disable":
|
case Const.Key.COREONLY:
|
||||||
enabled = prefs.getBoolean("disable", false);
|
if (prefs.getBoolean(key, false)) {
|
||||||
if (enabled) {
|
Utils.createFile(Const.MAGISK_DISABLE_FILE);
|
||||||
Utils.createFile(getShell(), MagiskManager.MAGISK_DISABLE_FILE);
|
|
||||||
} else {
|
} else {
|
||||||
Utils.removeItem(getShell(), MagiskManager.MAGISK_DISABLE_FILE);
|
Utils.removeItem(Const.MAGISK_DISABLE_FILE);
|
||||||
}
|
}
|
||||||
Toast.makeText(getActivity(), R.string.settings_reboot_toast, Toast.LENGTH_LONG).show();
|
Toast.makeText(getActivity(), R.string.settings_reboot_toast, Toast.LENGTH_LONG).show();
|
||||||
break;
|
break;
|
||||||
case "magiskhide":
|
case Const.Key.MAGISKHIDE:
|
||||||
enabled = prefs.getBoolean("magiskhide", false);
|
if (prefs.getBoolean(key, false)) {
|
||||||
if (enabled) {
|
Shell.su_raw("magiskhide --enable");
|
||||||
Utils.enableMagiskHide(getShell());
|
|
||||||
} else {
|
} else {
|
||||||
Utils.disableMagiskHide(getShell());
|
Shell.su_raw("magiskhide --disable");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "hosts":
|
case Const.Key.HOSTS:
|
||||||
enabled = prefs.getBoolean("hosts", false);
|
if (prefs.getBoolean(key, false)) {
|
||||||
if (enabled) {
|
Shell.su_raw(
|
||||||
getShell().su_raw(
|
"cp -af /system/etc/hosts " + Const.MAGISK_HOST_FILE(),
|
||||||
"cp -af /system/etc/hosts " + MagiskManager.MAGISK_HOST_FILE,
|
"mount -o bind " + Const.MAGISK_HOST_FILE() + " /system/etc/hosts");
|
||||||
"mount -o bind " + MagiskManager.MAGISK_HOST_FILE + " /system/etc/hosts");
|
|
||||||
} else {
|
} else {
|
||||||
getShell().su_raw(
|
Shell.su_raw(
|
||||||
"umount -l /system/etc/hosts",
|
"umount -l /system/etc/hosts",
|
||||||
"rm -f " + MagiskManager.MAGISK_HOST_FILE);
|
"rm -f " + Const.MAGISK_HOST_FILE());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "su_access":
|
case Const.Key.ROOT_ACCESS:
|
||||||
mm.suDB.setSettings(SuDatabaseHelper.ROOT_ACCESS, Utils.getPrefsInt(prefs, "su_access"));
|
case Const.Key.SU_MULTIUSER_MODE:
|
||||||
|
case Const.Key.SU_MNT_NS:
|
||||||
|
mm.suDB.setSettings(key, Utils.getPrefsInt(prefs, key));
|
||||||
break;
|
break;
|
||||||
case "multiuser_mode":
|
case Const.Key.LOCALE:
|
||||||
mm.suDB.setSettings(SuDatabaseHelper.MULTIUSER_MODE, Utils.getPrefsInt(prefs, "multiuser_mode"));
|
|
||||||
break;
|
|
||||||
case "mnt_ns":
|
|
||||||
mm.suDB.setSettings(SuDatabaseHelper.MNT_NS, Utils.getPrefsInt(prefs, "mnt_ns"));
|
|
||||||
break;
|
|
||||||
case "locale":
|
|
||||||
mm.setLocale();
|
mm.setLocale();
|
||||||
mm.reloadActivity.publish(false);
|
mm.reloadActivity.publish(false);
|
||||||
break;
|
break;
|
||||||
case "update_channel":
|
case Const.Key.UPDATE_CHANNEL:
|
||||||
mm.updateChannel = Utils.getPrefsInt(prefs, "update_channel");
|
new CheckUpdates().exec();
|
||||||
new CheckUpdates(mm, true).exec();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
mm.loadConfig();
|
mm.loadConfig();
|
||||||
setSummary();
|
setSummary();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Shell getShell() {
|
|
||||||
return Shell.getShell(getActivity());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setSummary() {
|
private void setSummary() {
|
||||||
updateChannel.setSummary(getResources()
|
updateChannel.setSummary(getResources()
|
||||||
.getStringArray(R.array.update_channel)[mm.updateChannel]);
|
.getStringArray(R.array.update_channel)[mm.updateChannel]);
|
||||||
@@ -257,7 +267,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
|
|||||||
suNotification.setSummary(getResources()
|
suNotification.setSummary(getResources()
|
||||||
.getStringArray(R.array.su_notification)[mm.suNotificationType]);
|
.getStringArray(R.array.su_notification)[mm.suNotificationType]);
|
||||||
requestTimeout.setSummary(
|
requestTimeout.setSummary(
|
||||||
getString(R.string.request_timeout_summary, prefs.getString("su_request_timeout", "10")));
|
getString(R.string.request_timeout_summary, prefs.getString(Const.Key.SU_REQUEST_TIMEOUT, "10")));
|
||||||
multiuserMode.setSummary(getResources()
|
multiuserMode.setSummary(getResources()
|
||||||
.getStringArray(R.array.multiuser_summary)[mm.multiuserMode]);
|
.getStringArray(R.array.multiuser_summary)[mm.multiuserMode]);
|
||||||
namespaceMode.setSummary(getResources()
|
namespaceMode.setSummary(getResources()
|
||||||
@@ -266,7 +276,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTopicPublished(Topic topic, Object result) {
|
public void onTopicPublished(Topic topic, Object result) {
|
||||||
setLocalePreference((ListPreference) findPreference("locale"));
|
setLocalePreference((ListPreference) findPreference(Const.Key.LOCALE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
105
src/main/java/com/topjohnwu/magisk/SplashActivity.java
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
package com.topjohnwu.magisk;
|
||||||
|
|
||||||
|
import android.app.NotificationChannel;
|
||||||
|
import android.app.NotificationManager;
|
||||||
|
import android.app.job.JobInfo;
|
||||||
|
import android.app.job.JobScheduler;
|
||||||
|
import android.content.ComponentName;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import com.topjohnwu.magisk.asyncs.CheckUpdates;
|
||||||
|
import com.topjohnwu.magisk.asyncs.LoadModules;
|
||||||
|
import com.topjohnwu.magisk.asyncs.ParallelTask;
|
||||||
|
import com.topjohnwu.magisk.asyncs.UpdateRepos;
|
||||||
|
import com.topjohnwu.magisk.components.Activity;
|
||||||
|
import com.topjohnwu.magisk.services.UpdateCheckService;
|
||||||
|
import com.topjohnwu.magisk.utils.Const;
|
||||||
|
import com.topjohnwu.magisk.utils.Shell;
|
||||||
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
|
|
||||||
|
public class SplashActivity extends Activity {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getDarkTheme() {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
MagiskManager mm = getMagiskManager();
|
||||||
|
|
||||||
|
mm.loadMagiskInfo();
|
||||||
|
mm.getDefaultInstallFlags();
|
||||||
|
Utils.loadPrefs();
|
||||||
|
|
||||||
|
// Dynamic detect all locales
|
||||||
|
new LoadLocale().exec();
|
||||||
|
|
||||||
|
// Create notification channel on Android O
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
NotificationChannel channel = new NotificationChannel(Const.ID.NOTIFICATION_CHANNEL,
|
||||||
|
getString(R.string.magisk_updates), NotificationManager.IMPORTANCE_DEFAULT);
|
||||||
|
getSystemService(NotificationManager.class).createNotificationChannel(channel);
|
||||||
|
}
|
||||||
|
|
||||||
|
LoadModules loadModuleTask = new LoadModules();
|
||||||
|
|
||||||
|
if (Utils.checkNetworkStatus()) {
|
||||||
|
|
||||||
|
// Fire update check
|
||||||
|
new CheckUpdates().exec();
|
||||||
|
|
||||||
|
// Add repo update check
|
||||||
|
loadModuleTask.setCallBack(() -> new UpdateRepos(false).exec());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Magisk working as expected
|
||||||
|
if (Shell.rootAccess() && mm.magiskVersionCode > 0) {
|
||||||
|
|
||||||
|
// Add update checking service
|
||||||
|
if (Const.UPDATE_SERVICE_VER > mm.prefs.getInt(Const.Key.UPDATE_SERVICE_VER, -1)) {
|
||||||
|
ComponentName service = new ComponentName(this, UpdateCheckService.class);
|
||||||
|
JobInfo info = new JobInfo.Builder(Const.ID.UPDATE_SERVICE_ID, service)
|
||||||
|
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
|
||||||
|
.setPersisted(true)
|
||||||
|
.setPeriodic(8 * 60 * 60 * 1000)
|
||||||
|
.build();
|
||||||
|
((JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE)).schedule(info);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fire asynctasks
|
||||||
|
loadModuleTask.exec();
|
||||||
|
|
||||||
|
// Check dtbo status
|
||||||
|
Utils.patchDTBO();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write back default values
|
||||||
|
mm.writeConfig();
|
||||||
|
|
||||||
|
mm.hasInit = true;
|
||||||
|
|
||||||
|
Intent intent = new Intent(this, MainActivity.class);
|
||||||
|
intent.putExtra(Const.Key.OPEN_SECTION, getIntent().getStringExtra(Const.Key.OPEN_SECTION));
|
||||||
|
intent.putExtra(Const.Key.INTENT_PERM, getIntent().getStringExtra(Const.Key.INTENT_PERM));
|
||||||
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
static class LoadLocale extends ParallelTask<Void, Void, Void> {
|
||||||
|
@Override
|
||||||
|
protected Void doInBackground(Void... voids) {
|
||||||
|
MagiskManager.get().locales = Utils.getAvailableLocale();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Void aVoid) {
|
||||||
|
MagiskManager.get().localeDone.publish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -5,6 +5,7 @@ import android.content.pm.ApplicationInfo;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.support.design.widget.Snackbar;
|
import android.support.design.widget.Snackbar;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@@ -16,12 +17,12 @@ import android.widget.TextView;
|
|||||||
import com.topjohnwu.magisk.R;
|
import com.topjohnwu.magisk.R;
|
||||||
import com.topjohnwu.magisk.asyncs.ParallelTask;
|
import com.topjohnwu.magisk.asyncs.ParallelTask;
|
||||||
import com.topjohnwu.magisk.components.SnackbarMaker;
|
import com.topjohnwu.magisk.components.SnackbarMaker;
|
||||||
|
import com.topjohnwu.magisk.utils.Const;
|
||||||
import com.topjohnwu.magisk.utils.Shell;
|
import com.topjohnwu.magisk.utils.Shell;
|
||||||
import com.topjohnwu.magisk.utils.Topic;
|
import com.topjohnwu.magisk.utils.Topic;
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -31,23 +32,11 @@ import butterknife.ButterKnife;
|
|||||||
|
|
||||||
public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.ViewHolder> {
|
public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.ViewHolder> {
|
||||||
|
|
||||||
public static final List<String> BLACKLIST = Arrays.asList(
|
|
||||||
"android",
|
|
||||||
"com.topjohnwu.magisk",
|
|
||||||
"com.google.android.gms"
|
|
||||||
);
|
|
||||||
|
|
||||||
private static final List<String> SNLIST = Arrays.asList(
|
|
||||||
"com.google.android.apps.walletnfcrel",
|
|
||||||
"com.nianticlabs.pokemongo"
|
|
||||||
);
|
|
||||||
|
|
||||||
private List<ApplicationInfo> mOriginalList, mList;
|
private List<ApplicationInfo> mOriginalList, mList;
|
||||||
private List<String> mHideList;
|
private List<String> mHideList;
|
||||||
private PackageManager pm;
|
private PackageManager pm;
|
||||||
private ApplicationFilter filter;
|
private ApplicationFilter filter;
|
||||||
private Topic magiskHideDone;
|
private Topic magiskHideDone;
|
||||||
private Shell shell;
|
|
||||||
|
|
||||||
public ApplicationAdapter(Context context) {
|
public ApplicationAdapter(Context context) {
|
||||||
mOriginalList = mList = Collections.emptyList();
|
mOriginalList = mList = Collections.emptyList();
|
||||||
@@ -55,10 +44,13 @@ public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.
|
|||||||
filter = new ApplicationFilter();
|
filter = new ApplicationFilter();
|
||||||
pm = context.getPackageManager();
|
pm = context.getPackageManager();
|
||||||
magiskHideDone = Utils.getMagiskManager(context).magiskHideDone;
|
magiskHideDone = Utils.getMagiskManager(context).magiskHideDone;
|
||||||
shell = Shell.getShell(context);
|
|
||||||
new LoadApps().exec();
|
new LoadApps().exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean lowercaseContains(CharSequence string, CharSequence nonNullLowercaseSearch) {
|
||||||
|
return !TextUtils.isEmpty(string) && string.toString().toLowerCase().contains(nonNullLowercaseSearch);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
View mView = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_app, parent, false);
|
View mView = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_app, parent, false);
|
||||||
@@ -77,7 +69,7 @@ public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.
|
|||||||
holder.itemView.setOnClickListener(null);
|
holder.itemView.setOnClickListener(null);
|
||||||
holder.checkBox.setOnCheckedChangeListener(null);
|
holder.checkBox.setOnCheckedChangeListener(null);
|
||||||
|
|
||||||
if (SNLIST.contains(info.packageName)) {
|
if (Const.SN_DEFAULTLIST.contains(info.packageName)) {
|
||||||
holder.checkBox.setChecked(true);
|
holder.checkBox.setChecked(true);
|
||||||
holder.checkBox.setEnabled(false);
|
holder.checkBox.setEnabled(false);
|
||||||
holder.itemView.setOnClickListener(v ->
|
holder.itemView.setOnClickListener(v ->
|
||||||
@@ -89,10 +81,10 @@ public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.
|
|||||||
holder.checkBox.setChecked(mHideList.contains(info.packageName));
|
holder.checkBox.setChecked(mHideList.contains(info.packageName));
|
||||||
holder.checkBox.setOnCheckedChangeListener((v, isChecked) -> {
|
holder.checkBox.setOnCheckedChangeListener((v, isChecked) -> {
|
||||||
if (isChecked) {
|
if (isChecked) {
|
||||||
Utils.addMagiskHide(shell, info.packageName);
|
Shell.su_raw("magiskhide --add " + info.packageName);
|
||||||
mHideList.add(info.packageName);
|
mHideList.add(info.packageName);
|
||||||
} else {
|
} else {
|
||||||
Utils.rmMagiskHide(shell, info.packageName);
|
Shell.su_raw("magiskhide --rm " + info.packageName);
|
||||||
mHideList.remove(info.packageName);
|
mHideList.remove(info.packageName);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -116,7 +108,7 @@ public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.
|
|||||||
|
|
||||||
@BindView(R.id.app_icon) ImageView appIcon;
|
@BindView(R.id.app_icon) ImageView appIcon;
|
||||||
@BindView(R.id.app_name) TextView appName;
|
@BindView(R.id.app_name) TextView appName;
|
||||||
@BindView(R.id.app_package) TextView appPackage;
|
@BindView(R.id.package_name) TextView appPackage;
|
||||||
@BindView(R.id.checkbox) CheckBox checkBox;
|
@BindView(R.id.checkbox) CheckBox checkBox;
|
||||||
|
|
||||||
ViewHolder(View itemView) {
|
ViewHolder(View itemView) {
|
||||||
@@ -135,8 +127,8 @@ public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.
|
|||||||
mList = new ArrayList<>();
|
mList = new ArrayList<>();
|
||||||
String filter = constraint.toString().toLowerCase();
|
String filter = constraint.toString().toLowerCase();
|
||||||
for (ApplicationInfo info : mOriginalList) {
|
for (ApplicationInfo info : mOriginalList) {
|
||||||
if (Utils.lowercaseContains(info.loadLabel(pm), filter)
|
if (lowercaseContains(info.loadLabel(pm), filter)
|
||||||
|| Utils.lowercaseContains(info.packageName, filter)) {
|
|| lowercaseContains(info.packageName, filter)) {
|
||||||
mList.add(info);
|
mList.add(info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -157,13 +149,13 @@ public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.
|
|||||||
mOriginalList = pm.getInstalledApplications(0);
|
mOriginalList = pm.getInstalledApplications(0);
|
||||||
for (Iterator<ApplicationInfo> i = mOriginalList.iterator(); i.hasNext(); ) {
|
for (Iterator<ApplicationInfo> i = mOriginalList.iterator(); i.hasNext(); ) {
|
||||||
ApplicationInfo info = i.next();
|
ApplicationInfo info = i.next();
|
||||||
if (ApplicationAdapter.BLACKLIST.contains(info.packageName) || !info.enabled) {
|
if (Const.HIDE_BLACKLIST.contains(info.packageName) || !info.enabled) {
|
||||||
i.remove();
|
i.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Collections.sort(mOriginalList, (a, b) -> a.loadLabel(pm).toString().toLowerCase()
|
Collections.sort(mOriginalList, (a, b) -> a.loadLabel(pm).toString().toLowerCase()
|
||||||
.compareTo(b.loadLabel(pm).toString().toLowerCase()));
|
.compareTo(b.loadLabel(pm).toString().toLowerCase()));
|
||||||
mHideList = Utils.listMagiskHide(shell);
|
mHideList = Shell.su("magiskhide --ls");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@@ -38,7 +38,6 @@ public class ModulesAdapter extends RecyclerView.Adapter<ModulesAdapter.ViewHold
|
|||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(final ViewHolder holder, int position) {
|
public void onBindViewHolder(final ViewHolder holder, int position) {
|
||||||
Context context = holder.itemView.getContext();
|
Context context = holder.itemView.getContext();
|
||||||
Shell rootShell = Shell.getShell(context);
|
|
||||||
final Module module = mList.get(position);
|
final Module module = mList.get(position);
|
||||||
|
|
||||||
String version = module.getVersion();
|
String version = module.getVersion();
|
||||||
@@ -56,10 +55,10 @@ public class ModulesAdapter extends RecyclerView.Adapter<ModulesAdapter.ViewHold
|
|||||||
holder.checkBox.setOnCheckedChangeListener((v, isChecked) -> {
|
holder.checkBox.setOnCheckedChangeListener((v, isChecked) -> {
|
||||||
int snack;
|
int snack;
|
||||||
if (isChecked) {
|
if (isChecked) {
|
||||||
module.removeDisableFile(rootShell);
|
module.removeDisableFile();
|
||||||
snack = R.string.disable_file_removed;
|
snack = R.string.disable_file_removed;
|
||||||
} else {
|
} else {
|
||||||
module.createDisableFile(rootShell);
|
module.createDisableFile();
|
||||||
snack = R.string.disable_file_created;
|
snack = R.string.disable_file_created;
|
||||||
}
|
}
|
||||||
SnackbarMaker.make(holder.itemView, snack, Snackbar.LENGTH_SHORT).show();
|
SnackbarMaker.make(holder.itemView, snack, Snackbar.LENGTH_SHORT).show();
|
||||||
@@ -69,10 +68,10 @@ public class ModulesAdapter extends RecyclerView.Adapter<ModulesAdapter.ViewHold
|
|||||||
boolean removed = module.willBeRemoved();
|
boolean removed = module.willBeRemoved();
|
||||||
int snack;
|
int snack;
|
||||||
if (removed) {
|
if (removed) {
|
||||||
module.deleteRemoveFile(rootShell);
|
module.deleteRemoveFile();
|
||||||
snack = R.string.remove_file_deleted;
|
snack = R.string.remove_file_deleted;
|
||||||
} else {
|
} else {
|
||||||
module.createRemoveFile(rootShell);
|
module.createRemoveFile();
|
||||||
snack = R.string.remove_file_created;
|
snack = R.string.remove_file_created;
|
||||||
}
|
}
|
||||||
SnackbarMaker.make(holder.itemView, snack, Snackbar.LENGTH_SHORT).show();
|
SnackbarMaker.make(holder.itemView, snack, Snackbar.LENGTH_SHORT).show();
|
@@ -95,6 +95,7 @@ public class ReposAdapter extends SectionedAdapter<ReposAdapter.SectionHolder, R
|
|||||||
String author = repo.getAuthor();
|
String author = repo.getAuthor();
|
||||||
holder.author.setText(TextUtils.isEmpty(author) ? null : context.getString(R.string.author, author));
|
holder.author.setText(TextUtils.isEmpty(author) ? null : context.getString(R.string.author, author));
|
||||||
holder.description.setText(repo.getDescription());
|
holder.description.setText(repo.getDescription());
|
||||||
|
holder.updateTime.setText(context.getString(R.string.updated_on, repo.getLastUpdateString()));
|
||||||
|
|
||||||
holder.infoLayout.setOnClickListener(v ->
|
holder.infoLayout.setOnClickListener(v ->
|
||||||
new MarkDownWindow((Activity) context, null, repo.getDetailUrl()).exec());
|
new MarkDownWindow((Activity) context, null, repo.getDetailUrl()).exec());
|
||||||
@@ -180,6 +181,7 @@ public class ReposAdapter extends SectionedAdapter<ReposAdapter.SectionHolder, R
|
|||||||
@BindView(R.id.author) TextView author;
|
@BindView(R.id.author) TextView author;
|
||||||
@BindView(R.id.info_layout) LinearLayout infoLayout;
|
@BindView(R.id.info_layout) LinearLayout infoLayout;
|
||||||
@BindView(R.id.download) ImageView downloadImage;
|
@BindView(R.id.download) ImageView downloadImage;
|
||||||
|
@BindView(R.id.update_time) TextView updateTime;
|
||||||
|
|
||||||
RepoHolder(View itemView) {
|
RepoHolder(View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
@@ -0,0 +1,97 @@
|
|||||||
|
package com.topjohnwu.magisk.asyncs;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
|
||||||
|
import com.topjohnwu.magisk.MagiskManager;
|
||||||
|
import com.topjohnwu.magisk.utils.Const;
|
||||||
|
import com.topjohnwu.magisk.utils.Shell;
|
||||||
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
|
import com.topjohnwu.magisk.utils.WebService;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.BufferedOutputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.lang.reflect.Proxy;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
|
||||||
|
import dalvik.system.DexClassLoader;
|
||||||
|
|
||||||
|
public class CheckSafetyNet extends ParallelTask<Void, Void, Exception> {
|
||||||
|
|
||||||
|
public static final File dexPath =
|
||||||
|
new File(MagiskManager.get().getFilesDir().getParent() + "/snet", "snet.apk");
|
||||||
|
private DexClassLoader loader;
|
||||||
|
private Class<?> helperClazz, callbackClazz;
|
||||||
|
|
||||||
|
public CheckSafetyNet(Activity activity) {
|
||||||
|
super(activity);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void dlSnet() throws IOException {
|
||||||
|
Shell.sh("rm -rf " + dexPath.getParent());
|
||||||
|
HttpURLConnection conn = WebService.request(Const.Url.SNET_URL, null);
|
||||||
|
dexPath.getParentFile().mkdir();
|
||||||
|
try (
|
||||||
|
OutputStream out = new BufferedOutputStream(new FileOutputStream(dexPath));
|
||||||
|
InputStream in = new BufferedInputStream(conn.getInputStream())) {
|
||||||
|
Utils.inToOut(in, out);
|
||||||
|
}
|
||||||
|
conn.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadClasses() throws ClassNotFoundException {
|
||||||
|
loader = new DexClassLoader(dexPath.toString(), dexPath.getParent(),
|
||||||
|
null, ClassLoader.getSystemClassLoader());
|
||||||
|
helperClazz = loader.loadClass(Const.SNET_PKG + ".SafetyNetHelper");
|
||||||
|
callbackClazz = loader.loadClass(Const.SNET_PKG + ".SafetyNetCallback");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Exception doInBackground(Void... voids) {
|
||||||
|
int snet_ver = -1;
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!dexPath.exists())
|
||||||
|
dlSnet();
|
||||||
|
loadClasses();
|
||||||
|
|
||||||
|
try {
|
||||||
|
snet_ver = (int) helperClazz.getMethod("getVersion").invoke(null);
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (snet_ver != Const.SNET_VER) {
|
||||||
|
dlSnet();
|
||||||
|
loadClasses();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Exception err) {
|
||||||
|
MagiskManager mm = MagiskManager.get();
|
||||||
|
try {
|
||||||
|
if (err != null) throw err;
|
||||||
|
Object helper = helperClazz.getConstructors()[0].newInstance(
|
||||||
|
getActivity(), dexPath.getPath(), Proxy.newProxyInstance(
|
||||||
|
loader, new Class[] { callbackClazz }, (proxy, method, args) -> {
|
||||||
|
mm.safetyNetDone.publish(false, args[0]);
|
||||||
|
return null;
|
||||||
|
}));
|
||||||
|
helperClazz.getMethod("attest").invoke(helper);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
mm.safetyNetDone.publish(false, -1);
|
||||||
|
}
|
||||||
|
super.onPostExecute(err);
|
||||||
|
}
|
||||||
|
}
|
@@ -1,10 +1,9 @@
|
|||||||
package com.topjohnwu.magisk.asyncs;
|
package com.topjohnwu.magisk.asyncs;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import com.topjohnwu.magisk.BuildConfig;
|
import com.topjohnwu.magisk.BuildConfig;
|
||||||
import com.topjohnwu.magisk.MagiskManager;
|
import com.topjohnwu.magisk.MagiskManager;
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
import com.topjohnwu.magisk.utils.Const;
|
||||||
|
import com.topjohnwu.magisk.utils.ShowUI;
|
||||||
import com.topjohnwu.magisk.utils.WebService;
|
import com.topjohnwu.magisk.utils.WebService;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
@@ -12,37 +11,30 @@ import org.json.JSONObject;
|
|||||||
|
|
||||||
public class CheckUpdates extends ParallelTask<Void, Void, Void> {
|
public class CheckUpdates extends ParallelTask<Void, Void, Void> {
|
||||||
|
|
||||||
public static final int STABLE_CHANNEL = 0;
|
private boolean showNotification;
|
||||||
public static final int BETA_CHANNEL = 1;
|
|
||||||
|
|
||||||
private static final String STABLE_URL = "https://raw.githubusercontent.com/topjohnwu/MagiskManager/update/stable.json";
|
public CheckUpdates() {
|
||||||
private static final String BETA_URL = "https://raw.githubusercontent.com/topjohnwu/MagiskManager/update/beta.json";
|
this(false);
|
||||||
|
|
||||||
private boolean showNotification = false;
|
|
||||||
|
|
||||||
public CheckUpdates(Context context) {
|
|
||||||
super(context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CheckUpdates(Context context, boolean b) {
|
public CheckUpdates(boolean b) {
|
||||||
super(context);
|
|
||||||
showNotification = b;
|
showNotification = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... voids) {
|
protected Void doInBackground(Void... voids) {
|
||||||
MagiskManager mm = getMagiskManager();
|
MagiskManager mm = MagiskManager.get();
|
||||||
if (mm == null) return null;
|
String jsonStr = "";
|
||||||
String jsonStr;
|
|
||||||
switch (mm.updateChannel) {
|
switch (mm.updateChannel) {
|
||||||
case STABLE_CHANNEL:
|
case Const.Value.STABLE_CHANNEL:
|
||||||
jsonStr = WebService.getString(STABLE_URL);
|
jsonStr = WebService.getString(Const.Url.STABLE_URL);
|
||||||
break;
|
break;
|
||||||
case BETA_CHANNEL:
|
case Const.Value.BETA_CHANNEL:
|
||||||
jsonStr = WebService.getString(BETA_URL);
|
jsonStr = WebService.getString(Const.Url.BETA_URL);
|
||||||
|
break;
|
||||||
|
case Const.Value.CUSTOM_CHANNEL:
|
||||||
|
jsonStr = WebService.getString(mm.customChannelUrl);
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
jsonStr = null;
|
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
JSONObject json = new JSONObject(jsonStr);
|
JSONObject json = new JSONObject(jsonStr);
|
||||||
@@ -61,13 +53,12 @@ public class CheckUpdates extends ParallelTask<Void, Void, Void> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Void v) {
|
protected void onPostExecute(Void v) {
|
||||||
MagiskManager mm = getMagiskManager();
|
MagiskManager mm = MagiskManager.get();
|
||||||
if (mm == null) return;
|
|
||||||
if (showNotification && mm.updateNotification) {
|
if (showNotification && mm.updateNotification) {
|
||||||
if (BuildConfig.VERSION_CODE < mm.remoteManagerVersionCode) {
|
if (BuildConfig.VERSION_CODE < mm.remoteManagerVersionCode) {
|
||||||
Utils.showManagerUpdateNotification(mm);
|
ShowUI.managerUpdateNotification();
|
||||||
} else if (mm.magiskVersionCode < mm.remoteMagiskVersionCode) {
|
} else if (mm.magiskVersionCode < mm.remoteMagiskVersionCode) {
|
||||||
Utils.showMagiskUpdateNotification(mm);
|
ShowUI.magiskUpdateNotification();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mm.updateCheckDone.publish();
|
mm.updateCheckDone.publish();
|
@@ -3,10 +3,12 @@ package com.topjohnwu.magisk.asyncs;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import com.topjohnwu.magisk.FlashActivity;
|
||||||
import com.topjohnwu.magisk.MagiskManager;
|
import com.topjohnwu.magisk.MagiskManager;
|
||||||
import com.topjohnwu.magisk.R;
|
import com.topjohnwu.magisk.utils.Const;
|
||||||
import com.topjohnwu.magisk.container.AdaptiveList;
|
import com.topjohnwu.magisk.utils.Shell;
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
import com.topjohnwu.magisk.utils.ZipUtils;
|
import com.topjohnwu.magisk.utils.ZipUtils;
|
||||||
|
|
||||||
@@ -24,38 +26,27 @@ public class FlashZip extends ParallelTask<Void, Void, Integer> {
|
|||||||
|
|
||||||
private Uri mUri;
|
private Uri mUri;
|
||||||
private File mCachedFile;
|
private File mCachedFile;
|
||||||
private AdaptiveList<String> mList;
|
private List<String> console, logs;
|
||||||
|
|
||||||
public FlashZip(Activity context, Uri uri, AdaptiveList<String> list) {
|
public FlashZip(Activity context, Uri uri, List<String> console, List<String> logs) {
|
||||||
super(context);
|
super(context);
|
||||||
mUri = uri;
|
mUri = uri;
|
||||||
mList = list;
|
this.console = console;
|
||||||
|
this.logs = logs;
|
||||||
mCachedFile = new File(context.getCacheDir(), "install.zip");
|
mCachedFile = new File(context.getCacheDir(), "install.zip");
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean unzipAndCheck() throws Exception {
|
private boolean unzipAndCheck() throws Exception {
|
||||||
ZipUtils.unzip(mCachedFile, mCachedFile.getParentFile(), "META-INF/com/google/android", true);
|
ZipUtils.unzip(mCachedFile, mCachedFile.getParentFile(), "META-INF/com/google/android", true);
|
||||||
List<String> ret = Utils.readFile(getShell(), new File(mCachedFile.getParentFile(), "updater-script").getPath());
|
List<String> ret = Utils.readFile(new File(mCachedFile.getParentFile(), "updater-script"));
|
||||||
return Utils.isValidShellResponse(ret) && ret.get(0).contains("#MAGISK");
|
return Utils.isValidShellResponse(ret) && ret.get(0).contains("#MAGISK");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPreExecute() {
|
|
||||||
// UI updates must run in the UI thread
|
|
||||||
mList.setCallback(this::publishProgress);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onProgressUpdate(Void... values) {
|
|
||||||
mList.updateView();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Integer doInBackground(Void... voids) {
|
protected Integer doInBackground(Void... voids) {
|
||||||
MagiskManager mm = getMagiskManager();
|
MagiskManager mm = MagiskManager.get();
|
||||||
if (mm == null) return -1;
|
|
||||||
try {
|
try {
|
||||||
mList.add("- Copying zip to temp directory");
|
console.add("- Copying zip to temp directory");
|
||||||
|
|
||||||
mCachedFile.delete();
|
mCachedFile.delete();
|
||||||
try (
|
try (
|
||||||
@@ -64,54 +55,54 @@ public class FlashZip extends ParallelTask<Void, Void, Integer> {
|
|||||||
) {
|
) {
|
||||||
if (in == null) throw new FileNotFoundException();
|
if (in == null) throw new FileNotFoundException();
|
||||||
InputStream buf= new BufferedInputStream(in);
|
InputStream buf= new BufferedInputStream(in);
|
||||||
byte buffer[] = new byte[4096];
|
Utils.inToOut(buf, out);
|
||||||
int length;
|
|
||||||
while ((length = buf.read(buffer)) > 0)
|
|
||||||
out.write(buffer, 0, length);
|
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
mList.add("! Invalid Uri");
|
console.add("! Invalid Uri");
|
||||||
throw e;
|
throw e;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
mList.add("! Cannot copy to cache");
|
console.add("! Cannot copy to cache");
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
if (!unzipAndCheck()) return 0;
|
if (!unzipAndCheck()) return 0;
|
||||||
mList.add("- Installing " + Utils.getNameFromUri(mm, mUri));
|
console.add("- Installing " + Utils.getNameFromUri(mm, mUri));
|
||||||
getShell().su(mList,
|
Shell.getShell().run(console, logs,
|
||||||
"cd " + mCachedFile.getParent(),
|
"cd " + mCachedFile.getParent(),
|
||||||
"BOOTMODE=true sh update-binary dummy 1 " + mCachedFile +
|
"BOOTMODE=true sh update-binary dummy 1 " + mCachedFile + " || echo 'Failed!'"
|
||||||
" && echo 'Success!' || echo 'Failed!'"
|
|
||||||
);
|
);
|
||||||
if (TextUtils.equals(mList.get(mList.size() - 1), "Success!"))
|
|
||||||
return 1;
|
if (TextUtils.equals(console.get(console.size() - 1), "Failed!"))
|
||||||
|
return -1;
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
return -1;
|
console.add("- All done!");
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -1 = error, manual install; 0 = invalid zip; 1 = success
|
// -1 = error, manual install; 0 = invalid zip; 1 = success
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Integer result) {
|
protected void onPostExecute(Integer result) {
|
||||||
MagiskManager mm = getMagiskManager();
|
FlashActivity activity = (FlashActivity) getActivity();
|
||||||
if (mm == null) return;
|
Shell.su_raw(
|
||||||
getShell().su_raw(
|
|
||||||
"rm -rf " + mCachedFile.getParent(),
|
"rm -rf " + mCachedFile.getParent(),
|
||||||
"rm -rf " + MagiskManager.TMP_FOLDER_PATH
|
"rm -rf " + Const.TMP_FOLDER_PATH
|
||||||
);
|
);
|
||||||
switch (result) {
|
switch (result) {
|
||||||
case -1:
|
case -1:
|
||||||
mList.add(mm.getString(R.string.install_error));
|
console.add("! Installation failed");
|
||||||
Utils.showUriSnack(getActivity(), mUri);
|
Utils.showUriSnack(getActivity(), mUri);
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
mList.add(mm.getString(R.string.invalid_zip));
|
console.add("! This zip is not a Magisk Module!");
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
// Success
|
// Success
|
||||||
new LoadModules(mm).exec();
|
new LoadModules().exec();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
super.onPostExecute(result);
|
activity.reboot.setVisibility(result > 0 ? View.VISIBLE : View.GONE);
|
||||||
|
activity.buttonPanel.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
154
src/main/java/com/topjohnwu/magisk/asyncs/HideManager.java
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
package com.topjohnwu.magisk.asyncs;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.ProgressDialog;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.topjohnwu.crypto.JarMap;
|
||||||
|
import com.topjohnwu.magisk.MagiskManager;
|
||||||
|
import com.topjohnwu.magisk.R;
|
||||||
|
import com.topjohnwu.magisk.utils.Const;
|
||||||
|
import com.topjohnwu.magisk.utils.Shell;
|
||||||
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
|
import com.topjohnwu.magisk.utils.ZipUtils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.jar.JarEntry;
|
||||||
|
|
||||||
|
public class HideManager extends ParallelTask<Void, Void, Boolean> {
|
||||||
|
|
||||||
|
private ProgressDialog dialog;
|
||||||
|
|
||||||
|
public HideManager(Activity activity) {
|
||||||
|
super(activity);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String genPackageName(String prefix, int length) {
|
||||||
|
StringBuilder builder = new StringBuilder(length);
|
||||||
|
builder.append(prefix);
|
||||||
|
length -= prefix.length();
|
||||||
|
SecureRandom random = new SecureRandom();
|
||||||
|
String base = "abcdefghijklmnopqrstuvwxyz";
|
||||||
|
String alpha = base + base.toUpperCase();
|
||||||
|
String full = alpha + "0123456789..........";
|
||||||
|
char next, prev = '\0';
|
||||||
|
for (int i = 0; i < length; ++i) {
|
||||||
|
if (prev == '.' || i == length - 1 || i == 0) {
|
||||||
|
next = alpha.charAt(random.nextInt(alpha.length()));
|
||||||
|
} else {
|
||||||
|
next = full.charAt(random.nextInt(full.length()));
|
||||||
|
}
|
||||||
|
builder.append(next);
|
||||||
|
prev = next;
|
||||||
|
}
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private int findOffset(byte buf[], byte pattern[]) {
|
||||||
|
int offset = -1;
|
||||||
|
for (int i = 0; i < buf.length - pattern.length; ++i) {
|
||||||
|
boolean match = true;
|
||||||
|
for (int j = 0; j < pattern.length; ++j) {
|
||||||
|
if (buf[i + j] != pattern[j]) {
|
||||||
|
match = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (match) {
|
||||||
|
offset = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* It seems that AAPT sometimes generate another type of string format */
|
||||||
|
private boolean fallbackPatch(byte xml[], String from, String to) {
|
||||||
|
|
||||||
|
byte[] target = new byte[from.length() * 2 + 2];
|
||||||
|
for (int i = 0; i < from.length(); ++i) {
|
||||||
|
target[i * 2] = (byte) from.charAt(i);
|
||||||
|
}
|
||||||
|
int offset = findOffset(xml, target);
|
||||||
|
if (offset < 0)
|
||||||
|
return false;
|
||||||
|
byte[] dest = new byte[target.length - 2];
|
||||||
|
for (int i = 0; i < to.length(); ++i) {
|
||||||
|
dest[i * 2] = (byte) to.charAt(i);
|
||||||
|
}
|
||||||
|
System.arraycopy(dest, 0, xml, offset, dest.length);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean findAndPatch(byte xml[], String from, String to) {
|
||||||
|
byte target[] = (from + '\0').getBytes();
|
||||||
|
int offset = findOffset(xml, target);
|
||||||
|
if (offset < 0)
|
||||||
|
return fallbackPatch(xml, from, to);
|
||||||
|
System.arraycopy(to.getBytes(), 0, xml, offset, to.length());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPreExecute() {
|
||||||
|
dialog = ProgressDialog.show(getActivity(),
|
||||||
|
getActivity().getString(R.string.hide_manager_toast),
|
||||||
|
getActivity().getString(R.string.hide_manager_toast2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Boolean doInBackground(Void... voids) {
|
||||||
|
MagiskManager mm = MagiskManager.get();
|
||||||
|
|
||||||
|
// Generate a new unhide app with random package name
|
||||||
|
File repack = new File(Const.EXTERNAL_PATH, "repack.apk");
|
||||||
|
repack.getParentFile().mkdirs();
|
||||||
|
String pkg = genPackageName("com.", Const.ORIG_PKG_NAME.length());
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Read whole APK into memory
|
||||||
|
JarMap apk = new JarMap(new FileInputStream(mm.getPackageCodePath()));
|
||||||
|
JarEntry je = new JarEntry(Const.ANDROID_MANIFEST);
|
||||||
|
byte xml[] = apk.getRawData(je);
|
||||||
|
|
||||||
|
if (!findAndPatch(xml, Const.ORIG_PKG_NAME, pkg))
|
||||||
|
return false;
|
||||||
|
if (!findAndPatch(xml, Const.ORIG_PKG_NAME + ".provider", pkg + ".provider"))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Write in changes
|
||||||
|
apk.getOutputStream(je).write(xml);
|
||||||
|
|
||||||
|
// Sign the APK
|
||||||
|
ZipUtils.signZip(apk, repack, false);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Install the application
|
||||||
|
|
||||||
|
List<String> ret = Shell.su(Utils.fmt("pm install %s >/dev/null && echo true || echo false", repack));
|
||||||
|
repack.delete();
|
||||||
|
if (!Utils.isValidShellResponse(ret) || !Boolean.parseBoolean(ret.get(0)))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
mm.suDB.setStrings(Const.Key.SU_REQUESTER, pkg);
|
||||||
|
Utils.dumpPrefs();
|
||||||
|
Utils.uninstallPkg(Const.ORIG_PKG_NAME);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Boolean b) {
|
||||||
|
dialog.dismiss();
|
||||||
|
if (!b) {
|
||||||
|
MagiskManager.toast(R.string.hide_manager_fail_toast, Toast.LENGTH_LONG);
|
||||||
|
}
|
||||||
|
super.onPostExecute(b);
|
||||||
|
}
|
||||||
|
}
|
275
src/main/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java
Normal file
@@ -0,0 +1,275 @@
|
|||||||
|
package com.topjohnwu.magisk.asyncs;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.res.AssetManager;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import com.topjohnwu.crypto.SignBoot;
|
||||||
|
import com.topjohnwu.magisk.FlashActivity;
|
||||||
|
import com.topjohnwu.magisk.MagiskManager;
|
||||||
|
import com.topjohnwu.magisk.container.TarEntry;
|
||||||
|
import com.topjohnwu.magisk.utils.Const;
|
||||||
|
import com.topjohnwu.magisk.utils.Shell;
|
||||||
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
|
import com.topjohnwu.magisk.utils.ZipUtils;
|
||||||
|
|
||||||
|
import org.kamranzafar.jtar.TarInputStream;
|
||||||
|
import org.kamranzafar.jtar.TarOutputStream;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.BufferedOutputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
|
||||||
|
|
||||||
|
private static final int PATCH_MODE = 0;
|
||||||
|
private static final int DIRECT_MODE = 1;
|
||||||
|
|
||||||
|
private Uri mBootImg, mZip;
|
||||||
|
private List<String> console, logs;
|
||||||
|
private String mBootLocation;
|
||||||
|
private int mode;
|
||||||
|
|
||||||
|
private InstallMagisk(Activity context, List<String> console, List<String> logs, Uri zip) {
|
||||||
|
super(context);
|
||||||
|
this.console = console;
|
||||||
|
this.logs = logs;
|
||||||
|
mZip = zip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InstallMagisk(Activity context, List<String> console, List<String> logs, Uri zip, Uri boot) {
|
||||||
|
this(context, console, logs, zip);
|
||||||
|
mBootImg = boot;
|
||||||
|
mode = PATCH_MODE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InstallMagisk(Activity context, List<String> console, List<String> logs, Uri zip, String boot) {
|
||||||
|
this(context, console, logs, zip);
|
||||||
|
mBootLocation = boot;
|
||||||
|
mode = DIRECT_MODE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Boolean doInBackground(Void... voids) {
|
||||||
|
MagiskManager mm = MagiskManager.get();
|
||||||
|
|
||||||
|
File install = new File(
|
||||||
|
(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ?
|
||||||
|
mm.createDeviceProtectedStorageContext() :
|
||||||
|
mm).getFilesDir().getParent()
|
||||||
|
, "install");
|
||||||
|
Shell.sh_raw("rm -rf " + install);
|
||||||
|
|
||||||
|
List<String> abis = Arrays.asList(Build.SUPPORTED_ABIS);
|
||||||
|
String arch;
|
||||||
|
if (abis.contains("x86_64")) arch = "x64";
|
||||||
|
else if (abis.contains("arm64-v8a")) arch = "arm64";
|
||||||
|
else if (abis.contains("x86")) arch = "x86";
|
||||||
|
else arch = "arm";
|
||||||
|
console.add("- Device platform: " + arch);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Unzip files
|
||||||
|
console.add("- Extracting files");
|
||||||
|
try (InputStream in = mm.getContentResolver().openInputStream(mZip)) {
|
||||||
|
if (in == null) throw new FileNotFoundException();
|
||||||
|
BufferedInputStream buf = new BufferedInputStream(in);
|
||||||
|
buf.mark(Integer.MAX_VALUE);
|
||||||
|
ZipUtils.unzip(buf, install, arch + "/", true);
|
||||||
|
buf.reset();
|
||||||
|
ZipUtils.unzip(buf, install, "common/", true);
|
||||||
|
buf.reset();
|
||||||
|
ZipUtils.unzip(buf, install, "chromeos/", false);
|
||||||
|
buf.reset();
|
||||||
|
ZipUtils.unzip(buf, install, "META-INF/com/google/android/update-binary", true);
|
||||||
|
buf.close();
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
console.add("! Invalid Uri");
|
||||||
|
throw e;
|
||||||
|
} catch (Exception e) {
|
||||||
|
console.add("! Cannot unzip zip");
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
Shell.sh("chmod 755 " + install + "/*");
|
||||||
|
|
||||||
|
File boot = new File(install, "boot.img");
|
||||||
|
boolean highCompression = false;
|
||||||
|
switch (mode) {
|
||||||
|
case PATCH_MODE:
|
||||||
|
console.add("- Use boot image: " + boot);
|
||||||
|
// Copy boot image to local
|
||||||
|
try (
|
||||||
|
InputStream in = mm.getContentResolver().openInputStream(mBootImg);
|
||||||
|
OutputStream out = new FileOutputStream(boot)
|
||||||
|
) {
|
||||||
|
InputStream source;
|
||||||
|
if (in == null) throw new FileNotFoundException();
|
||||||
|
|
||||||
|
if (Utils.getNameFromUri(mm, mBootImg).endsWith(".tar")) {
|
||||||
|
// Extract boot.img from tar
|
||||||
|
TarInputStream tar = new TarInputStream(new BufferedInputStream(in));
|
||||||
|
org.kamranzafar.jtar.TarEntry entry;
|
||||||
|
while ((entry = tar.getNextEntry()) != null) {
|
||||||
|
if (entry.getName().equals("boot.img"))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
source = tar;
|
||||||
|
} else {
|
||||||
|
// Direct copy raw image
|
||||||
|
source = new BufferedInputStream(in);
|
||||||
|
}
|
||||||
|
Utils.inToOut(source, out);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
console.add("! Invalid Uri");
|
||||||
|
throw e;
|
||||||
|
} catch (IOException e) {
|
||||||
|
console.add("! Copy failed");
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case DIRECT_MODE:
|
||||||
|
console.add("- Use boot image: " + mBootLocation);
|
||||||
|
if (mm.remoteMagiskVersionCode >= 1463) {
|
||||||
|
List<String> ret = new ArrayList<>();
|
||||||
|
Shell.getShell().run(ret, logs,
|
||||||
|
install + "/magiskboot --parse " + mBootLocation,
|
||||||
|
"echo $?"
|
||||||
|
);
|
||||||
|
if (Utils.isValidShellResponse(ret)) {
|
||||||
|
highCompression = Integer.parseInt(ret.get(ret.size() - 1)) == 2;
|
||||||
|
if (highCompression)
|
||||||
|
console.add("! Insufficient boot partition size detected");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (boot.createNewFile()) {
|
||||||
|
Shell.su("cat " + mBootLocation + " > " + boot);
|
||||||
|
} else {
|
||||||
|
console.add("! Dump boot image failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isSigned;
|
||||||
|
try (InputStream in = new FileInputStream(boot)) {
|
||||||
|
isSigned = SignBoot.verifySignature(in, null);
|
||||||
|
if (isSigned) {
|
||||||
|
console.add("- Signed boot image detected");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
console.add("! Unable to check signature");
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Force non-root shell
|
||||||
|
Shell shell;
|
||||||
|
if (Shell.rootAccess())
|
||||||
|
shell = new Shell("sh");
|
||||||
|
else
|
||||||
|
shell = Shell.getShell();
|
||||||
|
|
||||||
|
// Patch boot image
|
||||||
|
shell.run(console, logs,
|
||||||
|
"cd " + install,
|
||||||
|
Utils.fmt("KEEPFORCEENCRYPT=%b KEEPVERITY=%b HIGHCOMP=%b " +
|
||||||
|
"sh update-binary indep boot_patch.sh %s || echo 'Failed!'",
|
||||||
|
mm.keepEnc, mm.keepVerity, highCompression, boot));
|
||||||
|
|
||||||
|
if (TextUtils.equals(console.get(console.size() - 1), "Failed!"))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
shell.run(null, null,
|
||||||
|
"mv -f new-boot.img ../",
|
||||||
|
"mv bin/busybox busybox",
|
||||||
|
"rm -rf bin *.img update-binary",
|
||||||
|
"cd /");
|
||||||
|
|
||||||
|
File patched_boot = new File(install.getParent(), "new-boot.img");
|
||||||
|
|
||||||
|
if (isSigned) {
|
||||||
|
console.add("- Signing boot image");
|
||||||
|
File signed = new File(install.getParent(), "signed.img");
|
||||||
|
AssetManager assets = mm.getAssets();
|
||||||
|
try (
|
||||||
|
InputStream in = new FileInputStream(patched_boot);
|
||||||
|
OutputStream out = new BufferedOutputStream(new FileOutputStream(signed));
|
||||||
|
InputStream keyIn = assets.open(Const.PRIVATE_KEY_NAME);
|
||||||
|
InputStream certIn = assets.open(Const.PUBLIC_KEY_NAME)
|
||||||
|
) {
|
||||||
|
SignBoot.doSignature("/boot", in, out, keyIn, certIn);
|
||||||
|
}
|
||||||
|
shell.run_raw(false, false, "mv -f " + signed + " " + patched_boot);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (mode) {
|
||||||
|
case PATCH_MODE:
|
||||||
|
File dest = new File(Const.EXTERNAL_PATH, "patched_boot" + mm.bootFormat);
|
||||||
|
dest.getParentFile().mkdirs();
|
||||||
|
OutputStream out;
|
||||||
|
switch (mm.bootFormat) {
|
||||||
|
case ".img.tar":
|
||||||
|
out = new TarOutputStream(new BufferedOutputStream(new FileOutputStream(dest)));
|
||||||
|
((TarOutputStream) out).putNextEntry(new TarEntry(patched_boot, "boot.img"));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
case ".img":
|
||||||
|
out = new BufferedOutputStream(new FileOutputStream(dest));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
try (InputStream in = new BufferedInputStream(new FileInputStream(patched_boot))) {
|
||||||
|
Utils.inToOut(in, out);
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
console.add("");
|
||||||
|
console.add("*********************************");
|
||||||
|
console.add(" Patched Boot Image is placed in ");
|
||||||
|
console.add(" " + dest + " ");
|
||||||
|
console.add("*********************************");
|
||||||
|
break;
|
||||||
|
case DIRECT_MODE:
|
||||||
|
String binPath = mm.remoteMagiskVersionCode >= 1464 ? "/data/adb/magisk" : "/data/magisk";
|
||||||
|
Shell.getShell().run(console, logs,
|
||||||
|
Utils.fmt("rm -rf %s/*; mkdir -p %s; chmod 700 /data/adb", binPath, binPath),
|
||||||
|
Utils.fmt("cp -af %s/* %s; rm -rf %s", install, binPath, install),
|
||||||
|
Utils.fmt("flash_boot_image %s %s", patched_boot, mBootLocation),
|
||||||
|
mm.remoteMagiskVersionCode >= 1464 ? "[ -L /data/magisk.img ] || cp /data/magisk.img /data/adb/magisk.img" : "",
|
||||||
|
mm.keepVerity ? "" : "patch_dtbo_image");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
patched_boot.delete();
|
||||||
|
|
||||||
|
console.add("- All done!");
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Boolean result) {
|
||||||
|
FlashActivity activity = (FlashActivity) getActivity();
|
||||||
|
if (!result) {
|
||||||
|
console.add("! Installation failed");
|
||||||
|
activity.reboot.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
activity.buttonPanel.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
}
|
@@ -1,26 +1,27 @@
|
|||||||
package com.topjohnwu.magisk.asyncs;
|
package com.topjohnwu.magisk.asyncs;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import com.topjohnwu.magisk.MagiskManager;
|
import com.topjohnwu.magisk.MagiskManager;
|
||||||
import com.topjohnwu.magisk.container.Module;
|
import com.topjohnwu.magisk.container.Module;
|
||||||
import com.topjohnwu.magisk.container.ValueSortedMap;
|
import com.topjohnwu.magisk.container.ValueSortedMap;
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
import com.topjohnwu.magisk.utils.Const;
|
||||||
|
import com.topjohnwu.magisk.utils.Shell;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class LoadModules extends ParallelTask<Void, Void, Void> {
|
public class LoadModules extends ParallelTask<Void, Void, Void> {
|
||||||
|
|
||||||
public LoadModules(Context context) {
|
private List<String> getModList() {
|
||||||
super(context);
|
String command = "ls -d " + Const.MAGISK_PATH() + "/* | grep -v lost+found";
|
||||||
|
return Shell.su(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... voids) {
|
protected Void doInBackground(Void... voids) {
|
||||||
MagiskManager mm = getMagiskManager();
|
MagiskManager mm = MagiskManager.get();
|
||||||
if (mm == null) return null;
|
|
||||||
mm.moduleMap = new ValueSortedMap<>();
|
mm.moduleMap = new ValueSortedMap<>();
|
||||||
|
|
||||||
for (String path : Utils.getModList(getShell(), MagiskManager.MAGISK_PATH)) {
|
for (String path : getModList()) {
|
||||||
Module module = new Module(getShell(), path);
|
Module module = new Module(path);
|
||||||
mm.moduleMap.put(module.getId(), module);
|
mm.moduleMap.put(module.getId(), module);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,9 +30,7 @@ public class LoadModules extends ParallelTask<Void, Void, Void> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Void v) {
|
protected void onPostExecute(Void v) {
|
||||||
MagiskManager mm = getMagiskManager();
|
MagiskManager.get().moduleLoadDone.publish();
|
||||||
if (mm == null) return;
|
|
||||||
mm.moduleLoadDone.publish();
|
|
||||||
super.onPostExecute(v);
|
super.onPostExecute(v);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -0,0 +1,84 @@
|
|||||||
|
package com.topjohnwu.magisk.asyncs;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.support.v7.app.AlertDialog;
|
||||||
|
import android.webkit.WebView;
|
||||||
|
|
||||||
|
import com.topjohnwu.magisk.MagiskManager;
|
||||||
|
import com.topjohnwu.magisk.R;
|
||||||
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
|
import com.topjohnwu.magisk.utils.WebService;
|
||||||
|
|
||||||
|
import org.commonmark.node.Node;
|
||||||
|
import org.commonmark.parser.Parser;
|
||||||
|
import org.commonmark.renderer.html.HtmlRenderer;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
public class MarkDownWindow extends ParallelTask<Void, Void, String> {
|
||||||
|
|
||||||
|
private String mTitle;
|
||||||
|
private String mUrl;
|
||||||
|
private InputStream is;
|
||||||
|
|
||||||
|
|
||||||
|
public MarkDownWindow(Activity context, String title, String url) {
|
||||||
|
super(context);
|
||||||
|
mTitle = title;
|
||||||
|
mUrl = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MarkDownWindow(Activity context, String title, InputStream in) {
|
||||||
|
super(context);
|
||||||
|
mTitle = title;
|
||||||
|
is = in;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String doInBackground(Void... voids) {
|
||||||
|
MagiskManager mm = MagiskManager.get();
|
||||||
|
String md;
|
||||||
|
if (mUrl != null) {
|
||||||
|
md = WebService.getString(mUrl);
|
||||||
|
} else {
|
||||||
|
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
||||||
|
Utils.inToOut(is, out);
|
||||||
|
md = out.toString();
|
||||||
|
is.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String css;
|
||||||
|
try (
|
||||||
|
InputStream in = mm.getAssets().open(mm.isDarkTheme ? "dark.css" : "light.css");
|
||||||
|
ByteArrayOutputStream out = new ByteArrayOutputStream()
|
||||||
|
) {
|
||||||
|
Utils.inToOut(in, out);
|
||||||
|
css = out.toString();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
Parser parser = Parser.builder().build();
|
||||||
|
HtmlRenderer renderer = HtmlRenderer.builder().build();
|
||||||
|
Node doc = parser.parse(md);
|
||||||
|
return String.format("<style>%s</style>%s", css, renderer.render(doc));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(String html) {
|
||||||
|
AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
|
||||||
|
alert.setTitle(mTitle);
|
||||||
|
|
||||||
|
WebView wv = new WebView(getActivity());
|
||||||
|
wv.loadDataWithBaseURL("fake://", html, "text/html", "UTF-8", null);
|
||||||
|
|
||||||
|
alert.setView(wv);
|
||||||
|
alert.setNegativeButton(R.string.close, (dialog, id) -> dialog.dismiss());
|
||||||
|
alert.show();
|
||||||
|
}
|
||||||
|
}
|
@@ -1,30 +1,19 @@
|
|||||||
package com.topjohnwu.magisk.asyncs;
|
package com.topjohnwu.magisk.asyncs;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
|
||||||
import com.topjohnwu.magisk.MagiskManager;
|
|
||||||
import com.topjohnwu.magisk.utils.Shell;
|
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
|
|
||||||
public abstract class ParallelTask<Params, Progress, Result> extends AsyncTask<Params, Progress, Result> {
|
public abstract class ParallelTask<Params, Progress, Result> extends AsyncTask<Params, Progress, Result> {
|
||||||
|
|
||||||
private WeakReference<Activity> weakActivity;
|
private WeakReference<Activity> weakActivity;
|
||||||
private WeakReference<MagiskManager> weakMagiskManager;
|
|
||||||
|
|
||||||
private Runnable callback = null;
|
private Runnable callback = null;
|
||||||
|
|
||||||
public ParallelTask() {}
|
public ParallelTask() {}
|
||||||
|
|
||||||
public ParallelTask(Context context) {
|
|
||||||
weakMagiskManager = new WeakReference<>(Utils.getMagiskManager(context));
|
|
||||||
}
|
|
||||||
|
|
||||||
public ParallelTask(Activity context) {
|
public ParallelTask(Activity context) {
|
||||||
this((Context) context);
|
|
||||||
weakActivity = new WeakReference<>(context);
|
weakActivity = new WeakReference<>(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,15 +21,6 @@ public abstract class ParallelTask<Params, Progress, Result> extends AsyncTask<P
|
|||||||
return weakActivity.get();
|
return weakActivity.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected MagiskManager getMagiskManager() {
|
|
||||||
return weakMagiskManager.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Shell getShell() {
|
|
||||||
MagiskManager magiskManager = getMagiskManager();
|
|
||||||
return magiskManager == null ? null : Shell.getShell(magiskManager);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public ParallelTask<Params, Progress, Result> exec(Params... params) {
|
public ParallelTask<Params, Progress, Result> exec(Params... params) {
|
||||||
executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
|
executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
|
@@ -5,13 +5,14 @@ import android.app.Activity;
|
|||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Environment;
|
import android.os.Handler;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.topjohnwu.magisk.FlashActivity;
|
import com.topjohnwu.magisk.FlashActivity;
|
||||||
|
import com.topjohnwu.magisk.MagiskManager;
|
||||||
import com.topjohnwu.magisk.R;
|
import com.topjohnwu.magisk.R;
|
||||||
import com.topjohnwu.magisk.container.InputStreamWrapper;
|
import com.topjohnwu.magisk.utils.Const;
|
||||||
import com.topjohnwu.magisk.utils.Shell;
|
import com.topjohnwu.magisk.utils.Shell;
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
import com.topjohnwu.magisk.utils.WebService;
|
import com.topjohnwu.magisk.utils.WebService;
|
||||||
@@ -22,6 +23,7 @@ import java.io.BufferedOutputStream;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.FilterInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
@@ -37,43 +39,38 @@ public class ProcessRepoZip extends ParallelTask<Void, Object, Boolean> {
|
|||||||
private String mLink;
|
private String mLink;
|
||||||
private File mFile;
|
private File mFile;
|
||||||
private int progress = 0, total = -1;
|
private int progress = 0, total = -1;
|
||||||
|
private Handler mHandler;
|
||||||
private static final int UPDATE_DL_PROG = 0;
|
|
||||||
private static final int SHOW_PROCESSING = 1;
|
|
||||||
|
|
||||||
public ProcessRepoZip(Activity context, String link, String filename, boolean install) {
|
public ProcessRepoZip(Activity context, String link, String filename, boolean install) {
|
||||||
super(context);
|
super(context);
|
||||||
mLink = link;
|
mLink = link;
|
||||||
mFile = new File(Environment.getExternalStorageDirectory() + "/MagiskManager", filename);
|
mFile = new File(Const.EXTERNAL_PATH, filename);
|
||||||
mInstall = install;
|
mInstall = install;
|
||||||
|
mHandler = new Handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeTopFolder(InputStream in, File output) throws IOException {
|
private void removeTopFolder(File input, File output) throws IOException {
|
||||||
JarInputStream source = new JarInputStream(in);
|
|
||||||
JarOutputStream dest = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(output)));
|
|
||||||
JarEntry entry;
|
JarEntry entry;
|
||||||
String path;
|
try (
|
||||||
int size;
|
JarInputStream in = new JarInputStream(new BufferedInputStream(new FileInputStream(input)));
|
||||||
byte buffer[] = new byte[4096];
|
JarOutputStream out = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(output)))
|
||||||
while ((entry = source.getNextJarEntry()) != null) {
|
) {
|
||||||
// Remove the top directory from the path
|
String path;
|
||||||
path = entry.getName().substring(entry.getName().indexOf("/") + 1);
|
while ((entry = in.getNextJarEntry()) != null) {
|
||||||
// If it's the top folder, ignore it
|
// Remove the top directory from the path
|
||||||
if (path.isEmpty()) {
|
path = entry.getName().substring(entry.getName().indexOf("/") + 1);
|
||||||
continue;
|
// If it's the top folder, ignore it
|
||||||
}
|
if (path.isEmpty()) {
|
||||||
// Don't include placeholder
|
continue;
|
||||||
if (path.equals("system/placeholder")) {
|
}
|
||||||
continue;
|
// Don't include placeholder
|
||||||
}
|
if (path.equals("system/placeholder")) {
|
||||||
dest.putNextEntry(new JarEntry(path));
|
continue;
|
||||||
while((size = source.read(buffer)) != -1) {
|
}
|
||||||
dest.write(buffer, 0, size);
|
out.putNextEntry(new JarEntry(path));
|
||||||
|
Utils.inToOut(in, out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
source.close();
|
|
||||||
dest.close();
|
|
||||||
in.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -83,28 +80,11 @@ public class ProcessRepoZip extends ParallelTask<Void, Object, Boolean> {
|
|||||||
progressDialog = ProgressDialog.show(activity, activity.getString(R.string.zip_download_title), activity.getString(R.string.zip_download_msg, 0));
|
progressDialog = ProgressDialog.show(activity, activity.getString(R.string.zip_download_title), activity.getString(R.string.zip_download_msg, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onProgressUpdate(Object... values) {
|
|
||||||
int mode = (int) values[0];
|
|
||||||
switch (mode) {
|
|
||||||
case UPDATE_DL_PROG:
|
|
||||||
int add = (int) values[1];
|
|
||||||
progress += add;
|
|
||||||
progressDialog.setMessage(getActivity().getString(R.string.zip_download_msg, 100 * progress / total));
|
|
||||||
break;
|
|
||||||
case SHOW_PROCESSING:
|
|
||||||
progressDialog.setTitle(R.string.zip_process_title);
|
|
||||||
progressDialog.setMessage(getActivity().getString(R.string.zip_process_msg));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Boolean doInBackground(Void... params) {
|
protected Boolean doInBackground(Void... params) {
|
||||||
Activity activity = getActivity();
|
Activity activity = getActivity();
|
||||||
if (activity == null) return null;
|
if (activity == null) return null;
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// Request zip from Internet
|
// Request zip from Internet
|
||||||
HttpURLConnection conn;
|
HttpURLConnection conn;
|
||||||
do {
|
do {
|
||||||
@@ -117,37 +97,37 @@ public class ProcessRepoZip extends ParallelTask<Void, Object, Boolean> {
|
|||||||
break;
|
break;
|
||||||
} while (true);
|
} while (true);
|
||||||
|
|
||||||
InputStream in = new BufferedInputStream(new ProgressInputStream(conn.getInputStream()));
|
|
||||||
|
|
||||||
// Temp files
|
// Temp files
|
||||||
File temp1 = new File(activity.getCacheDir(), "1.zip");
|
File temp1 = new File(activity.getCacheDir(), "1.zip");
|
||||||
File temp2 = new File(temp1.getParentFile(), "2.zip");
|
File temp2 = new File(temp1.getParentFile(), "2.zip");
|
||||||
temp1.getParentFile().mkdir();
|
temp1.getParentFile().mkdir();
|
||||||
|
|
||||||
// First remove top folder in Github source zip, Web -> temp1
|
// First download the zip, Web -> temp1
|
||||||
removeTopFolder(in, temp1);
|
try (
|
||||||
|
InputStream in = new BufferedInputStream(new ProgressInputStream(conn.getInputStream()));
|
||||||
conn.disconnect();
|
OutputStream out = new BufferedOutputStream(new FileOutputStream(temp1))
|
||||||
publishProgress(SHOW_PROCESSING);
|
|
||||||
|
|
||||||
// Then sign the zip for the first time, temp1 -> temp2
|
|
||||||
ZipUtils.signZip(activity, temp1, temp2, false);
|
|
||||||
|
|
||||||
// Adjust the zip to prevent unzip issues, temp2 -> temp1
|
|
||||||
ZipUtils.zipAdjust(temp2.getPath(), temp1.getPath());
|
|
||||||
|
|
||||||
// Finally, sign the whole zip file again, temp1 -> temp2
|
|
||||||
ZipUtils.signZip(activity, temp1, temp2, true);
|
|
||||||
|
|
||||||
// Write it to the target zip, temp2 -> file
|
|
||||||
try (OutputStream out = new BufferedOutputStream(new FileOutputStream(mFile));
|
|
||||||
InputStream source = new BufferedInputStream(new FileInputStream(temp2))
|
|
||||||
) {
|
) {
|
||||||
byte[] buffer = new byte[4096];
|
Utils.inToOut(in, out);
|
||||||
int length;
|
in.close();
|
||||||
while ((length = source.read(buffer)) > 0)
|
|
||||||
out.write(buffer, 0, length);
|
|
||||||
}
|
}
|
||||||
|
conn.disconnect();
|
||||||
|
|
||||||
|
mHandler.post(() -> {
|
||||||
|
progressDialog.setTitle(R.string.zip_process_title);
|
||||||
|
progressDialog.setMessage(getActivity().getString(R.string.zip_process_msg));
|
||||||
|
});
|
||||||
|
|
||||||
|
// First remove top folder in Github source zip, temp1 -> temp2
|
||||||
|
removeTopFolder(temp1, temp2);
|
||||||
|
|
||||||
|
// Then sign the zip for the first time, temp2 -> temp1
|
||||||
|
ZipUtils.signZip(temp2, temp1, false);
|
||||||
|
|
||||||
|
// Adjust the zip to prevent unzip issues, temp1 -> temp2
|
||||||
|
ZipUtils.zipAdjust(temp1.getPath(), temp2.getPath());
|
||||||
|
|
||||||
|
// Finally, sign the whole zip file again, temp2 -> target
|
||||||
|
ZipUtils.signZip(temp2, mFile, true);
|
||||||
|
|
||||||
// Delete temp files
|
// Delete temp files
|
||||||
temp1.delete();
|
temp1.delete();
|
||||||
@@ -165,17 +145,17 @@ public class ProcessRepoZip extends ParallelTask<Void, Object, Boolean> {
|
|||||||
Activity activity = getActivity();
|
Activity activity = getActivity();
|
||||||
if (activity == null) return;
|
if (activity == null) return;
|
||||||
progressDialog.dismiss();
|
progressDialog.dismiss();
|
||||||
Uri uri = Uri.fromFile(mFile);
|
|
||||||
if (result) {
|
if (result) {
|
||||||
|
Uri uri = Uri.fromFile(mFile);
|
||||||
if (Shell.rootAccess() && mInstall) {
|
if (Shell.rootAccess() && mInstall) {
|
||||||
Intent intent = new Intent(getActivity(), FlashActivity.class);
|
Intent intent = new Intent(activity, FlashActivity.class);
|
||||||
intent.setData(uri).putExtra(FlashActivity.SET_ACTION, FlashActivity.FLASH_ZIP);
|
intent.setData(uri).putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_ZIP);
|
||||||
activity.startActivity(intent);
|
activity.startActivity(intent);
|
||||||
} else {
|
} else {
|
||||||
Utils.showUriSnack(activity, uri);
|
Utils.showUriSnack(activity, uri);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Utils.getMagiskManager(activity).toast(R.string.process_error, Toast.LENGTH_LONG);
|
MagiskManager.toast(R.string.process_error, Toast.LENGTH_LONG);
|
||||||
}
|
}
|
||||||
super.onPostExecute(result);
|
super.onPostExecute(result);
|
||||||
}
|
}
|
||||||
@@ -187,16 +167,24 @@ public class ProcessRepoZip extends ParallelTask<Void, Object, Boolean> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ProgressInputStream extends InputStreamWrapper {
|
private class ProgressInputStream extends FilterInputStream {
|
||||||
|
|
||||||
ProgressInputStream(InputStream in) {
|
ProgressInputStream(InputStream in) {
|
||||||
super(in);
|
super(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateDlProgress(int step) {
|
||||||
|
progress += step;
|
||||||
|
progressDialog.setMessage(getActivity().getString(R.string.zip_download_msg, (int) (100 * (double) progress / total + 0.5)));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized int read() throws IOException {
|
public synchronized int read() throws IOException {
|
||||||
publishProgress(UPDATE_DL_PROG, 1);
|
int b = super.read();
|
||||||
return super.read();
|
if (b > 0) {
|
||||||
|
mHandler.post(() -> updateDlProgress(1));
|
||||||
|
}
|
||||||
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -207,7 +195,9 @@ public class ProcessRepoZip extends ParallelTask<Void, Object, Boolean> {
|
|||||||
@Override
|
@Override
|
||||||
public synchronized int read(@NonNull byte[] b, int off, int len) throws IOException {
|
public synchronized int read(@NonNull byte[] b, int off, int len) throws IOException {
|
||||||
int read = super.read(b, off, len);
|
int read = super.read(b, off, len);
|
||||||
publishProgress(UPDATE_DL_PROG, read);
|
if (read > 0) {
|
||||||
|
mHandler.post(() -> updateDlProgress(read));
|
||||||
|
}
|
||||||
return read;
|
return read;
|
||||||
}
|
}
|
||||||
}
|
}
|
40
src/main/java/com/topjohnwu/magisk/asyncs/RestoreImages.java
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
package com.topjohnwu.magisk.asyncs;
|
||||||
|
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.topjohnwu.magisk.MagiskManager;
|
||||||
|
import com.topjohnwu.magisk.R;
|
||||||
|
import com.topjohnwu.magisk.utils.Shell;
|
||||||
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class RestoreImages extends ParallelTask<Void, Void, Boolean> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Boolean doInBackground(Void... voids) {
|
||||||
|
String sha1;
|
||||||
|
List<String> ret = Utils.readFile("/.backup/.sha1");
|
||||||
|
if (Utils.isValidShellResponse(ret)) {
|
||||||
|
sha1 = ret.get(0);
|
||||||
|
} else {
|
||||||
|
ret = Shell.su("cat /init.magisk.rc | grep STOCKSHA1");
|
||||||
|
if (!Utils.isValidShellResponse(ret))
|
||||||
|
return false;
|
||||||
|
sha1 = ret.get(0).substring(ret.get(0).indexOf('=') + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = Shell.su("restore_imgs " + sha1 + " && echo true || echo false");
|
||||||
|
|
||||||
|
return Utils.isValidShellResponse(ret) && Boolean.parseBoolean(ret.get(ret.size() - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Boolean result) {
|
||||||
|
if (result) {
|
||||||
|
MagiskManager.toast(R.string.restore_done, Toast.LENGTH_SHORT);
|
||||||
|
} else {
|
||||||
|
MagiskManager.toast(R.string.restore_fail, Toast.LENGTH_LONG);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1,6 +1,5 @@
|
|||||||
package com.topjohnwu.magisk.asyncs;
|
package com.topjohnwu.magisk.asyncs;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
|
||||||
@@ -8,6 +7,7 @@ import com.topjohnwu.magisk.MagiskManager;
|
|||||||
import com.topjohnwu.magisk.ReposFragment;
|
import com.topjohnwu.magisk.ReposFragment;
|
||||||
import com.topjohnwu.magisk.container.Repo;
|
import com.topjohnwu.magisk.container.Repo;
|
||||||
import com.topjohnwu.magisk.database.RepoDatabaseHelper;
|
import com.topjohnwu.magisk.database.RepoDatabaseHelper;
|
||||||
|
import com.topjohnwu.magisk.utils.Const;
|
||||||
import com.topjohnwu.magisk.utils.Logger;
|
import com.topjohnwu.magisk.utils.Logger;
|
||||||
import com.topjohnwu.magisk.utils.WebService;
|
import com.topjohnwu.magisk.utils.WebService;
|
||||||
|
|
||||||
@@ -27,12 +27,6 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class UpdateRepos extends ParallelTask<Void, Void, Void> {
|
public class UpdateRepos extends ParallelTask<Void, Void, Void> {
|
||||||
|
|
||||||
private static final String REPO_URL = "https://api.github.com/users/Magisk-Modules-Repo/repos?per_page=100&page=%d";
|
|
||||||
|
|
||||||
public static final String ETAG_KEY = "ETag";
|
|
||||||
private static final String IF_NONE_MATCH = "If-None-Match";
|
|
||||||
private static final String LINK_KEY = "Link";
|
|
||||||
|
|
||||||
private static final int CHECK_ETAG = 0;
|
private static final int CHECK_ETAG = 0;
|
||||||
private static final int LOAD_NEXT = 1;
|
private static final int LOAD_NEXT = 1;
|
||||||
private static final int LOAD_PREV = 2;
|
private static final int LOAD_PREV = 2;
|
||||||
@@ -44,16 +38,16 @@ public class UpdateRepos extends ParallelTask<Void, Void, Void> {
|
|||||||
|
|
||||||
private int tasks = 0;
|
private int tasks = 0;
|
||||||
|
|
||||||
public UpdateRepos(Context context, boolean force) {
|
public UpdateRepos(boolean force) {
|
||||||
super(context);
|
MagiskManager mm = MagiskManager.get();
|
||||||
prefs = getMagiskManager().prefs;
|
prefs = mm.prefs;
|
||||||
repoDB = getMagiskManager().repoDB;
|
repoDB = mm.repoDB;
|
||||||
getMagiskManager().repoLoadDone.hasPublished = false;
|
mm.repoLoadDone.hasPublished = false;
|
||||||
// Legacy data cleanup
|
// Legacy data cleanup
|
||||||
File old = new File(context.getApplicationInfo().dataDir + "/shared_prefs", "RepoMap.xml");
|
File old = new File(mm.getApplicationInfo().dataDir + "/shared_prefs", "RepoMap.xml");
|
||||||
if (old.exists() || prefs.getString("repomap", null) != null) {
|
if (old.exists() || prefs.getString("repomap", null) != null) {
|
||||||
old.delete();
|
old.delete();
|
||||||
prefs.edit().remove("version").remove("repomap").remove(ETAG_KEY).apply();
|
prefs.edit().remove("version").remove("repomap").remove(Const.Key.ETAG_KEY).apply();
|
||||||
repoDB.clearRepo();
|
repoDB.clearRepo();
|
||||||
}
|
}
|
||||||
forceUpdate = force;
|
forceUpdate = force;
|
||||||
@@ -112,8 +106,8 @@ public class UpdateRepos extends ParallelTask<Void, Void, Void> {
|
|||||||
if (mode == CHECK_ETAG && page < etags.size()) {
|
if (mode == CHECK_ETAG && page < etags.size()) {
|
||||||
etag = etags.get(page);
|
etag = etags.get(page);
|
||||||
}
|
}
|
||||||
header.put(IF_NONE_MATCH, etag);
|
header.put(Const.Key.IF_NONE_MATCH, etag);
|
||||||
String url = String.format(Locale.US, REPO_URL, page + 1);
|
String url = String.format(Locale.US, Const.Url.REPO_URL, page + 1);
|
||||||
HttpURLConnection conn = WebService.request(url, header);
|
HttpURLConnection conn = WebService.request(url, header);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -130,11 +124,11 @@ public class UpdateRepos extends ParallelTask<Void, Void, Void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update ETAG
|
// Update ETAG
|
||||||
etag = header.get(ETAG_KEY);
|
etag = header.get(Const.Key.ETAG_KEY);
|
||||||
etag = etag.substring(etag.indexOf('\"'), etag.lastIndexOf('\"') + 1);
|
etag = etag.substring(etag.indexOf('\"'), etag.lastIndexOf('\"') + 1);
|
||||||
newEtags.add(etag);
|
newEtags.add(etag);
|
||||||
|
|
||||||
String links = header.get(LINK_KEY);
|
String links = header.get(Const.Key.LINK_KEY);
|
||||||
if (links != null) {
|
if (links != null) {
|
||||||
for (String s : links.split(", ")) {
|
for (String s : links.split(", ")) {
|
||||||
if (mode != LOAD_PREV && s.contains("next")) {
|
if (mode != LOAD_PREV && s.contains("next")) {
|
||||||
@@ -168,7 +162,7 @@ public class UpdateRepos extends ParallelTask<Void, Void, Void> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... voids) {
|
protected Void doInBackground(Void... voids) {
|
||||||
etags = new ArrayList<>(Arrays.asList(prefs.getString(ETAG_KEY, "").split(",")));
|
etags = new ArrayList<>(Arrays.asList(prefs.getString(Const.Key.ETAG_KEY, "").split(",")));
|
||||||
cached = repoDB.getRepoIDList();
|
cached = repoDB.getRepoIDList();
|
||||||
|
|
||||||
if (!loadPage(0, CHECK_ETAG)) {
|
if (!loadPage(0, CHECK_ETAG)) {
|
||||||
@@ -205,15 +199,13 @@ public class UpdateRepos extends ParallelTask<Void, Void, Void> {
|
|||||||
if (i != 0) etagBuilder.append(",");
|
if (i != 0) etagBuilder.append(",");
|
||||||
etagBuilder.append(newEtags.get(i));
|
etagBuilder.append(newEtags.get(i));
|
||||||
}
|
}
|
||||||
prefs.edit().putString(ETAG_KEY, etagBuilder.toString()).apply();
|
prefs.edit().putString(Const.Key.ETAG_KEY, etagBuilder.toString()).apply();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Void v) {
|
protected void onPostExecute(Void v) {
|
||||||
MagiskManager mm = getMagiskManager();
|
MagiskManager.get().repoLoadDone.publish();
|
||||||
if (mm == null) return;
|
|
||||||
mm.repoLoadDone.publish();
|
|
||||||
super.onPostExecute(v);
|
super.onPostExecute(v);
|
||||||
}
|
}
|
||||||
}
|
}
|
135
src/main/java/com/topjohnwu/magisk/components/Activity.java
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
package com.topjohnwu.magisk.components;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.res.AssetManager;
|
||||||
|
import android.content.res.Configuration;
|
||||||
|
import android.content.res.Resources;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.Keep;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.annotation.StyleRes;
|
||||||
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
import android.view.WindowManager;
|
||||||
|
|
||||||
|
import com.topjohnwu.magisk.MagiskManager;
|
||||||
|
import com.topjohnwu.magisk.R;
|
||||||
|
import com.topjohnwu.magisk.utils.Topic;
|
||||||
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
|
|
||||||
|
public abstract class Activity extends AppCompatActivity {
|
||||||
|
|
||||||
|
private AssetManager swappedAssetManager = null;
|
||||||
|
private Resources swappedResources = null;
|
||||||
|
private Resources.Theme swappedTheme = null;
|
||||||
|
private ActivityResultListener activityResultListener;
|
||||||
|
|
||||||
|
public Activity() {
|
||||||
|
super();
|
||||||
|
Configuration configuration = new Configuration();
|
||||||
|
configuration.setLocale(MagiskManager.locale);
|
||||||
|
applyOverrideConfiguration(configuration);
|
||||||
|
}
|
||||||
|
|
||||||
|
@StyleRes
|
||||||
|
abstract public int getDarkTheme();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
if (this instanceof Topic.Subscriber) {
|
||||||
|
((Topic.Subscriber) this).subscribeTopics();
|
||||||
|
}
|
||||||
|
if (getMagiskManager().isDarkTheme && getDarkTheme() > 0) {
|
||||||
|
setTheme(getDarkTheme());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDestroy() {
|
||||||
|
if (this instanceof Topic.Subscriber) {
|
||||||
|
((Topic.Subscriber) this).unsubscribeTopics();
|
||||||
|
}
|
||||||
|
super.onDestroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||||
|
MagiskManager mm = getMagiskManager();
|
||||||
|
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||||
|
if (mm.permissionGrantCallback != null) {
|
||||||
|
mm.permissionGrantCallback.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mm.permissionGrantCallback = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Resources.Theme getTheme() {
|
||||||
|
return swappedTheme == null ? super.getTheme() : swappedTheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AssetManager getAssets() {
|
||||||
|
return swappedAssetManager == null ? super.getAssets() : swappedAssetManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Resources getResources() {
|
||||||
|
return swappedResources == null ? super.getResources() : swappedResources;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MagiskManager getMagiskManager() {
|
||||||
|
return (MagiskManager) super.getApplicationContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setFloating() {
|
||||||
|
boolean isTablet = getResources().getBoolean(R.bool.isTablet);
|
||||||
|
if (isTablet) {
|
||||||
|
WindowManager.LayoutParams params = getWindow().getAttributes();
|
||||||
|
params.height = getResources().getDimensionPixelSize(R.dimen.floating_height);
|
||||||
|
params.width = getResources().getDimensionPixelSize(R.dimen.floating_width);
|
||||||
|
params.alpha = 1.0f;
|
||||||
|
params.dimAmount = 0.6f;
|
||||||
|
params.flags |= 2;
|
||||||
|
getWindow().setAttributes(params);
|
||||||
|
setFinishOnTouchOutside(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
if (activityResultListener != null)
|
||||||
|
activityResultListener.onActivityResult(requestCode, resultCode, data);
|
||||||
|
activityResultListener = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startActivityForResult(Intent intent, int requestCode, ActivityResultListener listener) {
|
||||||
|
activityResultListener = listener;
|
||||||
|
super.startActivityForResult(intent, requestCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Keep
|
||||||
|
public void swapResources(String dexPath, int resId) {
|
||||||
|
swappedAssetManager = Utils.getAssets(dexPath);
|
||||||
|
if (swappedAssetManager == null)
|
||||||
|
return;
|
||||||
|
Resources res = super.getResources();
|
||||||
|
swappedResources = new Resources(swappedAssetManager, res.getDisplayMetrics(), res.getConfiguration());
|
||||||
|
swappedTheme = swappedResources.newTheme();
|
||||||
|
swappedTheme.applyStyle(resId, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Keep
|
||||||
|
public void restoreResources() {
|
||||||
|
swappedAssetManager = null;
|
||||||
|
swappedResources = null;
|
||||||
|
swappedTheme = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface ActivityResultListener {
|
||||||
|
void onActivityResult(int requestCode, int resultCode, Intent data);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -9,8 +9,6 @@ import android.support.annotation.StyleRes;
|
|||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.view.ViewStub;
|
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
@@ -29,7 +27,6 @@ public class AlertDialogBuilder extends AlertDialog.Builder {
|
|||||||
@BindView(R.id.positive) Button positive;
|
@BindView(R.id.positive) Button positive;
|
||||||
@BindView(R.id.neutral) Button neutral;
|
@BindView(R.id.neutral) Button neutral;
|
||||||
@BindView(R.id.message) TextView messageView;
|
@BindView(R.id.message) TextView messageView;
|
||||||
@BindView(R.id.custom_view) ViewStub custom;
|
|
||||||
|
|
||||||
private DialogInterface.OnClickListener positiveListener;
|
private DialogInterface.OnClickListener positiveListener;
|
||||||
private DialogInterface.OnClickListener negativeListener;
|
private DialogInterface.OnClickListener negativeListener;
|
||||||
@@ -59,20 +56,15 @@ public class AlertDialogBuilder extends AlertDialog.Builder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AlertDialog.Builder setView(int layoutResId) {
|
public AlertDialog.Builder setTitle(int titleId) {
|
||||||
custom.setLayoutResource(layoutResId);
|
return super.setTitle(titleId);
|
||||||
custom.inflate();
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AlertDialog.Builder setView(View view) {
|
public AlertDialog.Builder setView(int layoutResId) { return this; }
|
||||||
ViewGroup parent = (ViewGroup) custom.getParent();
|
|
||||||
int idx = parent.indexOfChild(custom);
|
@Override
|
||||||
parent.removeView(custom);
|
public AlertDialog.Builder setView(View view) { return this; }
|
||||||
parent.addView(view, idx);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AlertDialog.Builder setMessage(@Nullable CharSequence message) {
|
public AlertDialog.Builder setMessage(@Nullable CharSequence message) {
|
@@ -3,22 +3,15 @@ package com.topjohnwu.magisk.components;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
|
||||||
import com.topjohnwu.magisk.MagiskManager;
|
import com.topjohnwu.magisk.MagiskManager;
|
||||||
import com.topjohnwu.magisk.utils.Shell;
|
|
||||||
import com.topjohnwu.magisk.utils.Topic;
|
import com.topjohnwu.magisk.utils.Topic;
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
|
|
||||||
public class Fragment extends android.support.v4.app.Fragment {
|
public class Fragment extends android.support.v4.app.Fragment {
|
||||||
|
|
||||||
private ActivityResultListener activityResultListener;
|
|
||||||
|
|
||||||
public MagiskManager getApplication() {
|
public MagiskManager getApplication() {
|
||||||
return Utils.getMagiskManager(getActivity());
|
return Utils.getMagiskManager(getActivity());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Shell getShell() {
|
|
||||||
return Shell.getShell(getActivity());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
@@ -36,18 +29,11 @@ public class Fragment extends android.support.v4.app.Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
public void startActivityForResult(Intent intent, int requestCode) {
|
||||||
if (activityResultListener != null)
|
startActivityForResult(intent, requestCode, this::onActivityResult);
|
||||||
activityResultListener.onActivityResult(requestCode, resultCode, data);
|
|
||||||
activityResultListener = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startActivityForResult(Intent intent, int requestCode, ActivityResultListener listener) {
|
public void startActivityForResult(Intent intent, int requestCode, Activity.ActivityResultListener listener) {
|
||||||
activityResultListener = listener;
|
((Activity) getActivity()).startActivityForResult(intent, requestCode, listener);
|
||||||
super.startActivityForResult(intent, requestCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface ActivityResultListener {
|
|
||||||
void onActivityResult(int requestCode, int resultCode, Intent data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -10,7 +10,7 @@ import java.util.List;
|
|||||||
public abstract class BaseModule implements Comparable<BaseModule> {
|
public abstract class BaseModule implements Comparable<BaseModule> {
|
||||||
|
|
||||||
private String mId = null, mName, mVersion, mAuthor, mDescription;
|
private String mId = null, mName, mVersion, mAuthor, mDescription;
|
||||||
private int mVersionCode = -1, templateVersion = -1;
|
private int mVersionCode = -1, minMagiskVersion = -1;
|
||||||
|
|
||||||
protected BaseModule() {}
|
protected BaseModule() {}
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ public abstract class BaseModule implements Comparable<BaseModule> {
|
|||||||
mVersionCode = c.getInt(c.getColumnIndex("versionCode"));
|
mVersionCode = c.getInt(c.getColumnIndex("versionCode"));
|
||||||
mAuthor = c.getString(c.getColumnIndex("author"));
|
mAuthor = c.getString(c.getColumnIndex("author"));
|
||||||
mDescription = c.getString(c.getColumnIndex("description"));
|
mDescription = c.getString(c.getColumnIndex("description"));
|
||||||
templateVersion = c.getInt(c.getColumnIndex("template"));
|
minMagiskVersion = c.getInt(c.getColumnIndex("minMagisk"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContentValues getContentValues() {
|
public ContentValues getContentValues() {
|
||||||
@@ -32,7 +32,7 @@ public abstract class BaseModule implements Comparable<BaseModule> {
|
|||||||
values.put("versionCode", mVersionCode);
|
values.put("versionCode", mVersionCode);
|
||||||
values.put("author", mAuthor);
|
values.put("author", mAuthor);
|
||||||
values.put("description", mDescription);
|
values.put("description", mDescription);
|
||||||
values.put("template", templateVersion);
|
values.put("minMagisk", minMagiskVersion);
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,8 +67,9 @@ public abstract class BaseModule implements Comparable<BaseModule> {
|
|||||||
case "description":
|
case "description":
|
||||||
mDescription = prop[1];
|
mDescription = prop[1];
|
||||||
break;
|
break;
|
||||||
|
case "minMagisk":
|
||||||
case "template":
|
case "template":
|
||||||
templateVersion = Integer.parseInt(prop[1]);
|
minMagiskVersion = Integer.parseInt(prop[1]);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -108,8 +109,8 @@ public abstract class BaseModule implements Comparable<BaseModule> {
|
|||||||
return mVersionCode;
|
return mVersionCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getTemplateVersion() {
|
public int getMinMagiskVersion() {
|
||||||
return templateVersion;
|
return minMagiskVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|