Skip to content

Commit

Permalink
CHANGELOG: Added remove USB Dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
DHD2280 committed May 20, 2024
1 parent 41c4767 commit b97417d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package it.dhd.oxygencustomizer.xposed.hooks.systemui;

import static de.robv.android.xposed.XposedBridge.hookAllConstructors;
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 de.robv.android.xposed.XposedHelpers.setBooleanField;
import static it.dhd.oxygencustomizer.xposed.XPrefs.Xprefs;

import android.content.Context;
Expand All @@ -17,8 +21,9 @@ public class MiscMods extends XposedMods {

private static final String listenPackage = Constants.Packages.SYSTEM_UI;

private boolean mHideRotationButton;
private boolean mHideRotationButton = false;
private View mRotationButton;
private boolean mRemoveUsb = false;

public MiscMods(Context context) {
super(context);
Expand All @@ -27,6 +32,7 @@ public MiscMods(Context context) {
@Override
public void updatePrefs(String... Key) {
mHideRotationButton = Xprefs.getBoolean("misc_remove_rotate_floating", false);
mRemoveUsb = Xprefs.getBoolean("remove_usb_dialog", false);

if (Key.length > 0 && Key[0].equals("misc_remove_rotate_floating")) {
if (mRotationButton != null) mRotationButton.setVisibility(mHideRotationButton ? View.GONE : View.VISIBLE);
Expand All @@ -37,14 +43,40 @@ public void updatePrefs(String... Key) {
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
if (!listenPackage.equals(lpparam.packageName)) return;

Class<?> FloatingRotationButton = findClass("com.android.systemui.shared.rotation.FloatingRotationButton", lpparam.classLoader);
hookAllConstructors(FloatingRotationButton, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
mRotationButton = (View) getObjectField(param.thisObject, "mKeyButtonView");
if (mHideRotationButton) mRotationButton.setVisibility(View.GONE);
}
});
try {
Class<?> FloatingRotationButton = findClass("com.android.systemui.shared.rotation.FloatingRotationButton", lpparam.classLoader);
hookAllConstructors(FloatingRotationButton, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
mRotationButton = (View) getObjectField(param.thisObject, "mKeyButtonView");
if (mHideRotationButton) mRotationButton.setVisibility(View.GONE);
}
});
} catch (Throwable ignored) {}

try {
Class<?> UsbService = findClass("com.oplus.systemui.usb.UsbService", lpparam.classLoader);
hookAllMethods(UsbService, "onUsbConnected", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (!mRemoveUsb) return;
Context c = (Context) param.args[0];
param.setResult(null);
callMethod(param.thisObject, "onUsbSelect", 1);
callMethod(param.thisObject, "updateAdbNotification", c);
callMethod(param.thisObject, "updateUsbNotification", c, 1);
callMethod(param.thisObject, "changeUsbConfig", c, 1);
}
});

findAndHookMethod(UsbService, "helpUpdateUsbNotification", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (!mRemoveUsb) return;
setBooleanField(param.thisObject, "mNeedShowUsbDialog", false);
}
});
} catch (Throwable ignored) {}

}

Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,10 @@
<string name="use_auth_for_advanced_reboot_summary">Require authentication to use advanced reboot options.</string>
<string name="advanced_reboot_hide_lockscreen">Hide in Lockscreen</string>
<string name="show_entry_settings_title">Show entry in Settings</string>
<string name="remove_usb_dialog">Remove USB Dialog</string>
<string name="remove_usb_dialog_summary">If enabled, the USB dialog will be hidden and MTP option will be chosen automatically.</string>

<!-- Screenshot Strings -->
<string name="screenshot">Screenshot</string>
<string name="screenshots_prefs">Screenshot Options</string>
<string name="disable_secure_screenshot">Disable FLAG_SECURE</string>
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/xml/misc_prefs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
android:summaryOn="@string/general_on"
android:summaryOff="@string/general_off"
app:iconSpaceReserved="false" />
<SwitchPreferenceCompat
android:defaultValue="false"
android:key="remove_usb_dialog"
android:title="@string/remove_usb_dialog"
android:summary="@string/remove_usb_dialog_summary"
app:iconSpaceReserved="false" />


<PreferenceCategory
app:iconSpaceReserved="false"
Expand Down

0 comments on commit b97417d

Please sign in to comment.