Skip to content

Commit

Permalink
修复贴边小窗在横竖屏切换时卡片异常显示的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
HChenX committed Jan 26, 2024
1 parent 1ee2794 commit 7bba903
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 14 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ android {
minSdk 30
targetSdk 34
//noinspection HighAppVersionCode
versionCode 2023122002
versionName "1.2"
versionCode 2024012600
versionName "1.3"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
signingConfig signingConfigs.release
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/com/hchen/foregroundpin/HookMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.hchen.foregroundpin.hookMode.Hook;
import com.hchen.foregroundpin.pinHook.ForegroundPin;
import com.hchen.foregroundpin.pinHook.ShouldHeadUp;

import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam;
Expand Down
157 changes: 151 additions & 6 deletions app/src/main/java/com/hchen/foregroundpin/pinHook/ForegroundPin.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.hchen.foregroundpin.pinHook;

import android.graphics.Rect;
import android.util.Log;
import android.view.SurfaceControl;

import com.hchen.foregroundpin.hookMode.Hook;

Expand Down Expand Up @@ -35,19 +35,163 @@ protected void before(XC_MethodHook.MethodHookParam param) {
new HookAction() {
@Override
protected void before(XC_MethodHook.MethodHookParam param) {
Object stack = param.args[0];
if (stack != null) {
Object mTask = XposedHelpers.getObjectField(stack, "mTask");
if (mTask != null) {
SurfaceControl surfaceControl;
if (mTask != null && (surfaceControl =
(SurfaceControl) XposedHelpers.getObjectField(mTask,
"mSurfaceControl")) != null
&& surfaceControl.isValid()) {
SurfaceControl.Transaction transaction = new SurfaceControl.Transaction();
XposedHelpers.callMethod(transaction, "hide", surfaceControl);
XposedHelpers.callMethod(transaction, "apply");
// logE(tag, "moveTaskToBack: s: " + surfaceControl);
param.setResult(null);
}
}
}
}
}
);

/*findAndHookMethod("com.android.server.wm.MiuiFreeformPinManagerService",
"hideStack", "com.android.server.wm.MiuiFreeFormActivityStack",
new HookAction() {
@Override
protected void before(MethodHookParam param) throws Throwable {
Object stack = param.args[0];
Object mainWindow;
Object mController = XposedHelpers.getObjectField(param.thisObject, "mController");
Object mGestureListener = XposedHelpers.getObjectField(mController, "mGestureListener");
Object mGestureAnimator = XposedHelpers.getObjectField(mGestureListener, "mGestureAnimator");
XposedHelpers.callMethod(mGestureAnimator, "hideStack", stack);
XposedHelpers.callMethod(mGestureAnimator, "applyTransaction");
if (stack != null) {
Object mTask = XposedHelpers.getObjectField(stack, "mTask");
if (mTask != null) {
SurfaceControl surfaceControl;
if (mTask != null && (surfaceControl =
(SurfaceControl) XposedHelpers.getObjectField(mTask,
"mSurfaceControl")) != null
&& surfaceControl.isValid()) {
SurfaceControl.Transaction transaction = new SurfaceControl.Transaction();
// XposedHelpers.callMethod(transaction, "setCrop", surfaceControl, null);
XposedHelpers.callMethod(transaction, "hide", surfaceControl);
XposedHelpers.callMethod(transaction, "apply");
logE(tag, "moveTaskToBack: s: " + surfaceControl);
}
}
}
Object activityRecord = XposedHelpers.getObjectField(stack, "mLastIconLayerWindowToken");
if (activityRecord != null) {
if (XposedHelpers.getObjectField(activityRecord, "mFloatWindwoIconSurfaceControl") != null &&
(mainWindow = XposedHelpers.callMethod(activityRecord, "findMainWindow")) != null) {
XposedHelpers.callMethod(mGestureAnimator, "setAlphaInTransaction",
XposedHelpers.getObjectField(mainWindow, "mSurfaceControl"), 1.0f);
XposedHelpers.callMethod(mGestureAnimator, "applyTransaction");
}
}
XposedHelpers.callMethod(param.thisObject, "clearMiuiFreeWindowFloatIconLayer", stack);
boolean isInMiniFreeFormMode = (boolean) XposedHelpers.callMethod(stack, "isInMiniFreeFormMode");
if (!isInMiniFreeFormMode) {
XposedHelpers.callMethod(mGestureAnimator, "removeAnimationControlLeash", stack);
} else {
XposedHelpers.callMethod(mGestureAnimator, "setWindowCropInTransaction", stack, null);
}
XposedHelpers.callMethod(stack, "updateCornerRadius");
XposedHelpers.setObjectField(stack, "mIsRunningPinAnim", false);
Object service = XposedHelpers.getObjectField(mController, "mMiuiFreeFormManagerService");
Object mActivityTaskManagerService = XposedHelpers.getObjectField(service, "mActivityTaskManagerService");
Object getInstance = XposedHelpers.callStaticMethod(findClassIfExists("android.app.ActivityTaskManager"),
"getInstance");
List<ActivityManager.RunningTaskInfo> tasks = (List<ActivityManager.RunningTaskInfo>)
XposedHelpers.callMethod(getInstance, "getTasks", 1, false);
if (!tasks.isEmpty()) {
ActivityManager.RunningTaskInfo runningTaskInfo = tasks.get(0);
int taskId = runningTaskInfo.taskId;
Object nextFocusdTask = null;
Object curentTask = XposedHelpers.callMethod(XposedHelpers.getObjectField(mActivityTaskManagerService,
"mRootWindowContainer"),
"anyTaskForId", taskId, 0);
if (curentTask != null && (boolean) XposedHelpers.callMethod(curentTask, "isFocused")
&& (nextFocusdTask = XposedHelpers.callMethod(curentTask, "getNextFocusableTask", false)) != null) {
XposedHelpers.callMethod(mActivityTaskManagerService, "setFocusedRootTask",
XposedHelpers.callMethod(nextFocusdTask, "getRootTaskId"));
}
logE(tag, "run: " + runningTaskInfo + " id: " + taskId + " cur: " + curentTask + " next: " + nextFocusdTask);
}
logE(tag, "run here");
param.setResult(null);
}
}
);*/

hookAllConstructors("com.android.server.wm.Task",
new HookAction() {
@Override
protected void after(MethodHookParam param) {
XposedHelpers.setAdditionalInstanceField(param.thisObject, "mLastSurfaceVisibility", true);
// logE(tag, "Task add mLastSurfaceVisibility");
}
}
);

findAndHookMethod("com.android.server.wm.Task",
"prepareSurfaces", new HookAction() {
@Override
protected void after(MethodHookParam param) {
SurfaceControl.Transaction transaction = (SurfaceControl.Transaction) XposedHelpers.callMethod(param.thisObject, "getSyncTransaction");
SurfaceControl mSurfaceControl = (SurfaceControl) XposedHelpers.getObjectField(param.thisObject, "mSurfaceControl");
// String pkg = (String) XposedHelpers.callMethod(param.thisObject, "getPackageName");
// String mCallingPackage = (String) XposedHelpers.getObjectField(param.thisObject, "mCallingPackage");
// Object getTopNonFinishingActivity = XposedHelpers.callMethod(param.thisObject, "getTopNonFinishingActivity");
// String pkg = null;
/*if (getTopNonFinishingActivity != null) {
ActivityInfo activityInfo = (ActivityInfo) XposedHelpers.getObjectField(getTopNonFinishingActivity, "info");
if (activityInfo != null) {
pkg = activityInfo.applicationInfo.packageName;
}
}*/
int taskId = (int) XposedHelpers.callMethod(param.thisObject, "getRootTaskId");
Object mWmService = XposedHelpers.getObjectField(param.thisObject, "mWmService");
Object mAtmService = XposedHelpers.getObjectField(mWmService, "mAtmService");
Object mMiuiFreeFormManagerService = XposedHelpers.getObjectField(mAtmService, "mMiuiFreeFormManagerService");
Object mffs = XposedHelpers.callMethod(mMiuiFreeFormManagerService, "getMiuiFreeFormActivityStack", taskId);
boolean isVisible = (boolean) XposedHelpers.callMethod(param.thisObject, "isVisible");
boolean isAnimating = (boolean) XposedHelpers.callMethod(param.thisObject, "isAnimating", 7);
boolean inPinMode = false;
if (mffs != null) {
inPinMode = (boolean) XposedHelpers.callMethod(mffs, "inPinMode");
}
boolean mLastSurfaceVisibility = (boolean) XposedHelpers.getAdditionalInstanceField(param.thisObject, "mLastSurfaceVisibility");
if (mSurfaceControl != null && mffs != null && inPinMode) {
if (!isAnimating) {
XposedHelpers.callMethod(transaction, "setVisibility", mSurfaceControl, false);
XposedHelpers.setAdditionalInstanceField(param.thisObject, "mLastSurfaceVisibility", false);
}
// logE(tag, "setVisibility false pkg2: " + pkg + " taskid: " + taskId + " isVisble: " + isVisible
// + " an: " + isAnimating + " la: " + mLastSurfaceVisibility);
} else if (mSurfaceControl != null && mffs != null && !inPinMode) {
if (!mLastSurfaceVisibility) {
XposedHelpers.callMethod(transaction, "setVisibility", mSurfaceControl, true);
XposedHelpers.setAdditionalInstanceField(param.thisObject, "mLastSurfaceVisibility", true);
}
// logE(tag, "setVisibility true pkg2: " + pkg + " taskid: " + taskId + " isVisble: " + isVisible + " an: " + isAnimating);
}
// logE(tag, "sur: " + mSurfaceControl + " tra: " + transaction + " pkg: " + pkg + " inpin: " + inPinMode);
}
}
);

findAndHookMethod("com.android.server.wm.MiuiFreeFormManagerService",
/*findAndHookMethod("com.android.server.wm.MiuiFreeFormManagerService",
"updatePinFloatingWindowPos",
Rect.class, int.class, boolean.class, new HookAction() {
@Override
protected void before(MethodHookParam param) throws Throwable {
if ((boolean) param.args[2]) {
Object mffas = callMethod(param.thisObject, "getMiuiFreeFormActivityStackForMiuiFB", param.args[1]);
callMethod(getObjectField(mffas, "mLastIconLayerWindowToken"), "setVisibility", false, false);
Object mMiuiFreeFormGestureController = getObjectField(
getObjectField(
getObjectField(
Expand All @@ -59,15 +203,16 @@ protected void before(MethodHookParam param) throws Throwable {
getObjectField(mMiuiFreeFormGestureController,
"mGestureListener"),
"mGestureAnimator");
callMethod(getObjectField(mffas, "mLastIconLayerWindowToken"), "setVisibility", false);
callMethod(mGestureAnimator, "hideStack", mffas);
callMethod(mGestureAnimator, "applyTransaction");
}
}
}
);
);*/

findAndHookMethod("com.android.server.wm.MiuiFreeFormGestureController"
, "moveTaskToFront",
findAndHookMethod("com.android.server.wm.MiuiFreeFormGestureController",
"moveTaskToFront",
"com.android.server.wm.MiuiFreeFormActivityStack",
new HookAction() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public void init() {
new HookAction() {
@Override
protected void before(MethodHookParam param) {
// logE(tag, "kkkk: " + param.args[0] + " 2: " + param.args[1]);
// logE(tag, "kkkk: " + param.args[0] + " 2: " + param.args[1]);
}
}
);
Expand All @@ -24,7 +24,7 @@ protected void before(MethodHookParam param) {
new HookAction() {
@Override
protected void before(MethodHookParam param) {
// logE(tag, "ttt1: " + param.args[0] + " 2: " + param.args[1]);
// logE(tag, "ttt1: " + param.args[0] + " 2: " + param.args[1]);
}
}
);
Expand All @@ -34,8 +34,8 @@ protected void before(MethodHookParam param) {
new HookAction() {
@Override
protected void before(MethodHookParam param) {
// param.setResult(true);
// logE(tag, "ppp1: " + param.args[0] + " 2: " + param.args[1]);
// param.setResult(true);
// logE(tag, "ppp1: " + param.args[0] + " 2: " + param.args[1]);
}
}
);
Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ android.useAndroidX=true
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
android.nonTransitiveRClass=true
android.injected.testOnly=false

0 comments on commit 7bba903

Please sign in to comment.