Search in sources :

Example 1 with WifiActivityEnergyInfo

use of android.net.wifi.WifiActivityEnergyInfo in project android_frameworks_base by ResurrectionRemix.

the class BatteryStatsService method extractDelta.

private WifiActivityEnergyInfo extractDelta(WifiActivityEnergyInfo latest) {
    final long timePeriodMs = latest.mTimestamp - mLastInfo.mTimestamp;
    final long lastIdleMs = mLastInfo.mControllerIdleTimeMs;
    final long lastTxMs = mLastInfo.mControllerTxTimeMs;
    final long lastRxMs = mLastInfo.mControllerRxTimeMs;
    final long lastEnergy = mLastInfo.mControllerEnergyUsed;
    // We will modify the last info object to be the delta, and store the new
    // WifiActivityEnergyInfo object as our last one.
    final WifiActivityEnergyInfo delta = mLastInfo;
    delta.mTimestamp = latest.getTimeStamp();
    delta.mStackState = latest.getStackState();
    final long txTimeMs = latest.mControllerTxTimeMs - lastTxMs;
    final long rxTimeMs = latest.mControllerRxTimeMs - lastRxMs;
    final long idleTimeMs = latest.mControllerIdleTimeMs - lastIdleMs;
    if (txTimeMs < 0 || rxTimeMs < 0) {
        // The stats were reset by the WiFi system (which is why our delta is negative).
        // Returns the unaltered stats.
        delta.mControllerEnergyUsed = latest.mControllerEnergyUsed;
        delta.mControllerRxTimeMs = latest.mControllerRxTimeMs;
        delta.mControllerTxTimeMs = latest.mControllerTxTimeMs;
        delta.mControllerIdleTimeMs = latest.mControllerIdleTimeMs;
        Slog.v(TAG, "WiFi energy data was reset, new WiFi energy data is " + delta);
    } else {
        final long totalActiveTimeMs = txTimeMs + rxTimeMs;
        long maxExpectedIdleTimeMs;
        if (totalActiveTimeMs > timePeriodMs) {
            // Cap the max idle time at zero since the active time consumed the whole time
            maxExpectedIdleTimeMs = 0;
            if (totalActiveTimeMs > timePeriodMs + MAX_WIFI_STATS_SAMPLE_ERROR_MILLIS) {
                StringBuilder sb = new StringBuilder();
                sb.append("Total Active time ");
                TimeUtils.formatDuration(totalActiveTimeMs, sb);
                sb.append(" is longer than sample period ");
                TimeUtils.formatDuration(timePeriodMs, sb);
                sb.append(".\n");
                sb.append("Previous WiFi snapshot: ").append("idle=");
                TimeUtils.formatDuration(lastIdleMs, sb);
                sb.append(" rx=");
                TimeUtils.formatDuration(lastRxMs, sb);
                sb.append(" tx=");
                TimeUtils.formatDuration(lastTxMs, sb);
                sb.append(" e=").append(lastEnergy);
                sb.append("\n");
                sb.append("Current WiFi snapshot: ").append("idle=");
                TimeUtils.formatDuration(latest.mControllerIdleTimeMs, sb);
                sb.append(" rx=");
                TimeUtils.formatDuration(latest.mControllerRxTimeMs, sb);
                sb.append(" tx=");
                TimeUtils.formatDuration(latest.mControllerTxTimeMs, sb);
                sb.append(" e=").append(latest.mControllerEnergyUsed);
                Slog.wtf(TAG, sb.toString());
            }
        } else {
            maxExpectedIdleTimeMs = timePeriodMs - totalActiveTimeMs;
        }
        // These times seem to be the most reliable.
        delta.mControllerTxTimeMs = txTimeMs;
        delta.mControllerRxTimeMs = rxTimeMs;
        // WiFi calculates the idle time as a difference from the on time and the various
        // Rx + Tx times. There seems to be some missing time there because this sometimes
        // becomes negative. Just cap it at 0 and ensure that it is less than the expected idle
        // time from the difference in timestamps.
        // b/21613534
        delta.mControllerIdleTimeMs = Math.min(maxExpectedIdleTimeMs, Math.max(0, idleTimeMs));
        delta.mControllerEnergyUsed = Math.max(0, latest.mControllerEnergyUsed - lastEnergy);
    }
    mLastInfo = latest;
    return delta;
}
Also used : WifiActivityEnergyInfo(android.net.wifi.WifiActivityEnergyInfo)

