Skip to content

Conversation

@Nep-Timeline
Copy link
Contributor

ColorOS 15.0.1 通过系统框架fixSmallIcon方法替换通知图标为应用彩色图标, 通过Hook系统框架拦截此方法阻止 ColorOS 15.0.1 替换通知图标

@Nep-Timeline Nep-Timeline reopened this May 27, 2025
@fankes
Copy link
Owner

fankes commented May 28, 2025

它竟然加到系统框架里了吗

@Nep-Timeline
Copy link
Contributor Author

是的 他直接调用Notification.setSmallIcon覆盖图标了

@fankes
Copy link
Owner

fankes commented May 28, 2025

你可否看看这个方法有没有别的可能性 hook SystemUI 绕过,因为 hook 系统框架的代价有点高

@Nep-Timeline
Copy link
Contributor Author

你可否看看这个方法有没有别的可能性 hook SystemUI 绕过,因为 hook 系统框架的代价有点高

这不太行吧 他这个方法直接覆盖掉原本的SmallIcon

    private void fixSmallIcon(Notification notification, String pkg, String opPkg, boolean isExp) {
        Bundle notifExtras;
        if (notification == null || TextUtils.isEmpty(pkg)) {
            Slog.d(TAG, "fixSmallIcon: notification or pkg is null");
            return;
        }
        if (isExp || (notifExtras = notification.extras) == null) {
            return;
        }
        ApplicationInfo appInfo = (ApplicationInfo) notifExtras.getParcelable("android.appInfo", ApplicationInfo.class);
        if (appInfo == null) {
            Slog.d(TAG, "fixSmallIcon: appInfo is null");
            return;
        }
        if (NotificationInfoUtil.isAndroidPackage(pkg, appInfo) || NotificationInfoUtil.isSystemOrPlatformSignedApp(appInfo) || NotificationInfoUtil.isCommercialNotification(notification, opPkg) || isOplusAppUseSmallIcon(notification, pkg)) {
            return;
        }
        int appIconRes = appInfo.icon;
        if (appIconRes == 0) {
            Slog.d(TAG, "fixSmallIcon: Failed to get the app icon, no icon in appInfo");
            return;
        }
        Icon appIcon = Icon.createWithResource(pkg, appIconRes);
        if (appIcon == null) {
            return;
        }
        notifExtras.putBoolean(OPLUS_SMALLICON_USE_APP_ICON, true);
        notification.setSmallIcon(appIcon);
    }

@fankes
Copy link
Owner

fankes commented May 28, 2025

这个方法在哪里调用的

@Nep-Timeline
Copy link
Contributor Author

Nep-Timeline commented May 28, 2025

这个方法在哪里调用的

Android Services中通知管理服务(NotificationManagerService)的enqueueNotificationInternal方法内

@Nep-Timeline
Copy link
Contributor Author

Nep-Timeline commented May 28, 2025

https://cs.android.com/android/platform/superproject/main/+/main:frameworks/base/services/core/java/com/android/server/notification/NotificationManagerService.java;l=8058

        // Fix the notification as best we can.
        try {
            fixNotification(notification, pkg, tag, id, userId, notificationUid,
                    policy, stripUijFlag);
+           if (this.mNMSWrapper.getNMSExt() != null)
+               this.mNMSWrapper.getNMSExt().fixNotificationForOplus(notification, pkg, opPkg); // 此方法修改通知图标
        } catch (Exception e) {
            if (notification.isForegroundService()) {
                throw new SecurityException("Invalid FGS notification", e);
            }
            Slog.e(TAG, "Cannot fix notification", e);
            return false;
        }

@Nep-Timeline
Copy link
Contributor Author

ColorOS的行为比较的破坏原生逻辑 暂时不知道有什么别的办法

@fankes
Copy link
Owner

fankes commented May 28, 2025

有够过分的,hook 系统框架有行为变更重启手机的需求,代价比较高,我看看后面有没有什么解决方案,明天等我上班后再研究

@fankes fankes merged commit 492d0da into fankes:master May 29, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants