1 /*
2 * Copyright (C) 2017 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 "utils-fake.h"
18
19 namespace android {
20 namespace vintf {
21 namespace details {
22
MockRuntimeInfo()23 MockRuntimeInfo::MockRuntimeInfo() {
24 kernel_info_.mVersion = {3, 18, 31};
25 kernel_info_.mConfigs = {{"CONFIG_64BIT", "y"},
26 {"CONFIG_ANDROID_BINDER_DEVICES", "\"binder,hwbinder\""},
27 {"CONFIG_ARCH_MMAP_RND_BITS", "24"},
28 {"CONFIG_BUILD_ARM64_APPENDED_DTB_IMAGE_NAMES", "\"\""},
29 {"CONFIG_ILLEGAL_POINTER_VALUE", "0xdead000000000000"}};
30 ON_CALL(*this, fetchAllInformation(_)).WillByDefault(Invoke(this, &MockRuntimeInfo::doFetch));
31 }
32
doFetch(RuntimeInfo::FetchFlags flags)33 status_t MockRuntimeInfo::doFetch(RuntimeInfo::FetchFlags flags) {
34 if (failNextFetch_) {
35 failNextFetch_ = false;
36 return android::UNKNOWN_ERROR;
37 }
38
39 if (flags & RuntimeInfo::FetchFlag::CPU_VERSION) {
40 mOsName = "Linux";
41 mNodeName = "localhost";
42 mOsRelease = "3.18.31-g936f9a479d0f";
43 mOsVersion = "#4 SMP PREEMPT Wed Feb 1 18:10:52 PST 2017";
44 mHardwareId = "aarch64";
45 mKernel.mVersion = kernel_info_.mVersion;
46 }
47
48 if (flags & RuntimeInfo::FetchFlag::KERNEL_FCM && kernel_info_.mLevel != Level::UNSPECIFIED) {
49 mKernel.mLevel = kernel_info_.mLevel;
50 }
51
52 if (flags & RuntimeInfo::FetchFlag::POLICYVERS) {
53 mKernelSepolicyVersion = 30;
54 }
55
56 if (flags & RuntimeInfo::FetchFlag::CONFIG_GZ) {
57 mKernel.mConfigs = kernel_info_.mConfigs;
58 }
59 // fetchAllInformtion does not fetch kernel FCM version
60 return OK;
61 }
setNextFetchKernelInfo(KernelVersion && v,std::map<std::string,std::string> && configs)62 void MockRuntimeInfo::setNextFetchKernelInfo(KernelVersion&& v,
63 std::map<std::string, std::string>&& configs) {
64 kernel_info_.mVersion = std::move(v);
65 kernel_info_.mConfigs = std::move(configs);
66 }
setNextFetchKernelInfo(const KernelVersion & v,const std::map<std::string,std::string> & configs)67 void MockRuntimeInfo::setNextFetchKernelInfo(const KernelVersion& v,
68 const std::map<std::string, std::string>& configs) {
69 kernel_info_.mVersion = v;
70 kernel_info_.mConfigs = configs;
71 }
setNextFetchKernelLevel(Level level)72 void MockRuntimeInfo::setNextFetchKernelLevel(Level level) {
73 kernel_info_.mLevel = level;
74 }
75
76 } // namespace details
77 } // namespace vintf
78 } // namespace android
79