Skip to content

Commit

Permalink
opt: SystemUI Plugin loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
lingqiqi5211 committed Dec 10, 2024
1 parent c6b3142 commit 5f4043c
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,13 @@ public static <T> T findMember(@NonNull String key, ClassLoader classLoader, IDe
try {
BaseData baseData = iDexKit.dexkit(dexKitBridge);
if (baseData instanceof FieldData fieldData) {
mMMKV.putString(key, mGson.toJson(new MemberData(TYPE_FIELD, fieldData.toDexField().serialize())));
mMMKV.putString(key, mGson.toJson(new MemberData(TYPE_FIELD, fieldData.toDexField().serialize())) + "\n\n");
return (T) fieldData.getFieldInstance(classLoader);
} else if (baseData instanceof MethodData methodData) {
mMMKV.putString(key, mGson.toJson(new MemberData(TYPE_METHOD, methodData.toDexMethod().serialize())));
mMMKV.putString(key, mGson.toJson(new MemberData(TYPE_METHOD, methodData.toDexMethod().serialize())) + "\n\n");
return (T) methodData.getMethodInstance(classLoader);
} else if (baseData instanceof ClassData classData) {
mMMKV.putString(key, mGson.toJson(new MemberData(TYPE_CLASS, classData.toDexType().serialize())));
mMMKV.putString(key, mGson.toJson(new MemberData(TYPE_CLASS, classData.toDexType().serialize())) + "\n\n");
return (T) classData.getInstance(classLoader);
}
} catch (ReflectiveOperationException e) {
Expand Down Expand Up @@ -170,21 +170,21 @@ public static <T> List<T> findMemberList(@NonNull String key, ClassLoader classL
serializeList.add(f.toDexField().serialize());
instanceList.add((T) f.getFieldInstance(classLoader));
}
mMMKV.putString(key, mGson.toJson(new MemberData(TYPE_FIELD, serializeList)));
mMMKV.putString(key, mGson.toJson(new MemberData(TYPE_FIELD, serializeList)) + "\n\n");
return instanceList;
} else if (baseDataList instanceof MethodDataList methodDataList) {
for (MethodData m : methodDataList) {
serializeList.add(m.toDexMethod().serialize());
instanceList.add((T) m.getMethodInstance(classLoader));
}
mMMKV.putString(key, mGson.toJson(new MemberData(TYPE_METHOD, serializeList)));
mMMKV.putString(key, mGson.toJson(new MemberData(TYPE_METHOD, serializeList)) + "\n\n");
return instanceList;
} else if (baseDataList instanceof ClassDataList classDataList) {
for (ClassData c : classDataList) {
serializeList.add(c.toDexType().serialize());
instanceList.add((T) c.getInstance(classLoader));
}
mMMKV.putString(key, mGson.toJson(new MemberData(TYPE_CLASS, serializeList)));
mMMKV.putString(key, mGson.toJson(new MemberData(TYPE_CLASS, serializeList)) + "\n\n");
return instanceList;
}
} catch (ReflectiveOperationException e) {
Expand Down Expand Up @@ -253,7 +253,7 @@ public static void close() {
}

private static final class MemberData {
public String type = "";
public String type;
public String serialize = "";

public ArrayList<String> serializeList = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,9 @@ object NewPluginHelperKt : BaseHook() {
}

private fun onPluginLoaded(factory: PluginFactory) {
val mCardStyleTiles = getTileList()
val mIsDefaultMode = mPrefsMap.getStringAsInt("system_ui_plugin_tiles_load_way", 0) == 0 || mPrefsMap.getStringAsInt("system_ui_plugin_tiles_load_way", 0) == 1
val mIsCompatibilityMode = mPrefsMap.getStringAsInt("system_ui_plugin_tiles_load_way", 0) == 0 || mPrefsMap.getStringAsInt("system_ui_plugin_tiles_load_way", 0) == 2
try {
onPluginLoadedAll(factory)

when (factory.mComponentName) {
factory.componentNames("miui.systemui.volume.VolumeDialogPlugin") -> {
val classLoader: ClassLoader = factory.pluginCtxRef.get()!!.classLoader
Expand All @@ -66,8 +65,6 @@ object NewPluginHelperKt : BaseHook() {
if (mPrefsMap.getBoolean("system_framework_volume_separate_control") &&
mPrefsMap.getBoolean("system_framework_volume_separate_slider"))
NotificationVolumeSeparateSlider.initHideDeviceControlEntry(classLoader)
if (mPrefsMap.getBoolean("system_ui_other_default_plugin_theme"))
DefaultPluginTheme.initDefaultPluginTheme(classLoader)
}

factory.componentNames("miui.systemui.miplay.MiPlayPluginImpl") -> {
Expand All @@ -78,48 +75,12 @@ object NewPluginHelperKt : BaseHook() {
HideMiPlayEntry.initHideMiPlayEntry(classLoader)
}

factory.componentNames("miui.systemui.quicksettings.LocalMiuiQSTilePlugin") -> {
val classLoader: ClassLoader = factory.pluginCtxRef.get()!!.classLoader
logD(TAG, lpparam.packageName, "Plugin for sysui qs tiles loaded.")

if (mPrefsMap.getBoolean("systemui_plugin_card_tiles_enabled") &&
mPrefsMap.getString("systemui_plugin_card_tiles", "").isNotEmpty() &&
mIsCompatibilityMode
) {
CustomCardTiles.initCustomCardTiles(classLoader, mCardStyleTiles)
}
if (mPrefsMap.getBoolean("system_ui_control_center_rounded_rect") && mIsDefaultMode)
CCGridForHyperOS.initCCGridForHyperOS(classLoader) // 控制中心磁贴圆角 //A
if (mPrefsMap.getBoolean("system_ui_control_center_qs_open_color") ||
mPrefsMap.getBoolean("system_ui_control_center_qs_big_open_color")
) {
QSColor.pluginHook(classLoader)
}
if (mPrefsMap.getBoolean("system_ui_other_default_plugin_theme"))
DefaultPluginTheme.initDefaultPluginTheme(classLoader)
}

factory.componentNames("miui.systemui.controlcenter.MiuiControlCenter") -> {
val classLoader: ClassLoader = factory.pluginCtxRef.get()!!.classLoader
logD(TAG, lpparam.packageName, "Plugin for sysui control center loaded.")

if (mPrefsMap.getBoolean("systemui_plugin_card_tiles_enabled") &&
mPrefsMap.getString("systemui_plugin_card_tiles", "").isNotEmpty() &&
mIsDefaultMode
) {
CustomCardTiles.initCustomCardTiles(classLoader, mCardStyleTiles) //A
}
if (mPrefsMap.getBoolean("system_ui_control_center_hide_edit_botton"))
HideEditButton.initHideEditButton(classLoader)
if (mPrefsMap.getBoolean("system_ui_control_center_rounded_rect") && mIsCompatibilityMode)
CCGridForHyperOS.initCCGridForHyperOS(classLoader) // 控制中心磁贴圆角
if (mPrefsMap.getBoolean("system_ui_control_center_qs_open_color") ||
mPrefsMap.getBoolean("system_ui_control_center_qs_big_open_color")
) {
QSColor.pluginHook(classLoader)
}
if (mPrefsMap.getBoolean("system_ui_other_default_plugin_theme"))
DefaultPluginTheme.initDefaultPluginTheme(classLoader)
}

factory.componentNames("miui.systemui.notification.NotificationStatPluginImpl") -> {
Expand All @@ -128,8 +89,6 @@ object NewPluginHelperKt : BaseHook() {

if (mPrefsMap.getBoolean("system_ui_statusbar_music_switch"))
FocusNotifLyric.initLoader(classLoader);
if (mPrefsMap.getBoolean("system_ui_other_default_plugin_theme"))
DefaultPluginTheme.initDefaultPluginTheme(classLoader)
}

else -> {
Expand Down Expand Up @@ -161,6 +120,27 @@ object NewPluginHelperKt : BaseHook() {
} catch (_: Exception) {}
}

private fun onPluginLoadedAll(factory: PluginFactory) {
// 本列表将一次性加载所有插件,适用于需要载入多个 factory.mComponentName 的情况
val classLoader: ClassLoader = factory.pluginCtxRef.get()!!.classLoader
val mCardStyleTiles = getTileList()

if (mPrefsMap.getBoolean("systemui_plugin_card_tiles_enabled") &&
mPrefsMap.getString("systemui_plugin_card_tiles", "").isNotEmpty()) {
CustomCardTiles.initCustomCardTiles(classLoader, mCardStyleTiles) //A
}
if (mPrefsMap.getBoolean("system_ui_control_center_rounded_rect"))
CCGridForHyperOS.initCCGridForHyperOS(classLoader) // 控制中心磁贴圆角
if (mPrefsMap.getBoolean("system_ui_control_center_qs_open_color") ||
mPrefsMap.getBoolean("system_ui_control_center_qs_big_open_color")
) {
QSColor.pluginHook(classLoader)
}

if (mPrefsMap.getBoolean("system_ui_other_default_plugin_theme"))
DefaultPluginTheme.initDefaultPluginTheme(classLoader)
}

private fun getTileList(): List<String> {
val cardTiles =
mPrefsMap.getString("systemui_plugin_card_tiles", "").replace("List_", "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public class ControlCenterSettings extends DashboardFragment implements Preferen
ColorPickerPreference mProgressBarColor;
SwitchPreference mRedirectNotice;
SwitchPreference mShadeHeaderBlur;
DropDownPreference mPluginLoadMode;
DropDownPreference mSunshineMode;
DropDownPreference mSunshineModeHigh;
SeekBarPreferenceCompat mSunshineModeHighBrightness;
Expand Down Expand Up @@ -122,7 +121,6 @@ public void initPrefs() {
mProgressBarColor = findPreference("prefs_key_system_ui_control_center_media_control_seekbar_color");
mRedirectNotice = findPreference("prefs_key_system_ui_control_center_redirect_notice");
mShadeHeaderBlur = findPreference("prefs_key_system_ui_shade_header_gradient_blur");
mPluginLoadMode = findPreference("prefs_key_system_ui_plugin_tiles_load_way");
mSunshineMode = findPreference("prefs_key_system_control_center_sunshine_new_mode");
mSunshineModeHigh = findPreference("prefs_key_system_control_center_sunshine_new_mode_high");
mSunshineModeHighBrightness = findPreference("prefs_key_system_control_center_sunshine_mode_brightness");
Expand Down Expand Up @@ -160,7 +158,6 @@ public void initPrefs() {
mSunshineModeHighBrightness.setVisible(false);
}

mPluginLoadMode.setVisible(isMoreHyperOSVersion(2f));
if (isMoreHyperOSVersion(1f)) {
mNewCCGrid.setVisible(false);
mCard.setVisible(false);
Expand Down
6 changes: 0 additions & 6 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1078,12 +1078,6 @@
<string name="system_ui_other_default_plugin_theme_desc">解除系统界面组件对第三方主题默认禁用的高级材质模糊</string>
<string name="system_ui_plugin_enable_volume_blur">音量条模糊</string>
<string name="system_ui_plugin_enable_volume_blur_desc">仅供 Android 12 及以上的 MTK 机型使用,可能存在 GPU 负载较高的情况</string>

<string name="system_ui_plugin_tiles_load_way">磁贴 hook 加载方式</string>
<string name="system_ui_plugin_tiles_load_way_desc">全局加载可能会导致不必要的卡顿;请根据实际可用性选择加载方式</string>
<string name="system_ui_plugin_tiles_load_way_global">全局</string>
<string name="system_ui_plugin_tiles_load_way_default">默认</string>
<string name="system_ui_plugin_tiles_load_way_compatibility">兼容</string>
<!--设置-->
<string name="system_settings">设置</string>
<string name="system_settings_international_build">国际版本设置页面</string>
Expand Down
12 changes: 0 additions & 12 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1127,18 +1127,6 @@
<item>@color/update_text_border1</item>
</array>

<string-array name="system_ui_plugin_tiles_load_way_arr">
<item>@string/system_ui_plugin_tiles_load_way_global</item>
<item>@string/system_ui_plugin_tiles_load_way_default</item>
<item>@string/system_ui_plugin_tiles_load_way_compatibility</item>
</string-array>

<string-array name="system_ui_plugin_tiles_load_way_arr_value">
<item>0</item>
<item>1</item>
<item>2</item>
</string-array>

<string-array name="actions">
<item>@string/array_global_actions_none</item>
<item>@string/array_global_actions_lock</item>
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1016,11 +1016,6 @@
<string name="system_ui_control_center_unlock_blur_supported_desc">There is no restriction on background blur for Advanced textures, only for third-party theme removal.</string>
<string name="system_ui_control_center_remove_notif_num_limit">Remove notification count limit</string>
<string name="system_ui_control_center_remove_notif_num_limit_desc">Allow display 10, 17 or more notifications.</string>
<string name="system_ui_plugin_tiles_load_way">Tiles hook loading mode</string>
<string name="system_ui_plugin_tiles_load_way_desc">Global mode may cause unnecessary lag. Please choose the loading mode based on actual availability.</string>
<string name="system_ui_plugin_tiles_load_way_global">Global</string>
<string name="system_ui_plugin_tiles_load_way_default">Default</string>
<string name="system_ui_plugin_tiles_load_way_compatibility">Compatibility</string>

<string name="system_ui_other_title">Others</string>
<string name="system_ui_disable_volume">Native volume bar</string>
Expand Down
13 changes: 0 additions & 13 deletions app/src/main/res/xml/system_ui_control_center.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
app:myLocation="@string/system_ui_controlcenter_title"
app:quick_restart="com.android.systemui">

<PreferenceCategory>
<fan.preference.DropDownPreference
android:defaultValue="0"
android:key="prefs_key_system_ui_plugin_tiles_load_way"
android:summary="@string/system_ui_plugin_tiles_load_way_desc"
android:title="@string/system_ui_plugin_tiles_load_way"
app:entries="@array/system_ui_plugin_tiles_load_way_arr"
app:entryValues="@array/system_ui_plugin_tiles_load_way_arr_value" />

</PreferenceCategory>

<PreferenceCategory>

<SwitchPreference
android:defaultValue="false"
android:key="prefs_key_system_ui_shade_header_gradient_blur"
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
agp = "8.7.2"
agp = "8.7.3"
kotlin-android = "2.1.0"
lsparanoid = "0.6.0"
autoService = "1.1.1"
Expand Down

0 comments on commit 5f4043c

Please sign in to comment.