profcollectd: Avoid hard-coding Betterbug name

Use vendor config file to provide the uploader package name and action
name, so that OEMs can implement their own uploaders.

Test: manual
Bug: 178561556
Bug: 183487233
Change-Id: Ib398f34825233db1b9a9f2e4da78c7ce35953164
This commit is contained in:
Yi Kong
2021-06-24 14:52:44 +08:00
parent d6910efffd
commit 2d17c2844d
3 changed files with 39 additions and 3 deletions

View File

@@ -4632,6 +4632,15 @@
<!-- The package name for the default bug report handler app from power menu short press. This app must be allowlisted. --> <!-- The package name for the default bug report handler app from power menu short press. This app must be allowlisted. -->
<string name="config_defaultBugReportHandlerApp" translatable="false"></string> <string name="config_defaultBugReportHandlerApp" translatable="false"></string>
<!-- When true, enables the allowlisted app to upload profcollect reports. -->
<bool name="config_profcollectReportUploaderEnabled">false</bool>
<!-- The package name for the default profcollect report uploader app. This app must be allowlisted. -->
<string name="config_defaultProfcollectReportUploaderApp" translatable="false"></string>
<!-- The action name for the default profcollect report uploader app. -->
<string name="config_defaultProfcollectReportUploaderAction" translatable="false"></string>
<!-- The default value used for RawContacts.ACCOUNT_NAME when contacts are inserted without this <!-- The default value used for RawContacts.ACCOUNT_NAME when contacts are inserted without this
column set. These contacts are stored locally on the device and will not be removed even column set. These contacts are stored locally on the device and will not be removed even
if no android.account.Account with this name exists. A null string will be used if the if no android.account.Account with this name exists. A null string will be used if the

View File

@@ -4019,6 +4019,11 @@
<java-symbol type="bool" name="config_bugReportHandlerEnabled" /> <java-symbol type="bool" name="config_bugReportHandlerEnabled" />
<java-symbol type="string" name="config_defaultBugReportHandlerApp" /> <java-symbol type="string" name="config_defaultBugReportHandlerApp" />
<!-- For profcollect report uploader -->
<java-symbol type="bool" name="config_profcollectReportUploaderEnabled" />
<java-symbol type="string" name="config_defaultProfcollectReportUploaderApp" />
<java-symbol type="string" name="config_defaultProfcollectReportUploaderAction" />
<java-symbol type="string" name="usb_device_resolve_prompt_warn" /> <java-symbol type="string" name="usb_device_resolve_prompt_warn" />
<!-- For Accessibility system actions --> <!-- For Accessibility system actions -->

View File

@@ -37,6 +37,7 @@ import android.os.UserManager;
import android.provider.DeviceConfig; import android.provider.DeviceConfig;
import android.util.Log; import android.util.Log;
import com.android.internal.R;
import com.android.server.IoThread; import com.android.server.IoThread;
import com.android.server.LocalServices; import com.android.server.LocalServices;
import com.android.server.SystemService; import com.android.server.SystemService;
@@ -302,8 +303,15 @@ public final class ProfcollectForwardingService extends SystemService {
return; return;
} }
if (!getUploaderEnabledConfig(getContext())) {
return;
}
new Thread(() -> { new Thread(() -> {
try { try {
Context context = getContext();
final String uploaderPkg = getUploaderPackageName(context);
final String uploaderAction = getUploaderActionName(context);
String reportUuid = mIProfcollect.report(); String reportUuid = mIProfcollect.report();
final int profileId = getBBProfileId(); final int profileId = getBBProfileId();
@@ -317,13 +325,12 @@ public final class ProfcollectForwardingService extends SystemService {
} }
Intent uploadIntent = Intent uploadIntent =
new Intent("com.google.android.apps.betterbug.intent.action.UPLOAD_PROFILE") new Intent(uploaderAction)
.setPackage("com.google.android.apps.internal.betterbug") .setPackage(uploaderPkg)
.putExtra("EXTRA_DESTINATION", "PROFCOLLECT") .putExtra("EXTRA_DESTINATION", "PROFCOLLECT")
.putExtra("EXTRA_PACKAGE_NAME", getContext().getPackageName()) .putExtra("EXTRA_PACKAGE_NAME", getContext().getPackageName())
.putExtra("EXTRA_PROFILE_PATH", reportPath) .putExtra("EXTRA_PROFILE_PATH", reportPath)
.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); .addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
Context context = getContext();
List<ResolveInfo> receivers = List<ResolveInfo> receivers =
context.getPackageManager().queryBroadcastReceivers(uploadIntent, 0); context.getPackageManager().queryBroadcastReceivers(uploadIntent, 0);
@@ -356,4 +363,19 @@ public final class ProfcollectForwardingService extends SystemService {
} }
return UserHandle.USER_SYSTEM; return UserHandle.USER_SYSTEM;
} }
private boolean getUploaderEnabledConfig(Context context) {
return context.getResources().getBoolean(
R.bool.config_profcollectReportUploaderEnabled);
}
private String getUploaderPackageName(Context context) {
return context.getResources().getString(
R.string.config_defaultProfcollectReportUploaderApp);
}
private String getUploaderActionName(Context context) {
return context.getResources().getString(
R.string.config_defaultProfcollectReportUploaderAction);
}
} }