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

Commit 08d78a59 authored by Paul Chang's avatar Paul Chang Committed by Android (Google) Code Review
Browse files

Merge "Revert "Let bug report shortcut handle the case that bug report handler...

Merge "Revert "Let bug report shortcut handle the case that bug report handler app is not available"" into rvc-dev
parents 555ae029 319b13bf
Loading
Loading
Loading
Loading
+2 −30
Original line number Original line Diff line number Diff line
@@ -16,20 +16,15 @@


package com.android.server.am;
package com.android.server.am;


import static android.app.AppOpsManager.OP_NONE;
import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;


import android.app.Activity;
import android.app.BroadcastOptions;
import android.app.BroadcastOptions;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ResolveInfo;
import android.os.Binder;
import android.os.Binder;
import android.os.BugreportManager;
import android.os.BugreportParams;
import android.os.UserHandle;
import android.os.UserHandle;
import android.provider.Settings;
import android.provider.Settings;
import android.text.TextUtils;
import android.text.TextUtils;
@@ -115,17 +110,9 @@ public final class BugReportHandlerUtil {
        options.setBackgroundActivityStartsAllowed(true);
        options.setBackgroundActivityStartsAllowed(true);
        final long identity = Binder.clearCallingIdentity();
        final long identity = Binder.clearCallingIdentity();
        try {
        try {
            // Handler app's BroadcastReceiver should call setResultCode(Activity.RESULT_OK) to
            context.sendBroadcastAsUser(intent, UserHandle.of(handlerUser),
            // let ResultBroadcastReceiver know the handler app is available.
            context.sendOrderedBroadcastAsUser(intent,
                    UserHandle.of(handlerUser),
                    android.Manifest.permission.DUMP,
                    android.Manifest.permission.DUMP,
                    OP_NONE, options.toBundle(),
                    options.toBundle());
                    new ResultBroadcastReceiver(),
                    /* scheduler= */ null,
                    Activity.RESULT_CANCELED,
                    /* initialData= */ null,
                    /* initialExtras= */ null);
        } catch (RuntimeException e) {
        } catch (RuntimeException e) {
            Slog.e(TAG, "Error while trying to launch bugreport handler app.", e);
            Slog.e(TAG, "Error while trying to launch bugreport handler app.", e);
            return false;
            return false;
@@ -189,19 +176,4 @@ public final class BugReportHandlerUtil {
            Binder.restoreCallingIdentity(identity);
            Binder.restoreCallingIdentity(identity);
        }
        }
    }
    }

    private static class ResultBroadcastReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (getResultCode() == Activity.RESULT_OK) {
                return;
            }

            Slog.w(TAG, "Request bug report because handler app seems to be not available.");
            BugreportManager bugreportManager = context.getSystemService(BugreportManager.class);
            bugreportManager.requestBugreport(
                    new BugreportParams(BugreportParams.BUGREPORT_MODE_INTERACTIVE),
                    /* shareTitle= */null, /* shareDescription= */ null);
        }
    }
}
}