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

Commit 51829447 authored by Daniel Bright's avatar Daniel Bright Committed by Android (Google) Code Review
Browse files

Merge "Remove dependency on apn network attributes"

parents fa836529 07693319
Loading
Loading
Loading
Loading
+49 −0
Original line number Original line 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 Original line 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));
    }
}
+42 −23
Original line number Original line Diff line number Diff line
@@ -18,11 +18,9 @@ package com.android.internal.telephony.dataconnection;


import android.net.ConnectivityManager;
import android.net.ConnectivityManager;
import android.net.NetworkCapabilities;
import android.net.NetworkCapabilities;
import android.net.NetworkConfig;
import android.net.NetworkRequest;
import android.net.NetworkRequest;
import android.os.Message;
import android.os.Message;
import android.telephony.Annotation.ApnType;
import android.telephony.Annotation.ApnType;
import com.android.telephony.Rlog;
import android.telephony.data.ApnSetting;
import android.telephony.data.ApnSetting;
import android.text.TextUtils;
import android.text.TextUtils;
import android.util.LocalLog;
import android.util.LocalLog;
@@ -35,6 +33,7 @@ import com.android.internal.telephony.RetryManager;
import com.android.internal.telephony.dataconnection.DcTracker.ReleaseNetworkType;
import com.android.internal.telephony.dataconnection.DcTracker.ReleaseNetworkType;
import com.android.internal.telephony.dataconnection.DcTracker.RequestNetworkType;
import com.android.internal.telephony.dataconnection.DcTracker.RequestNetworkType;
import com.android.internal.util.IndentingPrintWriter;
import com.android.internal.util.IndentingPrintWriter;
import com.android.telephony.Rlog;


import java.io.FileDescriptor;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.io.PrintWriter;
@@ -59,13 +58,13 @@ public class ApnContext {


    private DctConstants.State mState;
    private DctConstants.State mState;


    public final int priority;
    private final int mPriority;


    private ApnSetting mApnSetting;
    private ApnSetting mApnSetting;


    private DataConnection mDataConnection;
    private DataConnection mDataConnection;


    String mReason;
    private String mReason;


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


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

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


    private final DcTracker mDcTracker;
    private final DcTracker mDcTracker;



    /**
    /**
     * Remember this as a change in this value to a more permissive state
     * Remember this as a change in this value to a more permissive state
     * should cause us to retry even permanent failures
     * should cause us to retry even permanent failures
@@ -100,27 +94,40 @@ public class ApnContext {
    private final RetryManager mRetryManager;
    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 phone phone object
     * @param apnType APN type (e.g. default, supl, mms, etc...)
     * @param apnType APN type (e.g. default, supl, mms, etc...)
     * @param logTag Tag for logging
     * @param logTag Tag for logging
     * @param config Network configuration
     * @param tracker Data call tracker
     * @param tracker Data call tracker
     * @param priority Priority of APN type
     */
     */
    public ApnContext(Phone phone, String apnType, String logTag, NetworkConfig config,
    public ApnContext(Phone phone, String apnType, String logTag, DcTracker tracker,
            DcTracker tracker) {
            int priority) {
        mPhone = phone;
        mPhone = phone;
        mApnType = apnType;
        mApnType = apnType;
        mState = DctConstants.State.IDLE;
        mState = DctConstants.State.IDLE;
        setReason(Phone.REASON_DATA_ENABLED);
        setReason(Phone.REASON_DATA_ENABLED);
        mDataEnabled = new AtomicBoolean(false);
        mDataEnabled = new AtomicBoolean(false);
        mDependencyMet = new AtomicBoolean(config.dependencyMet);
        mPriority = priority;
        priority = config.priority;
        LOG_TAG = logTag;
        LOG_TAG = logTag;
        mDcTracker = tracker;
        mDcTracker = tracker;
        mRetryManager = new RetryManager(phone, apnType);
        mRetryManager = new RetryManager(phone, apnType);
    }
    }




    /**
    /**
     * Get the APN type
     * Get the APN type
     * @return The APN type
     * @return The APN type
@@ -145,6 +152,23 @@ public class ApnContext {
        return mDataConnection;
        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.
     * Set the associated data connection.
     * @param dc data connection
     * @param dc data connection
@@ -312,7 +336,7 @@ public class ApnContext {
     * @return True if ready, otherwise false.
     * @return True if ready, otherwise false.
     */
     */
    public boolean isReady() {
    public boolean isReady() {
        return mDataEnabled.get() && mDependencyMet.get();
        return mDataEnabled.get() && isDependencyMet();
    }
    }


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


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

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


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


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


import java.util.HashMap;

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


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


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


    public String toString() {
    public String toString() {
@@ -54,26 +50,4 @@ public class DcRequest implements Comparable<DcRequest> {
    public int compareTo(DcRequest o) {
    public int compareTo(DcRequest o) {
        return o.priority - priority;
        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 Original line Diff line number Diff line
@@ -47,7 +47,6 @@ import android.net.INetworkPolicyListener;
import android.net.LinkProperties;
import android.net.LinkProperties;
import android.net.NetworkAgent;
import android.net.NetworkAgent;
import android.net.NetworkCapabilities;
import android.net.NetworkCapabilities;
import android.net.NetworkConfig;
import android.net.NetworkPolicyManager;
import android.net.NetworkPolicyManager;
import android.net.NetworkRequest;
import android.net.NetworkRequest;
import android.net.ProxyInfo;
import android.net.ProxyInfo;
@@ -123,6 +122,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashMap;
import java.util.List;
import java.util.List;
@@ -145,26 +145,6 @@ public class DcTracker extends Handler {
    private static final boolean VDBG_STALL = false; // STOPSHIP if true
    private static final boolean VDBG_STALL = false; // STOPSHIP if true
    private static final boolean RADIO_TESTS = false;
    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 = {
    @IntDef(value = {
            REQUEST_TYPE_NORMAL,
            REQUEST_TYPE_NORMAL,
            REQUEST_TYPE_HANDOVER,
            REQUEST_TYPE_HANDOVER,
@@ -287,7 +267,7 @@ public class DcTracker extends Handler {
            new PriorityQueue<ApnContext>(5,
            new PriorityQueue<ApnContext>(5,
            new Comparator<ApnContext>() {
            new Comparator<ApnContext>() {
                public int compare(ApnContext c1, ApnContext c2) {
                public int compare(ApnContext c1, ApnContext c2) {
                    return c2.priority - c1.priority;
                    return c2.getPriority() - c1.getPriority();
                }
                }
            } );
            } );


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


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


    private void initApnContexts() {
        log("initApnContexts: E");
        log("initApnContexts: E");
        // Load device network attributes from resources
        // Load device network attributes from resources
        String[] networkConfigStrings = mPhone.getContext().getResources().getStringArray(
        final Collection<ApnConfigType> types = ApnConfigTypeRepository.getDefault().getTypes();
                com.android.internal.R.array.networkAttributes);
        for (ApnConfigType apnConfigType : types) {
        for (String networkConfigString : networkConfigStrings) {
            addApnContext(apnConfigType);
            NetworkConfig networkConfig = new NetworkConfig(networkConfigString);
            log("initApnContexts: apnContext=" + ApnSetting.getApnTypeString(
            ApnContext apnContext;
                    apnConfigType.getType()));

            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;
        }
        }
            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) {
    public LinkProperties getLinkProperties(String apnType) {
@@ -1128,6 +1070,11 @@ public class DcTracker extends Handler {
        return result.toArray(new String[0]);
        return result.toArray(new String[0]);
    }
    }


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

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