Merge "Add XSSO support for multiple network handles"

This commit is contained in:
qctecmdr 2019-07-09 10:25:05 -07:00 committed by Gerrit - the friendly Code Review server
commit a4c0207725
6 changed files with 168 additions and 52 deletions

View file

@ -57,29 +57,29 @@ Return<bool> AGnssRil::updateNetworkState(bool connected, NetworkType type, bool
// for XTRA // for XTRA
if (nullptr != mGnss && ( nullptr != mGnss->getGnssInterface() )) { if (nullptr != mGnss && ( nullptr != mGnss->getGnssInterface() )) {
int8_t typeout = loc_core::NetworkInfoDataItemBase::TYPE_UNKNOWN; int8_t typeout = loc_core::TYPE_UNKNOWN;
switch(type) switch(type)
{ {
case IAGnssRil::NetworkType::MOBILE: case IAGnssRil::NetworkType::MOBILE:
typeout = loc_core::NetworkInfoDataItemBase::TYPE_MOBILE; typeout = loc_core::TYPE_MOBILE;
break; break;
case IAGnssRil::NetworkType::WIFI: case IAGnssRil::NetworkType::WIFI:
typeout = loc_core::NetworkInfoDataItemBase::TYPE_WIFI; typeout = loc_core::TYPE_WIFI;
break; break;
case IAGnssRil::NetworkType::MMS: case IAGnssRil::NetworkType::MMS:
typeout = loc_core::NetworkInfoDataItemBase::TYPE_MMS; typeout = loc_core::TYPE_MMS;
break; break;
case IAGnssRil::NetworkType::SUPL: case IAGnssRil::NetworkType::SUPL:
typeout = loc_core::NetworkInfoDataItemBase::TYPE_SUPL; typeout = loc_core::TYPE_SUPL;
break; break;
case IAGnssRil::NetworkType::DUN: case IAGnssRil::NetworkType::DUN:
typeout = loc_core::NetworkInfoDataItemBase::TYPE_DUN; typeout = loc_core::TYPE_DUN;
break; break;
case IAGnssRil::NetworkType::HIPRI: case IAGnssRil::NetworkType::HIPRI:
typeout = loc_core::NetworkInfoDataItemBase::TYPE_HIPRI; typeout = loc_core::TYPE_HIPRI;
break; break;
case IAGnssRil::NetworkType::WIMAX: case IAGnssRil::NetworkType::WIMAX:
typeout = loc_core::NetworkInfoDataItemBase::TYPE_WIMAX; typeout = loc_core::TYPE_WIMAX;
break; break;
default: default:
{ {
@ -88,16 +88,16 @@ Return<bool> AGnssRil::updateNetworkState(bool connected, NetworkType type, bool
switch(networkType) switch(networkType)
{ {
case NetworkType_BLUETOOTH: case NetworkType_BLUETOOTH:
typeout = loc_core::NetworkInfoDataItemBase::TYPE_BLUETOOTH; typeout = loc_core::TYPE_BLUETOOTH;
break; break;
case NetworkType_ETHERNET: case NetworkType_ETHERNET:
typeout = loc_core::NetworkInfoDataItemBase::TYPE_ETHERNET; typeout = loc_core::TYPE_ETHERNET;
break; break;
case NetworkType_PROXY: case NetworkType_PROXY:
typeout = loc_core::NetworkInfoDataItemBase::TYPE_PROXY; typeout = loc_core::TYPE_PROXY;
break; break;
default: default:
typeout = loc_core::NetworkInfoDataItemBase::TYPE_UNKNOWN; typeout = loc_core::TYPE_UNKNOWN;
} }
} }
break; break;
@ -110,12 +110,12 @@ Return<bool> AGnssRil::updateNetworkState_2_0(const V2_0::IAGnssRil::NetworkAttr
ENTRY_LOG_CALLFLOW(); ENTRY_LOG_CALLFLOW();
if (nullptr != mGnss && (nullptr != mGnss->getGnssInterface())) { if (nullptr != mGnss && (nullptr != mGnss->getGnssInterface())) {
int8_t typeout = loc_core::NetworkInfoDataItemBase::TYPE_UNKNOWN; int8_t typeout = loc_core::TYPE_UNKNOWN;
bool roaming = false; bool roaming = false;
if (attributes.capabilities & IAGnssRil::NetworkCapability::NOT_METERED) { if (attributes.capabilities & IAGnssRil::NetworkCapability::NOT_METERED) {
typeout = loc_core::NetworkInfoDataItemBase::TYPE_WIFI; typeout = loc_core::TYPE_WIFI;
} else { } else {
typeout = loc_core::NetworkInfoDataItemBase::TYPE_MOBILE; typeout = loc_core::TYPE_MOBILE;
} }
if (attributes.capabilities & IAGnssRil::NetworkCapability::NOT_ROAMING) { if (attributes.capabilities & IAGnssRil::NetworkCapability::NOT_ROAMING) {
roaming = false; roaming = false;

View file

@ -501,19 +501,67 @@ public:
mType = itemBase.getType(); mType = itemBase.getType();
} }
inline bool equals(const SystemStatusNetworkInfo& peer) { inline bool equals(const SystemStatusNetworkInfo& peer) {
return (mAllTypes == peer.mAllTypes); for (uint8_t i = 0; i < MAX_NETWORK_HANDLES; ++i) {
if (!(mAllNetworkHandles[i] == peer.mAllNetworkHandles[i])) {
return false;
}
}
return true;
} }
inline virtual SystemStatusItemBase& collate(SystemStatusItemBase& curInfo) { inline virtual SystemStatusItemBase& collate(SystemStatusItemBase& curInfo) {
uint64_t allTypes = (static_cast<SystemStatusNetworkInfo&>(curInfo)).mAllTypes; uint64_t allTypes = (static_cast<SystemStatusNetworkInfo&>(curInfo)).mAllTypes;
uint64_t networkHandle = uint64_t networkHandle =
(static_cast<SystemStatusNetworkInfo&>(curInfo)).mNetworkHandle; (static_cast<SystemStatusNetworkInfo&>(curInfo)).mNetworkHandle;
int32_t type = (static_cast<SystemStatusNetworkInfo&>(curInfo)).mType; int32_t type = (static_cast<SystemStatusNetworkInfo&>(curInfo)).mType;
// Replace current with cached table for now and then update
memcpy(mAllNetworkHandles,
(static_cast<SystemStatusNetworkInfo&>(curInfo)).getNetworkHandle(),
sizeof(mAllNetworkHandles));
if (mConnected) { if (mConnected) {
mAllTypes |= allTypes; mAllTypes |= allTypes;
mAllNetworkHandles[type] = networkHandle; for (uint8_t i = 0; i < MAX_NETWORK_HANDLES; ++i) {
if (mNetworkHandle == mAllNetworkHandles[i].networkHandle) {
LOC_LOGD("collate duplicate detected, not updating");
break;
}
if (NETWORK_HANDLE_UNKNOWN == mAllNetworkHandles[i].networkHandle) {
mAllNetworkHandles[i].networkHandle = mNetworkHandle;
mAllNetworkHandles[i].networkType = (loc_core::NetworkType) mType;
break;
}
}
} else if (0 != mAllTypes) { } else if (0 != mAllTypes) {
mAllTypes = (allTypes & (~mAllTypes)); uint8_t deletedIndex = MAX_NETWORK_HANDLES;
mAllNetworkHandles[type] = NETWORK_HANDLE_UNKNOWN; uint8_t lastValidIndex = 0;
uint8_t typeCount = 0;
for (; lastValidIndex < MAX_NETWORK_HANDLES &&
NETWORK_HANDLE_UNKNOWN != mAllNetworkHandles[lastValidIndex].networkHandle;
++lastValidIndex) {
// Maintain count for number of network handles still
// connected for given type
if (mType == mAllNetworkHandles[lastValidIndex].networkType) {
typeCount++;
}
if (mNetworkHandle == mAllNetworkHandles[lastValidIndex].networkHandle) {
deletedIndex = lastValidIndex;
typeCount--;
}
}
if (MAX_NETWORK_HANDLES != deletedIndex) {
LOC_LOGD("deletedIndex:%u, lastValidIndex:%u, typeCount:%u",
deletedIndex, lastValidIndex, typeCount);
mAllNetworkHandles[deletedIndex] = mAllNetworkHandles[lastValidIndex];
mAllNetworkHandles[lastValidIndex].networkHandle = NETWORK_HANDLE_UNKNOWN;
mAllNetworkHandles[lastValidIndex].networkType = TYPE_UNKNOWN;
}
// If no more handles of given type, set bitmask
if (0 == typeCount) {
mAllTypes = (allTypes & (~mAllTypes));
LOC_LOGD("mAllTypes:%" PRIx64, mAllTypes);
}
} // else (mConnected == false && mAllTypes == 0) } // else (mConnected == false && mAllTypes == 0)
// we keep mAllTypes as 0, which means no more connections. // we keep mAllTypes as 0, which means no more connections.

View file

@ -32,9 +32,11 @@
#include <string> #include <string>
#include <cstring> #include <cstring>
#include <sstream>
#include <DataItemId.h> #include <DataItemId.h>
#include <IDataItemCore.h> #include <IDataItemCore.h>
#include <gps_extended_c.h> #include <gps_extended_c.h>
#include <inttypes.h>
#define MAC_ADDRESS_LENGTH 6 #define MAC_ADDRESS_LENGTH 6
// MAC address length in bytes // MAC address length in bytes
@ -42,10 +44,68 @@
#define SRN_MAC_ADDRESS_LENGTH 6 #define SRN_MAC_ADDRESS_LENGTH 6
#define WIFI_SUPPLICANT_DEFAULT_STATE 0 #define WIFI_SUPPLICANT_DEFAULT_STATE 0
static constexpr char sDelimit = ':';
namespace loc_core namespace loc_core
{ {
using namespace std; using namespace std;
enum NetworkType {
TYPE_MOBILE = 0,
TYPE_WIFI,
TYPE_ETHERNET,
TYPE_BLUETOOTH,
TYPE_MMS,
TYPE_SUPL,
TYPE_DUN,
TYPE_HIPRI,
TYPE_WIMAX,
TYPE_PROXY,
TYPE_UNKNOWN,
};
typedef struct NetworkInfoType
{
// Unique network handle ID
uint64_t networkHandle;
// Type of network for corresponding network handle
NetworkType networkType;
NetworkInfoType() : networkHandle(NETWORK_HANDLE_UNKNOWN), networkType(TYPE_UNKNOWN) {}
NetworkInfoType(string strObj) {
size_t posDelimit = strObj.find(sDelimit);
if ( posDelimit != string::npos) {
int32_t type = TYPE_UNKNOWN;
string handleStr = strObj.substr(0, posDelimit);
string typeStr = strObj.substr(posDelimit + 1, strObj.length() - posDelimit - 1);
stringstream(handleStr) >> networkHandle;
stringstream(typeStr) >> type;
networkType = (NetworkType) type;
} else {
networkHandle = NETWORK_HANDLE_UNKNOWN;
networkType = TYPE_UNKNOWN;
}
}
bool operator== (const NetworkInfoType& other) {
return ((networkHandle == other.networkHandle) && (networkType == other.networkType));
}
string toString() {
string valueStr;
valueStr.clear ();
char nethandle [32];
memset (nethandle, 0, 32);
snprintf(nethandle, sizeof(nethandle), "%" PRIu64, networkHandle);
valueStr += string(nethandle);
valueStr += sDelimit;
char type [12];
memset (type, 0, 12);
snprintf (type, 12, "%u", networkType);
valueStr += string (type);
return valueStr;
}
} NetworkInfoType;
class AirplaneModeDataItemBase : public IDataItemCore { class AirplaneModeDataItemBase : public IDataItemCore {
public: public:
AirplaneModeDataItemBase(bool mode): AirplaneModeDataItemBase(bool mode):
@ -222,19 +282,6 @@ protected:
class NetworkInfoDataItemBase : public IDataItemCore { class NetworkInfoDataItemBase : public IDataItemCore {
public: public:
enum NetworkType {
TYPE_MOBILE = 0,
TYPE_WIFI,
TYPE_ETHERNET,
TYPE_BLUETOOTH,
TYPE_MMS,
TYPE_SUPL,
TYPE_DUN,
TYPE_HIPRI,
TYPE_WIMAX,
TYPE_PROXY,
TYPE_UNKNOWN,
};
NetworkInfoDataItemBase( NetworkInfoDataItemBase(
NetworkType initialType, int32_t type, string typeName, string subTypeName, NetworkType initialType, int32_t type, string typeName, string subTypeName,
bool available, bool connected, bool roaming, uint64_t networkHandle ): bool available, bool connected, bool roaming, uint64_t networkHandle ):
@ -247,9 +294,8 @@ public:
mRoaming(roaming), mRoaming(roaming),
mNetworkHandle(networkHandle), mNetworkHandle(networkHandle),
mId(NETWORKINFO_DATA_ITEM_ID) { mId(NETWORKINFO_DATA_ITEM_ID) {
memset (&mAllNetworkHandles, NETWORK_HANDLE_UNKNOWN, mAllNetworkHandles[0].networkHandle = networkHandle;
sizeof (mAllNetworkHandles)); mAllNetworkHandles[0].networkType = initialType;
mAllNetworkHandles[initialType] = networkHandle;
} }
virtual ~NetworkInfoDataItemBase() {} virtual ~NetworkInfoDataItemBase() {}
inline virtual DataItemId getId() { return mId; } inline virtual DataItemId getId() { return mId; }
@ -259,8 +305,8 @@ public:
return (NetworkType)mType; return (NetworkType)mType;
} }
inline uint64_t getAllTypes() { return mAllTypes; } inline uint64_t getAllTypes() { return mAllTypes; }
inline uint64_t getNetworkHandle(NetworkType type) { inline NetworkInfoType* getNetworkHandle() {
return mAllNetworkHandles[type]; return &mAllNetworkHandles[0];
} }
// Data members // Data members
uint64_t mAllTypes; uint64_t mAllTypes;
@ -270,7 +316,7 @@ public:
bool mAvailable; bool mAvailable;
bool mConnected; bool mConnected;
bool mRoaming; bool mRoaming;
uint64_t mAllNetworkHandles[TYPE_UNKNOWN + 1]; NetworkInfoType mAllNetworkHandles[MAX_NETWORK_HANDLES];
uint64_t mNetworkHandle; uint64_t mNetworkHandle;
protected: protected:
DataItemId mId; DataItemId mId;

View file

@ -129,19 +129,33 @@ bool XtraSystemStatusObserver::updateLockStatus(GnssConfigGpsLock lock) {
} }
bool XtraSystemStatusObserver::updateConnections(uint64_t allConnections, bool XtraSystemStatusObserver::updateConnections(uint64_t allConnections,
uint64_t wifiNetworkHandle, uint64_t mobileNetworkHandle) { NetworkInfoType* networkHandleInfo) {
mIsConnectivityStatusKnown = true; mIsConnectivityStatusKnown = true;
mConnections = allConnections; mConnections = allConnections;
mWifiNetworkHandle = wifiNetworkHandle;
mMobileNetworkHandle = mobileNetworkHandle; LOC_LOGd("updateConnections mConnections:%" PRIx64, mConnections);
for (uint8_t i = 0; i < MAX_NETWORK_HANDLES; ++i) {
mNetworkHandle[i] = networkHandleInfo[i];
LOC_LOGd("updateConnections [%d] networkHandle:%" PRIx64 " networkType:%u",
i, mNetworkHandle[i].networkHandle, mNetworkHandle[i].networkType);
}
if (!mReqStatusReceived) { if (!mReqStatusReceived) {
return true; return true;
} }
stringstream ss; stringstream ss;
ss << "connection" << endl << mConnections << endl << wifiNetworkHandle ss << "connection" << endl << mConnections << endl
<< endl << mobileNetworkHandle; << mNetworkHandle[0].toString() << endl
<< mNetworkHandle[1].toString() << endl
<< mNetworkHandle[2].toString() << endl
<< mNetworkHandle[3].toString() << endl
<< mNetworkHandle[4].toString() << endl
<< mNetworkHandle[5].toString() << endl
<< mNetworkHandle[6].toString() << endl
<< mNetworkHandle[7].toString() << endl
<< mNetworkHandle[8].toString() << endl
<< mNetworkHandle[MAX_NETWORK_HANDLES-1].toString();
string s = ss.str(); string s = ss.str();
return ( LocIpc::send(*mSender, (const uint8_t*)s.data(), s.size()) ); return ( LocIpc::send(*mSender, (const uint8_t*)s.data(), s.size()) );
} }
@ -200,7 +214,16 @@ inline bool XtraSystemStatusObserver::onStatusRequested(int32_t xtraStatusUpdate
ss << "respondStatus" << endl; ss << "respondStatus" << endl;
(mGpsLock == -1 ? ss : ss << mGpsLock) << endl; (mGpsLock == -1 ? ss : ss << mGpsLock) << endl;
(mConnections == (uint64_t)~0 ? ss : ss << mConnections) << endl (mConnections == (uint64_t)~0 ? ss : ss << mConnections) << endl
<< mWifiNetworkHandle << endl << mMobileNetworkHandle << endl << mNetworkHandle[0].toString() << endl
<< mNetworkHandle[1].toString() << endl
<< mNetworkHandle[2].toString() << endl
<< mNetworkHandle[3].toString() << endl
<< mNetworkHandle[4].toString() << endl
<< mNetworkHandle[5].toString() << endl
<< mNetworkHandle[6].toString() << endl
<< mNetworkHandle[7].toString() << endl
<< mNetworkHandle[8].toString() << endl
<< mNetworkHandle[MAX_NETWORK_HANDLES-1].toString() << endl
<< mTac << endl << mMccmnc << endl << mIsConnectivityStatusKnown; << mTac << endl << mMccmnc << endl << mIsConnectivityStatusKnown;
string s = ss.str(); string s = ss.str();
@ -272,11 +295,10 @@ void XtraSystemStatusObserver::notify(const list<IDataItemCore*>& dlist)
{ {
NetworkInfoDataItemBase* networkInfo = NetworkInfoDataItemBase* networkInfo =
static_cast<NetworkInfoDataItemBase*>(each); static_cast<NetworkInfoDataItemBase*>(each);
NetworkInfoType* networkHandleInfo =
static_cast<NetworkInfoType*>(networkInfo->getNetworkHandle());
mXtraSysStatObj->updateConnections(networkInfo->getAllTypes(), mXtraSysStatObj->updateConnections(networkInfo->getAllTypes(),
(NetworkHandle) networkInfo->getNetworkHandle( networkHandleInfo);
loc_core::NetworkInfoDataItemBase::TYPE_WIFI),
(NetworkHandle) networkInfo->getNetworkHandle(
loc_core::NetworkInfoDataItemBase::TYPE_MOBILE));
} }
break; break;

View file

@ -55,7 +55,7 @@ public :
bool updateLockStatus(GnssConfigGpsLock lock); bool updateLockStatus(GnssConfigGpsLock lock);
bool updateConnections(uint64_t allConnections, bool updateConnections(uint64_t allConnections,
uint64_t wifiNetworkHandle, uint64_t mobileNetworkHandle); loc_core::NetworkInfoType* networkHandleInfo);
bool updateTac(const string& tac); bool updateTac(const string& tac);
bool updateMccMnc(const string& mccmnc); bool updateMccMnc(const string& mccmnc);
bool updateXtraThrottle(const bool enabled); bool updateXtraThrottle(const bool enabled);
@ -69,8 +69,7 @@ private:
GnssConfigGpsLock mGpsLock; GnssConfigGpsLock mGpsLock;
LocIpc mIpc; LocIpc mIpc;
uint64_t mConnections; uint64_t mConnections;
uint64_t mWifiNetworkHandle; loc_core::NetworkInfoType mNetworkHandle[MAX_NETWORK_HANDLES];
uint64_t mMobileNetworkHandle;
string mTac; string mTac;
string mMccmnc; string mMccmnc;
bool mXtraThrottle; bool mXtraThrottle;

View file

@ -2196,6 +2196,7 @@ typedef void (*LocAgpsCloseResultCb)(bool isSuccess, AGpsExtType agpsType, void*
typedef uint64_t NetworkHandle; typedef uint64_t NetworkHandle;
#define NETWORK_HANDLE_UNKNOWN ~0 #define NETWORK_HANDLE_UNKNOWN ~0
#define MAX_NETWORK_HANDLES 10
#ifdef __cplusplus #ifdef __cplusplus
} }