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

Commit 2934f74a authored by Eduard Dumitrescul's avatar Eduard Dumitrescul
Browse files

Update bugreport Uri to include userId

Bug: 341879351
Test: as described in buganizer
Flag: android.app.admin.flags.fix_hsum_bugreport_share_crash

Change-Id: Ia09a1136bb310bd1b01a646254695e80186bb114
parent d265afe3
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -518,3 +518,13 @@ flag {
  description: "Enable any user (not just the Main User) to be a DeviceOwner"
  bug: "435271558"
}

flag {
  name: "fix_hsum_bugreport_share_crash"
  namespace: "enterprise"
  description: "[HSUM][Framework Bug][DO] TestDPC crashes when sharing a bugreport requested from TestDPC"
  bug: "341879351"
  metadata {
    purpose: PURPOSE_BUGFIX
  }
}
+15 −3
Original line number Diff line number Diff line
@@ -397,6 +397,7 @@ import android.compat.annotation.EnabledSince;
import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentProvider;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
@@ -9601,8 +9602,19 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
    void sendBugreportToDeviceOwner(Uri bugreportUri, String bugreportHash) {
        synchronized (getLockObject()) {
            final Intent intent = new Intent(DeviceAdminReceiver.ACTION_BUGREPORT_SHARE);
            final int deviceOwnerUserId = mOwners.getDeviceOwnerUserId();
            final Uri bugreportUriForUser;
            if (Flags.fixHsumBugreportShareCrash()) {
                // Bugreports are collected by the shell, which runs as UserHandle.USER_SYSTEM.
                bugreportUriForUser = ContentProvider.createContentUriForUser(
                        bugreportUri, UserHandle.of(UserHandle.USER_SYSTEM));
            } else {
                bugreportUriForUser = bugreportUri;
            }
            intent.setComponent(mOwners.getDeviceOwnerComponent());
            intent.setDataAndType(bugreportUri, RemoteBugreportManager.BUGREPORT_MIMETYPE);
            intent.setDataAndType(bugreportUriForUser, RemoteBugreportManager.BUGREPORT_MIMETYPE);
            intent.putExtra(DeviceAdminReceiver.EXTRA_BUGREPORT_HASH, bugreportHash);
            intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
@@ -9610,10 +9622,10 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
                    .getService(UriGrantsManagerInternal.class);
            final NeededUriGrants needed = ugm.checkGrantUriPermissionFromIntent(intent,
                    Process.SHELL_UID, mOwners.getDeviceOwnerComponent().getPackageName(),
                    mOwners.getDeviceOwnerUserId());
                    deviceOwnerUserId);
            ugm.grantUriPermissionUncheckedFromIntent(needed, null);
            mContext.sendBroadcastAsUser(intent, UserHandle.of(mOwners.getDeviceOwnerUserId()));
            mContext.sendBroadcastAsUser(intent, UserHandle.of(deviceOwnerUserId));
        }
    }