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

Commit cc1afb47 authored by Pengquan Meng's avatar Pengquan Meng Committed by android-build-merger
Browse files

Merge "Refactor simState & activeSubscriptionInfo"

am: ec9f1c77

Change-Id: Ib24960a1fb4667b0ff7b10f45efc0fc197659f64
parents 241d3407 ec9f1c77
Loading
Loading
Loading
Loading
+41 −54
Original line number Original line Diff line number Diff line
@@ -50,6 +50,9 @@ message TelephonyLog {


  // Hardware revision (EVT, DVT, PVT etc.)
  // Hardware revision (EVT, DVT, PVT etc.)
  optional string hardware_revision = 9;
  optional string hardware_revision = 9;

  // The active subscription info for a specific slot.
  repeated ActiveSubscriptionInfo active_subscription_info = 10;
}
}


// The time information
// The time information
@@ -276,9 +279,6 @@ message TelephonyServiceState {


  // Current data radio technology
  // Current data radio technology
  optional RadioAccessTechnology data_rat = 6 [default = UNKNOWN];
  optional RadioAccessTechnology data_rat = 6 [default = UNKNOWN];

  // All the active subscription information.
  repeated ActiveSubscriptionInfo active_subscription_info = 7;
}
}


// Radio access families
// Radio access families
@@ -619,9 +619,6 @@ message RilDataCall {


  // The network interface name e.g. wlan0, rmnet_data0.
  // The network interface name e.g. wlan0, rmnet_data0.
  optional string iframe = 3;
  optional string iframe = 3;

  // All the active subscription information.
  repeated ActiveSubscriptionInfo active_subscription_info = 4;
}
}


