Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 03b87a2f authored by Christoph Studer's avatar Christoph Studer
Browse files

Log notification clicks

Emit notification_clicked log events when a notification
is clicked from SystemUI.

Also refactor the onNotificationClicked method to work with
a key instead of individual notification params.

Change-Id: Iffd15e95d46371b2ae7bfd00b2c348d9f4cf5d14
parent ff8dbe52
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ interface IStatusBarService
            out int[] switches, out List<IBinder> binders);
    void onPanelRevealed();
    void onPanelHidden();
    void onNotificationClick(String pkg, String tag, int id, int userId);
    void onNotificationClick(String key);
    void onNotificationError(String pkg, String tag, int id,
            int uid, int initialPid, String message, int userId);
    void onClearAllNotifications(int userId);
+11 −19
Original line number Diff line number Diff line
@@ -768,8 +768,8 @@ public abstract class BaseStatusBar extends SystemUI implements

        PendingIntent contentIntent = sbn.getNotification().contentIntent;
        if (contentIntent != null) {
            final View.OnClickListener listener = makeClicker(contentIntent,
                    sbn.getPackageName(), sbn.getTag(), sbn.getId(), isHeadsUp, sbn.getUserId());
            final View.OnClickListener listener = makeClicker(contentIntent, sbn.getKey(),
                    isHeadsUp);
            row.setOnClickListener(listener);
        } else {
            row.setOnClickListener(null);
@@ -879,27 +879,20 @@ public abstract class BaseStatusBar extends SystemUI implements
        return true;
    }

    public NotificationClicker makeClicker(PendingIntent intent, String pkg, String tag,
            int id, boolean forHun, int userId) {
        return new NotificationClicker(intent, pkg, tag, id, forHun, userId);
    public NotificationClicker makeClicker(PendingIntent intent, String notificationKey,
            boolean forHun) {
        return new NotificationClicker(intent, notificationKey, forHun);
    }

    protected class NotificationClicker implements View.OnClickListener {
        private PendingIntent mIntent;
        private String mPkg;
        private String mTag;
        private int mId;
        private final String mNotificationKey;
        private boolean mIsHeadsUp;
        private int mUserId;

        public NotificationClicker(PendingIntent intent, String pkg, String tag, int id,
                boolean forHun, int userId) {
        public NotificationClicker(PendingIntent intent, String notificationKey, boolean forHun) {
            mIntent = intent;
            mPkg = pkg;
            mTag = tag;
            mId = id;
            mNotificationKey = notificationKey;
            mIsHeadsUp = forHun;
            mUserId = userId;
        }

        public void onClick(View v) {
@@ -935,7 +928,7 @@ public abstract class BaseStatusBar extends SystemUI implements
                if (mIsHeadsUp) {
                    mHandler.sendEmptyMessage(MSG_HIDE_HEADS_UP);
                }
                mBarService.onNotificationClick(mPkg, mTag, mId, mUserId);
                mBarService.onNotificationClick(mNotificationKey);
            } catch (RemoteException ex) {
                // system process is dead if we're here.
            }
@@ -1338,9 +1331,8 @@ public abstract class BaseStatusBar extends SystemUI implements
        // update the contentIntent
        final PendingIntent contentIntent = notification.getNotification().contentIntent;
        if (contentIntent != null) {
            final View.OnClickListener listener = makeClicker(contentIntent,
                    notification.getPackageName(), notification.getTag(), notification.getId(),
                    isHeadsUp, notification.getUserId());
            final View.OnClickListener listener = makeClicker(contentIntent, notification.getKey(),
                    isHeadsUp);
            entry.row.setOnClickListener(listener);
        } else {
            entry.row.setOnClickListener(null);
+2 −0
Original line number Diff line number Diff line
@@ -65,6 +65,8 @@ option java_package com.android.server
27501 notification_panel_hidden
# when notifications are newly displayed on screen, or disappear from screen
27510 notification_visibility_changed (newlyVisibleKeys|3),(noLongerVisibleKeys|3)
# when a notification has been clicked
27520 notification_clicked (key|3)

# ---------------------------
# Watchdog.java
+1 −2
Original line number Diff line number Diff line
@@ -21,8 +21,7 @@ import android.os.IBinder;
public interface NotificationDelegate {
    void onSetDisabled(int status);
    void onClearAll(int callingUid, int callingPid, int userId);
    void onNotificationClick(int callingUid, int callingPid,
            String pkg, String tag, int id, int userId);
    void onNotificationClick(int callingUid, int callingPid, String key);
    void onNotificationClear(int callingUid, int callingPid,
            String pkg, String tag, int id, int userId);
    void onNotificationError(int callingUid, int callingPid,
+14 −4
Original line number Diff line number Diff line
@@ -602,10 +602,20 @@ public class NotificationManagerService extends SystemService {
        }

        @Override
        public void onNotificationClick(int callingUid, int callingPid,
                String pkg, String tag, int id, int userId) {
            cancelNotification(callingUid, callingPid, pkg, tag, id, Notification.FLAG_AUTO_CANCEL,
                    Notification.FLAG_FOREGROUND_SERVICE, false, userId, REASON_DELEGATE_CLICK, null);
        public void onNotificationClick(int callingUid, int callingPid, String key) {
            synchronized (mNotificationList) {
                EventLogTags.writeNotificationClicked(key);
                NotificationRecord r = mNotificationsByKey.get(key);
                if (r == null) {
                    Log.w(TAG, "No notification with key: " + key);
                    return;
                }
                StatusBarNotification sbn = r.sbn;
                cancelNotification(callingUid, callingPid, sbn.getPackageName(), sbn.getTag(),
                        sbn.getId(), Notification.FLAG_AUTO_CANCEL,
                        Notification.FLAG_FOREGROUND_SERVICE, false, r.getUserId(),
                        REASON_DELEGATE_CLICK, null);
            }
        }

        @Override
Loading