Example 2 with WifiActivityEnergyInfo

use of android.net.wifi.WifiActivityEnergyInfo in project android_frameworks_base by DirtyUnicorns.

the class BatteryStatsService method extractDelta.

private WifiActivityEnergyInfo extractDelta(WifiActivityEnergyInfo latest) {
    final long timePeriodMs = latest.mTimestamp - mLastInfo.mTimestamp;
    final long lastIdleMs = mLastInfo.mControllerIdleTimeMs;
    final long lastTxMs = mLastInfo.mControllerTxTimeMs;
    final long lastRxMs = mLastInfo.mControllerRxTimeMs;
    final long lastEnergy = mLastInfo.mControllerEnergyUsed;
    // We will modify the last info object to be the delta, and store the new
    // WifiActivityEnergyInfo object as our last one.
    final WifiActivityEnergyInfo delta = mLastInfo;
    delta.mTimestamp = latest.getTimeStamp();
    delta.mStackState = latest.getStackState();
    final long txTimeMs = latest.mControllerTxTimeMs - lastTxMs;
    final long rxTimeMs = latest.mControllerRxTimeMs - lastRxMs;
    final long idleTimeMs = latest.mControllerIdleTimeMs - lastIdleMs;
    if (txTimeMs < 0 || rxTimeMs < 0) {
        // The stats were reset by the WiFi system (which is why our delta is negative).
        // Returns the unaltered stats.
        delta.mControllerEnergyUsed = latest.mControllerEnergyUsed;
        delta.mControllerRxTimeMs = latest.mControllerRxTimeMs;
        delta.mControllerTxTimeMs = latest.mControllerTxTimeMs;
        delta.mControllerIdleTimeMs = latest.mControllerIdleTimeMs;
        Slog.v(TAG, "WiFi energy data was reset, new WiFi energy data is " + delta);
    } else {
        final long totalActiveTimeMs = txTimeMs + rxTimeMs;
        long maxExpectedIdleTimeMs;
        if (totalActiveTimeMs > timePeriodMs) {
            // Cap the max idle time at zero since the active time consumed the whole time
            maxExpectedIdleTimeMs = 0;
            if (totalActiveTimeMs > timePeriodMs + MAX_WIFI_STATS_SAMPLE_ERROR_MILLIS) {
                StringBuilder sb = new StringBuilder();
                sb.append("Total Active time ");
                TimeUtils.formatDuration(totalActiveTimeMs, sb);
                sb.append(" is longer than sample period ");
                TimeUtils.formatDuration(timePeriodMs, sb);
                sb.append(".\n");
                sb.append("Previous WiFi snapshot: ").append("idle=");
                TimeUtils.formatDuration(lastIdleMs, sb);
                sb.append(" rx=");
                TimeUtils.formatDuration(lastRxMs, sb);
                sb.append(" tx=");
                TimeUtils.formatDuration(lastTxMs, sb);
                sb.append(" e=").append(lastEnergy);
                sb.append("\n");
                sb.append("Current WiFi snapshot: ").append("idle=");
                TimeUtils.formatDuration(latest.mControllerIdleTimeMs, sb);
                sb.append(" rx=");
                TimeUtils.formatDuration(latest.mControllerRxTimeMs, sb);
                sb.append(" tx=");
                TimeUtils.formatDuration(latest.mControllerTxTimeMs, sb);
                sb.append(" e=").append(latest.mControllerEnergyUsed);
                Slog.wtf(TAG, sb.toString());
            }
        } else {
            maxExpectedIdleTimeMs = timePeriodMs - totalActiveTimeMs;
        }
        // These times seem to be the most reliable.
        delta.mControllerTxTimeMs = txTimeMs;
        delta.mControllerRxTimeMs = rxTimeMs;
        // WiFi calculates the idle time as a difference from the on time and the various
        // Rx + Tx times. There seems to be some missing time there because this sometimes
        // becomes negative. Just cap it at 0 and ensure that it is less than the expected idle
        // time from the difference in timestamps.
        // b/21613534
        delta.mControllerIdleTimeMs = Math.min(maxExpectedIdleTimeMs, Math.max(0, idleTimeMs));
        delta.mControllerEnergyUsed = Math.max(0, latest.mControllerEnergyUsed - lastEnergy);
    }
    mLastInfo = latest;
    return delta;
}
Also used : WifiActivityEnergyInfo(android.net.wifi.WifiActivityEnergyInfo)

