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.verifier.sensors.sixdof.Utils.PoseProvider; 17 18 import android.content.Context; 19 import android.hardware.Sensor; 20 import android.hardware.SensorEvent; 21 import android.hardware.SensorEventListener; 22 import android.hardware.SensorManager; 23 24 /** 25 * Provides pose data using Android Sensors. 26 */ 27 public class AndroidPoseProvider extends PoseProvider { 28 private static final int SENSOR_TYPE_POSE = 26; //28; 29 private SensorManager mSensorManager; 30 private Sensor m6DoFSensor; 31 32 private SensorEventListener mSensorListener = new SensorEventListener() { 33 @Override 34 public void onSensorChanged(SensorEvent event) { 35 synchronized (POSE_LOCK) { 36 mLatestPoseData = new PoseData(event.values, event.timestamp); 37 } 38 39 onNewPoseData(mLatestPoseData); 40 } 41 42 @Override 43 public void onAccuracyChanged(Sensor sensor, int accuracy) { 44 } 45 }; 46 47 public AndroidPoseProvider(Context context, PoseProviderListener poseListener) { 48 super(context, poseListener); 49 mIntrinsics = new Intrinsics(); 50 } 51 52 @Override 53 public void onStartPoseProviding() { 54 mSensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE); 55 56 m6DoFSensor = mSensorManager.getDefaultSensor(SENSOR_TYPE_POSE); 57 mSensorManager.registerListener(mSensorListener, m6DoFSensor, SensorManager.SENSOR_DELAY_FASTEST); 58 } 59 60 @Override 61 public void onStopPoseProviding() { 62 mSensorManager.unregisterListener(mSensorListener); 63 } 64 65 @Override 66 public void setup() { 67 // Don't need to do anything here. 68 mPoseProviderListener.onSetupComplete(); 69 } 70 } 71