public void start() {
    synchronized (this) {
      if (!preferences.isCommandEnabled()) {
        Log.w(NotifierConstants.LOG_TAG, "Commands disabled, not starting");
        return;
      }

      // Ensure the CPU keeps running while we listen for connections
      if (wakeLock == null) {
        PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, COMMANDS_LOCK_TAG);
        wakeLock.acquire();
      }

      if (preferences.isBluetoothCommandEnabled()) {
        startBluetoothListener();
      }

      if (preferences.isIpCommandEnabled()) {
        startIpListener();
      }

      if (preferences.isUsbCommandEnabled()) {
        startUsbListener();
      }

      startDiscoveryListener();

      preferences.registerOnSharedPreferenceChangeListener(this);
    }
  }
 @Override
 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
   synchronized (this) {
     if (key.equals(context.getString(R.string.command_bluetooth_key))) {
       if (preferences.isBluetoothCommandEnabled()) {
         startBluetoothListener();
       } else {
         shutdownBluetoothListener();
       }
     } else if (key.equals(context.getString(R.string.command_wifi_key))) {
       if (preferences.isIpCommandEnabled()) {
         startIpListener();
       } else {
         shutdownIpListener();
       }
     } else if (key.equals(context.getString(R.string.command_usb_key))) {
       if (preferences.isUsbCommandEnabled()) {
         startUsbListener();
       } else {
         shutdownUsbListener();
       }
     }
   }
 }