Merge "connectity events for XC2.0 daemonize"

This commit is contained in:
Linux Build Service Account 2017-04-27 07:13:38 -07:00 committed by Gerrit - the friendly Code Review server
commit 6cf01fac92
5 changed files with 219 additions and 3 deletions

127
android/AGnssRil.cpp Normal file
View file

@ -0,0 +1,127 @@
/*
* Copyright (c) 2017, The Linux Foundation. All rights reserved.
* Not a Contribution
*/
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define LOG_TAG "LocSvc__AGnssRilInterface"
#include <log_util.h>
#include <dlfcn.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sstream>
#include <string>
#include "Gnss.h"
#include "AGnssRil.h"
typedef void* (getLocationInterface)();
namespace android {
namespace hardware {
namespace gnss {
namespace V1_0 {
namespace implementation {
static bool sendConnectionEvent(const bool connected, const uint8_t type);
AGnssRil::AGnssRil(Gnss* gnss) : mGnss(gnss) {
ENTRY_LOG_CALLFLOW();
}
AGnssRil::~AGnssRil() {
ENTRY_LOG_CALLFLOW();
}
Return<bool> AGnssRil::updateNetworkState(bool connected, NetworkType type, bool roaming) {
ENTRY_LOG_CALLFLOW();
// for XTRA
sendConnectionEvent(connected, (uint8_t)type);
return true;
}
// for XTRA
static inline int createSocket() {
int socketFd = -1;
if ((socketFd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
LOC_LOGe("create socket error. reason:%s", strerror(errno));
} else {
const char* socketPath = "/data/misc/location/xtra/socket_hal_xtra";
struct sockaddr_un addr = { .sun_family = AF_UNIX };
snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", socketPath);
if (::connect(socketFd, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
LOC_LOGe("cannot connect to XTRA. reason:%s", strerror(errno));
if (::close(socketFd)) {
LOC_LOGe("close socket error. reason:%s", strerror(errno));
}
socketFd = -1;
}
}
return socketFd;
}
static inline void closeSocket(const int socketFd) {
if (socketFd >= 0) {
if(::close(socketFd)) {
LOC_LOGe("close socket error. reason:%s", strerror(errno));
}
}
}
static inline bool sendConnectionEvent(const bool connected, const uint8_t type) {
int socketFd = createSocket();
if (socketFd < 0) {
LOC_LOGe("XTRA unreachable. sending failed.");
return false;
}
std::stringstream ss;
ss << "connection";
ss << " " << (connected ? "1" : "0");
ss << " " << (int)type;
ss << "\n"; // append seperator
const std::string& data = ss.str();
int remain = data.length();
ssize_t sent = 0;
while (remain > 0 &&
(sent = ::send(socketFd, data.c_str() + (data.length() - remain),
remain, MSG_NOSIGNAL)) > 0) {
remain -= sent;
}
if (sent < 0) {
LOC_LOGe("sending error. reason:%s", strerror(errno));
}
closeSocket(socketFd);
return (remain == 0);
}
} // namespace implementation
} // namespace V1_0
} // namespace gnss
} // namespace hardware
} // namespace android

83
android/AGnssRil.h Normal file
View file

@ -0,0 +1,83 @@
/*
* Copyright (c) 2017, The Linux Foundation. All rights reserved.
* Not a Contribution
*/
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ANDROID_HARDWARE_GNSS_V1_0_AGNSSRIL_H_
#define ANDROID_HARDWARE_GNSS_V1_0_AGNSSRIL_H_
#include <android/hardware/gnss/1.0/IAGnssRil.h>
#include <hidl/Status.h>
#include <location_interface.h>
namespace android {
namespace hardware {
namespace gnss {
namespace V1_0 {
namespace implementation {
using ::android::hardware::gnss::V1_0::IAGnssRil;
using ::android::hardware::gnss::V1_0::IAGnssRilCallback;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::hardware::hidl_vec;
using ::android::hardware::hidl_string;
using ::android::sp;
struct Gnss;
/*
* Extended interface for AGNSS RIL support. An Assisted GNSS Radio Interface Layer interface
* allows the GNSS chipset to request radio interface layer information from Android platform.
* Examples of such information are reference location, unique subscriber ID, phone number string
* and network availability changes. Also contains wrapper methods to allow methods from
* IAGnssiRilCallback interface to be passed into the conventional implementation of the GNSS HAL.
*/
struct AGnssRil : public IAGnssRil {
AGnssRil(Gnss* gnss);
~AGnssRil();
/*
* Methods from ::android::hardware::gnss::V1_0::IAGnssRil follow.
* These declarations were generated from IAGnssRil.hal.
*/
Return<void> setCallback(const sp<IAGnssRilCallback>& /*callback*/) override {
return Void();
}
Return<void> setRefLocation(const IAGnssRil::AGnssRefLocation& /*agnssReflocation*/) override {
return Void();
}
Return<bool> setSetId(IAGnssRil::SetIDType /*type*/, const hidl_string& /*setid*/) override {
return false;
}
Return<bool> updateNetworkAvailability(bool /*available*/,
const hidl_string& /*apn*/) override {
return false;
}
Return<bool> updateNetworkState(bool connected, NetworkType type, bool roaming) override;
private:
Gnss* mGnss = nullptr;
};
} // namespace implementation
} // namespace V1_0
} // namespace gnss
} // namespace hardware
} // namespace android
#endif // ANDROID_HARDWARE_GNSS_V1_0_AGNSSRIL_H_

View file

@ -14,6 +14,7 @@ LOCAL_SRC_FILES := \
GnssNi.cpp \
GnssConfiguration.cpp \
GnssDebug.cpp \
AGnssRil.cpp
LOCAL_SRC_FILES += \
location_api/LocationUtil.cpp \

View file

@ -316,6 +316,11 @@ Return<sp<IGnssDebug>> Gnss::getExtensionGnssDebug() {
return mGnssDebug;
}
Return<sp<IAGnssRil>> Gnss::getExtensionAGnssRil() {
mGnssRil = new AGnssRil(this);
return mGnssRil;
}
IGnss* HIDL_FETCH_IGnss(const char* hal) {
ENTRY_LOG_CALLFLOW();
IGnss* iface = nullptr;

View file

@ -22,6 +22,7 @@
#define ANDROID_HARDWARE_GNSS_V1_1_GNSS_H
#include <AGnss.h>
#include <AGnssRil.h>
#include <GnssBatching.h>
#include <GnssConfiguration.h>
#include <GnssGeofencing.h>
@ -91,9 +92,7 @@ struct Gnss : public IGnss {
Return<sp<IGnssGeofencing>> getExtensionGnssGeofencing() override;
Return<sp<IGnssBatching>> getExtensionGnssBatching() override;
inline Return<sp<IAGnssRil>> getExtensionAGnssRil() override {
return nullptr;
}
Return<sp<IAGnssRil>> getExtensionAGnssRil() override;
inline Return<sp<IGnssNavigationMessage>> getExtensionGnssNavigationMessage() override {
return nullptr;
@ -130,6 +129,7 @@ struct Gnss : public IGnss {
sp<GnssGeofencing> mGnssGeofencingIface = nullptr;
sp<GnssBatching> mGnssBatching = nullptr;
sp<IGnssDebug> mGnssDebug = nullptr;
sp<AGnssRil> mGnssRil = nullptr;
GnssAPIClient* mApi = nullptr;
sp<IGnssCallback> mGnssCbIface = nullptr;