Merge "SysUI/NoMan: Log clicks on notification buttons" into lmp-mr1-dev

This commit is contained in:
Christoph Studer
2014-10-24 14:29:19 +00:00
committed by Android (Google) Code Review
6 changed files with 65 additions and 0 deletions

View File

@@ -43,6 +43,7 @@ interface IStatusBarService
void onPanelRevealed();
void onPanelHidden();
void onNotificationClick(String key);
void onNotificationActionClick(String key, int actionIndex);
void onNotificationError(String pkg, String tag, int id,
int uid, int initialPid, String message, int userId);
void onClearAllNotifications(int userId);

View File

@@ -69,6 +69,7 @@ import android.view.View;
import android.view.ViewAnimationUtils;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewParent;
import android.view.ViewStub;
import android.view.WindowManager;
import android.view.WindowManagerGlobal;
@@ -266,6 +267,7 @@ public abstract class BaseStatusBar extends SystemUI implements
if (DEBUG) {
Log.v(TAG, "Notification click handler invoked for intent: " + pendingIntent);
}
logActionClick(view);
// The intent we are sending is for the application, which
// won't have permission to immediately start an activity after
// the user switches to home. We know it is safe to do at this
@@ -308,6 +310,37 @@ public abstract class BaseStatusBar extends SystemUI implements
}
}
private void logActionClick(View view) {
ViewParent parent = view.getParent();
String key = getNotificationKeyForParent(parent);
if (key == null) {
Log.w(TAG, "Couldn't determine notification for click.");
return;
}
int index = -1;
// If this is a default template, determine the index of the button.
if (view.getId() == com.android.internal.R.id.action0 &&
parent != null && parent instanceof ViewGroup) {
ViewGroup actionGroup = (ViewGroup) parent;
index = actionGroup.indexOfChild(view);
}
try {
mBarService.onNotificationActionClick(key, index);
} catch (RemoteException e) {
// Ignore
}
}
private String getNotificationKeyForParent(ViewParent parent) {
while (parent != null) {
if (parent instanceof ExpandableNotificationRow) {
return ((ExpandableNotificationRow) parent).getStatusBarNotification().getKey();
}
parent = parent.getParent();
}
return null;
}
private boolean superOnClickHandler(View view, PendingIntent pendingIntent,
Intent fillInIntent) {
return super.onClickHandler(view, pendingIntent, fillInIntent);

View File

@@ -69,6 +69,8 @@ option java_package com.android.server
27511 notification_expansion (key|3),(user_action|1),(expanded|1)
# when a notification has been clicked
27520 notification_clicked (key|3)
# when a notification action button has been clicked
27521 notification_action_clicked (key|3),(action_index|1)
# ---------------------------
# Watchdog.java

View File

@@ -20,6 +20,7 @@ public interface NotificationDelegate {
void onSetDisabled(int status);
void onClearAll(int callingUid, int callingPid, int userId);
void onNotificationClick(int callingUid, int callingPid, String key);
void onNotificationActionClick(int callingUid, int callingPid, String key, int actionIndex);
void onNotificationClear(int callingUid, int callingPid,
String pkg, String tag, int id, int userId);
void onNotificationError(int callingUid, int callingPid,

View File

@@ -540,6 +540,20 @@ public class NotificationManagerService extends SystemService {
}
}
@Override
public void onNotificationActionClick(int callingUid, int callingPid, String key,
int actionIndex) {
synchronized (mNotificationList) {
EventLogTags.writeNotificationActionClicked(key, actionIndex);
NotificationRecord r = mNotificationsByKey.get(key);
if (r == null) {
Log.w(TAG, "No notification with key: " + key);
return;
}
// TODO: Log action click via UsageStats.
}
}
@Override
public void onNotificationClear(int callingUid, int callingPid,
String pkg, String tag, int id, int userId) {

View File

@@ -524,6 +524,20 @@ public class StatusBarManagerService extends IStatusBarService.Stub {
}
}
@Override
public void onNotificationActionClick(String key, int actionIndex) {
enforceStatusBarService();
final int callingUid = Binder.getCallingUid();
final int callingPid = Binder.getCallingPid();
long identity = Binder.clearCallingIdentity();
try {
mNotificationDelegate.onNotificationActionClick(callingUid, callingPid, key,
actionIndex);
} finally {
Binder.restoreCallingIdentity(identity);
}
}
@Override
public void onNotificationError(String pkg, String tag, int id,
int uid, int initialPid, String message, int userId) {