1 /*
2  * Copyright (C) 2021 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 <android-base/properties.h>
18 #include <android/hardware/automotive/vehicle/2.0/IVehicle.h>
19 #include <gtest/gtest.h>
20 
21 namespace android {
22 namespace automotive {
23 namespace security {
24 namespace {
25 
26 using android::hardware::automotive::vehicle::V2_0::IVehicle;
27 using android::hardware::automotive::vehicle::V2_0::StatusCode;
28 using android::hardware::automotive::vehicle::V2_0::VehiclePropConfig;
29 using android::hardware::automotive::vehicle::V2_0::VehicleProperty;
30 
31 template <typename T>
32 using hidl_vec = android::hardware::hidl_vec<T>;
33 
isSeedVhalPropertySupported(sp<IVehicle> vehicle)34 bool isSeedVhalPropertySupported(sp<IVehicle> vehicle) {
35     bool is_supported = false;
36 
37     hidl_vec<int32_t> props = {
38             static_cast<int32_t>(VehicleProperty::STORAGE_ENCRYPTION_BINDING_SEED)};
39     vehicle->getPropConfigs(props,
40                             [&is_supported](StatusCode status,
41                                             hidl_vec<VehiclePropConfig> /*propConfigs*/) {
42                                 is_supported = (status == StatusCode::OK);
43                             });
44     return is_supported;
45 }
46 
47 // Verify that vold got the binding seed if VHAL reports a seed
TEST(VehicleBindingIntegrationTedt,TestVehicleBindingSeedSet)48 TEST(VehicleBindingIntegrationTedt, TestVehicleBindingSeedSet) {
49     std::string expected_value = "1";
50     if (!isSeedVhalPropertySupported(IVehicle::getService())) {
51         GTEST_LOG_(INFO) << "Device does not support vehicle binding seed "
52                             "(STORAGE_ENCRYPTION_BINDING_SEED).";
53         expected_value = "";
54     }
55 
56     ASSERT_EQ(expected_value, android::base::GetProperty("vold.storage_seed_bound", ""));
57 }
58 
59 }  // namespace
60 }  // namespace security
61 }  // namespace automotive
62 }  // namespace android
63