@Override
 public void onUpdateDevice(StateDevice stateDevice) {
   if (stateDevice.getType() == StateDeviceProtos.StateDeviceMessage.Type.DOORBELL) {
     // If the state is set to inactive by the client
     Log.i(TAG, "Device updated");
     if (stateDevice.getState() == StateDeviceProtos.StateDeviceMessage.State.INACTIVE) {
       StateDeviceProtos.StateDeviceMessage msg =
           StateDeviceProtos.StateDeviceMessage.newBuilder()
               .setId(stateDevice.getId())
               .setName(stateDevice.getName())
               .setState(stateDevice.getState())
               .setType(stateDevice.getType())
               .build();
       // Send the message
       try {
         Log.i(TAG, "Sending message: \n" + msg.toString());
         OutputStream out = Client.getConnection().getOutputStream();
         msg.writeDelimitedTo(out);
       } catch (IOException e) {
         Client.removeConnection();
         Log.e(TAG, "unable to write to output stream", e);
       }
     }
   }
 }
 /** Called to deactivate the plugin */
 public void deactivate() {
   if (mNetworkHandler != null) {
     Client.removeNetworkHandler(mNetworkHandler);
     mNetworkHandler = null;
   }
   if (mStateHandler != null) {
     StateDeviceManager.removeDeviceHandler(mStateHandler);
     mStateHandler = null;
   }
 }
 /** Called to activate the plugin */
 public void activate() {
   // add the network handler to the client
   if (mNetworkHandler == null) {
     mNetworkHandler = new DoorbellNetworkHandler();
     Client.addNetworkHandler(mNetworkHandler);
   }
   // add the state handler to the device manager
   if (mStateHandler == null) {
     mStateHandler = new DoorbellStateHandler();
     StateDeviceManager.addDeviceHandler(mStateHandler);
   }
 }