Commit 82811c5c authored by Vyacheslav Koscheev's avatar Vyacheslav Koscheev

Fix gms location status reporting

parent 9a0e220a
......@@ -56,6 +56,13 @@ Q_DECL_EXPORT void JNICALL Java_GooglePlayServiceLocationProvider_locationStatus
}
Q_DECL_EXPORT void JNICALL Java_GooglePlayServiceLocationProvider_locationAvailable(JNIEnv *, jobject, jlong param, jboolean available)
{
JNI_LINKER_OBJECT(QAndroidGmsLocationProvider, param, obj)
obj->onLocationAvailable(available);
}
Q_DECL_EXPORT void JNICALL Java_GooglePlayServiceLocationProvider_locationRecieved(JNIEnv *, jobject, jlong param, jobject location, jboolean initial, jlong requestId)
{
if (0x0 == location)
......@@ -72,6 +79,7 @@ Q_DECL_EXPORT void JNICALL Java_GooglePlayServiceLocationProvider_locationReciev
static const JNINativeMethod methods[] = {
{"getActivity", "()Landroid/app/Activity;", reinterpret_cast<void*>(QAndroidQPAPluginGap::getActivityNoThrow)},
{"googleApiClientStatus", "(JI)V", reinterpret_cast<void*>(Java_GooglePlayServiceLocationProvider_locationStatus)},
{"googleApiClientLocationAvailable", "(JZ)V", reinterpret_cast<void*>(Java_GooglePlayServiceLocationProvider_locationAvailable)},
{"googleApiClientLocation", "(JLandroid/location/Location;ZJ)V", reinterpret_cast<void*>(Java_GooglePlayServiceLocationProvider_locationRecieved)},
};
......@@ -114,30 +122,30 @@ QGeoPositionInfo QAndroidGmsLocationProvider::lastKnownPosition() const
}
void QAndroidGmsLocationProvider::onStatusChanged(int status)
void QAndroidGmsLocationProvider::onLocationAvailable(jboolean available)
{
emit locationAvailable(available);
}
void QAndroidGmsLocationProvider::onStatusChanged(jint status)
{
const char * szStatus = "Unknown";
switch (status)
{
case 0:
case S_DISCONNECTED:
szStatus = "Disconnected";
break;
case 1:
case S_CONNECTED:
szStatus = "Connected";
break;
case 2:
case S_CONNECT_ERROR:
szStatus = "Error";
break;
case 3:
case S_CONNECT_SUSPEND:
szStatus = "Suspended";
break;
case 4:
szStatus = "Success";
break;
case 5:
szStatus = "Fail";
break;
default:
assert(!"Unexpected status");
}
......@@ -184,7 +192,7 @@ void QAndroidGmsLocationProvider::startUpdates()
if (isJniReady())
{
jlong maxWaitTime = reqiredInterval_ * 1.5;
jlong maxWaitTime = reqiredInterval_ * 3 / 2;
jint numUpdates = 0;
jlong expirationDuration = 0;
jlong expirationTime = 0;
......
......@@ -58,8 +58,6 @@ public:
S_CONNECTED = 1,
S_CONNECT_ERROR = 2,
S_CONNECT_SUSPEND = 3,
S_REQUEST_SUCCESS = 4,
S_REQUEST_FAIL = 5,
};
enum enPriority
......@@ -86,6 +84,7 @@ private slots:
signals:
void statusChanged(int);
void locationAvailable(bool);
void locationRecieved(QGeoPositionInfo);
void checkRequest(jlong requestId);
......@@ -98,13 +97,15 @@ public:
private:
void stopUpdates(jlong requestId);
void onStatusChanged(int status);
void onStatusChanged(jint status);
void onLocationAvailable(jboolean available);
void onLocationRecieved(const QGeoPositionInfo &location, jboolean initial, jlong requestId);
private:
Q_DISABLE_COPY(QAndroidGmsLocationProvider)
friend void JNICALL Java_GooglePlayServiceLocationProvider_locationRecieved(JNIEnv * env, jobject, jlong param, jobject location, jboolean initial, jlong requestId);
friend void JNICALL Java_GooglePlayServiceLocationProvider_locationStatus(JNIEnv * env, jobject, jlong param, jint state);
friend void JNICALL Java_GooglePlayServiceLocationProvider_locationAvailable(JNIEnv *, jobject, jlong param, jboolean available);
private:
QGeoPositionInfo lastLocation_;
......
......@@ -259,12 +259,10 @@ void QGeoPositionInfoSourceAndroidGms::onStatusChanged(int status)
case QAndroidGmsLocationProvider::S_DISCONNECTED:
case QAndroidGmsLocationProvider::S_CONNECT_ERROR:
case QAndroidGmsLocationProvider::S_CONNECT_SUSPEND:
case QAndroidGmsLocationProvider::S_REQUEST_FAIL:
setError(QGeoPositionInfoSource::ClosedError);
break;
case QAndroidGmsLocationProvider::S_CONNECTED:
case QAndroidGmsLocationProvider::S_REQUEST_SUCCESS:
setError(QGeoPositionInfoSource::NoError);
break;
......
......@@ -85,8 +85,6 @@ public class GmsLocationProvider implements ConnectionCallbacks, OnConnectionFai
public final static int STATUS_CONNECTED = 1;
public final static int STATUS_CONNECTION_ERROR = 2;
public final static int STATUS_CONNECTION_SUSPENDED = 3;
public final static int STATUS_REQUEST_SUCCESS = 4;
public final static int STATUS_REQUEST_FAIL = 5;
private volatile long native_ptr_ = 0;
......@@ -348,13 +346,12 @@ public class GmsLocationProvider implements ConnectionCallbacks, OnConnectionFai
LocationCallback callback = new LocationCallback() {
@Override
public void onLocationAvailability(LocationAvailability locationAvailability)
{
public void onLocationAvailability(LocationAvailability locationAvailability) {
boolean available = false;
if (null != locationAvailability) {
available = locationAvailability.isLocationAvailable();
}
googleApiClientStatus(native_ptr_, available ? STATUS_REQUEST_SUCCESS : STATUS_REQUEST_FAIL);
googleApiClientLocationAvailable(native_ptr_, available);
}
@Override
......@@ -480,5 +477,6 @@ public class GmsLocationProvider implements ConnectionCallbacks, OnConnectionFai
public native Activity getActivity();
public native void googleApiClientStatus(long nativeptr, int status);
public native void googleApiClientLocationAvailable(long nativeptr, boolean available);
public native void googleApiClientLocation(long nativeptr, Location location, boolean initial, long requestId);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment