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

Commit cbbb4bae authored by Chi Zhang's avatar Chi Zhang
Browse files

Add radio_state to telephony.proto

Bug: 177356513
Test: build && manual test && atest FrameworksTelephonyTests
Change-Id: Iec44e8c121fc888185c35382d3367468c5d49c6f
Merged-In: I0f776e7bd034b5644dd8fce1106b2c327e14d475
parent 0c52bf1a
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -836,6 +836,9 @@ message TelephonyEvent {

    // Signal strength
    SIGNAL_STRENGTH = 23;

    // Radio state change event
    RADIO_STATE_CHANGED = 24;
  }

  enum ApnType {
@@ -884,6 +887,20 @@ message TelephonyEvent {
    NETWORK_VALIDATION_STATE_PASSED = 3;
  }

  enum RadioState {
    /** Radio state is unknown or invalid. */
    RADIO_STATE_UNKNOWN = 0;

    /** Radio is explicitly off (e.g. airplane mode). */
    RADIO_STATE_OFF = 1;

    /** Radio is on. */
    RADIO_STATE_ON = 2;

    /** Radio power unavailable (eg, modem resetting or not booted). */
    RADIO_STATE_UNAVAILABLE = 3;
  }

  message DataSwitch {
    enum Reason {
      /** Data switch caused by unknown reason. */
@@ -1828,6 +1845,9 @@ message TelephonyEvent {
  //  (datapol.semantic_type) = ST_SOFTWARE_ID,
  //  (datapol.qualifier) = { is_public: true }
  //]

  // Radio state for the given phone_id
  optional RadioState radio_state = 29;
}

message ActiveSubscriptionInfo {
+6 −2
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ import android.telecom.PhoneAccountHandle;
import android.telecom.TelecomManager;
import android.telecom.VideoProfile;
import android.telephony.AccessNetworkConstants;
import android.telephony.Annotation.RadioPowerState;
import android.telephony.BarringInfo;
import android.telephony.CarrierConfigManager;
import android.telephony.CellIdentity;
@@ -96,6 +97,7 @@ import com.android.internal.telephony.gsm.SuppServiceNotification;
import com.android.internal.telephony.imsphone.ImsPhone;
import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
import com.android.internal.telephony.imsphone.ImsPhoneMmiCode;
import com.android.internal.telephony.metrics.TelephonyMetrics;
import com.android.internal.telephony.metrics.VoiceCallSessionStats;
import com.android.internal.telephony.test.SimulatedRadioControl;
import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
@@ -2763,8 +2765,10 @@ public class GsmCdmaPhone extends Phone {
    }

    private void handleRadioPowerStateChange() {
        Rlog.d(LOG_TAG, "handleRadioPowerStateChange, state= " + mCi.getRadioState());
        mNotifier.notifyRadioPowerStateChanged(this, mCi.getRadioState());
        @RadioPowerState int newState = mCi.getRadioState();
        Rlog.d(LOG_TAG, "handleRadioPowerStateChange, state= " + newState);
        mNotifier.notifyRadioPowerStateChanged(this, newState);
        TelephonyMetrics.getInstance().writeRadioState(mPhoneId, newState);
    }

    @Override
+7 −0
Original line number Diff line number Diff line
@@ -226,4 +226,11 @@ public class TelephonyEventBuilder {
        mEvent.networkCapabilities = networkCapabilities;
        return this;
    }

    /** Set radio state. */
    public TelephonyEventBuilder setRadioState(int radioState) {
        mEvent.type = TelephonyEvent.Type.RADIO_STATE_CHANGED;
        mEvent.radioState = radioState;
        return this;
    }
}
+40 −20
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import android.os.SystemClock;
import android.os.SystemProperties;
import android.provider.Telephony.Sms.Intents;
import android.telephony.AccessNetworkConstants;
import android.telephony.Annotation.RadioPowerState;
import android.telephony.CallQuality;
import android.telephony.DisconnectCause;
import android.telephony.NetworkRegistrationInfo;
@@ -104,6 +105,7 @@ import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.DataSwi
import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.ModemRestart;
import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.NetworkCapabilitiesInfo;
import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.OnDemandDataSwitch;
import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.RadioState;
import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.RilDeactivateDataCall;
import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.RilDeactivateDataCall.DeactivateReason;
import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.RilSetupDataCall;
@@ -177,8 +179,7 @@ public class TelephonyMetrics {
    private final SparseArray<TelephonyServiceState> mLastServiceState = new SparseArray<>();

    /**
     * Last ims capabilities. This is for injecting the base of a new log or a new call/sms
     * session
     * Last ims capabilities. This is for injecting the base of a new log or a new call/sms session
     */
    private final SparseArray<ImsCapabilities> mLastImsCapabilities = new SparseArray<>();

@@ -188,19 +189,16 @@ public class TelephonyMetrics {
     */
    private final SparseArray<ImsConnectionState> mLastImsConnectionState = new SparseArray<>();

    /**
     * Last settings state. This is for deduping same settings event logged.
     */
    /** Last settings state. This is for deduping same settings event logged. */
    private final SparseArray<TelephonySettings> mLastSettings = new SparseArray<>();

    /**
     * Last sim state, indexed by phone id.
     */
    /** Last sim state, indexed by phone id. */
    private final SparseArray<Integer> mLastSimState = new SparseArray<>();

    /**
     * Last active subscription information, indexed by phone id.
     */
    /** Last radio state, indexed by phone id. */
    private final SparseArray<Integer> mLastRadioState = new SparseArray<>();

    /** Last active subscription information, indexed by phone id. */
    private final SparseArray<ActiveSubscriptionInfo> mLastActiveSubscriptionInfos =
            new SparseArray<>();

@@ -212,20 +210,14 @@ public class TelephonyMetrics {
     */
    private int mLastEnabledModemBitmap = (1 << TelephonyManager.getDefault().getPhoneCount()) - 1;

    /**
     * Last carrier id matching.
     */
    /** Last carrier id matching. */
    private final SparseArray<CarrierIdMatching> mLastCarrierId = new SparseArray<>();

    /**
     * Last NetworkCapabilitiesInfo, indexed by phone id.
     */
    /** Last NetworkCapabilitiesInfo, indexed by phone id. */
    private final SparseArray<NetworkCapabilitiesInfo> mLastNetworkCapabilitiesInfos =
            new SparseArray<>();

    /**
     * Last RilDataCall Events (indexed by cid), indexed by phone id
     */
    /** Last RilDataCall Events (indexed by cid), indexed by phone id */
    private final SparseArray<SparseArray<RilDataCall>> mLastRilDataCallEvents =
            new SparseArray<>();

@@ -720,6 +712,13 @@ public class TelephonyMetrics {
                        .setDataCalls(dataCalls).build());
            }
        }

        for (int i = 0; i < mLastRadioState.size(); i++) {
            final int key = mLastRadioState.keyAt(i);
            TelephonyEvent event = new TelephonyEventBuilder(mStartElapsedTimeMs, key)
                    .setRadioState(mLastRadioState.get(key)).build();
            addTelephonyEvent(event);
        }
    }

    /**
@@ -2681,6 +2680,27 @@ public class TelephonyMetrics {
        addTelephonyEvent(event);
    }

    /** Write radio state changed event */
    public void writeRadioState(int phoneId, @RadioPowerState int state) {
        int radioState = convertRadioState(state);
        TelephonyEvent event = new TelephonyEventBuilder(phoneId).setRadioState(radioState).build();
        mLastRadioState.put(phoneId, radioState);
        addTelephonyEvent(event);
    }

    private static int convertRadioState(@RadioPowerState int state) {
        switch (state) {
            case TelephonyManager.RADIO_POWER_OFF:
                return RadioState.RADIO_STATE_OFF;
            case TelephonyManager.RADIO_POWER_ON:
                return RadioState.RADIO_STATE_ON;
            case TelephonyManager.RADIO_POWER_UNAVAILABLE:
                return RadioState.RADIO_STATE_UNAVAILABLE;
            default:
                return RadioState.RADIO_STATE_UNKNOWN;
        }
    }

    /**
     * Convert SMS format
     */