1 /* 2 * Copyright (C) 2016 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.cts.deviceinfo; 17 18 import android.content.Context; 19 import android.hardware.Sensor; 20 import android.hardware.SensorManager; 21 import android.os.Bundle; 22 23 import com.android.compatibility.common.deviceinfo.DeviceInfo; 24 import com.android.compatibility.common.util.DeviceInfoStore; 25 26 import java.lang.Exception; 27 import java.util.Arrays; 28 import java.util.List; 29 30 /** 31 * Sensor device info collector. 32 */ 33 public class SensorDeviceInfo extends DeviceInfo { 34 35 private static final String SENSOR = "sensor"; 36 private static final String REPORTING_MODE = "reporting_mode"; 37 private static final String NAME = "name"; 38 private static final String VENDOR = "vendor"; 39 private static final String TYPE = "type"; 40 private static final String VERSION = "version"; 41 private static final String MAXIMUM_RANGE = "maximum_range"; 42 private static final String RESOLUTION = "resolution"; 43 private static final String POWER = "power"; 44 private static final String MIN_DELAY = "min_delay"; 45 private static final String FIFO_RESERVED_EVENT_COUNT = 46 "fifo_reserved_event_count"; 47 private static final String FIFO_MAX_EVENT_COUNT = "fifo_max_event_count"; 48 private static final String STRING_TYPE = "string_type"; 49 private static final String ID = "id"; 50 private static final String MAX_DELAY = "max_delay"; 51 private static final String IS_WAKE_UP_SENSOR = "is_wake_up_sensor"; 52 private static final String IS_DYNAMIC_SENSOR = "is_dynamic_sensor"; 53 private static final String IS_ADDITONAL_INFO_SUPPORTED = 54 "is_additional_info_supported"; 55 56 @Override collectDeviceInfo(DeviceInfoStore store)57 protected void collectDeviceInfo(DeviceInfoStore store) throws Exception { 58 SensorManager sensorManager = (SensorManager) 59 getContext().getSystemService(Context.SENSOR_SERVICE); 60 List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ALL); 61 store.startArray(SENSOR); 62 for (Sensor sensor : sensors) { 63 store.startGroup(); 64 store.addResult(REPORTING_MODE, sensor.getReportingMode()); 65 store.addResult(NAME, sensor.getName()); 66 store.addResult(VENDOR, sensor.getVendor()); 67 store.addResult(TYPE, sensor.getType()); 68 store.addResult(VERSION, sensor.getVersion()); 69 store.addResult(MAXIMUM_RANGE, sensor.getMaximumRange()); 70 store.addResult(RESOLUTION, sensor.getResolution()); 71 store.addResult(POWER, sensor.getPower()); 72 store.addResult(MIN_DELAY, sensor.getMinDelay()); 73 store.addResult(FIFO_RESERVED_EVENT_COUNT, 74 sensor.getFifoReservedEventCount()); 75 store.addResult(FIFO_MAX_EVENT_COUNT, 76 sensor.getFifoMaxEventCount()); 77 store.addResult(STRING_TYPE, sensor.getStringType()); 78 store.addResult(ID, sensor.getId()); 79 store.addResult(MAX_DELAY, sensor.getMaxDelay()); 80 store.addResult(IS_WAKE_UP_SENSOR, sensor.isWakeUpSensor()); 81 store.addResult(IS_DYNAMIC_SENSOR, sensor.isDynamicSensor()); 82 store.addResult(IS_ADDITONAL_INFO_SUPPORTED, 83 sensor.isAdditionalInfoSupported()); 84 store.endGroup(); 85 } 86 store.endArray(); // Sensor 87 } 88 } 89