Skip to content

Commit

Permalink
Merge branch 'canary' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
siavash79 committed Aug 23, 2022
2 parents 3a7d7cc + ecd4206 commit d1b2a61
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 52 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ This module is designed based on AOSP source code. What does it mean? it means t

- Android 12: Compatible
- Android 12.1 (12L): Compatible
- Andriod 12.1 beta: Compatible
- Android 13: NOT Compatible

- Android 13: Compatible


**Prerequisites:**
- Compatible Roms (see above)
Expand Down Expand Up @@ -120,6 +119,8 @@ Automated install/updates: only through in-app updater - updates will NOT appear
- @nmayorga092 Spanish
- @vitalitk Ukrainian
- @siavash79 Persian
- @abalam1980 Dutch
- @trinhloivn Vietnamese

**Brought to you by:**
@siavash79 & @ElTifo
2 changes: 1 addition & 1 deletion app/src/main/java/sh/siava/AOSPMods/AOSPMods.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Th

if(lpparam.packageName.equals(SYSTEM_UI_PACKAGE) && false) {
log("------------");
Helpers.dumpClass("com.android.systemui.navigationbar.NavigationBar", lpparam.classLoader);
Helpers.dumpClass("com.android.systemui.settings.brightness.BrightnessController", lpparam.classLoader);
log("------------");
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/sh/siava/AOSPMods/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ private void updateVisibililty(SharedPreferences sharedPreferences) {

findPreference("BSThickTrackOverlay").setVisible(!sharedPreferences.getBoolean("QSBrightnessDisabled", false) && showOverlays);
findPreference("BrightnessSlierOnBottom").setVisible(!sharedPreferences.getBoolean("QSBrightnessDisabled", false));
findPreference("QQSBrightnessEnabled").setVisible(!sharedPreferences.getBoolean("QSBrightnessDisabled", false) && Build.VERSION.SDK_INT < 33);
findPreference("QQSBrightnessEnabled").setVisible(!sharedPreferences.getBoolean("QSBrightnessDisabled", false));
findPreference("QSFooterText").setVisible(sharedPreferences.getBoolean("QSFooterMod", false));
findPreference("QSPulldownPercent").setSummary(sharedPreferences.getInt("QSPulldownPercent", 25) + "%");
findPreference("dualToneQSEnabled").setVisible(sharedPreferences.getBoolean("LightQSPanel", false));
Expand Down
141 changes: 109 additions & 32 deletions app/src/main/java/sh/siava/AOSPMods/systemui/BrightnessSlider.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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.callStaticMethod;
import static de.robv.android.xposed.XposedHelpers.findClass;
import static de.robv.android.xposed.XposedHelpers.findClassIfExists;
import static de.robv.android.xposed.XposedHelpers.getIntField;
Expand All @@ -12,20 +13,26 @@

import android.content.Context;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Build;
import android.provider.Settings;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;

import java.util.ArrayList;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.callbacks.XC_LoadPackage;
import sh.siava.AOSPMods.AOSPMods;
import sh.siava.AOSPMods.XposedModPack;

@SuppressWarnings("RedundantThrows")
@SuppressWarnings({"RedundantThrows", "unchecked", "rawtypes"})
public class BrightnessSlider extends XposedModPack {
private static final String listenPackage = AOSPMods.SYSTEM_UI_PACKAGE;

Expand All @@ -44,6 +51,9 @@ public class BrightnessSlider extends XposedModPack {
private final ArrayList<Integer> collectedFields = new ArrayList<>();
private Object mBrightnessController;
private Object mBrightnessMirrorHandler;
private View QQSBrightnessSliderView;
static Class<?> BrightnessControllerClass = null;
static Class<?> DejankUtilsClass = null;

public BrightnessSlider(Context context) { super(context); }

Expand Down Expand Up @@ -88,29 +98,6 @@ public void updatePrefs(String... Key) {
@Override
public boolean listensTo(String packageName) { return listenPackage.equals(packageName); }

private void makeQQSBrightness(Class<?> BrightnessMirrorHandlerClass) throws Throwable {
ViewGroup quickQSPanel = (ViewGroup) getObjectField(QQSPC, "mView");

Object mBrightnessSliderController = callMethod(brightnessSliderFactory, "create", mContext, quickQSPanel);

View QQSBrightnessSliderView = (View) getObjectField(mBrightnessSliderController, "mView");
setBrightnessView(quickQSPanel, QQSBrightnessSliderView, true);

//mBrightnessController = BrightnessControllerClass.getConstructors()[0].newInstance(getObjectField(brightnessControllerFactory, "mContext"), mBrightnessSliderController, getObjectField(brightnessControllerFactory, "mBroadcastDispatcher"),getObjectField(brightnessControllerFactory, "mBackgroundHandler"));
mBrightnessController = callMethod(brightnessControllerFactory, "create", mBrightnessSliderController);

mBrightnessMirrorHandler = BrightnessMirrorHandlerClass.getConstructors()[0].newInstance(mBrightnessController);

callMethod(mBrightnessController, "checkRestrictionAndSetEnabled");

callMethod(mTunerService, "addTunable", quickQSPanel, QS_SHOW_BRIGHTNESS);
callMethod(mBrightnessMirrorHandler, "onQsPanelAttached");
callMethod(mBrightnessController, "registerCallbacks");
callMethod(mBrightnessMirrorHandler, "setController", mBrightnessMirrorController);
callMethod(mBrightnessSliderController, "init");
}


@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
if(!BrightnessHookEnabled || !listenPackage.equals(lpparam.packageName)) //master switch
Expand All @@ -121,6 +108,10 @@ public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Th
Class<?> QuickQSPanelControllerClass = findClass("com.android.systemui.qs.QuickQSPanelController", lpparam.classLoader);
Class<?> QSPanelControllerBaseClass = findClass("com.android.systemui.qs.QSPanelControllerBase", lpparam.classLoader);
Class<?> CentralSurfacesImplClass = findClassIfExists("com.android.systemui.statusbar.phone.CentralSurfacesImpl", lpparam.classLoader);
Class<?> StatusBarClass = findClassIfExists("com.android.systemui.statusbar.phone.StatusBar", lpparam.classLoader);
DejankUtilsClass = findClass("com.android.systemui.DejankUtils", lpparam.classLoader);

BrightnessControllerClass = findClass("com.android.systemui.settings.brightness.BrightnessController", lpparam.classLoader);

if(CentralSurfacesImplClass != null)
{
Expand All @@ -130,16 +121,26 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
new Thread(() -> {
try {
while (mBrightnessMirrorController == null) {
Thread.currentThread().wait(500);
//noinspection BusyWait
Thread.sleep(500);
mBrightnessMirrorController = getObjectField(param.thisObject, "mBrightnessMirrorController");
}
dataCollected(2, BrightnessMirrorHandlerClass);
} catch (Throwable ignored) {
}
} catch (Throwable ignored) {}
}).start();
}
});
}
else
{
hookAllMethods(StatusBarClass, "makeStatusBarView", new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
mBrightnessMirrorController = getObjectField(param.thisObject, "mBrightnessMirrorController");
dataCollected(2, BrightnessMirrorHandlerClass);
}
});
}