Example 3 with WifiActivityEnergyInfo

use of android.net.wifi.WifiActivityEnergyInfo in project android_frameworks_base by DirtyUnicorns.

the class BatteryStatsService method updateExternalStatsSync.

/**
     * Fetches data from external sources (WiFi controller, bluetooth chipset) and updates
     * batterystats with that information.
     *
     * We first grab a lock specific to this method, then once all the data has been collected,
     * we grab the mStats lock and update the data.
     *
     * @param reason The reason why this collection was requested. Useful for debugging.
     * @param updateFlags Which external stats to update. Can be a combination of
     *                    {@link BatteryStatsImpl.ExternalStatsSync#UPDATE_CPU},
     *                    {@link BatteryStatsImpl.ExternalStatsSync#UPDATE_RADIO},
     *                    {@link BatteryStatsImpl.ExternalStatsSync#UPDATE_WIFI},
     *                    and {@link BatteryStatsImpl.ExternalStatsSync#UPDATE_BT}.
     */
void updateExternalStatsSync(final String reason, int updateFlags) {
    SynchronousResultReceiver wifiReceiver = null;
    SynchronousResultReceiver bluetoothReceiver = null;
    SynchronousResultReceiver modemReceiver = null;
    synchronized (mExternalStatsLock) {
        if (mContext == null) {
            // Don't do any work yet.
            return;
        }
        if ((updateFlags & BatteryStatsImpl.ExternalStatsSync.UPDATE_WIFI) != 0) {
            if (mWifiManager == null) {
                mWifiManager = IWifiManager.Stub.asInterface(ServiceManager.getService(Context.WIFI_SERVICE));
            }
            if (mWifiManager != null) {
                try {
                    wifiReceiver = new SynchronousResultReceiver();
                    mWifiManager.requestActivityInfo(wifiReceiver);
                } catch (RemoteException e) {
                // Oh well.
                }
            }
        }
        if ((updateFlags & BatteryStatsImpl.ExternalStatsSync.UPDATE_BT) != 0) {
            final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
            if (adapter != null) {
                bluetoothReceiver = new SynchronousResultReceiver();
                adapter.requestControllerActivityEnergyInfo(bluetoothReceiver);
            }
        }
        if ((updateFlags & BatteryStatsImpl.ExternalStatsSync.UPDATE_RADIO) != 0) {
            if (mTelephony == null) {
                mTelephony = TelephonyManager.from(mContext);
            }
            if (mTelephony != null) {
                modemReceiver = new SynchronousResultReceiver();
                mTelephony.requestModemActivityInfo(modemReceiver);
            }
        }
        WifiActivityEnergyInfo wifiInfo = null;
        BluetoothActivityEnergyInfo bluetoothInfo = null;
        ModemActivityInfo modemInfo = null;
        try {
            wifiInfo = awaitControllerInfo(wifiReceiver);
        } catch (TimeoutException e) {
            Slog.w(TAG, "Timeout reading wifi stats");
        }
        try {
            bluetoothInfo = awaitControllerInfo(bluetoothReceiver);
        } catch (TimeoutException e) {
            Slog.w(TAG, "Timeout reading bt stats");
        }
        try {
            modemInfo = awaitControllerInfo(modemReceiver);
        } catch (TimeoutException e) {
            Slog.w(TAG, "Timeout reading modem stats");
        }
        synchronized (mStats) {
            mStats.addHistoryEventLocked(SystemClock.elapsedRealtime(), SystemClock.uptimeMillis(), BatteryStats.HistoryItem.EVENT_COLLECT_EXTERNAL_STATS, reason, 0);
            mStats.updateCpuTimeLocked();
            mStats.updateKernelWakelocksLocked();
            if (wifiInfo != null) {
                if (wifiInfo.isValid()) {
                    mStats.updateWifiStateLocked(extractDelta(wifiInfo));
                } else {
                    Slog.e(TAG, "wifi info is invalid: " + wifiInfo);
                }
            }
            if (bluetoothInfo != null) {
                if (bluetoothInfo.isValid()) {
                    mStats.updateBluetoothStateLocked(bluetoothInfo);
                } else {
                    Slog.e(TAG, "bluetooth info is invalid: " + bluetoothInfo);
                }
            }
            if (modemInfo != null) {
                if (modemInfo.isValid()) {
                    mStats.updateMobileRadioStateLocked(SystemClock.elapsedRealtime(), modemInfo);
                } else {
                    Slog.e(TAG, "modem info is invalid: " + modemInfo);
                }
            }
        }
    }
}
Also used : SynchronousResultReceiver(android.os.SynchronousResultReceiver) WifiActivityEnergyInfo(android.net.wifi.WifiActivityEnergyInfo) ModemActivityInfo(android.telephony.ModemActivityInfo) RemoteException(android.os.RemoteException) BluetoothAdapter(android.bluetooth.BluetoothAdapter) BluetoothActivityEnergyInfo(android.bluetooth.BluetoothActivityEnergyInfo) TimeoutException(java.util.concurrent.TimeoutException)

