use of android.bluetooth.BluetoothAdapter 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);
}
}
}
}
}
use of android.bluetooth.BluetoothAdapter in project android_frameworks_base by DirtyUnicorns.
the class AudioService method getBluetoothHeadset.
private boolean getBluetoothHeadset() {
boolean result = false;
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if (adapter != null) {
result = adapter.getProfileProxy(mContext, mBluetoothProfileServiceListener, BluetoothProfile.HEADSET);
}
// If we could not get a bluetooth headset proxy, send a failure message
// without delay to reset the SCO audio state and clear SCO clients.
// If we could get a proxy, send a delayed failure message that will reset our state
// in case we don't receive onServiceConnected().
sendMsg(mAudioHandler, MSG_BT_HEADSET_CNCT_FAILED, SENDMSG_REPLACE, 0, 0, null, result ? BT_HEADSET_CNCT_TIMEOUT_MS : 0);
return result;
}
use of android.bluetooth.BluetoothAdapter in project android_frameworks_base by DirtyUnicorns.
the class AudioService method onSystemReady.
public void onSystemReady() {
mSystemReady = true;
sendMsg(mAudioHandler, MSG_LOAD_SOUND_EFFECTS, SENDMSG_QUEUE, 0, 0, null, 0);
mScoConnectionState = AudioManager.SCO_AUDIO_STATE_ERROR;
resetBluetoothSco();
getBluetoothHeadset();
//FIXME: this is to maintain compatibility with deprecated intent
// AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED. Remove when appropriate.
Intent newIntent = new Intent(AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED);
newIntent.putExtra(AudioManager.EXTRA_SCO_AUDIO_STATE, AudioManager.SCO_AUDIO_STATE_DISCONNECTED);
sendStickyBroadcastToAll(newIntent);
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if (adapter != null) {
adapter.getProfileProxy(mContext, mBluetoothProfileServiceListener, BluetoothProfile.A2DP);
}
mHdmiManager = (HdmiControlManager) mContext.getSystemService(Context.HDMI_CONTROL_SERVICE);
if (mHdmiManager != null) {
synchronized (mHdmiManager) {
mHdmiTvClient = mHdmiManager.getTvClient();
if (mHdmiTvClient != null) {
mFixedVolumeDevices &= ~AudioSystem.DEVICE_ALL_HDMI_SYSTEM_AUDIO_AND_SPEAKER;
}
mHdmiPlaybackClient = mHdmiManager.getPlaybackClient();
mHdmiCecSink = false;
}
}
mNm = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
sendMsg(mAudioHandler, MSG_CONFIGURE_SAFE_MEDIA_VOLUME_FORCED, SENDMSG_REPLACE, 0, 0, TAG, SAFE_VOLUME_CONFIGURE_TIMEOUT_MS);
StreamOverride.init(mContext);
mControllerService.init();
onIndicateSystemReady();
}
use of android.bluetooth.BluetoothAdapter in project android_frameworks_base by AOSPA.
the class AudioService method getBluetoothHeadset.
private boolean getBluetoothHeadset() {
boolean result = false;
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if (adapter != null) {
result = adapter.getProfileProxy(mContext, mBluetoothProfileServiceListener, BluetoothProfile.HEADSET);
}
// If we could not get a bluetooth headset proxy, send a failure message
// without delay to reset the SCO audio state and clear SCO clients.
// If we could get a proxy, send a delayed failure message that will reset our state
// in case we don't receive onServiceConnected().
sendMsg(mAudioHandler, MSG_BT_HEADSET_CNCT_FAILED, SENDMSG_REPLACE, 0, 0, null, result ? BT_HEADSET_CNCT_TIMEOUT_MS : 0);
return result;
}
use of android.bluetooth.BluetoothAdapter in project android_frameworks_base by AOSPA.
the class ExternalSharedPermsTest method testRunLocationAndBluetooth.
/** The use of location manager and bluetooth below are simply to simulate an app that
* tries to use them, so we can verify whether permissions are granted and accessible.
* */
public void testRunLocationAndBluetooth() {
LocationManager locationManager = (LocationManager) getInstrumentation().getContext().getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new LocationListener() {
public void onLocationChanged(Location location) {
}
public void onProviderDisabled(String provider) {
}
public void onProviderEnabled(String provider) {
}
public void onStatusChanged(String provider, int status, Bundle extras) {
}
});
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if ((mBluetoothAdapter != null) && (!mBluetoothAdapter.isEnabled())) {
mBluetoothAdapter.getName();
}
}
Aggregations