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

Commit 8bc5e1c1 authored by Sooraj Sasindran's avatar Sooraj Sasindran Committed by Automerger Merge Worker
Browse files

Merge "Add hidden API to support allowed networks reason" into rvc-dev am:...

Merge "Add hidden API to support allowed networks reason" into rvc-dev am: 844ca213 am: dacd8231

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/opt/telephony/+/11715931

Change-Id: Ib62f601ab116e54c77d25f0ec1f93a9888ff2d2f
parents cb79c266 dacd8231
Loading
Loading
Loading
Loading
+85 −18
Original line number Diff line number Diff line
@@ -95,9 +95,11 @@ import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
@@ -423,7 +425,7 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
    protected SimulatedRadioControl mSimulatedRadioControl;

    private boolean mUnitTestMode;

    private Map<Integer, Long> mAllowedNetworkTypesForReasons = new HashMap<>();
    private final CarrierPrivilegesTracker mCarrierPrivilegesTracker;

    protected VoiceCallSessionStats mVoiceCallSessionStats;
@@ -1719,6 +1721,23 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
        }
    }

    private @TelephonyManager.NetworkTypeBitMask long getAllowedNetworkTypes() {
        long allowedNetworkTypes = TelephonyManager.getAllNetworkTypesBitmask();
        if (SubscriptionController.getInstance() != null) {
            String result = SubscriptionController.getInstance().getSubscriptionProperty(
                    getSubId(),
                    SubscriptionManager.ALLOWED_NETWORK_TYPES);

            if (result != null) {
                try {
                    allowedNetworkTypes = Long.parseLong(result);
                } catch (NumberFormatException err) {
                    Rlog.e(LOG_TAG, "allowedNetworkTypes NumberFormat exception");
                }
            }
        }
        return allowedNetworkTypes;
    }
    /**
     * Set the properties by matching the carrier string in
     * a string-array resource
@@ -2036,6 +2055,16 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
        editor.apply();
    }

    private @TelephonyManager.NetworkTypeBitMask long getAllowedNetworkTypesForAllReasons() {
        long allowedNetworkTypes = TelephonyManager.getAllNetworkTypesBitmask();
        synchronized (mAllowedNetworkTypesForReasons) {
            for (long networkTypes: mAllowedNetworkTypesForReasons.values()) {
                allowedNetworkTypes = allowedNetworkTypes & networkTypes;
            }
        }
        return allowedNetworkTypes;
    }

    public void setVoiceCallForwardingFlag(int line, boolean enable, String number) {
        setCallForwardingIndicatorInSharedPref(enable);
        IccRecords r = getIccRecords();
@@ -2150,6 +2179,55 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
        mCi.setCdmaSubscriptionSource(cdmaSubscriptionType, response);
    }

    /**
     * Get the effective allowed network types on the device.
     * @return effective network type
     */
    public @TelephonyManager.NetworkTypeBitMask long getEffectiveAllowedNetworkTypes() {
        long allowedNetworkTypes = getAllowedNetworkTypes();
        return allowedNetworkTypes & getAllowedNetworkTypesForAllReasons();
    }

    /**
     * Get the allowed network types for a certain reason.
     * @param reason reason to configure allowed network types
     * @return the allowed network types.
     */
    public @TelephonyManager.NetworkTypeBitMask long getAllowedNetworkTypes(
            @TelephonyManager.AllowedNetworkTypesReason int reason) {
        synchronized (mAllowedNetworkTypesForReasons) {
            switch (reason) {
                case TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER:
                    return mAllowedNetworkTypesForReasons.getOrDefault(
                            TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER,
                            TelephonyManager.getAllNetworkTypesBitmask());
                default:
                    Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason);
                    return TelephonyManager.getAllNetworkTypesBitmask();
            }
        }
    }

    /**
     * Requests to set the allowed network types for a specific reason
     * @param reason reason to configure allowed network type
     * @param networkTypes one of the network types
     */
    public void setAllowedNetworkTypes(@TelephonyManager.AllowedNetworkTypesReason int reason,
            @TelephonyManager.NetworkTypeBitMask long networkTypes) {
        synchronized (mAllowedNetworkTypesForReasons) {
            switch (reason) {
                case TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER:
                    mAllowedNetworkTypesForReasons.put(
                            TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER, networkTypes);
                    break;
                default:
                    Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason);
                    break;
            }
        }
    }

    /**
     *  Requests to set the preferred network type for searching and registering
     * (CS/PS domain, RAT, and operation mode)
@@ -2162,21 +2240,7 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
        int modemRaf = getRadioAccessFamily();
        int rafFromType = RadioAccessFamily.getRafFromNetworkType(networkType);

        long allowedNetworkTypes = -1;
        if (SubscriptionController.getInstance() != null) {
            String result = SubscriptionController.getInstance().getSubscriptionProperty(
                    getSubId(),
                    SubscriptionManager.ALLOWED_NETWORK_TYPES);

            if (result != null) {
                try {
                    allowedNetworkTypes = Long.parseLong(result);
                } catch (NumberFormatException err) {
                    Rlog.d(LOG_TAG, "allowedNetworkTypes NumberFormat exception");
                }
            }
        }

        long allowedNetworkTypes = getAllowedNetworkTypes();
        if (modemRaf == RadioAccessFamily.RAF_UNKNOWN
                || rafFromType == RadioAccessFamily.RAF_UNKNOWN) {
            Rlog.d(LOG_TAG, "setPreferredNetworkType: Abort, unknown RAF: "
@@ -2191,13 +2255,16 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
            return;
        }

        int filteredRaf = (int) (rafFromType & modemRaf & allowedNetworkTypes);
        int filteredRaf = (int) (rafFromType & modemRaf & allowedNetworkTypes
                & getAllowedNetworkTypesForAllReasons());
        int filteredType = RadioAccessFamily.getNetworkTypeFromRaf(filteredRaf);

        long powerAllowedNetworkTypes = getAllowedNetworkTypes(
                TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER);
        Rlog.d(LOG_TAG, "setPreferredNetworkType: networkType = " + networkType
                + " modemRaf = " + modemRaf
                + " rafFromType = " + rafFromType
                + " allowedNetworkTypes = " + allowedNetworkTypes
                + " power allowedNetworkTypes = " + powerAllowedNetworkTypes
                + " filteredType = " + filteredType);

        mCi.setPreferredNetworkType(filteredType, response);