Merge "Bluetooth should use Slog." into nyc-dev

am: 0e9e642bd9

* commit '0e9e642bd91ccfc82ffe3ad001a79f232636ba3d':
  Bluetooth should use Slog.
This commit is contained in:
Jeff Sharkey
2016-03-05 21:34:08 +00:00
committed by android-build-merger

View File

@@ -19,7 +19,6 @@ package com.android.server;
import android.Manifest;
import android.app.ActivityManager;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.IBluetooth;
import android.bluetooth.IBluetoothCallback;
@@ -44,7 +43,6 @@ import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.os.ParcelFileDescriptor;
import android.os.Process;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
@@ -53,10 +51,9 @@ import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
import android.util.Log;
import android.util.Slog;
import java.io.FileDescriptor;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
@@ -176,7 +173,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
String action = intent.getAction();
if (BluetoothAdapter.ACTION_LOCAL_NAME_CHANGED.equals(action)) {
String newName = intent.getStringExtra(BluetoothAdapter.EXTRA_LOCAL_NAME);
if (DBG) Log.d(TAG, "Bluetooth Adapter name changed to " + newName);
if (DBG) Slog.d(TAG, "Bluetooth Adapter name changed to " + newName);
if (newName != null) {
storeNameAndAddress(newName, null);
}
@@ -195,10 +192,10 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
try {
st = mBluetooth.getState();
} catch (RemoteException e) {
Log.e(TAG,"Unable to call getState", e);
Slog.e(TAG,"Unable to call getState", e);
}
}
Log.d(TAG, "state" + st);
Slog.d(TAG, "state" + st);
if (isAirplaneModeOn()) {
// Clear registered LE apps to force shut-off
@@ -214,16 +211,16 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
mEnableExternal = false;
}
} catch(RemoteException e) {
Log.e(TAG,"Unable to call onBrEdrDown", e);
Slog.e(TAG,"Unable to call onBrEdrDown", e);
}
} else if (st == BluetoothAdapter.STATE_ON){
// disable without persisting the setting
Log.d(TAG, "Calling disable");
Slog.d(TAG, "Calling disable");
sendDisableMsg();
}
} else if (mEnableExternal) {
// enable without persisting the setting
Log.d(TAG, "Calling enable");
Slog.d(TAG, "Calling enable");
sendEnableMsg(mQuietEnableExternal);
}
}
@@ -267,7 +264,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
PackageManager.MATCH_SYSTEM_ONLY, UserHandle.USER_SYSTEM);
} catch (PackageManager.NameNotFoundException e) {
// Some platforms, such as wearables do not have a system ui.
Log.w(TAG, "Unable to resolve SystemUI's UID.", e);
Slog.w(TAG, "Unable to resolve SystemUI's UID.", e);
}
mSystemUiUid = sysUiUid;
}
@@ -320,17 +317,17 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
* in the local cache
*/
private void loadStoredNameAndAddress() {
if (DBG) Log.d(TAG, "Loading stored name and address");
if (DBG) Slog.d(TAG, "Loading stored name and address");
if (mContext.getResources().getBoolean
(com.android.internal.R.bool.config_bluetooth_address_validation) &&
Settings.Secure.getInt(mContentResolver, SECURE_SETTINGS_BLUETOOTH_ADDR_VALID, 0) == 0) {
// if the valid flag is not set, don't load the address and name
if (DBG) Log.d(TAG, "invalid bluetooth name and address stored");
if (DBG) Slog.d(TAG, "invalid bluetooth name and address stored");
return;
}
mName = Settings.Secure.getString(mContentResolver, SECURE_SETTINGS_BLUETOOTH_NAME);
mAddress = Settings.Secure.getString(mContentResolver, SECURE_SETTINGS_BLUETOOTH_ADDRESS);
if (DBG) Log.d(TAG, "Stored bluetooth Name=" + mName + ",Address=" + mAddress);
if (DBG) Slog.d(TAG, "Stored bluetooth Name=" + mName + ",Address=" + mAddress);
}
/**
@@ -343,14 +340,14 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
if (name != null) {
Settings.Secure.putString(mContentResolver, SECURE_SETTINGS_BLUETOOTH_NAME, name);
mName = name;
if (DBG) Log.d(TAG,"Stored Bluetooth name: " +
if (DBG) Slog.d(TAG,"Stored Bluetooth name: " +
Settings.Secure.getString(mContentResolver,SECURE_SETTINGS_BLUETOOTH_NAME));
}
if (address != null) {
Settings.Secure.putString(mContentResolver, SECURE_SETTINGS_BLUETOOTH_ADDRESS, address);
mAddress=address;
if (DBG) Log.d(TAG,"Stored Bluetoothaddress: " +
if (DBG) Slog.d(TAG,"Stored Bluetoothaddress: " +
Settings.Secure.getString(mContentResolver,SECURE_SETTINGS_BLUETOOTH_ADDRESS));
}
@@ -361,7 +358,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
public IBluetooth registerAdapter(IBluetoothManagerCallback callback){
if (callback == null) {
Log.w(TAG, "Callback is null in registerAdapter");
Slog.w(TAG, "Callback is null in registerAdapter");
return null;
}
Message msg = mHandler.obtainMessage(MESSAGE_REGISTER_ADAPTER);
@@ -374,7 +371,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
public void unregisterAdapter(IBluetoothManagerCallback callback) {
if (callback == null) {
Log.w(TAG, "Callback is null in unregisterAdapter");
Slog.w(TAG, "Callback is null in unregisterAdapter");
return;
}
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM,
@@ -403,7 +400,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
public boolean isEnabled() {
if ((Binder.getCallingUid() != Process.SYSTEM_UID) &&
(!checkIfCallerIsForegroundUser())) {
Log.w(TAG,"isEnabled(): not allowed for non-active and non system user");
Slog.w(TAG,"isEnabled(): not allowed for non-active and non system user");
return false;
}
@@ -411,7 +408,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
try {
return (mBluetooth != null && mBluetooth.isEnabled());
} catch (RemoteException e) {
Log.e(TAG, "isEnabled()", e);
Slog.e(TAG, "isEnabled()", e);
}
}
return false;
@@ -419,17 +416,17 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
class ClientDeathRecipient implements IBinder.DeathRecipient {
public void binderDied() {
if (DBG) Log.d(TAG, "Binder is dead - unregister Ble App");
if (DBG) Slog.d(TAG, "Binder is dead - unregister Ble App");
if (mBleAppCount > 0) --mBleAppCount;
if (mBleAppCount == 0) {
if (DBG) Log.d(TAG, "Disabling LE only mode after application crash");
if (DBG) Slog.d(TAG, "Disabling LE only mode after application crash");
try {
if (mBluetooth != null) {
mBluetooth.onBrEdrDown();
}
} catch(RemoteException e) {
Log.e(TAG,"Unable to call onBrEdrDown", e);
Slog.e(TAG,"Unable to call onBrEdrDown", e);
}
}
}
@@ -459,7 +456,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
try {
if (mBluetooth != null) mBluetooth.onBrEdrDown();
} catch (RemoteException e) {
Log.e(TAG, "error when disabling bluetooth", e);
Slog.e(TAG, "error when disabling bluetooth", e);
}
}
}
@@ -474,11 +471,11 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
private void disableBleScanMode() {
try {
if (mBluetooth != null && (mBluetooth.getState() != BluetoothAdapter.STATE_ON)) {
if (DBG) Log.d(TAG, "Reseting the mEnable flag for clean disable");
if (DBG) Slog.d(TAG, "Reseting the mEnable flag for clean disable");
mEnable = false;
}
} catch (RemoteException e) {
Log.e(TAG, "getState()", e);
Slog.e(TAG, "getState()", e);
}
}
@@ -496,7 +493,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
synchronized (this) {
++mBleAppCount;
}
if (DBG) Log.d(TAG, "Registered for death Notification");
if (DBG) Slog.d(TAG, "Registered for death Notification");
}
} else {
@@ -508,10 +505,10 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
synchronized (this) {
if (mBleAppCount > 0) --mBleAppCount;
}
if (DBG) Log.d(TAG, "Unregistered for death Notification");
if (DBG) Slog.d(TAG, "Unregistered for death Notification");
}
}
if (DBG) Log.d(TAG, "Updated BleAppCount" + mBleAppCount);
if (DBG) Slog.d(TAG, "Updated BleAppCount" + mBleAppCount);
if (mBleAppCount == 0 && mEnable) {
disableBleScanMode();
}
@@ -528,7 +525,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
/** @hide*/
public boolean isBleAppPresent() {
if (DBG) Log.d(TAG, "isBleAppPresent() count: " + mBleAppCount);
if (DBG) Slog.d(TAG, "isBleAppPresent() count: " + mBleAppCount);
return (mBleAppCount > 0);
}
@@ -536,7 +533,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
* Action taken when GattService is turned off
*/
private void onBluetoothGattServiceUp() {
if (DBG) Log.d(TAG,"BluetoothGatt Service is Up");
if (DBG) Slog.d(TAG,"BluetoothGatt Service is Up");
try{
if (isBleAppPresent() == false && mBluetooth != null
&& mBluetooth.getState() == BluetoothAdapter.STATE_BLE_ON) {
@@ -548,7 +545,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
Binder.restoreCallingIdentity(callingIdentity);
}
} catch(RemoteException e) {
Log.e(TAG,"Unable to call onServiceUp", e);
Slog.e(TAG,"Unable to call onServiceUp", e);
}
}
@@ -557,10 +554,10 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
* and turn off all service and stack if no LE app needs it
*/
private void sendBrEdrDownCallback() {
if (DBG) Log.d(TAG,"Calling sendBrEdrDownCallback callbacks");
if (DBG) Slog.d(TAG,"Calling sendBrEdrDownCallback callbacks");
if(mBluetooth == null) {
Log.w(TAG, "Bluetooth handle is null");
Slog.w(TAG, "Bluetooth handle is null");
return;
}
@@ -568,14 +565,14 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
try {
mBluetooth.onBrEdrDown();
} catch(RemoteException e) {
Log.e(TAG, "Call to onBrEdrDown() failed.", e);
Slog.e(TAG, "Call to onBrEdrDown() failed.", e);
}
} else {
// Need to stay at BLE ON. Disconnect all Gatt connections
try{
mBluetoothGatt.unregAll();
} catch(RemoteException e) {
Log.e(TAG, "Unable to disconnect all apps.", e);
Slog.e(TAG, "Unable to disconnect all apps.", e);
}
}
}
@@ -586,7 +583,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
"Need BLUETOOTH ADMIN permission");
if (DBG) {
Log.d(TAG,"enableNoAutoConnect(): mBluetooth =" + mBluetooth +
Slog.d(TAG,"enableNoAutoConnect(): mBluetooth =" + mBluetooth +
" mBinding = " + mBinding);
}
int callingAppId = UserHandle.getAppId(Binder.getCallingUid());
@@ -606,14 +603,14 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
public boolean enable() {
if ((Binder.getCallingUid() != Process.SYSTEM_UID) &&
(!checkIfCallerIsForegroundUser())) {
Log.w(TAG,"enable(): not allowed for non-active and non system user");
Slog.w(TAG,"enable(): not allowed for non-active and non system user");
return false;
}
mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
"Need BLUETOOTH ADMIN permission");
if (DBG) {
Log.d(TAG,"enable(): mBluetooth =" + mBluetooth +
Slog.d(TAG,"enable(): mBluetooth =" + mBluetooth +
" mBinding = " + mBinding);
}
@@ -623,7 +620,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
// waive WRITE_SECURE_SETTINGS permission check
sendEnableMsg(false);
}
if (DBG) Log.d(TAG, "enable returning");
if (DBG) Slog.d(TAG, "enable returning");
return true;
}
@@ -633,12 +630,12 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
if ((Binder.getCallingUid() != Process.SYSTEM_UID) &&
(!checkIfCallerIsForegroundUser())) {
Log.w(TAG,"disable(): not allowed for non-active and non system user");
Slog.w(TAG,"disable(): not allowed for non-active and non system user");
return false;
}
if (DBG) {
Log.d(TAG,"disable(): mBluetooth = " + mBluetooth +
Slog.d(TAG,"disable(): mBluetooth = " + mBluetooth +
" mBinding = " + mBinding);
}
@@ -657,7 +654,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
public void unbindAndFinish() {
if (DBG) {
Log.d(TAG,"unbindAndFinish(): " + mBluetooth +
Slog.d(TAG,"unbindAndFinish(): " + mBluetooth +
" mBinding = " + mBinding);
}
@@ -669,10 +666,10 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
try {
mBluetooth.unregisterCallback(mBluetoothCallback);
} catch (RemoteException re) {
Log.e(TAG, "Unable to unregister BluetoothCallback",re);
Slog.e(TAG, "Unable to unregister BluetoothCallback",re);
}
if (DBG) Log.d(TAG, "Sending unbind request.");
if (DBG) Slog.d(TAG, "Sending unbind request.");
mBluetoothBinder = null;
mBluetooth = null;
//Unbind
@@ -696,7 +693,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
IBluetoothProfileServiceConnection proxy) {
if (!mEnable) {
if (DBG) {
Log.d(TAG, "Trying to bind to profile: " + bluetoothProfile +
Slog.d(TAG, "Trying to bind to profile: " + bluetoothProfile +
", while Bluetooth was disabled");
}
return false;
@@ -705,7 +702,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
ProfileServiceConnections psc = mProfileServices.get(new Integer(bluetoothProfile));
if (psc == null) {
if (DBG) {
Log.d(TAG, "Creating new ProfileServiceConnections object for"
Slog.d(TAG, "Creating new ProfileServiceConnections object for"
+ " profile: " + bluetoothProfile);
}
@@ -746,7 +743,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
try {
mContext.unbindService(psc);
} catch (IllegalArgumentException e) {
Log.e(TAG, "Unable to unbind service with intent: " + psc.mIntent, e);
Slog.e(TAG, "Unable to unbind service with intent: " + psc.mIntent, e);
}
psc.removeAllProxies();
}
@@ -759,9 +756,9 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
* PHASE_SYSTEM_SERVICES_READY.
*/
public void handleOnBootPhase() {
if (DBG) Log.d(TAG, "Bluetooth boot completed");
if (DBG) Slog.d(TAG, "Bluetooth boot completed");
if (mEnableExternal && isBluetoothPersistedStateOnBluetooth()) {
if (DBG) Log.d(TAG, "Auto-enabling Bluetooth.");
if (DBG) Slog.d(TAG, "Auto-enabling Bluetooth.");
sendEnableMsg(mQuietEnableExternal);
}
}
@@ -770,7 +767,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
* Called when switching to a different foreground user.
*/
public void handleOnSwitchUser(int userHandle) {
if (DBG) Log.d(TAG, "Bluetooth user switched");
if (DBG) Slog.d(TAG, "Bluetooth user switched");
mHandler.sendMessage(mHandler.obtainMessage(MESSAGE_USER_SWITCHED, userHandle, 0));
}
@@ -801,7 +798,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
mHandler.sendMessageDelayed(msg, TIMEOUT_BIND_MS);
return true;
}
Log.w(TAG, "Unable to bind with intent: " + mIntent);
Slog.w(TAG, "Unable to bind with intent: " + mIntent);
return false;
}
@@ -811,7 +808,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
try{
proxy.onServiceConnected(mClassName, mService);
} catch (RemoteException e) {
Log.e(TAG, "Unable to connect to proxy", e);
Slog.e(TAG, "Unable to connect to proxy", e);
}
} else {
if (!mHandler.hasMessages(MESSAGE_BIND_PROFILE_SERVICE, this)) {
@@ -828,11 +825,11 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
try {
proxy.onServiceDisconnected(mClassName);
} catch (RemoteException e) {
Log.e(TAG, "Unable to disconnect proxy", e);
Slog.e(TAG, "Unable to disconnect proxy", e);
}
}
} else {
Log.w(TAG, "Trying to remove a null proxy");
Slog.w(TAG, "Trying to remove a null proxy");
}
}
@@ -850,11 +847,11 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
try {
mService.linkToDeath(this, 0);
} catch (RemoteException e) {
Log.e(TAG, "Unable to linkToDeath", e);
Slog.e(TAG, "Unable to linkToDeath", e);
}
if (mInvokingProxyCallbacks) {
Log.e(TAG, "Proxy callbacks already in progress.");
Slog.e(TAG, "Proxy callbacks already in progress.");
return;
}
mInvokingProxyCallbacks = true;
@@ -865,7 +862,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
try {
mProxies.getBroadcastItem(i).onServiceConnected(className, service);
} catch (RemoteException e) {
Log.e(TAG, "Unable to connect to proxy", e);
Slog.e(TAG, "Unable to connect to proxy", e);
}
}
} finally {
@@ -882,7 +879,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
mClassName = null;
if (mInvokingProxyCallbacks) {
Log.e(TAG, "Proxy callbacks already in progress.");
Slog.e(TAG, "Proxy callbacks already in progress.");
return;
}
mInvokingProxyCallbacks = true;
@@ -893,7 +890,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
try {
mProxies.getBroadcastItem(i).onServiceDisconnected(className);
} catch (RemoteException e) {
Log.e(TAG, "Unable to disconnect from proxy", e);
Slog.e(TAG, "Unable to disconnect from proxy", e);
}
}
} finally {
@@ -905,7 +902,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
@Override
public void binderDied() {
if (DBG) {
Log.w(TAG, "Profile service for profile: " + mClassName
Slog.w(TAG, "Profile service for profile: " + mClassName
+ " died.");
}
onServiceDisconnected(mClassName);
@@ -919,12 +916,12 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
private void sendBluetoothStateCallback(boolean isUp) {
try {
int n = mStateChangeCallbacks.beginBroadcast();
if (DBG) Log.d(TAG,"Broadcasting onBluetoothStateChange("+isUp+") to " + n + " receivers.");
if (DBG) Slog.d(TAG,"Broadcasting onBluetoothStateChange("+isUp+") to " + n + " receivers.");
for (int i=0; i <n;i++) {
try {
mStateChangeCallbacks.getBroadcastItem(i).onBluetoothStateChange(isUp);
} catch (RemoteException e) {
Log.e(TAG, "Unable to call onBluetoothStateChange() on callback #" + i , e);
Slog.e(TAG, "Unable to call onBluetoothStateChange() on callback #" + i , e);
}
}
} finally {
@@ -936,15 +933,15 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
* Inform BluetoothAdapter instances that Adapter service is up
*/
private void sendBluetoothServiceUpCallback() {
if (DBG) Log.d(TAG,"Calling onBluetoothServiceUp callbacks");
if (DBG) Slog.d(TAG,"Calling onBluetoothServiceUp callbacks");
try {
int n = mCallbacks.beginBroadcast();
Log.d(TAG,"Broadcasting onBluetoothServiceUp() to " + n + " receivers.");
Slog.d(TAG,"Broadcasting onBluetoothServiceUp() to " + n + " receivers.");
for (int i=0; i <n;i++) {
try {
mCallbacks.getBroadcastItem(i).onBluetoothServiceUp(mBluetooth);
} catch (RemoteException e) {
Log.e(TAG, "Unable to call onBluetoothServiceUp() on callback #" + i, e);
Slog.e(TAG, "Unable to call onBluetoothServiceUp() on callback #" + i, e);
}
}
} finally {
@@ -955,15 +952,15 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
* Inform BluetoothAdapter instances that Adapter service is down
*/
private void sendBluetoothServiceDownCallback() {
if (DBG) Log.d(TAG,"Calling onBluetoothServiceDown callbacks");
if (DBG) Slog.d(TAG,"Calling onBluetoothServiceDown callbacks");
try {
int n = mCallbacks.beginBroadcast();
Log.d(TAG,"Broadcasting onBluetoothServiceDown() to " + n + " receivers.");
Slog.d(TAG,"Broadcasting onBluetoothServiceDown() to " + n + " receivers.");
for (int i=0; i <n;i++) {
try {
mCallbacks.getBroadcastItem(i).onBluetoothServiceDown();
} catch (RemoteException e) {
Log.e(TAG, "Unable to call onBluetoothServiceDown() on callback #" + i, e);
Slog.e(TAG, "Unable to call onBluetoothServiceDown() on callback #" + i, e);
}
}
} finally {
@@ -977,7 +974,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
if ((Binder.getCallingUid() != Process.SYSTEM_UID) &&
(!checkIfCallerIsForegroundUser())) {
Log.w(TAG,"getAddress(): not allowed for non-active and non system user");
Slog.w(TAG,"getAddress(): not allowed for non-active and non system user");
return null;
}
@@ -991,7 +988,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
try {
return mBluetooth.getAddress();
} catch (RemoteException e) {
Log.e(TAG, "getAddress(): Unable to retrieve address remotely..Returning cached address",e);
Slog.e(TAG, "getAddress(): Unable to retrieve address remotely..Returning cached address",e);
}
}
}
@@ -1007,7 +1004,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
if ((Binder.getCallingUid() != Process.SYSTEM_UID) &&
(!checkIfCallerIsForegroundUser())) {
Log.w(TAG,"getName(): not allowed for non-active and non system user");
Slog.w(TAG,"getName(): not allowed for non-active and non system user");
return null;
}
@@ -1016,7 +1013,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
try {
return mBluetooth.getName();
} catch (RemoteException e) {
Log.e(TAG, "getName(): Unable to retrieve name remotely..Returning cached name",e);
Slog.e(TAG, "getName(): Unable to retrieve name remotely..Returning cached name",e);
}
}
}
@@ -1028,7 +1025,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
private class BluetoothServiceConnection implements ServiceConnection {
public void onServiceConnected(ComponentName className, IBinder service) {
if (DBG) Log.d(TAG, "BluetoothServiceConnection: " + className.getClassName());
if (DBG) Slog.d(TAG, "BluetoothServiceConnection: " + className.getClassName());
Message msg = mHandler.obtainMessage(MESSAGE_BLUETOOTH_SERVICE_CONNECTED);
// TBD if (className.getClassName().equals(IBluetooth.class.getName())) {
if (className.getClassName().equals("com.android.bluetooth.btservice.AdapterService")) {
@@ -1037,7 +1034,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
} else if (className.getClassName().equals("com.android.bluetooth.gatt.GattService")) {
msg.arg1 = SERVICE_IBLUETOOTHGATT;
} else {
Log.e(TAG, "Unknown service connected: " + className.getClassName());
Slog.e(TAG, "Unknown service connected: " + className.getClassName());
return;
}
msg.obj = service;
@@ -1046,7 +1043,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
public void onServiceDisconnected(ComponentName className) {
// Called if we unexpected disconnected.
if (DBG) Log.d(TAG, "BluetoothServiceConnection, disconnected: " +
if (DBG) Slog.d(TAG, "BluetoothServiceConnection, disconnected: " +
className.getClassName());
Message msg = mHandler.obtainMessage(MESSAGE_BLUETOOTH_SERVICE_DISCONNECTED);
if (className.getClassName().equals("com.android.bluetooth.btservice.AdapterService")) {
@@ -1054,7 +1051,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
} else if (className.getClassName().equals("com.android.bluetooth.gatt.GattService")) {
msg.arg1 = SERVICE_IBLUETOOTHGATT;
} else {
Log.e(TAG, "Unknown service disconnected: " + className.getClassName());
Slog.e(TAG, "Unknown service disconnected: " + className.getClassName());
return;
}
mHandler.sendMessage(msg);
@@ -1070,11 +1067,11 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
@Override
public void handleMessage(Message msg) {
if (DBG) Log.d (TAG, "Message: " + msg.what);
if (DBG) Slog.d (TAG, "Message: " + msg.what);
switch (msg.what) {
case MESSAGE_ENABLE:
if (DBG) {
Log.d(TAG, "MESSAGE_ENABLE: mBluetooth = " + mBluetooth);
Slog.d(TAG, "MESSAGE_ENABLE: mBluetooth = " + mBluetooth);
}
mHandler.removeMessages(MESSAGE_RESTART_BLUETOOTH_SERVICE);
mEnable = true;
@@ -1098,14 +1095,14 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
{
IBluetoothManagerCallback callback = (IBluetoothManagerCallback) msg.obj;
boolean added = mCallbacks.register(callback);
Log.d(TAG,"Added callback: " + (callback == null? "null": callback) +":" +added );
Slog.d(TAG,"Added callback: " + (callback == null? "null": callback) +":" +added );
}
break;
case MESSAGE_UNREGISTER_ADAPTER:
{
IBluetoothManagerCallback callback = (IBluetoothManagerCallback) msg.obj;
boolean removed = mCallbacks.unregister(callback);
Log.d(TAG,"Removed callback: " + (callback == null? "null": callback) +":" + removed);
Slog.d(TAG,"Removed callback: " + (callback == null? "null": callback) +":" + removed);
break;
}
case MESSAGE_REGISTER_STATE_CHANGE_CALLBACK:
@@ -1148,7 +1145,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
}
case MESSAGE_BLUETOOTH_SERVICE_CONNECTED:
{
if (DBG) Log.d(TAG,"MESSAGE_BLUETOOTH_SERVICE_CONNECTED: " + msg.arg1);
if (DBG) Slog.d(TAG,"MESSAGE_BLUETOOTH_SERVICE_CONNECTED: " + msg.arg1);
IBinder service = (IBinder) msg.obj;
synchronized(mConnection) {
@@ -1169,17 +1166,17 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
boolean enableHciSnoopLog = (Settings.Secure.getInt(mContentResolver,
Settings.Secure.BLUETOOTH_HCI_LOG, 0) == 1);
if (!mBluetooth.configHciSnoopLog(enableHciSnoopLog)) {
Log.e(TAG,"IBluetooth.configHciSnoopLog return false");
Slog.e(TAG,"IBluetooth.configHciSnoopLog return false");
}
} catch (RemoteException e) {
Log.e(TAG,"Unable to call configHciSnoopLog", e);
Slog.e(TAG,"Unable to call configHciSnoopLog", e);
}
//Register callback object
try {
mBluetooth.registerCallback(mBluetoothCallback);
} catch (RemoteException re) {
Log.e(TAG, "Unable to register BluetoothCallback",re);
Slog.e(TAG, "Unable to register BluetoothCallback",re);
}
//Inform BluetoothAdapter instances that service is up
sendBluetoothServiceUpCallback();
@@ -1188,17 +1185,17 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
try {
if (mQuietEnable == false) {
if(!mBluetooth.enable()) {
Log.e(TAG,"IBluetooth.enable() returned false");
Slog.e(TAG,"IBluetooth.enable() returned false");
}
}
else
{
if(!mBluetooth.enableNoAutoConnect()) {
Log.e(TAG,"IBluetooth.enableNoAutoConnect() returned false");
Slog.e(TAG,"IBluetooth.enableNoAutoConnect() returned false");
}
}
} catch (RemoteException e) {
Log.e(TAG,"Unable to call enable()",e);
Slog.e(TAG,"Unable to call enable()",e);
}
}
@@ -1210,7 +1207,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
break;
}
case MESSAGE_TIMEOUT_BIND: {
Log.e(TAG, "MESSAGE_TIMEOUT_BIND");
Slog.e(TAG, "MESSAGE_TIMEOUT_BIND");
synchronized(mConnection) {
mBinding = false;
}
@@ -1220,7 +1217,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
{
int prevState = msg.arg1;
int newState = msg.arg2;
if (DBG) Log.d(TAG, "MESSAGE_BLUETOOTH_STATE_CHANGE: prevState = " + prevState + ", newState=" + newState);
if (DBG) Slog.d(TAG, "MESSAGE_BLUETOOTH_STATE_CHANGE: prevState = " + prevState + ", newState=" + newState);
mState = newState;
bluetoothStateChangeHandler(prevState, newState);
// handle error state transition case from TURNING_ON to OFF
@@ -1239,7 +1236,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
newState == BluetoothAdapter.STATE_BLE_ON) {
// bluetooth is working, reset the counter
if (mErrorRecoveryRetryCounter != 0) {
Log.w(TAG, "bluetooth is recovered from error");
Slog.w(TAG, "bluetooth is recovered from error");
mErrorRecoveryRetryCounter = 0;
}
}
@@ -1247,7 +1244,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
}
case MESSAGE_BLUETOOTH_SERVICE_DISCONNECTED:
{
Log.e(TAG, "MESSAGE_BLUETOOTH_SERVICE_DISCONNECTED: " + msg.arg1);
Slog.e(TAG, "MESSAGE_BLUETOOTH_SERVICE_DISCONNECTED: " + msg.arg1);
synchronized(mConnection) {
if (msg.arg1 == SERVICE_IBLUETOOTH) {
// if service is unbinded already, do nothing and return
@@ -1257,7 +1254,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
mBluetoothGatt = null;
break;
} else {
Log.e(TAG, "Bad msg.arg1: " + msg.arg1);
Slog.e(TAG, "Bad msg.arg1: " + msg.arg1);
break;
}
}
@@ -1292,7 +1289,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
}
case MESSAGE_RESTART_BLUETOOTH_SERVICE:
{
Log.d(TAG, "MESSAGE_RESTART_BLUETOOTH_SERVICE:"
Slog.d(TAG, "MESSAGE_RESTART_BLUETOOTH_SERVICE:"
+" Restart IBluetooth service");
/* Enable without persisting the setting as
it doesnt change when IBluetooth
@@ -1304,7 +1301,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
case MESSAGE_TIMEOUT_UNBIND:
{
Log.e(TAG, "MESSAGE_TIMEOUT_UNBIND");
Slog.e(TAG, "MESSAGE_TIMEOUT_UNBIND");
synchronized(mConnection) {
mUnbinding = false;
}
@@ -1314,7 +1311,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
case MESSAGE_USER_SWITCHED:
{
if (DBG) {
Log.d(TAG, "MESSAGE_USER_SWITCHED");
Slog.d(TAG, "MESSAGE_USER_SWITCHED");
}
mHandler.removeMessages(MESSAGE_USER_SWITCHED);
/* disable and enable BT when detect a user switch */
@@ -1325,7 +1322,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
try {
mBluetooth.unregisterCallback(mBluetoothCallback);
} catch (RemoteException re) {
Log.e(TAG, "Unable to unregister",re);
Slog.e(TAG, "Unable to unregister",re);
}
}
}
@@ -1379,7 +1376,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
// delay sending MESSAGE_USER_SWITCHED
mHandler.sendMessageDelayed(userMsg, USER_SWITCHED_TIME_MS);
if (DBG) {
Log.d(TAG, "delay MESSAGE_USER_SWITCHED " + userMsg.arg2);
Slog.d(TAG, "delay MESSAGE_USER_SWITCHED " + userMsg.arg2);
}
}
break;
@@ -1408,16 +1405,16 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
try {
if (!mQuietEnable) {
if(!mBluetooth.enable()) {
Log.e(TAG,"IBluetooth.enable() returned false");
Slog.e(TAG,"IBluetooth.enable() returned false");
}
}
else {
if(!mBluetooth.enableNoAutoConnect()) {
Log.e(TAG,"IBluetooth.enableNoAutoConnect() returned false");
Slog.e(TAG,"IBluetooth.enableNoAutoConnect() returned false");
}
}
} catch (RemoteException e) {
Log.e(TAG,"Unable to call enable()",e);
Slog.e(TAG,"Unable to call enable()",e);
}
}
}
@@ -1427,7 +1424,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
ComponentName comp = intent.resolveSystemService(mContext.getPackageManager(), 0);
intent.setComponent(comp);
if (comp == null || !mContext.bindServiceAsUser(intent, conn, flags, user)) {
Log.e(TAG, "Fail to bind to: " + intent);
Slog.e(TAG, "Fail to bind to: " + intent);
return false;
}
return true;
@@ -1436,14 +1433,14 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
private void handleDisable() {
synchronized(mConnection) {
if (mBluetooth != null) {
if (DBG) Log.d(TAG,"Sending off request.");
if (DBG) Slog.d(TAG,"Sending off request.");
try {
if(!mBluetooth.disable()) {
Log.e(TAG,"IBluetooth.disable() returned false");
Slog.e(TAG,"IBluetooth.disable() returned false");
}
} catch (RemoteException e) {
Log.e(TAG,"Unable to call disable()",e);
Slog.e(TAG,"Unable to call disable()",e);
}
}
}
@@ -1466,7 +1463,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
callingAppId == Process.NFC_UID ||
callingAppId == mSystemUiUid;
if (DBG) {
Log.d(TAG, "checkIfCallerIsForegroundUser: valid=" + valid
Slog.d(TAG, "checkIfCallerIsForegroundUser: valid=" + valid
+ " callingUser=" + callingUser
+ " parentUser=" + parentUser
+ " foregroundUser=" + foregroundUser);
@@ -1478,7 +1475,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
}
private void sendBleStateChanged(int prevState, int newState) {
if (DBG) Log.d(TAG,"BLE State Change Intent: " + prevState + " -> " + newState);
if (DBG) Slog.d(TAG,"BLE State Change Intent: " + prevState + " -> " + newState);
// Send broadcast message to everyone else
Intent intent = new Intent(BluetoothAdapter.ACTION_BLE_STATE_CHANGED);
intent.putExtra(BluetoothAdapter.EXTRA_PREVIOUS_STATE, prevState);
@@ -1498,9 +1495,9 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
if (newState == BluetoothAdapter.STATE_OFF) {
// If Bluetooth is off, send service down event to proxy objects, and unbind
if (DBG) Log.d(TAG, "Bluetooth is complete turn off");
if (DBG) Slog.d(TAG, "Bluetooth is complete turn off");
if (canUnbindBluetoothService()) {
if (DBG) Log.d(TAG, "Good to unbind!");
if (DBG) Slog.d(TAG, "Good to unbind!");
sendBluetoothServiceDownCallback();
unbindAndFinish();
sendBleStateChanged(prevState, newState);
@@ -1510,12 +1507,12 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
} else if (!intermediate_off) {
// connect to GattService
if (DBG) Log.d(TAG, "Bluetooth is in LE only mode");
if (DBG) Slog.d(TAG, "Bluetooth is in LE only mode");
if (mBluetoothGatt != null) {
if (DBG) Log.d(TAG, "Calling BluetoothGattServiceUp");
if (DBG) Slog.d(TAG, "Calling BluetoothGattServiceUp");
onBluetoothGattServiceUp();
} else {
if (DBG) Log.d(TAG, "Binding Bluetooth GATT service");
if (DBG) Slog.d(TAG, "Binding Bluetooth GATT service");
if (mContext.getPackageManager().hasSystemFeature(
PackageManager.FEATURE_BLUETOOTH_LE)) {
Intent i = new Intent(IBluetoothGatt.class.getName());
@@ -1527,7 +1524,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
isStandardBroadcast = false;
} else if (intermediate_off){
if (DBG) Log.d(TAG, "Intermediate off, back to LE only mode");
if (DBG) Slog.d(TAG, "Intermediate off, back to LE only mode");
// For LE only mode, broadcast as is
sendBleStateChanged(prevState, newState);
sendBluetoothStateCallback(false); // BT is OFF for general users
@@ -1583,7 +1580,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
if (mBluetooth.getState() != BluetoothAdapter.STATE_ON) return true;
}
} catch (RemoteException e) {
Log.e(TAG, "getState()", e);
Slog.e(TAG, "getState()", e);
break;
}
}
@@ -1594,7 +1591,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
}
i++;
}
Log.e(TAG,"waitForOnOff time out");
Slog.e(TAG,"waitForOnOff time out");
return false;
}
@@ -1619,21 +1616,21 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
if (mHandler.hasMessages(MESSAGE_BLUETOOTH_STATE_CHANGE)) return false;
return (mBluetooth.getState() == BluetoothAdapter.STATE_OFF);
} catch (RemoteException e) {
Log.e(TAG, "getState()", e);
Slog.e(TAG, "getState()", e);
}
}
return false;
}
private void recoverBluetoothServiceFromError() {
Log.e(TAG,"recoverBluetoothServiceFromError");
Slog.e(TAG,"recoverBluetoothServiceFromError");
synchronized (mConnection) {
if (mBluetooth != null) {
//Unregister callback object
try {
mBluetooth.unregisterCallback(mBluetoothCallback);
} catch (RemoteException re) {
Log.e(TAG, "Unable to unregister",re);
Slog.e(TAG, "Unable to unregister",re);
}
}
}