From 2607937a41095bcd5cda5b367cb3ec4da3d87663 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=BB=80=E6=BC=93=E4=B8=A8Sevtinge?=
<89193494+Sevtinge@users.noreply.github.com>
Date: Sun, 25 Aug 2024 02:28:47 +0800
Subject: [PATCH] feat: analytics - remove guard
from gykkuo/MIUI_NoGuard
#818
---
.../hyperceiler/module/app/Analytics.java | 32 +++++
.../module/hook/analytics/FuckMiuiUpload.java | 110 ++++++++++++++++++
.../ui/fragment/AnalyticsFragment.java | 41 +++++++
.../utils/search/SearchHelper.java | 3 +
app/src/main/res/values-zh-rCN/strings.xml | 3 +
app/src/main/res/values/arrays.xml | 1 +
app/src/main/res/values/strings.xml | 3 +
app/src/main/res/xml/analytics.xml | 30 +++++
app/src/main/res/xml/prefs_about_use.xml | 7 ++
app/src/main/res/xml/prefs_main.xml | 7 ++
.../res/xml/prefs_set_homepage_entrance.xml | 8 ++
11 files changed, 245 insertions(+)
create mode 100644 app/src/main/java/com/sevtinge/hyperceiler/module/app/Analytics.java
create mode 100644 app/src/main/java/com/sevtinge/hyperceiler/module/hook/analytics/FuckMiuiUpload.java
create mode 100644 app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/AnalyticsFragment.java
create mode 100644 app/src/main/res/xml/analytics.xml
diff --git a/app/src/main/java/com/sevtinge/hyperceiler/module/app/Analytics.java b/app/src/main/java/com/sevtinge/hyperceiler/module/app/Analytics.java
new file mode 100644
index 0000000000..7d03c47d31
--- /dev/null
+++ b/app/src/main/java/com/sevtinge/hyperceiler/module/app/Analytics.java
@@ -0,0 +1,32 @@
+/*
+ * This file is part of HyperCeiler.
+ *
+ * HyperCeiler is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ *
+ * Copyright (C) 2023-2024 HyperCeiler Contributions
+ */
+
+package com.sevtinge.hyperceiler.module.app;
+
+import com.sevtinge.hyperceiler.module.base.BaseModule;
+import com.sevtinge.hyperceiler.module.base.HookExpand;
+import com.sevtinge.hyperceiler.module.hook.analytics.FuckMiuiUpload;
+
+@HookExpand(pkg = "com.miui.analytics", isPad = false, tarAndroid = 33)
+public class Analytics extends BaseModule {
+ @Override
+ public void handleLoadPackage() {
+ initHook(new FuckMiuiUpload(), mPrefsMap.getBoolean("analytics_fuck_guard"));
+ }
+}
diff --git a/app/src/main/java/com/sevtinge/hyperceiler/module/hook/analytics/FuckMiuiUpload.java b/app/src/main/java/com/sevtinge/hyperceiler/module/hook/analytics/FuckMiuiUpload.java
new file mode 100644
index 0000000000..b796038ecd
--- /dev/null
+++ b/app/src/main/java/com/sevtinge/hyperceiler/module/hook/analytics/FuckMiuiUpload.java
@@ -0,0 +1,110 @@
+/*
+ * This file is part of HyperCeiler.
+ *
+ * HyperCeiler is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ *
+ * Copyright (C) 2023-2024 HyperCeiler Contributions
+ */
+
+package com.sevtinge.hyperceiler.module.hook.analytics;
+
+import android.content.Context;
+
+import com.sevtinge.hyperceiler.module.base.BaseHook;
+
+import de.robv.android.xposed.XC_MethodHook;
+import de.robv.android.xposed.XposedHelpers;
+
+// from https://github.com/gykkuo/MIUI_NoGuard/blob/master/app/src/main/java/cn/fyyr/noguardpls/MainHook.java
+public class FuckMiuiUpload extends BaseHook {
+ @Override
+ public void init() throws NoSuchMethodException {
+ int needmod = 0;
+ Class> classs = null;
+ // com.miui.analytics.onetrack.p.u.w
+ try {
+ classs = XposedHelpers.findClass("com.miui.analytics.onetrack.p.u", lpparam.classLoader);
+ XposedHelpers.findAndHookMethod(classs, "w", long.class, long.class, new XC_MethodHook() {
+ @Override
+ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
+ // XposedBridge.log("com.miui.analytics:执行拦截! --- 1");
+ param.setResult(null);
+ }
+ });
+
+ needmod++;
+ } catch (XposedHelpers.ClassNotFoundError | NoSuchMethodError err) {
+ logD(TAG, lpparam.packageName, err.toString());
+ }
+ // com.miui.analytics.c.f.k.y
+ try {
+ classs = XposedHelpers.findClass("com.miui.analytics.c.f.k", lpparam.classLoader);
+ XposedHelpers.findAndHookMethod(classs, "y", long.class, long.class, new XC_MethodHook() {
+ @Override
+ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
+ // XposedBridge.log("com.miui.analytics:执行拦截! --- 2");
+ param.setResult(null);
+ }
+ });
+ needmod++;
+ } catch (XposedHelpers.ClassNotFoundError | NoSuchMethodError err) {
+ logD(TAG, lpparam.packageName, err.toString());
+ }
+ try {
+ classs = XposedHelpers.findClass("com.miui.analytics.onetrack.q.c", lpparam.classLoader);
+ // com.miui.analytics.onetrack.q.c.a
+ try {
+ XposedHelpers.findAndHookMethod(classs, "a", Context.class, new XC_MethodHook() {
+ @Override
+ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
+ // XposedBridge.log("com.miui.analytics:执行拦截! --- 3");
+ param.setResult(0);
+ }
+ });
+ needmod++;
+ } catch (XposedHelpers.ClassNotFoundError | NoSuchMethodError err) {
+ logD(TAG, lpparam.packageName, err.toString());
+ }
+ // com.miui.analytics.onetrack.q.c.b
+ try {
+ XposedHelpers.findAndHookMethod(classs, "b", Context.class, new XC_MethodHook() {
+ @Override
+ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
+ // XposedBridge.log("com.miui.analytics:执行拦截! --- 4");
+ param.setResult("NONE");
+ }
+ });
+ needmod++;
+ } catch (XposedHelpers.ClassNotFoundError | NoSuchMethodError err) {
+ logD(TAG, lpparam.packageName, err.toString());
+ }
+ // com.miui.analytics.onetrack.q.c.c
+ try {
+ XposedHelpers.findAndHookMethod(classs, "c", new XC_MethodHook() {
+ @Override
+ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
+ // XposedBridge.log("com.miui.analytics:执行拦截! --- 5");
+ param.setResult(false);
+ }
+ });
+ needmod++;
+ } catch (XposedHelpers.ClassNotFoundError | NoSuchMethodError err) {
+ logD(TAG, lpparam.packageName, err.toString());
+ }
+ } catch (XposedHelpers.ClassNotFoundError | NoSuchMethodError err) {
+ logD(TAG, lpparam.packageName, err.toString());
+ }
+ }
+}
+
diff --git a/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/AnalyticsFragment.java b/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/AnalyticsFragment.java
new file mode 100644
index 0000000000..d32ac02160
--- /dev/null
+++ b/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/AnalyticsFragment.java
@@ -0,0 +1,41 @@
+/*
+ * This file is part of HyperCeiler.
+ *
+ * HyperCeiler is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ *
+ * Copyright (C) 2023-2024 HyperCeiler Contributions
+ */
+
+package com.sevtinge.hyperceiler.ui.fragment;
+
+import android.view.View;
+
+import com.sevtinge.hyperceiler.R;
+import com.sevtinge.hyperceiler.ui.base.BaseSettingsActivity;
+import com.sevtinge.hyperceiler.ui.fragment.base.SettingsPreferenceFragment;
+
+public class AnalyticsFragment extends SettingsPreferenceFragment {
+ @Override
+ public int getContentResId() {
+ return R.xml.analytics;
+ }
+
+ @Override
+ public View.OnClickListener addRestartListener() {
+ return view -> ((BaseSettingsActivity)getActivity()).showRestartDialog(
+ getResources().getString(R.string.analytics),
+ "com.miui.analytics"
+ );
+ }
+}
diff --git a/app/src/main/java/com/sevtinge/hyperceiler/utils/search/SearchHelper.java b/app/src/main/java/com/sevtinge/hyperceiler/utils/search/SearchHelper.java
index c53c63eae4..816f4d5c05 100644
--- a/app/src/main/java/com/sevtinge/hyperceiler/utils/search/SearchHelper.java
+++ b/app/src/main/java/com/sevtinge/hyperceiler/utils/search/SearchHelper.java
@@ -243,6 +243,9 @@ public static void getAllMods(Context context, boolean force) {
"com.sevtinge.hyperceiler.ui.fragment.SystemSettingsFragment");
// 其他杂项
+ parsePrefXml(context, R.xml.analytics,
+ "com.sevtinge.hyperceiler.ui.fragment.AnalyticsFragment");
+
parsePrefXml(context, R.xml.browser,
"com.sevtinge.hyperceiler.ui.fragment.BrowserFragment");
diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml
index 5457a417b5..94866944da 100644
--- a/app/src/main/res/values-zh-rCN/strings.xml
+++ b/app/src/main/res/values-zh-rCN/strings.xml
@@ -1606,6 +1606,9 @@
卡片显示样式
浅色模式
深色模式
+
+ Analytics
+ 禁止收集遥测数据
小爱翻译
强制启用实时字幕
diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml
index fd591e3807..b2ce9cf40b 100644
--- a/app/src/main/res/values/arrays.xml
+++ b/app/src/main/res/values/arrays.xml
@@ -40,6 +40,7 @@
- com.duokan.phone.remotecontroller
- com.lbe.security.miui
- com.milink.service
+ - com.miui.analytics
- com.miui.aod
- com.miui.backup
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 1a7ab74fdd..0d950dd877 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1574,6 +1574,9 @@
Card display type
Light mode
Dark mode
+
+ Analytics
+ Remove guard
Mi AI Translate
Force enabled AI captions
diff --git a/app/src/main/res/xml/analytics.xml b/app/src/main/res/xml/analytics.xml
new file mode 100644
index 0000000000..786aac4339
--- /dev/null
+++ b/app/src/main/res/xml/analytics.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/xml/prefs_about_use.xml b/app/src/main/res/xml/prefs_about_use.xml
index 0a9750e756..7d22981667 100644
--- a/app/src/main/res/xml/prefs_about_use.xml
+++ b/app/src/main/res/xml/prefs_about_use.xml
@@ -229,6 +229,13 @@
android:action="android.intent.action.VIEW"
android:data="https://github.com/RC1844/MIUI_IME_Unlock" />
+
+
+
diff --git a/app/src/main/res/xml/prefs_main.xml b/app/src/main/res/xml/prefs_main.xml
index bfc1cc52fc..8722f97abd 100644
--- a/app/src/main/res/xml/prefs_main.xml
+++ b/app/src/main/res/xml/prefs_main.xml
@@ -180,6 +180,13 @@
android:summary="com.milink.service"
android:title="@string/milink" />
+
+
+
+