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

Commit e9377a7d authored by Michal Karpinski's avatar Michal Karpinski
Browse files

Remote bugreport notifications rework

Merging two notifications into one.

Bug: 27095707
Change-Id: Ib6582dabb7370f9b3b6e673b19ab43b70c73433a
parent 5db2f16f
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -2920,17 +2920,19 @@
    <string name="adb_active_notification_message">Touch to disable USB debugging.</string>

    <!-- Title of notification shown to ask for user consent for sharing a bugreport that was requested remotely by the IT administrator. -->
    <string name="share_remote_bugreport_notification_title">Share bug report with admin?</string>
    <string name="share_remote_bugreport_notification_title">Share bug report?</string>
    <!-- Title of notification shown to indicate that bug report is still being collected after sharing was accepted. -->
    <string name="sharing_remote_bugreport_notification_title">Sharing bug report</string>
    <!-- Message of notification shown to ask for user consent for sharing a bugreport that was requested remotely by the IT administrator. -->
    <string name="share_remote_bugreport_notification_message">Your IT admin requested a bug report to help troubleshoot</string>
    <string name="share_remote_bugreport_notification_message">Your IT admin requested a bug report to help troubleshoot this device. Apps and data may be shared. This may temporarily slow down your device.</string>
    <!-- Message of notification shown to ask for user consent for sharing a bugreport that was requested remotely by the IT administrator. -->
    <string name="share_finished_remote_bugreport_notification_message">Your IT admin requested a bug report to help troubleshoot this device. Apps and data may be shared.</string>
    <!-- Message of notification shown to shown to indicate that bug report is still being collected after sharing was accepted. -->
    <string name="sharing_remote_bugreport_notification_message">This may temporarily slow down your device</string>
    <!-- Acceptance label of notification shown to ask for user consent for sharing the remote bugreport. -->
    <string name="share_remote_bugreport_notification_accept">ACCEPT</string>
    <!-- Decline label of notification shown to ask for user consent for sharing the remote bugreport. -->
    <string name="share_remote_bugreport_notification_decline">DECLINE</string>
    <!-- Title of notification shown for remote bugreport progress. -->
    <string name="remote_bugreport_progress_notification_title">Taking bug report\u2026</string>
    <!-- Message of notification shown for remote bugreport progress. User can cancel the bugreport -->
    <string name="remote_bugreport_progress_notification_message_can_cancel">Touch to cancel</string>

    <!-- Used to replace %s in urls retreived from the signin server with locales.  For Some        -->
    <!-- devices we don't support all the locales we ship to and need to replace the '%s' with a    -->
+3 −2
Original line number Diff line number Diff line
@@ -1770,10 +1770,11 @@
  <java-symbol type="string" name="adb_active_notification_title" />
  <java-symbol type="string" name="share_remote_bugreport_notification_title" />
  <java-symbol type="string" name="share_remote_bugreport_notification_message" />
  <java-symbol type="string" name="share_finished_remote_bugreport_notification_message" />
  <java-symbol type="string" name="sharing_remote_bugreport_notification_title" />
  <java-symbol type="string" name="sharing_remote_bugreport_notification_message" />
  <java-symbol type="string" name="share_remote_bugreport_notification_accept" />
  <java-symbol type="string" name="share_remote_bugreport_notification_decline" />
  <java-symbol type="string" name="remote_bugreport_progress_notification_title" />
  <java-symbol type="string" name="remote_bugreport_progress_notification_message_can_cancel" />
  <java-symbol type="string" name="aerr_application" />
  <java-symbol type="string" name="aerr_process" />
  <java-symbol type="string" name="aerr_application_repeated" />
