11/*
2- * This file is part of HyperCeiler.
2+ * This file is part of HyperCeiler.
33
4- * HyperCeiler is free software: you can redistribute it and/or modify
5- * it under the terms of the GNU Affero General Public License as
6- * published by the Free Software Foundation, either version 3 of the
7- * License.
4+ * HyperCeiler is free software: you can redistribute it and/or modify
5+ * it under the terms of the GNU Affero General Public License as
6+ * published by the Free Software Foundation, either version 3 of the
7+ * License.
88
9- * This program is distributed in the hope that it will be useful,
10- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12- * GNU Affero General Public License for more details.
9+ * This program is distributed in the hope that it will be useful,
10+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+ * GNU Affero General Public License for more details.
1313
14- * You should have received a copy of the GNU Affero General Public License
15- * along with this program. If not, see <https://www.gnu.org/licenses/>.
14+ * You should have received a copy of the GNU Affero General Public License
15+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
1616
17- * Copyright (C) 2023-2024 HyperCeiler Contributions
18- */
17+ * Copyright (C) 2023-2024 HyperCeiler Contributions
18+ */
1919package com .sevtinge .hyperceiler .module .hook .systemframework ;
2020
2121import android .annotation .SuppressLint ;
@@ -44,7 +44,6 @@ public class StickyFloatingWindows extends BaseHook {
4444
4545 @ Override
4646 public void init () {
47-
4847 final List <String > fwBlackList = new ArrayList <>();
4948 fwBlackList .add ("com.miui.securitycenter" );
5049 fwBlackList .add ("com.miui.home" );
@@ -54,9 +53,16 @@ public void init() {
5453 protected void after (MethodHookParam param ) {
5554 if (param .args .length != 8 ) return ;
5655 Intent intent = (Intent ) param .args [5 ];
56+ Object activityRecord = param .args [7 ];
57+ Intent recordIntent = (Intent ) XposedHelpers .getObjectField (activityRecord , "intent" );
58+ String recordPackageName = recordIntent .getComponent ().getPackageName ();
59+ String packageName = intent .getComponent ().getPackageName ();
60+ if (recordPackageName .equals (packageName )) {
61+ // 如果是相同应用跳转就忽略,防止出现全屏应用跳转页面之后变成小窗的情况
62+ return ;
63+ }
5764 if (intent == null || intent .getComponent () == null ) return ;
5865 ActivityOptions options = (ActivityOptions ) param .getResult ();
59- int windowingMode = options == null ? -1 : (int ) XposedHelpers .callMethod (options , "getLaunchWindowingMode" );
6066 String pkgName = intent .getComponent ().getPackageName ();
6167 if (fwBlackList .contains (pkgName )) return ;
6268 Context mContext ;
@@ -65,7 +71,7 @@ protected void after(MethodHookParam param) {
6571 } catch (Throwable ignore ) {
6672 mContext = (Context ) XposedHelpers .getObjectField (XposedHelpers .getObjectField (param .args [0 ], "mService" ), "mContext" );
6773 }
68- if (windowingMode != 5 && fwApps .containsKey (pkgName )) {
74+ if (fwApps .containsKey (pkgName )) {
6975 try {
7076 if (MiuiMultiWindowUtils == null ) {
7177 logE (TAG , StickyFloatingWindows .this .lpparam .packageName , "Cannot find MiuiMultiWindowUtils class" );
@@ -76,36 +82,19 @@ protected void after(MethodHookParam param) {
7682 } catch (Throwable t ) {
7783 logW (TAG , "" , t );
7884 }
79- } else if (windowingMode == 5 && !fwApps .containsKey (pkgName )) {
80- fwApps .put (pkgName , new Pair <>(0f , null ));
81- storeFwAppsInSetting (mContext );
8285 }
8386 }
8487 });
8588
8689 hookAllMethods ("com.android.server.wm.ActivityTaskSupervisor" , "startActivityFromRecents" , new MethodHook () {
87- @ Override
88- protected void after (MethodHookParam param ) {
89- Object safeOptions = param .args [3 ];
90- ActivityOptions options = (ActivityOptions ) XposedHelpers .callMethod (safeOptions , "getOptions" , param .thisObject );
91- int windowingMode = options == null ? -1 : (int ) XposedHelpers .callMethod (options , "getLaunchWindowingMode" );
92- String pkgName = getTaskPackageName (param .thisObject , (int ) param .args [2 ], options );
93- if (fwBlackList .contains (pkgName )) return ;
94- if (windowingMode == 5 && pkgName != null ) {
95- fwApps .put (pkgName , new Pair <>(0f , null ));
96- Context mContext = (Context ) XposedHelpers .getObjectField (XposedHelpers .getObjectField (param .thisObject , "mService" ), "mContext" );
97- storeFwAppsInSetting (mContext );
98- }
99- }
10090
10191 @ Override
10292 protected void before (MethodHookParam param ) {
10393 Object safeOptions = param .args [3 ];
10494 ActivityOptions options = (ActivityOptions ) XposedHelpers .callMethod (safeOptions , "getOptions" , param .thisObject );
105- int windowingMode = options == null ? -1 : (int ) XposedHelpers .callMethod (options , "getLaunchWindowingMode" );
10695 String pkgName = getTaskPackageName (param .thisObject , (int ) param .args [2 ], options );
10796 if (fwBlackList .contains (pkgName )) return ;
108- if (windowingMode != 5 && fwApps .containsKey (pkgName )) {
97+ if (fwApps .containsKey (pkgName )) {
10998 Context mContext = (Context ) XposedHelpers .getObjectField (XposedHelpers .getObjectField (param .thisObject , "mService" ), "mContext" );
11099 options = patchActivityOptions (mContext , options , pkgName , MiuiMultiWindowUtils );
111100 XposedHelpers .setObjectField (safeOptions , "mOriginalOptions" , options );
@@ -184,6 +173,47 @@ public void onReceive(Context context, Intent intent) {
184173 }
185174 }
186175 }, new IntentFilter ("miui.intent.action_launch_fullscreen_from_freeform" ));
176+
177+ IntentFilter mFilter = new IntentFilter ();
178+ mFilter .addAction (ACTION_PREFIX + "updateFwApps" );
179+ mFilter .addAction (ACTION_PREFIX + "getFwApps" );
180+ mFilter .addAction (ACTION_PREFIX + "removeFwApps" );
181+ mContext .registerReceiver (new BroadcastReceiver () {
182+ @ Override
183+ public void onReceive (Context context , Intent intent ) {
184+ String pkgName = intent .getStringExtra ("package" );
185+ switch (intent .getAction ()) {
186+ case ACTION_PREFIX + "updateFwApps" :
187+ float scale = intent .getFloatExtra ("scale" , 0f );
188+ Rect rect = intent .getParcelableExtra ("rect" );
189+ if (!fwApps .containsKey (pkgName )) {
190+ fwApps .put (pkgName , new Pair <>(scale , rect ));
191+ storeFwAppsInSetting (context );
192+ return ;
193+ }
194+ Pair <Float , Rect > oldPair = fwApps .get (pkgName );
195+ if (scale == 0f ) {
196+ scale = oldPair .first ;
197+ }
198+ if (rect == null ) {
199+ rect = oldPair .second ;
200+ }
201+ fwApps .put (pkgName , new Pair <>(scale , rect ));
202+ storeFwAppsInSetting (context );
203+ break ;
204+ case ACTION_PREFIX + "getFwApps" :
205+ syncFwApps (context );
206+ break ;
207+ case ACTION_PREFIX + "removeFwApps" :
208+ if (pkgName != null && fwApps .remove (pkgName ) != null ) {
209+ storeFwAppsInSetting (context );
210+ }
211+ break ;
212+ default :
213+ break ;
214+ }
215+ }
216+ }, mFilter );
187217 }
188218 });
189219
@@ -228,8 +258,8 @@ public static String getTaskPackageName(Object thisObject, int taskId, boolean w
228258 Object mRootWindowContainer = XposedHelpers .getObjectField (thisObject , "mRootWindowContainer" );
229259 if (mRootWindowContainer == null ) return null ;
230260 Object task = withOptions ?
231- XposedHelpers .callMethod (mRootWindowContainer , "anyTaskForId" , taskId , 2 , options , true ) :
232- XposedHelpers .callMethod (mRootWindowContainer , "anyTaskForId" , taskId , 0 );
261+ XposedHelpers .callMethod (mRootWindowContainer , "anyTaskForId" , taskId , 2 , options , true ) :
262+ XposedHelpers .callMethod (mRootWindowContainer , "anyTaskForId" , taskId , 0 );
233263 if (task == null ) return null ;
234264 Intent intent = (Intent ) XposedHelpers .getObjectField (task , "intent" );
235265 return intent == null ? null : intent .getComponent ().getPackageName ();
@@ -260,7 +290,15 @@ public static void unserializeFwApps(String data) {
260290 }
261291 }
262292
293+ public static void syncFwApps (Context context ) {
294+ if (context == null ) return ;
295+ Intent intent = new Intent (ACTION_PREFIX + "syncFwApps" );
296+ intent .putExtra ("fwApps" , serializeFwApps ());
297+ context .sendBroadcast (intent );
298+ }
299+
263300 public static void storeFwAppsInSetting (Context context ) {
301+ syncFwApps (context );
264302 Settings .Global .putString (context .getContentResolver (), ProjectApi .mAppModulePkg + ".fw.apps" , serializeFwApps ());
265303 }
266304
0 commit comments