Replace reset with speed optimize (#50)
This commit is contained in:
parent
73f9a8d6af
commit
425b11f152
|
|
@ -66,11 +66,9 @@ dependencies {
|
|||
implementation "androidx.recyclerview:recyclerview:1.1.0"
|
||||
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
|
||||
implementation 'com.github.bumptech.glide:glide:4.11.0'
|
||||
implementation "com.github.topjohnwu.libsu:core:2.5.1"
|
||||
implementation 'com.google.android.material:material:1.2.1'
|
||||
implementation 'com.takisoft.preferencex:preferencex:1.1.0'
|
||||
implementation 'com.takisoft.preferencex:preferencex-colorpicker:1.1.0'
|
||||
implementation "rikka.shizuku:api:11.0.1"
|
||||
implementation 'tech.rectifier.preferencex-android:preferencex-simplemenu:88f93154b2'
|
||||
implementation 'me.zhanghai.android.appiconloader:appiconloader-glide:1.2.0'
|
||||
implementation 'me.zhanghai.android.fastscroll:library:1.1.5'
|
||||
|
|
|
|||
|
|
@ -4,8 +4,6 @@ import android.annotation.SuppressLint;
|
|||
import android.app.Application;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
|
|
@ -13,61 +11,18 @@ import java.io.PrintWriter;
|
|||
import java.io.StringWriter;
|
||||
|
||||
import io.github.lsposed.manager.ui.activity.CrashReportActivity;
|
||||
import io.github.lsposed.manager.util.CompileUtil;
|
||||
import io.github.lsposed.manager.util.NotificationUtil;
|
||||
import rikka.shizuku.Shizuku;
|
||||
import rikka.sui.Sui;
|
||||
|
||||
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
||||
|
||||
public class App extends Application {
|
||||
public static final String TAG = "LSPosedManager";
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private static App instance = null;
|
||||
private static Thread uiThread;
|
||||
private static Handler mainHandler;
|
||||
private SharedPreferences pref;
|
||||
|
||||
private final Shizuku.OnRequestPermissionResultListener REQUEST_PERMISSION_RESULT_LISTENER = this::onRequestPermissionsResult;
|
||||
|
||||
static {
|
||||
Sui.init(BuildConfig.APPLICATION_ID);
|
||||
}
|
||||
|
||||
private void onRequestPermissionsResult(int requestCode, int grantResult) {
|
||||
CompileUtil.onRequestPermissionsResult(requestCode, grantResult);
|
||||
}
|
||||
|
||||
public static int checkPermission(int code) {
|
||||
try {
|
||||
if (!Shizuku.isPreV11() && Shizuku.getVersion() >= 11) {
|
||||
if (Shizuku.checkSelfPermission() == PERMISSION_GRANTED) {
|
||||
return 0;
|
||||
} else if (Shizuku.shouldShowRequestPermissionRationale()) {
|
||||
return -1;
|
||||
} else {
|
||||
Shizuku.requestPermission(code);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return -2;
|
||||
}
|
||||
|
||||
public static App getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static void runOnUiThread(Runnable action) {
|
||||
if (Thread.currentThread() != uiThread) {
|
||||
mainHandler.post(action);
|
||||
} else {
|
||||
action.run();
|
||||
}
|
||||
}
|
||||
|
||||
public static SharedPreferences getPreferences() {
|
||||
return instance.pref;
|
||||
}
|
||||
|
|
@ -104,13 +59,9 @@ public class App extends Application {
|
|||
}
|
||||
|
||||
instance = this;
|
||||
uiThread = Thread.currentThread();
|
||||
mainHandler = new Handler(Looper.getMainLooper());
|
||||
|
||||
pref = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
|
||||
NotificationUtil.init();
|
||||
|
||||
Shizuku.addRequestPermissionResultListener(REQUEST_PERMISSION_RESULT_LISTENER);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,8 +47,8 @@ import java.util.List;
|
|||
import io.github.lsposed.manager.App;
|
||||
import io.github.lsposed.manager.R;
|
||||
import io.github.lsposed.manager.ui.activity.AppListActivity;
|
||||
import io.github.lsposed.manager.ui.fragment.CompileDialogFragment;
|
||||
import io.github.lsposed.manager.ui.widget.MasterSwitch;
|
||||
import io.github.lsposed.manager.util.CompileUtil;
|
||||
import io.github.lsposed.manager.util.GlideApp;
|
||||
import io.github.lsposed.manager.util.ModuleUtil;
|
||||
|
||||
|
|
@ -247,8 +247,8 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
|
|||
if (launchIntent != null) {
|
||||
activity.startActivity(launchIntent);
|
||||
}
|
||||
} else if (itemId == R.id.app_menu_compile_reset) {
|
||||
CompileUtil.reset(activity, activity.getSupportFragmentManager(), info);
|
||||
} else if (itemId == R.id.app_menu_compile_speed) {
|
||||
CompileDialogFragment.speed(activity, activity.getSupportFragmentManager(), info);
|
||||
} else if (itemId == R.id.app_menu_store) {
|
||||
Uri uri = Uri.parse("market://details?id=" + info.packageName);
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
||||
|
|
@ -352,7 +352,7 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
|
|||
menu.removeItem(R.id.app_menu_launch);
|
||||
}
|
||||
if (android) {
|
||||
menu.removeItem(R.id.app_menu_compile_reset);
|
||||
menu.removeItem(R.id.app_menu_compile_speed);
|
||||
menu.removeItem(R.id.app_menu_store);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -12,50 +12,40 @@ import android.view.LayoutInflater;
|
|||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatDialogFragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import com.topjohnwu.superuser.Shell;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import io.github.lsposed.manager.App;
|
||||
import io.github.lsposed.manager.R;
|
||||
import io.github.lsposed.manager.databinding.FragmentCompileDialogBinding;
|
||||
import io.github.lsposed.manager.util.CompileUtil;
|
||||
import io.github.lsposed.manager.util.ToastUtil;
|
||||
import rikka.shizuku.ShizukuSystemProperties;
|
||||
|
||||
import static android.content.pm.PackageManager.PERMISSION_DENIED;
|
||||
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class CompileDialogFragment extends AppCompatDialogFragment {
|
||||
|
||||
// TODO:
|
||||
private static final String COMPILE_COMMAND_PREFIX = "cmd package ";
|
||||
private static final String COMPILE_RESET_COMMAND = COMPILE_COMMAND_PREFIX + "compile --reset ";
|
||||
private static final String[] COMPILE_RESET_COMMAND = new String[]{"cmd", "package", "compile", "-f", "-m", "speed", ""};
|
||||
|
||||
private static final String KEY_APP_INFO = "app_info";
|
||||
private static final String KEY_MSG = "msg";
|
||||
private static final String KEY_TYPE = "type";
|
||||
private ApplicationInfo appInfo;
|
||||
|
||||
|
||||
public CompileDialogFragment() {
|
||||
}
|
||||
|
||||
public static CompileDialogFragment newInstance(ApplicationInfo appInfo,
|
||||
String msg, CompileUtil.CompileType type) {
|
||||
public static void speed(Context context, FragmentManager fragmentManager, ApplicationInfo info) {
|
||||
Bundle arguments = new Bundle();
|
||||
arguments.putParcelable(KEY_APP_INFO, appInfo);
|
||||
arguments.putString(KEY_MSG, msg);
|
||||
arguments.putInt(KEY_TYPE, type.ordinal());
|
||||
arguments.putParcelable(KEY_APP_INFO, info);
|
||||
arguments.putString(KEY_MSG, context.getString(R.string.compile_speed_msg));
|
||||
CompileDialogFragment fragment = new CompileDialogFragment();
|
||||
fragment.setArguments(arguments);
|
||||
fragment.setCancelable(false);
|
||||
return fragment;
|
||||
fragment.show(fragmentManager, "compile_dialog");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -83,66 +73,14 @@ public class CompileDialogFragment extends AppCompatDialogFragment {
|
|||
return alertDialog;
|
||||
}
|
||||
|
||||
public void onRequestPermissionsResult(int requestCode, int grantResult) {
|
||||
CompileUtil.CompileType mode = CompileUtil.CompileType.values()[requestCode];
|
||||
if (grantResult == PERMISSION_GRANTED) {
|
||||
AsyncTask.THREAD_POOL_EXECUTOR.execute(() -> {
|
||||
try {
|
||||
boolean checkProfiles = ShizukuSystemProperties.getBoolean("dalvik.vm.usejitprofiles", false);
|
||||
if (mode == CompileUtil.CompileType.RESET) {
|
||||
CompileUtil.PACKAGE_MANAGER.get().clearApplicationProfileData(appInfo.packageName);
|
||||
String filter = ShizukuSystemProperties.get("pm.dexopt.install");
|
||||
CompileUtil.PACKAGE_MANAGER.get().performDexOptMode(appInfo.packageName, checkProfiles, filter, true, true, null);
|
||||
}
|
||||
App.runOnUiThread(() -> {
|
||||
ToastUtil.showLongToast(App.getInstance(), R.string.done);
|
||||
try {
|
||||
dismissAllowingStateLoss();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
compileWithShell(mode);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
compileWithShell(mode);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(@NonNull Context context) {
|
||||
super.onAttach(context);
|
||||
Bundle arguments = getArguments();
|
||||
if (arguments != null) {
|
||||
int type = arguments.getInt(KEY_TYPE);
|
||||
appInfo = arguments.getParcelable(KEY_APP_INFO);
|
||||
int result = App.checkPermission(type);
|
||||
switch (result) {
|
||||
case 0:
|
||||
onRequestPermissionsResult(type, PERMISSION_GRANTED);
|
||||
break;
|
||||
case -2:
|
||||
onRequestPermissionsResult(type, PERMISSION_DENIED);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
dismissAllowingStateLoss();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void compileWithShell(CompileUtil.CompileType type) {
|
||||
String command = null;
|
||||
if (type == CompileUtil.CompileType.RESET) {
|
||||
command = COMPILE_RESET_COMMAND + appInfo.packageName;
|
||||
}
|
||||
if (command != null) {
|
||||
String[] command = COMPILE_RESET_COMMAND;
|
||||
command[6] = appInfo.packageName;
|
||||
new CompileTask(this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, command);
|
||||
} else {
|
||||
try {
|
||||
|
|
@ -164,18 +102,37 @@ public class CompileDialogFragment extends AppCompatDialogFragment {
|
|||
@Override
|
||||
protected String doInBackground(String... commands) {
|
||||
if (outerRef.get() == null) {
|
||||
return App.getInstance().getString(R.string.compile_failed);
|
||||
return "";
|
||||
}
|
||||
// Also get STDERR
|
||||
List<String> stdout = new ArrayList<>();
|
||||
List<String> stderr = new ArrayList<>();
|
||||
Shell.Result result = Shell.su(commands).to(stdout, stderr).exec();
|
||||
if (stderr.size() > 0) {
|
||||
return "Error: " + TextUtils.join("\n", stderr);
|
||||
} else if (!result.isSuccess()) { // they might don't write to stderr
|
||||
return "Error: " + TextUtils.join("\n", stdout);
|
||||
} else {
|
||||
return TextUtils.join("\n", stdout);
|
||||
try {
|
||||
Process process = Runtime.getRuntime().exec(commands);
|
||||
BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
|
||||
BufferedReader inputReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||
int read;
|
||||
char[] buffer = new char[4096];
|
||||
StringBuilder err = new StringBuilder();
|
||||
while ((read = errorReader.read(buffer)) > 0) {
|
||||
err.append(buffer, 0, read);
|
||||
}
|
||||
StringBuilder input = new StringBuilder();
|
||||
while ((read = inputReader.read(buffer)) > 0) {
|
||||
input.append(buffer, 0, read);
|
||||
}
|
||||
errorReader.close();
|
||||
inputReader.close();
|
||||
process.waitFor();
|
||||
String result = "";
|
||||
if (process.exitValue() != 0) {
|
||||
result = "Error ";
|
||||
}
|
||||
if (TextUtils.isEmpty(err)) {
|
||||
return result + input.toString();
|
||||
} else {
|
||||
return result + err.toString();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return "Error " + e.getCause();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,55 +0,0 @@
|
|||
package io.github.lsposed.manager.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.IPackageManager;
|
||||
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
import io.github.lsposed.manager.R;
|
||||
import io.github.lsposed.manager.ui.fragment.CompileDialogFragment;
|
||||
import rikka.shizuku.ShizukuBinderWrapper;
|
||||
import rikka.shizuku.SystemServiceHelper;
|
||||
|
||||
public class CompileUtil {
|
||||
// TODO:
|
||||
|
||||
public enum CompileType {
|
||||
RESET;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString().toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
private static CompileDialogFragment instance;
|
||||
|
||||
private static final String TAG_COMPILE_DIALOG = "compile_dialog";
|
||||
|
||||
public static final Singleton<IPackageManager> PACKAGE_MANAGER = new Singleton<IPackageManager>() {
|
||||
@Override
|
||||
protected IPackageManager create() {
|
||||
return IPackageManager.Stub.asInterface(new ShizukuBinderWrapper(SystemServiceHelper.getSystemService("package")));
|
||||
}
|
||||
};
|
||||
|
||||
public static void onRequestPermissionsResult(int requestCode, int grantResult) {
|
||||
if (instance != null) {
|
||||
instance.onRequestPermissionsResult(requestCode, grantResult);
|
||||
}
|
||||
}
|
||||
|
||||
public static void reset(Context context, FragmentManager fragmentManager,
|
||||
ApplicationInfo info) {
|
||||
compilePackageInBg(fragmentManager, info,
|
||||
context.getString(R.string.compile_reset_msg));
|
||||
}
|
||||
|
||||
private static void compilePackageInBg(FragmentManager fragmentManager,
|
||||
ApplicationInfo info, String msg) {
|
||||
instance = CompileDialogFragment.newInstance(info, msg, CompileType.RESET);
|
||||
instance.show(fragmentManager, TAG_COMPILE_DIALOG);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -4,8 +4,8 @@
|
|||
android:id="@+id/app_menu_launch"
|
||||
android:title="@string/app_launch" />
|
||||
<item
|
||||
android:id="@+id/app_menu_compile_reset"
|
||||
android:title="@string/menu_title_compile_reset" />
|
||||
android:id="@+id/app_menu_compile_speed"
|
||||
android:title="@string/compile_speed" />
|
||||
<item
|
||||
android:id="@+id/app_menu_store"
|
||||
android:title="@string/modules_app_store" />
|
||||
|
|
|
|||
|
|
@ -82,8 +82,6 @@
|
|||
<string name="not_logcat">此处仅显示 LSPosed 及模块相关日志信息\n如果您想抓取系统日志, 可以尝试我们的 Log Catcher Magisk 模块</string>
|
||||
|
||||
<!-- LSPd related -->
|
||||
<string name="menu_title_compile_reset">取消优化</string>
|
||||
<string name="compile_reset_msg">清除中…</string>
|
||||
<string name="compile_speed_msg">优化中…</string>
|
||||
<string name="done">完成!</string>
|
||||
|
||||
|
|
@ -132,6 +130,7 @@
|
|||
<string name="module_disabled_no_selection">由于未选择任何应用,模块 %s 已被禁用。</string>
|
||||
<string name="android_framework">系统框架</string>
|
||||
<string name="app_destroyed">此应用程序已被损坏,请确保您从官方来源下载该应用程序。</string>
|
||||
<string name="compile_speed">重新优化</string>
|
||||
<string name="selinux_permissive"><b>警告:<\/b>SELinux 未处于严格模式!对此进行攻击的恶意程序可以完全控制你的设备,并可能造成你的财产损失和法律责任。</string>
|
||||
<string name="selinux_permissive_summary">SELinux 未处于严格模式!</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -81,8 +81,6 @@
|
|||
<string name="not_logcat">此處僅顯示 LSPosed 及模塊相關日誌信息\n如果您想抓取系統日誌, 可以嘗試我們的 Log Catcher Magisk 模塊</string>
|
||||
|
||||
<!-- LSPd related -->
|
||||
<string name="menu_title_compile_reset">取消優化</string>
|
||||
<string name="compile_reset_msg">清除中…</string>
|
||||
<string name="compile_speed_msg">優化中…</string>
|
||||
<string name="done">完成!</string>
|
||||
|
||||
|
|
|
|||
|
|
@ -81,8 +81,6 @@
|
|||
<string name="not_logcat">此處僅顯示 LSPosed 及模組相關日誌資訊\n如果您想抓取系統日誌, 可以嘗試我們的 Log Catcher Magisk 模組</string>
|
||||
|
||||
<!-- LSPd related -->
|
||||
<string name="menu_title_compile_reset">取消優化</string>
|
||||
<string name="compile_reset_msg">清除中…</string>
|
||||
<string name="compile_speed_msg">優化中…</string>
|
||||
<string name="done">完成!</string>
|
||||
|
||||
|
|
|
|||
|
|
@ -89,8 +89,6 @@
|
|||
<string name="done">Done!</string>
|
||||
|
||||
<!-- LSPd related -->
|
||||
<string name="menu_title_compile_reset">De-optimize</string>
|
||||
<string name="compile_reset_msg">Resetting …</string>
|
||||
<string name="compile_speed_msg">Optimizing …</string>
|
||||
|
||||
<string name="about_source" translatable="false">https://github.com/LSPosed/LSPosed/</string>
|
||||
|
|
@ -139,6 +137,7 @@
|
|||
<string name="module_disabled_no_selection">Module %s has been disabled since no app selected.</string>
|
||||
<string name="android_framework">System Framework</string>
|
||||
<string name="app_destroyed">This application has been destroyed, please make sure you download it from the official source.</string>
|
||||
<string name="compile_speed">Re-optimize</string>
|
||||
<string name="selinux_permissive"><b>WARNING:<\/b> SELinux is not enforcing! the malicious program that attacks this can completely control your device and may cause your property damage and legal liability.</string>
|
||||
<string name="selinux_permissive_summary">SELinux is not enforcing!</string>
|
||||
</resources>
|
||||
|
|
|
|||
Loading…
Reference in New Issue