hookAllMethods(QSPanelControllerBaseClass, "setTiles", new XC_MethodHook() {
@Override
Expand All @@ -156,15 +157,15 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {

int indexCorrection = (Build.VERSION.SDK_INT == 33)
? 0
: 1;
: 1; //A12

brightnessControllerFactory = param.args[11 + indexCorrection];
brightnessSliderFactory = param.args[12 + indexCorrection];
mTunerService = getObjectField(param.thisObject, "mTunerService");

dataCollected(0, BrightnessMirrorHandlerClass);
Object mView = getObjectField(param.thisObject,"mView");
setBrightnessView((ViewGroup) mView, (View) getObjectField(mView, "mBrightnessView"), false);

setQSVisibility();
}
});

Expand Down Expand Up @@ -228,6 +229,7 @@ private void setSliderMargins(View slider) {

private void setBrightnessView(ViewGroup o, @NonNull View view, boolean isQQS) { //Classloader can't find the method by reflection
View mBrightnessView = (View) getObjectField(o,"mBrightnessView");

if (mBrightnessView != null) {
o.removeView(mBrightnessView);
setObjectField(o, "mMovableContentStartIndex", getIntField(o, "mMovableContentStartIndex") - 1);
Expand Down Expand Up @@ -268,10 +270,8 @@ private void setQSVisibility(){
private void setQQSVisibility() {
if(mBrightnessMirrorHandler == null) return; //Brightness slider isn't made
ViewGroup QuickQSPanel = (ViewGroup) getObjectField(QQSPC, "mView");
View QQSBrightnessSliderView = (View) getObjectField(QuickQSPanel, "mBrightnessView");

if(QuickQSPanel == null || QQSBrightnessSliderView == null) return;

QuickQSPanel.post(() -> {
try {
if (QQSBrightnessEnabled) {
Expand All @@ -282,4 +282,81 @@ private void setQQSVisibility() {
} catch (Exception ignored) {}
});
}

private void makeQQSBrightness(Class<?> BrightnessMirrorHandlerClass) throws Throwable {
ViewGroup quickQSPanel = (ViewGroup) getObjectField(QQSPC, "mView");

Object mBrightnessSliderController = callMethod(brightnessSliderFactory, "create", mContext, quickQSPanel);

QQSBrightnessSliderView = (View) getObjectField(mBrightnessSliderController, "mView");

mBrightnessController = BrightnessControllerClass.getConstructors()[0].newInstance(getObjectField(brightnessControllerFactory, "mContext"), mBrightnessSliderController, getObjectField(brightnessControllerFactory, "mBroadcastDispatcher"),getObjectField(brightnessControllerFactory, "mBackgroundHandler"));
//mBrightnessController = callMethod(brightnessControllerFactory, "create", mBrightnessSliderController);

mBrightnessMirrorHandler = BrightnessMirrorHandlerClass.getConstructors()[0].newInstance(mBrightnessController);

addTunable(mTunerService, quickQSPanel, QS_SHOW_BRIGHTNESS);
setController(mBrightnessMirrorHandler, mBrightnessMirrorController);
registerCallbacks(mBrightnessController);
callMethod(mBrightnessSliderController, "init");

// callMethod(mBrightnessController, "checkRestrictionAndSetEnabled"); //apparently not needed

onQsPanelAttached(mBrightnessMirrorHandler);

setQQSVisibility();
}

private static void onQsPanelAttached(Object mBrightnessMirrorHandler)
{
Object mirrorController = getObjectField(mBrightnessMirrorHandler, "mirrorController");
if(mirrorController != null)
{
callMethod(mirrorController, "addCallback", getObjectField(mBrightnessMirrorHandler, "brightnessMirrorListener"));
}
}

private static void registerCallbacks(Object mBrightnessController)
{
callMethod(getObjectField(mBrightnessController, "mBackgroundHandler"), "post", getObjectField(mBrightnessController, "mStartListeningRunnable"));
}

private static void setController(Object mirrorHandler, Object controller) {
Object mirrorController = getObjectField(mirrorHandler, "mirrorController");
if(mirrorController != null) {
callMethod(mirrorController, "removeCallback", getObjectField(mirrorHandler, "brightnessMirrorListener"));
}
setObjectField(mirrorHandler, "mirrorController", controller);
if(controller != null) {
Object listener = getObjectField(mirrorHandler, "brightnessMirrorListener"); //BrightnessMirrorController#Addcalback
if(listener != null)
{
@SuppressWarnings("rawtypes") ArraySet mBrightnessMirrorListeners = (ArraySet) getObjectField(controller, "mBrightnessMirrorListeners");
//noinspection unchecked
mBrightnessMirrorListeners.add(listener);
}
callMethod(getObjectField(mirrorHandler, "brightnessController"), "setMirror", controller);
}
}

private void addTunable(Object service, Object tunable, @SuppressWarnings("SameParameterValue") String key) {
ConcurrentHashMap<String, Set<Object>> mTunableLookup = (ConcurrentHashMap<String, Set<Object>>) getObjectField(service, "mTunableLookup");
if (!mTunableLookup.containsKey(key)) {
mTunableLookup.put(key, new ArraySet());
}
mTunableLookup.get(key).add(tunable);

Uri uri = Settings.Secure.getUriFor(key);

ArrayMap<Uri, String> mListeningUris = (ArrayMap<Uri, String>) getObjectField(service, "mListeningUris");
if (!mListeningUris.containsKey(uri)) {
mListeningUris.put(uri, key);
callMethod(getObjectField(service, "mContentResolver"), "registerContentObserver", uri, false, getObjectField(service, "mObserver"), getObjectField(service, "mCurrentUser"));
}
// Send the first state.
Runnable runnable = () -> callStaticMethod(Settings.Secure.class,
"getStringForUser", getObjectField(service, "mContentResolver"), key, getObjectField(service, "mCurrentUser"));
String value = (String) callStaticMethod(DejankUtilsClass, "whitelistIpcs", runnable);
callMethod(tunable, "onTuningChanged", key, value);
}
}
31 changes: 16 additions & 15 deletions app/src/main/java/sh/siava/AOSPMods/systemui/QSTileGrid.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static de.robv.android.xposed.XposedBridge.hookAllMethods;
import static de.robv.android.xposed.XposedHelpers.callStaticMethod;
import static de.robv.android.xposed.XposedHelpers.findClass;
import static de.robv.android.xposed.XposedHelpers.findClassIfExists;
import static de.robv.android.xposed.XposedHelpers.getObjectField;
import static de.robv.android.xposed.XposedHelpers.setObjectField;
import static sh.siava.AOSPMods.ResourceManager.resparams;
Expand Down Expand Up @@ -81,26 +82,26 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
}
});

Class<?> QRCodeScannerTileClass = findClassIfExists("com.android.systemui.qs.tiles.QRCodeScannerTile", lpparam.classLoader);

if(QRCodeScannerTileClass != null) {
hookAllMethods(QRCodeScannerTileClass, "handleUpdateState", new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
if (!QRTileInactiveColor) return;

if (getObjectField(param.args[0], "state").equals(STATE_ACTIVE)) {
setObjectField(param.args[0], "state", STATE_INACTIVE);
}
}
});
}

