Esempio n. 1
0
 public void setColorModel(COLORMODEL cm) {
   decoder.setColorModel(cm);
 }
Esempio n. 2
0
  /**
   * Create a view showing a VNC connection
   *
   * @param context Containing context (activity)
   * @param bean Connection settings
   * @param setModes Callback to run on UI thread after connection is set up
   */
  void initializeVncCanvas(ConnectionBean bean, VncDatabase db, final Runnable setModes) {

    this.setModes = setModes;
    connection = bean;
    database = db;
    decoder.setColorModel(COLORMODEL.valueOf(bean.getColorModel()));

    // Startup the RFB thread with a nifty progress dialog
    final ProgressDialog pd =
        ProgressDialog.show(
            getContext(),
            "Connecting...",
            "Establishing handshake.\nPlease wait...",
            true,
            true,
            new DialogInterface.OnCancelListener() {
              @Override
              public void onCancel(DialogInterface dialog) {
                closeConnection();
                handler.post(
                    new Runnable() {
                      public void run() {
                        Utils.showFatalErrorMessage(getContext(), "VNC connection aborted!");
                      }
                    });
              }
            });

    // Make this dialog cancellable only upon hitting the Back button and not touching outside.
    pd.setCanceledOnTouchOutside(false);

    final Display display = pd.getWindow().getWindowManager().getDefaultDisplay();
    displayWidth = display.getWidth();
    displayHeight = display.getHeight();
    Thread t =
        new Thread() {
          public void run() {
            try {
              if (connection.getConnectionType() < 4) {
                connectAndAuthenticate(connection.getUserName(), connection.getPassword());
                rfbconn = rfb;
                pointer = new RemotePointer(rfbconn, VncCanvas.this, handler);
                keyboard = new RemoteKeyboard(rfbconn, VncCanvas.this, handler);
                doProtocolInitialisation(displayWidth, displayHeight);
                handler.post(
                    new Runnable() {
                      public void run() {
                        pd.setMessage("Downloading first frame.\nPlease wait...");
                      }
                    });
                sendUnixAuth();
                if (connection.getUseLocalCursor()) initializeSoftCursor();
                processNormalProtocol(getContext(), pd, setModes);
              } else {
                cc = new CConn(VncCanvas.this, sock, null, false, connection);
                rfbconn = cc;
                pointer = new RemotePointer(rfbconn, VncCanvas.this, handler);
                keyboard = new RemoteKeyboard(rfbconn, VncCanvas.this, handler);
                initializeBitmap(displayWidth, displayHeight);
                processNormalProtocolSecure(getContext(), pd, setModes);
              }
            } catch (Throwable e) {
              if (maintainConnection) {
                Log.e(TAG, e.toString());
                e.printStackTrace();
                // Ensure we dismiss the progress dialog
                // before we fatal error finish
                if (pd.isShowing()) pd.dismiss();

                if (e instanceof OutOfMemoryError) {
                  System.gc();
                  showFatalMessageAndQuit(
                      "Unable to allocate sufficient memory to draw remote screen. "
                          + "To fix this, it's best to restart the application. "
                          + "As a last resort, you may try restarting your device.");
                } else {
                  String error = "Connection failed!";
                  if (e.getMessage() != null) {
                    if (e.getMessage().indexOf("authentication") > -1
                        || e.getMessage().indexOf("Unknown security result") > -1
                        || e.getMessage().indexOf("password check failed") > -1) {
                      error =
                          "VNC authentication failed! Check VNC password (and user if applicable).";
                    }
                    error = error + "<br>" + e.getLocalizedMessage();
                  }
                  showFatalMessageAndQuit(error);
                }
              }
            }
          }
        };
    t.start();

    clipboardMonitor = new ClipboardMonitor(getContext(), this);
    if (clipboardMonitor != null) {
      clipboardMonitorTimer = new Timer();
      clipboardMonitorTimer.schedule(clipboardMonitor, 0, 500);
    }
  }