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

Commit 5de3c5fe authored by Amit Mahajan's avatar Amit Mahajan Committed by Gerrit Code Review
Browse files

Merge "Add new vendor prefix data files"

parents eedd3319 2a990bba
Loading
Loading
Loading
Loading
+34 −34
Original line number Diff line number Diff line
@@ -84,7 +84,7 @@ import java.util.concurrent.CompletableFuture;
 */
public class PhoneSwitcher extends Handler {
    private static final String LOG_TAG = "PhoneSwitcher";
    private static final boolean VDBG = false;
    protected static final boolean VDBG = false;

    private static final int DEFAULT_NETWORK_CHANGE_TIMEOUT_MS = 5000;
    private static final int MODEM_COMMAND_RETRY_PERIOD_MS     = 5000;
@@ -154,17 +154,17 @@ public class PhoneSwitcher extends Handler {
        }
    }

    private final List<DcRequest> mPrioritizedDcRequests = new ArrayList<>();
    private final RegistrantList mActivePhoneRegistrants;
    private final SubscriptionController mSubscriptionController;
    private final Context mContext;
    protected final List<DcRequest> mPrioritizedDcRequests = new ArrayList<DcRequest>();
    protected final RegistrantList mActivePhoneRegistrants;
    protected final SubscriptionController mSubscriptionController;
    protected final Context mContext;
    private final LocalLog mLocalLog;
    private PhoneState[] mPhoneStates;
    private int[] mPhoneSubscriptions;
    private final CellularNetworkValidator mValidator;
    protected PhoneState[] mPhoneStates;
    protected int[] mPhoneSubscriptions;
    @VisibleForTesting
    protected final CellularNetworkValidator mValidator;
    private int mPendingSwitchSubId = INVALID_SUBSCRIPTION_ID;
    private boolean mPendingSwitchNeedValidation;

    @VisibleForTesting
    public final CellularNetworkValidator.ValidationCallback mValidationCallback =
            new CellularNetworkValidator.ValidationCallback() {
@@ -185,16 +185,16 @@ public class PhoneSwitcher extends Handler {
    @UnsupportedAppUsage
    // How many phones (correspondingly logical modems) are allowed for PS attach. This is used
    // when we specifically use setDataAllowed to initiate on-demand PS(data) attach for each phone.
    private int mMaxDataAttachModemCount;
    protected int mMaxDataAttachModemCount;
    // Local cache of TelephonyManager#getActiveModemCount(). 1 if in single SIM mode, 2 if in dual
    // SIM mode.
    private int mActiveModemCount;
    private static PhoneSwitcher sPhoneSwitcher = null;
    protected int mActiveModemCount;
    protected static PhoneSwitcher sPhoneSwitcher = null;

    // Which primary (non-opportunistic) subscription is set as data subscription among all primary
    // subscriptions. This value usually comes from user setting, and it's the subscription used for
    // Internet data if mOpptDataSubId is not set.
    private int mPrimaryDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
    protected int mPrimaryDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;

    // mOpptDataSubId must be an active subscription. If it's set, it overrides mPrimaryDataSubId
    // to be used for Internet data.
@@ -202,7 +202,7 @@ public class PhoneSwitcher extends Handler {

    // The phone ID that has an active voice call. If set, and its mobile data setting is on,
    // it will become the mPreferredDataPhoneId.
    private int mPhoneIdInVoiceCall = SubscriptionManager.INVALID_PHONE_INDEX;
    protected int mPhoneIdInVoiceCall = SubscriptionManager.INVALID_PHONE_INDEX;

    @VisibleForTesting
    // It decides:
@@ -214,7 +214,7 @@ public class PhoneSwitcher extends Handler {
    protected int mPreferredDataPhoneId = SubscriptionManager.INVALID_PHONE_INDEX;

    // Subscription ID corresponds to mPreferredDataPhoneId.
    private int mPreferredDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
    protected int mPreferredDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;

    // If non-null, An emergency call is about to be started, is ongoing, or has just ended and we
    // are overriding the DDS.
@@ -224,7 +224,7 @@ public class PhoneSwitcher extends Handler {
    private ISetOpportunisticDataCallback mSetOpptSubCallback;

    private static final int EVENT_PRIMARY_DATA_SUB_CHANGED       = 101;
    private static final int EVENT_SUBSCRIPTION_CHANGED           = 102;
    protected static final int EVENT_SUBSCRIPTION_CHANGED           = 102;
    private static final int EVENT_REQUEST_NETWORK                = 103;
    private static final int EVENT_RELEASE_NETWORK                = 104;
    // ECBM has started/ended. If we just ended an emergency call and mEmergencyOverride is not
@@ -262,12 +262,12 @@ public class PhoneSwitcher extends Handler {
    // Depending on version of IRadioConfig, we need to send either RIL_REQUEST_ALLOW_DATA if it's
    // 1.0, or RIL_REQUEST_SET_PREFERRED_DATA if it's 1.1 or later. So internally mHalCommandToUse
    // will be either HAL_COMMAND_ALLOW_DATA or HAL_COMMAND_ALLOW_DATA or HAL_COMMAND_UNKNOWN.
    private static final int HAL_COMMAND_UNKNOWN        = 0;
    private static final int HAL_COMMAND_ALLOW_DATA     = 1;
    private static final int HAL_COMMAND_PREFERRED_DATA = 2;
    private int mHalCommandToUse = HAL_COMMAND_UNKNOWN;
    protected static final int HAL_COMMAND_UNKNOWN        = 0;
    protected static final int HAL_COMMAND_ALLOW_DATA     = 1;
    protected static final int HAL_COMMAND_PREFERRED_DATA = 2;
    protected int mHalCommandToUse = HAL_COMMAND_UNKNOWN;

    private RadioConfig mRadioConfig;
    protected RadioConfig mRadioConfig;

    private final static int MAX_LOCAL_LOG_LINES = 30;

@@ -768,8 +768,8 @@ public class PhoneSwitcher extends Handler {
        return (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
    }

    private static final boolean REQUESTS_CHANGED   = true;
    private static final boolean REQUESTS_UNCHANGED = false;
    protected static final boolean REQUESTS_CHANGED   = true;
    protected static final boolean REQUESTS_UNCHANGED = false;
    /**
     * Re-evaluate things. Do nothing if nothing's changed.
     *
@@ -779,7 +779,7 @@ public class PhoneSwitcher extends Handler {
     *
     * @return {@code True} if the default data subscription need to be changed.
     */
    private boolean onEvaluate(boolean requestsChanged, String reason) {
    protected boolean onEvaluate(boolean requestsChanged, String reason) {
        StringBuilder sb = new StringBuilder(reason);

        // If we use HAL_COMMAND_PREFERRED_DATA,
@@ -907,18 +907,18 @@ public class PhoneSwitcher extends Handler {
        return diffDetected;
    }

    private static class PhoneState {
    protected static class PhoneState {
        public volatile boolean active = false;
        public long lastRequested = 0;
    }

    @UnsupportedAppUsage
    private void activate(int phoneId) {
    protected void activate(int phoneId) {
        switchPhone(phoneId, true);
    }

    @UnsupportedAppUsage
    private void deactivate(int phoneId) {
    protected void deactivate(int phoneId) {
        switchPhone(phoneId, false);
    }

@@ -971,7 +971,7 @@ public class PhoneSwitcher extends Handler {
        msg.sendToTarget();
    }

    private void sendRilCommands(int phoneId) {
    protected void sendRilCommands(int phoneId) {
        if (!SubscriptionManager.isValidPhoneId(phoneId)) return;

        Message message = Message.obtain(this, EVENT_MODEM_COMMAND_DONE, phoneId);
@@ -1030,7 +1030,7 @@ public class PhoneSwitcher extends Handler {
        return phoneId;
    }

    private int getSubIdFromNetworkSpecifier(NetworkSpecifier specifier) {
    protected int getSubIdFromNetworkSpecifier(NetworkSpecifier specifier) {
        if (specifier == null) {
            return DEFAULT_SUBSCRIPTION_ID;
        }
@@ -1050,7 +1050,7 @@ public class PhoneSwitcher extends Handler {

    // This updates mPreferredDataPhoneId which decides which phone should handle default network
    // requests.
    private void updatePreferredDataPhoneId() {
    protected void updatePreferredDataPhoneId() {
        Phone voicePhone = findPhoneById(mPhoneIdInVoiceCall);
        if (mEmergencyOverride != null && findPhoneById(mEmergencyOverride.mPhoneId) != null) {
            // Override DDS for emergency even if user data is not enabled, since it is an
@@ -1086,7 +1086,7 @@ public class PhoneSwitcher extends Handler {
        mPreferredDataSubId = mSubscriptionController.getSubIdUsingPhoneId(mPreferredDataPhoneId);
    }

    private void transitionToEmergencyPhone() {
    protected void transitionToEmergencyPhone() {
        if (mActiveModemCount <= 0) {
            log("No phones: unable to reset preferred phone for emergency");
            return;
@@ -1324,7 +1324,7 @@ public class PhoneSwitcher extends Handler {
                subId, needValidation ? 1 : 0, callback).sendToTarget();
    }

    private boolean isPhoneInVoiceCall(Phone phone) {
    protected boolean isPhoneInVoiceCall(Phone phone) {
        if (phone == null) {
            return false;
        }
@@ -1354,7 +1354,7 @@ public class PhoneSwitcher extends Handler {
    }

    @UnsupportedAppUsage
    private void log(String l) {
    protected void log(String l) {
        Rlog.d(LOG_TAG, l);
        mLocalLog.log(l);
    }
@@ -1370,7 +1370,7 @@ public class PhoneSwitcher extends Handler {
    /**
     * See {@link PhoneStateListener#LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE}.
     */
    private void notifyPreferredDataSubIdChanged() {
    protected void notifyPreferredDataSubIdChanged() {
        TelephonyRegistryManager telephonyRegistryManager = (TelephonyRegistryManager) mContext
                .getSystemService(Context.TELEPHONY_REGISTRY_SERVICE);
        log("notifyPreferredDataSubIdChanged to " + mPreferredDataSubId);
+16 −16
Original line number Diff line number Diff line
@@ -137,7 +137,7 @@ import java.util.stream.Collectors;
 * {@hide}
 */
public class DcTracker extends Handler {
    private static final boolean DBG = true;
    protected static final boolean DBG = true;
    private static final boolean VDBG = false; // STOPSHIP if true
    private static final boolean VDBG_STALL = false; // STOPSHIP if true
    private static final boolean RADIO_TESTS = false;
@@ -238,7 +238,7 @@ public class DcTracker extends Handler {
    private static final int DATA_STALL_ALARM_AGGRESSIVE_DELAY_IN_MS_DEFAULT = 1000 * 60;

    private static final boolean DATA_STALL_SUSPECTED = true;
    private static final boolean DATA_STALL_NOT_SUSPECTED = false;
    protected static final boolean DATA_STALL_NOT_SUSPECTED = false;

    private static final String INTENT_DATA_STALL_ALARM =
            "com.android.internal.telephony.data-stall";
@@ -568,10 +568,10 @@ public class DcTracker extends Handler {
    // True if data stall detection is enabled
    private volatile boolean mDataStallNoRxEnabled = true;

    private volatile boolean mFailFast = false;
    protected volatile boolean mFailFast = false;

    // True when in voice call
    private boolean mInVoiceCall = false;
    protected boolean mInVoiceCall = false;

    /** Intent sent when the reconnect alarm fires. */
    private PendingIntent mReconnectIntent = null;
@@ -596,7 +596,7 @@ public class DcTracker extends Handler {
    private HashMap<String, Integer> mApnToDataConnectionId = new HashMap<String, Integer>();

    /** Phone.APN_TYPE_* ===> ApnContext */
    private ConcurrentHashMap<String, ApnContext> mApnContexts =
    protected ConcurrentHashMap<String, ApnContext> mApnContexts =
            new ConcurrentHashMap<String, ApnContext>();

    private SparseArray<ApnContext> mApnContextsByType = new SparseArray<ApnContext>();
@@ -1484,7 +1484,7 @@ public class DcTracker extends Handler {
        }
    }

    private void setupDataOnConnectableApn(ApnContext apnContext, String reason,
    protected void setupDataOnConnectableApn(ApnContext apnContext, String reason,
            RetryFailures retryFailures) {
        if (VDBG) log("setupDataOnAllConnectableApns: apnContext " + apnContext);

@@ -2229,7 +2229,7 @@ public class DcTracker extends Handler {
        return retry;
    }

    private void startReconnect(long delay, ApnContext apnContext) {
    protected void startReconnect(long delay, ApnContext apnContext) {
        Message msg = obtainMessage(DctConstants.EVENT_DATA_RECONNECT,
                       mPhone.getSubId(), mTransportType, apnContext);
        cancelReconnect(apnContext);
@@ -2247,7 +2247,7 @@ public class DcTracker extends Handler {
     *
     * @param apnContext on which the alarm should be stopped.
     */
    private void cancelReconnect(ApnContext apnContext) {
    protected void cancelReconnect(ApnContext apnContext) {
        if (apnContext == null) return;

        if (DBG) {
@@ -2787,7 +2787,7 @@ public class DcTracker extends Handler {
     * A SETUP (aka bringUp) has completed, possibly with an error. If
     * there is an error this method will call {@link #onDataSetupCompleteError}.
     */
    private void onDataSetupComplete(ApnContext apnContext, boolean success, int cause,
    protected void onDataSetupComplete(ApnContext apnContext, boolean success, int cause,
                                     @RequestNetworkType int requestType) {
        int apnType = ApnSetting.getApnTypesBitmaskFromString(apnContext.getApnType());
        List<Message> messageList = mRequestNetworkCompletionMsgs.get(apnType);
@@ -2969,7 +2969,7 @@ public class DcTracker extends Handler {
     * beginning if the list is empty. Between each SETUP request there will
     * be a delay defined by {@link #getApnDelay()}.
     */
    private void onDataSetupCompleteError(ApnContext apnContext,
    protected void onDataSetupCompleteError(ApnContext apnContext,
                                          @RequestNetworkType int requestType) {
        long delay = apnContext.getDelayForNextApn(mFailFast);

@@ -3116,7 +3116,7 @@ public class DcTracker extends Handler {
        }
    }

    private void onVoiceCallEnded() {
    protected void onVoiceCallEnded() {
        if (DBG) log("onVoiceCallEnded");
        mInVoiceCall = false;
        if (isConnected()) {
@@ -3133,7 +3133,7 @@ public class DcTracker extends Handler {
        setupDataOnAllConnectableApns(Phone.REASON_VOICE_CALL_ENDED, RetryFailures.ALWAYS);
    }

    private boolean isConnected() {
    protected boolean isConnected() {
        for (ApnContext apnContext : mApnContexts.values()) {
            if (apnContext.getState() == DctConstants.State.CONNECTED) {
                // At least one context is connected, return true
@@ -4421,13 +4421,13 @@ public class DcTracker extends Handler {
    /**
     * Polling stuff
     */
    private void resetPollStats() {
    protected void resetPollStats() {
        mTxPkts = -1;
        mRxPkts = -1;
        mNetStatPollPeriod = POLL_NETSTAT_MILLIS;
    }

    private void startNetStatPoll() {
    protected void startNetStatPoll() {
        if (getOverallState() == DctConstants.State.CONNECTED
                && mNetStatPollEnabled == false) {
            if (DBG) {
@@ -4868,7 +4868,7 @@ public class DcTracker extends Handler {
        startDataStallAlarm(suspectedStall);
    }

    private void startDataStallAlarm(boolean suspectedStall) {
    protected void startDataStallAlarm(boolean suspectedStall) {
        int delayInMs;

        if (mDsRecoveryHandler.isNoRxDataStallDetectionEnabled()
@@ -5060,7 +5060,7 @@ public class DcTracker extends Handler {
    }

    @RilRadioTechnology
    private int getDataRat() {
    protected int getDataRat() {
        ServiceState ss = mPhone.getServiceState();
        NetworkRegistrationInfo nrs = ss.getNetworkRegistrationInfo(
                NetworkRegistrationInfo.DOMAIN_PS, mTransportType);
+648 −0

File added.

Preview size limit exceeded, changes collapsed.

+209 −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.vendor.dataconnection;

import com.android.internal.telephony.DctConstants;
import com.android.internal.telephony.IccCardConstants;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.TelephonyIntents;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.AsyncResult;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.os.SystemProperties;

import android.telephony.CellLocation;
import android.telephony.PhoneStateListener;
import android.telephony.Rlog;
import android.telephony.ServiceState;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telephony.gsm.GsmCellLocation;
import android.text.TextUtils;
import android.util.Log;
import android.util.Pair;

import java.util.ArrayList;

public class VendorDataResetEventTracker {

    public static interface ResetEventListener {
        public void onResetEvent(boolean retry);
    }

    private static final boolean DBG = true;

    private TelephonyManager mTelephonyManager = null;
    private GsmCellLocation mPreviousLocation = null;
    private PhoneStateListener mPhoneStateListener = null;
    private Context mContext = null;
    private Phone mPhone = null;
    private ResetEventListener mListener = null;
    private int mPreviousRAT = 0;
    private int mTransportType;

    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case DctConstants.EVENT_DATA_RAT_CHANGED: {
                    AsyncResult ar = (AsyncResult) msg.obj;
                    Pair<Integer, Integer> result = (Pair<Integer, Integer>) ar.result;
                    if (result != null) {
                        if (mPreviousRAT > 0 && result.second > 0
                                && mPreviousRAT != result.second) {
                            if (DBG) log("RAT CHANGED, " + mPreviousRAT
                                     + "->" + result.second);
                            notifyResetEvent("DATA_RAT_CHANGED", false);
                        }
                        mPreviousRAT = result.second;
                    }
                    break;
                }
                case DctConstants.EVENT_RADIO_OFF_OR_NOT_AVAILABLE: {
                    if (DBG) log("EVENT_RADIO_OFF_OR_NOT_AVAILABLE");
                    notifyResetEvent("RADIO_OFF_OR_NOT_AVAILABLE", false);
                    break;
                }
            }
        }
    };

    private BroadcastReceiver mSimStateReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            final String action = intent.getAction();
            if (TelephonyIntents.ACTION_SIM_STATE_CHANGED.equals(action)) {
                final String stateExtra = intent
                        .getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE);
                log("ACTION_SIM_STATE_CHANGED, action " + stateExtra);
                if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(stateExtra)) {
                    notifyResetEvent("SIM_STATE_ABSENT", false);
                }
            }
        }
    };

    public VendorDataResetEventTracker(int transportType, Phone phone,
            ResetEventListener listener) {
        if (DBG) log("VendorDataResetEventTracker constructor: " + this);
        mPhone = phone;
        mContext = mPhone.getContext();
        this.mListener = listener;
        mTransportType = transportType;
        mTelephonyManager = (TelephonyManager) mContext
                .getSystemService(Context.TELEPHONY_SERVICE);
    }

    /**
     * Register listener for RAU update and RAT change.
     */
    public void startResetEventTracker() {
        if (DBG) log("startResetEventTracker");
        mPhone.getServiceStateTracker().registerForDataRegStateOrRatChanged(
                mTransportType, mHandler, DctConstants.EVENT_DATA_RAT_CHANGED, null);
        mPhone.mCi.registerForOffOrNotAvailable(mHandler,
                DctConstants.EVENT_RADIO_OFF_OR_NOT_AVAILABLE, null);
        mContext.registerReceiver(mSimStateReceiver, new IntentFilter(
                TelephonyIntents.ACTION_SIM_STATE_CHANGED));

        CellLocation currentCellLocation = mPhone.getCellIdentity().asCellLocation();
        if (currentCellLocation instanceof GsmCellLocation) {
            mPreviousLocation = (GsmCellLocation) mPhone.getCellIdentity().asCellLocation();
            if (DBG) log("DataConnection mPreviousLocation : " + mPreviousLocation);
        }
        int ddsSubId = SubscriptionManager.getDefaultDataSubscriptionId();

        if (mPhoneStateListener == null) {
            mPhoneStateListener = new PhoneStateListener() {
                public void onCellLocationChanged(CellLocation location) {
                    if (DBG) log("DataConnection onCellLocationChanged : "
                                + location);

                    if (location instanceof GsmCellLocation) {
                        GsmCellLocation currentLocation = (GsmCellLocation) location;

                        if (mPreviousLocation != null
                                && currentLocation != null) {
                            if (mPreviousLocation.getCid() != currentLocation
                                    .getCid()
                                    || mPreviousLocation.getLac() != currentLocation
                                            .getLac()) {
                                if (DBG) log("DataConnection location updated");
                                notifyResetEvent("LOCATION_UPDATED", true);
                            }
                        }
                        mPreviousLocation = currentLocation;
                    }
                }
            };
        }

        mTelephonyManager.
                createForSubscriptionId(ddsSubId).
                listen(mPhoneStateListener, PhoneStateListener.LISTEN_CELL_LOCATION);
    }

    /**
     * Unregister for RAU update and RAT change.
     */
    public void stopResetEventTracker() {
        if (DBG) log("stopResetTimer");
        try {
            mPreviousRAT = 0;
            mPreviousLocation = null;
            if (mPhoneStateListener != null) {
                mTelephonyManager.listen(mPhoneStateListener,
                        PhoneStateListener.LISTEN_NONE);
            }
            mPhone.getServiceStateTracker()
                    .unregisterForDataRegStateOrRatChanged(mTransportType, mHandler);
            mPhone.mCi.unregisterForOffOrNotAvailable(mHandler);
            mContext.unregisterReceiver(mSimStateReceiver);
        } catch (Exception e) {
            if (DBG) log("error:" + e.getMessage());
            e.printStackTrace();
        }
    }

    public void dispose() {
        if (DBG) log("dispose");
        stopResetEventTracker();
        mTelephonyManager = null;
    }

    /**
     * notify the listener for reset event
     */
    private void notifyResetEvent(String reason, boolean retry) {
        if (DBG) log("notifyResetEvent: reason=" + reason + ", retry=" + retry);
        stopResetEventTracker();
        if (mListener != null) {
            mListener.onResetEvent(retry);
        }
    }

    private void log(String log) {
        Rlog.d("VendorDataResetEventTracker", log);
    }
}
+293 −5

File changed.

Preview size limit exceeded, changes collapsed.