Skip to content

Commit

Permalink
Move ScreenShotRunnable class
Browse files Browse the repository at this point in the history
Signed-off-by: DHD2280 <[email protected]>
  • Loading branch information
DHD2280 committed Dec 14, 2024
1 parent 2c10749 commit 6c5c3a0
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
}

0 comments on commit 6c5c3a0

Please sign in to comment.