Example 4 with WifiActivityEnergyInfo

use of android.net.wifi.WifiActivityEnergyInfo in project android_frameworks_base by AOSPA.

the class BatteryStatsService method updateExternalStatsSync.

/**
     * Fetches data from external sources (WiFi controller, bluetooth chipset) and updates
     * batterystats with that information.
     *
     * We first grab a lock specific to this method, then once all the data has been collected,
     * we grab the mStats lock and update the data.
     *
     * @param reason The reason why this collection was requested. Useful for debugging.
     * @param updateFlags Which external stats to update. Can be a combination of
     *                    {@link BatteryStatsImpl.ExternalStatsSync#UPDATE_CPU},
     *                    {@link BatteryStatsImpl.ExternalStatsSync#UPDATE_RADIO},
     *                    {@link BatteryStatsImpl.ExternalStatsSync#UPDATE_WIFI},
     *                    and {@link BatteryStatsImpl.ExternalStatsSync#UPDATE_BT}.
     */
void updateExternalStatsSync(final String reason, int updateFlags) {
    SynchronousResultReceiver wifiReceiver = null;
    SynchronousResultReceiver bluetoothReceiver = null;
    SynchronousResultReceiver modemReceiver = null;
    synchronized (mExternalStatsLock) {
        if (mContext == null) {
            // Don't do any work yet.
            return;
        }
        if ((updateFlags & BatteryStatsImpl.ExternalStatsSync.UPDATE_WIFI) != 0) {
            if (mWifiManager == null) {
                mWifiManager = IWifiManager.Stub.asInterface(ServiceManager.getService(Context.WIFI_SERVICE));
            }
            if (mWifiManager != null) {
                try {
                    wifiReceiver = new SynchronousResultReceiver();
                    mWifiManager.requestActivityInfo(wifiReceiver);
                } catch (RemoteException e) {
                // Oh well.
                }
            }
        }
        if ((updateFlags & BatteryStatsImpl.ExternalStatsSync.UPDATE_BT) != 0) {
            final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
            if (adapter != null) {
                bluetoothReceiver = new SynchronousResultReceiver();
                adapter.requestControllerActivityEnergyInfo(bluetoothReceiver);
            }
        }
        if ((updateFlags & BatteryStatsImpl.ExternalStatsSync.UPDATE_RADIO) != 0) {
            if (mTelephony == null) {
                mTelephony = TelephonyManager.from(mContext);
            }
            if (mTelephony != null) {
                modemReceiver = new SynchronousResultReceiver();
                mTelephony.requestModemActivityInfo(modemReceiver);
            }
        }
        WifiActivityEnergyInfo wifiInfo = null;
        BluetoothActivityEnergyInfo bluetoothInfo = null;
        ModemActivityInfo modemInfo = null;
        try {
            wifiInfo = awaitControllerInfo(wifiReceiver);
        } catch (TimeoutException e) {
            Slog.w(TAG, "Timeout reading wifi stats");
        }
        try {
            bluetoothInfo = awaitControllerInfo(bluetoothReceiver);
        } catch (TimeoutException e) {
            Slog.w(TAG, "Timeout reading bt stats");
        }
        try {
            modemInfo = awaitControllerInfo(modemReceiver);
        } catch (TimeoutException e) {
            Slog.w(TAG, "Timeout reading modem stats");
        }
        synchronized (mStats) {
            mStats.addHistoryEventLocked(SystemClock.elapsedRealtime(), SystemClock.uptimeMillis(), BatteryStats.HistoryItem.EVENT_COLLECT_EXTERNAL_STATS, reason, 0);
            mStats.updateCpuTimeLocked();
            mStats.updateKernelWakelocksLocked();
            if (wifiInfo != null) {
                if (wifiInfo.isValid()) {
                    mStats.updateWifiStateLocked(extractDelta(wifiInfo));
                } else {
                    Slog.e(TAG, "wifi info is invalid: " + wifiInfo);
                }
            }
            if (bluetoothInfo != null) {
                if (bluetoothInfo.isValid()) {
                    mStats.updateBluetoothStateLocked(bluetoothInfo);
                } else {
                    Slog.e(TAG, "bluetooth info is invalid: " + bluetoothInfo);
                }
            }
            if (modemInfo != null) {
                if (modemInfo.isValid()) {
                    mStats.updateMobileRadioStateLocked(SystemClock.elapsedRealtime(), modemInfo);
                } else {
                    Slog.e(TAG, "modem info is invalid: " + modemInfo);
                }
            }
        }
    }
}
Also used : SynchronousResultReceiver(android.os.SynchronousResultReceiver) WifiActivityEnergyInfo(android.net.wifi.WifiActivityEnergyInfo) ModemActivityInfo(android.telephony.ModemActivityInfo) RemoteException(android.os.RemoteException) BluetoothAdapter(android.bluetooth.BluetoothAdapter) BluetoothActivityEnergyInfo(android.bluetooth.BluetoothActivityEnergyInfo) TimeoutException(java.util.concurrent.TimeoutException)

Example 5 with WifiActivityEnergyInfo

use of android.net.wifi.WifiActivityEnergyInfo in project platform_frameworks_base by android.

the class BatteryStatsService method updateExternalStatsSync.

/**
     * Fetches data from external sources (WiFi controller, bluetooth chipset) and updates
     * batterystats with that information.
     *
     * We first grab a lock specific to this method, then once all the data has been collected,
     * we grab the mStats lock and update the data.
     *
     * @param reason The reason why this collection was requested. Useful for debugging.
     * @param updateFlags Which external stats to update. Can be a combination of
     *                    {@link BatteryStatsImpl.ExternalStatsSync#UPDATE_CPU},
     *                    {@link BatteryStatsImpl.ExternalStatsSync#UPDATE_RADIO},
     *                    {@link BatteryStatsImpl.ExternalStatsSync#UPDATE_WIFI},
     *                    and {@link BatteryStatsImpl.ExternalStatsSync#UPDATE_BT}.
     */
void updateExternalStatsSync(final String reason, int updateFlags) {
    SynchronousResultReceiver wifiReceiver = null;
    SynchronousResultReceiver bluetoothReceiver = null;
    SynchronousResultReceiver modemReceiver = null;
    synchronized (mExternalStatsLock) {
        if (mContext == null) {
            // Don't do any work yet.
            return;
        }
        if ((updateFlags & BatteryStatsImpl.ExternalStatsSync.UPDATE_WIFI) != 0) {
            if (mWifiManager == null) {
                mWifiManager = IWifiManager.Stub.asInterface(ServiceManager.getService(Context.WIFI_SERVICE));
            }
            if (mWifiManager != null) {
                try {
                    wifiReceiver = new SynchronousResultReceiver();
                    mWifiManager.requestActivityInfo(wifiReceiver);
                } catch (RemoteException e) {
                // Oh well.
                }
            }
        }
        if ((updateFlags & BatteryStatsImpl.ExternalStatsSync.UPDATE_BT) != 0) {
            final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
            if (adapter != null) {
                bluetoothReceiver = new SynchronousResultReceiver();
                adapter.requestControllerActivityEnergyInfo(bluetoothReceiver);
            }
        }
        if ((updateFlags & BatteryStatsImpl.ExternalStatsSync.UPDATE_RADIO) != 0) {
            if (mTelephony == null) {
                mTelephony = TelephonyManager.from(mContext);
            }
            if (mTelephony != null) {
                modemReceiver = new SynchronousResultReceiver();
                mTelephony.requestModemActivityInfo(modemReceiver);
            }
        }
        WifiActivityEnergyInfo wifiInfo = null;
        BluetoothActivityEnergyInfo bluetoothInfo = null;
        ModemActivityInfo modemInfo = null;
        try {
            wifiInfo = awaitControllerInfo(wifiReceiver);
        } catch (TimeoutException e) {
            Slog.w(TAG, "Timeout reading wifi stats");
        }
        try {
            bluetoothInfo = awaitControllerInfo(bluetoothReceiver);
        } catch (TimeoutException e) {
            Slog.w(TAG, "Timeout reading bt stats");
        }
        try {
            modemInfo = awaitControllerInfo(modemReceiver);
        } catch (TimeoutException e) {
            Slog.w(TAG, "Timeout reading modem stats");
        }
        synchronized (mStats) {
            mStats.addHistoryEventLocked(SystemClock.elapsedRealtime(), SystemClock.uptimeMillis(), BatteryStats.HistoryItem.EVENT_COLLECT_EXTERNAL_STATS, reason, 0);
            mStats.updateCpuTimeLocked();
            mStats.updateKernelWakelocksLocked();
            if (wifiInfo != null) {
                if (wifiInfo.isValid()) {
                    mStats.updateWifiStateLocked(extractDelta(wifiInfo));
                } else {
                    Slog.e(TAG, "wifi info is invalid: " + wifiInfo);
                }
            }
            if (bluetoothInfo != null) {
                if (bluetoothInfo.isValid()) {
                    mStats.updateBluetoothStateLocked(bluetoothInfo);
                } else {
                    Slog.e(TAG, "bluetooth info is invalid: " + bluetoothInfo);
                }
            }
            if (modemInfo != null) {
                if (modemInfo.isValid()) {
                    mStats.updateMobileRadioStateLocked(SystemClock.elapsedRealtime(), modemInfo);
                } else {
                    Slog.e(TAG, "modem info is invalid: " + modemInfo);
                }
            }
        }
    }
}
Also used : SynchronousResultReceiver(android.os.SynchronousResultReceiver) WifiActivityEnergyInfo(android.net.wifi.WifiActivityEnergyInfo) ModemActivityInfo(android.telephony.ModemActivityInfo) RemoteException(android.os.RemoteException) BluetoothAdapter(android.bluetooth.BluetoothAdapter) BluetoothActivityEnergyInfo(android.bluetooth.BluetoothActivityEnergyInfo) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

WifiActivityEnergyInfo (android.net.wifi.WifiActivityEnergyInfo)10 BluetoothActivityEnergyInfo (android.bluetooth.BluetoothActivityEnergyInfo)5 BluetoothAdapter (android.bluetooth.BluetoothAdapter)5 RemoteException (android.os.RemoteException)5 SynchronousResultReceiver (android.os.SynchronousResultReceiver)5 ModemActivityInfo (android.telephony.ModemActivityInfo)5 TimeoutException (java.util.concurrent.TimeoutException)5