Loading src/java/com/android/internal/telephony/SubscriptionController.java +20 −13 Original line number Diff line number Diff line Loading @@ -49,6 +49,7 @@ import android.util.Log; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.telephony.IccCardConstants.State; import com.android.internal.telephony.metrics.TelephonyMetrics; import com.android.internal.telephony.uicc.IccUtils; import com.android.internal.telephony.uicc.UiccCard; import com.android.internal.telephony.uicc.UiccController; Loading Loading @@ -280,6 +281,9 @@ public class SubscriptionController extends ISub.Stub { mContext.sendBroadcast(intent); } /** * Notify the changed of subscription info. */ public void notifySubscriptionInfoChanged() { ITelephonyRegistry tr = ITelephonyRegistry.Stub.asInterface(ServiceManager.getService( "telephony.registry")); Loading @@ -292,6 +296,9 @@ public class SubscriptionController extends ISub.Stub { // FIXME: Remove if listener technique accepted. broadcastSimInfoContentChanged(); TelephonyMetrics metrics = TelephonyMetrics.getInstance(); metrics.updateActiveSubscriptionInfoList(mCacheActiveSubInfoList); } /** Loading src/java/com/android/internal/telephony/SubscriptionInfoUpdater.java +3 −0 Original line number Diff line number Diff line Loading @@ -51,6 +51,7 @@ import android.text.TextUtils; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.telephony.euicc.EuiccController; import com.android.internal.telephony.metrics.TelephonyMetrics; import com.android.internal.telephony.uicc.IccRecords; import com.android.internal.telephony.uicc.IccUtils; import com.android.internal.telephony.uicc.UiccController; Loading Loading @@ -785,6 +786,7 @@ public class SubscriptionInfoUpdater extends Handler { logd("Broadcasting intent ACTION_SIM_CARD_STATE_CHANGED " + simStateString(state) + " for phone: " + phoneId); mContext.sendBroadcast(i, Manifest.permission.READ_PRIVILEGED_PHONE_STATE); TelephonyMetrics.getInstance().updateSimState(phoneId, state); } } Loading @@ -804,6 +806,7 @@ public class SubscriptionInfoUpdater extends Handler { logd("Broadcasting intent ACTION_SIM_APPLICATION_STATE_CHANGED " + simStateString(state) + " for phone: " + phoneId); mContext.sendBroadcast(i, Manifest.permission.READ_PRIVILEGED_PHONE_STATE); TelephonyMetrics.getInstance().updateSimState(phoneId, state); } } Loading src/java/com/android/internal/telephony/metrics/TelephonyEventBuilder.java +12 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,9 @@ import static com.android.internal.telephony.nano.TelephonyProto.TelephonySettin import android.os.SystemClock; import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.PhoneStatus; import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.Type; public class TelephonyEventBuilder { private final TelephonyEvent mEvent = new TelephonyEvent(); Loading Loading @@ -133,4 +136,13 @@ public class TelephonyEventBuilder { mEvent.carrierKeyChange = carrierKeyChange; return this; } /** * Set and build phone status changed event. */ public TelephonyEventBuilder setPhoneStatusChange(PhoneStatus phoneStatus) { mEvent.type = Type.PHONE_STATUS_CHANGED; mEvent.phoneStatus = phoneStatus; return this; } } src/java/com/android/internal/telephony/metrics/TelephonyMetrics.java +89 −1 Original line number Diff line number Diff line Loading @@ -45,6 +45,8 @@ import android.telephony.Rlog; import android.telephony.ServiceState; import android.telephony.SmsManager; import android.telephony.SmsMessage; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.telephony.TelephonyHistogram; import android.telephony.TelephonyManager; import android.telephony.data.DataCallResponse; Loading @@ -69,10 +71,12 @@ import com.android.internal.telephony.SmsResponse; import com.android.internal.telephony.UUSInfo; import com.android.internal.telephony.imsphone.ImsPhoneCall; import com.android.internal.telephony.nano.TelephonyProto; import com.android.internal.telephony.nano.TelephonyProto.ActiveSubscriptionInfo; import com.android.internal.telephony.nano.TelephonyProto.ImsCapabilities; import com.android.internal.telephony.nano.TelephonyProto.ImsConnectionState; import com.android.internal.telephony.nano.TelephonyProto.ModemPowerStats; import com.android.internal.telephony.nano.TelephonyProto.RilDataCall; import com.android.internal.telephony.nano.TelephonyProto.SimState; import com.android.internal.telephony.nano.TelephonyProto.SmsSession; import com.android.internal.telephony.nano.TelephonyProto.TelephonyCallSession; import com.android.internal.telephony.nano.TelephonyProto.TelephonyCallSession.Event.CallState; Loading @@ -83,6 +87,7 @@ import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.Carrier import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.CarrierIdMatchingResult; import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.CarrierKeyChange; import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.ModemRestart; 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.DeactivateReason; import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.RilSetupDataCall; Loading Loading @@ -167,6 +172,25 @@ public class TelephonyMetrics { */ private final SparseArray<TelephonySettings> mLastSettings = new SparseArray<>(); /** * Last sim state, indexed by phone id. */ private final SparseArray<Integer> mLastSimState = new SparseArray<>(); /** * Last active subscription information, indexed by phone id. */ private final SparseArray<ActiveSubscriptionInfo> mLastActiveSubscriptionInfos = new SparseArray<>(); /** * The last modem state represent by a bitmap, the i-th bit(LSB) indicates the i-th modem * state(0 - disabled, 1 - enabled). * * TODO: initialize the enabled modem bitmap when it's possible to get the modem state. */ private int mLastEnabledModemBitmap = (1 << TelephonyManager.getDefault().getPhoneCount()) - 1; /** * Last carrier id matching. */ Loading @@ -182,7 +206,8 @@ public class TelephonyMetrics { private boolean mTelephonyEventsDropped = false; public TelephonyMetrics() { reset(); mStartSystemTimeMs = System.currentTimeMillis(); mStartElapsedTimeMs = SystemClock.elapsedRealtime(); } /** Loading Loading @@ -569,6 +594,8 @@ public class TelephonyMetrics { .setCarrierIdMatching(mLastCarrierId.get(key)).build(); addTelephonyEvent(event); } writePhoneStatusChangedEvent(); } /** Loading Loading @@ -628,6 +655,56 @@ public class TelephonyMetrics { return log; } /** Update the sim state. */ public void updateSimState(int phoneId, int simState) { int state = mapSimStateToProto(simState); Integer lastSimState = mLastSimState.get(phoneId); if (lastSimState == null || !lastSimState.equals(state)) { mLastSimState.put(phoneId, state); writePhoneStatusChangedEvent(); } } /** Update active subscription info list. */ public void updateActiveSubscriptionInfoList(List<SubscriptionInfo> subInfos) { mLastActiveSubscriptionInfos.clear(); for (SubscriptionInfo info : subInfos) { int phoneId = SubscriptionManager.getPhoneId(info.getSubscriptionId()); ActiveSubscriptionInfo activeSubscriptionInfo = new ActiveSubscriptionInfo(); activeSubscriptionInfo.isOpportunistic = info.isOpportunistic(); activeSubscriptionInfo.carrierId = info.getCarrierId(); mLastActiveSubscriptionInfos.put(phoneId, activeSubscriptionInfo); } } /** Update the enabled modem bitmap. */ public void updateEnabledModemBitmap(int enabledModemBitmap) { if (mLastEnabledModemBitmap == enabledModemBitmap) return; mLastEnabledModemBitmap = enabledModemBitmap; writePhoneStatusChangedEvent(); } /** 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()); } /** * Reduce precision to meet privacy requirements. * Loading Loading @@ -2343,4 +2420,15 @@ public class TelephonyMetrics { public void writeOnImsCallResumeFailed(int phoneId, ImsCallSession session, ImsReasonInfo reasonInfo) {} public void writeOnRilTimeoutResponse(int phoneId, int rilSerial, int rilRequest) {} private static int mapSimStateToProto(int simState) { switch (simState) { case TelephonyManager.SIM_STATE_ABSENT: return SimState.SIM_STATE_ABSENT; case TelephonyManager.SIM_STATE_LOADED: return SimState.SIM_STATE_LOADED; default: return SimState.SIM_STATE_UNKNOWN; } } } tests/telephonytests/src/com/android/internal/telephony/metrics/TelephonyMetricsTest.java +7 −4 Original line number Diff line number Diff line Loading @@ -618,15 +618,18 @@ public class TelephonyMetricsTest extends TelephonyTest { public void testReset() throws Exception { mMetrics.writeServiceStateChanged(mPhone.getPhoneId(), mServiceState); reset(); TelephonyLog log = buildProto(); assertEquals(1, log.events.length); assertEquals(0, log.callSessions.length); assertEquals(0, log.smsSessions.length); Object[] serviceStateEvents = Arrays.stream(log.events) .filter(event -> event.type == TelephonyEvent.Type.RIL_SERVICE_STATE_CHANGED) .toArray(); assertEquals(1, serviceStateEvents.length); assertFalse(log.eventsDropped); TelephonyEvent event = log.events[0]; TelephonyEvent event = (TelephonyEvent) serviceStateEvents[0]; assertEquals(TelephonyEvent.Type.RIL_SERVICE_STATE_CHANGED, event.type); Loading Loading
src/java/com/android/internal/telephony/SubscriptionController.java +20 −13 Original line number Diff line number Diff line Loading @@ -49,6 +49,7 @@ import android.util.Log; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.telephony.IccCardConstants.State; import com.android.internal.telephony.metrics.TelephonyMetrics; import com.android.internal.telephony.uicc.IccUtils; import com.android.internal.telephony.uicc.UiccCard; import com.android.internal.telephony.uicc.UiccController; Loading Loading @@ -280,6 +281,9 @@ public class SubscriptionController extends ISub.Stub { mContext.sendBroadcast(intent); } /** * Notify the changed of subscription info. */ public void notifySubscriptionInfoChanged() { ITelephonyRegistry tr = ITelephonyRegistry.Stub.asInterface(ServiceManager.getService( "telephony.registry")); Loading @@ -292,6 +296,9 @@ public class SubscriptionController extends ISub.Stub { // FIXME: Remove if listener technique accepted. broadcastSimInfoContentChanged(); TelephonyMetrics metrics = TelephonyMetrics.getInstance(); metrics.updateActiveSubscriptionInfoList(mCacheActiveSubInfoList); } /** Loading
src/java/com/android/internal/telephony/SubscriptionInfoUpdater.java +3 −0 Original line number Diff line number Diff line Loading @@ -51,6 +51,7 @@ import android.text.TextUtils; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.telephony.euicc.EuiccController; import com.android.internal.telephony.metrics.TelephonyMetrics; import com.android.internal.telephony.uicc.IccRecords; import com.android.internal.telephony.uicc.IccUtils; import com.android.internal.telephony.uicc.UiccController; Loading Loading @@ -785,6 +786,7 @@ public class SubscriptionInfoUpdater extends Handler { logd("Broadcasting intent ACTION_SIM_CARD_STATE_CHANGED " + simStateString(state) + " for phone: " + phoneId); mContext.sendBroadcast(i, Manifest.permission.READ_PRIVILEGED_PHONE_STATE); TelephonyMetrics.getInstance().updateSimState(phoneId, state); } } Loading @@ -804,6 +806,7 @@ public class SubscriptionInfoUpdater extends Handler { logd("Broadcasting intent ACTION_SIM_APPLICATION_STATE_CHANGED " + simStateString(state) + " for phone: " + phoneId); mContext.sendBroadcast(i, Manifest.permission.READ_PRIVILEGED_PHONE_STATE); TelephonyMetrics.getInstance().updateSimState(phoneId, state); } } Loading
src/java/com/android/internal/telephony/metrics/TelephonyEventBuilder.java +12 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,9 @@ import static com.android.internal.telephony.nano.TelephonyProto.TelephonySettin import android.os.SystemClock; import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.PhoneStatus; import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.Type; public class TelephonyEventBuilder { private final TelephonyEvent mEvent = new TelephonyEvent(); Loading Loading @@ -133,4 +136,13 @@ public class TelephonyEventBuilder { mEvent.carrierKeyChange = carrierKeyChange; return this; } /** * Set and build phone status changed event. */ public TelephonyEventBuilder setPhoneStatusChange(PhoneStatus phoneStatus) { mEvent.type = Type.PHONE_STATUS_CHANGED; mEvent.phoneStatus = phoneStatus; return this; } }
src/java/com/android/internal/telephony/metrics/TelephonyMetrics.java +89 −1 Original line number Diff line number Diff line Loading @@ -45,6 +45,8 @@ import android.telephony.Rlog; import android.telephony.ServiceState; import android.telephony.SmsManager; import android.telephony.SmsMessage; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.telephony.TelephonyHistogram; import android.telephony.TelephonyManager; import android.telephony.data.DataCallResponse; Loading @@ -69,10 +71,12 @@ import com.android.internal.telephony.SmsResponse; import com.android.internal.telephony.UUSInfo; import com.android.internal.telephony.imsphone.ImsPhoneCall; import com.android.internal.telephony.nano.TelephonyProto; import com.android.internal.telephony.nano.TelephonyProto.ActiveSubscriptionInfo; import com.android.internal.telephony.nano.TelephonyProto.ImsCapabilities; import com.android.internal.telephony.nano.TelephonyProto.ImsConnectionState; import com.android.internal.telephony.nano.TelephonyProto.ModemPowerStats; import com.android.internal.telephony.nano.TelephonyProto.RilDataCall; import com.android.internal.telephony.nano.TelephonyProto.SimState; import com.android.internal.telephony.nano.TelephonyProto.SmsSession; import com.android.internal.telephony.nano.TelephonyProto.TelephonyCallSession; import com.android.internal.telephony.nano.TelephonyProto.TelephonyCallSession.Event.CallState; Loading @@ -83,6 +87,7 @@ import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.Carrier import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.CarrierIdMatchingResult; import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.CarrierKeyChange; import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.ModemRestart; 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.DeactivateReason; import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.RilSetupDataCall; Loading Loading @@ -167,6 +172,25 @@ public class TelephonyMetrics { */ private final SparseArray<TelephonySettings> mLastSettings = new SparseArray<>(); /** * Last sim state, indexed by phone id. */ private final SparseArray<Integer> mLastSimState = new SparseArray<>(); /** * Last active subscription information, indexed by phone id. */ private final SparseArray<ActiveSubscriptionInfo> mLastActiveSubscriptionInfos = new SparseArray<>(); /** * The last modem state represent by a bitmap, the i-th bit(LSB) indicates the i-th modem * state(0 - disabled, 1 - enabled). * * TODO: initialize the enabled modem bitmap when it's possible to get the modem state. */ private int mLastEnabledModemBitmap = (1 << TelephonyManager.getDefault().getPhoneCount()) - 1; /** * Last carrier id matching. */ Loading @@ -182,7 +206,8 @@ public class TelephonyMetrics { private boolean mTelephonyEventsDropped = false; public TelephonyMetrics() { reset(); mStartSystemTimeMs = System.currentTimeMillis(); mStartElapsedTimeMs = SystemClock.elapsedRealtime(); } /** Loading Loading @@ -569,6 +594,8 @@ public class TelephonyMetrics { .setCarrierIdMatching(mLastCarrierId.get(key)).build(); addTelephonyEvent(event); } writePhoneStatusChangedEvent(); } /** Loading Loading @@ -628,6 +655,56 @@ public class TelephonyMetrics { return log; } /** Update the sim state. */ public void updateSimState(int phoneId, int simState) { int state = mapSimStateToProto(simState); Integer lastSimState = mLastSimState.get(phoneId); if (lastSimState == null || !lastSimState.equals(state)) { mLastSimState.put(phoneId, state); writePhoneStatusChangedEvent(); } } /** Update active subscription info list. */ public void updateActiveSubscriptionInfoList(List<SubscriptionInfo> subInfos) { mLastActiveSubscriptionInfos.clear(); for (SubscriptionInfo info : subInfos) { int phoneId = SubscriptionManager.getPhoneId(info.getSubscriptionId()); ActiveSubscriptionInfo activeSubscriptionInfo = new ActiveSubscriptionInfo(); activeSubscriptionInfo.isOpportunistic = info.isOpportunistic(); activeSubscriptionInfo.carrierId = info.getCarrierId(); mLastActiveSubscriptionInfos.put(phoneId, activeSubscriptionInfo); } } /** Update the enabled modem bitmap. */ public void updateEnabledModemBitmap(int enabledModemBitmap) { if (mLastEnabledModemBitmap == enabledModemBitmap) return; mLastEnabledModemBitmap = enabledModemBitmap; writePhoneStatusChangedEvent(); } /** 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()); } /** * Reduce precision to meet privacy requirements. * Loading Loading @@ -2343,4 +2420,15 @@ public class TelephonyMetrics { public void writeOnImsCallResumeFailed(int phoneId, ImsCallSession session, ImsReasonInfo reasonInfo) {} public void writeOnRilTimeoutResponse(int phoneId, int rilSerial, int rilRequest) {} private static int mapSimStateToProto(int simState) { switch (simState) { case TelephonyManager.SIM_STATE_ABSENT: return SimState.SIM_STATE_ABSENT; case TelephonyManager.SIM_STATE_LOADED: return SimState.SIM_STATE_LOADED; default: return SimState.SIM_STATE_UNKNOWN; } } }
tests/telephonytests/src/com/android/internal/telephony/metrics/TelephonyMetricsTest.java +7 −4 Original line number Diff line number Diff line Loading @@ -618,15 +618,18 @@ public class TelephonyMetricsTest extends TelephonyTest { public void testReset() throws Exception { mMetrics.writeServiceStateChanged(mPhone.getPhoneId(), mServiceState); reset(); TelephonyLog log = buildProto(); assertEquals(1, log.events.length); assertEquals(0, log.callSessions.length); assertEquals(0, log.smsSessions.length); Object[] serviceStateEvents = Arrays.stream(log.events) .filter(event -> event.type == TelephonyEvent.Type.RIL_SERVICE_STATE_CHANGED) .toArray(); assertEquals(1, serviceStateEvents.length); assertFalse(log.eventsDropped); TelephonyEvent event = log.events[0]; TelephonyEvent event = (TelephonyEvent) serviceStateEvents[0]; assertEquals(TelephonyEvent.Type.RIL_SERVICE_STATE_CHANGED, event.type); Loading