Fix checkstyle errors (1/2)

* Automatic style corrections through IDE

Bug: 63596319
Test: make checkbuild, no manual changes, no functional changes
Change-Id: I2397d55abc34c9b7a9b748bec6137778df3421a7
diff --git a/core/java/android/bluetooth/BluetoothGatt.java b/core/java/android/bluetooth/BluetoothGatt.java
index 678159b..8a3650c 100644
--- a/core/java/android/bluetooth/BluetoothGatt.java
+++ b/core/java/android/bluetooth/BluetoothGatt.java
@@ -118,18 +118,21 @@
 
     /**
      * No authentication required.
+     *
      * @hide
      */
     /*package*/ static final int AUTHENTICATION_NONE = 0;
 
     /**
      * Authentication requested; no man-in-the-middle protection required.
+     *
      * @hide
      */
     /*package*/ static final int AUTHENTICATION_NO_MITM = 1;
 
     /**
      * Authentication with man-in-the-middle protection requested.
+     *
      * @hide
      */
     /*package*/ static final int AUTHENTICATION_MITM = 2;
@@ -138,498 +141,536 @@
      * Bluetooth GATT callbacks. Overrides the default BluetoothGattCallback implementation.
      */
     private final IBluetoothGattCallback mBluetoothGattCallback =
