Initial implementation of logging metrics for bugreport.

This change logs the following user actions:

  - Interactive bug report initiated from power menu.
  - Full bug report initiated from power menu.
  - Bug report canceled using system notification.
  - Bug report details screen open using system notification.
  - Additional Bug report screen shot taken using system notification.
  - User changed bug report name using the details screen.
  - User changed bug report title using the details screen.
  - User changed bug report description using the details screen.
  - Changes made on bug report details screen were saved by user.
  - Changes made on bug report details screen were canceled by user.

BUG: 26759986
Change-Id: I1aae98b87a4dea66a1030a024dd799b97c25dd6d
diff --git a/packages/Shell/src/com/android/shell/BugreportProgressService.java b/packages/Shell/src/com/android/shell/BugreportProgressService.java
index 9926ae5..d8b0571c 100644
--- a/packages/Shell/src/com/android/shell/BugreportProgressService.java
+++ b/packages/Shell/src/com/android/shell/BugreportProgressService.java
@@ -41,6 +41,8 @@
 import libcore.io.Streams;
 
 import com.android.internal.annotations.VisibleForTesting;
+import com.android.internal.logging.MetricsLogger;
+import com.android.internal.logging.MetricsProto.MetricsEvent;
 import com.google.android.collect.Lists;
 
 import android.accounts.Account;