+17 −23
Original line number Diff line number Diff line
@@ -336,7 +336,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            mInjector.getNotificationManager().cancel(LOG_TAG,
                    RemoteBugreportUtils.REMOTE_BUGREPORT_CONSENT_NOTIFICATION_ID);
                    RemoteBugreportUtils.NOTIFICATION_ID);
            if (RemoteBugreportUtils.ACTION_REMOTE_BUGREPORT_SHARING_ACCEPTED.equals(action)) {
                onBugreportSharingAccepted();
            } else if (RemoteBugreportUtils.ACTION_REMOTE_BUGREPORT_SHARING_DECLINED
@@ -437,9 +437,10 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
                filterConsent.addAction(
                        RemoteBugreportUtils.ACTION_REMOTE_BUGREPORT_SHARING_ACCEPTED);
                mContext.registerReceiver(mRemoteBugreportConsentReceiver, filterConsent);
                mInjector.getNotificationManager().notify(
                        LOG_TAG, RemoteBugreportUtils.REMOTE_BUGREPORT_CONSENT_NOTIFICATION_ID,
                        RemoteBugreportUtils.buildRemoteBugreportConsentNotification(mContext));
                mInjector.getNotificationManager().notify(LOG_TAG,
                        RemoteBugreportUtils.NOTIFICATION_ID,
                        RemoteBugreportUtils.buildNotification(mContext,
                                RemoteBugreportUtils.NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED));
            }
            if (Intent.ACTION_BOOT_COMPLETED.equals(action)
                    || ACTION_EXPIRED_PASSWORD_NOTIFICATION.equals(action)) {
@@ -5044,13 +5045,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
            mRemoteBugreportServiceIsActive.set(true);
            mRemoteBugreportSharingAccepted.set(false);
            registerRemoteBugreportReceivers();
            mInjector.getNotificationManager().notify(
                    LOG_TAG, RemoteBugreportUtils.REMOTE_BUGREPORT_CONSENT_NOTIFICATION_ID,
                    RemoteBugreportUtils.buildRemoteBugreportConsentNotification(mContext));
            mInjector.getNotificationManager().notify(
                    LOG_TAG, RemoteBugreportUtils.REMOTE_BUGREPORT_IN_PROGRESS_NOTIFICATION_ID,
                    RemoteBugreportUtils.buildRemoteBugreportInProgressNotification(mContext,
                            /* canCancelBugReport */ true));
            mInjector.getNotificationManager().notify(LOG_TAG, RemoteBugreportUtils.NOTIFICATION_ID,
                    RemoteBugreportUtils.buildNotification(mContext,
                            RemoteBugreportUtils.NOTIFICATION_BUGREPORT_STARTED));
            mHandler.postDelayed(mRemoteBugreportTimeoutRunnable,
                    RemoteBugreportUtils.REMOTE_BUGREPORT_TIMEOUT_MILLIS);
            return true;
@@ -5100,8 +5097,6 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
    private void onBugreportFinished(Intent intent) {
        mHandler.removeCallbacks(mRemoteBugreportTimeoutRunnable);
        mRemoteBugreportServiceIsActive.set(false);
        mInjector.getNotificationManager().cancel(LOG_TAG,
                RemoteBugreportUtils.REMOTE_BUGREPORT_IN_PROGRESS_NOTIFICATION_ID);
        Uri bugreportUri = intent.getData();
        String bugreportUriString = null;
        if (bugreportUri != null) {
@@ -5111,8 +5106,13 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
                RemoteBugreportUtils.EXTRA_REMOTE_BUGREPORT_HASH);
        if (mRemoteBugreportSharingAccepted.get()) {
            shareBugreportWithDeviceOwnerIfExists(bugreportUriString, bugreportHash);
            mInjector.getNotificationManager().cancel(LOG_TAG,
                    RemoteBugreportUtils.NOTIFICATION_ID);
        } else {
            setDeviceOwnerRemoteBugreportUriAndHash(bugreportUriString, bugreportHash);
            mInjector.getNotificationManager().notify(LOG_TAG, RemoteBugreportUtils.NOTIFICATION_ID,
                    RemoteBugreportUtils.buildNotification(mContext,
                            RemoteBugreportUtils.NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED));
        }
        mContext.unregisterReceiver(mRemoteBugreportFinishedReceiver);
    }
@@ -5123,10 +5123,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
                RemoteBugreportUtils.REMOTE_BUGREPORT_SERVICE);
        mRemoteBugreportSharingAccepted.set(false);
        setDeviceOwnerRemoteBugreportUriAndHash(null, null);
        mInjector.getNotificationManager().cancel(LOG_TAG,
                RemoteBugreportUtils.REMOTE_BUGREPORT_CONSENT_NOTIFICATION_ID);
        mInjector.getNotificationManager().cancel(LOG_TAG,
                RemoteBugreportUtils.REMOTE_BUGREPORT_IN_PROGRESS_NOTIFICATION_ID);
        mInjector.getNotificationManager().cancel(LOG_TAG, RemoteBugreportUtils.NOTIFICATION_ID);
        Bundle extras = new Bundle();
        extras.putInt(DeviceAdminReceiver.EXTRA_BUGREPORT_FAILURE_REASON,
                DeviceAdminReceiver.BUGREPORT_FAILURE_FAILED_COMPLETING);
