1 /**
2 * Copyright (c) 2020, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "PolicyManager.h"
18
19 #include <aidl/android/hardware/automotive/vehicle/VehicleApPowerStateReport.h>
20 #include <android-base/file.h>
21 #include <gmock/gmock.h>
22
23 #include <unordered_set>
24
25 namespace android {
26 namespace frameworks {
27 namespace automotive {
28 namespace powerpolicy {
29
30 using ::aidl::android::frameworks::automotive::powerpolicy::CarPowerPolicy;
31 using ::aidl::android::frameworks::automotive::powerpolicy::PowerComponent;
32 using ::aidl::android::hardware::automotive::vehicle::VehicleApPowerStateReport;
33 using ::tinyxml2::XML_SUCCESS;
34 using ::tinyxml2::XMLDocument;
35
36 namespace test {
37
38 constexpr const char* kDirPrefix = "/tests/data/";
39
40 constexpr const char* kValidPowerPolicyXmlFile = "valid_power_policy.xml";
41 constexpr const char* kValidPowerPolicyNoPowerPolicyGroupsXmlFile =
42 "valid_power_policy_no_power_policy_groups.xml";
43 constexpr const char* kValidPowerPolicyNoSystemPowerPolicyXmlFile =
44 "valid_power_policy_no_system_power_policy.xml";
45 constexpr const char* kValidPowerPolicyPowerPoliciesOnlyXmlFile =
46 "valid_power_policy_policies_only.xml";
47 constexpr const char* kValidPowerPolicySystemPowerPolicyOnlyXmlFile =
48 "valid_power_policy_system_power_policy_only.xml";
49 constexpr const char* kValidPowerPolicyWithDefaultPolicyGroup =
50 "valid_power_policy_default_policy_group.xml";
51 constexpr const char* kValidPowerPolicyWithInvalidDefaultPolicyGroup =
52 "invalid_system_power_policy_incorrect_default_power_policy_group_id.xml";
53 const std::vector<const char*> kInvalidPowerPolicyXmlFiles =
54 {"invalid_power_policy_incorrect_id.xml",
55 "invalid_power_policy_incorrect_othercomponent.xml",
56 "invalid_power_policy_incorrect_value.xml", "invalid_power_policy_unknown_component.xml",
57 "invalid_system_power_policy_incorrect_default_power_policy_group_id.xml"};
58 const std::vector<const char*> kInvalidPowerPolicyGroupXmlFiles =
59 {"invalid_power_policy_group_incorrect_state.xml",
60 "invalid_power_policy_group_missing_policy.xml"};
61 const std::vector<const char*> kInvalidSystemPowerPolicyXmlFiles =
62 {"invalid_system_power_policy_incorrect_component.xml",
63 "invalid_system_power_policy_incorrect_id.xml"};
64
65 constexpr const char* kExistingPowerPolicyId = "expected_to_be_registered";
66 constexpr const char* kExistingPowerPolicyId_OtherOff = "policy_id_other_off";
67 constexpr const char* kExistingPowerPolicyId_OtherOn = "policy_id_other_on";
68 constexpr const char* kExistingPowerPolicyId_OtherUntouched = "policy_id_other_untouched";
69 constexpr const char* kExistingPowerPolicyId_OtherNone = "policy_id_other_none";
70 constexpr const char* kNonExistingPowerPolicyId = "non_existing_power_poicy_id";
71 constexpr const char* kValidPowerPolicyGroupId = "mixed_policy_group";
72 constexpr const char* kInvalidPowerPolicyGroupId = "invalid_policy_group";
73 constexpr const char* kSystemPolicyIdNoUserInteraction = "system_power_policy_no_user_interaction";
74 constexpr const char* kSystemPolicyIdInitialOn = "system_power_policy_initial_on";
75 constexpr const char* kSystemPolicyIdInitialAllOn = "system_power_policy_all_on";
76 constexpr const char* kSystemPolicyIdSuspendPrep = "system_power_policy_suspend_prep";
77 constexpr const char* kMixedPolicyGroupName = "mixed_policy_group";
78
79 const VehicleApPowerStateReport kExistingTransition = VehicleApPowerStateReport::WAIT_FOR_VHAL;
80 const VehicleApPowerStateReport kNonExistingTransition = static_cast<VehicleApPowerStateReport>(-1);
81
createCarPowerPolicy(const std::string & id,const std::vector<PowerComponent> & enabledComponents,const std::vector<PowerComponent> & disabledComponents)82 CarPowerPolicy createCarPowerPolicy(const std::string& id,
83 const std::vector<PowerComponent>& enabledComponents,
84 const std::vector<PowerComponent>& disabledComponents) {
85 CarPowerPolicy policy;
86 policy.policyId = id;
87 policy.enabledComponents = enabledComponents;
88 policy.disabledComponents = disabledComponents;
89 return policy;
90 }
91
92 const CarPowerPolicy kExistingPowerPolicy_OtherOff =
93 createCarPowerPolicy("policy_id_other_off", {PowerComponent::WIFI},
94 {PowerComponent::AUDIO, PowerComponent::MEDIA, PowerComponent::DISPLAY,
95 PowerComponent::BLUETOOTH, PowerComponent::CELLULAR,
96 PowerComponent::ETHERNET, PowerComponent::PROJECTION,
97 PowerComponent::NFC, PowerComponent::INPUT,
98 PowerComponent::VOICE_INTERACTION, PowerComponent::VISUAL_INTERACTION,
99 PowerComponent::TRUSTED_DEVICE_DETECTION, PowerComponent::LOCATION,
100 PowerComponent::MICROPHONE, PowerComponent::CPU});
101 const CarPowerPolicy kExistingPowerPolicy_OtherOn =
102 createCarPowerPolicy("policy_id_other_on",
103 {PowerComponent::MEDIA, PowerComponent::DISPLAY,
104 PowerComponent::BLUETOOTH, PowerComponent::WIFI,
105 PowerComponent::CELLULAR, PowerComponent::ETHERNET,
106 PowerComponent::PROJECTION, PowerComponent::NFC,
107 PowerComponent::INPUT, PowerComponent::LOCATION,
108 PowerComponent::MICROPHONE, PowerComponent::CPU},
109 {PowerComponent::AUDIO, PowerComponent::VOICE_INTERACTION,
110 PowerComponent::VISUAL_INTERACTION,
111 PowerComponent::TRUSTED_DEVICE_DETECTION});
112 const CarPowerPolicy kExistingPowerPolicy_OtherUntouched =
113 createCarPowerPolicy("policy_id_other_untouched",
114 {PowerComponent::AUDIO, PowerComponent::DISPLAY,
115 PowerComponent::BLUETOOTH, PowerComponent::WIFI,
116 PowerComponent::VOICE_INTERACTION, PowerComponent::VISUAL_INTERACTION,
117 PowerComponent::TRUSTED_DEVICE_DETECTION},
118 {});
119 const CarPowerPolicy kExistingPowerPolicy_OtherNone =
120 createCarPowerPolicy("policy_id_other_none", {PowerComponent::WIFI},
121 {PowerComponent::AUDIO, PowerComponent::VOICE_INTERACTION,
122 PowerComponent::VISUAL_INTERACTION,
123 PowerComponent::TRUSTED_DEVICE_DETECTION});
124 const CarPowerPolicy& kExistingTransitionPolicy = kExistingPowerPolicy_OtherOn;
125 const CarPowerPolicy kSystemPowerPolicyNoUserInteraction =
126 createCarPowerPolicy("system_power_policy_no_user_interaction",
127 {PowerComponent::WIFI, PowerComponent::CELLULAR,
128 PowerComponent::ETHERNET, PowerComponent::TRUSTED_DEVICE_DETECTION,
129 PowerComponent::CPU},
130 {PowerComponent::AUDIO, PowerComponent::MEDIA, PowerComponent::DISPLAY,
131 PowerComponent::BLUETOOTH, PowerComponent::PROJECTION,
132 PowerComponent::NFC, PowerComponent::INPUT,
133 PowerComponent::VOICE_INTERACTION, PowerComponent::VISUAL_INTERACTION,
134 PowerComponent::LOCATION, PowerComponent::MICROPHONE});
135 const CarPowerPolicy kModifiedSystemPowerPolicy =
136 createCarPowerPolicy("system_power_policy_no_user_interaction",
137 {PowerComponent::BLUETOOTH, PowerComponent::WIFI,
138 PowerComponent::CELLULAR, PowerComponent::ETHERNET,
139 PowerComponent::NFC, PowerComponent::CPU},
140 {PowerComponent::AUDIO, PowerComponent::MEDIA, PowerComponent::DISPLAY,
141 PowerComponent::PROJECTION, PowerComponent::INPUT,
142 PowerComponent::VOICE_INTERACTION, PowerComponent::VISUAL_INTERACTION,
143 PowerComponent::TRUSTED_DEVICE_DETECTION, PowerComponent::LOCATION,
144 PowerComponent::MICROPHONE});
145
getTestDataPath(const char * filename)146 std::string getTestDataPath(const char* filename) {
147 static std::string baseDir = android::base::GetExecutableDirectory();
148 return baseDir + kDirPrefix + filename;
149 }
150
compareComponents(const std::vector<PowerComponent> & a,const std::vector<PowerComponent> & b)151 bool compareComponents(const std::vector<PowerComponent>& a, const std::vector<PowerComponent>& b) {
152 int lenA = a.size();
153 int lenB = b.size();
154 if (lenA != lenB) {
155 return false;
156 }
157 std::unordered_set<PowerComponent> componentSet;
158 for (const auto component : a) {
159 componentSet.insert(component);
160 }
161 for (const auto component : b) {
162 if (componentSet.count(component) == 0) {
163 return false;
164 }
165 componentSet.erase(component);
166 }
167 return componentSet.size() == 0;
168 }
169
isEqual(const CarPowerPolicy & a,const CarPowerPolicy & b)170 bool isEqual(const CarPowerPolicy& a, const CarPowerPolicy& b) {
171 return a.policyId == a.policyId &&
172 compareComponents(a.enabledComponents, b.enabledComponents) &&
173 compareComponents(a.disabledComponents, b.disabledComponents);
174 }
175
checkPolicies(const PolicyManager & policyManager)176 void checkPolicies(const PolicyManager& policyManager) {
177 ASSERT_FALSE(policyManager.getPowerPolicy(kNonExistingPowerPolicyId).ok());
178
179 // otherComponents behavior = off
180 auto policyMeta = policyManager.getPowerPolicy(kExistingPowerPolicyId_OtherOff);
181 ASSERT_TRUE(policyMeta.ok());
182 ASSERT_TRUE(isEqual(*policyMeta->powerPolicy, kExistingPowerPolicy_OtherOff));
183 // otherComponents behavior = on
184 policyMeta = policyManager.getPowerPolicy(kExistingPowerPolicyId_OtherOn);
185 ASSERT_TRUE(policyMeta.ok());
186 ASSERT_TRUE(isEqual(*policyMeta->powerPolicy, kExistingPowerPolicy_OtherOn));
187 // otherComponents behavior = untouched
188 policyMeta = policyManager.getPowerPolicy(kExistingPowerPolicyId_OtherUntouched);
189 ASSERT_TRUE(policyMeta.ok());
190 ASSERT_TRUE(isEqual(*policyMeta->powerPolicy, kExistingPowerPolicy_OtherUntouched));
191 // otherComponents behavior = none
192 policyMeta = policyManager.getPowerPolicy(kExistingPowerPolicyId_OtherNone);
193 ASSERT_TRUE(policyMeta.ok());
194 ASSERT_TRUE(isEqual(*policyMeta->powerPolicy, kExistingPowerPolicy_OtherNone));
195 }
196
checkPowerPolicyGroups(const PolicyManager & policyManager)197 void checkPowerPolicyGroups(const PolicyManager& policyManager) {
198 auto policy = policyManager.getDefaultPowerPolicyForState(kValidPowerPolicyGroupId,
199 kExistingTransition);
200 ASSERT_TRUE(policy.ok());
201 ASSERT_TRUE(isEqual(**policy, kExistingTransitionPolicy));
202 ASSERT_FALSE(
203 policyManager
204 .getDefaultPowerPolicyForState(kValidPowerPolicyGroupId, kNonExistingTransition)
205 .ok());
206 }
207
checkSystemPowerPolicy(const PolicyManager & policyManager,const CarPowerPolicy & expectedPolicy)208 void checkSystemPowerPolicy(const PolicyManager& policyManager,
209 const CarPowerPolicy& expectedPolicy) {
210 auto policyMeta = policyManager.getPowerPolicy(kSystemPolicyIdNoUserInteraction);
211 ASSERT_TRUE(isEqual(*policyMeta->powerPolicy, expectedPolicy));
212 }
213
checkInvalidPolicies(const PolicyManager & policyManager)214 void checkInvalidPolicies(const PolicyManager& policyManager) {
215 ASSERT_FALSE(policyManager.getPowerPolicy(kExistingPowerPolicyId).ok());
216 ASSERT_FALSE(policyManager.getPowerPolicy(kNonExistingPowerPolicyId).ok());
217 ASSERT_FALSE(
218 policyManager
219 .getDefaultPowerPolicyForState(kValidPowerPolicyGroupId, kExistingTransition)
220 .ok());
221 ASSERT_FALSE(
222 policyManager
223 .getDefaultPowerPolicyForState(kValidPowerPolicyGroupId, kNonExistingTransition)
224 .ok());
225 auto policyMeta = policyManager.getPowerPolicy(kSystemPolicyIdNoUserInteraction);
226 ASSERT_TRUE(isEqual(*policyMeta->powerPolicy, kSystemPowerPolicyNoUserInteraction));
227 }
228
assertDefaultPolicies(const PolicyManager & policyManager)229 void assertDefaultPolicies(const PolicyManager& policyManager) {
230 ASSERT_TRUE(policyManager.getPowerPolicy(kSystemPolicyIdSuspendPrep).ok());
231 ASSERT_TRUE(policyManager.getPowerPolicy(kSystemPolicyIdNoUserInteraction).ok());
232 ASSERT_TRUE(policyManager.getPowerPolicy(kSystemPolicyIdInitialOn).ok());
233 ASSERT_TRUE(policyManager.getPowerPolicy(kSystemPolicyIdInitialAllOn).ok());
234 }
235
236 } // namespace test
237
238 namespace internal {
239
240 class PolicyManagerPeer {
241 public:
PolicyManagerPeer(PolicyManager * manager)242 explicit PolicyManagerPeer(PolicyManager* manager) : mManager(manager) {
243 manager->initRegularPowerPolicy(/*override=*/true);
244 manager->initPreemptivePowerPolicy();
245 }
246
expectValidPowerPolicyXML(const char * filename)247 void expectValidPowerPolicyXML(const char* filename) { readXmlFile(filename); }
expectInvalidPowerPolicyXML(const char * filename)248 void expectInvalidPowerPolicyXML(const char* filename) { readXmlFile(filename); }
249
250 private:
readXmlFile(const char * filename)251 void readXmlFile(const char* filename) {
252 XMLDocument xmlDoc;
253 std::string path = test::getTestDataPath(filename);
254 xmlDoc.LoadFile(path.c_str());
255 ASSERT_TRUE(xmlDoc.ErrorID() == XML_SUCCESS);
256 mManager->readPowerPolicyFromXml(xmlDoc);
257 }
258
259 private:
260 PolicyManager* mManager;
261 };
262
263 } // namespace internal
264
265 namespace test {
266
267 class PolicyManagerTest : public ::testing::Test {};
268
TEST_F(PolicyManagerTest,TestValidXml_PowerPolicy)269 TEST_F(PolicyManagerTest, TestValidXml_PowerPolicy) {
270 PolicyManager policyManager;
271 internal::PolicyManagerPeer policyManagerPeer(&policyManager);
272 policyManagerPeer.expectValidPowerPolicyXML(kValidPowerPolicyXmlFile);
273
274 checkPolicies(policyManager);
275 }
276
TEST_F(PolicyManagerTest,TestValidXml_PowerPolicyGroup)277 TEST_F(PolicyManagerTest, TestValidXml_PowerPolicyGroup) {
278 PolicyManager policyManager;
279 internal::PolicyManagerPeer policyManagerPeer(&policyManager);
280 policyManagerPeer.expectValidPowerPolicyXML(kValidPowerPolicyXmlFile);
281
282 checkPowerPolicyGroups(policyManager);
283 }
284
TEST_F(PolicyManagerTest,TestValidXml_SystemPowerPolicy)285 TEST_F(PolicyManagerTest, TestValidXml_SystemPowerPolicy) {
286 PolicyManager policyManager;
287 internal::PolicyManagerPeer policyManagerPeer(&policyManager);
288 policyManagerPeer.expectValidPowerPolicyXML(kValidPowerPolicyXmlFile);
289
290 checkSystemPowerPolicy(policyManager, kModifiedSystemPowerPolicy);
291 }
292
TEST_F(PolicyManagerTest,TestValidXml_NoPowerPolicyGroups)293 TEST_F(PolicyManagerTest, TestValidXml_NoPowerPolicyGroups) {
294 PolicyManager policyManager;
295 internal::PolicyManagerPeer policyManagerPeer(&policyManager);
296 policyManagerPeer.expectValidPowerPolicyXML(kValidPowerPolicyNoPowerPolicyGroupsXmlFile);
297
298 checkPolicies(policyManager);
299 ASSERT_FALSE(
300 policyManager
301 .getDefaultPowerPolicyForState(kValidPowerPolicyGroupId, kExistingTransition)
302 .ok());
303 ASSERT_FALSE(
304 policyManager
305 .getDefaultPowerPolicyForState(kValidPowerPolicyGroupId, kNonExistingTransition)
306 .ok());
307 checkSystemPowerPolicy(policyManager, kModifiedSystemPowerPolicy);
308 }
309
TEST_F(PolicyManagerTest,TestValidXml_NoSystemPowerPolicy)310 TEST_F(PolicyManagerTest, TestValidXml_NoSystemPowerPolicy) {
311 PolicyManager policyManager;
312 internal::PolicyManagerPeer policyManagerPeer(&policyManager);
313 policyManagerPeer.expectValidPowerPolicyXML(kValidPowerPolicyNoSystemPowerPolicyXmlFile);
314
315 checkPolicies(policyManager);
316 checkPowerPolicyGroups(policyManager);
317 checkSystemPowerPolicy(policyManager, kSystemPowerPolicyNoUserInteraction);
318 }
319
TEST_F(PolicyManagerTest,TestValidXml_PoliciesOnly)320 TEST_F(PolicyManagerTest, TestValidXml_PoliciesOnly) {
321 PolicyManager policyManager;
322 internal::PolicyManagerPeer policyManagerPeer(&policyManager);
323 policyManagerPeer.expectValidPowerPolicyXML(kValidPowerPolicyPowerPoliciesOnlyXmlFile);
324
325 checkPolicies(policyManager);
326 ASSERT_FALSE(
327 policyManager
328 .getDefaultPowerPolicyForState(kValidPowerPolicyGroupId, kExistingTransition)
329 .ok());
330 ASSERT_FALSE(
331 policyManager
332 .getDefaultPowerPolicyForState(kValidPowerPolicyGroupId, kNonExistingTransition)
333 .ok());
334 checkSystemPowerPolicy(policyManager, kSystemPowerPolicyNoUserInteraction);
335 }
336
TEST_F(PolicyManagerTest,TestValidXml_SystemPowerPolicyOnly)337 TEST_F(PolicyManagerTest, TestValidXml_SystemPowerPolicyOnly) {
338 PolicyManager policyManager;
339 internal::PolicyManagerPeer policyManagerPeer(&policyManager);
340 policyManagerPeer.expectValidPowerPolicyXML(kValidPowerPolicySystemPowerPolicyOnlyXmlFile);
341
342 ASSERT_FALSE(policyManager.getPowerPolicy(kExistingPowerPolicyId).ok());
343 ASSERT_FALSE(policyManager.getPowerPolicy(kNonExistingPowerPolicyId).ok());
344 ASSERT_FALSE(
345 policyManager
346 .getDefaultPowerPolicyForState(kValidPowerPolicyGroupId, kExistingTransition)
347 .ok());
348 ASSERT_FALSE(
349 policyManager
350 .getDefaultPowerPolicyForState(kValidPowerPolicyGroupId, kNonExistingTransition)
351 .ok());
352 checkSystemPowerPolicy(policyManager, kModifiedSystemPowerPolicy);
353 }
354
TEST_F(PolicyManagerTest,TestValidXml_TestDefaultPowerPolicyGroupId)355 TEST_F(PolicyManagerTest, TestValidXml_TestDefaultPowerPolicyGroupId) {
356 PolicyManager policyManager;
357 internal::PolicyManagerPeer policyManagerPeer(&policyManager);
358 policyManagerPeer.expectValidPowerPolicyXML(kValidPowerPolicyWithDefaultPolicyGroup);
359
360 ASSERT_TRUE(policyManager.getDefaultPolicyGroup() == kMixedPolicyGroupName);
361 }
362
TEST_F(PolicyManagerTest,TestValidXml_TestInvalidDefaultPowerPolicyGroupId)363 TEST_F(PolicyManagerTest, TestValidXml_TestInvalidDefaultPowerPolicyGroupId) {
364 PolicyManager policyManager;
365 internal::PolicyManagerPeer policyManagerPeer(&policyManager);
366 policyManagerPeer.expectValidPowerPolicyXML(kValidPowerPolicyWithInvalidDefaultPolicyGroup);
367
368 ASSERT_EQ(policyManager.getDefaultPolicyGroup(), "");
369
370 ASSERT_FALSE(
371 policyManager
372 .getDefaultPowerPolicyForState(kInvalidPowerPolicyGroupId, kExistingTransition)
373 .ok());
374 }
375
TEST_F(PolicyManagerTest,TestDefaultPowerPolicies)376 TEST_F(PolicyManagerTest, TestDefaultPowerPolicies) {
377 PolicyManager policyManager;
378 internal::PolicyManagerPeer policyManagerPeer(&policyManager);
379
380 assertDefaultPolicies(policyManager);
381 }
382
TEST_F(PolicyManagerTest,TestValidXml_DefaultPowerPolicies)383 TEST_F(PolicyManagerTest, TestValidXml_DefaultPowerPolicies) {
384 PolicyManager policyManager;
385 internal::PolicyManagerPeer policyManagerPeer(&policyManager);
386 policyManagerPeer.expectValidPowerPolicyXML(kValidPowerPolicyXmlFile);
387
388 assertDefaultPolicies(policyManager);
389 }
390
TEST_F(PolicyManagerTest,TestInvalidPowerPolicyXml)391 TEST_F(PolicyManagerTest, TestInvalidPowerPolicyXml) {
392 for (const auto& filename : kInvalidPowerPolicyXmlFiles) {
393 PolicyManager policyManager;
394 internal::PolicyManagerPeer policyManagerPeer(&policyManager);
395 policyManagerPeer.expectInvalidPowerPolicyXML(filename);
396
397 checkInvalidPolicies(policyManager);
398 }
399 }
400
TEST_F(PolicyManagerTest,TestInvalidPowerPolicyGroupXml)401 TEST_F(PolicyManagerTest, TestInvalidPowerPolicyGroupXml) {
402 for (const auto& filename : kInvalidPowerPolicyGroupXmlFiles) {
403 PolicyManager policyManager;
404 internal::PolicyManagerPeer policyManagerPeer(&policyManager);
405 policyManagerPeer.expectInvalidPowerPolicyXML(filename);
406
407 checkInvalidPolicies(policyManager);
408 }
409 }
410
TEST_F(PolicyManagerTest,TestInvalidSystemPowerPolicyXml)411 TEST_F(PolicyManagerTest, TestInvalidSystemPowerPolicyXml) {
412 for (const auto& filename : kInvalidSystemPowerPolicyXmlFiles) {
413 PolicyManager policyManager;
414 internal::PolicyManagerPeer policyManagerPeer(&policyManager);
415 policyManagerPeer.expectInvalidPowerPolicyXML(filename);
416
417 checkInvalidPolicies(policyManager);
418 }
419 }
420
TEST_F(PolicyManagerTest,TestValidXml_PowerPolicyGroupAvailable)421 TEST_F(PolicyManagerTest, TestValidXml_PowerPolicyGroupAvailable) {
422 PolicyManager policyManager;
423 internal::PolicyManagerPeer policyManagerPeer(&policyManager);
424 policyManagerPeer.expectValidPowerPolicyXML(kValidPowerPolicyXmlFile);
425
426 ASSERT_TRUE(policyManager.isPowerPolicyGroupAvailable(kValidPowerPolicyGroupId));
427 ASSERT_FALSE(policyManager.isPowerPolicyGroupAvailable(kInvalidPowerPolicyGroupId));
428 }
429
TEST_F(PolicyManagerTest,TestSystemPowerPolicyAllOn)430 TEST_F(PolicyManagerTest, TestSystemPowerPolicyAllOn) {
431 PolicyManager policyManager;
432 internal::PolicyManagerPeer policyManagerPeer(&policyManager);
433 std::unordered_set<PowerComponent> enabledComponentSet;
434 auto policyMeta = policyManager.getPowerPolicy("system_power_policy_all_on");
435
436 ASSERT_TRUE(policyMeta.ok());
437
438 CarPowerPolicyPtr systemPolicyDefault = policyMeta->powerPolicy;
439 for (const auto& component : systemPolicyDefault->enabledComponents) {
440 enabledComponentSet.insert(component);
441 }
442 for (const auto component : ::ndk::enum_range<PowerComponent>()) {
443 ASSERT_GT(enabledComponentSet.count(component), static_cast<size_t>(0));
444 enabledComponentSet.erase(component);
445 }
446
447 ASSERT_TRUE(enabledComponentSet.empty());
448 ASSERT_TRUE(systemPolicyDefault->disabledComponents.empty());
449 }
450
451 } // namespace test
452 } // namespace powerpolicy
453 } // namespace automotive
454 } // namespace frameworks
455 } // namespace android
456