diff --git a/app/src/main/java/Com/HChen/Hook/Base/AlertDialogFactory.java b/app/src/main/java/Com/HChen/Hook/Base/AlertDialogFactory.java new file mode 100644 index 0000000..3c29467 --- /dev/null +++ b/app/src/main/java/Com/HChen/Hook/Base/AlertDialogFactory.java @@ -0,0 +1,47 @@ +package Com.HChen.Hook.Base; + +import android.content.Context; + +import moralnorm.appcompat.app.AlertDialog; + +public class AlertDialogFactory { + + public void makeAlertDialog(Context context, String mTitle, String mMessage, Runnable mCode, Runnable mCodeT) { + new AlertDialog.Builder(context) + .setCancelable(true) + .setTitle(mTitle) + .setMessage(mMessage) + .setHapticFeedbackEnabled(true) + .setPositiveButton(android.R.string.ok, (dialog, which) -> { + if (mCode != null) mCode.run(); + }) + .setNegativeButton(android.R.string.cancel, (dialog, which) -> { + if (mCodeT != null) mCodeT.run(); + }) + .show(); + } + + public void makeAlertDialog(Context context, String mTitle, String mMessage, Runnable mCode) { + new AlertDialog.Builder(context) + .setCancelable(true) + .setTitle(mTitle) + .setMessage(mMessage) + .setHapticFeedbackEnabled(true) + .setPositiveButton(android.R.string.ok, (dialog, which) -> { + if (mCode != null) mCode.run(); + }) + .show(); + } + + public void makeAlertDialog(Context context, String mTitle, String mMessage, Runnable mCodeT, boolean needT) { + new AlertDialog.Builder(context) + .setCancelable(true) + .setTitle(mTitle) + .setMessage(mMessage) + .setHapticFeedbackEnabled(true) + .setNegativeButton(android.R.string.cancel, (dialog, which) -> { + if (mCodeT != null) mCodeT.run(); + }) + .show(); + } +} diff --git a/app/src/main/java/Com/HChen/Hook/Base/BaseGetKey.java b/app/src/main/java/Com/HChen/Hook/Base/BaseGetKey.java index 61a4b3f..bb74006 100644 --- a/app/src/main/java/Com/HChen/Hook/Base/BaseGetKey.java +++ b/app/src/main/java/Com/HChen/Hook/Base/BaseGetKey.java @@ -6,8 +6,8 @@ import java.util.Map; import Com.HChen.Hook.BuildConfig; -import Com.HChen.Hook.SystemLog; import Com.HChen.Hook.Utils.GetKey; +import Com.HChen.Hook.Utils.SystemLog; import de.robv.android.xposed.XSharedPreferences; public class BaseGetKey extends SystemLog { diff --git a/app/src/main/java/Com/HChen/Hook/Base/BasePreferenceFragment.java b/app/src/main/java/Com/HChen/Hook/Base/BasePreferenceFragment.java index 9ab26df..ccab8a7 100644 --- a/app/src/main/java/Com/HChen/Hook/Base/BasePreferenceFragment.java +++ b/app/src/main/java/Com/HChen/Hook/Base/BasePreferenceFragment.java @@ -9,7 +9,7 @@ import java.util.Objects; -import Com.HChen.Hook.SystemLog; +import Com.HChen.Hook.Utils.SystemLog; import moralnorm.preference.Preference; import moralnorm.preference.PreferenceManager; import moralnorm.preference.compat.PreferenceFragment; @@ -28,7 +28,7 @@ public void onCreatePreferences(Bundle bundle, String s) { PreferenceManager mPreferenceManager = getPreferenceManager(); mPreferenceManager.setSharedPreferencesName(mPrefsName); mPreferenceManager.setSharedPreferencesMode(Context.MODE_WORLD_READABLE); - mPreferenceManager.setStorageDeviceProtected(); + mPreferenceManager.setStorageDefault(); systemLog.logI(TAG, "onCreatePreferences: " + mPreferenceManager); } diff --git a/app/src/main/java/Com/HChen/Hook/Base/BaseSettingsActivity.java b/app/src/main/java/Com/HChen/Hook/Base/BaseSettingsActivity.java index 74e0ce7..76452ad 100644 --- a/app/src/main/java/Com/HChen/Hook/Base/BaseSettingsActivity.java +++ b/app/src/main/java/Com/HChen/Hook/Base/BaseSettingsActivity.java @@ -15,15 +15,16 @@ import java.util.Objects; import Com.HChen.Hook.R; -import Com.HChen.Hook.SystemLog; import Com.HChen.Hook.Utils.ShellUtils; -import moralnorm.appcompat.app.AlertDialog; +import Com.HChen.Hook.Utils.SystemLog; import moralnorm.appcompat.app.AppCompatActivity; public class BaseSettingsActivity extends AppCompatActivity { + private String initialFragmentName; AppCompatActivity context; SystemLog systemLog = new SystemLog(); + AlertDialogFactory alertDialogFactory = new AlertDialogFactory(); public final String TAG = "BaseSettingsActivity"; // public static List mActivityList = new ArrayList<>(); @@ -113,15 +114,11 @@ public void showRestartDialog(String appLabel, String packagename) { } public void showRestartDialog(boolean isRestartSystem, String appLabel, String packagename) { - new AlertDialog.Builder(this) - .setCancelable(true) - .setTitle(getResources().getString(R.string.soft_reboot) + " " + appLabel) - .setMessage(getResources().getString(R.string.restart_app_desc1 - ) + appLabel + getResources().getString(R.string.restart_app_desc2)) - .setHapticFeedbackEnabled(true) - .setPositiveButton(android.R.string.ok, (dialog, which) -> doRestart(packagename, isRestartSystem)) - .setNegativeButton(android.R.string.cancel, (dialog, which) -> Toast.makeText(this, getResources().getString(R.string.cancel), Toast.LENGTH_SHORT).show()) - .show(); + alertDialogFactory.makeAlertDialog(this, + getResources().getString(R.string.soft_reboot) + " " + appLabel, + getResources().getString(R.string.restart_app_desc1) + appLabel + getResources().getString(R.string.restart_app_desc2), + () -> doRestart(packagename, isRestartSystem), + () -> Toast.makeText(this, getResources().getString(R.string.cancel), Toast.LENGTH_SHORT).show()); } public void doRestart(String packagename, boolean isRestartSystem) { @@ -133,13 +130,8 @@ public void doRestart(String packagename, boolean isRestartSystem) { result = ShellUtils.RootCommand("killall " + packagename); } if (!result) { - new AlertDialog.Builder(this) - .setCancelable(false) - .setTitle(getResources().getString(R.string.tip)) - .setMessage(isRestartSystem ? getResources().getString(R.string.reboot_failed) : getResources().getString(R.string.kill_failed)) - .setHapticFeedbackEnabled(true) - .setPositiveButton(android.R.string.ok, null) - .show(); + alertDialogFactory.makeAlertDialog(this, getResources().getString(R.string.tip), + isRestartSystem ? getResources().getString(R.string.reboot_failed) : getResources().getString(R.string.kill_failed), null); } else { Toast.makeText(this, getResources().getString(R.string.sucess) + packagename, Toast.LENGTH_SHORT).show(); } diff --git a/app/src/main/java/Com/HChen/Hook/Base/SettingLauncher.java b/app/src/main/java/Com/HChen/Hook/Base/SettingLauncher.java index e439a4a..cf84496 100644 --- a/app/src/main/java/Com/HChen/Hook/Base/SettingLauncher.java +++ b/app/src/main/java/Com/HChen/Hook/Base/SettingLauncher.java @@ -7,7 +7,7 @@ import androidx.fragment.app.Fragment; -import Com.HChen.Hook.SystemLog; +import Com.HChen.Hook.Utils.SystemLog; public class SettingLauncher extends SystemLog { public final String TAG = "SettingLauncher"; diff --git a/app/src/main/java/Com/HChen/Hook/Base/SettingsActivity.java b/app/src/main/java/Com/HChen/Hook/Base/SettingsActivity.java index c37ab3b..e5ddb83 100644 --- a/app/src/main/java/Com/HChen/Hook/Base/SettingsActivity.java +++ b/app/src/main/java/Com/HChen/Hook/Base/SettingsActivity.java @@ -33,13 +33,15 @@ public void onStartSettingsForArguments(Class cls, Preference preference, boo } String mFragmentName = preference.getFragment(); String mTitle = Objects.requireNonNull(preference.getTitle()).toString(); - onStartSettingsForArguments(context, cls, mFragmentName, args, 0, mTitle); + if (args == null) args = new Bundle(); +// onStartSettingsForArguments(context, cls, mFragmentName, args, 0, mTitle); + onStartSettings(context, cls, mFragmentName, null, args, 0, mTitle); } - public static void onStartSettingsForArguments(Context context, Class cls, String fragment, Bundle args, int titleResId, String title) { + /*public static void onStartSettingsForArguments(Context context, Class cls, String fragment, Bundle args, int titleResId, String title) { if (args == null) args = new Bundle(); onStartSettings(context, cls, fragment, null, args, titleResId, title); - } + }*/ public static void onStartSettings(Context context, Class cls, String fragment, Bundle extras, Bundle args, int titleResId, String title) { new SettingLauncher(context) diff --git a/app/src/main/java/Com/HChen/Hook/Base/SettingsPreferenceFragment.java b/app/src/main/java/Com/HChen/Hook/Base/SettingsPreferenceFragment.java index b13f45a..85ec4ff 100644 --- a/app/src/main/java/Com/HChen/Hook/Base/SettingsPreferenceFragment.java +++ b/app/src/main/java/Com/HChen/Hook/Base/SettingsPreferenceFragment.java @@ -4,7 +4,7 @@ import android.text.TextUtils; import android.view.View; -import Com.HChen.Hook.SystemLog; +import Com.HChen.Hook.Utils.SystemLog; public abstract class SettingsPreferenceFragment extends BasePreferenceFragment { public final String TAG = "SettingsPreferenceFragment"; diff --git a/app/src/main/java/Com/HChen/Hook/Mode/HookMode.java b/app/src/main/java/Com/HChen/Hook/Mode/HookMode.java index acf64f5..af03e9e 100644 --- a/app/src/main/java/Com/HChen/Hook/Mode/HookMode.java +++ b/app/src/main/java/Com/HChen/Hook/Mode/HookMode.java @@ -10,7 +10,7 @@ import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam; public abstract class HookMode extends HookLog { - GetKey mPrefsMap = BaseGetKey.mPrefsMap; + public final GetKey mPrefsMap = BaseGetKey.mPrefsMap; LoadPackageParam loadPackageParam; public abstract void init(); @@ -215,7 +215,6 @@ public void getDeclaredField(XC_MethodHook.MethodHookParam param, String iNeedSt setString.set(param.thisObject, iNeedTo); Object result = setString.get(param.thisObject); checkLast("getDeclaredField", iNeedString, iNeedTo, result); - } catch (IllegalAccessException e) { logE("IllegalAccessException to: " + iNeedString + " Need to: " + iNeedTo + " Code:" + e); } diff --git a/app/src/main/java/Com/HChen/Hook/Mode/HookRun.java b/app/src/main/java/Com/HChen/Hook/Mode/HookRun.java index a15a31c..78208c5 100644 --- a/app/src/main/java/Com/HChen/Hook/Mode/HookRun.java +++ b/app/src/main/java/Com/HChen/Hook/Mode/HookRun.java @@ -10,6 +10,7 @@ import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam; public class HookRun extends HookLog { + public final String TAG = "HookRun"; LoadPackageParam loadPackageParam; public final GetKey mPrefsMap = BaseGetKey.mPrefsMap; diff --git a/app/src/main/java/Com/HChen/Hook/SystemLog.java b/app/src/main/java/Com/HChen/Hook/Utils/SystemLog.java similarity index 95% rename from app/src/main/java/Com/HChen/Hook/SystemLog.java rename to app/src/main/java/Com/HChen/Hook/Utils/SystemLog.java index ba943aa..5511532 100644 --- a/app/src/main/java/Com/HChen/Hook/SystemLog.java +++ b/app/src/main/java/Com/HChen/Hook/Utils/SystemLog.java @@ -1,4 +1,4 @@ -package Com.HChen.Hook; +package Com.HChen.Hook.Utils; import android.util.Log;