[installd] Extend profile operations to take the profile name
Extend the installd profile interface to take the profile name as
argument. This shifts the responsibility for choosing the names of
profiles for primary apks completely to PackageManager. Each of the
application code paths will get an unique profile name.
All the profile operations will now work on a specific profile name rather
than assuming a default global name.
(cherry picked from commit 562de815339bedd29206f5f98be44c824945b627)
Test: installd_dexopt_test
Bug: 30934496
Merged-In: I5847d35fe4d3caa5a2b32293426a24683af42030
Change-Id: I5847d35fe4d3caa5a2b32293426a24683af42030
diff --git a/cmds/installd/otapreopt.cpp b/cmds/installd/otapreopt.cpp
index 5663d12..223b17a 100644
--- a/cmds/installd/otapreopt.cpp
+++ b/cmds/installd/otapreopt.cpp
@@ -181,6 +181,7 @@
const char* se_info;
bool downgrade;
int target_sdk_version;
+ const char* profile_name;
};
bool ReadSystemProperties() {
@@ -363,6 +364,8 @@
return ReadArgumentsV3(argc, argv);
case 4:
return ReadArgumentsV4(argc, argv);
+ case 5:
+ return ReadArgumentsV5(argc, argv);
default:
LOG(ERROR) << "Unsupported version " << version;
@@ -449,6 +452,9 @@
// conservative and may force some classes to verify at runtime.
package_parameters_.target_sdk_version = 0;
+ // Set the profile name to the primary apk profile.
+ package_parameters_.profile_name = "primary.prof";
+
if (param_index != 11) {
LOG(ERROR) << "Not enough parameters";
return false;
@@ -536,6 +542,9 @@
// conservative and may force some classes to verify at runtime.
package_parameters_.target_sdk_version = 0;
+ // Set the profile name to the primary apk profile.
+ package_parameters_.profile_name = "primary.prof";
+
if (param_index != 12) {
LOG(ERROR) << "Not enough parameters";
return false;
@@ -623,6 +632,9 @@
}
}
+ // Set the profile name to the primary apk profile.
+ package_parameters_.profile_name = "primary.prof";
+
if (param_index != 13) {
LOG(ERROR) << "Not enough parameters";
return false;
@@ -631,6 +643,99 @@
return true;
}
+ // TODO: this pattern does not scale and result in a lot of code duplication.
+ // Either find a better pattern or refactor the code to eliminate the duplication.
+ bool ReadArgumentsV5(int argc ATTRIBUTE_UNUSED, char** argv) {
+ size_t dexopt_index = 3;
+
+ // Check for "dexopt".
+ if (argv[dexopt_index] == nullptr) {
+ LOG(ERROR) << "Missing parameters";
+ return false;
+ }
+ if (std::string("dexopt").compare(argv[dexopt_index]) != 0) {
+ LOG(ERROR) << "Expected \"dexopt\"";
+ return false;
+ }
+
+ size_t param_index = 0;
+ for (;; ++param_index) {
+ const char* param = argv[dexopt_index + 1 + param_index];
+ if (param == nullptr) {
+ break;
+ }
+
+ switch (param_index) {
+ case 0:
+ package_parameters_.apk_path = param;
+ break;
+
+ case 1:
+ package_parameters_.uid = atoi(param);
+ break;
+
+ case 2:
+ package_parameters_.pkgName = param;
+ break;
+
+ case 3:
+ package_parameters_.instruction_set = param;
+ break;
+
+ case 4:
+ package_parameters_.dexopt_needed = atoi(param);
+ break;
+
+ case 5:
+ package_parameters_.oat_dir = param;
+ break;
+
+ case 6:
+ package_parameters_.dexopt_flags = atoi(param);
+ break;
+
+ case 7:
+ package_parameters_.compiler_filter = param;
+ break;
+
+ case 8:
+ package_parameters_.volume_uuid = ParseNull(param);
+ break;
+
+ case 9:
+ package_parameters_.shared_libraries = ParseNull(param);
+ break;
+
+ case 10:
+ package_parameters_.se_info = ParseNull(param);
+ break;
+
+ case 11:
+ package_parameters_.downgrade = ParseBool(param);
+ break;
+
+ case 12:
+ package_parameters_.target_sdk_version = atoi(param);
+ break;
+
+ case 13:
+ package_parameters_.profile_name = ParseNull(param);
+ break;
+
+ default:
+ LOG(ERROR) << "Too many arguments, got " << param;
+ return false;
+ }
+ }
+
+ if (param_index != 14) {
+ LOG(ERROR) << "Not enough parameters";
+ return false;
+ }
+
+ return true;
+ }
+
static int ReplaceMask(int input, int old_mask, int new_mask) {
return (input & old_mask) != 0 ? new_mask : 0;
}
@@ -738,6 +843,9 @@
// conservative and may force some classes to verify at runtime.
package_parameters_.target_sdk_version = 0;
+ // Set the profile name to the primary apk profile.
+ package_parameters_.profile_name = "primary.prof";
+
return true;
}
@@ -1027,7 +1135,7 @@
package_parameters_.se_info,
package_parameters_.downgrade,
package_parameters_.target_sdk_version,
- "primary.prof");
+ package_parameters_.profile_name);
}
int RunPreopt() {