Search in sources :

Example 1 with BatteryStatsManager

use of android.os.BatteryStatsManager in project android_frameworks_opt_telephony by LineageOS.

the class TelephonyMetrics method printAllMetrics.

/**
 * Print all metrics data for debugging purposes
 *
 * @param rawWriter Print writer
 */
private synchronized void printAllMetrics(PrintWriter rawWriter) {
    final IndentingPrintWriter pw = new IndentingPrintWriter(rawWriter, "  ");
    pw.println("Telephony metrics proto:");
    pw.println("------------------------------------------");
    pw.println("Telephony events:");
    pw.increaseIndent();
    for (TelephonyEvent event : mTelephonyEvents) {
        pw.print(event.timestampMillis);
        pw.print(" [");
        pw.print(event.phoneId);
        pw.print("] ");
        pw.print("T=");
        if (event.type == TelephonyEvent.Type.RIL_SERVICE_STATE_CHANGED) {
            pw.print(telephonyEventToString(event.type) + "(" + "Data RAT " + event.serviceState.dataRat + " Voice RAT " + event.serviceState.voiceRat + " Channel Number " + event.serviceState.channelNumber + " NR Frequency Range " + event.serviceState.nrFrequencyRange + " NR State " + event.serviceState.nrState + ")");
            for (int i = 0; i < event.serviceState.networkRegistrationInfo.length; i++) {
                pw.print("reg info: domain=" + event.serviceState.networkRegistrationInfo[i].domain + ", rat=" + event.serviceState.networkRegistrationInfo[i].rat);
            }
        } else {
            pw.print(telephonyEventToString(event.type));
        }
        pw.println("");
    }
    pw.decreaseIndent();
    pw.println("Call sessions:");
    pw.increaseIndent();
    for (TelephonyCallSession callSession : mCompletedCallSessions) {
        pw.print("Start time in minutes: " + callSession.startTimeMinutes);
        pw.print(", phone: " + callSession.phoneId);
        if (callSession.eventsDropped) {
            pw.println(" Events dropped: " + callSession.eventsDropped);
        }
        pw.println(" Events: ");
        pw.increaseIndent();
        for (TelephonyCallSession.Event event : callSession.events) {
            pw.print(event.delay);
            pw.print(" T=");
            if (event.type == TelephonyCallSession.Event.Type.RIL_SERVICE_STATE_CHANGED) {
                pw.println(callSessionEventToString(event.type) + "(" + "Data RAT " + event.serviceState.dataRat + " Voice RAT " + event.serviceState.voiceRat + " Channel Number " + event.serviceState.channelNumber + " NR Frequency Range " + event.serviceState.nrFrequencyRange + " NR State " + event.serviceState.nrState + ")");
            } else if (event.type == TelephonyCallSession.Event.Type.RIL_CALL_LIST_CHANGED) {
                pw.println(callSessionEventToString(event.type));
                pw.increaseIndent();
                for (RilCall call : event.calls) {
                    pw.println(call.index + ". Type = " + call.type + " State = " + call.state + " End Reason " + call.callEndReason + " Precise Disconnect Cause " + call.preciseDisconnectCause + " isMultiparty = " + call.isMultiparty);
                }
                pw.decreaseIndent();
            } else if (event.type == TelephonyCallSession.Event.Type.AUDIO_CODEC) {
                pw.println(callSessionEventToString(event.type) + "(" + event.audioCodec + ")");
            } else {
                pw.println(callSessionEventToString(event.type));
            }
        }
        pw.decreaseIndent();
    }
    pw.decreaseIndent();
    pw.println("Sms sessions:");
    pw.increaseIndent();
    int count = 0;
    for (SmsSession smsSession : mCompletedSmsSessions) {
        count++;
        pw.print("[" + count + "] Start time in minutes: " + smsSession.startTimeMinutes);
        pw.print(", phone: " + smsSession.phoneId);
        if (smsSession.eventsDropped) {
            pw.println(", events dropped: " + smsSession.eventsDropped);
        } else {
            pw.println("");
        }
        pw.println("Events: ");
        pw.increaseIndent();
        for (SmsSession.Event event : smsSession.events) {
            pw.print(event.delay);
            pw.print(" T=");
            pw.println(smsSessionEventToString(event.type));
            // Only show more info for tx/rx sms
            if (event.type == SmsSession.Event.Type.SMS_RECEIVED) {
                pw.increaseIndent();
                switch(event.smsType) {
                    case SmsSession.Event.SmsType.SMS_TYPE_SMS_PP:
                        pw.println("Type: SMS-PP");
                        break;
                    case SmsSession.Event.SmsType.SMS_TYPE_VOICEMAIL_INDICATION:
                        pw.println("Type: Voicemail indication");
                        break;
                    case SmsSession.Event.SmsType.SMS_TYPE_ZERO:
                        pw.println("Type: zero");
                        break;
                    case SmsSession.Event.SmsType.SMS_TYPE_WAP_PUSH:
                        pw.println("Type: WAP PUSH");
                        break;
                    default:
                        break;
                }
                if (event.errorCode != SmsManager.RESULT_ERROR_NONE) {
                    pw.println("E=" + event.errorCode);
                }
                pw.decreaseIndent();
            } else if (event.type == SmsSession.Event.Type.SMS_SEND || event.type == SmsSession.Event.Type.SMS_SEND_RESULT) {
                pw.increaseIndent();
                pw.println("ReqId=" + event.rilRequestId);
                pw.println("E=" + event.errorCode);
                pw.println("RilE=" + event.error);
                pw.println("ImsE=" + event.imsError);
                pw.decreaseIndent();
            } else if (event.type == SmsSession.Event.Type.INCOMPLETE_SMS_RECEIVED) {
                pw.increaseIndent();
                pw.println("Received: " + event.incompleteSms.receivedParts + "/" + event.incompleteSms.totalParts);
                pw.decreaseIndent();
            }
        }
        pw.decreaseIndent();
    }
    pw.decreaseIndent();
    pw.println("Modem power stats:");
    pw.increaseIndent();
    BatteryStatsManager batteryStatsManager = mContext == null ? null : (BatteryStatsManager) mContext.getSystemService(Context.BATTERY_STATS_SERVICE);
    ModemPowerStats s = new ModemPowerMetrics(batteryStatsManager).buildProto();
    pw.println("Power log duration (battery time) (ms): " + s.loggingDurationMs);
    pw.println("Energy consumed by modem (mAh): " + s.energyConsumedMah);
    pw.println("Number of packets sent (tx): " + s.numPacketsTx);
    pw.println("Number of bytes sent (tx): " + s.numBytesTx);
    pw.println("Number of packets received (rx): " + s.numPacketsRx);
    pw.println("Number of bytes received (rx): " + s.numBytesRx);
    pw.println("Amount of time kernel is active because of cellular data (ms): " + s.cellularKernelActiveTimeMs);
    pw.println("Amount of time spent in very poor rx signal level (ms): " + s.timeInVeryPoorRxSignalLevelMs);
    pw.println("Amount of time modem is in sleep (ms): " + s.sleepTimeMs);
    pw.println("Amount of time modem is in idle (ms): " + s.idleTimeMs);
    pw.println("Amount of time modem is in rx (ms): " + s.rxTimeMs);
    pw.println("Amount of time modem is in tx (ms): " + Arrays.toString(s.txTimeMs));
    pw.println("Amount of time phone spent in various Radio Access Technologies (ms): " + Arrays.toString(s.timeInRatMs));
    pw.println("Amount of time phone spent in various cellular " + "rx signal strength levels (ms): " + Arrays.toString(s.timeInRxSignalStrengthLevelMs));
    pw.println("Energy consumed across measured modem rails (mAh): " + new DecimalFormat("#.##").format(s.monitoredRailEnergyConsumedMah));
    pw.decreaseIndent();
    pw.println("Hardware Version: " + SystemProperties.get("ro.boot.revision", ""));
}
Also used : TelephonyEvent(com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent) DecimalFormat(java.text.DecimalFormat) TelephonyCallSession(com.android.internal.telephony.nano.TelephonyProto.TelephonyCallSession) BatteryStatsManager(android.os.BatteryStatsManager) ModemPowerStats(com.android.internal.telephony.nano.TelephonyProto.ModemPowerStats) IndentingPrintWriter(com.android.internal.util.IndentingPrintWriter) RilCall(com.android.internal.telephony.nano.TelephonyProto.TelephonyCallSession.Event.RilCall) SmsSession(com.android.internal.telephony.nano.TelephonyProto.SmsSession)

