profcollect: attempt to upload reports if BetterBug is available

BetterBug has their feature flag for controlling report upload, no need
to have duplicate flag in profcollect.

Test: manual
Change-Id: I82b0c341d3b150c3567ffe8da35bf41ac199419b
This commit is contained in:
Yi Kong
2021-04-28 14:57:08 +08:00
parent 16019ad77d
commit 2069f61ccd

View File

@@ -23,6 +23,7 @@ import android.app.job.JobService;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.os.Handler;
import android.os.IBinder.DeathRecipient;
import android.os.Looper;
@@ -42,6 +43,9 @@ import com.android.server.wm.ActivityMetricsLaunchObserver;
import com.android.server.wm.ActivityMetricsLaunchObserverRegistry;
import com.android.server.wm.ActivityTaskManagerInternal;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
@@ -297,24 +301,20 @@ public final class ProfcollectForwardingService extends SystemService {
return;
}
final boolean uploadReport =
DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_PROFCOLLECT_NATIVE_BOOT,
"upload_report", false);
new Thread(() -> {
try {
String reportUuid = mIProfcollect.report();
if (!uploadReport) {
final int profileId = getBBProfileId();
String reportDir = "/data/user/" + profileId
+ "/com.google.android.apps.internal.betterbug/cache/";
String reportPath = reportDir + reportUuid + ".zip";
if (!Files.exists(Paths.get(reportDir))) {
Log.i(LOG_TAG, "Destination directory does not exist, abort upload.");
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")
@@ -323,9 +323,15 @@ public final class ProfcollectForwardingService extends SystemService {
.putExtra("EXTRA_PROFILE_PATH", reportPath)
.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
Context context = getContext();
if (context.getPackageManager().queryBroadcastReceivers(uploadIntent, 0) != null) {
context.sendBroadcast(uploadIntent);
List<ResolveInfo> receivers =
context.getPackageManager().queryBroadcastReceivers(uploadIntent, 0);
if (receivers == null || receivers.isEmpty()) {
Log.i(LOG_TAG, "No one to receive upload intent, abort upload.");
return;
}
mIProfcollect.copy_report_to_bb(profileId, reportUuid);
context.sendBroadcast(uploadIntent);
mIProfcollect.delete_report(reportUuid);
} catch (RemoteException e) {
Log.e(LOG_TAG, e.getMessage());