1 /*
2  * Copyright (C) 2019 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.util.Log;
19 
20 import com.android.compatibility.common.util.DeviceInfoStore;
21 import com.android.compatibility.common.util.PropertyUtil;
22 
23 import java.io.IOException;
24 import java.util.Map;
25 
26 /**
27  * Client ID info collector.
28  */
29 public final class ClientIdDeviceInfo extends DeviceInfo {
30 
31     private static final String LOG_TAG = "ClientIdDeviceInfo";
32 
33     @Override
collectDeviceInfo(DeviceInfoStore store)34     protected void collectDeviceInfo(DeviceInfoStore store) throws Exception {
35         try {
36             collectClientIds(store);
37         } catch (IOException e) {
38             Log.w(LOG_TAG, "Failed to collect client IDs", e);
39         }
40     }
41 
collectClientIds(DeviceInfoStore store)42     private void collectClientIds(DeviceInfoStore store) throws IOException {
43         store.startArray("client_id");
44         Map<String, String> clientIds = PropertyUtil.getClientIds();
45         for (String name : clientIds.keySet()) {
46             store.startGroup();
47             store.addResult("name", name);
48             store.addResult("value", clientIds.get(name));
49             store.endGroup();
50         }
51         store.endArray();
52     }
53 }
54