@@ -506,6 +508,7 @@
      * Cancels a bugreport upon user's request.
      */
     private void cancel(int id) {
+        MetricsLogger.action(this, MetricsEvent.ACTION_BUGREPORT_NOTIFICATION_ACTION_CANCEL);
         Log.v(TAG, "cancel: ID=" + id);
         final BugreportInfo info = getInfo(id);
         if (info != null && !info.finished) {
@@ -582,6 +585,7 @@
      * change its values.
      */
     private void launchBugreportInfoDialog(int id) {
+        MetricsLogger.action(this, MetricsEvent.ACTION_BUGREPORT_NOTIFICATION_ACTION_DETAILS);
         // Copy values so it doesn't lock mProcesses while UI is being updated
         final String name, title, description;
         final BugreportInfo info = getInfo(id);
@@ -610,6 +614,7 @@
      * upon receiving a {@link #INTENT_BUGREPORT_STARTED}.
      */
     private void takeScreenshot(int id, boolean delayed) {
+        MetricsLogger.action(this, MetricsEvent.ACTION_BUGREPORT_NOTIFICATION_ACTION_SCREENSHOT);
         if (getInfo(id) == null) {
             // Most likely am killed Shell before user tapped the notification. Since system might
             // be too busy anwyays, it's better to ignore the notification and switch back to the
@@ -859,6 +864,7 @@
      * intent, but issuing a warning dialog the first time.
      */
     private void shareBugreport(int id, BugreportInfo sharedInfo) {
+        MetricsLogger.action(this, MetricsEvent.ACTION_BUGREPORT_NOTIFICATION_ACTION_SHARE);
         BugreportInfo info = getInfo(id);
         if (info == null) {
             // Service was terminated but notification persisted
@@ -1139,9 +1145,16 @@
         if (info == null) {
             return;
         }
+        if (title != null && !title.equals(info.title)) {
+            MetricsLogger.action(this, MetricsEvent.ACTION_BUGREPORT_DETAILS_TITLE_CHANGED);
+        }
         info.title = title;
+        if (description != null && !description.equals(info.description)) {
+            MetricsLogger.action(this, MetricsEvent.ACTION_BUGREPORT_DETAILS_DESCRIPTION_CHANGED);
+        }
         info.description = description;
         if (name != null && !name.equals(info.name)) {
+            MetricsLogger.action(this, MetricsEvent.ACTION_BUGREPORT_DETAILS_NAME_CHANGED);
             info.name = name;
             updateProgress(info);
         }
@@ -1229,7 +1242,7 @@
         /**
          * Sets its internal state and displays the dialog.
          */
-        private void initialize(Context context, BugreportInfo info) {
+        private void initialize(final Context context, BugreportInfo info) {
             // First initializes singleton.
             if (mDialog == null) {
                 @SuppressLint("InflateParams")
@@ -1263,6 +1276,8 @@
                                     @Override
                                     public void onClick(DialogInterface dialog, int id)
                                     {
+                                        MetricsLogger.action(context,
+                                                MetricsEvent.ACTION_BUGREPORT_DETAILS_CANCELED);
                                         if (!mTempName.equals(mSavedName)) {
                                             // Must restore dumpstate's name since it was changed
                                             // before user clicked OK.
@@ -1307,6 +1322,7 @@
 
                     @Override
                     public void onClick(View view) {
+                        MetricsLogger.action(context, MetricsEvent.ACTION_BUGREPORT_DETAILS_SAVED);
                         sanitizeName();
                         final String name = mInfoName.getText().toString();
                         final String title = mInfoTitle.getText().toString();
diff --git a/proto/src/metrics_constants.proto b/proto/src/metrics_constants.proto
index 3f3f851..cd31b17 100644
--- a/proto/src/metrics_constants.proto
+++ b/proto/src/metrics_constants.proto
@@ -369,5 +369,44 @@
     // Logged when the user saves a modification to notification importance. Negative numbers
     // indicate the user lowered the importance; positive means they increased it.
     ACTION_SAVE_IMPORTANCE = 291;
+
+    // Interactive bug report initiated from power menu.
+    ACTION_BUGREPORT_FROM_POWER_MENU_INTERACTIVE = 292;
+
+    // Full bug report initiated from power menu.
+    ACTION_BUGREPORT_FROM_POWER_MENU_FULL = 293;
+
+    // Interactive bug report initiated from Settings.
+    ACTION_BUGREPORT_FROM_SETTINGS_INTERACTIVE = 294;
+
+    // Full bug report initiated from Settings.
+    ACTION_BUGREPORT_FROM_SETTINGS_FULL = 295;
+
+    // Bug report canceled using system notification.
+    ACTION_BUGREPORT_NOTIFICATION_ACTION_CANCEL = 296;
+
+    // Bug report details screen open using system notification.
+    ACTION_BUGREPORT_NOTIFICATION_ACTION_DETAILS = 297;
+
+    // Additional Bug report screen shot taken using system notification.
+    ACTION_BUGREPORT_NOTIFICATION_ACTION_SCREENSHOT = 298;
+
+    // Bug report shared by user using system notification.
+    ACTION_BUGREPORT_NOTIFICATION_ACTION_SHARE = 299;
+
+    // User changed bug report name using the details screen.
+    ACTION_BUGREPORT_DETAILS_NAME_CHANGED = 300;
+
+    // User changed bug report title using the details screen.
+    ACTION_BUGREPORT_DETAILS_TITLE_CHANGED = 301;
+
+    // User changed bug report description using the details screen.
+    ACTION_BUGREPORT_DETAILS_DESCRIPTION_CHANGED = 302;
+
+    // Changes made on bug report details screen were saved by user.
+    ACTION_BUGREPORT_DETAILS_SAVED = 303;
+
+    // Changes made on bug report details screen were canceled by user.
+    ACTION_BUGREPORT_DETAILS_CANCELED = 304;
   }
 }
diff --git a/services/core/java/com/android/server/policy/GlobalActions.java b/services/core/java/com/android/server/policy/GlobalActions.java
index a0f20aa..5615998 100644
--- a/services/core/java/com/android/server/policy/GlobalActions.java
+++ b/services/core/java/com/android/server/policy/GlobalActions.java
@@ -388,6 +388,8 @@
                 public void run() {
                     try {
                         // Take an "interactive" bugreport.
+                        MetricsLogger.visible(this,
+                                MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_INTERACTIVE);
                         ActivityManagerNative.getDefault().requestBugReport(
                                 ActivityManager.BUGREPORT_OPTION_INTERACTIVE);
                     } catch (RemoteException e) {
@@ -405,6 +407,8 @@
             }
             try {
                 // Take a "full" bugreport.
+                MetricsLogger.visible(this,
+                        MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_FULL);
                 ActivityManagerNative.getDefault().requestBugReport(
                         ActivityManager.BUGREPORT_OPTION_FULL);
             } catch (RemoteException e) {