@@ -5146,10 +5143,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
        if (bugreportUriString != null) {
            shareBugreportWithDeviceOwnerIfExists(bugreportUriString, bugreportHash);
        } else if (mRemoteBugreportServiceIsActive.get()) {
            mInjector.getNotificationManager().notify(LOG_TAG,
                    RemoteBugreportUtils.REMOTE_BUGREPORT_IN_PROGRESS_NOTIFICATION_ID,
                    RemoteBugreportUtils.buildRemoteBugreportInProgressNotification(mContext,
                            /* canCancelBugReport */ false));
            mInjector.getNotificationManager().notify(LOG_TAG, RemoteBugreportUtils.NOTIFICATION_ID,
                    RemoteBugreportUtils.buildNotification(mContext,
                            RemoteBugreportUtils.NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED));
        }
    }

@@ -5163,8 +5159,6 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
        }
        mRemoteBugreportSharingAccepted.set(false);
        setDeviceOwnerRemoteBugreportUriAndHash(null, null);
        mInjector.getNotificationManager().cancel(LOG_TAG,
                RemoteBugreportUtils.REMOTE_BUGREPORT_IN_PROGRESS_NOTIFICATION_ID);
        sendDeviceOwnerCommand(DeviceAdminReceiver.ACTION_BUGREPORT_SHARING_DECLINED, null);
    }

+59 −53
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.server.devicepolicy;

import android.annotation.IntDef;
import android.app.Notification;
import android.app.PendingIntent;
import android.content.Context;
@@ -24,13 +25,26 @@ import android.text.format.DateUtils;

import com.android.internal.R;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * Utilities class for the remote bugreport operation.
 */
class RemoteBugreportUtils {

    static final int REMOTE_BUGREPORT_CONSENT_NOTIFICATION_ID = 678435657;
    static final int REMOTE_BUGREPORT_IN_PROGRESS_NOTIFICATION_ID = 590907895;
    static final int NOTIFICATION_ID = 678432343;

    @Retention(RetentionPolicy.SOURCE)
    @IntDef({
        NOTIFICATION_BUGREPORT_STARTED,
        NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED,
        NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED
    })
    @interface RemoteBugreportNotificationType {}
    static final int NOTIFICATION_BUGREPORT_STARTED = 1;
    static final int NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED = 2;
    static final int NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED = 3;

