Skip to content

Commit

Permalink
新增: 1.禁用无极缩放(平板) 2.小窗-记住状态 改为 记住状态及位置 (#709)
Browse files Browse the repository at this point in the history
* feat: disable infinitymode gesture for pad

* feat: freeform - Remember state function adds remember location

* refactor: hide "disable infinitymode gesture" switch on phone
  • Loading branch information
wuyou-123 authored Jun 27, 2024
1 parent 7daee7a commit 9dbb1aa
Show file tree
Hide file tree
Showing 8 changed files with 279 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.sevtinge.hyperceiler.module.hook.systemui.BrightnessPct;
import com.sevtinge.hyperceiler.module.hook.systemui.ChargeAnimationStyle;
import com.sevtinge.hyperceiler.module.hook.systemui.DisableBottomBar;
import com.sevtinge.hyperceiler.module.hook.systemui.DisableInfinitymodeGesture;
import com.sevtinge.hyperceiler.module.hook.systemui.DisableMiuiMultiWinSwitch;
import com.sevtinge.hyperceiler.module.hook.systemui.DisableTransparent;
import com.sevtinge.hyperceiler.module.hook.systemui.MediaButton;
Expand All @@ -42,6 +43,7 @@
import com.sevtinge.hyperceiler.module.hook.systemui.RemoveMiuiMultiWinSwitch;
import com.sevtinge.hyperceiler.module.hook.systemui.SquigglyProgress;
import com.sevtinge.hyperceiler.module.hook.systemui.StatusBarActions;
import com.sevtinge.hyperceiler.module.hook.systemui.StickyFloatingWindowsForSystemUI;
import com.sevtinge.hyperceiler.module.hook.systemui.UiLockApp;
import com.sevtinge.hyperceiler.module.hook.systemui.UnimportantNotification;
import com.sevtinge.hyperceiler.module.hook.systemui.UnlockClipboard;
Expand Down Expand Up @@ -183,6 +185,7 @@ public void handleLoadPackage() {
initHook(StatusBarSimIcon.INSTANCE, isHideSim);
initHook(HideVoWiFiIcon.INSTANCE, mPrefsMap.getBoolean("system_ui_status_bar_icon_vowifi") || mPrefsMap.getBoolean("system_ui_status_bar_icon_volte"));
initHook(UseNewHD.INSTANCE, mPrefsMap.getBoolean("system_ui_status_bar_use_new_hd"));
initHook(new StickyFloatingWindowsForSystemUI(), mPrefsMap.getBoolean("system_framework_freeform_sticky"));

// 移动网络图标
boolean isEnableMobilePublic = mPrefsMap.getBoolean("system_ui_status_bar_icon_mobile_network_hide_card_1") ||
Expand Down Expand Up @@ -333,6 +336,7 @@ public void handleLoadPackage() {
initHook(new BrightnessPct(), mPrefsMap.getBoolean("system_showpct_title"));
initHook(DisableMiuiMultiWinSwitch.INSTANCE, mPrefsMap.getBoolean("system_ui_disable_miui_multi_win_switch"));
initHook(RemoveMiuiMultiWinSwitch.INSTANCE, mPrefsMap.getBoolean("system_ui_remove_miui_multi_win_switch"));
initHook(DisableInfinitymodeGesture.INSTANCE, mPrefsMap.getBoolean("system_ui_disable_infinitymode_gesture"));
initHook(DisableBottomBar.INSTANCE, mPrefsMap.getBoolean("system_ui_disable_bottombar"));
initHook(UnlockClipboard.INSTANCE, mPrefsMap.getBoolean("system_ui_unlock_clipboard"));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
/*
* This file is part of HyperCeiler.
* 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.
* 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.
* 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 <https://www.gnu.org/licenses/>.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* Copyright (C) 2023-2024 HyperCeiler Contributions
*/
* Copyright (C) 2023-2024 HyperCeiler Contributions
*/
package com.sevtinge.hyperceiler.module.hook.systemframework;

import android.annotation.SuppressLint;
Expand Down Expand Up @@ -44,7 +44,6 @@ public class StickyFloatingWindows extends BaseHook {

@Override
public void init() {

final List<String> fwBlackList = new ArrayList<>();
fwBlackList.add("com.miui.securitycenter");
fwBlackList.add("com.miui.home");
Expand All @@ -54,9 +53,16 @@ public void init() {
protected void after(MethodHookParam param) {
if (param.args.length != 8) return;
Intent intent = (Intent) param.args[5];
Object activityRecord = param.args[7];
Intent recordIntent = (Intent) XposedHelpers.getObjectField(activityRecord, "intent");
String recordPackageName = recordIntent.getComponent().getPackageName();
String packageName = intent.getComponent().getPackageName();
if (recordPackageName.equals(packageName)) {
// 如果是相同应用跳转就忽略,防止出现全屏应用跳转页面之后变成小窗的情况
return;
}
if (intent == null || intent.getComponent() == null) return;
ActivityOptions options = (ActivityOptions) param.getResult();
int windowingMode = options == null ? -1 : (int) XposedHelpers.callMethod(options, "getLaunchWindowingMode");
String pkgName = intent.getComponent().getPackageName();
if (fwBlackList.contains(pkgName)) return;
Context mContext;
Expand All @@ -65,7 +71,7 @@ protected void after(MethodHookParam param) {
} catch (Throwable ignore) {
mContext = (Context) XposedHelpers.getObjectField(XposedHelpers.getObjectField(param.args[0], "mService"), "mContext");
}
if (windowingMode != 5 && fwApps.containsKey(pkgName)) {
if (fwApps.containsKey(pkgName)) {
try {
if (MiuiMultiWindowUtils == null) {
logE(TAG, StickyFloatingWindows.this.lpparam.packageName, "Cannot find MiuiMultiWindowUtils class");
Expand All @@ -76,36 +82,19 @@ protected void after(MethodHookParam param) {
} catch (Throwable t) {
logW(TAG, "", t);
}
} else if (windowingMode == 5 && !fwApps.containsKey(pkgName)) {
fwApps.put(pkgName, new Pair<>(0f, null));
storeFwAppsInSetting(mContext);
}
}
});

hookAllMethods("com.android.server.wm.ActivityTaskSupervisor", "startActivityFromRecents", new MethodHook() {
@Override
protected void after(MethodHookParam param) {
Object safeOptions = param.args[3];
ActivityOptions options = (ActivityOptions) XposedHelpers.callMethod(safeOptions, "getOptions", param.thisObject);
int windowingMode = options == null ? -1 : (int) XposedHelpers.callMethod(options, "getLaunchWindowingMode");
String pkgName = getTaskPackageName(param.thisObject, (int) param.args[2], options);
if (fwBlackList.contains(pkgName)) return;
if (windowingMode == 5 && pkgName != null) {
fwApps.put(pkgName, new Pair<>(0f, null));
Context mContext = (Context) XposedHelpers.getObjectField(XposedHelpers.getObjectField(param.thisObject, "mService"), "mContext");
storeFwAppsInSetting(mContext);
}
}

@Override
protected void before(MethodHookParam param) {
Object safeOptions = param.args[3];
ActivityOptions options = (ActivityOptions) XposedHelpers.callMethod(safeOptions, "getOptions", param.thisObject);
int windowingMode = options == null ? -1 : (int) XposedHelpers.callMethod(options, "getLaunchWindowingMode");
String pkgName = getTaskPackageName(param.thisObject, (int) param.args[2], options);
if (fwBlackList.contains(pkgName)) return;
if (windowingMode != 5 && fwApps.containsKey(pkgName)) {
if (fwApps.containsKey(pkgName)) {
Context mContext = (Context) XposedHelpers.getObjectField(XposedHelpers.getObjectField(param.thisObject, "mService"), "mContext");
options = patchActivityOptions(mContext, options, pkgName, MiuiMultiWindowUtils);
XposedHelpers.setObjectField(safeOptions, "mOriginalOptions", options);
Expand Down Expand Up @@ -184,6 +173,47 @@ public void onReceive(Context context, Intent intent) {
}
}
}, new IntentFilter("miui.intent.action_launch_fullscreen_from_freeform"));

IntentFilter mFilter = new IntentFilter();
mFilter.addAction(ACTION_PREFIX + "updateFwApps");
mFilter.addAction(ACTION_PREFIX + "getFwApps");
mFilter.addAction(ACTION_PREFIX + "removeFwApps");
mContext.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String pkgName = intent.getStringExtra("package");
switch (intent.getAction()) {
case ACTION_PREFIX + "updateFwApps":
float scale = intent.getFloatExtra("scale", 0f);
Rect rect = intent.getParcelableExtra("rect");
if (!fwApps.containsKey(pkgName)) {
fwApps.put(pkgName, new Pair<>(scale, rect));
storeFwAppsInSetting(context);
return;
}
Pair<Float, Rect> oldPair = fwApps.get(pkgName);
if (scale == 0f) {
scale = oldPair.first;
}
if (rect == null) {
rect = oldPair.second;
}
fwApps.put(pkgName, new Pair<>(scale, rect));
storeFwAppsInSetting(context);
break;
case ACTION_PREFIX + "getFwApps":
syncFwApps(context);
break;
case ACTION_PREFIX + "removeFwApps":
if (pkgName != null && fwApps.remove(pkgName) != null) {
storeFwAppsInSetting(context);
}
break;
default:
break;
}
}
}, mFilter);
}
});

Expand Down Expand Up @@ -228,8 +258,8 @@ public static String getTaskPackageName(Object thisObject, int taskId, boolean w
Object mRootWindowContainer = XposedHelpers.getObjectField(thisObject, "mRootWindowContainer");
if (mRootWindowContainer == null) return null;
Object task = withOptions ?
XposedHelpers.callMethod(mRootWindowContainer, "anyTaskForId", taskId, 2, options, true) :
XposedHelpers.callMethod(mRootWindowContainer, "anyTaskForId", taskId, 0);
XposedHelpers.callMethod(mRootWindowContainer, "anyTaskForId", taskId, 2, options, true) :
XposedHelpers.callMethod(mRootWindowContainer, "anyTaskForId", taskId, 0);
if (task == null) return null;
Intent intent = (Intent) XposedHelpers.getObjectField(task, "intent");
return intent == null ? null : intent.getComponent().getPackageName();
Expand Down Expand Up @@ -260,7 +290,15 @@ public static void unserializeFwApps(String data) {
}
}

public static void syncFwApps(Context context) {
if (context == null) return;
Intent intent = new Intent(ACTION_PREFIX + "syncFwApps");
intent.putExtra("fwApps", serializeFwApps());
context.sendBroadcast(intent);
}

public static void storeFwAppsInSetting(Context context) {
syncFwApps(context);
Settings.Global.putString(context.getContentResolver(), ProjectApi.mAppModulePkg + ".fw.apps", serializeFwApps());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.sevtinge.hyperceiler.module.hook.systemui

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.*


object DisableInfinitymodeGesture : BaseHook() {
override fun init() {
loadClass(
"com.android.wm.shell.miuifreeform.MiuiInfinityModeSizesPolicy",
).methodFinder().filterByName("isForbiddenWindow").single().createHook {
returnConstant(true)
}
}
}
Loading

0 comments on commit 9dbb1aa

Please sign in to comment.