Fix android 14 crashes (#5620)

This commit is contained in:
Berke Emin Kabagöz
2025-09-28 04:21:02 +03:00
committed by GitHub
parent 40575a66a9
commit cb8b206a50
8 changed files with 97 additions and 9 deletions

View File

@@ -36,6 +36,7 @@ import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.graphics.Rect;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
@@ -53,6 +54,7 @@ import com.android.internal.app.IVoiceInteractionManagerService;
import com.android.systemui.shared.recents.model.Task;
import com.android.systemui.shared.recents.model.ThumbnailData;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
@@ -155,9 +157,24 @@ public class ActivityManagerWrapper {
public @NonNull ThumbnailData getTaskThumbnail(int taskId, boolean isLowResolution) {
TaskSnapshot snapshot = null;
try {
snapshot = getService().getTaskSnapshot(taskId, isLowResolution);
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
Method getTaskSnapshotMethod = getService().getClass().getMethod(
"getTaskSnapshot",
int.class, // taskId
boolean.class, // isLowResolution
boolean.class // isTranslucent (added in Android 14)
);
snapshot = (TaskSnapshot) getTaskSnapshotMethod.invoke(
getService(), taskId, isLowResolution, false);
} else {
snapshot = getService().getTaskSnapshot(taskId, isLowResolution);
}
} catch (RemoteException e) {
Log.w(TAG, "Failed to retrieve task snapshot", e);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
Log.e(TAG, "Failed to invoke getTaskSnapshot", e);
}
if (snapshot != null) {
return ThumbnailData.fromSnapshot(snapshot);

View File

@@ -20,6 +20,7 @@ import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.WindowManager.INPUT_CONSUMER_RECENTS_ANIMATION;
import android.os.Binder;
import android.os.Build;
import android.os.IBinder;
import android.os.Looper;
import android.os.RemoteException;
@@ -32,6 +33,8 @@ import android.view.InputEvent;
import android.view.WindowManagerGlobal;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/**
* Manages the input consumer that allows the SystemUI to directly receive input.
@@ -139,7 +142,14 @@ public class InputConsumerController {
if (mInputEventReceiver == null) {
final InputChannel inputChannel = new InputChannel();
try {
mWindowManager.destroyInputConsumer(mToken, DEFAULT_DISPLAY);
// Hook for Android P (9) to VANILLA_ICE_CREAM (15), where the method signature changed
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P
&& Build.VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
hookDestroyInputConsumer(mWindowManager);
} else {
mWindowManager.destroyInputConsumer(mToken, DEFAULT_DISPLAY);
}
mWindowManager.createInputConsumer(mToken, mName, DEFAULT_DISPLAY, inputChannel);
} catch (RemoteException e) {
Log.e(TAG, "Failed to create input consumer", e);
@@ -152,13 +162,36 @@ public class InputConsumerController {
}
}
/**
* IWindowManager @destroyInputConsumer reflection
*/
private void hookDestroyInputConsumer(IWindowManager mWindowManager) throws RemoteException {
try {
Class<?> iWindowManagerClass = Class.forName("android.view.IWindowManager");
Method destroyInputConsumerMethod = iWindowManagerClass.getMethod("destroyInputConsumer", String.class, int.class);
destroyInputConsumerMethod.invoke(mWindowManager, mName, DEFAULT_DISPLAY);
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException |
InvocationTargetException e) {
Log.e(TAG, "Failed to invoke destroyInputConsumer", e);
mWindowManager.destroyInputConsumer(mToken, DEFAULT_DISPLAY);
}
}
/**
* Unregisters the input consumer.
*/
public void unregisterInputConsumer() {
if (mInputEventReceiver != null) {
try {
mWindowManager.destroyInputConsumer(mToken, DEFAULT_DISPLAY);
// Hook for Android P (9) to VANILLA_ICE_CREAM (15), where the method signature changed
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P
&& Build.VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
hookDestroyInputConsumer(mWindowManager);
} else {
mWindowManager.destroyInputConsumer(mToken, DEFAULT_DISPLAY);
}
} catch (RemoteException e) {
Log.e(TAG, "Failed to destroy input consumer", e);
}

View File

@@ -16,6 +16,7 @@
package com.android.systemui.shared.system;
import android.os.Build;
import android.os.RemoteException;
import android.util.Log;
import android.view.IRecentsAnimationController;
@@ -26,6 +27,8 @@ import android.window.TaskSnapshot;
import com.android.internal.os.IResultReceiver;
import com.android.systemui.shared.recents.model.ThumbnailData;
import java.lang.reflect.Method;
public class RecentsAnimationControllerCompat {
private static final String TAG = RecentsAnimationControllerCompat.class.getSimpleName();
@@ -92,7 +95,24 @@ public class RecentsAnimationControllerCompat {
*/
public void finish(boolean toHome, boolean sendUserLeaveHint, IResultReceiver finishCb) {
try {
mAnimationController.finish(toHome, sendUserLeaveHint, finishCb);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
mAnimationController.finish(toHome, sendUserLeaveHint, finishCb);
} else {
try {
Method finishMethod = mAnimationController.getClass().getMethod(
"finish", boolean.class, boolean.class);
finishMethod.invoke(mAnimationController, toHome, sendUserLeaveHint);
if (finishCb != null) {
finishCb.send(0, null);
}
} catch (Exception e) {
Log.e(TAG, "Failed to finish recents animation via reflection", e);
if (finishCb != null) {
finishCb.send(0, null);
}
}
}
} catch (RemoteException e) {
Log.e(TAG, "Failed to finish recents animation", e);
try {