hookAllConstructors(QSTileViewImplClass, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
try {
Class<?> QRCodeScannerTileClass = findClass("com.android.systemui.qs.tiles.QRCodeScannerTile", lpparam.classLoader);

hookAllMethods(QRCodeScannerTileClass, "handleUpdateState", new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
if(!QRTileInactiveColor) return;

if(getObjectField(param.args[0], "state").equals(STATE_ACTIVE))
{
setObjectField(param.args[0], "state", STATE_INACTIVE);
}
}
});

if (labelSize == null) { //we need initial font sizes

if(Build.VERSION.SDK_INT == 33) {
callStaticMethod(FontSizeUtilsClass,
"updateFontSize",
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values-pt/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,9 @@
<string name="qs_tile_label_size">Tamanho do texto</string>
<string name="qs_tile_secondary_label_size">Tamanho do texto secundário</string>
<string name="toggle_dark_apply">"(ative o tema escuro para aplicar)"</string>
<string name="qs_leveled_flashlight_summary">Requer hardware compatível</string>
<string name="qs_leveled_flashlight_title">Atalho da lanterna com controlo de brilho</string>
<string name="qs_footer_text_value">Inserir texto personalizado</string>
<string name="qs_flashlight_level_global_title">Aplicar nível da lanterna globalmente</string>
<string name="qs_qr_tile_inactive_title">Inverter cores do atalho QR</string>
</resources>

0 comments on commit d1b2a61

Please sign in to comment.