• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <libvts_vintf_test_common/common.h>
18 
19 namespace android::vintf::testing {
20 
21 // kApiLevel2FcmMap is associated with API level. There can be multiple
22 // Framework Compatibility Matrix Version (FCM Version) per API level, or
23 // multiple API levels per FCM version.
24 // kApiLevel2FcmMap is defined apart from android::vintf::Level. Level is an
25 // integer designed to be irrelevant with API level; the O / O_MR1 values are
26 // historic values for convenience, and should be removed (b/70628538). Hence
27 // these values are not used here.
28 // For example:
29 //    ...
30 //    // Assume devices launch with Android X must implement FCM version >= 9
31 //    X = 9,
32 //    // Assume devices launch with Android Y and Android Z must implement
33 //    // FCM version >= 11
34 //    Y = 11,
35 //    Z = 11
36 static const std::map<uint64_t /* Vendor API Level */, Level /* FCM Version */>
37     kApiLevel2FcmMap{{
38         // N. The test runs on devices that launch with N and
39         // become a Treble device when upgrading to O.
40         {25, Level::O},
41 
42         {26, Level::O},
43         {27, Level::O_MR1},
44         {28, Level::P},
45         {29, Level::Q},
46         {30, Level::R},
47         {31, Level::S},
48         {32, Level::S},
49         {33, Level::T},
50         {34, Level::U},  // subject to change, placeholder value
51     }};
52 
GetFcmVersionFromApiLevel(uint64_t api_level)53 android::base::Result<Level> GetFcmVersionFromApiLevel(uint64_t api_level) {
54   auto it = android::vintf::testing::kApiLevel2FcmMap.find(api_level);
55   if (it == android::vintf::testing::kApiLevel2FcmMap.end()) {
56     return android::base::Error()
57            << "Can't find corresponding VINTF level for API level " << api_level
58            << ". Is the test updated?";
59   }
60   return it->second;
61 }
62 
TestTargetFcmVersion(Level target_fcm_version,uint64_t vendor_api_level)63 android::base::Result<void> TestTargetFcmVersion(Level target_fcm_version,
64                                                  uint64_t vendor_api_level) {
65   if (vendor_api_level == 0u) {
66     return android::base::Error()
67            << "Device's vendor API level cannot be determined.";
68   }
69 
70   if (target_fcm_version == Level::UNSPECIFIED) {
71     // O / O-MR1 vendor image doesn't have target FCM version declared and
72     // target FCM version is inferred from vendor API level, hence it always
73     // meets the requirement.
74     if (vendor_api_level <= 27) {  // O-MR1
75       return {};
76     }
77     return android::base::Error() << "Target FCM version (device manifest "
78                                      "target-level) must be set for "
79                                      "device with vendor api level "
80                                   << vendor_api_level;
81   }
82 
83   if (vendor_api_level < kApiLevel2FcmMap.begin()->first /* 25 */) {
84     return android::base::Error() << "Pre-N devices should not run this test.";
85   }
86 
87   auto it = kApiLevel2FcmMap.find(vendor_api_level);
88   if (it == kApiLevel2FcmMap.end()) {
89     return android::base::Error()
90            << "No launch requirement is set yet for vendor API level "
91            << vendor_api_level << ". Please update the test.";
92   }
93 
94   Level required_fcm_version = it->second;
95   if (target_fcm_version < required_fcm_version) {
96     return android::base::Error()
97            << "Vendor API level == " << vendor_api_level
98            << " requires Target FCM Version >= " << required_fcm_version
99            << " (but is " << target_fcm_version << ")";
100   }
101 
102   return {};
103 }
104 
105 }  // namespace android::vintf::testing
106