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

Commit be8722a0 authored by Daniel Bright's avatar Daniel Bright
Browse files

Remove dependency on apn network attributes

* Hardcoded list of apn types that are relevant for telephony leaving the rest off.
* Reading isDataCapable in telephony manager to determine if any apns should exist.
* Removed is dependency met from the ..ctor of ApnContext since it wasn't being set.
* Cleaned up the logic of DcRequest while pointing it to new config source

Bug: 146206136
Test: FrameworkTests, FrameworkOptTelephonyTests
Merged-In: I2b5093f550a60ab16e2e5546532942ab8891ff0a
Change-Id: I6bc0fcb715657e113c3b3e1226404c1bbbdb3b9a
parent 5b639d8c
Loading
Loading
Loading
Loading
+49 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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.
 */

package com.android.internal.telephony.dataconnection;

import android.telephony.Annotation;

/**
 * Container of network configuration settings relevant for telephony module.
 */
class ApnConfigType {

    private final int mType;
    private final int mPriority;

    ApnConfigType(@Annotation.ApnType int type, int priority) {
        mType = type;
        mPriority = priority;
    }

    /**
     * Returns the apn type of this config type
     * @return Type of apn.
     */
    int getType() {
        return mType;
    }

    /**
     * Returns the priority of this apn config type.
     * @return The priority of this apn.
     */
    int getPriority() {
        return mPriority;
    }
}
+88 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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.
 */

package com.android.internal.telephony.dataconnection;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.telephony.Annotation;
import android.telephony.data.ApnSetting;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * Hard coded configuration of specific network types that the telephony module needs.
 * Formerly stored in network attributes within the resources file.
 */
public final class ApnConfigTypeRepository {

    private static final ApnConfigTypeRepository sDefault = new ApnConfigTypeRepository();

    private final Map<Integer, ApnConfigType> mConfigTypeMap;

    ApnConfigTypeRepository() {
        mConfigTypeMap = new HashMap<>();
        setup();
    }

    /**
     * Gets the default instance of the repository.
     * @return The singleton instance of repository.
     */
    @NonNull
    public static ApnConfigTypeRepository getDefault() {
        return sDefault;
    }

    /**
     * Gets list of apn config types.
     * @return All apn config types.
     */
    public Collection<ApnConfigType> getTypes() {
        return mConfigTypeMap.values();
    }

    /**
     * Gets the apn config type by apn type.
     * @param type The ApnType to search for.
     * @return The config type matching the given apn type.
     */
    @Nullable
    public ApnConfigType getByType(@Annotation.ApnType int type) {
        return mConfigTypeMap.get(type);
    }

    private void setup() {
        add(ApnSetting.TYPE_DEFAULT, 0);
        add(ApnSetting.TYPE_MMS, 2);
        add(ApnSetting.TYPE_SUPL, 2);
        add(ApnSetting.TYPE_DUN, 2);
        add(ApnSetting.TYPE_HIPRI, 3);
        add(ApnSetting.TYPE_FOTA, 2);
        add(ApnSetting.TYPE_IMS, 2);
        add(ApnSetting.TYPE_CBS, 2);
        add(ApnSetting.TYPE_IA, 2);
        add(ApnSetting.TYPE_EMERGENCY, 2);
        add(ApnSetting.TYPE_MCX, 3);
        add(ApnSetting.TYPE_XCAP, 3);
    }

    private void add(@Annotation.ApnType int type, int priority) {
        mConfigTypeMap.put(type, new ApnConfigType(type, priority));
    }
}
+41 −22
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.internal.telephony.dataconnection;

