Skip to content

Commit

Permalink
AdvancedReboot: Fixed positioning with find my device.
Browse files Browse the repository at this point in the history
Signed-off-by: DHD2280 <[email protected]>
  • Loading branch information
DHD2280 committed Jan 23, 2025
1 parent dc964b7 commit eb02d47
Showing 1 changed file with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
package it.dhd.oxygencustomizer.xposed.hooks.systemui;

import static android.content.Context.RECEIVER_EXPORTED;
import static de.robv.android.xposed.XposedBridge.hookAllMethods;
import static de.robv.android.xposed.XposedHelpers.callMethod;
import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;
import static de.robv.android.xposed.XposedHelpers.findClass;
import static de.robv.android.xposed.XposedHelpers.getObjectField;
import static it.dhd.oxygencustomizer.BuildConfig.APPLICATION_ID;
import static it.dhd.oxygencustomizer.utils.Constants.Packages.SYSTEM_UI;
import static it.dhd.oxygencustomizer.xposed.ResourceManager.modRes;
import static it.dhd.oxygencustomizer.xposed.XPrefs.Xprefs;
import static it.dhd.oxygencustomizer.xposed.utils.ViewHelper.dp2px;

import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Color;
Expand All @@ -25,17 +18,12 @@
import android.graphics.drawable.Drawable;
import android.hardware.biometrics.BiometricManager;
import android.view.MotionEvent;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;

import androidx.core.content.res.ResourcesCompat;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.callbacks.XC_LoadPackage;
import it.dhd.oxygencustomizer.R;
import it.dhd.oxygencustomizer.utils.Constants;
import it.dhd.oxygencustomizer.xposed.XPLauncher;
import it.dhd.oxygencustomizer.xposed.XposedMods;
import it.dhd.oxygencustomizer.xposed.utils.toolkit.ReflectedClass;

Expand All @@ -49,6 +37,8 @@ public class AdvancedReboot extends XposedMods {
private int centerX;
private int centerY;
private int radius;
private Object mNearbyManager = null;
private boolean isFinderActive = false;

public AdvancedReboot(Context context) {
super(context);
Expand All @@ -66,6 +56,17 @@ public void updatePrefs(String... Key) {
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
if (!listenPackage.equals(lpparam.packageName)) return;

ReflectedClass ShutdownUi = ReflectedClass.of("com.android.systemui.globalactions.ShutdownUi");
ShutdownUi
.after("getShutdownDialogContent")
.run(param -> {
try {
mNearbyManager = getObjectField(param.thisObject, "mNearbyManager");
int powerOffFindingMode = (int) callMethod(mNearbyManager, "getPoweredOffFindingMode");
isFinderActive = !(boolean) param.args[1] && powerOffFindingMode == 2;
} catch (Throwable ignored) {}
});

ReflectedClass ShutdownView = ReflectedClass.of(
"com.oplus.systemui.shutdown.OplusShutdownView" /* OOS14-15 */,
"com.oplusos.systemui.controls.OplusShutdownView" /* OOS13 */);
Expand All @@ -76,7 +77,7 @@ public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Th
if (showAdvancedReboot) {
drawAdvancedReboot((Canvas) param.args[0], param.thisObject);
}
});
});

ShutdownView
.after("onTouchEvent")
Expand Down Expand Up @@ -137,6 +138,9 @@ private void drawAdvancedReboot(Canvas canvas, Object param) {

centerX = viewWidth / 2;
centerY = radius + dp2px(mContext, 50);
if (isFinderActive) {
centerY += dp2px(mContext, 50);
}

canvas.drawCircle(centerX, centerY, radius, buttonPaint);

Expand All @@ -157,7 +161,6 @@ private void drawAdvancedReboot(Canvas canvas, Object param) {
canvas.drawText(buttonText, textX, textY, textPaint);
}


@Override
public boolean listensTo(String packageName) {
return listenPackage.equals(packageName);
Expand Down

0 comments on commit eb02d47

Please sign in to comment.