1 /* 2 * Copyright 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 17 #include "hal_gps.h" 18 19 #include <pthread.h> 20 #include <stdlib.h> 21 22 #include <hardware/gps.h> 23 24 #include "vts_datatype.h" 25 26 namespace android { 27 namespace vts { 28 29 // Callbacks { 30 static void vts_gps_location_callback(GpsLocation* /*location*/) {} 31 static void vts_gps_status_callback(GpsStatus* /*status*/) {} 32 static void vts_gps_sv_status_callback(GpsSvStatus* /*sv_info*/) {} 33 static void vts_gps_nmea_callback( 34 GpsUtcTime /*timestamp*/, const char* /*nmea*/, int /*length*/) {} 35 static void vts_gps_set_capabilities(uint32_t /*capabilities*/) {} 36 static void vts_gps_acquire_wakelock() {} 37 static void vts_gps_release_wakelock() {} 38 static void vts_gps_request_utc_time() {} 39 40 static pthread_t vts_gps_create_thread( 41 const char* /*name*/, void (*/*start*/)(void*), void* /*arg*/) { 42 return (pthread_t)NULL; 43 } 44 // } Callbacks 45 46 GpsCallbacks* GenerateGpsCallbacks() { 47 if (RandomBool()) { 48 return NULL; 49 } else { 50 GpsCallbacks* cbs = (GpsCallbacks*)malloc(sizeof(GpsCallbacks)); 51 cbs->size = sizeof(GpsCallbacks); 52 cbs->location_cb = vts_gps_location_callback; 53 cbs->status_cb = vts_gps_status_callback; 54 cbs->sv_status_cb = vts_gps_sv_status_callback; 55 cbs->nmea_cb = vts_gps_nmea_callback; 56 cbs->set_capabilities_cb = vts_gps_set_capabilities; 57 cbs->acquire_wakelock_cb = vts_gps_acquire_wakelock; 58 cbs->release_wakelock_cb = vts_gps_release_wakelock; 59 cbs->create_thread_cb = vts_gps_create_thread; 60 cbs->request_utc_time_cb = vts_gps_request_utc_time; 61 62 return cbs; 63 } 64 } 65 66 GpsUtcTime /*int64_t*/ GenerateGpsUtcTime() { 67 // TOOD: consider returning the current time + a random number. 68 return RandomInt64(); 69 } 70 71 double GenerateLatitude() { return 10.0; } 72 73 double GenerateLongitude() { return 20.0; } 74 75 float GenerateGpsAccuracy() { return 5.0; } 76 77 uint16_t GenerateGpsFlagsUint16() { return 1; } 78 79 GpsPositionMode /*uint32_t*/ GenerateGpsPositionMode() { 80 if (RandomBool()) { 81 return RandomUint32(); 82 } else { 83 if (RandomBool()) { 84 return GPS_POSITION_MODE_STANDALONE; 85 } else if (RandomBool()) { 86 return GPS_POSITION_MODE_MS_BASED; 87 } else { 88 return GPS_POSITION_MODE_MS_ASSISTED; 89 } 90 } 91 return RandomUint32(); 92 } 93 94 GpsPositionRecurrence /*uint32_t*/ GenerateGpsPositionRecurrence() { 95 if (RandomBool()) { 96 return RandomUint32(); 97 } else { 98 if (RandomBool()) { 99 return GPS_POSITION_RECURRENCE_PERIODIC; 100 } else { 101 return GPS_POSITION_RECURRENCE_SINGLE; 102 } 103 } 104 } 105 106 // TODO: add generators for min_interval, preferred_accuracy, and preferred_time 107 // all uint32_t. 108 109 } // namespace vts 110 } // namespace android 111