Example 2 with BatteryStatsManager

use of android.os.BatteryStatsManager in project android_packages_apps_Settings by omnirom.

the class BatteryUtils method getBatteryInfo.

@WorkerThread
public BatteryInfo getBatteryInfo(final String tag) {
    final BatteryStatsManager systemService = mContext.getSystemService(BatteryStatsManager.class);
    BatteryUsageStats batteryUsageStats;
    try {
        batteryUsageStats = systemService.getBatteryUsageStats(new BatteryUsageStatsQuery.Builder().includeBatteryHistory().build());
    } catch (RuntimeException e) {
        Log.e(TAG, "getBatteryInfo() error for getBatteryUsageStats()", e);
        // Use default BatteryUsageStats.
        batteryUsageStats = new BatteryUsageStats.Builder(new String[0], /* includePowerModels */
        false).build();
    }
    final long startTime = System.currentTimeMillis();
    // Stuff we always need to get BatteryInfo
    final Intent batteryBroadcast = mContext.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
    final long elapsedRealtimeUs = PowerUtil.convertMsToUs(SystemClock.elapsedRealtime());
    BatteryInfo batteryInfo;
    Estimate estimate = getEnhancedEstimate();
    // couldn't get estimate from cache or provider, use fallback
    if (estimate == null) {
        estimate = new Estimate(batteryUsageStats.getBatteryTimeRemainingMs(), false, /* isBasedOnUsage */
        EstimateKt.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN);
    }
    BatteryUtils.logRuntime(tag, "BatteryInfoLoader post query", startTime);
    batteryInfo = BatteryInfo.getBatteryInfo(mContext, batteryBroadcast, batteryUsageStats, estimate, elapsedRealtimeUs, false);
    BatteryUtils.logRuntime(tag, "BatteryInfoLoader.loadInBackground", startTime);
    return batteryInfo;
}
Also used : IntentFilter(android.content.IntentFilter) Estimate(com.android.settingslib.fuelgauge.Estimate) Intent(android.content.Intent) BatteryStatsManager(android.os.BatteryStatsManager) BatteryUsageStats(android.os.BatteryUsageStats) WorkerThread(androidx.annotation.WorkerThread)

