Exemplo n.º 1
0
  /**
   * Android Service destroy
   *
   * @see android.app.Service#onDestroy()
   */
  public void onDestroy() {
    try {
      if (wakeLock != null) {
        wakeLock.release();
        wakeLock = null;
      }

      if (server != null) {
        new JettyStopperThread(_handler).start();

      } else {
        Log.i("Jetty", "Jetty not running");
        IJettyToast.showServiceToast(IJettyService.this, R.string.jetty_not_running);
      }
    } catch (Exception e) {
      Log.e("Jetty", "Error stopping jetty", e);
      IJettyToast.showServiceToast(IJettyService.this, R.string.jetty_not_stopped);
    }
  }
Exemplo n.º 2
0
  /**
   * Android Service Start
   *
   * @see android.app.Service#onStart(android.content.Intent, int)
   */
  public void onStart(Intent intent, int startId) {
    if (server != null) {
      IJettyToast.showServiceToast(IJettyService.this, R.string.jetty_already_started);
      return;
    }

    try {
      preferences = PreferenceManager.getDefaultSharedPreferences(this);

      String portDefault = getText(R.string.pref_port_value).toString();
      String sslPortDefault = getText(R.string.pref_ssl_port_value).toString();
      String pwdDefault = getText(R.string.pref_console_pwd_value).toString();

      String nioEnabledDefault = getText(R.string.pref_nio_value).toString();
      String sslEnabledDefault = getText(R.string.pref_ssl_value).toString();

      String portKey = getText(R.string.pref_port_key).toString();
      String sslPortKey = getText(R.string.pref_ssl_port_key).toString();
      String pwdKey = getText(R.string.pref_console_pwd_key).toString();
      String nioKey = getText(R.string.pref_nio_key).toString();
      String sslKey = getText(R.string.pref_ssl_key).toString();

      _useSSL = preferences.getBoolean(sslKey, Boolean.valueOf(sslEnabledDefault));
      _useNIO = preferences.getBoolean(nioKey, Boolean.valueOf(nioEnabledDefault));
      _port = Integer.parseInt(preferences.getString(portKey, portDefault));
      if (_useSSL) {
        _sslPort = Integer.parseInt(preferences.getString(sslPortKey, sslPortDefault));
        String defaultValue = getText(R.string.pref_keystore_pwd_value).toString();
        String key = getText(R.string.pref_keystore_pwd_key).toString();
        _keystorePassword = preferences.getString(key, defaultValue);

        defaultValue = getText(R.string.pref_keymgr_pwd_value).toString();
        key = getText(R.string.pref_keymgr_pwd_key).toString();
        _keymgrPassword = preferences.getString(key, defaultValue);

        defaultValue = getText(R.string.pref_truststore_pwd_value).toString();
        key = getText(R.string.pref_truststore_pwd_key).toString();
        _truststorePassword = preferences.getString(key, defaultValue);

        defaultValue = getText(R.string.pref_keystore_file).toString();
        key = getText(R.string.pref_keystore_file_key).toString();
        _keystoreFile = preferences.getString(key, defaultValue);

        defaultValue = getText(R.string.pref_truststore_file).toString();
        key = getText(R.string.pref_truststore_file_key).toString();
        _truststoreFile = preferences.getString(key, defaultValue);
      }

      _consolePassword = preferences.getString(pwdKey, pwdDefault);

      Log.d("Jetty", "pref port = " + _port);
      Log.d("Jetty", "pref use nio = " + _useNIO);
      Log.d("Jetty", "pref use ssl = " + _useSSL);
      Log.d("Jetty", "pref ssl port = " + _sslPort);

      // Get a wake lock to stop the cpu going to sleep
      PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
      wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "IJetty");
      wakeLock.acquire();

      new JettyStarterThread(_handler).start();

      super.onStart(intent, startId);
    } catch (Exception e) {
      Log.e("Jetty", "Error starting jetty", e);
      IJettyToast.showServiceToast(IJettyService.this, R.string.jetty_not_started);
    }
  }