阅读:23373回复:1

Android系统默认关闭第三方App通知

楼主#
更多 发布于:2021-02-03 10:40
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index c1f9843..76888b0 100755
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -107,6 +107,7 @@ import android.app.ResourcesManager;
import android.app.admin.IDevicePolicyManager;
import android.app.admin.SecurityLog;
import android.app.backup.IBackupManager;
+import android.app.INotificationManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentResolver;
@@ -14308,7 +14309,11 @@ public class PackageManagerService extends IPackageManager.Stub {

            if (res.returnCode == PackageManager.INSTALL_SUCCEEDED) {
                prepareAppDataAfterInstallLIF(newPackage);
-
+                //Add by jackly for disable notification 2021.2.3
+                if("com.google.android.youtube.tv".equals(pkgName) || "com.google.android.youtube".equals(pkgName)){
+                    Slog.d("yu","-------New install pkg = " + pkgName);
+                    disableAppNotification(pkgName);
+                }

            } else {
                // Remove package from internal structures, but keep around any
                // data that might have already existed
@@ -14322,6 +14327,19 @@ public class PackageManagerService extends IPackageManager.Stub {
        Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
    }

+    //Add by jackly 2021.2.3
+    private void disableAppNotification(String packageName){
+        //NotificationManager mNotificationManager =(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
+        INotificationManager mNotificationManager = INotificationManager.Stub.asInterface(ServiceManager.getService(Context.NOTIFICATION_SERVICE));
+        try {
+            int uid = getPackageUid(packageName, 0, UserHandle.USER_SYSTEM);
+            Slog.i("yu","-----------------disableAppNotification: " + packageName + ", uid = " + uid);
+            mNotificationManager.setNotificationsEnabledForPackage(packageName, uid, false);
+        } catch (Exception e) {
+            Slog.e("yu", "--------------------disableAppNotification: " + e);
+        }
+    }
+

[url]http://190.lsal.cn/195/1329.gif?0728100424873[/url]
沙发#
发布于:2021-02-03 15:39
我现在把所有通知都干掉了,直接在notificationservice里改的

--- a/base/core/java/android/app/NotificationManager.java
+++ b/base/core/java/android/app/NotificationManager.java
@@ -343,7 +343,7 @@ public class NotificationManager {
      */
     public void notify(int id, Notification notification)
     {
-        notify(null, id, notification);
+        //notify(null, id, notification); do not show notification
     }


锁屏的通知改的相对复杂一点
游客

返回顶部