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 package com.android.compatibility.common.deviceinfo;
17 
18 import com.android.compatibility.common.util.DeviceInfoStore;
19 import com.android.compatibility.common.util.SystemUtil;
20 
21 /**
22  * A device info collector that collects whether device-idle was enabled or not on the device.
23  */
24 public final class DeviceIdleDeviceInfo extends DeviceInfo {
25     private static final String KEY_DEVICE_IDLE_DEEP_ENABLED = "device_idle_deep_enabled";
26     private static final String KEY_DEVICE_IDLE_LIGHT_ENABLED = "device_idle_light_enabled";
27 
isDeviceIdleEnabled()28     private static boolean isDeviceIdleEnabled() throws Exception {
29         final String output = SystemUtil.runShellCommand("cmd deviceidle enabled deep").trim();
30         return Integer.parseInt(output) != 0;
31     }
32 
isDeviceLightIdleEnabled()33     private static boolean isDeviceLightIdleEnabled() throws Exception {
34         final String output = SystemUtil.runShellCommand("cmd deviceidle enabled light").trim();
35         return Integer.parseInt(output) != 0;
36     }
37 
38     @Override
collectDeviceInfo(DeviceInfoStore store)39     protected void collectDeviceInfo(DeviceInfoStore store) throws Exception {
40         store.addResult(KEY_DEVICE_IDLE_DEEP_ENABLED, isDeviceIdleEnabled());
41         store.addResult(KEY_DEVICE_IDLE_LIGHT_ENABLED, isDeviceLightIdleEnabled());
42     }
43 }
44