1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.internal.telephony.metrics; 18 19 import android.telephony.Annotation.NetworkType; 20 import android.telephony.ServiceState; 21 import android.telephony.TelephonyManager; 22 23 import com.android.internal.telephony.Phone; 24 import com.android.internal.telephony.PhoneConstants; 25 import com.android.internal.telephony.ServiceStateTracker; 26 import com.android.internal.telephony.SubscriptionController; 27 import com.android.internal.telephony.TelephonyStatsLog; 28 import com.android.internal.telephony.dataconnection.DcTracker; 29 30 /** Generates metrics related to data stall recovery events per phone ID for the pushed atom. */ 31 public class DataStallRecoveryStats { 32 /** 33 * Create and push new atom when there is a data stall recovery event 34 * 35 * @param recoveryAction Data stall recovery action 36 * @param phone 37 */ onDataStallEvent(@cTracker.RecoveryAction int recoveryAction, Phone phone, boolean isRecovered, int durationMillis)38 public static void onDataStallEvent(@DcTracker.RecoveryAction int recoveryAction, 39 Phone phone, boolean isRecovered, int durationMillis) { 40 if (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_IMS) { 41 phone = phone.getDefaultPhone(); 42 } 43 44 int carrierId = phone.getCarrierId(); 45 int rat = getRat(phone); 46 int band = ServiceStateStats.getBand(phone, rat); 47 // the number returned here matches the SignalStrength enum we have 48 int signalStrength = phone.getSignalStrength().getLevel(); 49 boolean isOpportunistic = getIsOpportunistic(phone); 50 boolean isMultiSim = SimSlotState.getCurrentState().numActiveSims > 1; 51 52 TelephonyStatsLog.write(TelephonyStatsLog.DATA_STALL_RECOVERY_REPORTED, carrierId, rat, 53 signalStrength, recoveryAction, isOpportunistic, isMultiSim, band, isRecovered, 54 durationMillis); 55 } 56 57 /** Returns the RAT used for data (including IWLAN). */ getRat(Phone phone)58 private static @NetworkType int getRat(Phone phone) { 59 ServiceStateTracker serviceStateTracker = phone.getServiceStateTracker(); 60 ServiceState serviceState = 61 serviceStateTracker != null ? serviceStateTracker.getServiceState() : null; 62 return serviceState != null ? serviceState.getDataNetworkType() 63 : TelephonyManager.NETWORK_TYPE_UNKNOWN; 64 } 65 getIsOpportunistic(Phone phone)66 private static boolean getIsOpportunistic(Phone phone) { 67 SubscriptionController subController = SubscriptionController.getInstance(); 68 return subController != null ? subController.isOpportunistic(phone.getSubId()) : false; 69 } 70 } 71