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 package com.android.compatibility.common.deviceinfo;
17 
18 import android.os.Build;
19 import android.os.VintfObject;
20 import android.os.VintfRuntimeInfo;
21 
22 import java.util.Arrays;
23 import java.util.Collections;
24 import java.util.Map;
25 
26 import com.android.compatibility.common.util.DeviceInfoStore;
27 
28 /**
29  * VINTF device info collector.
30  */
31 public final class VintfDeviceInfo extends DeviceInfo {
32 
33     private static final String[] sEmptyStringArray = new String[0];
34 
35     @Override
collectDeviceInfo(DeviceInfoStore store)36     protected void collectDeviceInfo(DeviceInfoStore store) throws Exception {
37         // VintfRuntimeInfo is available Android O onward.
38         if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
39            return;
40         }
41         store.addResult("cpu_info", VintfRuntimeInfo.getCpuInfo());
42         store.addResult("os_name", VintfRuntimeInfo.getOsName());
43         store.addResult("node_name", VintfRuntimeInfo.getNodeName());
44         store.addResult("os_release", VintfRuntimeInfo.getOsRelease());
45         store.addResult("os_version", VintfRuntimeInfo.getOsVersion());
46         store.addResult("hardware_id", VintfRuntimeInfo.getHardwareId());
47         store.addResult("kernel_version", VintfRuntimeInfo.getKernelVersion());
48         store.addResult("sepolicy_version", VintfObject.getSepolicyVersion());
49 
50         String[] hals = VintfObject.getHalNamesAndVersions();
51         store.addListResult("hals", hals == null
52                 ? Collections.emptyList() : Arrays.<String>asList(hals));
53 
54         Map<String, String[]> vndks = VintfObject.getVndkSnapshots();
55         if (vndks == null) vndks = Collections.emptyMap();
56         store.startArray("vndk_snapshots");
57         for (Map.Entry<String, String[]> e : vndks.entrySet()) {
58             store.startGroup();
59             store.addResult("version", e.getKey());
60             String[] libraries = e.getValue();
61             store.addListResult("libraries", libraries == null
62                     ? Collections.emptyList() : Arrays.<String>asList(libraries));
63             store.endGroup();
64         }
65         store.endArray();
66 
67         // getTargetFrameworkCompatibilityMatrixVersion is available Android P onward.
68         // (Use O_MR1 until P is released.)
69         if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.O_MR1) {
70            return;
71         }
72         Long version = VintfObject.getTargetFrameworkCompatibilityMatrixVersion();
73         if (version != null) {
74             store.addResult("target_fcm_version", version);
75         }
76     }
77 }
78