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

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

Merge "Add hidden API to support allowed networks reason" am: 2fd7bb6b

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

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


    private boolean mUnitTestMode;
    private boolean mUnitTestMode;

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


    protected VoiceCallSessionStats mVoiceCallSessionStats;
    protected VoiceCallSessionStats mVoiceCallSessionStats;
@@ -1708,6 +1710,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
     * Set the properties by matching the carrier string in
     * a string-array resource
     * a string-array resource
@@ -2017,6 +2036,16 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
        editor.apply();
        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) {
    public void setVoiceCallForwardingFlag(int line, boolean enable, String number) {
        setCallForwardingIndicatorInSharedPref(enable);
        setCallForwardingIndicatorInSharedPref(enable);
        IccRecords r = getIccRecords();
        IccRecords r = getIccRecords();
@@ -2131,6 +2160,55 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
        mCi.setCdmaSubscriptionSource(cdmaSubscriptionType, response);
        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
     *  Requests to set the preferred network type for searching and registering
     * (CS/PS domain, RAT, and operation mode)
     * (CS/PS domain, RAT, and operation mode)
@@ -2143,21 +2221,7 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
        int modemRaf = getRadioAccessFamily();
        int modemRaf = getRadioAccessFamily();
        int rafFromType = RadioAccessFamily.getRafFromNetworkType(networkType);
        int rafFromType = RadioAccessFamily.getRafFromNetworkType(networkType);


        long allowedNetworkTypes = -1;
        long allowedNetworkTypes = getAllowedNetworkTypes();
        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");
                }
            }
        }

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


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

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


        mCi.setPreferredNetworkType(filteredType, response);
        mCi.setPreferredNetworkType(filteredType, response);