-        new IBluetoothGattCallback.Stub() {
-            /**
-             * Application interface registered - app is ready to go
-             * @hide
-             */
-            @Override
-            public void onClientRegistered(int status, int clientIf) {
-                if (DBG) Log.d(TAG, "onClientRegistered() - status=" + status
-                    + " clientIf=" + clientIf);
-                if (VDBG) {
-                    synchronized(mStateLock) {
-                        if (mConnState != CONN_STATE_CONNECTING) {
-                            Log.e(TAG, "Bad connection state: " + mConnState);
+            new IBluetoothGattCallback.Stub() {
+                /**
+                 * Application interface registered - app is ready to go
+                 * @hide
+                 */
+                @Override
+                public void onClientRegistered(int status, int clientIf) {
+                    if (DBG) {
+                        Log.d(TAG, "onClientRegistered() - status=" + status
+                                + " clientIf=" + clientIf);
+                    }
+                    if (VDBG) {
+                        synchronized (mStateLock) {
+                            if (mConnState != CONN_STATE_CONNECTING) {
+                                Log.e(TAG, "Bad connection state: " + mConnState);
+                            }
                         }
                     }
+                    mClientIf = clientIf;
+                    if (status != GATT_SUCCESS) {
+                        runOrQueueCallback(new Runnable() {
+                            @Override
+                            public void run() {
+                                if (mCallback != null) {
+                                    mCallback.onConnectionStateChange(BluetoothGatt.this,
+                                            GATT_FAILURE,
+                                            BluetoothProfile.STATE_DISCONNECTED);
+                                }
+                            }
+                        });
+
+                        synchronized (mStateLock) {
+                            mConnState = CONN_STATE_IDLE;
+                        }
+                        return;
+                    }
+                    try {
+                        mService.clientConnect(mClientIf, mDevice.getAddress(),
+                                !mAutoConnect, mTransport, mOpportunistic,
+                                mPhy); // autoConnect is inverse of "isDirect"
+                    } catch (RemoteException e) {
+                        Log.e(TAG, "", e);
+                    }
                 }
-                mClientIf = clientIf;
-                if (status != GATT_SUCCESS) {
+
+                /**
+                 * Phy update callback
+                 * @hide
+                 */
+                @Override
+                public void onPhyUpdate(String address, int txPhy, int rxPhy, int status) {
+                    if (DBG) {
+                        Log.d(TAG, "onPhyUpdate() - status=" + status
+                                + " address=" + address + " txPhy=" + txPhy + " rxPhy=" + rxPhy);
+                    }
+                    if (!address.equals(mDevice.getAddress())) {
+                        return;
+                    }
+
                     runOrQueueCallback(new Runnable() {
                         @Override
                         public void run() {
                             if (mCallback != null) {
-                                mCallback.onConnectionStateChange(BluetoothGatt.this, GATT_FAILURE,
-                                                  BluetoothProfile.STATE_DISCONNECTED);
+                                mCallback.onPhyUpdate(BluetoothGatt.this, txPhy, rxPhy, status);
+                            }
+                        }
+                    });
+                }
+
+                /**
+                 * Phy read callback
+                 * @hide
+                 */
+                @Override
+                public void onPhyRead(String address, int txPhy, int rxPhy, int status) {
+                    if (DBG) {
+                        Log.d(TAG, "onPhyRead() - status=" + status
+                                + " address=" + address + " txPhy=" + txPhy + " rxPhy=" + rxPhy);
+                    }
+                    if (!address.equals(mDevice.getAddress())) {
+                        return;
+                    }
+
+                    runOrQueueCallback(new Runnable() {
+                        @Override
+                        public void run() {
+                            if (mCallback != null) {
+                                mCallback.onPhyRead(BluetoothGatt.this, txPhy, rxPhy, status);
+                            }
+                        }
+                    });
+                }
+
+                /**
+                 * Client connection state changed
+                 * @hide
+                 */
+                @Override
+                public void onClientConnectionState(int status, int clientIf,
+                        boolean connected, String address) {
+                    if (DBG) {
+                        Log.d(TAG, "onClientConnectionState() - status=" + status
+                                + " clientIf=" + clientIf + " device=" + address);
+                    }
+                    if (!address.equals(mDevice.getAddress())) {
+                        return;
+                    }
+                    int profileState = connected ? BluetoothProfile.STATE_CONNECTED :
+                            BluetoothProfile.STATE_DISCONNECTED;
+
+                    runOrQueueCallback(new Runnable() {
+                        @Override
+                        public void run() {
+                            if (mCallback != null) {
+                                mCallback.onConnectionStateChange(BluetoothGatt.this, status,
+                                        profileState);
                             }
                         }
                     });
 
-                    synchronized(mStateLock) {
-                        mConnState = CONN_STATE_IDLE;
-                    }
-                    return;
-                }
-                try {
-                    mService.clientConnect(mClientIf, mDevice.getAddress(),
-                                           !mAutoConnect, mTransport, mOpportunistic, mPhy); // autoConnect is inverse of "isDirect"
-                } catch (RemoteException e) {
-                    Log.e(TAG,"",e);
-                }
-            }
-
-            /**
-             * Phy update callback
-             * @hide
-             */
-            @Override
-            public void onPhyUpdate(String address, int txPhy, int rxPhy, int status) {
-                if (DBG) Log.d(TAG, "onPhyUpdate() - status=" + status
-                                 + " address=" + address + " txPhy=" + txPhy + " rxPhy=" + rxPhy);
-                if (!address.equals(mDevice.getAddress())) {
-                    return;
-                }
-
-                runOrQueueCallback(new Runnable() {
-                    @Override
-                    public void run() {
-                        if (mCallback != null) {
-                            mCallback.onPhyUpdate(BluetoothGatt.this, txPhy, rxPhy, status);
-                        }
-                    }
-                });
-            }
-
-            /**
-             * Phy read callback
-             * @hide
-             */
-            @Override
-            public void onPhyRead(String address, int txPhy, int rxPhy, int status) {
-                if (DBG) Log.d(TAG, "onPhyRead() - status=" + status
-                                 + " address=" + address + " txPhy=" + txPhy + " rxPhy=" + rxPhy);
-                if (!address.equals(mDevice.getAddress())) {
-                    return;
-                }
-
-                runOrQueueCallback(new Runnable() {
-                    @Override
-                    public void run() {
-                        if (mCallback != null) {
-                            mCallback.onPhyRead(BluetoothGatt.this, txPhy, rxPhy, status);
-                        }
-                    }
-                });
-            }
-
-            /**
-             * Client connection state changed
-             * @hide
-             */
-            @Override
-            public void onClientConnectionState(int status, int clientIf,
-                                                boolean connected, String address) {
-                if (DBG) Log.d(TAG, "onClientConnectionState() - status=" + status
-                                 + " clientIf=" + clientIf + " device=" + address);
-                if (!address.equals(mDevice.getAddress())) {
-                    return;
-                }
-                int profileState = connected ? BluetoothProfile.STATE_CONNECTED :
-                                               BluetoothProfile.STATE_DISCONNECTED;
-
-                runOrQueueCallback(new Runnable() {
-                    @Override
-                    public void run() {
-                        if (mCallback != null) {
-                            mCallback.onConnectionStateChange(BluetoothGatt.this, status,
-                                                              profileState);
-                        }
-                    }
-                });
-
-                synchronized(mStateLock) {
-                    if (connected) {
-                        mConnState = CONN_STATE_CONNECTED;
-                    } else {
-                        mConnState = CONN_STATE_IDLE;
-                    }
-                }
-
-                synchronized(mDeviceBusy) {
-                    mDeviceBusy = false;
-                }
-            }
-
-            /**
-             * Remote search has been completed.
-             * The internal object structure should now reflect the state
-             * of the remote device database. Let the application know that
-             * we are done at this point.
-             * @hide
-             */
-            @Override
-            public void onSearchComplete(String address, List<BluetoothGattService> services,
-                                         int status) {
-                if (DBG) Log.d(TAG, "onSearchComplete() = Device=" + address + " Status=" + status);
-                if (!address.equals(mDevice.getAddress())) {
-                    return;
-                }
-
-                for (BluetoothGattService s : services) {
-                    //services we receive don't have device set properly.
-                    s.setDevice(mDevice);
-                }
-
-                mServices.addAll(services);
-
-                // Fix references to included services, as they doesn't point to right objects.
-                for (BluetoothGattService fixedService : mServices) {
-                    ArrayList<BluetoothGattService> includedServices =
-                        new ArrayList(fixedService.getIncludedServices());
-                    fixedService.getIncludedServices().clear();
-
-                    for(BluetoothGattService brokenRef : includedServices) {
-                        BluetoothGattService includedService = getService(mDevice,
-                            brokenRef.getUuid(), brokenRef.getInstanceId(), brokenRef.getType());
-                        if (includedService != null) {
-                            fixedService.addIncludedService(includedService);
+                    synchronized (mStateLock) {
+                        if (connected) {
+                            mConnState = CONN_STATE_CONNECTED;
                         } else {
-                            Log.e(TAG, "Broken GATT database: can't find included service.");
+                            mConnState = CONN_STATE_IDLE;
                         }
                     }
+
+                    synchronized (mDeviceBusy) {
+                        mDeviceBusy = false;
+                    }
                 }
 
-                runOrQueueCallback(new Runnable() {
-                    @Override
-                    public void run() {
-                        if (mCallback != null) {
-                            mCallback.onServicesDiscovered(BluetoothGatt.this, status);
-                        }
+                /**
+                 * Remote search has been completed.
+                 * The internal object structure should now reflect the state
+                 * of the remote device database. Let the application know that
+                 * we are done at this point.
+                 * @hide
+                 */
+                @Override
+                public void onSearchComplete(String address, List<BluetoothGattService> services,
+                        int status) {
+                    if (DBG) {
+                        Log.d(TAG,
+                                "onSearchComplete() = Device=" + address + " Status=" + status);
                     }
-                });
-            }
-
-            /**
-             * Remote characteristic has been read.
-             * Updates the internal value.
-             * @hide
-             */
-            @Override
-            public void onCharacteristicRead(String address, int status, int handle, byte[] value) {
-                if (VDBG) Log.d(TAG, "onCharacteristicRead() - Device=" + address
-                            + " handle=" + handle + " Status=" + status);
-
-                if (!address.equals(mDevice.getAddress())) {
-                    return;
-                }
-
-                synchronized(mDeviceBusy) {
-                    mDeviceBusy = false;
-                }
-
-                if ((status == GATT_INSUFFICIENT_AUTHENTICATION
-                  || status == GATT_INSUFFICIENT_ENCRYPTION)
-                  && (mAuthRetryState != AUTH_RETRY_STATE_MITM)) {
-                    try {
-                        final int authReq = (mAuthRetryState == AUTH_RETRY_STATE_IDLE) ?
-                                AUTHENTICATION_NO_MITM : AUTHENTICATION_MITM;
-                        mService.readCharacteristic(mClientIf, address, handle, authReq);
-                        mAuthRetryState++;
+                    if (!address.equals(mDevice.getAddress())) {
                         return;
-                    } catch (RemoteException e) {
-                        Log.e(TAG,"",e);
                     }
-                }
 
-                mAuthRetryState = AUTH_RETRY_STATE_IDLE;
+                    for (BluetoothGattService s : services) {
+                        //services we receive don't have device set properly.
+                        s.setDevice(mDevice);
+                    }
 
-                BluetoothGattCharacteristic characteristic = getCharacteristicById(mDevice, handle);
-                if (characteristic == null) {
-                    Log.w(TAG, "onCharacteristicRead() failed to find characteristic!");
-                    return;
-                }
+                    mServices.addAll(services);
 
-                if (status == 0) characteristic.setValue(value);
+                    // Fix references to included services, as they doesn't point to right objects.
+                    for (BluetoothGattService fixedService : mServices) {
+                        ArrayList<BluetoothGattService> includedServices =
+                                new ArrayList(fixedService.getIncludedServices());
+                        fixedService.getIncludedServices().clear();
 
-                runOrQueueCallback(new Runnable() {
-                    @Override
-                    public void run() {
-                        if (mCallback != null) {
-                            mCallback.onCharacteristicRead(BluetoothGatt.this, characteristic,
-                                                           status);
+                        for (BluetoothGattService brokenRef : includedServices) {
+                            BluetoothGattService includedService = getService(mDevice,
+                                    brokenRef.getUuid(), brokenRef.getInstanceId(),
+                                    brokenRef.getType());
+                            if (includedService != null) {
+                                fixedService.addIncludedService(includedService);
+                            } else {
+                                Log.e(TAG, "Broken GATT database: can't find included service.");
+                            }
                         }
                     }
-                });
-            }
 
-            /**
-             * Characteristic has been written to the remote device.
-             * Let the app know how we did...
-             * @hide
-             */
-            @Override
-            public void onCharacteristicWrite(String address, int status, int handle) {
-                if (VDBG) Log.d(TAG, "onCharacteristicWrite() - Device=" + address
-                            + " handle=" + handle + " Status=" + status);
-
-                if (!address.equals(mDevice.getAddress())) {
-                    return;
+                    runOrQueueCallback(new Runnable() {
+                        @Override
+                        public void run() {
+                            if (mCallback != null) {
+                                mCallback.onServicesDiscovered(BluetoothGatt.this, status);
+                            }
+                        }
+                    });
                 }
 
-                synchronized(mDeviceBusy) {
-                    mDeviceBusy = false;
-                }
+                /**
+                 * Remote characteristic has been read.
+                 * Updates the internal value.
+                 * @hide
+                 */
+                @Override
+                public void onCharacteristicRead(String address, int status, int handle,
+                        byte[] value) {
+                    if (VDBG) {
+                        Log.d(TAG, "onCharacteristicRead() - Device=" + address
+                                + " handle=" + handle + " Status=" + status);
+                    }
 
-                BluetoothGattCharacteristic characteristic = getCharacteristicById(mDevice, handle);
-                if (characteristic == null) return;
-
-                if ((status == GATT_INSUFFICIENT_AUTHENTICATION
-                  || status == GATT_INSUFFICIENT_ENCRYPTION)
-                  && (mAuthRetryState != AUTH_RETRY_STATE_MITM)) {
-                    try {
-                        final int authReq = (mAuthRetryState == AUTH_RETRY_STATE_IDLE) ?
-                                AUTHENTICATION_NO_MITM : AUTHENTICATION_MITM;
-                        mService.writeCharacteristic(mClientIf, address, handle,
-                            characteristic.getWriteType(), authReq, characteristic.getValue());
-                        mAuthRetryState++;
+                    if (!address.equals(mDevice.getAddress())) {
                         return;
-                    } catch (RemoteException e) {
-                        Log.e(TAG,"",e);
                     }
-                }
 
-                mAuthRetryState = AUTH_RETRY_STATE_IDLE;
+                    synchronized (mDeviceBusy) {
+                        mDeviceBusy = false;
+                    }
 
-                runOrQueueCallback(new Runnable() {
-                    @Override
-                    public void run() {
-                        if (mCallback != null) {
-                            mCallback.onCharacteristicWrite(BluetoothGatt.this, characteristic,
-                                                            status);
+                    if ((status == GATT_INSUFFICIENT_AUTHENTICATION
+                            || status == GATT_INSUFFICIENT_ENCRYPTION)
+                            && (mAuthRetryState != AUTH_RETRY_STATE_MITM)) {
+                        try {
+                            final int authReq = (mAuthRetryState == AUTH_RETRY_STATE_IDLE) ?
+                                    AUTHENTICATION_NO_MITM : AUTHENTICATION_MITM;
+                            mService.readCharacteristic(mClientIf, address, handle, authReq);
+                            mAuthRetryState++;
+                            return;
+                        } catch (RemoteException e) {
+                            Log.e(TAG, "", e);
                         }
                     }
-                });
-            }
 
-            /**
-             * Remote characteristic has been updated.
-             * Updates the internal value.
-             * @hide
-             */
-            @Override
-            public void onNotify(String address, int handle, byte[] value) {
-                if (VDBG) Log.d(TAG, "onNotify() - Device=" + address + " handle=" + handle);
+                    mAuthRetryState = AUTH_RETRY_STATE_IDLE;
 
-                if (!address.equals(mDevice.getAddress())) {
-                    return;
-                }
-
-                BluetoothGattCharacteristic characteristic = getCharacteristicById(mDevice, handle);
-                if (characteristic == null) return;
-
-                characteristic.setValue(value);
-
-                runOrQueueCallback(new Runnable() {
-                    @Override
-                    public void run() {
-                        if (mCallback != null) {
-                            mCallback.onCharacteristicChanged(BluetoothGatt.this, characteristic);
-                        }
-                    }
-                });
-            }
-
-            /**
-             * Descriptor has been read.
-             * @hide
-             */
-            @Override
-            public void onDescriptorRead(String address, int status, int handle, byte[] value) {
-                if (VDBG) Log.d(TAG, "onDescriptorRead() - Device=" + address + " handle=" + handle);
-
-                if (!address.equals(mDevice.getAddress())) {
-                    return;
-                }
-
-                synchronized(mDeviceBusy) {
-                    mDeviceBusy = false;
-                }
-
-                BluetoothGattDescriptor descriptor = getDescriptorById(mDevice, handle);
-                if (descriptor == null) return;
-
-                if (status == 0) descriptor.setValue(value);
-
-                if ((status == GATT_INSUFFICIENT_AUTHENTICATION
-                  || status == GATT_INSUFFICIENT_ENCRYPTION)
-                  && (mAuthRetryState != AUTH_RETRY_STATE_MITM)) {
-                    try {
-                        final int authReq = (mAuthRetryState == AUTH_RETRY_STATE_IDLE) ?
-                                AUTHENTICATION_NO_MITM : AUTHENTICATION_MITM;
-                        mService.readDescriptor(mClientIf, address, handle, authReq);
-                        mAuthRetryState++;
+                    BluetoothGattCharacteristic characteristic = getCharacteristicById(mDevice,
+                            handle);
+                    if (characteristic == null) {
+                        Log.w(TAG, "onCharacteristicRead() failed to find characteristic!");
                         return;
-                    } catch (RemoteException e) {
-                        Log.e(TAG,"",e);
                     }
-                }
 
-                mAuthRetryState = AUTH_RETRY_STATE_IDLE;
+                    if (status == 0) characteristic.setValue(value);
 
-                runOrQueueCallback(new Runnable() {
-                    @Override
-                    public void run() {
-                        if (mCallback != null) {
-                            mCallback.onDescriptorRead(BluetoothGatt.this, descriptor, status);
+                    runOrQueueCallback(new Runnable() {
+                        @Override
+                        public void run() {
+                            if (mCallback != null) {
+                                mCallback.onCharacteristicRead(BluetoothGatt.this, characteristic,
+                                        status);
+                            }
                         }
+                    });
+                }
+
+                /**
+                 * Characteristic has been written to the remote device.
+                 * Let the app know how we did...
+                 * @hide
+                 */
+                @Override
+                public void onCharacteristicWrite(String address, int status, int handle) {
+                    if (VDBG) {
+                        Log.d(TAG, "onCharacteristicWrite() - Device=" + address
+                                + " handle=" + handle + " Status=" + status);
                     }
-                });
-            }
 
-            /**
-             * Descriptor write operation complete.
-             * @hide
-             */
-            @Override
-            public void onDescriptorWrite(String address, int status, int handle) {
-                if (VDBG) Log.d(TAG, "onDescriptorWrite() - Device=" + address + " handle=" + handle);
-
-                if (!address.equals(mDevice.getAddress())) {
-                    return;
-                }
-
-                synchronized(mDeviceBusy) {
-                    mDeviceBusy = false;
-                }
-
-                BluetoothGattDescriptor descriptor = getDescriptorById(mDevice, handle);
-                if (descriptor == null) return;
-
-                if ((status == GATT_INSUFFICIENT_AUTHENTICATION
-                  || status == GATT_INSUFFICIENT_ENCRYPTION)
-                  && (mAuthRetryState != AUTH_RETRY_STATE_MITM)) {
-                    try {
-                        final int authReq = (mAuthRetryState == AUTH_RETRY_STATE_IDLE) ?
-                                AUTHENTICATION_NO_MITM : AUTHENTICATION_MITM;
-                        mService.writeDescriptor(mClientIf, address, handle,
-                            authReq, descriptor.getValue());
-                        mAuthRetryState++;
+                    if (!address.equals(mDevice.getAddress())) {
                         return;
-                    } catch (RemoteException e) {
-                        Log.e(TAG,"",e);
                     }
-                }
 
-                mAuthRetryState = AUTH_RETRY_STATE_IDLE;
+                    synchronized (mDeviceBusy) {
+                        mDeviceBusy = false;
+                    }
 
-                runOrQueueCallback(new Runnable() {
-                    @Override
-                    public void run() {
-                        if (mCallback != null) {
-                            mCallback.onDescriptorWrite(BluetoothGatt.this, descriptor, status);
+                    BluetoothGattCharacteristic characteristic = getCharacteristicById(mDevice,
+                            handle);
+                    if (characteristic == null) return;
+
+                    if ((status == GATT_INSUFFICIENT_AUTHENTICATION
+                            || status == GATT_INSUFFICIENT_ENCRYPTION)
+                            && (mAuthRetryState != AUTH_RETRY_STATE_MITM)) {
+                        try {
+                            final int authReq = (mAuthRetryState == AUTH_RETRY_STATE_IDLE) ?
+                                    AUTHENTICATION_NO_MITM : AUTHENTICATION_MITM;
+                            mService.writeCharacteristic(mClientIf, address, handle,
+                                    characteristic.getWriteType(), authReq,
+                                    characteristic.getValue());
+                            mAuthRetryState++;
+                            return;
+                        } catch (RemoteException e) {
+                            Log.e(TAG, "", e);
                         }
                     }
-                });
-            }
 
-            /**
-             * Prepared write transaction completed (or aborted)
-             * @hide
-             */
-            @Override
-            public void onExecuteWrite(String address, int status) {
-                if (VDBG) Log.d(TAG, "onExecuteWrite() - Device=" + address
-                    + " status=" + status);
-                if (!address.equals(mDevice.getAddress())) {
-                    return;
+                    mAuthRetryState = AUTH_RETRY_STATE_IDLE;
+
+                    runOrQueueCallback(new Runnable() {
+                        @Override
+                        public void run() {
+                            if (mCallback != null) {
+                                mCallback.onCharacteristicWrite(BluetoothGatt.this, characteristic,
+                                        status);
+                            }
+                        }
+                    });
                 }
 
-                synchronized(mDeviceBusy) {
-                    mDeviceBusy = false;
+                /**
+                 * Remote characteristic has been updated.
+                 * Updates the internal value.
+                 * @hide
+                 */
+                @Override
+                public void onNotify(String address, int handle, byte[] value) {
+                    if (VDBG) Log.d(TAG, "onNotify() - Device=" + address + " handle=" + handle);
+
+                    if (!address.equals(mDevice.getAddress())) {
+                        return;
+                    }
+
+                    BluetoothGattCharacteristic characteristic = getCharacteristicById(mDevice,
+                            handle);
+                    if (characteristic == null) return;
+
+                    characteristic.setValue(value);
+
+                    runOrQueueCallback(new Runnable() {
+                        @Override
+                        public void run() {
+                            if (mCallback != null) {
+                                mCallback.onCharacteristicChanged(BluetoothGatt.this,
+                                        characteristic);
+                            }
+                        }
+                    });
                 }
 
-                runOrQueueCallback(new Runnable() {
-                    @Override
-                    public void run() {
-                        if (mCallback != null) {
-                           mCallback.onReliableWriteCompleted(BluetoothGatt.this, status);
+                /**
+                 * Descriptor has been read.
+                 * @hide
+                 */
+                @Override
+                public void onDescriptorRead(String address, int status, int handle, byte[] value) {
+                    if (VDBG) {
+                        Log.d(TAG,
+                                "onDescriptorRead() - Device=" + address + " handle=" + handle);
+                    }
+
+                    if (!address.equals(mDevice.getAddress())) {
+                        return;
+                    }
+
+                    synchronized (mDeviceBusy) {
+                        mDeviceBusy = false;
+                    }
+
+                    BluetoothGattDescriptor descriptor = getDescriptorById(mDevice, handle);
+                    if (descriptor == null) return;
+
+                    if (status == 0) descriptor.setValue(value);
+
+                    if ((status == GATT_INSUFFICIENT_AUTHENTICATION
+                            || status == GATT_INSUFFICIENT_ENCRYPTION)
+                            && (mAuthRetryState != AUTH_RETRY_STATE_MITM)) {
+                        try {
+                            final int authReq = (mAuthRetryState == AUTH_RETRY_STATE_IDLE) ?
+                                    AUTHENTICATION_NO_MITM : AUTHENTICATION_MITM;
+                            mService.readDescriptor(mClientIf, address, handle, authReq);
+                            mAuthRetryState++;
+                            return;
+                        } catch (RemoteException e) {
+                            Log.e(TAG, "", e);
                         }
                     }
-                });
-            }
 
-            /**
-             * Remote device RSSI has been read
-             * @hide
-             */
-            @Override
-            public void onReadRemoteRssi(String address, int rssi, int status) {
-                if (VDBG) Log.d(TAG, "onReadRemoteRssi() - Device=" + address +
-                            " rssi=" + rssi + " status=" + status);
-                if (!address.equals(mDevice.getAddress())) {
-                    return;
-                }
-                runOrQueueCallback(new Runnable() {
-                    @Override
-                    public void run() {
-                        if (mCallback != null) {
-                            mCallback.onReadRemoteRssi(BluetoothGatt.this, rssi, status);
+                    mAuthRetryState = AUTH_RETRY_STATE_IDLE;
+
+                    runOrQueueCallback(new Runnable() {
+                        @Override
+                        public void run() {
+                            if (mCallback != null) {
+                                mCallback.onDescriptorRead(BluetoothGatt.this, descriptor, status);
+                            }
                         }
-                    }
-                });
-            }
-
-            /**
-             * Callback invoked when the MTU for a given connection changes
-             * @hide
-             */
-            @Override
-            public void onConfigureMTU(String address, int mtu, int status) {
-                if (DBG) Log.d(TAG, "onConfigureMTU() - Device=" + address +
-                            " mtu=" + mtu + " status=" + status);
-                if (!address.equals(mDevice.getAddress())) {
-                    return;
+                    });
                 }
 
-                runOrQueueCallback(new Runnable() {
-                    @Override
-                    public void run() {
-                        if (mCallback != null) {
-                            mCallback.onMtuChanged(BluetoothGatt.this, mtu, status);
+                /**
+                 * Descriptor write operation complete.
+                 * @hide
+                 */
+                @Override
+                public void onDescriptorWrite(String address, int status, int handle) {
+                    if (VDBG) {
+                        Log.d(TAG,
+                                "onDescriptorWrite() - Device=" + address + " handle=" + handle);
+                    }
+
+                    if (!address.equals(mDevice.getAddress())) {
+                        return;
+                    }
+
+                    synchronized (mDeviceBusy) {
+                        mDeviceBusy = false;
+                    }
+
+                    BluetoothGattDescriptor descriptor = getDescriptorById(mDevice, handle);
+                    if (descriptor == null) return;
+
+                    if ((status == GATT_INSUFFICIENT_AUTHENTICATION
+                            || status == GATT_INSUFFICIENT_ENCRYPTION)
+                            && (mAuthRetryState != AUTH_RETRY_STATE_MITM)) {
+                        try {
+                            final int authReq = (mAuthRetryState == AUTH_RETRY_STATE_IDLE) ?
+                                    AUTHENTICATION_NO_MITM : AUTHENTICATION_MITM;
+                            mService.writeDescriptor(mClientIf, address, handle,
+                                    authReq, descriptor.getValue());
+                            mAuthRetryState++;
+                            return;
+                        } catch (RemoteException e) {
+                            Log.e(TAG, "", e);
                         }
                     }
-                });
-            }
 
-            /**
-             * Callback invoked when the given connection is updated
-             * @hide
-             */
-            @Override
-            public void onConnectionUpdated(String address, int interval, int latency,
-                                            int timeout, int status) {
-                if (DBG) Log.d(TAG, "onConnectionUpdated() - Device=" + address +
-                            " interval=" + interval + " latency=" + latency +
-                            " timeout=" + timeout + " status=" + status);
-                if (!address.equals(mDevice.getAddress())) {
-                    return;
+                    mAuthRetryState = AUTH_RETRY_STATE_IDLE;
+
+                    runOrQueueCallback(new Runnable() {
+                        @Override
+                        public void run() {
+                            if (mCallback != null) {
+                                mCallback.onDescriptorWrite(BluetoothGatt.this, descriptor, status);
+                            }
+                        }
+                    });
                 }
 
-                runOrQueueCallback(new Runnable() {
-                    @Override
-                    public void run() {
-                        if (mCallback != null) {
-                            mCallback.onConnectionUpdated(BluetoothGatt.this, interval, latency,
-                                                          timeout, status);
-                        }
+                /**
+                 * Prepared write transaction completed (or aborted)
+                 * @hide
+                 */
+                @Override
+                public void onExecuteWrite(String address, int status) {
+                    if (VDBG) {
+                        Log.d(TAG, "onExecuteWrite() - Device=" + address
+                                + " status=" + status);
                     }
-                });
-            }
-        };
+                    if (!address.equals(mDevice.getAddress())) {
+                        return;
+                    }
+
+                    synchronized (mDeviceBusy) {
+                        mDeviceBusy = false;
+                    }
+
+                    runOrQueueCallback(new Runnable() {
+                        @Override
+                        public void run() {
+                            if (mCallback != null) {
+                                mCallback.onReliableWriteCompleted(BluetoothGatt.this, status);
+                            }
+                        }
+                    });
+                }
+
+                /**
+                 * Remote device RSSI has been read
+                 * @hide
+                 */
+                @Override
+                public void onReadRemoteRssi(String address, int rssi, int status) {
+                    if (VDBG) {
+                        Log.d(TAG, "onReadRemoteRssi() - Device=" + address +
+                                " rssi=" + rssi + " status=" + status);
+                    }
+                    if (!address.equals(mDevice.getAddress())) {
+                        return;
+                    }
+                    runOrQueueCallback(new Runnable() {
+                        @Override
+                        public void run() {
+                            if (mCallback != null) {
+                                mCallback.onReadRemoteRssi(BluetoothGatt.this, rssi, status);
+                            }
+                        }
+                    });
+                }
+
+                /**
+                 * Callback invoked when the MTU for a given connection changes
+                 * @hide
+                 */
+                @Override
+                public void onConfigureMTU(String address, int mtu, int status) {
+                    if (DBG) {
+                        Log.d(TAG, "onConfigureMTU() - Device=" + address +
+                                " mtu=" + mtu + " status=" + status);
+                    }
+                    if (!address.equals(mDevice.getAddress())) {
+                        return;
+                    }
+
+                    runOrQueueCallback(new Runnable() {
+                        @Override
+                        public void run() {
+                            if (mCallback != null) {
+                                mCallback.onMtuChanged(BluetoothGatt.this, mtu, status);
+                            }
+                        }
+                    });
+                }
+
+                /**
+                 * Callback invoked when the given connection is updated
+                 * @hide
+                 */
+                @Override
+                public void onConnectionUpdated(String address, int interval, int latency,
+                        int timeout, int status) {
+                    if (DBG) {
+                        Log.d(TAG, "onConnectionUpdated() - Device=" + address +
+                                " interval=" + interval + " latency=" + latency +
+                                " timeout=" + timeout + " status=" + status);
+                    }
+                    if (!address.equals(mDevice.getAddress())) {
+                        return;
+                    }
+
+                    runOrQueueCallback(new Runnable() {
+                        @Override
+                        public void run() {
+                            if (mCallback != null) {
+                                mCallback.onConnectionUpdated(BluetoothGatt.this, interval, latency,
+                                        timeout, status);
+                            }
+                        }
+                    });
+                }
+            };
 
     /*package*/ BluetoothGatt(IBluetoothGatt iGatt, BluetoothDevice device,
-                                int transport, boolean opportunistic, int phy) {
+            int transport, boolean opportunistic, int phy) {
         mService = iGatt;
         mDevice = device;
         mTransport = transport;
@@ -657,15 +698,16 @@
 
     /**
      * Returns a service by UUID, instance and type.
+     *
      * @hide
      */
     /*package*/ BluetoothGattService getService(BluetoothDevice device, UUID uuid,
-                                                int instanceId, int type) {
-        for(BluetoothGattService svc : mServices) {
+            int instanceId, int type) {
+        for (BluetoothGattService svc : mServices) {
             if (svc.getDevice().equals(device) &&
-                svc.getType() == type &&
-                svc.getInstanceId() == instanceId &&
-                svc.getUuid().equals(uuid)) {
+                    svc.getType() == type &&
+                    svc.getInstanceId() == instanceId &&
+                    svc.getUuid().equals(uuid)) {
                 return svc;
             }
         }
@@ -675,13 +717,16 @@
 
     /**
      * Returns a characteristic with id equal to instanceId.
+     *
      * @hide
      */
-    /*package*/ BluetoothGattCharacteristic getCharacteristicById(BluetoothDevice device, int instanceId) {
-        for(BluetoothGattService svc : mServices) {
-            for(BluetoothGattCharacteristic charac : svc.getCharacteristics()) {
-                if (charac.getInstanceId() == instanceId)
+    /*package*/ BluetoothGattCharacteristic getCharacteristicById(BluetoothDevice device,
+            int instanceId) {
+        for (BluetoothGattService svc : mServices) {
+            for (BluetoothGattCharacteristic charac : svc.getCharacteristics()) {
+                if (charac.getInstanceId() == instanceId) {
                     return charac;
+                }
             }
         }
         return null;
@@ -689,14 +734,16 @@
 
     /**
      * Returns a descriptor with id equal to instanceId.
+     *
      * @hide
      */
     /*package*/ BluetoothGattDescriptor getDescriptorById(BluetoothDevice device, int instanceId) {
-        for(BluetoothGattService svc : mServices) {
-            for(BluetoothGattCharacteristic charac : svc.getCharacteristics()) {
-                for(BluetoothGattDescriptor desc : charac.getDescriptors()) {
-                    if (desc.getInstanceId() == instanceId)
+        for (BluetoothGattService svc : mServices) {
+            for (BluetoothGattCharacteristic charac : svc.getCharacteristics()) {
+                for (BluetoothGattDescriptor desc : charac.getDescriptors()) {
+                    if (desc.getInstanceId() == instanceId) {
                         return desc;
+                    }
                 }
             }
         }
@@ -709,13 +756,13 @@
      */
     private void runOrQueueCallback(final Runnable cb) {
         if (mHandler == null) {
-          try {
-            cb.run();
-          } catch (Exception ex) {
-            Log.w(TAG, "Unhandled exception in callback", ex);
-          }
+            try {
+                cb.run();
+            } catch (Exception ex) {
+                Log.w(TAG, "Unhandled exception in callback", ex);
+            }
         } else {
-          mHandler.post(cb);
+            mHandler.post(cb);
         }
     }
 
@@ -728,8 +775,8 @@
      * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
      *
      * @param callback GATT callback handler that will receive asynchronous callbacks.
-     * @return If true, the callback will be called to notify success or failure,
-     *         false on immediate error
+     * @return If true, the callback will be called to notify success or failure, false on immediate
+     * error
      */
     private boolean registerApp(BluetoothGattCallback callback, Handler handler) {
         if (DBG) Log.d(TAG, "registerApp()");
@@ -743,7 +790,7 @@
         try {
             mService.registerClient(new ParcelUuid(uuid), mBluetoothGattCallback);
         } catch (RemoteException e) {
-            Log.e(TAG,"",e);
+            Log.e(TAG, "", e);
             return false;
         }
 
@@ -762,7 +809,7 @@
             mService.unregisterClient(mClientIf);
             mClientIf = 0;
         } catch (RemoteException e) {
-            Log.e(TAG,"",e);
+            Log.e(TAG, "", e);
         }
     }
 
@@ -784,15 +831,17 @@
      * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
      *
      * @param device Remote device to connect to
-     * @param autoConnect Whether to directly connect to the remote device (false)
-     *                    or to automatically connect as soon as the remote
-     *                    device becomes available (true).
+     * @param autoConnect Whether to directly connect to the remote device (false) or to
+     * automatically connect as soon as the remote device becomes available (true).
      * @return true, if the connection attempt was initiated successfully
      */
     /*package*/ boolean connect(Boolean autoConnect, BluetoothGattCallback callback,
-                                Handler handler) {
-        if (DBG) Log.d(TAG, "connect() - device: " + mDevice.getAddress() + ", auto: " + autoConnect);
-        synchronized(mStateLock) {
+            Handler handler) {
+        if (DBG) {
+            Log.d(TAG,
+                    "connect() - device: " + mDevice.getAddress() + ", auto: " + autoConnect);
+        }
+        synchronized (mStateLock) {
             if (mConnState != CONN_STATE_IDLE) {
                 throw new IllegalStateException("Not idle");
             }
@@ -802,7 +851,7 @@
         mAutoConnect = autoConnect;
 
         if (!registerApp(callback, handler)) {
-            synchronized(mStateLock) {
+            synchronized (mStateLock) {
                 mConnState = CONN_STATE_IDLE;
             }
             Log.e(TAG, "Failed to register callback");
@@ -826,7 +875,7 @@
         try {
             mService.clientDisconnect(mClientIf, mDevice.getAddress());
         } catch (RemoteException e) {
-            Log.e(TAG,"",e);
+            Log.e(TAG, "", e);
         }
     }
 
@@ -845,7 +894,7 @@
                     mOpportunistic, mPhy); // autoConnect is inverse of "isDirect"
             return true;
         } catch (RemoteException e) {
-            Log.e(TAG,"",e);
+            Log.e(TAG, "", e);
             return false;
         }
     }
@@ -858,22 +907,22 @@
      * {@link BluetoothGattCallback#onPhyUpdate} will be triggered as a result of this call, even
      * if no PHY change happens. It is also triggered when remote device updates the PHY.
      *
-     * @param txPhy preferred transmitter PHY. Bitwise OR of any of
-     *             {@link BluetoothDevice#PHY_LE_1M_MASK}, {@link BluetoothDevice#PHY_LE_2M_MASK},
-     *             and {@link BluetoothDevice#PHY_LE_CODED_MASK}.
-     * @param rxPhy preferred receiver PHY. Bitwise OR of any of
-     *             {@link BluetoothDevice#PHY_LE_1M_MASK}, {@link BluetoothDevice#PHY_LE_2M_MASK},
-     *             and {@link BluetoothDevice#PHY_LE_CODED_MASK}.
+     * @param txPhy preferred transmitter PHY. Bitwise OR of any of {@link
+     * BluetoothDevice#PHY_LE_1M_MASK}, {@link BluetoothDevice#PHY_LE_2M_MASK}, and {@link
+     * BluetoothDevice#PHY_LE_CODED_MASK}.
+     * @param rxPhy preferred receiver PHY. Bitwise OR of any of {@link
+     * BluetoothDevice#PHY_LE_1M_MASK}, {@link BluetoothDevice#PHY_LE_2M_MASK}, and {@link
+     * BluetoothDevice#PHY_LE_CODED_MASK}.
      * @param phyOptions preferred coding to use when transmitting on the LE Coded PHY. Can be one
-     *             of {@link BluetoothDevice#PHY_OPTION_NO_PREFERRED},
-     *             {@link BluetoothDevice#PHY_OPTION_S2} or {@link BluetoothDevice#PHY_OPTION_S8}
+     * of {@link BluetoothDevice#PHY_OPTION_NO_PREFERRED}, {@link BluetoothDevice#PHY_OPTION_S2} or
+     * {@link BluetoothDevice#PHY_OPTION_S8}
      */
     public void setPreferredPhy(int txPhy, int rxPhy, int phyOptions) {
         try {
             mService.clientSetPreferredPhy(mClientIf, mDevice.getAddress(), txPhy, rxPhy,
-                                           phyOptions);
+                    phyOptions);
         } catch (RemoteException e) {
-            Log.e(TAG,"",e);
+            Log.e(TAG, "", e);
         }
     }
 
@@ -885,7 +934,7 @@
         try {
             mService.clientReadPhy(mClientIf, mDevice.getAddress());
         } catch (RemoteException e) {
-            Log.e(TAG,"",e);
+            Log.e(TAG, "", e);
         }
     }
 
@@ -920,7 +969,7 @@
         try {
             mService.discoverServices(mClientIf, mDevice.getAddress());
         } catch (RemoteException e) {
-            Log.e(TAG,"",e);
+            Log.e(TAG, "", e);
             return false;
         }
 
@@ -960,8 +1009,8 @@
      *
      * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
      *
-     * @return List of services on the remote device. Returns an empty list
-     *         if service discovery has not yet been performed.
+     * @return List of services on the remote device. Returns an empty list if service discovery has
+     * not yet been performed.
      */
     public List<BluetoothGattService> getServices() {
         List<BluetoothGattService> result =
@@ -989,13 +1038,13 @@
      * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
      *
      * @param uuid UUID of the requested service
-     * @return BluetoothGattService if supported, or null if the requested
-     *         service is not offered by the remote device.
+     * @return BluetoothGattService if supported, or null if the requested service is not offered by
+     * the remote device.
      */
     public BluetoothGattService getService(UUID uuid) {
         for (BluetoothGattService service : mServices) {
             if (service.getDevice().equals(mDevice) &&
-                service.getUuid().equals(uuid)) {
+                    service.getUuid().equals(uuid)) {
                 return service;
             }
         }
@@ -1017,7 +1066,9 @@
      */
     public boolean readCharacteristic(BluetoothGattCharacteristic characteristic) {
         if ((characteristic.getProperties() &
-                BluetoothGattCharacteristic.PROPERTY_READ) == 0) return false;
+                BluetoothGattCharacteristic.PROPERTY_READ) == 0) {
+            return false;
+        }
 
         if (VDBG) Log.d(TAG, "readCharacteristic() - uuid: " + characteristic.getUuid());
         if (mService == null || mClientIf == 0) return false;
@@ -1028,16 +1079,16 @@
         BluetoothDevice device = service.getDevice();
         if (device == null) return false;
 
-        synchronized(mDeviceBusy) {
+        synchronized (mDeviceBusy) {
             if (mDeviceBusy) return false;
             mDeviceBusy = true;
         }
 
         try {
             mService.readCharacteristic(mClientIf, device.getAddress(),
-                characteristic.getInstanceId(), AUTHENTICATION_NONE);
+                    characteristic.getInstanceId(), AUTHENTICATION_NONE);
         } catch (RemoteException e) {
-            Log.e(TAG,"",e);
+            Log.e(TAG, "", e);
             mDeviceBusy = false;
             return false;
         }
@@ -1062,16 +1113,16 @@
         if (VDBG) Log.d(TAG, "readUsingCharacteristicUuid() - uuid: " + uuid);
         if (mService == null || mClientIf == 0) return false;
 
-        synchronized(mDeviceBusy) {
+        synchronized (mDeviceBusy) {
             if (mDeviceBusy) return false;
             mDeviceBusy = true;
         }
 
         try {
             mService.readUsingCharacteristicUuid(mClientIf, mDevice.getAddress(),
-                new ParcelUuid(uuid), startHandle, endHandle, AUTHENTICATION_NONE);
+                    new ParcelUuid(uuid), startHandle, endHandle, AUTHENTICATION_NONE);
         } catch (RemoteException e) {
-            Log.e(TAG,"",e);
+            Log.e(TAG, "", e);
             mDeviceBusy = false;
             return false;
         }
@@ -1094,8 +1145,10 @@
      */
     public boolean writeCharacteristic(BluetoothGattCharacteristic characteristic) {
         if ((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_WRITE) == 0
-            && (characteristic.getProperties() &
-                BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) == 0) return false;
+                && (characteristic.getProperties() &
+                BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) == 0) {
+            return false;
+        }
 
         if (VDBG) Log.d(TAG, "writeCharacteristic() - uuid: " + characteristic.getUuid());
         if (mService == null || mClientIf == 0 || characteristic.getValue() == null) return false;
@@ -1106,17 +1159,17 @@
         BluetoothDevice device = service.getDevice();
         if (device == null) return false;
 
-        synchronized(mDeviceBusy) {
+        synchronized (mDeviceBusy) {
             if (mDeviceBusy) return false;
             mDeviceBusy = true;
         }
 
         try {
             mService.writeCharacteristic(mClientIf, device.getAddress(),
-                characteristic.getInstanceId(), characteristic.getWriteType(),
-                AUTHENTICATION_NONE, characteristic.getValue());
+                    characteristic.getInstanceId(), characteristic.getWriteType(),
+                    AUTHENTICATION_NONE, characteristic.getValue());
         } catch (RemoteException e) {
-            Log.e(TAG,"",e);
+            Log.e(TAG, "", e);
             mDeviceBusy = false;
             return false;
         }
@@ -1149,16 +1202,16 @@
         BluetoothDevice device = service.getDevice();
         if (device == null) return false;
 
-        synchronized(mDeviceBusy) {
+        synchronized (mDeviceBusy) {
             if (mDeviceBusy) return false;
             mDeviceBusy = true;
         }
 
         try {
             mService.readDescriptor(mClientIf, device.getAddress(),
-                descriptor.getInstanceId(), AUTHENTICATION_NONE);
+                    descriptor.getInstanceId(), AUTHENTICATION_NONE);
         } catch (RemoteException e) {
-            Log.e(TAG,"",e);
+            Log.e(TAG, "", e);
             mDeviceBusy = false;
             return false;
         }
@@ -1190,16 +1243,16 @@
         BluetoothDevice device = service.getDevice();
         if (device == null) return false;
 
-        synchronized(mDeviceBusy) {
+        synchronized (mDeviceBusy) {
             if (mDeviceBusy) return false;
             mDeviceBusy = true;
         }
 
         try {
             mService.writeDescriptor(mClientIf, device.getAddress(), descriptor.getInstanceId(),
-                AUTHENTICATION_NONE, descriptor.getValue());
+                    AUTHENTICATION_NONE, descriptor.getValue());
         } catch (RemoteException e) {
-            Log.e(TAG,"",e);
+            Log.e(TAG, "", e);
             mDeviceBusy = false;
             return false;
         }
@@ -1234,7 +1287,7 @@
         try {
             mService.beginReliableWrite(mClientIf, mDevice.getAddress());
         } catch (RemoteException e) {
-            Log.e(TAG,"",e);
+            Log.e(TAG, "", e);
             return false;
         }
 
@@ -1258,7 +1311,7 @@
         if (VDBG) Log.d(TAG, "executeReliableWrite() - device: " + mDevice.getAddress());
         if (mService == null || mClientIf == 0) return false;
 
-        synchronized(mDeviceBusy) {
+        synchronized (mDeviceBusy) {
             if (mDeviceBusy) return false;
             mDeviceBusy = true;
         }
@@ -1266,7 +1319,7 @@
         try {
             mService.endReliableWrite(mClientIf, mDevice.getAddress(), true);
         } catch (RemoteException e) {
-            Log.e(TAG,"",e);
+            Log.e(TAG, "", e);
             mDeviceBusy = false;
             return false;
         }
@@ -1289,7 +1342,7 @@
         try {
             mService.endReliableWrite(mClientIf, mDevice.getAddress(), false);
         } catch (RemoteException e) {
-            Log.e(TAG,"",e);
+            Log.e(TAG, "", e);
         }
     }
 
@@ -1316,9 +1369,11 @@
      * @return true, if the requested notification status was set successfully
      */
     public boolean setCharacteristicNotification(BluetoothGattCharacteristic characteristic,
-                                              boolean enable) {
-        if (DBG) Log.d(TAG, "setCharacteristicNotification() - uuid: " + characteristic.getUuid()
-                         + " enable: " + enable);
+            boolean enable) {
+        if (DBG) {
+            Log.d(TAG, "setCharacteristicNotification() - uuid: " + characteristic.getUuid()
+                    + " enable: " + enable);
+        }
         if (mService == null || mClientIf == 0) return false;
 
         BluetoothGattService service = characteristic.getService();
@@ -1329,9 +1384,9 @@
 
         try {
             mService.registerForNotification(mClientIf, device.getAddress(),
-                characteristic.getInstanceId(), enable);
+                    characteristic.getInstanceId(), enable);
         } catch (RemoteException e) {
-            Log.e(TAG,"",e);
+            Log.e(TAG, "", e);
             return false;
         }
 
@@ -1341,6 +1396,7 @@
     /**
      * Clears the internal cache and forces a refresh of the services from the
      * remote device.
+     *
      * @hide
      */
     public boolean refresh() {
@@ -1350,7 +1406,7 @@
         try {
             mService.refreshDevice(mClientIf, mDevice.getAddress());
         } catch (RemoteException e) {
-            Log.e(TAG,"",e);
+            Log.e(TAG, "", e);
             return false;
         }
 
@@ -1374,7 +1430,7 @@
         try {
             mService.readRemoteRssi(mClientIf, mDevice.getAddress());
         } catch (RemoteException e) {
-            Log.e(TAG,"",e);
+            Log.e(TAG, "", e);
             return false;
         }
 
@@ -1396,14 +1452,16 @@
      * @return true, if the new MTU value has been requested successfully
      */
     public boolean requestMtu(int mtu) {
-        if (DBG) Log.d(TAG, "configureMTU() - device: " + mDevice.getAddress()
-                            + " mtu: " + mtu);
+        if (DBG) {
+            Log.d(TAG, "configureMTU() - device: " + mDevice.getAddress()
+                    + " mtu: " + mtu);
+        }
         if (mService == null || mClientIf == 0) return false;
 
         try {
             mService.configureMTU(mClientIf, mDevice.getAddress(), mtu);
         } catch (RemoteException e) {
-            Log.e(TAG,"",e);
+            Log.e(TAG, "", e);
             return false;
         }
 
@@ -1416,16 +1474,14 @@
      * <p>This function will send a connection parameter update request to the
      * remote device.
      *
-     * @param connectionPriority Request a specific connection priority. Must be one of
-     *          {@link BluetoothGatt#CONNECTION_PRIORITY_BALANCED},
-     *          {@link BluetoothGatt#CONNECTION_PRIORITY_HIGH}
-     *          or {@link BluetoothGatt#CONNECTION_PRIORITY_LOW_POWER}.
-     * @throws IllegalArgumentException If the parameters are outside of their
-     *                                  specified range.
+     * @param connectionPriority Request a specific connection priority. Must be one of {@link
+     * BluetoothGatt#CONNECTION_PRIORITY_BALANCED}, {@link BluetoothGatt#CONNECTION_PRIORITY_HIGH}
+     * or {@link BluetoothGatt#CONNECTION_PRIORITY_LOW_POWER}.
+     * @throws IllegalArgumentException If the parameters are outside of their specified range.
      */
     public boolean requestConnectionPriority(int connectionPriority) {
         if (connectionPriority < CONNECTION_PRIORITY_BALANCED ||
-            connectionPriority > CONNECTION_PRIORITY_LOW_POWER) {
+                connectionPriority > CONNECTION_PRIORITY_LOW_POWER) {
             throw new IllegalArgumentException("connectionPriority not within valid range");
         }
 
@@ -1435,7 +1491,7 @@
         try {
             mService.connectionParameterUpdate(mClientIf, mDevice.getAddress(), connectionPriority);
         } catch (RemoteException e) {
-            Log.e(TAG,"",e);
+            Log.e(TAG, "", e);
             return false;
         }
 
@@ -1462,7 +1518,7 @@
     @Override
     public List<BluetoothDevice> getConnectedDevices() {
         throw new UnsupportedOperationException
-            ("Use BluetoothManager#getConnectedDevices instead.");
+                ("Use BluetoothManager#getConnectedDevices instead.");
     }
 
     /**
@@ -1475,6 +1531,6 @@
     @Override
     public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
         throw new UnsupportedOperationException
-            ("Use BluetoothManager#getDevicesMatchingConnectionStates instead.");
+                ("Use BluetoothManager#getDevicesMatchingConnectionStates instead.");
     }
 }