auto privileges = PrivilegeInfo::getPrivacyPrivileges(privacy);
for (const auto &privilege : privileges) {
ALOGD("Calculating policy for privilege " << privilege);
- PolicyEntry filter;
- filter.setApp(appId);
- filter.setUser(std::to_string(geteuid()));
- filter.setPrivilege(privilege);
-
- PolicyFetchRequest fetch(std::move(filter));
- auto policies = fetch.fetchPolicy();
- if (policies.size() == 0) {
- ALOGD("No policy for given privilege " << privilege);
- continue;
- }
- if (policies.size() > 1) {
- ALOGW("Something went wrong, there should be no more than one policy for specific filter");
- // FIXME : don't really know what to do with it. Lets ignore it for now.
+
+ std::string policyLevel = getPrivilegePolicy(appId, privilege);
+
+ if (policyLevel.empty()) {
+ ALOGE("Couldn't get policy level, skipping");
continue;
}
- std::string policyLevel = policies[0].getLevel();
- ALOGD("Fetched policy level : " << policyLevel);
+ ALOGD("Fetched policy level : " << policyLevel);
privsPolicies.push_back(std::move(policyLevel));
}
return getMinimumPolicy(privsPolicies);
}
+Policy getPrivilegePolicy(const std::string &appId, const Privilege &privilege) {
+ PolicyEntry filter;
+ filter.setApp(appId);
+ filter.setUser(std::to_string(geteuid()));
+ filter.setPrivilege(privilege);
+
+ PolicyFetchRequest fetch(std::move(filter));
+ auto policies = fetch.fetchPolicy();
+ if (policies.size() == 0) {
+ ALOGD("No policy for given privilege " << privilege);
+ return "";
+ }
+ if (policies.size() > 1) {
+ ALOGW("Something went wrong, there should be no more than one policy for specific filter");
+ // FIXME : don't really know what to do with it. Lets ignore it for now.
+ return "";
+ }
+ return policies[0].getLevel();
+}
+
Policy getPrivaciesPolicy(const std::string &appId, const std::vector<Privacy> &privacies) {
std::vector<Policy> policies;
for (auto &privacy : privacies) {
pkgLabel = pkgInfo.pkgLabel();
}
-Policy getPrivilegePolicy(const std::string &appId, const std::string &privilege) {
+Policy getPrivilegeMappedPolicy(const std::string &appId, const std::string &privilege) {
std::vector<Privacy> privacies = PrivilegeInfo::getPrivilegePrivaciesMapping(appId, privilege);
if (privacies.empty()) {
ALOGE("Privilege doesn't map to any privacy");
Policy calculatePolicyForPrivacy(const std::string &appId, const Privacy &privacy);
Policy getMinimumPolicy(const std::vector<Policy> &policies);
-Policy getPrivilegePolicy(const std::string &appId, const Privilege &privilege);
+Policy getPrivilegeMappedPolicy(const std::string &appId, const Privilege &privilege);
Policy getPrivaciesPolicy(const std::string &appId, const std::vector<Privacy> &privacies);
+Policy getPrivilegePolicy(const std::string &appId, const Privilege &corePrivilege);
+
class PolicyEntry {
public: