Search in sources :

Example 6 with SynchronousResultReceiver

use of android.os.SynchronousResultReceiver 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 7 with SynchronousResultReceiver

use of android.os.SynchronousResultReceiver in project android_frameworks_base by crdroidandroid.

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 8 with SynchronousResultReceiver

use of android.os.SynchronousResultReceiver in project android_frameworks_base by ResurrectionRemix.

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 9 with SynchronousResultReceiver

use of android.os.SynchronousResultReceiver in project android_frameworks_base by ResurrectionRemix.

the class BluetoothAdapter method getControllerActivityEnergyInfo.

/**
     * Return the record of {@link BluetoothActivityEnergyInfo} object that
     * has the activity and energy info. This can be used to ascertain what
     * the controller has been up to, since the last sample.
     * @param updateType Type of info, cached vs refreshed.
     *
     * @return a record with {@link BluetoothActivityEnergyInfo} or null if
     * report is unavailable or unsupported
     * @deprecated use the asynchronous
     * {@link #requestControllerActivityEnergyInfo(ResultReceiver)} instead.
     * @hide
     */
@Deprecated
public BluetoothActivityEnergyInfo getControllerActivityEnergyInfo(int updateType) {
    SynchronousResultReceiver receiver = new SynchronousResultReceiver();
    requestControllerActivityEnergyInfo(receiver);
    try {
        SynchronousResultReceiver.Result result = receiver.awaitResult(1000);
        if (result.bundle != null) {
            return result.bundle.getParcelable(BatteryStats.RESULT_RECEIVER_CONTROLLER_KEY);
        }
    } catch (TimeoutException e) {
        Log.e(TAG, "getControllerActivityEnergyInfo timed out");
    }
    return null;
}
Also used : SynchronousResultReceiver(android.os.SynchronousResultReceiver) TimeoutException(java.util.concurrent.TimeoutException)

Example 10 with SynchronousResultReceiver

use of android.os.SynchronousResultReceiver in project android_frameworks_base by crdroidandroid.

the class BluetoothAdapter method getControllerActivityEnergyInfo.

/**
     * Return the record of {@link BluetoothActivityEnergyInfo} object that
     * has the activity and energy info. This can be used to ascertain what
     * the controller has been up to, since the last sample.
     * @param updateType Type of info, cached vs refreshed.
     *
     * @return a record with {@link BluetoothActivityEnergyInfo} or null if
     * report is unavailable or unsupported
     * @deprecated use the asynchronous
     * {@link #requestControllerActivityEnergyInfo(ResultReceiver)} instead.
     * @hide
     */
@Deprecated
public BluetoothActivityEnergyInfo getControllerActivityEnergyInfo(int updateType) {
    SynchronousResultReceiver receiver = new SynchronousResultReceiver();
    requestControllerActivityEnergyInfo(receiver);
    try {
        SynchronousResultReceiver.Result result = receiver.awaitResult(1000);
        if (result.bundle != null) {
            return result.bundle.getParcelable(BatteryStats.RESULT_RECEIVER_CONTROLLER_KEY);
        }
    } catch (TimeoutException e) {
        Log.e(TAG, "getControllerActivityEnergyInfo timed out");
    }
    return null;
}
Also used : SynchronousResultReceiver(android.os.SynchronousResultReceiver) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

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