    static final long REMOTE_BUGREPORT_TIMEOUT_MILLIS = 10 * DateUtils.MINUTE_IN_MILLIS;

@@ -47,65 +61,57 @@ class RemoteBugreportUtils {

    static final String BUGREPORT_MIMETYPE = "application/vnd.android.bugreport";

    static Notification buildRemoteBugreportConsentNotification(Context context) {
        PendingIntent pendingIntentAccept = PendingIntent.getBroadcast(
                context, REMOTE_BUGREPORT_CONSENT_NOTIFICATION_ID,
    static Notification buildNotification(Context context,
            @RemoteBugreportNotificationType int type) {
        Notification.Builder builder = new Notification.Builder(context)
                .setSmallIcon(com.android.internal.R.drawable.stat_sys_adb)
                .setOngoing(true)
                .setLocalOnly(true)
                .setColor(context.getColor(
                        com.android.internal.R.color.system_notification_accent_color));

        if (type == NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED) {
            builder.setContentTitle(context.getString(
                            R.string.sharing_remote_bugreport_notification_title))
                    .setContentText(context.getString(
                            R.string.sharing_remote_bugreport_notification_message))
                    .setPriority(Notification.PRIORITY_HIGH)
                    .setProgress(0, 0, true)
                    .setStyle(new Notification.BigTextStyle().bigText(context.getString(
                            R.string.sharing_remote_bugreport_notification_message)));
        } else {
            PendingIntent pendingIntentAccept = PendingIntent.getBroadcast(context, NOTIFICATION_ID,
                    new Intent(ACTION_REMOTE_BUGREPORT_SHARING_ACCEPTED),
                    PendingIntent.FLAG_CANCEL_CURRENT);
        PendingIntent pendingIntentDecline = PendingIntent.getBroadcast(
                context, REMOTE_BUGREPORT_CONSENT_NOTIFICATION_ID,
                new Intent(ACTION_REMOTE_BUGREPORT_SHARING_DECLINED),
            PendingIntent pendingIntentDecline = PendingIntent.getBroadcast(context,
                    NOTIFICATION_ID, new Intent(ACTION_REMOTE_BUGREPORT_SHARING_DECLINED),
                    PendingIntent.FLAG_CANCEL_CURRENT);

        return new Notification.Builder(context)
                .setSmallIcon(com.android.internal.R.drawable.stat_sys_adb)
            builder.addAction(new Notification.Action.Builder(null /* icon */, context.getString(
                            R.string.share_remote_bugreport_notification_decline),
                            pendingIntentDecline).build())
                    .addAction(new Notification.Action.Builder(null /* icon */, context.getString(
                            R.string.share_remote_bugreport_notification_accept),
                            pendingIntentAccept).build())
                    .setContentTitle(context.getString(
                        R.string.share_remote_bugreport_notification_title))
                .setTicker(context.getString(R.string.share_remote_bugreport_notification_title))
                .setContentText(context.getString(
                            R.string.share_remote_bugreport_notification_title));

            if (type == NOTIFICATION_BUGREPORT_STARTED) {
                builder.setContentText(context.getString(
                                R.string.share_remote_bugreport_notification_message))
                        .setStyle(new Notification.BigTextStyle().bigText(context.getString(
                                R.string.share_remote_bugreport_notification_message)))
                .addAction(new Notification.Action.Builder(null /* icon */,
                        context.getString(R.string.share_remote_bugreport_notification_decline),
                        pendingIntentDecline).build())
                .addAction(new Notification.Action.Builder(null /* icon */,
                        context.getString(R.string.share_remote_bugreport_notification_accept),
                        pendingIntentAccept).build())
                .setOngoing(true)
                .setLocalOnly(true)
                .setColor(context.getColor(
                        com.android.internal.R.color.system_notification_accent_color))
                        .setProgress(0, 0, true)
                        .setPriority(Notification.PRIORITY_MAX)
                .setVibrate(new long[0])
                .build();
    }

    static Notification buildRemoteBugreportInProgressNotification(Context context,
            boolean canCancelBugreport) {
        Notification.Builder builder = new Notification.Builder(context)
                .setSmallIcon(com.android.internal.R.drawable.stat_sys_adb)
                .setContentTitle(context.getString(
                        R.string.remote_bugreport_progress_notification_title))
                .setTicker(context.getString(
                        R.string.remote_bugreport_progress_notification_title))
                .setOngoing(true)
                .setLocalOnly(true)
                .setColor(context.getColor(
                        com.android.internal.R.color.system_notification_accent_color))
                        .setVibrate(new long[0]);
            } else if (type == NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED) {
                builder.setContentText(context.getString(
                                R.string.share_finished_remote_bugreport_notification_message))
                        .setStyle(new Notification.BigTextStyle().bigText(context.getString(
                                R.string.share_finished_remote_bugreport_notification_message)))
                        .setPriority(Notification.PRIORITY_HIGH);

        if (canCancelBugreport) {
            PendingIntent pendingIntentCancel = PendingIntent.getBroadcast(context,
                    REMOTE_BUGREPORT_IN_PROGRESS_NOTIFICATION_ID,
                    new Intent(ACTION_REMOTE_BUGREPORT_SHARING_DECLINED),
                    PendingIntent.FLAG_CANCEL_CURRENT);
            String message = context.getString(
                    R.string.remote_bugreport_progress_notification_message_can_cancel);
            builder.setContentText(message)
                    .setContentIntent(pendingIntentCancel)
                    .setStyle(new Notification.BigTextStyle().bigText(message));
            }
        }

        return builder.build();
    }
}