Example 3 with BatteryStatsManager

use of android.os.BatteryStatsManager in project android_frameworks_opt_telephony by LineageOS.

the class TelephonyMetrics method buildProto.

/**
 * Build the telephony proto
 *
 * @return Telephony proto
 */
private synchronized TelephonyLog buildProto() {
    TelephonyLog log = new TelephonyLog();
    // Build telephony events
    log.events = new TelephonyEvent[mTelephonyEvents.size()];
    mTelephonyEvents.toArray(log.events);
    log.eventsDropped = mTelephonyEventsDropped;
    // Build call sessions
    log.callSessions = new TelephonyCallSession[mCompletedCallSessions.size()];
    mCompletedCallSessions.toArray(log.callSessions);
    // Build SMS sessions
    log.smsSessions = new SmsSession[mCompletedSmsSessions.size()];
    mCompletedSmsSessions.toArray(log.smsSessions);
    // Build histogram. Currently we only support RIL histograms.
    List<TelephonyHistogram> rilHistograms = RIL.getTelephonyRILTimingHistograms();
    log.histograms = new TelephonyProto.TelephonyHistogram[rilHistograms.size()];
    for (int i = 0; i < rilHistograms.size(); i++) {
        log.histograms[i] = new TelephonyProto.TelephonyHistogram();
        TelephonyHistogram rilHistogram = rilHistograms.get(i);
        TelephonyProto.TelephonyHistogram histogramProto = log.histograms[i];
        histogramProto.category = rilHistogram.getCategory();
        histogramProto.id = rilHistogram.getId();
        histogramProto.minTimeMillis = rilHistogram.getMinTime();
        histogramProto.maxTimeMillis = rilHistogram.getMaxTime();
        histogramProto.avgTimeMillis = rilHistogram.getAverageTime();
        histogramProto.count = rilHistogram.getSampleCount();
        histogramProto.bucketCount = rilHistogram.getBucketCount();
        histogramProto.bucketEndPoints = rilHistogram.getBucketEndPoints();
        histogramProto.bucketCounters = rilHistogram.getBucketCounters();
    }
    // Build modem power metrics
    BatteryStatsManager batteryStatsManager = mContext == null ? null : (BatteryStatsManager) mContext.getSystemService(Context.BATTERY_STATS_SERVICE);
    log.modemPowerStats = new ModemPowerMetrics(batteryStatsManager).buildProto();
    // Log the hardware revision
    log.hardwareRevision = SystemProperties.get("ro.boot.revision", "");
    // Log the starting system time
    log.startTime = new TelephonyProto.Time();
    log.startTime.systemTimestampMillis = mStartSystemTimeMs;
    log.startTime.elapsedTimestampMillis = mStartElapsedTimeMs;
    log.endTime = new TelephonyProto.Time();
    log.endTime.systemTimestampMillis = System.currentTimeMillis();
    log.endTime.elapsedTimestampMillis = SystemClock.elapsedRealtime();
    // Log the last active subscription information.
    int phoneCount = TelephonyManager.getDefault().getPhoneCount();
    ActiveSubscriptionInfo[] activeSubscriptionInfo = new ActiveSubscriptionInfo[phoneCount];
    for (int i = 0; i < mLastActiveSubscriptionInfos.size(); i++) {
        int key = mLastActiveSubscriptionInfos.keyAt(i);
        activeSubscriptionInfo[key] = mLastActiveSubscriptionInfos.get(key);
    }
    for (int i = 0; i < phoneCount; i++) {
        if (activeSubscriptionInfo[i] == null) {
            activeSubscriptionInfo[i] = makeInvalidSubscriptionInfo(i);
        }
    }
    log.lastActiveSubscriptionInfo = activeSubscriptionInfo;
    return log;
}
Also used : TelephonyLog(com.android.internal.telephony.nano.TelephonyProto.TelephonyLog) TelephonyHistogram(android.telephony.TelephonyHistogram) ActiveSubscriptionInfo(com.android.internal.telephony.nano.TelephonyProto.ActiveSubscriptionInfo) TelephonyProto(com.android.internal.telephony.nano.TelephonyProto) BatteryStatsManager(android.os.BatteryStatsManager)

Aggregations

BatteryStatsManager (android.os.BatteryStatsManager)3 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 BatteryUsageStats (android.os.BatteryUsageStats)1 TelephonyHistogram (android.telephony.TelephonyHistogram)1 WorkerThread (androidx.annotation.WorkerThread)1 TelephonyProto (com.android.internal.telephony.nano.TelephonyProto)1 ActiveSubscriptionInfo (com.android.internal.telephony.nano.TelephonyProto.ActiveSubscriptionInfo)1 ModemPowerStats (com.android.internal.telephony.nano.TelephonyProto.ModemPowerStats)1 SmsSession (com.android.internal.telephony.nano.TelephonyProto.SmsSession)1 TelephonyCallSession (com.android.internal.telephony.nano.TelephonyProto.TelephonyCallSession)1 RilCall (com.android.internal.telephony.nano.TelephonyProto.TelephonyCallSession.Event.RilCall)1 TelephonyEvent (com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent)1 TelephonyLog (com.android.internal.telephony.nano.TelephonyProto.TelephonyLog)1 IndentingPrintWriter (com.android.internal.util.IndentingPrintWriter)1 Estimate (com.android.settingslib.fuelgauge.Estimate)1 DecimalFormat (java.text.DecimalFormat)1