diff --git a/services/core/java/com/android/server/BluetoothManagerService.java b/services/core/java/com/android/server/BluetoothManagerService.java index 8cfeb748ccee4..f65dbb67b228b 100644 --- a/services/core/java/com/android/server/BluetoothManagerService.java +++ b/services/core/java/com/android/server/BluetoothManagerService.java @@ -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 " + 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); } } }