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

Commit 7d4b7f34 authored by Shinru Han's avatar Shinru Han Committed by Automerger Merge Worker
Browse files

「DO NOT MERGE」Revert "Get ApnIpType from ConnectivityManager#getLinkProperties()" am: d461be70

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11899380

Change-Id: Id1296d30a54331bde0e199a30b6dadd766e4f96a
parents 562470c2 d461be70
Loading
Loading
Loading
Loading
+72 −32
Original line number Diff line number Diff line
@@ -17,9 +17,8 @@
package com.android.server.location.gnss;

import android.content.Context;
import android.database.Cursor;
import android.net.ConnectivityManager;
import android.net.LinkAddress;
import android.net.LinkProperties;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
@@ -27,26 +26,25 @@ import android.net.NetworkRequest;
import android.os.Handler;
import android.os.Looper;
import android.os.PowerManager;
import android.telephony.PhoneStateListener;
import android.telephony.PreciseCallState;
import android.provider.Telephony.Carriers;
import android.telephony.ServiceState;
import android.telephony.TelephonyManager;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telephony.PreciseCallState;
import android.telephony.PhoneStateListener;
import android.util.Log;

import com.android.internal.location.GpsNetInitiatedHandler;

import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.Map;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import java.util.Iterator;

/**
 * Handles network connection requests and network state change updates for AGPS data download.
@@ -387,10 +385,10 @@ class GnssNetworkConnectivityHandler {
    private ConnectivityManager.NetworkCallback createSuplConnectivityCallback() {
        return new ConnectivityManager.NetworkCallback() {
            @Override
            public void onLinkPropertiesChanged(Network network, LinkProperties linkProperties) {
            public void onAvailable(Network network) {
                if (DEBUG) Log.d(TAG, "SUPL network connection available.");
                // Specific to a change to a SUPL enabled network becoming ready
                handleSuplConnectionAvailable(network, linkProperties);
                handleSuplConnectionAvailable(network);
            }

            @Override
@@ -498,7 +496,7 @@ class GnssNetworkConnectivityHandler {
        return networkAttributes;
    }

    private void handleSuplConnectionAvailable(Network network, LinkProperties linkProperties) {
    private void handleSuplConnectionAvailable(Network network) {
        // TODO: The synchronous method ConnectivityManager.getNetworkInfo() should not be called
        //       inside the asynchronous ConnectivityManager.NetworkCallback methods.
        NetworkInfo info = mConnMgr.getNetworkInfo(network);
@@ -530,7 +528,7 @@ class GnssNetworkConnectivityHandler {
                setRouting();
            }

            int apnIpType = getLinkIpType(linkProperties);
            int apnIpType = getApnIpType(apn);
            if (DEBUG) {
                String message = String.format(
                        "native_agps_data_conn_open: mAgpsApn=%s, mApnIpType=%s",
@@ -706,32 +704,74 @@ class GnssNetworkConnectivityHandler {
        }
    }

    private int getLinkIpType(LinkProperties linkProperties) {
    private int getApnIpType(String apn) {
        ensureInHandlerThread();
        boolean isIPv4 = false;
        boolean isIPv6 = false;
        if (apn == null) {
            return APN_INVALID;
        }
        TelephonyManager phone = (TelephonyManager)
                mContext.getSystemService(Context.TELEPHONY_SERVICE);
        // During an emergency call with an active sub id, get the Telephony Manager specific
        // to the active sub to get the correct value from getServiceState and getNetworkType
        if (mNiHandler.getInEmergency() && mActiveSubId >= 0) {
            TelephonyManager subIdTelManager =
                    phone.createForSubscriptionId(mActiveSubId);
            if (subIdTelManager != null) {
                phone = subIdTelManager;
            }
        }
        ServiceState serviceState = phone.getServiceState();
        String projection = null;
        String selection = null;

        List<LinkAddress> linkAddresses = linkProperties.getLinkAddresses();
        for (LinkAddress linkAddress : linkAddresses) {
            InetAddress inetAddress = linkAddress.getAddress();
            if (inetAddress instanceof Inet4Address) {
                isIPv4 = true;
            } else if (inetAddress instanceof Inet6Address) {
                isIPv6 = true;
        // Carrier configuration may override framework roaming state, we need to use the actual
        // modem roaming state instead of the framework roaming state.
        if (serviceState != null && serviceState.getDataRoamingFromRegistration()) {
            projection = Carriers.ROAMING_PROTOCOL;
        } else {
            projection = Carriers.PROTOCOL;
        }
        // No SIM case for emergency
        if (TelephonyManager.NETWORK_TYPE_UNKNOWN == phone.getNetworkType()
                && AGPS_TYPE_EIMS == mAGpsType) {
            selection = String.format(
                "type like '%%emergency%%' and apn = '%s' and carrier_enabled = 1", apn);
        } else {
            selection = String.format("current = 1 and apn = '%s' and carrier_enabled = 1", apn);
        }
        try (Cursor cursor = mContext.getContentResolver().query(
                Carriers.CONTENT_URI,
                new String[]{projection},
                selection,
                null,
                Carriers.DEFAULT_SORT_ORDER)) {
            if (null != cursor && cursor.moveToFirst()) {
                return translateToApnIpType(cursor.getString(0), apn);
            } else {
                Log.e(TAG, "No entry found in query for APN: " + apn);
            }
            if (DEBUG) Log.d(TAG, "LinkAddress : " + inetAddress.toString());
        } catch (Exception e) {
            Log.e(TAG, "Error encountered on APN query for: " + apn, e);
        }

        if (isIPv4 && isIPv6) {
        return APN_IPV4V6;
    }
        if (isIPv4) {

    private int translateToApnIpType(String ipProtocol, String apn) {
        if ("IP".equals(ipProtocol)) {
            return APN_IPV4;
        }
        if (isIPv6) {
        if ("IPV6".equals(ipProtocol)) {
            return APN_IPV6;
        }
        return APN_INVALID;
        if ("IPV4V6".equals(ipProtocol)) {
            return APN_IPV4V6;
        }

        // we hit the default case so the ipProtocol is not recognized
        String message = String.format("Unknown IP Protocol: %s, for APN: %s", ipProtocol, apn);
        Log.e(TAG, message);
        return APN_IPV4V6;
    }

    // AGPS support