1 /*
2  * Copyright (C) 2023 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 package com.android.compatibility.common.deviceinfo;
18 
19 import android.content.res.Resources;
20 import android.util.Log;
21 import android.util.TypedValue;
22 
23 import com.android.compatibility.common.util.DeviceInfoStore;
24 
25 /**
26  * Media output information collector.
27  */
28 public final class MediaOutputDeviceInfo extends DeviceInfo {
29     private static final String TAG = "MediaOutputDeviceInfo";
30 
31     @Override
collectDeviceInfo(DeviceInfoStore store)32     protected void collectDeviceInfo(DeviceInfoStore store) throws Exception {
33         int outputSwitcherVersion = 0;
34         int identifier =
35                 Resources.getSystem()
36                         .getIdentifier("config_mediaOutputSwitchDialogVersion", "integer",
37                                 "android");
38         try {
39             if (identifier != 0) {
40                 TypedValue typedValue = new TypedValue();
41                 Resources.getSystem().getValue(identifier, typedValue, true);
42                 if (typedValue.type == TypedValue.TYPE_INT_DEC
43                         || typedValue.type == TypedValue.TYPE_INT_HEX) {
44                     outputSwitcherVersion = typedValue.data;
45                 }
46             }
47         } catch (Resources.NotFoundException e) {
48             Log.w(TAG, "failed to get media output version", e);
49         }
50         store.addResult("media_output_switch_dialog_version", outputSwitcherVersion);
51     }
52 }
53