Skip to content

Commit

Permalink
fix: audio visualizer
Browse files Browse the repository at this point in the history
  • Loading branch information
MonwF committed Jul 12, 2022
1 parent 2ec9c69 commit d30963f
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 91 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ android {
minSdkVersion 30
//noinspection OldTargetApi,ExpiredTargetSdkVersion
targetSdkVersion 31
versionCode 13
versionName "3.2.1.2207011"
versionCode 14
versionName "3.2.1.2207012"
resConfigs 'ru-rRU', 'zh-rCN'
ndk { abiFilters "arm64-v8a" }
}
Expand Down
79 changes: 28 additions & 51 deletions app/src/main/java/name/mikanoshi/customiuizer/mods/Controls.java
Original file line number Diff line number Diff line change
Expand Up @@ -588,33 +588,33 @@ public static void FingerprintEventsHook(LoadPackageParam lpparam) {
Helpers.hookAllMethods("com.android.server.policy.BaseMiuiPhoneWindowManager", lpparam.classLoader, "initInternal", new MethodHook() {
@Override
protected void after(MethodHookParam param) throws Throwable {
Context mContext = (Context)XposedHelpers.getObjectField(param.thisObject, "mContext");
Handler mHandler = (Handler)XposedHelpers.getObjectField(param.thisObject, "mHandler");

new Helpers.SharedPrefObserver(mContext, mHandler) {
@Override
public void onChange(Uri uri) {
try {
String type = uri.getPathSegments().get(1);
String key = uri.getPathSegments().get(2);
if (!key.contains("pref_key_controls_fingerprint")) return;
Context mContext = (Context)XposedHelpers.getObjectField(param.thisObject, "mContext");
Handler mHandler = (Handler)XposedHelpers.getObjectField(param.thisObject, "mHandler");

switch (type) {
case "string":
MainModule.mPrefs.put(key, Helpers.getSharedStringPref(mContext, key, ""));
break;
case "integer":
MainModule.mPrefs.put(key, Helpers.getSharedIntPref(mContext, key, 1));
break;
case "boolean":
MainModule.mPrefs.put(key, Helpers.getSharedBoolPref(mContext, key, false));
break;
}
} catch (Throwable t) {
XposedBridge.log(t);
new Helpers.SharedPrefObserver(mContext, mHandler) {
@Override
public void onChange(Uri uri) {
try {
String type = uri.getPathSegments().get(1);
String key = uri.getPathSegments().get(2);
if (!key.contains("pref_key_controls_fingerprint")) return;

switch (type) {
case "string":
MainModule.mPrefs.put(key, Helpers.getSharedStringPref(mContext, key, ""));
break;
case "integer":
MainModule.mPrefs.put(key, Helpers.getSharedIntPref(mContext, key, 1));
break;
case "boolean":
MainModule.mPrefs.put(key, Helpers.getSharedBoolPref(mContext, key, false));
break;
}
} catch (Throwable t) {
XposedBridge.log(t);
}
};
}
};
}
});

Expand Down Expand Up @@ -721,30 +721,20 @@ protected void after(MethodHookParam param) throws Throwable {
Helpers.hookAllMethods(fpService, lpparam.classLoader, "startClient", new MethodHook() {
@Override
protected void before(MethodHookParam param) throws Throwable {
Context mContext = (Context)XposedHelpers.getObjectField(param.thisObject, "mContext");
Settings.System.putInt(mContext.getContentResolver(), "is_fingerprint_active", 1);
Context mContext = (Context)XposedHelpers.getObjectField(param.thisObject, "mContext");
Settings.System.putInt(mContext.getContentResolver(), "is_fingerprint_active", 1);
}
});

Helpers.hookAllMethods(fpService, lpparam.classLoader, "removeClient", new MethodHook() {
@Override
protected void after(MethodHookParam param) throws Throwable {
Context mContext = (Context)XposedHelpers.getObjectField(param.thisObject, "mContext");
Settings.System.putInt(mContext.getContentResolver(), "is_fingerprint_active", 0);
Context mContext = (Context)XposedHelpers.getObjectField(param.thisObject, "mContext");
Settings.System.putInt(mContext.getContentResolver(), "is_fingerprint_active", 0);
}
});
}

// public static void FingerprintHook(LoadPackageParam lpparam) {
// Helpers.findAndHookMethod("com.android.server.devicepolicy.DevicePolicyManagerService", lpparam.classLoader, "reportSuccessfulFingerprintAttempt", int.class, new MethodHook() {
// @Override
// protected void before(MethodHookParam param) throws Throwable {
// Helpers.log("reportSuccessfulFingerprintAttempt");
// Context mContext = (Context)XposedHelpers.getObjectField(param.thisObject, "mContext");
// }
// });
// }

@SuppressLint("StaticFieldLeak")
private static Context basePWMContext;
private static Object basePWMObject;
Expand Down Expand Up @@ -1013,19 +1003,6 @@ protected void before(final MethodHookParam param) throws Throwable {
}
});

Helpers.findAndHookMethod("com.android.systemui.assist.AssistManager", lpparam.classLoader, "startAssist", Bundle.class, new MethodHook() {
@Override
protected void before(final MethodHookParam param) throws Throwable {
Bundle bundle = (Bundle)param.args[0];
if (bundle == null || bundle.getInt("triggered_by", 0) != 83 || bundle.getInt("invocation_type", 0) != 1) return;
Context mContext = (Context)XposedHelpers.getObjectField(param.thisObject, "mContext");
if (GlobalActions.handleAction(mContext, "pref_key_controls_fsg_assist")) {
Helpers.performLightVibration(mContext);
param.setResult(null);
}
}
});

Helpers.hookAllConstructors("com.android.systemui.assist.ui.DefaultUiController", lpparam.classLoader, new MethodHook() {
@Override
protected void after(MethodHookParam param) throws Throwable {
Expand Down
77 changes: 42 additions & 35 deletions app/src/main/java/name/mikanoshi/customiuizer/mods/System.java
Original file line number Diff line number Diff line change
Expand Up @@ -3498,7 +3498,8 @@ public static void AudioVisualizerHook(LoadPackageParam lpparam) {
Helpers.hookAllMethods("com.android.systemui.statusbar.phone.StatusBar", lpparam.classLoader, "makeStatusBarView", new MethodHook() {
@Override
protected void after(final MethodHookParam param) throws Throwable {
ViewGroup mNotificationPanel = (ViewGroup)XposedHelpers.getObjectField(param.thisObject, "mNotificationPanel");
Object viewController = XposedHelpers.getObjectField(param.thisObject, "mNotificationPanelViewController");
FrameLayout mNotificationPanel = (FrameLayout) XposedHelpers.getObjectField(viewController, "mView");
if (mNotificationPanel == null) {
Helpers.log("AudioVisualizerHook", "Cannot find mNotificationPanel");
return;
Expand All @@ -3524,14 +3525,21 @@ protected void after(final MethodHookParam param) throws Throwable {
}
});

Helpers.findAndHookMethod("com.android.systemui.statusbar.phone.StatusBar", lpparam.classLoader, "onScreenTurnedOff", new MethodHook() {
Helpers.findAndHookMethod("com.android.systemui.statusbar.phone.ScrimController", lpparam.classLoader, "onScreenTurnedOff", new MethodHook() {
@Override
protected void after(final MethodHookParam param) throws Throwable {
if (audioViz != null) audioViz.updateScreenOn(false);
}
});

Helpers.findAndHookMethod("com.android.systemui.statusbar.phone.StatusBar", lpparam.classLoader, "updateKeyguardState", boolean.class, boolean.class, new MethodHook() {
Helpers.findAndHookMethod("com.android.systemui.statusbar.phone.ScrimController", lpparam.classLoader, "onScreenTurnedOn", new MethodHook() {
@Override
protected void after(final MethodHookParam param) throws Throwable {
if (audioViz != null) audioViz.updateScreenOn(true);
}
});

Helpers.findAndHookMethod("com.android.systemui.statusbar.phone.StatusBar", lpparam.classLoader, "updateKeyguardState", new MethodHook() {
@Override
protected void after(final MethodHookParam param) throws Throwable {
Object mStatusBarKeyguardViewManager = XposedHelpers.getObjectField(param.thisObject, "mStatusBarKeyguardViewManager");
Expand All @@ -3544,46 +3552,46 @@ protected void after(final MethodHookParam param) throws Throwable {
}
});

Helpers.findAndHookMethod("com.android.systemui.statusbar.phone.NotificationPanelView", lpparam.classLoader, "onExpandingFinished", new MethodHook() {
Helpers.hookAllMethods("com.android.systemui.statusbar.phone.StatusBar", lpparam.classLoader, "setPanelExpanded", new MethodHook() {
@Override
protected void after(final MethodHookParam param) throws Throwable {
boolean isNotificationPanelExpandedNew = XposedHelpers.getBooleanField(param.thisObject, "mPanelExpanded");
if (isNotificationPanelExpanded != isNotificationPanelExpandedNew) {
isNotificationPanelExpanded = isNotificationPanelExpandedNew;
updateAudioVisualizerState((Context)XposedHelpers.getObjectField(param.thisObject, "mContext"));
}
boolean isNotificationPanelExpandedNew = XposedHelpers.getBooleanField(param.thisObject, "mPanelExpanded");
if (isNotificationPanelExpanded != isNotificationPanelExpandedNew) {
isNotificationPanelExpanded = isNotificationPanelExpandedNew;
updateAudioVisualizerState((Context)XposedHelpers.getObjectField(param.thisObject, "mContext"));
}
}
});

Helpers.findAndHookMethod("com.android.systemui.statusbar.phone.StatusBar", lpparam.classLoader, "updateMediaMetaData", boolean.class, boolean.class, new MethodHook() {
Helpers.findAndHookMethod("com.android.systemui.statusbar.NotificationMediaManager", lpparam.classLoader, "updateMediaMetaData", boolean.class, boolean.class, new MethodHook() {
@Override
protected void before(final MethodHookParam param) throws Throwable {
if (audioViz == null) return;
Context mContext = (Context)XposedHelpers.getObjectField(param.thisObject, "mContext");
PowerManager powerMgr = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE);
boolean isScreenOn = powerMgr.isInteractive();
if (!isScreenOn) {
audioViz.updateScreenOn(false);
return;
} else audioViz.isScreenOn = true;
if (audioViz == null) return;
Context mContext = (Context)XposedHelpers.getObjectField(param.thisObject, "mContext");
PowerManager powerMgr = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE);
boolean isScreenOn = powerMgr.isInteractive();
if (!isScreenOn) {
audioViz.updateScreenOn(false);
return;
} else audioViz.isScreenOn = true;

MediaMetadata mMediaMetadata = (MediaMetadata)XposedHelpers.getObjectField(param.thisObject, "mMediaMetadata");
Bitmap art = null;
if (mMediaMetadata != null) {
art = mMediaMetadata.getBitmap(MediaMetadata.METADATA_KEY_ART);
if (art == null) art = mMediaMetadata.getBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART);
if (art == null) art = mMediaMetadata.getBitmap(MediaMetadata.METADATA_KEY_DISPLAY_ICON);
}
if (art == null) {
WallpaperManager wallpaperMgr = WallpaperManager.getInstance(mContext);
Drawable wallpaperDrawable = wallpaperMgr.getDrawable();
if (wallpaperDrawable instanceof BitmapDrawable)
art = ((BitmapDrawable)wallpaperDrawable).getBitmap();
}
MediaMetadata mMediaMetadata = (MediaMetadata)XposedHelpers.getObjectField(param.thisObject, "mMediaMetadata");
Bitmap art = null;
if (mMediaMetadata != null) {
art = mMediaMetadata.getBitmap(MediaMetadata.METADATA_KEY_ART);
if (art == null) art = mMediaMetadata.getBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART);
if (art == null) art = mMediaMetadata.getBitmap(MediaMetadata.METADATA_KEY_DISPLAY_ICON);
}
if (art == null) {
WallpaperManager wallpaperMgr = WallpaperManager.getInstance(mContext);
@SuppressLint("MissingPermission") Drawable wallpaperDrawable = wallpaperMgr.getDrawable();
if (wallpaperDrawable instanceof BitmapDrawable)
art = ((BitmapDrawable)wallpaperDrawable).getBitmap();
}

mMediaController = (MediaController)XposedHelpers.getObjectField(param.thisObject, "mMediaController");
updateAudioVisualizerState(mContext);
audioViz.updateMusicArt(art);
mMediaController = (MediaController)XposedHelpers.getObjectField(param.thisObject, "mMediaController");
updateAudioVisualizerState(mContext);
audioViz.updateMusicArt(art);
}
});
}
Expand Down Expand Up @@ -7584,7 +7592,6 @@ public static void HideLockScreenStatusBarHook(LoadPackageParam lpparam) {
Helpers.hookAllMethods("com.android.systemui.statusbar.phone.StatusBar", lpparam.classLoader, "makeStatusBarView", new MethodHook() {
@Override
protected void after(final MethodHookParam param) throws Throwable {
XposedHelpers.getObjectField(param.thisObject, "mNotificationPanelViewController");
View mKeyguardStatusBar = (View) XposedHelpers.getObjectField(XposedHelpers.getObjectField(param.thisObject, "mNotificationPanelViewController"), "mKeyguardStatusBar");
mKeyguardStatusBar.setTranslationY(-999f);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
case "pref_key_controls_cat_fsg":
findPreference("pref_key_controls_fsg_horiz_apps").setOnPreferenceClickListener(openAppsEdit);
findPreference("pref_key_controls_fsg_assist").setOnPreferenceClickListener(openNavbarActions);

if (!Helpers.is12()) ((PreferenceEx)findPreference("pref_key_controls_fsg_assist")).setUnsupported(true);

break;
}
}
Expand Down

0 comments on commit d30963f

Please sign in to comment.