/*=========================================================================== FUNCTION loc_ni_thread_proc ===========================================================================*/ static void* loc_ni_thread_proc(void *threadid) { int rc = 0; /* return code from pthread calls */ struct timeval present_time; struct timespec expire_time; LOC_LOGD("Starting Loc NI thread...\n"); pthread_mutex_lock(&user_cb_data_mutex); /* Calculate absolute expire time */ gettimeofday(&present_time, NULL); expire_time.tv_sec = present_time.tv_sec; expire_time.tv_nsec = present_time.tv_usec * 1000; expire_time.tv_sec += loc_eng_ni_data.response_time_left; LOC_LOGD("loc_ni_thread_proc-Time out set for abs time %ld\n", (long) expire_time.tv_sec ); while (!loc_eng_ni_data.user_response_received) { rc = pthread_cond_timedwait(&user_cb_arrived_cond, &user_cb_data_mutex, &expire_time); if (rc == ETIMEDOUT) { loc_eng_ni_data.resp = RPC_LOC_NI_LCS_NOTIFY_VERIFY_NORESP; LOC_LOGD("loc_ni_thread_proc-Thread time out after valting for specified time. Ret Val %d\n",rc ); break; } } if (loc_eng_ni_data.user_response_received == TRUE) { LOC_LOGD("loc_ni_thread_proc-Java layer has sent us a user response and return value from " "pthread_cond_timedwait = %d\n",rc ); loc_eng_ni_data.user_response_received = FALSE; /* Reset the user response flag for the next session*/ } // adding this check to support modem restart, in which case, we need the thread // to exit without calling loc_ni_respond. We make sure notif_in_progress is false // in loc_ni_reset_on_modem_restart() if (loc_eng_ni_data.notif_in_progress) { loc_ni_respond(loc_eng_ni_data.resp, &loc_eng_ni_data.loc_ni_request); } pthread_mutex_unlock(&user_cb_data_mutex); pthread_mutex_lock(&loc_eng_ni_data.loc_ni_lock); loc_eng_ni_data.notif_in_progress = FALSE; loc_eng_ni_data.response_time_left = 0; loc_eng_ni_data.current_notif_id = -1; pthread_mutex_unlock(&loc_eng_ni_data.loc_ni_lock); return NULL; }
/*=========================================================================== FUNCTION loc_ni_request_handler DESCRIPTION Displays the NI request and awaits user input. If a previous request is in session, it is ignored. RETURN VALUE none ===========================================================================*/ static void loc_ni_request_handler(const char *msg, const rpc_loc_ni_event_s_type *ni_req) { GpsNiNotification notif; notif.size = sizeof(notif); strlcpy(notif.text, "[text]", sizeof notif.text); // defaults strlcpy(notif.requestor_id, "[requestor id]", sizeof notif.requestor_id); /* If busy, use default or deny */ if (loc_eng_ni_data.notif_in_progress) { #if 0 /* Cannot be here because the current thread is in RPC client */ /* XXX Consider adding an event queue to process overlapped NI requests */ loc_ni_user_resp_e_type response = sys.ni_default_resp == 1 /* accept */ ? LOC_NI_LCS_NOTIFY_VERIFY_ACCEPT : LOC_NI_LCS_NOTIFY_VERIFY_DENY; loc_ni_respond(response, ni_req); */ #endif ALOGW("loc_ni_request_handler, notification in progress, new NI request ignored, type: %d", ni_req->event); }