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

Commit ec3ce576 authored by Nandana Dutt's avatar Nandana Dutt Committed by android-build-merger
Browse files

Merge "Pass in calling UID and package to dumpstate" am: bc6e433a

am: ae977163

Change-Id: Ie1126fb68184c7789fe969b008ee1550d4424809
parents 3be2df7b ae977163
Loading
Loading
Loading
Loading
+10 −3
Original line number Original line Diff line number Diff line
@@ -66,10 +66,14 @@ public class BugreportManager {
        @interface BugreportErrorCode {}
        @interface BugreportErrorCode {}


        /** The input options were invalid */
        /** The input options were invalid */
        int BUGREPORT_ERROR_INVALID_INPUT = 1;
        int BUGREPORT_ERROR_INVALID_INPUT = IDumpstateListener.BUGREPORT_ERROR_INVALID_INPUT;


        /** A runtime error occured */
        /** A runtime error occured */
        int BUGREPORT_ERROR_RUNTIME = 2;
        int BUGREPORT_ERROR_RUNTIME = IDumpstateListener.BUGREPORT_ERROR_RUNTIME_ERROR;

        /** User denied consent to share the bugreport */
        int BUGREPORT_ERROR_USER_DENIED_CONSENT =
                IDumpstateListener.BUGREPORT_ERROR_USER_DENIED_CONSENT;


        /**
        /**
         * Called when taking bugreport resulted in an error.
         * Called when taking bugreport resulted in an error.
@@ -108,7 +112,10 @@ public class BugreportManager {
        DumpstateListener dsListener = new DumpstateListener(listener);
        DumpstateListener dsListener = new DumpstateListener(listener);


        try {
        try {
            mBinder.startBugreport(bugreportFd, screenshotFd, params.getMode(), dsListener);
            // Note: mBinder can get callingUid from the binder transaction.
            mBinder.startBugreport(-1 /* callingUid */,
                    mContext.getOpPackageName(), bugreportFd, screenshotFd,
                    params.getMode(), dsListener);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
+11 −4
Original line number Original line Diff line number Diff line
@@ -17,7 +17,9 @@
package com.android.server.os;
package com.android.server.os;


import android.annotation.RequiresPermission;
import android.annotation.RequiresPermission;
import android.app.AppOpsManager;
import android.content.Context;
import android.content.Context;
import android.os.Binder;
import android.os.BugreportParams;
import android.os.BugreportParams;
import android.os.IDumpstate;
import android.os.IDumpstate;
import android.os.IDumpstateListener;
import android.os.IDumpstateListener;
@@ -46,9 +48,11 @@ class BugreportManagerServiceImpl extends IDumpstate.Stub {


    private IDumpstate mDs = null;
    private IDumpstate mDs = null;
    private final Context mContext;
    private final Context mContext;
    private final AppOpsManager mAppOps;


    BugreportManagerServiceImpl(Context context) {
    BugreportManagerServiceImpl(Context context) {
        mContext = context;
        mContext = context;
        mAppOps = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
    }
    }


    @Override
    @Override
@@ -60,21 +64,24 @@ class BugreportManagerServiceImpl extends IDumpstate.Stub {
        throw new UnsupportedOperationException("setListener is not allowed on this service");
        throw new UnsupportedOperationException("setListener is not allowed on this service");
    }
    }



    @Override
    @Override
    @RequiresPermission(android.Manifest.permission.DUMP)
    @RequiresPermission(android.Manifest.permission.DUMP)
    public void startBugreport(FileDescriptor bugreportFd, FileDescriptor screenshotFd,
    public void startBugreport(int callingUidUnused, String callingPackage,
            FileDescriptor bugreportFd, FileDescriptor screenshotFd,
            int bugreportMode, IDumpstateListener listener) throws RemoteException {
            int bugreportMode, IDumpstateListener listener) throws RemoteException {

        int callingUid = Binder.getCallingUid();
        // TODO(b/111441001): validate all arguments & ensure primary user
        validate(bugreportMode);
        validate(bugreportMode);


        mAppOps.checkPackage(callingUid, callingPackage);
        mDs = getDumpstateService();
        mDs = getDumpstateService();
        if (mDs == null) {
        if (mDs == null) {
            Slog.w(TAG, "Unable to get bugreport service");
            Slog.w(TAG, "Unable to get bugreport service");
            // TODO(b/111441001): pass error on listener
            // TODO(b/111441001): pass error on listener
            return;
            return;
        }
        }
        mDs.startBugreport(bugreportFd, screenshotFd, bugreportMode, listener);
        mDs.startBugreport(callingUid, callingPackage,
                bugreportFd, screenshotFd, bugreportMode, listener);
    }
    }


    private boolean validate(@BugreportParams.BugreportMode int mode) {
    private boolean validate(@BugreportParams.BugreportMode int mode) {