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

Commit 17bf973b authored by Yi Kong's avatar Yi Kong
Browse files

profcollect: Copy report file to BetterBug's internal storage

BetterBug cannot directly access profcollectd's cache dir, let
profcollectd copy the report to BB's internal storage instead, as it has
higher privilege.

Test: manual
Bug: 79161490
Bug: 183487233
Change-Id: If86a00ab9fe9ed3c1418ca3ffe225b19ad4711b4
parent a819b9fc
Loading
Loading
Loading
Loading
+29 −1
Original line number Diff line number Diff line
@@ -30,6 +30,8 @@ import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UpdateEngine;
import android.os.UpdateEngineCallback;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.DeviceConfig;
import android.util.Log;

@@ -301,10 +303,18 @@ public final class ProfcollectForwardingService extends SystemService {

        new Thread(() -> {
            try {
                String reportPath = mIProfcollect.report();
                String reportUuid = mIProfcollect.report();

                if (!uploadReport) {
                    return;
                }

                final int profileId = getBBProfileId();
                mIProfcollect.copy_report_to_bb(profileId, reportUuid);
                String reportPath =
                        "/data/user/" + profileId
                        + "/com.google.android.apps.internal.betterbug/cache/"
                        + reportUuid + ".zip";
                Intent uploadIntent =
                        new Intent("com.google.android.apps.betterbug.intent.action.UPLOAD_PROFILE")
                        .setPackage("com.google.android.apps.internal.betterbug")
@@ -316,9 +326,27 @@ public final class ProfcollectForwardingService extends SystemService {
                if (context.getPackageManager().queryBroadcastReceivers(uploadIntent, 0) != null) {
                    context.sendBroadcast(uploadIntent);
                }
                mIProfcollect.delete_report(reportUuid);
            } catch (RemoteException e) {
                Log.e(LOG_TAG, e.getMessage());
            }
        }).start();
    }

    /**
     * Get BetterBug's profile ID. It is the work profile ID, if it exists. Otherwise the system
     * user ID.
     *
     * @return BetterBug's profile ID.
     */
    private int getBBProfileId() {
        UserManager userManager = UserManager.get(getContext());
        int[] profiles = userManager.getProfileIds(UserHandle.USER_SYSTEM, false);
        for (int p : profiles) {
            if (userManager.getUserInfo(p).isManagedProfile()) {
                return p;
            }
        }
        return UserHandle.USER_SYSTEM;
    }
}