import android.net.ConnectivityManager;
import android.net.NetworkCapabilities;
import android.net.NetworkConfig;
import android.net.NetworkRequest;
import android.os.Message;
import android.telephony.Annotation.ApnType;
@@ -59,13 +58,13 @@ public class ApnContext {

    private DctConstants.State mState;

    public final int priority;
    private final int mPriority;

    private ApnSetting mApnSetting;

    private DataConnection mDataConnection;

    String mReason;
    private String mReason;

    /**
     * user/app requested connection on this APN
@@ -73,15 +72,10 @@ public class ApnContext {
    AtomicBoolean mDataEnabled;

    private final Object mRefCountLock = new Object();
    private int mRefCount = 0;

    /**
     * carrier requirements met
     */
    AtomicBoolean mDependencyMet;

    private final DcTracker mDcTracker;


    /**
     * Remember this as a change in this value to a more permissive state
     * should cause us to retry even permanent failures
@@ -100,27 +94,40 @@ public class ApnContext {
    private final RetryManager mRetryManager;

    /**
     * AonContext constructor
     * ApnContext constructor
     * @param phone phone object
     * @param typeId APN type Id
     * @param logTag Tag for logging
     * @param tracker Data call tracker
     * @param priority Priority of APN type
     */
    public ApnContext(Phone phone, int typeId, String logTag, DcTracker tracker, int priority) {
        this(phone, ApnSetting.getApnTypeString(typeId), logTag, tracker, priority);
    }

    /**
     * ApnContext constructor
     * @param phone phone object
     * @param apnType APN type (e.g. default, supl, mms, etc...)
     * @param logTag Tag for logging
     * @param config Network configuration
     * @param tracker Data call tracker
     * @param priority Priority of APN type
     */
    public ApnContext(Phone phone, String apnType, String logTag, NetworkConfig config,
            DcTracker tracker) {
    public ApnContext(Phone phone, String apnType, String logTag, DcTracker tracker,
            int priority) {
        mPhone = phone;
        mApnType = apnType;
        mState = DctConstants.State.IDLE;
        setReason(Phone.REASON_DATA_ENABLED);
        mDataEnabled = new AtomicBoolean(false);
        mDependencyMet = new AtomicBoolean(config.dependencyMet);
        priority = config.priority;
        mPriority = priority;
        LOG_TAG = logTag;
        mDcTracker = tracker;
        mRetryManager = new RetryManager(phone, apnType);
    }



    /**
     * Get the APN type
     * @return The APN type
@@ -145,6 +152,23 @@ public class ApnContext {
        return mDataConnection;
    }

    /**
     * This priority is taken into account when concurrent data connections are not allowed.  The
     * APN with the HIGHER priority is given preference.
     * @return The priority of the APN type
     */
    public int getPriority() {
        return mPriority;
    }

    /**
     * Keeping for backwards compatibility and in case it's needed in the future
     * @return true
     */
    public boolean isDependencyMet() {
        return true;
    }

    /**
     * Set the associated data connection.
     * @param dc data connection
@@ -312,7 +336,7 @@ public class ApnContext {
     * @return True if ready, otherwise false.
     */
    public boolean isReady() {
        return mDataEnabled.get() && mDependencyMet.get();
        return mDataEnabled.get() && isDependencyMet();
    }

    /**
@@ -360,10 +384,6 @@ public class ApnContext {
        return mDataEnabled.get();
    }

    public boolean isDependencyMet() {
       return mDependencyMet.get();
    }

    public boolean isProvisioningApn() {
        String provisioningApn = mPhone.getContext().getResources()
                .getString(R.string.mobile_provisioning_apn);
@@ -619,8 +639,7 @@ public class ApnContext {
        // We don't print mDataConnection because its recursive.
        return "{mApnType=" + mApnType + " mState=" + getState() + " mWaitingApns={" +
                mRetryManager.getWaitingApns() + "}" + " mApnSetting={" + mApnSetting +
                "} mReason=" + mReason + " mDataEnabled=" + mDataEnabled + " mDependencyMet=" +
                mDependencyMet + "}";
                "} mReason=" + mReason + " mDataEnabled=" + mDataEnabled + "}";
    }

    private void log(String s) {
+1 −27
Original line number Diff line number Diff line
@@ -16,12 +16,9 @@
package com.android.internal.telephony.dataconnection;

import android.content.Context;
import android.net.NetworkConfig;
import android.net.NetworkRequest;
import android.telephony.Annotation.ApnType;

import java.util.HashMap;

public class DcRequest implements Comparable<DcRequest> {
    private static final String LOG_TAG = "DcRequest";

@@ -30,10 +27,9 @@ public class DcRequest implements Comparable<DcRequest> {
    public final @ApnType int apnType;

    public DcRequest(NetworkRequest nr, Context context) {
        initApnPriorities(context);
        networkRequest = nr;
        apnType = ApnContext.getApnTypeFromNetworkRequest(networkRequest);
        priority = priorityForApnType(apnType);
        priority = ApnConfigTypeRepository.getDefault().getByType(apnType).getPriority();
    }

    public String toString() {
@@ -54,26 +50,4 @@ public class DcRequest implements Comparable<DcRequest> {
    public int compareTo(DcRequest o) {
        return o.priority - priority;
    }

    private static final HashMap<Integer, Integer> sApnPriorityMap =
            new HashMap<Integer, Integer>();

    private void initApnPriorities(Context context) {
        synchronized (sApnPriorityMap) {
            if (sApnPriorityMap.isEmpty()) {
                String[] networkConfigStrings = context.getResources().getStringArray(
                        com.android.internal.R.array.networkAttributes);
                for (String networkConfigString : networkConfigStrings) {
                    NetworkConfig networkConfig = new NetworkConfig(networkConfigString);
                    final int apnType = ApnContext.getApnTypeFromNetworkType(networkConfig.type);
                    sApnPriorityMap.put(apnType, networkConfig.priority);
                }
            }
        }
    }

    private int priorityForApnType(int apnType) {
        Integer priority = sApnPriorityMap.get(apnType);
        return (priority != null ? priority.intValue() : 0);
    }
}
+26 −79
Original line number Diff line number Diff line
@@ -46,7 +46,6 @@ import android.net.ConnectivityManager;
import android.net.LinkProperties;
import android.net.NetworkAgent;
import android.net.NetworkCapabilities;
import android.net.NetworkConfig;
import android.net.NetworkPolicyManager;
import android.net.NetworkRequest;
import android.net.ProxyInfo;
@@ -123,6 +122,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
@@ -146,26 +146,6 @@ public class DcTracker extends Handler {
    private static final boolean VDBG_STALL = false; // STOPSHIP if true
    private static final boolean RADIO_TESTS = false;

    /**
     * These constants exist here because ConnectivityManager.TYPE_xxx constants are deprecated and
     * new ones will not be added (for instance NETWORK_TYPE_MCX below).
     * For backward compatibility, the values here need to be the same as
     * ConnectivityManager.TYPE_xxx because networkAttributes overlay uses those values.
     */
    private static final int NETWORK_TYPE_DEFAULT = ConnectivityManager.TYPE_MOBILE;
    private static final int NETWORK_TYPE_MMS = ConnectivityManager.TYPE_MOBILE_MMS;
    private static final int NETWORK_TYPE_SUPL = ConnectivityManager.TYPE_MOBILE_SUPL;
    private static final int NETWORK_TYPE_DUN = ConnectivityManager.TYPE_MOBILE_DUN;
    private static final int NETWORK_TYPE_HIPRI = ConnectivityManager.TYPE_MOBILE_HIPRI;
    private static final int NETWORK_TYPE_FOTA = ConnectivityManager.TYPE_MOBILE_FOTA;
    private static final int NETWORK_TYPE_IMS = ConnectivityManager.TYPE_MOBILE_IMS;
    private static final int NETWORK_TYPE_CBS = ConnectivityManager.TYPE_MOBILE_CBS;
    private static final int NETWORK_TYPE_IA = ConnectivityManager.TYPE_MOBILE_IA;
    private static final int NETWORK_TYPE_EMERGENCY = ConnectivityManager.TYPE_MOBILE_EMERGENCY;
    // far away from ConnectivityManager.TYPE_xxx constants as the APNs below aren't defined there.
    private static final int NETWORK_TYPE_MCX = 1001;
    private static final int NETWORK_TYPE_XCAP = 1002;

    @IntDef(value = {
            REQUEST_TYPE_NORMAL,
            REQUEST_TYPE_HANDOVER,
@@ -288,7 +268,7 @@ public class DcTracker extends Handler {
            new PriorityQueue<ApnContext>(5,
            new Comparator<ApnContext>() {
                public int compare(ApnContext c1, ApnContext c2) {
                    return c2.priority - c1.priority;
                    return c2.getPriority() - c1.getPriority();
                }
            } );

@@ -1072,68 +1052,30 @@ public class DcTracker extends Handler {
        if(DBG && mPhone != null) log("finalize");
    }

    private ApnContext addApnContext(String type, NetworkConfig networkConfig) {
        ApnContext apnContext = new ApnContext(mPhone, type, mLogTag, networkConfig, this);
        mApnContexts.put(type, apnContext);
        mApnContextsByType.put(ApnSetting.getApnTypesBitmaskFromString(type), apnContext);
        mPrioritySortedApnContexts.add(apnContext);
        return apnContext;
    private void initApnContexts() {
        if (!mTelephonyManager.isDataCapable()) {
            log("initApnContexts: isDataCapable == false.  No Apn Contexts loaded");
            return;
        }

    private void initApnContexts() {
        log("initApnContexts: E");
        // Load device network attributes from resources
        String[] networkConfigStrings = mPhone.getContext().getResources().getStringArray(
                com.android.internal.R.array.networkAttributes);
        for (String networkConfigString : networkConfigStrings) {
            NetworkConfig networkConfig = new NetworkConfig(networkConfigString);
            ApnContext apnContext;

            switch (networkConfig.type) {
                case NETWORK_TYPE_DEFAULT:
                    apnContext = addApnContext(PhoneConstants.APN_TYPE_DEFAULT, networkConfig);
                    break;
                case NETWORK_TYPE_MMS:
                    apnContext = addApnContext(PhoneConstants.APN_TYPE_MMS, networkConfig);
                    break;
                case NETWORK_TYPE_SUPL:
                    apnContext = addApnContext(PhoneConstants.APN_TYPE_SUPL, networkConfig);
                    break;
                case NETWORK_TYPE_DUN:
                    apnContext = addApnContext(PhoneConstants.APN_TYPE_DUN, networkConfig);
                    break;
                case NETWORK_TYPE_HIPRI:
                    apnContext = addApnContext(PhoneConstants.APN_TYPE_HIPRI, networkConfig);
                    break;
                case NETWORK_TYPE_FOTA:
                    apnContext = addApnContext(PhoneConstants.APN_TYPE_FOTA, networkConfig);
                    break;
                case NETWORK_TYPE_IMS:
                    apnContext = addApnContext(PhoneConstants.APN_TYPE_IMS, networkConfig);
                    break;
                case NETWORK_TYPE_CBS:
                    apnContext = addApnContext(PhoneConstants.APN_TYPE_CBS, networkConfig);
                    break;
                case NETWORK_TYPE_IA:
                    apnContext = addApnContext(PhoneConstants.APN_TYPE_IA, networkConfig);
                    break;
                case NETWORK_TYPE_EMERGENCY:
                    apnContext = addApnContext(PhoneConstants.APN_TYPE_EMERGENCY, networkConfig);
                    break;
                case NETWORK_TYPE_MCX:
                    apnContext = addApnContext(PhoneConstants.APN_TYPE_MCX, networkConfig);
                    break;
                case NETWORK_TYPE_XCAP:
                    apnContext = addApnContext(PhoneConstants.APN_TYPE_XCAP, networkConfig);
                    break;
                default:
                    log("initApnContexts: skipping unknown type=" + networkConfig.type);
                    continue;
        final Collection<ApnConfigType> types = ApnConfigTypeRepository.getDefault().getTypes();
        for (ApnConfigType apnConfigType : types) {
            addApnContext(apnConfigType);
            log("initApnContexts: apnContext=" + ApnSetting.getApnTypeString(
                    apnConfigType.getType()));
        }
            log("initApnContexts: apnContext=" + apnContext);
        if (VDBG) log("initApnContexts: X mApnContexts=" + mApnContexts);
    }

        if (VDBG) log("initApnContexts: X mApnContexts=" + mApnContexts);
    private void addApnContext(ApnConfigType apnContextType) {
        ApnContext apnContext = new ApnContext(mPhone, apnContextType.getType(), mLogTag, this,
                apnContextType.getPriority());
        mApnContexts.put(apnContext.getApnType(), apnContext);
        mApnContextsByType.put(ApnSetting.getApnTypesBitmaskFromString(apnContext.getApnType()),
                apnContext);
        mPrioritySortedApnContexts.add(apnContext);
    }

    public LinkProperties getLinkProperties(String apnType) {
@@ -1178,6 +1120,11 @@ public class DcTracker extends Handler {
        return result.toArray(new String[0]);
    }

    @VisibleForTesting
    public Collection<ApnContext> getApnContexts() {
        return mApnContexts.values();
    }

    /** Return active ApnSetting of a specific apnType */
    public ApnSetting getActiveApnSetting(String apnType) {
        if (VDBG) log("get active ApnSetting for type:" + apnType);
Loading