Skip to content

Commit

Permalink
opt: move some func
Browse files Browse the repository at this point in the history
  • Loading branch information
lingqiqi5211 committed Dec 28, 2024
1 parent 065f497 commit 1dd31af
Show file tree
Hide file tree
Showing 27 changed files with 384 additions and 373 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,6 @@ public void handleLoadPackage() {
initHook(new SwitchCCAndNotification(), mPrefsMap.getBoolean("system_ui_control_center_switch_cc_and_notification"));
initHook(QSControlDetailBackgroundAlpha.INSTANCE, mPrefsMap.getInt("system_ui_control_center_control_detail_background_alpha", 255) != 255);
initHook(NotificationWeather.INSTANCE, mPrefsMap.getBoolean("system_ui_control_center_show_weather"));
initHook(NotificationWeatherOld.INSTANCE, mPrefsMap.getBoolean("system_ui_control_center_show_weather"));
initHook(NotificationWeatherNew.INSTANCE, mPrefsMap.getBoolean("system_ui_control_center_show_weather"));
initHook(CompactNotificationsHook.INSTANCE, mPrefsMap.getBoolean("system_ui_control_center_compact_notice"));
/*initHook(CCGridOld.INSTANCE, mPrefsMap.getInt("system_control_center_cc_rows", 4) > 4 ||
mPrefsMap.getInt("system_control_center_cc_columns", 4) > 4 ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,6 @@ public void handleLoadPackage() {
initHook(new SwitchCCAndNotification(), mPrefsMap.getBoolean("system_ui_control_center_switch_cc_and_notification"));
initHook(QSControlDetailBackgroundAlpha.INSTANCE, mPrefsMap.getInt("system_ui_control_center_control_detail_background_alpha", 255) != 255);
initHook(NotificationWeather.INSTANCE, mPrefsMap.getBoolean("system_ui_control_center_show_weather"));
initHook(NotificationWeatherOld.INSTANCE, mPrefsMap.getBoolean("system_ui_control_center_show_weather"));
initHook(NotificationWeatherNew.INSTANCE, mPrefsMap.getBoolean("system_ui_control_center_show_weather"));
initHook(CompactNotificationsHook.INSTANCE, mPrefsMap.getBoolean("system_ui_control_center_compact_notice"));
/*initHook(CCGridOld.INSTANCE, mPrefsMap.getInt("system_control_center_cc_rows", 4) > 4 ||
mPrefsMap.getInt("system_control_center_cc_columns", 4) > 4 ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,6 @@ public void handleLoadPackage() {
initHook(new SwitchCCAndNotification(), mPrefsMap.getBoolean("system_ui_control_center_switch_cc_and_notification"));
initHook(QSControlDetailBackgroundAlpha.INSTANCE, mPrefsMap.getInt("system_ui_control_center_control_detail_background_alpha", 255) != 255);
initHook(NotificationWeather.INSTANCE, mPrefsMap.getBoolean("system_ui_control_center_show_weather"));
initHook(NotificationWeatherOld.INSTANCE, mPrefsMap.getBoolean("system_ui_control_center_show_weather"));
initHook(NotificationWeatherNew.INSTANCE, mPrefsMap.getBoolean("system_ui_control_center_show_weather"));
initHook(CompactNotificationsHook.INSTANCE, mPrefsMap.getBoolean("system_ui_control_center_compact_notice"));
/*initHook(CCGridOld.INSTANCE, mPrefsMap.getInt("system_control_center_cc_rows", 4) > 4 ||
mPrefsMap.getInt("system_control_center_cc_columns", 4) > 4 ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,6 @@ public void handleLoadPackage() {
initHook(new SwitchCCAndNotification(), mPrefsMap.getBoolean("system_ui_control_center_switch_cc_and_notification"));
initHook(QSControlDetailBackgroundAlpha.INSTANCE, mPrefsMap.getInt("system_ui_control_center_control_detail_background_alpha", 255) != 255);
initHook(NotificationWeather.INSTANCE, mPrefsMap.getBoolean("system_ui_control_center_show_weather"));
initHook(NotificationWeatherOld.INSTANCE, mPrefsMap.getBoolean("system_ui_control_center_show_weather"));
initHook(NotificationWeatherNew.INSTANCE, mPrefsMap.getBoolean("system_ui_control_center_show_weather"));
initHook(CompactNotificationsHook.INSTANCE, mPrefsMap.getBoolean("system_ui_control_center_compact_notice"));
initHook(new CCGrid(), (mPrefsMap.getInt("system_control_center_cc_rows", 4) > 4 ||
mPrefsMap.getInt("system_control_center_cc_columns", 4) > 4 ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,22 @@
package com.sevtinge.hyperceiler.module.hook.systemui.controlcenter

import android.annotation.SuppressLint
import android.content.pm.ApplicationInfo
import android.widget.TextView
import com.github.kyuubiran.ezxhelper.ClassUtils.loadClass
import com.github.kyuubiran.ezxhelper.HookFactory.`-Static`.createHook
import com.github.kyuubiran.ezxhelper.finders.MethodFinder.`-Static`.methodFinder
import com.sevtinge.hyperceiler.module.base.BaseHook
import com.sevtinge.hyperceiler.utils.api.invokeMethod
import com.sevtinge.hyperceiler.utils.devicesdk.isAndroidVersion
import com.sevtinge.hyperceiler.utils.devicesdk.isMoreHyperOSVersion
import com.sevtinge.hyperceiler.utils.getObjectFieldOrNullAs
import com.sevtinge.hyperceiler.view.WeatherData


@SuppressLint("StaticFieldLeak")
// 控制中心添加天气信息
object NotificationWeatherNew : BaseHook() {
lateinit var weather: WeatherData
var clockId: Int = -2
private var clockId: Int = -2

@SuppressLint("DiscouragedApi", "ClickableViewAccessibility")
override fun init() {
Expand All @@ -44,7 +43,7 @@ object NotificationWeatherNew : BaseHook() {

mControlCenterDateViewClass.methodFinder().findSuper()
.filterByName("onDetachedFromWindow")
.single().createHook {
.first().createHook {
before {
if ((it.thisObject as TextView).id == clockId && this@NotificationWeatherNew::weather.isInitialized) {
weather.onDetachedFromWindow()
Expand All @@ -53,7 +52,7 @@ object NotificationWeatherNew : BaseHook() {
}
mControlCenterDateViewClass.methodFinder().findSuper()
.filterByName("setText")
.single().createHook {
.first().createHook {
before {
val time = it.args[0]?.toString()
val view = it.thisObject as TextView
Expand All @@ -65,61 +64,9 @@ object NotificationWeatherNew : BaseHook() {
}
}
}

val pluginLoaderClass =
if (isAndroidVersion(34)) "com.android.systemui.shared.plugins.PluginInstance\$Factory\$\$ExternalSyntheticLambda0"
else "com.android.systemui.shared.plugins.PluginInstance\$Factory"

var appInfo: ApplicationInfo?

if (isAndroidVersion(34) && !isMoreHyperOSVersion(1f)) {
hookAllMethods("com.android.systemui.shared.plugins.PluginInstance\$Factory",
"create", object : MethodHook() {
override fun before(param: MethodHookParam) {
appInfo = param.args[1] as ApplicationInfo?

loadClass(pluginLoaderClass, lpparam.classLoader).methodFinder().first {
name == "get"
}.createHook {
after { getClassLoader ->
val classLoader = getClassLoader.result as ClassLoader
if (appInfo != null) {
if ("miui.systemui.plugin" == appInfo!!.packageName) {
mainPanelHeader(classLoader)
logW(TAG, "com.android.systemui", "im get ClassLoader: $classLoader")
} else {
logW(TAG, "com.android.systemui", "Au get classloader miui.systemui.plugin error: $classLoader")
}
} else {
if (
classLoader.toString().contains("MIUISystemUIPlugin") ||
classLoader.toString().contains("miui.systemui.plugin")
) {
mainPanelHeader(classLoader)
} else {
logW(TAG, "com.android.systemui", "Au get classloader miui.systemui.plugin error & appInfo is null")
}
}
}
}
}
}
)
} else {
loadClass(pluginLoaderClass, lpparam.classLoader).methodFinder()
.filterByName("getClassLoader")
.first().createHook {
after { getClassLoader ->
appInfo = getClassLoader.args[0] as ApplicationInfo
if (appInfo!!.packageName == "miui.systemui.plugin") {
val classLoader = getClassLoader.result as ClassLoader
mainPanelHeader(classLoader)
}
}
}
}
}

@JvmStatic
fun mainPanelHeader(pluginClassLoader: ClassLoader) {
if (isMoreHyperOSVersion(1f)) return
val isDisplayCity = mPrefsMap.getBoolean("system_ui_control_center_show_weather_city")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import com.sevtinge.hyperceiler.module.base.BaseHook
import com.sevtinge.hyperceiler.utils.setObjectField
import com.sevtinge.hyperceiler.view.WeatherView

// 控制中心添加天气信息
object NotificationWeatherOld : BaseHook() {

@SuppressLint("DiscouragedApi")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.CCGrid;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.CCGridForHyperOS;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.CustomCardTiles;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.NotificationWeatherNew;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.QSColor;

import java.util.ArrayList;
Expand Down Expand Up @@ -74,6 +75,8 @@ public void setClassLoader(ClassLoader classLoader) {
EnableVolumeBlur.initEnableVolumeBlur(classLoader);
if (mPrefsMap.getStringAsInt("system_ui_control_center_mi_smart_hub_entry", 0) != 0)
HideMiSmartHubEntry.initHideMiSmartHubEntry(classLoader);
if (mPrefsMap.getBoolean("system_ui_control_center_show_weather"))
NotificationWeatherNew.mainPanelHeader(classLoader);
if (mPrefsMap.getStringAsInt("system_ui_control_center_mi_play_entry", 0) != 0)
HideMiPlayEntry.initHideMiPlayEntry(classLoader);
if (mPrefsMap.getStringAsInt("system_ui_control_center_device_ctrl_entry", 0) != 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,15 @@
*/
package com.sevtinge.hyperceiler.ui.fragment.app.systemui;

import static com.sevtinge.hyperceiler.utils.devicesdk.SystemSDKKt.getWhoAmI;
import static com.sevtinge.hyperceiler.utils.devicesdk.SystemSDKKt.isMoreAndroidVersion;
import static com.sevtinge.hyperceiler.utils.devicesdk.SystemSDKKt.isMoreHyperOSVersion;
import static com.sevtinge.hyperceiler.utils.shell.ShellUtils.rootExecCmd;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings;
import android.view.View;
import android.widget.SeekBar;

import androidx.annotation.NonNull;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.SwitchPreference;
Expand All @@ -41,44 +37,29 @@
import com.sevtinge.hyperceiler.ui.activity.base.BaseSettingsActivity;
import com.sevtinge.hyperceiler.ui.fragment.dashboard.DashboardFragment;
import com.sevtinge.hyperceiler.ui.fragment.sub.AppPicker;
import com.sevtinge.hyperceiler.utils.KillApp;
import com.sevtinge.hyperceiler.utils.ThreadPoolManager;
import com.sevtinge.hyperceiler.utils.devicesdk.TelephonyManager;
import com.sevtinge.hyperceiler.utils.log.AndroidLogUtils;
import com.sevtinge.hyperceiler.utils.prefs.PrefsUtils;

import fan.preference.ColorPickerPreference;
import fan.preference.DropDownPreference;
import fan.preference.SeekBarPreferenceCompat;

public class ControlCenterSettings extends DashboardFragment implements Preference.OnPreferenceChangeListener {
public class ControlCenterSettings extends DashboardFragment {

Preference mExpandNotification;
Preference mMusic;
PreferenceCategory mCard;
PreferenceCategory mOldCCGrid;
SwitchPreference mNotice;
SwitchPreference mNoticex;
SwitchPreference mSwitchCCAN;
SwitchPreference mSpotlightNotifColorMix;
SeekBarPreferenceCompat mNewCCGrid;
SeekBarPreferenceCompat mNewCCGridColumns;
SwitchPreference mNewCCGridLabel;
DropDownPreference mFiveG;
DropDownPreference mBluetoothSytle;
SwitchPreference mRoundedRect;
SeekBarPreferenceCompat mRoundedRectRadius;
SwitchPreference mThemeBlur;
SwitchPreference mRedirectNotice;
SwitchPreference mShadeHeaderBlur;
DropDownPreference mSunshineMode;
DropDownPreference mSunshineModeHigh;
SeekBarPreferenceCompat mSunshineModeHighBrightness;
SwitchPreference mSpotlightNotifColorMix;

SwitchPreference mTaplus;
SwitchPreference mNotifrowmenu;
RecommendPreference mRecommend;
Handler handler;

int mMaxBrightness = 0;

@Override
public int getPreferenceScreenResId() {
Expand All @@ -97,30 +78,19 @@ public View.OnClickListener addRestartListener() {
public void initPrefs() {
mMusic = findPreference("prefs_key_system_ui_control_center_media_control_media_custom");
mCard = findPreference("prefs_key_system_ui_controlcenter_card");
mOldCCGrid = findPreference("prefs_key_system_ui_controlcenter_old");
mExpandNotification = findPreference("prefs_key_system_ui_control_center_expand_notification");
mNewCCGrid = findPreference("prefs_key_system_control_center_cc_rows");
mNewCCGridColumns = findPreference("prefs_key_system_control_center_cc_columns");
mNewCCGridLabel = findPreference("prefs_key_system_control_center_qs_tile_label");
mNotice = findPreference("prefs_key_n_enable");
mNoticex = findPreference("prefs_key_n_enable_fix");
mSwitchCCAN = findPreference("prefs_key_system_ui_control_center_switch_cc_and_notification");
mBluetoothSytle = findPreference("prefs_key_system_ui_control_center_cc_bluetooth_tile_style");
mFiveG = findPreference("prefs_key_system_control_center_5g_new_tile");
mRoundedRect = findPreference("prefs_key_system_ui_control_center_rounded_rect");
mRoundedRectRadius = findPreference("prefs_key_system_ui_control_center_rounded_rect_radius");
mTaplus = findPreference("prefs_key_security_center_taplus");
mThemeBlur = findPreference("prefs_key_system_ui_control_center_unlock_blur_supported");
mNotifrowmenu = findPreference("prefs_key_system_ui_control_center_notifrowmenu");
mRedirectNotice = findPreference("prefs_key_system_ui_control_center_redirect_notice");
mShadeHeaderBlur = findPreference("prefs_key_system_ui_shade_header_gradient_blur");
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");
mSpotlightNotifColorMix = findPreference("prefs_key_system_ui_control_center_opt_notification_element_background_color");
handler = new Handler();

try {
mMaxBrightness = Integer.parseInt(rootExecCmd("cat /sys/class/backlight/panel0-backlight/max_brightness"));
} catch (Exception ignore) {}
mShadeHeaderBlur = findPreference("prefs_key_system_ui_shade_header_gradient_blur");

mExpandNotification.setOnPreferenceClickListener(
preference -> {
Expand All @@ -132,54 +102,31 @@ public void initPrefs() {
}
);

mTaplus.setOnPreferenceChangeListener(
(preference, o) -> {
killTaplus();
return true;
}
);

if (getWhoAmI().equals("root") && mMaxBrightness > 2048) {
mSunshineModeHigh.setVisible(true);
mSunshineMode.setVisible(false);
mSunshineModeHigh.setOnPreferenceChangeListener(this);
mSunshineModeHighBrightness.setMaxValue(mMaxBrightness);
} else {
mSunshineMode.setVisible(true);
mSunshineModeHigh.setVisible(false);
mSunshineModeHighBrightness.setVisible(false);
}

if (isMoreHyperOSVersion(1f)) {
mNewCCGrid.setVisible(false);
mCard.setVisible(false);
mNewCCGridColumns.setVisible(false);
mNewCCGridLabel.setVisible(false);

mNotice.setVisible(false);
mBluetoothSytle.setVisible(false);
mNotifrowmenu.setVisible(false);
mMusic.setVisible(true);
mThemeBlur.setVisible(true);
mRoundedRectRadius.setVisible(PrefsUtils.getSharedBoolPrefs(getContext(), "prefs_key_system_ui_control_center_rounded_rect", false));
} else {
mNewCCGrid.setVisible(true);
mCard.setVisible(true);
mNewCCGridColumns.setVisible(true);
mNewCCGridLabel.setVisible(true);
mNotice.setVisible(true);
mBluetoothSytle.setVisible(true);
mNotifrowmenu.setVisible(true);
mMusic.setVisible(false);
mThemeBlur.setVisible(false);
mRoundedRectRadius.setVisible(false);
}
mOldCCGrid.setVisible(!isMoreHyperOSVersion(2f));
mSwitchCCAN.setVisible(!isMoreHyperOSVersion(2f));
mRedirectNotice.setVisible(!isMoreAndroidVersion(35));
mSpotlightNotifColorMix.setVisible(isMoreHyperOSVersion(2f) && isMoreAndroidVersion(35));
mShadeHeaderBlur.setVisible(isMoreHyperOSVersion(2f) && isMoreAndroidVersion(35));
mFiveG.setVisible(TelephonyManager.getDefault().isFiveGCapable());
mSunshineModeHighBrightness.setVisible(Integer.parseInt(PrefsUtils.mSharedPreferences.getString("prefs_key_system_control_center_sunshine_new_mode_high", "0")) == 3);;

mRoundedRect.setOnPreferenceChangeListener(this);

((SeekBarPreferenceCompat) findPreference("prefs_key_system_control_center_old_qs_grid_columns")).setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
Expand Down Expand Up @@ -217,27 +164,4 @@ public void onStopTrackingTouch(SeekBar seekBar) {
);

}

public void killTaplus() {
ThreadPoolManager.getInstance().submit(() -> handler.post(() ->
KillApp.killApps("com.miui.contentextension")));
}

@Override
public boolean onPreferenceChange(@NonNull Preference preference, Object o) {
if (preference == mRoundedRect) {
setCanBeVisibleRoundedRect((Boolean) o);
} else if (preference == mSunshineModeHigh) {
setCanBeVisibleSunshineBrightness(Integer.parseInt((String) o));
}
return true;
}

private void setCanBeVisibleRoundedRect(boolean mode) {
mRoundedRectRadius.setVisible(mode && isMoreHyperOSVersion(1f));
}

private void setCanBeVisibleSunshineBrightness(int mode) {
mSunshineModeHighBrightness.setVisible(mode == 3);
}
}
Loading

0 comments on commit 1dd31af

Please sign in to comment.