Exemplo n.º 1
0
 public void click(View view) throws IOException {
   if (_service == null || !_service.isStarted()) {
     // Ensure device is rooted if SU is activated
     if (!checkRoot()) {
       // Display error dialog
       AlertDialog.Builder builder = new AlertDialog.Builder(this);
       builder
           .setMessage(R.string.no_su_error)
           .setCancelable(false)
           .setNegativeButton(
               android.R.string.cancel,
               new DialogInterface.OnClickListener() {
                 public void onClick(DialogInterface dialog, int id) {
                   dialog.dismiss();
                 }
               });
       AlertDialog alert = builder.create();
       alert.show();
     } else {
       // Start tincd service
       Intent intent = new Intent(this, TincdService.class);
       startService(intent);
     }
   } else {
     Log.d(Tools.TAG, "Requesting stop");
     _service.stopTincd();
   }
 }
Exemplo n.º 2
0
  private void updateLog(String iData) {
    if (_service != null) {
      List<String> aTempOut = _service.popOutput();
      if (aTempOut != null) {
        Log.d(Tools.TAG, "Popping temporary logs (" + aTempOut.size() + " lines)");
        _logTextView.append(Tools.ToString(aTempOut));
      }
    }
    if (iData != null) _logTextView.append(iData + "\n");

    // Limit log size (allow 10% to avoid doing it on each iteration)
    if (_service != null && _logTextView.getLineCount() > 1.1 * _service._maxLogSize) {
      int excessLineNumber = _logTextView.getLineCount() - _service._maxLogSize;
      Log.d(Tools.TAG, "Truncating logs (deleting " + excessLineNumber + " lines)");
      int eolIndex = -1;
      CharSequence charSequence = _logTextView.getText();
      for (int i = 0; i < excessLineNumber; i++) {
        do {
          eolIndex++;
        } while (eolIndex < charSequence.length() && charSequence.charAt(eolIndex) != '\n');
      }
      if (eolIndex < charSequence.length()) {
        _logTextView.getEditableText().delete(0, eolIndex + 1);
      } else {
        _logTextView.setText("");
      }
    }
  }
Exemplo n.º 3
0
 @Override
 protected void onResume() {
   super.onResume();
   if (_service != null) {
     // Set activity as service callback
     _service._callback = this;
   }
 }
Exemplo n.º 4
0
 @Override
 protected void onPause() {
   super.onPause();
   if (_service != null) {
     // Unset service callback
     _service._callback = null;
   }
 }
Exemplo n.º 5
0
 // @Override
 public void onServiceConnected(ComponentName className, IBinder service) {
   // We've bound to LocalService, cast the IBinder and get LocalService instance
   LocalBinder binder = (LocalBinder) service;
   _service = binder.getService();
   Log.d(Tools.TAG, "Service connected");
   _service._callback = TincActivity.this;
   updateLog(null);
   updateStatus();
 }
Exemplo n.º 6
0
 @Override
 protected void onStop() {
   super.onStop();
   // Unbind from the service
   if (_service != null) {
     unbindService(_connection);
     _service._callback = null;
   }
 }
Exemplo n.º 7
0
 private void updateStatus() {
   if (_service != null && _service.isStarted()) {
     _txtView.setText("Started");
     _startStopButton.setText(getText(R.string.stop));
     _debugButton.setEnabled(true);
   } else {
     _txtView.setText("Stopped");
     _startStopButton.setText(getText(R.string.start));
     _debugButton.setEnabled(false);
   }
   if (_service != null) _debugButton.setChecked(_service._debug);
   else _debugButton.setChecked(false);
 }
Exemplo n.º 8
0
 public void clickStatus(View iView) {
   if (_service != null) _logTextView.append(_service.getStatus() + "\n");
 }
Exemplo n.º 9
0
 public void debugClick(View view) throws IOException {
   if (_service != null) {
     _service.toggleDebug();
   }
 }