Skip to content

Commit

Permalink
新增 系统界面-通知与控制中心-扩展通知菜单 & 优化 日志输出
Browse files Browse the repository at this point in the history
from CustoMIUIzer
  • Loading branch information
Sevtinge committed Nov 2, 2023
1 parent 7432a6b commit 7180524
Show file tree
Hide file tree
Showing 12 changed files with 217 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.FlashLight;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.GmsTile;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.MuteVisibleNotifications;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.NotificationRowMenu;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.NotificationWeather;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.NotificationWeatherNew;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.NotificationWeatherOld;
Expand Down Expand Up @@ -210,6 +211,7 @@ public void handleLoadPackage() {
initHook(new AutoCollapse(), mPrefsMap.getBoolean("system_ui_control_auto_close"));
initHook(RedirectToNotificationChannelSetting.INSTANCE, mPrefsMap.getBoolean("system_ui_control_center_redirect_notice"));
initHook(ControlCenterStyle.INSTANCE, mPrefsMap.getBoolean("system_control_center_unlock_old"));
initHook(new NotificationRowMenu(), mPrefsMap.getBoolean("system_ui_control_center_notifrowmenu"));

// Actions
initHook(new StatusBarActions());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package com.sevtinge.hyperceiler.module.hook.systemui.controlcenter;

import android.app.ActivityManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.UserHandle;
import android.util.TypedValue;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.sevtinge.hyperceiler.R;
import com.sevtinge.hyperceiler.module.base.BaseHook;
import com.sevtinge.hyperceiler.utils.Helpers;

import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.function.Consumer;

import de.robv.android.xposed.XposedHelpers;

public class NotificationRowMenu extends BaseHook {
@Override
public void init() {
int appInfoIconResId = mResHook.addResource("ic_appinfo", R.drawable.ic_appinfo12);
int forceCloseIconResId = mResHook.addResource("ic_forceclose", R.drawable.ic_forceclose12);
int openInFwIconResId = mResHook.addResource("ic_openinfw", R.drawable.ic_openinfw);
int appInfoDescId = mResHook.addResource("miui_notification_menu_appinfo_title", R.string.system_notifrowmenu_appinfo);
int forceCloseDescId = mResHook.addResource("miui_notification_menu_forceclose_title", R.string.system_notifrowmenu_forceclose);
int openInFwDescId = mResHook.addResource("miui_notification_menu_openinfw_title", R.string.system_notifrowmenu_openinfw);
mResHook.setDensityReplacement("com.android.systemui", "dimen", "notification_menu_icon_padding", 0);
mResHook.setDensityReplacement("com.android.systemui", "dimen", "miui_notification_modal_menu_margin_left_right", 3);
mResHook.setResReplacement("com.android.systemui", "drawable", "miui_notification_menu_ic_bg_active", R.drawable.miui_notification_menu_ic_bg_active);
mResHook.setResReplacement("com.android.systemui", "drawable", "miui_notification_menu_ic_bg_inactive", R.drawable.miui_notification_menu_ic_bg_inactive);

Class<?> MiuiNotificationMenuItem = findClass("com.android.systemui.statusbar.notification.row.MiuiNotificationMenuRow.MiuiNotificationMenuItem", lpparam.classLoader);
findAndHookMethod("com.android.systemui.statusbar.notification.row.MiuiNotificationMenuRow", "createMenuViews", boolean.class, boolean.class, new MethodHook() {
@Override
@SuppressWarnings("unchecked")
protected void after(final MethodHookParam param) throws Throwable {
Context mContext = (Context) XposedHelpers.getObjectField(param.thisObject, "mContext");
ArrayList<Object> mMenuItems = (ArrayList<Object>)XposedHelpers.getObjectField(param.thisObject, "mMenuItems");

Object infoBtn = null;
Object forceCloseBtn = null;
Object openFwBtn = null;
Constructor MenuItem = MiuiNotificationMenuItem.getConstructors()[0];
try {
infoBtn = MenuItem.newInstance(param.thisObject, mContext, appInfoDescId, null, appInfoIconResId);
forceCloseBtn = MenuItem.newInstance(param.thisObject, mContext, forceCloseDescId, null, forceCloseIconResId);
openFwBtn = MenuItem.newInstance(param.thisObject, mContext, openInFwDescId, null, openInFwIconResId);
} catch (Throwable t1) {
logW(TAG, "com.android.systemui", t1);
}
if (infoBtn == null || forceCloseBtn == null || openFwBtn == null) return;
Object notification = XposedHelpers.getObjectField(param.thisObject, "mSbn");
Object expandNotifyRow = XposedHelpers.getObjectField(param.thisObject, "mParent");
mMenuItems.add(infoBtn);
mMenuItems.add(forceCloseBtn);
mMenuItems.add(openFwBtn);
XposedHelpers.setObjectField(param.thisObject, "mMenuItems", mMenuItems);
int menuMargin = (int) XposedHelpers.getObjectField(param.thisObject, "mMenuMargin");
LinearLayout mMenuContainer = (LinearLayout)XposedHelpers.getObjectField(param.thisObject, "mMenuContainer");
View mInfoBtn = (View) XposedHelpers.callMethod(infoBtn, "getMenuView");
View mForceCloseBtn = (View) XposedHelpers.callMethod(forceCloseBtn, "getMenuView");
View mOpenFwBtn = (View) XposedHelpers.callMethod(openFwBtn, "getMenuView");

View.OnClickListener itemClick = new View.OnClickListener() {
@Override
public void onClick(View view) {
if (view == null) return;
String pkgName = (String)XposedHelpers.callMethod(notification, "getPackageName");
int uid = (int)XposedHelpers.callMethod(notification, "getAppUid");
int user = 0;
try {
user = (int)XposedHelpers.callStaticMethod(UserHandle.class, "getUserId", uid);
} catch (Throwable t) {
logW(TAG, "com.android.systemui", t);
}

if (view == mInfoBtn) {
Helpers.openAppInfo(mContext, pkgName, user);
mContext.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
} else if (view == mForceCloseBtn) {
ActivityManager am = (ActivityManager)mContext.getSystemService(Context.ACTIVITY_SERVICE);
if (user != 0)
XposedHelpers.callMethod(am, "forceStopPackageAsUser", pkgName, user);
else
XposedHelpers.callMethod(am, "forceStopPackage", pkgName);
try {
CharSequence appName = mContext.getPackageManager().getApplicationLabel(mContext.getPackageManager().getApplicationInfo(pkgName, 0));
//Toast.makeText(mContext, Helpers.getModuleRes(mContext).getString(R.string.force_closed, appName), Toast.LENGTH_SHORT).show();
} catch (Throwable ignore) {}
}
else if (view == mOpenFwBtn) {
Class<?> Dependency = findClass("com.android.systemui.Dependency", lpparam.classLoader);
Object AppMiniWindowManager = XposedHelpers.callStaticMethod(Dependency, "get", findClassIfExists("com.android.systemui.statusbar.notification.policy.AppMiniWindowManager", lpparam.classLoader));
String miniWindowPkg = (String) XposedHelpers.callMethod(expandNotifyRow, "getMiniWindowTargetPkg");
PendingIntent notifyIntent = (PendingIntent) XposedHelpers.callMethod(expandNotifyRow, "getPendingIntent");
String ModalControllerForDep = "com.android.systemui.statusbar.notification.modal.ModalController";
Object ModalController = XposedHelpers.callStaticMethod(Dependency, "get", findClass(ModalControllerForDep, lpparam.classLoader));
XposedHelpers.callMethod(ModalController, "animExitModelCollapsePanels");
XposedHelpers.callMethod(AppMiniWindowManager, "launchMiniWindowActivity", miniWindowPkg, notifyIntent);
// mContext.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
}
}
};
mInfoBtn.setOnClickListener(itemClick);
mForceCloseBtn.setOnClickListener(itemClick);
mOpenFwBtn.setOnClickListener(itemClick);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(-2, -2);
layoutParams.leftMargin = menuMargin;
layoutParams.rightMargin = menuMargin;
mMenuContainer.addView(mInfoBtn, layoutParams);
mMenuContainer.addView(mForceCloseBtn, layoutParams);
mMenuContainer.addView(mOpenFwBtn, layoutParams);
int menuWidth = (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
52,
mContext.getResources().getDisplayMetrics()
);
int titleId = mContext.getResources().getIdentifier("modal_menu_title", "id", lpparam.packageName);
mMenuItems.forEach(new Consumer() {
@Override
public void accept(Object obj) {
View menuView = (View) XposedHelpers.callMethod(obj, "getMenuView");
((TextView) menuView.findViewById(titleId)).setMaxWidth(menuWidth);
}
});
}
});
}
}
33 changes: 29 additions & 4 deletions app/src/main/java/com/sevtinge/hyperceiler/utils/Helpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import static com.sevtinge.hyperceiler.utils.log.AndroidLogUtils.LogD;
import static com.sevtinge.hyperceiler.utils.log.AndroidLogUtils.LogI;
import static com.sevtinge.hyperceiler.utils.log.XposedLogUtils.logE;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ActivityOptions;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.ContentObserver;
Expand All @@ -21,6 +23,7 @@
import android.net.Uri;
import android.os.Environment;
import android.os.Handler;
import android.os.UserHandle;
import android.util.LruCache;
import android.widget.TextView;

Expand Down Expand Up @@ -316,6 +319,28 @@ public void onChange(String name, boolean defValue) {
}
}

