Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 931a37f9 authored by destradaa's avatar destradaa
Browse files

Add additional logging around AGPS IP Address handling.

The additional logging is expected to help troubleshoot and prevent the issue tracked by the
following bugs:
b/16875580
b/16961654

Change-Id: Ibee7fe0774efa3db77ab53af96c128ced186b40e
parent f2546bf4
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -1372,6 +1372,7 @@ public class GpsLocationProvider implements LocationProviderInterface {
        switch (status) {
            case GPS_REQUEST_AGPS_DATA_CONN:
                if (DEBUG) Log.d(TAG, "GPS_REQUEST_AGPS_DATA_CONN");
                Log.v(TAG, "Received SUPL IP addr[]: " + ipaddr);
                // Set mAGpsDataConnectionState before calling startUsingNetworkFeature
                //  to avoid a race condition with handleUpdateNetworkState()
                mAGpsDataConnectionState = AGPS_DATA_CONNECTION_OPENING;
@@ -1380,6 +1381,7 @@ public class GpsLocationProvider implements LocationProviderInterface {
                if (ipaddr != null) {
                    try {
                        mAGpsDataConnectionIpAddr = InetAddress.getByAddress(ipaddr);
                        Log.v(TAG, "IP address converted to: " + mAGpsDataConnectionIpAddr);
                    } catch (UnknownHostException e) {
                        Log.e(TAG, "Bad IP Address: " + ipaddr, e);
                        mAGpsDataConnectionIpAddr = null;
@@ -1426,6 +1428,8 @@ public class GpsLocationProvider implements LocationProviderInterface {
            case GPS_AGPS_DATA_CONN_FAILED:
                if (DEBUG) Log.d(TAG, "GPS_AGPS_DATA_CONN_FAILED");
                break;
            default:
                Log.d(TAG, "Received Unknown AGPS status: " + status);
        }
    }

+21 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@
#include "android_runtime/AndroidRuntime.h"
#include "android_runtime/Log.h"

#include <arpa/inet.h>
#include <string.h>
#include <pthread.h>
#include <linux/in.h>
@@ -189,8 +190,10 @@ static jbyteArray convert_to_ipv4(uint32_t ip, bool net_order)

    jbyte ipv4[4];
    if (net_order) {
        ALOGV("Converting IPv4 address(net_order) %x", ip);
        memcpy(ipv4, &ip, sizeof(ipv4));
    } else {
        ALOGV("Converting IPv4 address(host_order) %x", ip);
        //endianess transparent conversion from int to char[]
        ipv4[0] = (jbyte) (ip & 0xFF);
        ipv4[1] = (jbyte)((ip>>8) & 0xFF);
@@ -210,6 +213,7 @@ static void agps_status_callback(AGpsStatus* agps_status)

    size_t status_size = agps_status->size;
    if (status_size == sizeof(AGpsStatus_v3)) {
      ALOGV("AGpsStatus is V3: %d", status_size);
      switch (agps_status->addr.ss_family)
      {
      case AF_INET:
@@ -220,6 +224,12 @@ static void agps_status_callback(AGpsStatus* agps_status)
            if (byteArray != NULL) {
                isSupported = true;
            }
            IF_ALOGD() {
                // log the IP for reference in case there is a bogus value pushed by HAL
                char str[INET_ADDRSTRLEN];
                inet_ntop(AF_INET, &(in->sin_addr), str, INET_ADDRSTRLEN);
                ALOGD("AGPS IP is v4: %s", str);
            }
          }
          break;
      case AF_INET6:
@@ -232,6 +242,12 @@ static void agps_status_callback(AGpsStatus* agps_status)
            } else {
                ALOGE("Unable to allocate byte array for IPv6 address.");
            }
            IF_ALOGD() {
                // log the IP for reference in case there is a bogus value pushed by HAL
                char str[INET6_ADDRSTRLEN];
                inet_ntop(AF_INET6, &(in6->sin6_addr), str, INET6_ADDRSTRLEN);
                ALOGD("AGPS IP is v6: %s", str);
            }
          }
          break;
      default:
@@ -239,14 +255,17 @@ static void agps_status_callback(AGpsStatus* agps_status)
          break;
      }
    } else if (status_size >= sizeof(AGpsStatus_v2)) {
      ALOGV("AGpsStatus is V2+: %d", status_size);
      // for back-compatibility reasons we check in v2 that the data structure size is greater or
      // equal to the declared size in gps.h
      uint32_t ipaddr = agps_status->ipaddr;
      ALOGV("AGPS IP is v4: %x", ipaddr);
      byteArray = convert_to_ipv4(ipaddr, false /* net_order */);
      if (ipaddr == INADDR_NONE || byteArray != NULL) {
          isSupported = true;
      }
    } else if (status_size >= sizeof(AGpsStatus_v1)) {
        ALOGV("AGpsStatus is V1+: %d", status_size);
        // because we have to check for >= with regards to v2, we also need to relax the check here
        // and only make sure that the size is at least what we expect
        isSupported = true;
@@ -255,6 +274,8 @@ static void agps_status_callback(AGpsStatus* agps_status)
    }

    if (isSupported) {
        jsize byteArrayLength = byteArray != NULL ? env->GetArrayLength(byteArray) : 0;
        ALOGV("Passing AGPS IP addr: size %d", byteArrayLength);
        env->CallVoidMethod(mCallbacksObj, method_reportAGpsStatus, agps_status->type,
                            agps_status->status, byteArray);