From 6c5c3a0e6a0223723429e44cbe6d12d9d5430aec Mon Sep 17 00:00:00 2001 From: DHD2280 Date: Sat, 14 Dec 2024 20:00:38 +0100 Subject: [PATCH] Move ScreenShotRunnable class Signed-off-by: DHD2280 --- .../systemui/navbar/GestureNavbarManager.java | 58 ++--------------- .../xposed/utils/ScreenShotRunnable.java | 62 +++++++++++++++++++ 2 files changed, 66 insertions(+), 54 deletions(-) create mode 100644 app/src/main/java/it/dhd/oxygencustomizer/xposed/utils/ScreenShotRunnable.java diff --git a/app/src/main/java/it/dhd/oxygencustomizer/xposed/hooks/systemui/navbar/GestureNavbarManager.java b/app/src/main/java/it/dhd/oxygencustomizer/xposed/hooks/systemui/navbar/GestureNavbarManager.java index 245bc84e..eebff026 100644 --- a/app/src/main/java/it/dhd/oxygencustomizer/xposed/hooks/systemui/navbar/GestureNavbarManager.java +++ b/app/src/main/java/it/dhd/oxygencustomizer/xposed/hooks/systemui/navbar/GestureNavbarManager.java @@ -52,6 +52,7 @@ import it.dhd.oxygencustomizer.xposed.XPLauncher; import it.dhd.oxygencustomizer.xposed.XposedMods; import it.dhd.oxygencustomizer.xposed.utils.DrawableConverter; +import it.dhd.oxygencustomizer.xposed.utils.ScreenShotRunnable; import it.dhd.oxygencustomizer.xposed.utils.SystemUtils; public class GestureNavbarManager extends XposedMods { @@ -143,7 +144,7 @@ public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Th SideGestureNavView = findClass("com.oplusos.systemui.navigationbar.gesture.sidegesture.SideGestureNavView", lpparam.classLoader); // OOS 13 } - Class CentralSurfacesImpl = findClass("com.android.systemui.statusbar.phone.CentralSurfacesImpl", lpparam.classLoader); + Class CentralSurfacesImpl = findClass("com.android.systemui.statusbar.CommandQueue", lpparam.classLoader); hookAllConstructors(CentralSurfacesImpl, new XC_MethodHook() { @Override protected void afterHookedMethod(MethodHookParam param) throws Throwable { @@ -467,58 +468,6 @@ private void killForegroundApp() { }); } - public final class ScreenShotRunnable implements Runnable { - public final Context context; - public final String relationId; - public final String screenshotSource; - public final long startTime; - - public ScreenShotRunnable(String str, Context context, long j, String str2) { - this.screenshotSource = str; - this.context = context; - this.startTime = j; - this.relationId = str2; - } - - @Override - public void run() { - takeScreenshot(this.screenshotSource); - } - - public final void takeScreenshot(String str) { - Class OplusLongshotUtils = null; - try { - Context otherAppContext = context.createPackageContext("com.oplus.screenshot", Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY); - ClassLoader classLoader = otherAppContext.getClassLoader(); - OplusLongshotUtils = Class.forName("com.oplus.screenshot.OplusLongshotUtils", false, classLoader); - } catch (Exception e) { - log(e); - } - if (OplusLongshotUtils == null) return; - Method getScreenshotManagerMethod = null; - Object screenshotManager = null; - try { - getScreenshotManagerMethod = OplusLongshotUtils.getMethod("getScreenshotManager", Context.class); - screenshotManager = getScreenshotManagerMethod.invoke(null, context); - } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { - log(e); - } - - if (screenshotManager != null) { - Bundle bundle = new Bundle(); - bundle.putString("screenshot_source", str); - bundle.putString("screenshot_relation_id", this.relationId); - bundle.putLong("screenshot_start_time", this.startTime); - bundle.putBoolean("statusbar_visible", false); - bundle.putBoolean("navigationbar_visible", false); - bundle.putBoolean("global_action_visible", false); - bundle.putBoolean("screenshot_orientation", this.context.getResources().getConfiguration().orientation == 2); - callMethod(screenshotManager, "takeScreenshot", bundle); - } - } - } - - private void takeScreenshot() { new Handler(Looper.getMainLooper()).postDelayed( new ScreenShotRunnable("systemQuickTileScreenshotIn", mContext, SystemClock.uptimeMillis(), UUID.randomUUID().toString().replace("-", "")), 750L); @@ -543,7 +492,8 @@ private void toggleNotifications() { if (mCentralSurfacesImpl == null) return; try { - new Handler(Looper.getMainLooper()).post(() -> callMethod(mCentralSurfacesImpl, "togglePanel")); +// new Handler(Looper.getMainLooper()).post(() -> ); + callMethod(mCentralSurfacesImpl, "togglePanel"); } catch (Throwable t) { log(t); } diff --git a/app/src/main/java/it/dhd/oxygencustomizer/xposed/utils/ScreenShotRunnable.java b/app/src/main/java/it/dhd/oxygencustomizer/xposed/utils/ScreenShotRunnable.java new file mode 100644 index 00000000..c4e08a99 --- /dev/null +++ b/app/src/main/java/it/dhd/oxygencustomizer/xposed/utils/ScreenShotRunnable.java @@ -0,0 +1,62 @@ +package it.dhd.oxygencustomizer.xposed.utils; + +import static de.robv.android.xposed.XposedHelpers.callMethod; + +import android.content.Context; +import android.os.Bundle; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import de.robv.android.xposed.XposedBridge; + +public final class ScreenShotRunnable implements Runnable { + public final Context context; + public final String relationId; + public final String screenshotSource; + public final long startTime; + + public ScreenShotRunnable(String str, Context context, long j, String str2) { + this.screenshotSource = str; + this.context = context; + this.startTime = j; + this.relationId = str2; + } + + @Override + public void run() { + takeScreenshot(this.screenshotSource); + } + + public void takeScreenshot(String str) { + Class OplusLongshotUtils = null; + try { + Context otherAppContext = context.createPackageContext("com.oplus.screenshot", Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY); + ClassLoader classLoader = otherAppContext.getClassLoader(); + OplusLongshotUtils = Class.forName("com.oplus.screenshot.OplusLongshotUtils", false, classLoader); + } catch (Exception e) { + XposedBridge.log(e); + } + if (OplusLongshotUtils == null) return; + Method getScreenshotManagerMethod = null; + Object screenshotManager = null; + try { + getScreenshotManagerMethod = OplusLongshotUtils.getMethod("getScreenshotManager", Context.class); + screenshotManager = getScreenshotManagerMethod.invoke(null, context); + } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { + XposedBridge.log(e); + } + + if (screenshotManager != null) { + Bundle bundle = new Bundle(); + bundle.putString("screenshot_source", str); + bundle.putString("screenshot_relation_id", this.relationId); + bundle.putLong("screenshot_start_time", this.startTime); + bundle.putBoolean("statusbar_visible", false); + bundle.putBoolean("navigationbar_visible", false); + bundle.putBoolean("global_action_visible", false); + bundle.putBoolean("screenshot_orientation", this.context.getResources().getConfiguration().orientation == 2); + callMethod(screenshotManager, "takeScreenshot", bundle); + } + } +}