public static void openAppInfo(Context context, String pkg, int user) {
try {
Intent intent = new Intent("miui.intent.action.APP_MANAGER_APPLICATION_DETAIL");
intent.setPackage("com.miui.securitycenter");
intent.putExtra("package_name", pkg);
if (user != 0) intent.putExtra("miui.intent.extra.USER_ID", user);
context.startActivity(intent);
} catch (Throwable t) {
try {
Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
intent.setData(Uri.parse("package:" + pkg));
if (user != 0)
XposedHelpers.callMethod(context, "startActivityAsUser", intent, XposedHelpers.newInstance(UserHandle.class, user));
else
context.startActivity(intent);
} catch (Throwable t2) {
logE(TAG, "openAppInfo" + t2);
}
}
}

@SuppressWarnings("unchecked")
public static Set<String> getSharedStringSetPref(Context context, String name) {
Uri uri = stringSetPrefToUri(name);
Expand Down Expand Up @@ -412,10 +437,10 @@ public static String getPackageVersionName(XC_LoadPackage.LoadPackageParam lppar
File apkPath = new File(lpparam.appInfo.sourceDir);
Object pkg = XposedHelpers.callMethod(parser, "parsePackage", apkPath, 0);
String versionName = (String) XposedHelpers.getObjectField(pkg, "mVersionName");
XposedLogUtils.logI("getPackageVersionName", lpparam + " versionName is " + versionName);
//XposedLogUtils.logI("getPackageVersionName", lpparam.packageName + " versionName is " + versionName);
return versionName;
} catch (Throwable e) {
XposedLogUtils.logW("getPackageVersionName", e);
//XposedLogUtils.logW("getPackageVersionName", e);
return "null";
}
}
Expand All @@ -427,10 +452,10 @@ public static int getPackageVersionCode(XC_LoadPackage.LoadPackageParam lpparam)
File apkPath = new File(lpparam.appInfo.sourceDir);
Object pkg = XposedHelpers.callMethod(parser, "parsePackage", apkPath, 0);
int versionCode = XposedHelpers.getIntField(pkg, "mVersionCode");
XposedLogUtils.logI("getPackageVersionCode", lpparam + " versionCode is " + versionCode);
//XposedLogUtils.logI("getPackageVersionCode", lpparam.packageName + " versionCode is " + versionCode);
return versionCode;
} catch (Throwable e) {
XposedLogUtils.logW("getPackageVersionCode", e);
//XposedLogUtils.logW("getPackageVersionCode", e);
return -1;
}
}
Expand Down
Loading

0 comments on commit 7180524

Please sign in to comment.