mirror of
https://github.com/gkd-kit/gkd.git
synced 2026-09-03 07:19:59 +08:00
fix: compat takeScreenshot for android-16.0.0_r4
This commit is contained in:
@@ -12,6 +12,7 @@ import android.os.RemoteException
|
||||
import android.view.Display.DEFAULT_DISPLAY
|
||||
import android.view.accessibility.AccessibilityEvent
|
||||
import android.window.ScreenCapture
|
||||
import android.window.ScreenCaptureInternal
|
||||
import androidx.annotation.RequiresApi
|
||||
import li.songe.gkd.util.AndroidTarget
|
||||
import rikka.shizuku.Shizuku
|
||||
@@ -192,6 +193,31 @@ class ProxyUiAutomationConnection : IUiAutomationConnection.Stub() {
|
||||
return true
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
|
||||
override fun takeScreenshot(
|
||||
crop: Rect,
|
||||
listener: ScreenCaptureInternal.ScreenCaptureListener,
|
||||
displayId: Int,
|
||||
): Boolean {
|
||||
synchronized(mLock) {
|
||||
throwIfCalledByNotTrustedUidLocked()
|
||||
throwIfShutdownLocked()
|
||||
throwIfNotConnectedLocked()
|
||||
}
|
||||
val identity = clearCallingIdentity()
|
||||
try {
|
||||
val captureArgs = ScreenCaptureInternal.CaptureArgs.Builder()
|
||||
.setSourceCrop(crop)
|
||||
.build()
|
||||
mWindowManager.captureDisplay(displayId, captureArgs, listener)
|
||||
} catch (re: RemoteException) {
|
||||
throw re.rethrowAsRuntimeException()
|
||||
} finally {
|
||||
restoreCallingIdentity(identity)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private fun registerUiTestAutomationServiceLocked(
|
||||
client: IAccessibilityServiceClient,
|
||||
userId: Int,
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.os.Binder;
|
||||
import android.os.Build;
|
||||
import android.os.IBinder;
|
||||
import android.window.ScreenCapture;
|
||||
import android.window.ScreenCaptureInternal;
|
||||
|
||||
import androidx.annotation.DeprecatedSinceApi;
|
||||
import androidx.annotation.RequiresApi;
|
||||
@@ -45,4 +46,8 @@ public interface IUiAutomationConnection {
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.VANILLA_ICE_CREAM)
|
||||
boolean takeScreenshot(Rect crop, ScreenCapture.ScreenCaptureListener listener, int displayId);
|
||||
|
||||
// android-16.0.0_r4
|
||||
@RequiresApi(Build.VERSION_CODES.VANILLA_ICE_CREAM)
|
||||
boolean takeScreenshot(Rect crop, ScreenCaptureInternal.ScreenCaptureListener listener, int displayId);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.os.Build;
|
||||
import android.os.IBinder;
|
||||
import android.os.IInterface;
|
||||
import android.window.ScreenCapture;
|
||||
import android.window.ScreenCaptureInternal;
|
||||
|
||||
import androidx.annotation.DeprecatedSinceApi;
|
||||
import androidx.annotation.RequiresApi;
|
||||
@@ -41,4 +42,7 @@ public interface IWindowManager extends IInterface {
|
||||
@RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
|
||||
void captureDisplay(int displayId, ScreenCapture.CaptureArgs captureArgs, ScreenCapture.ScreenCaptureListener listener);
|
||||
|
||||
// android-16.0.0_r4
|
||||
@RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
|
||||
void captureDisplay(int displayId, ScreenCaptureInternal.CaptureArgs captureArgs, ScreenCaptureInternal.ScreenCaptureListener listener);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package android.window;
|
||||
|
||||
import android.graphics.Rect;
|
||||
import android.os.Build;
|
||||
|
||||
import androidx.annotation.RequiresApi;
|
||||
|
||||
/**
|
||||
* @version android-16.0.0_r4
|
||||
* @noinspection unused
|
||||
*/
|
||||
@RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
|
||||
public class ScreenCaptureInternal {
|
||||
public static class ScreenCaptureListener {
|
||||
}
|
||||
|
||||
public static class CaptureArgs {
|
||||
public static class Builder<T extends ScreenCaptureInternal.CaptureArgs.Builder<T>> {
|
||||
public ScreenCaptureInternal.CaptureArgs build() {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
public T setSourceCrop(Rect sourceCrop) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user