 +                             address);
 +  }.bind(this));
 +
++  if (!this.subscriptions.size) {
++    this.bindings.on('disconnect', this._unsubscribeBound);
++  }
 +  this.subscriptions.set(address, newValue);
 +  callback(Characteristic.RESULT_SUCCESS);
 +};
 +
 +CCCDescriptor.prototype.unsubscribe = function(address) {
++  if (!this.subscriptions.has(address)) {
++    log.debug('not subscribed to', address);
++    return;
++  }
 +  log.debug('unsubscribe', address);
-+
-+  if (!this.subscriptions.has(address)) {
-+    return;
-+  }
 +
 +  process.nextTick(function() {
 +    this.characteristic.emit('unsubscribe', address);
 +  }.bind(this));
 +
 +  this.subscriptions.delete(address);
++  if (!this.subscriptions.size) {
++    log.debug('No more subscriptions, removing disconnect listener');
++    this.bindings.removeListener('disconnect', this._unsubscribeBound);
++  }
 +};
 +
 +module.exports = CCCDescriptor;

From 06bdad4d5d33e4f3f1309393675923c4945e0cff Mon Sep 17 00:00:00 2001
From: Ben Turner <bent@silklabs.com>
Date: Thu, 16 Jun 2016 14:29:54 -0700
Subject: [PATCH] Android Bluedroid bindings

+  this.on('readRequest', this.onReadRequest.bind(this));
+  this.on('writeRequest', this.onWriteRequest.bind(this));
+
+  this._unsubscribeBound = this.unsubscribe.bind(this);
+}
+
+util.inherits(CCCDescriptor, events.EventEmitter);
