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

Commit 72468611 authored by Yi Kong's avatar Yi Kong Committed by Gerrit Code Review
Browse files

Merge "profcollect: Copy report file to BetterBug's internal storage"

parents 06c6ff8b 17bf973b
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;
    }
}