message TelephonyEvent {
message TelephonyEvent {
@@ -675,35 +672,41 @@ message TelephonyEvent {
    // Carrier Key Change event.
    // Carrier Key Change event.
    CARRIER_KEY_CHANGED = 14;
    CARRIER_KEY_CHANGED = 14;


    // Phone status change event.
    PHONE_STATUS_CHANGED = 15;

    // Data switch event.
    // Data switch event.
    DATA_SWITCH = 16;
    DATA_SWITCH = 15;


    // Network validate event.
    // Network validate event.
    NETWORK_VALIDATE = 17;
    NETWORK_VALIDATE = 16;


    // On deman data switch event.
    // On deman data switch event.
    ON_DEMAND_DATA_SWITCH = 18;
    ON_DEMAND_DATA_SWITCH = 17;

    // SIM state change event.
    SIM_STATE_CHANGE = 18;

    // Active subscription info change event.
    ACTIVE_SUBSCRIPTION_INFO_CHANGE = 19;

    // Enabled modem change event.
    ENABLED_MODEM_CHANGE = 20;
  }
  }


  enum ApnType {
  enum ApnType {
      DEFAULT = 0;
      DEFAULT = 1;
      MMS = 1;
      MMS = 2;
      SUPL = 2;
      SUPL = 3;
      DUN = 3;
      DUN = 4;
      HIPRI = 4;
      HIPRI = 5;
      FOTA = 5;
      FOTA = 6;
      IMS = 6;
      IMS = 7;
      CBS = 7;
      CBS = 8;
      IA = 8;
      IA = 9;
      EMERGENCY = 9;
      EMERGENCY = 10;
  }
  }


  enum EventState {
  enum EventState {
      START = 0;
      START = 1;
      END = 1;
      END = 2;
  }
  }


  enum NetworkValidationState {
  enum NetworkValidationState {
@@ -1542,17 +1545,6 @@ message TelephonyEvent {
    optional string mccmnc = 3;
    optional string mccmnc = 3;
  }
  }


  message PhoneStatus {
      /** The sim state of each active slot. */
      repeated SimState sim_state = 1;

      /**
       * The modem state represent by a bitmap, the i-th bit(LSB) indicates the i-th modem
       * state(0 - disabled, 1 - enabled).
       */
      optional int32 enabled_modem_bitmap = 2;
  }

  // Time when event happened on device, in milliseconds since epoch
  // Time when event happened on device, in milliseconds since epoch
  optional int64 timestamp_millis = 1;
  optional int64 timestamp_millis = 1;


@@ -1604,9 +1596,6 @@ message TelephonyEvent {
  // Carrier key change
  // Carrier key change
  optional CarrierKeyChange carrier_key_change = 17;
  optional CarrierKeyChange carrier_key_change = 17;


  // Phone status
  optional PhoneStatus phone_status = 18;

  // Data switch event
  // Data switch event
  optional DataSwitch data_switch = 19;
  optional DataSwitch data_switch = 19;


@@ -1615,17 +1604,27 @@ message TelephonyEvent {


  // On demand data switch event
  // On demand data switch event
  optional OnDemandDataSwitch on_demand_data_switch = 21;
  optional OnDemandDataSwitch on_demand_data_switch = 21;

  // Sim state for each slot.
  repeated SimState sim_state = 22;

  // The active subscription info for a specific slot.
  optional ActiveSubscriptionInfo active_subscription_info = 23;

  // The modem state represent by a bitmap, the i-th bit(LSB) indicates the i-th modem
  // state(0 - disabled, 1 - enabled).
  optional int32 enabled_modem_bitmap = 24;
}
}


message ActiveSubscriptionInfo {
message ActiveSubscriptionInfo {
    /** The slot index which this subscription associated with. */
    /** The slot index which this subscription is associated with. */
    optional int32 slot_index = 1;
    optional int32 slot_index = 1;


    /** The Carrier id of this subscription. */
    /** The Carrier id of this subscription. -1 indicates unknown value. */
    optional int32 carrier_id = 2;
    optional int32 carrier_id = 2;


    /** whether subscription is opportunistic. */
    /** whether subscription is opportunistic (0 - false, 1 - true, -1 - unknown). */
    optional bool is_opportunistic = 3;
    optional int32 is_opportunistic = 3;
};
};


enum SimState {
enum SimState {
@@ -2007,12 +2006,6 @@ message TelephonyCallSession {


  // Indicating some call events are dropped
  // Indicating some call events are dropped
  optional bool events_dropped = 4;
  optional bool events_dropped = 4;

  // SIM state of the active slots
  repeated SimState sim_states = 5;

  // All the active subscription information.
  repeated ActiveSubscriptionInfo active_subscription_info = 6;
}
}


message SmsSession {
message SmsSession {
@@ -2227,12 +2220,6 @@ message SmsSession {


  // Indicating some sms session events are dropped
  // Indicating some sms session events are dropped
  optional bool events_dropped = 4;
  optional bool events_dropped = 4;

  // SIM state of the active slots.
  repeated SimState sim_state = 5;

  // All the active subscription information.
  repeated ActiveSubscriptionInfo active_subscription_info = 6;
}
}


// Power stats for modem
// Power stats for modem
+32 −7
Original line number Original line Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.internal.telephony.metrics;
import static com.android.internal.telephony.nano.TelephonyProto.ImsCapabilities;
import static com.android.internal.telephony.nano.TelephonyProto.ImsCapabilities;
import static com.android.internal.telephony.nano.TelephonyProto.ImsConnectionState;
import static com.android.internal.telephony.nano.TelephonyProto.ImsConnectionState;
import static com.android.internal.telephony.nano.TelephonyProto.RilDataCall;
import static com.android.internal.telephony.nano.TelephonyProto.RilDataCall;
import static com.android.internal.telephony.nano.TelephonyProto.SimState;
import static com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent;
import static com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent;
import static com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.CarrierIdMatching;
import static com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.CarrierIdMatching;
import static com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.CarrierKeyChange;
import static com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.CarrierKeyChange;
@@ -30,12 +31,16 @@ import static com.android.internal.telephony.nano.TelephonyProto.TelephonyServic
import static com.android.internal.telephony.nano.TelephonyProto.TelephonySettings;
import static com.android.internal.telephony.nano.TelephonyProto.TelephonySettings;


import android.os.SystemClock;
import android.os.SystemClock;
import android.telephony.TelephonyManager;
import android.util.SparseArray;


import com.android.internal.telephony.nano.TelephonyProto.ActiveSubscriptionInfo;
import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.DataSwitch;
import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.DataSwitch;
import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.OnDemandDataSwitch;
import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.OnDemandDataSwitch;
import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.PhoneStatus;
import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.Type;
import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.Type;


import java.util.Arrays;

public class TelephonyEventBuilder {
public class TelephonyEventBuilder {
    private final TelephonyEvent mEvent = new TelephonyEvent();
    private final TelephonyEvent mEvent = new TelephonyEvent();


@@ -144,12 +149,32 @@ public class TelephonyEventBuilder {
        return this;
        return this;
    }
    }


    /**
    /** Set and build SIM state change event. */
     * Set and build phone status changed event.
    public TelephonyEventBuilder setSimStateChange(SparseArray<Integer> simStates) {
     */
        int phoneCount = TelephonyManager.getDefault().getPhoneCount();
    public TelephonyEventBuilder setPhoneStatusChange(PhoneStatus phoneStatus) {
        mEvent.simState = new int[phoneCount];
        mEvent.type = Type.PHONE_STATUS_CHANGED;
        Arrays.fill(mEvent.simState, SimState.SIM_STATE_UNKNOWN);
        mEvent.phoneStatus = phoneStatus;
        mEvent.type = Type.SIM_STATE_CHANGE;
        for (int i = 0; i < simStates.size(); i++) {
            int key = simStates.keyAt(i);
            if (0 <= key && key < phoneCount) {
                mEvent.simState[key] = simStates.get(key);
            }
        }
        return this;
    }

    /** Set and build subscription info change event. */
    public TelephonyEventBuilder setActiveSubscriptionInfoChange(ActiveSubscriptionInfo info) {
        mEvent.type = Type.ACTIVE_SUBSCRIPTION_INFO_CHANGE;
        mEvent.activeSubscriptionInfo = info;
        return this;
    }

    /** Set and build enabled modem bitmap change event. */
    public TelephonyEventBuilder setEnabledModemBitmap(int enabledModemBitmap) {
        mEvent.type = Type.ENABLED_MODEM_CHANGE;
        mEvent.enabledModemBitmap = enabledModemBitmap;
        return this;
        return this;
    }
    }


+60 −28
Original line number Original line Diff line number Diff line
@@ -89,7 +89,6 @@ import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.Carrier
import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.DataSwitch;
import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.DataSwitch;
import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.ModemRestart;
import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.ModemRestart;
import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.OnDemandDataSwitch;
import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.OnDemandDataSwitch;
import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.PhoneStatus;
import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.RilDeactivateDataCall;
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.RilDeactivateDataCall.DeactivateReason;
import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.RilSetupDataCall;
import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.RilSetupDataCall;
@@ -600,7 +599,18 @@ public class TelephonyMetrics {
            addTelephonyEvent(event);
            addTelephonyEvent(event);
        }
        }


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

        addTelephonyEvent(new TelephonyEventBuilder(mStartElapsedTimeMs, -1 /* phoneId */)
                .setSimStateChange(mLastSimState).build());

        addTelephonyEvent(new TelephonyEventBuilder(mStartElapsedTimeMs, -1 /* phoneId */)
                .setEnabledModemBitmap(mLastEnabledModemBitmap).build());
    }
    }


    /**
    /**
@@ -657,6 +667,16 @@ public class TelephonyMetrics {
        log.endTime = new TelephonyProto.Time();
        log.endTime = new TelephonyProto.Time();
        log.endTime.systemTimestampMillis = System.currentTimeMillis();
        log.endTime.systemTimestampMillis = System.currentTimeMillis();
        log.endTime.elapsedTimestampMillis = SystemClock.elapsedRealtime();
        log.endTime.elapsedTimestampMillis = SystemClock.elapsedRealtime();

        // Log the last active subscription information.
        ActiveSubscriptionInfo[] activeSubscriptionInfo =
                new ActiveSubscriptionInfo[mLastActiveSubscriptionInfos.size()];
        for (int i = 0; i < mLastActiveSubscriptionInfos.size(); i++) {
            int key = mLastActiveSubscriptionInfos.keyAt(i);
            activeSubscriptionInfo[key] = mLastActiveSubscriptionInfos.get(key);
        }
        log.activeSubscriptionInfo = activeSubscriptionInfo;

        return log;
        return log;
    }
    }


@@ -666,48 +686,50 @@ public class TelephonyMetrics {
        Integer lastSimState = mLastSimState.get(phoneId);
        Integer lastSimState = mLastSimState.get(phoneId);
        if (lastSimState == null || !lastSimState.equals(state)) {
        if (lastSimState == null || !lastSimState.equals(state)) {
            mLastSimState.put(phoneId, state);
            mLastSimState.put(phoneId, state);
            writePhoneStatusChangedEvent();
            addTelephonyEvent(new TelephonyEventBuilder().setSimStateChange(mLastSimState).build());
        }
        }
    }
    }


    /** Update active subscription info list. */
    /** Update active subscription info list. */
    public void updateActiveSubscriptionInfoList(List<SubscriptionInfo> subInfos) {
    public void updateActiveSubscriptionInfoList(List<SubscriptionInfo> subInfos) {
        mLastActiveSubscriptionInfos.clear();
        List<Integer> inActivePhoneList = new ArrayList<>();
        for (int i = 0; i < mLastActiveSubscriptionInfos.size(); i++) {
            inActivePhoneList.add(mLastActiveSubscriptionInfos.keyAt(i));
        }

        for (SubscriptionInfo info : subInfos) {
        for (SubscriptionInfo info : subInfos) {
            int phoneId = SubscriptionManager.getPhoneId(info.getSubscriptionId());
            int phoneId = SubscriptionManager.getPhoneId(info.getSubscriptionId());
            inActivePhoneList.removeIf(value -> value.equals(phoneId));
            ActiveSubscriptionInfo activeSubscriptionInfo = new ActiveSubscriptionInfo();
            ActiveSubscriptionInfo activeSubscriptionInfo = new ActiveSubscriptionInfo();
            activeSubscriptionInfo.isOpportunistic = info.isOpportunistic();
            activeSubscriptionInfo.slotIndex = phoneId;
            activeSubscriptionInfo.isOpportunistic = info.isOpportunistic() ? 1 : 0;
            activeSubscriptionInfo.carrierId = info.getCarrierId();
            activeSubscriptionInfo.carrierId = info.getCarrierId();
            if (isDifferentSubscriptionInfo(
                    mLastActiveSubscriptionInfos.get(phoneId), activeSubscriptionInfo)) {
                addTelephonyEvent(new TelephonyEventBuilder(phoneId)
                        .setActiveSubscriptionInfoChange(activeSubscriptionInfo).build());

                mLastActiveSubscriptionInfos.put(phoneId, activeSubscriptionInfo);
                mLastActiveSubscriptionInfos.put(phoneId, activeSubscriptionInfo);
            }
            }
        }
        }


        for (int phoneId : inActivePhoneList) {
            mLastActiveSubscriptionInfos.remove(phoneId);
            ActiveSubscriptionInfo invalidSubInfo = new ActiveSubscriptionInfo();
            invalidSubInfo.slotIndex = phoneId;
            invalidSubInfo.carrierId = -1;
            invalidSubInfo.isOpportunistic = -1;
            addTelephonyEvent(new TelephonyEventBuilder(phoneId)
                    .setActiveSubscriptionInfoChange(invalidSubInfo).build());
        }
    }

    /** Update the enabled modem bitmap. */
    /** Update the enabled modem bitmap. */
    public void updateEnabledModemBitmap(int enabledModemBitmap) {
    public void updateEnabledModemBitmap(int enabledModemBitmap) {
        if (mLastEnabledModemBitmap == enabledModemBitmap) return;
        if (mLastEnabledModemBitmap == enabledModemBitmap) return;
        mLastEnabledModemBitmap = enabledModemBitmap;
        mLastEnabledModemBitmap = enabledModemBitmap;
        writePhoneStatusChangedEvent();
        addTelephonyEvent(new TelephonyEventBuilder()
    }
                .setEnabledModemBitmap(mLastEnabledModemBitmap).build());

    /** Write the event of phone status changed. */
    public void writePhoneStatusChangedEvent() {
        int phoneCount = TelephonyManager.getDefault().getPhoneCount();
        PhoneStatus phoneStatus = new PhoneStatus();
        phoneStatus.enabledModemBitmap = mLastEnabledModemBitmap;
        phoneStatus.simState = new int[phoneCount];
        Arrays.fill(phoneStatus.simState, SimState.SIM_STATE_ABSENT);
        for (int i = 0; i < mLastSimState.size(); i++) {
            int phoneId = mLastSimState.keyAt(i);
            if (SubscriptionManager.isValidPhoneId(phoneId)) {
                phoneStatus.simState[phoneId] = mLastSimState.get(phoneId);
            }
        }

        // Phone status is not associated with any phone id, so set the phone id to -1 for the phone
        // status changed event.
        addTelephonyEvent(new TelephonyEventBuilder(-1 /* phoneId */)
                .setPhoneStatusChange(phoneStatus)
                .build());
    }
    }


    /**
    /**
@@ -2462,4 +2484,14 @@ public class TelephonyMetrics {
                return SimState.SIM_STATE_UNKNOWN;
                return SimState.SIM_STATE_UNKNOWN;
        }
        }
    }
    }

    private static boolean isDifferentSubscriptionInfo(
            ActiveSubscriptionInfo oldInfo, ActiveSubscriptionInfo newInfo) {
        if (oldInfo == null || newInfo == null) {
            return oldInfo == newInfo;
        }

        return oldInfo.slotIndex != newInfo.slotIndex || oldInfo.carrierId != newInfo.carrierId
                || oldInfo.isOpportunistic != newInfo.isOpportunistic;
    }
}
}