From 623f5a6fc56486d07f7972b5c6d3c294fde5438c Mon Sep 17 00:00:00 2001 From: Kevin Tang Date: Mon, 19 Jan 2015 16:22:28 -0800 Subject: [PATCH] adding dev id into xtra user agent setting XTRA_USER_AGENT at GPS HAL init time, incorporating Android sw version, manufacturer, model, board. CRs-Fixed: 788356 Change-Id: I8d9dcc80a0769796a25a0477f5f1598a292fe8b0 --- core/ContextBase.h | 5 +- core/LBSProxyBase.h | 3 +- core/gps_extended_c.h | 2 + loc_api/libloc_api_50001/LocEngAdapter.cpp | 71 +++++++++++++++++++++- loc_api/libloc_api_50001/LocEngAdapter.h | 3 +- loc_api/libloc_api_50001/loc.cpp | 3 +- 6 files changed, 82 insertions(+), 5 deletions(-) diff --git a/core/ContextBase.h b/core/ContextBase.h index ff7a4b33..fe0b8606 100644 --- a/core/ContextBase.h +++ b/core/ContextBase.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved. +/* Copyright (c) 2011-2015, The Linux Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -63,6 +63,9 @@ public: unsigned long capabilities) { mLBSProxy->requestUlp(adapter, capabilities); } + inline IzatDevId_t getIzatDevId() const { + return mLBSProxy->getIzatDevId(); + } inline void sendMsg(const LocMsg *msg) { getMsgTask()->sendMsg(msg); } }; diff --git a/core/LBSProxyBase.h b/core/LBSProxyBase.h index 75ae9922..0faf8012 100644 --- a/core/LBSProxyBase.h +++ b/core/LBSProxyBase.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved. +/* Copyright (c) 2013-2015, The Linux Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -55,6 +55,7 @@ public: inline virtual bool hasCPIExtendedCapabilities() const { return false; } inline virtual void modemPowerVote(bool power) const {} virtual void injectFeatureConfig(ContextBase* context) const {} + inline virtual IzatDevId_t getIzatDevId() const { return 0; } }; typedef LBSProxyBase* (getLBSProxy_t)(); diff --git a/core/gps_extended_c.h b/core/gps_extended_c.h index 05730146..06764cf3 100644 --- a/core/gps_extended_c.h +++ b/core/gps_extended_c.h @@ -400,6 +400,8 @@ typedef enum loc_api_adapter_msg_to_check_supported { LOC_API_ADAPTER_MESSAGE_MAX } LocCheckingMessagesID; +typedef int IzatDevId_t; + typedef uint32_t LOC_GPS_LOCK_MASK; #define isGpsLockNone(lock) ((lock) == 0) #define isGpsLockMO(lock) ((lock) & ((LOC_GPS_LOCK_MASK)1)) diff --git a/loc_api/libloc_api_50001/LocEngAdapter.cpp b/loc_api/libloc_api_50001/LocEngAdapter.cpp index fd6f9b09..1afa0a8c 100644 --- a/loc_api/libloc_api_50001/LocEngAdapter.cpp +++ b/loc_api/libloc_api_50001/LocEngAdapter.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved. +/* Copyright (c) 2011-2015, The Linux Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -29,10 +29,13 @@ #define LOG_NDDEBUG 0 #define LOG_TAG "LocSvc_EngAdapter" +#include #include #include "loc_eng_msg.h" #include "loc_log.h" +#define CHIPSET_SERIAL_NUMBER_MAX_LEN 16 + using namespace loc_core; LocInternalAdapter::LocInternalAdapter(LocEngAdapter* adapter) : @@ -82,6 +85,72 @@ LocEngAdapter::~LocEngAdapter() LOC_LOGV("LocEngAdapter deleted"); } +void LocEngAdapter::setXtraUserAgent() { + struct LocSetXtraUserAgent : public LocMsg { + const ContextBase* const mContext; + inline LocSetXtraUserAgent(ContextBase* context) : + LocMsg(), mContext(context) { + } + virtual void proc() const { + char release[PROPERTY_VALUE_MAX]; + char manufacture[PROPERTY_VALUE_MAX]; + char model[PROPERTY_VALUE_MAX]; + char carrier[PROPERTY_VALUE_MAX]; + char board[PROPERTY_VALUE_MAX]; + char brand[PROPERTY_VALUE_MAX]; + char chipsetsn[CHIPSET_SERIAL_NUMBER_MAX_LEN]; + char userAgent[PROPERTY_VALUE_MAX]; + const char defVal[] = "-"; + + property_get("ro.build.version.release", release, defVal); + property_get("ro.product.manufacturer", manufacture, defVal); + property_get("ro.product.model", model, defVal); + property_get("ro.carrier", carrier, defVal); + property_get("ro.product.board", board, defVal); + property_get("ro.product.brand", brand, defVal); + getChipsetSerialNo(chipsetsn, sizeof(chipsetsn), defVal); + + snprintf(userAgent, sizeof(userAgent), "A/%s/%s/%s/%s/%s/QCX3/s%u/-/%s/-/%s/-/-/-", + release, manufacture, model, board, carrier, + mContext->getIzatDevId(), chipsetsn, brand); + + for (int i = 0; i < sizeof(userAgent) && userAgent[i]; i++) { + if (' ' == userAgent[i]) userAgent[i] = '#'; + } + + property_set("location.XTRA_USER_AGENT", userAgent); + LOC_LOGV("%s] UserAgent %s", __func__, userAgent); + } + + void getChipsetSerialNo(char buf[], int buflen, const char def[]) const { + const char SOC_SERIAL_NUMBER[] = "/sys/devices/soc0/serial_number"; + + FILE* file = fopen(SOC_SERIAL_NUMBER, "rt"); + if (file == NULL) { + // use default upon unreadable file + strlcpy(buf, def, buflen); + + } else { + size_t size = fread(buf, 1, buflen - 1, file); + if (size == 0) { + // use default upon empty file + strlcpy(buf, def, buflen); + + } else { + buf[size] = '\0'; + } + + fclose(file); + } + + return; + } + + }; + + sendMsg(new LocSetXtraUserAgent(mContext)); +} + void LocInternalAdapter::setUlpProxy(UlpProxyBase* ulp) { struct LocSetUlpProxy : public LocMsg { LocAdapterBase* mAdapter; diff --git a/loc_api/libloc_api_50001/LocEngAdapter.h b/loc_api/libloc_api_50001/LocEngAdapter.h index 9e01b98c..b119d990 100644 --- a/loc_api/libloc_api_50001/LocEngAdapter.h +++ b/loc_api/libloc_api_50001/LocEngAdapter.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved. +/* Copyright (c) 2011-2015, The Linux Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -92,6 +92,7 @@ public: virtual ~LocEngAdapter(); virtual void setUlpProxy(UlpProxyBase* ulp); + void setXtraUserAgent(); inline void requestUlp(unsigned long capabilities) { mContext->requestUlp(mInternalAdapter, capabilities); } diff --git a/loc_api/libloc_api_50001/loc.cpp b/loc_api/libloc_api_50001/loc.cpp index a1ae9933..f7d7cb45 100644 --- a/loc_api/libloc_api_50001/loc.cpp +++ b/loc_api/libloc_api_50001/loc.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved. +/* Copyright (c) 2011-2015, The Linux Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -313,6 +313,7 @@ static int loc_init(GpsCallbacks* callbacks) loc_afw_data.adapter->mSupportsTimeInjection = !loc_afw_data.adapter->hasCPIExtendedCapabilities(); loc_afw_data.adapter->setGpsLockMsg(0); loc_afw_data.adapter->requestUlp(getCarrierCapabilities()); + loc_afw_data.adapter->setXtraUserAgent(); if(retVal) { LOC_LOGE("loc_eng_init() fail!");