Skip to content

Commit

Permalink
Bugfix for RDP servers that do not support automatic resolution reque…
Browse files Browse the repository at this point in the history
…st by the client like Ubuntu's remote desktop sharing.
  • Loading branch information
iiordanov committed Feb 19, 2024
1 parent 52bf56f commit 54731e8
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 30 deletions.
4 changes: 0 additions & 4 deletions bVNC/src/main/java/com/iiordanov/bVNC/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,6 @@ public class Constants {
public final static String MV_DMRC_BACK = " ; [ -O ${HOME}/.dmrc.$$ ] && mv ${HOME}/.dmrc.$$ ${HOME}/.dmrc";
public final static int AUTOX_GEOM_SELECT_NATIVE = 0;
public final static int AUTOX_GEOM_SELECT_CUSTOM = 1;
public final static int RDP_GEOM_SELECT_NATIVE_LANDSCAPE = 0;
public final static int RDP_GEOM_SELECT_NATIVE_PORTRAIT = 1;
public final static int RDP_GEOM_SELECT_CUSTOM = 2;
public final static int RDP_GEOM_SELECT_AUTO = 3;
public final static int VNC_GEOM_SELECT_DISABLED = 0;
public final static int VNC_GEOM_SELECT_AUTOMATIC = 1;
public final static int VNC_GEOM_SELECT_NATIVE_LANDSCAPE = 2;
Expand Down
17 changes: 9 additions & 8 deletions bVNC/src/main/java/com/iiordanov/bVNC/RemoteCanvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import com.undatech.opaque.AbstractDrawableData;
import com.undatech.opaque.Connection;
import com.undatech.opaque.DrawableReallocatedListener;
import com.undatech.opaque.RemoteClientLibConstants;
import com.undatech.opaque.Viewable;
import com.undatech.opaque.input.RemotePointer;
import com.undatech.remoteClientUi.R;
Expand Down Expand Up @@ -208,7 +209,7 @@ public void setParameters(
public int getDesiredWidth() {
int w = getRemoteWidth(getWidth(), getHeight());
if (!connection.isRequestingNewDisplayResolution() &&
connection.getRdpResType() == Constants.RDP_GEOM_SELECT_CUSTOM) {
connection.getRdpResType() == RemoteClientLibConstants.RDP_GEOM_SELECT_CUSTOM) {
w = connection.getRdpWidth();
}
Log.d(TAG, "Width requested: " + w);
Expand All @@ -222,7 +223,7 @@ public int getDesiredWidth() {
public int getDesiredHeight() {
int h = getRemoteHeight(getWidth(), getHeight());
if (!connection.isRequestingNewDisplayResolution() &&
connection.getRdpResType() == Constants.RDP_GEOM_SELECT_CUSTOM) {
connection.getRdpResType() == RemoteClientLibConstants.RDP_GEOM_SELECT_CUSTOM) {
h = connection.getRdpHeight();
}
Log.d(TAG, "Height requested: " + h);
Expand All @@ -236,12 +237,12 @@ public int getRemoteWidth(int viewWidth, int viewHeight) {
int remoteWidth;
int reqWidth = connection.getRdpWidth();
int reqHeight = connection.getRdpHeight();
if (connection.getRdpResType() == Constants.RDP_GEOM_SELECT_CUSTOM &&
if (connection.getRdpResType() == RemoteClientLibConstants.RDP_GEOM_SELECT_CUSTOM &&
reqWidth >= 2 && reqHeight >= 2) {
remoteWidth = reqWidth;
} else if (connection.getRdpResType() == Constants.RDP_GEOM_SELECT_NATIVE_PORTRAIT) {
} else if (connection.getRdpResType() == RemoteClientLibConstants.RDP_GEOM_SELECT_NATIVE_PORTRAIT) {
remoteWidth = Math.min(viewWidth, viewHeight);
} else if (connection.getRdpResType() == Constants.RDP_GEOM_SELECT_NATIVE_LANDSCAPE) {
} else if (connection.getRdpResType() == RemoteClientLibConstants.RDP_GEOM_SELECT_NATIVE_LANDSCAPE) {
remoteWidth = Math.max(viewWidth, viewHeight);
} else {
remoteWidth = viewWidth;
Expand All @@ -258,12 +259,12 @@ public int getRemoteHeight(int viewWidth, int viewHeight) {
int remoteHeight;
int reqWidth = connection.getRdpWidth();
int reqHeight = connection.getRdpHeight();
if (connection.getRdpResType() == Constants.RDP_GEOM_SELECT_CUSTOM &&
if (connection.getRdpResType() == RemoteClientLibConstants.RDP_GEOM_SELECT_CUSTOM &&
reqWidth >= 2 && reqHeight >= 2) {
remoteHeight = reqHeight;
} else if (connection.getRdpResType() == Constants.RDP_GEOM_SELECT_NATIVE_PORTRAIT) {
} else if (connection.getRdpResType() == RemoteClientLibConstants.RDP_GEOM_SELECT_NATIVE_PORTRAIT) {
remoteHeight = Math.max(viewWidth, viewHeight);
} else if (connection.getRdpResType() == Constants.RDP_GEOM_SELECT_NATIVE_LANDSCAPE) {
} else if (connection.getRdpResType() == RemoteClientLibConstants.RDP_GEOM_SELECT_NATIVE_LANDSCAPE) {
remoteHeight = Math.min(viewWidth, viewHeight);
} else {
remoteHeight = viewHeight;
Expand Down
5 changes: 3 additions & 2 deletions bVNC/src/main/java/com/iiordanov/bVNC/aRDP.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.iiordanov.util.PermissionGroups;
import com.iiordanov.util.PermissionsManager;
import com.morpheusly.common.Utilities;
import com.undatech.opaque.RemoteClientLibConstants;
import com.undatech.remoteClientUi.R;

import java.util.List;
Expand Down Expand Up @@ -121,7 +122,7 @@ private void initializeRdpResolutionSpinner() {
@Override
public void onItemSelected(AdapterView<?> arg0, View view, int itemIndex, long id) {
selected.setRdpResType(itemIndex);
setRemoteWidthAndHeight(Constants.RDP_GEOM_SELECT_CUSTOM);
setRemoteWidthAndHeight(RemoteClientLibConstants.RDP_GEOM_SELECT_CUSTOM);
}

@Override
Expand Down Expand Up @@ -167,7 +168,7 @@ public void updateViewFromSelected() {
setRdpSpecificSettingsFromSelected();
setRdpColorSpinnerPositionFromSelected();
setRdpGeometrySpinnerPositionFromSelected();
setRemoteWidthAndHeight(Constants.RDP_GEOM_SELECT_CUSTOM);
setRemoteWidthAndHeight(RemoteClientLibConstants.RDP_GEOM_SELECT_CUSTOM);
setRemoteSoundTypeFromSelected(selected.getRemoteSoundType());
updateAdvancedSettingsViewsFromSelected();
}
Expand Down
5 changes: 3 additions & 2 deletions bVNC/src/main/java/com/iiordanov/bVNC/aSPICE.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import com.iiordanov.util.PermissionGroups;
import com.iiordanov.util.PermissionsManager;
import com.morpheusly.common.Utilities;
import com.undatech.opaque.RemoteClientLibConstants;
import com.undatech.opaque.util.FileUtils;
import com.undatech.remoteClientUi.R;

Expand Down Expand Up @@ -82,7 +83,7 @@ public void onCreate(Bundle icicle) {
@Override
public void onItemSelected(AdapterView<?> arg0, View view, int itemIndex, long id) {
selected.setRdpResType(itemIndex);
setRemoteWidthAndHeight(Constants.RDP_GEOM_SELECT_CUSTOM);
setRemoteWidthAndHeight(RemoteClientLibConstants.RDP_GEOM_SELECT_CUSTOM);
}

@Override
Expand Down Expand Up @@ -143,7 +144,7 @@ public void updateViewFromSelected() {
checkboxEnableSound.setChecked(selected.getEnableSound());
spinnerGeometry.setSelection(selected.getRdpResType());

setRemoteWidthAndHeight(Constants.RDP_GEOM_SELECT_CUSTOM);
setRemoteWidthAndHeight(RemoteClientLibConstants.RDP_GEOM_SELECT_CUSTOM);

// Write out CA to file if it doesn't exist.
writeCaToFileIfNotThere(selected.getCaCert());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.iiordanov.bVNC.input.RemoteSpiceKeyboard
import com.iiordanov.bVNC.input.RemoteSpicePointer
import com.undatech.opaque.Connection
import com.undatech.opaque.MessageDialogs
import com.undatech.opaque.RemoteClientLibConstants
import com.undatech.opaque.SpiceCommunicator
import com.undatech.opaque.Viewable
import com.undatech.remoteClientUi.R
Expand All @@ -30,7 +31,7 @@ open class RemoteOpaqueConnection(
checkNetworkConnectivity()
spiceComm = SpiceCommunicator(
context, handler, canvas,
connection.isRequestingNewDisplayResolution || connection.rdpResType == Constants.RDP_GEOM_SELECT_CUSTOM,
connection.isRequestingNewDisplayResolution || connection.rdpResType == RemoteClientLibConstants.RDP_GEOM_SELECT_CUSTOM,
!Utils.isFree(context) && connection.isUsbEnabled, App.debugLog
)
rfbConn = spiceComm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class RemoteRdpConnection(
private fun initializeRdpConnection() {
Log.i(tag, "initializeRdpConnection: Initializing RDP connection.")
rdpComm = RdpCommunicator(
context, handler, canvas,
connection, context, handler, canvas,
connection.userName, connection.rdpDomain, connection.password,
App.debugLog
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.iiordanov.bVNC.Utils
import com.iiordanov.bVNC.input.RemoteSpiceKeyboard
import com.iiordanov.bVNC.input.RemoteSpicePointer
import com.undatech.opaque.Connection
import com.undatech.opaque.RemoteClientLibConstants
import com.undatech.opaque.SpiceCommunicator
import com.undatech.opaque.Viewable
import com.undatech.remoteClientUi.R
Expand Down Expand Up @@ -114,7 +115,7 @@ class RemoteSpiceConnection(

@Throws(java.lang.Exception::class)
override fun correctAfterRotation() {
if (connection.rdpResType == Constants.RDP_GEOM_SELECT_AUTO) {
if (connection.rdpResType == RemoteClientLibConstants.RDP_GEOM_SELECT_AUTO) {
spiceComm?.requestResolution(canvas.width, canvas.height)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void onCreate(Bundle icicle) {
toggleAutoRequestDisplayResolution.setChecked(currentConnection.isRequestingNewDisplayResolution());

toggleCustomDisplayResolution = (ToggleButton) findViewById(R.id.toggleCustomDisplayResolution);
toggleCustomDisplayResolution.setChecked(currentConnection.getRdpResType() == Constants.RDP_GEOM_SELECT_CUSTOM);
toggleCustomDisplayResolution.setChecked(currentConnection.getRdpResType() == RemoteClientLibConstants.RDP_GEOM_SELECT_CUSTOM);

toggleSslStrict = (ToggleButton) findViewById(R.id.toggleSslStrict);
toggleSslStrict.setChecked(currentConnection.isSslStrict());
Expand Down Expand Up @@ -266,7 +266,7 @@ public void toggleCustomDisplayResolution(View view) {
boolean customDisplayResolution = s.isChecked();
int resType = 0;
if (customDisplayResolution) {
resType = Constants.RDP_GEOM_SELECT_CUSTOM;
resType = RemoteClientLibConstants.RDP_GEOM_SELECT_CUSTOM;
}
currentConnection.setRdpResType(resType);
if (customDisplayResolution) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class ConnectionSettings implements Connection, Serializable {

private int rdpWidth = 0;
private int rdpHeight = 0;
private int rdpResType = Constants.RDP_GEOM_SELECT_CUSTOM;
private int rdpResType = RemoteClientLibConstants.RDP_GEOM_SELECT_CUSTOM;

private boolean useLastPositionToolbar = true;
private int useLastPositionToolbarX;
Expand Down Expand Up @@ -868,7 +868,7 @@ public void loadAdvancedSettings(Context context, String file) {
scaleMode = sp.getString("scaleMode", ImageView.ScaleType.MATRIX.toString()).trim();
rdpWidth = sp.getInt("rdpWidth", 0);
rdpHeight = sp.getInt("rdpHeight", 0);
rdpResType = sp.getInt("rdpResType", Constants.RDP_GEOM_SELECT_CUSTOM);
rdpResType = sp.getInt("rdpResType", RemoteClientLibConstants.RDP_GEOM_SELECT_CUSTOM);
useLastPositionToolbar = sp.getBoolean("useLastPositionToolbar", true);
useLastPositionToolbarX = sp.getInt("useLastPositionToolbarX", 0);
useLastPositionToolbarY = sp.getInt("useLastPositionToolbarY", 0);
Expand Down
2 changes: 1 addition & 1 deletion remoteClientLib/jni/libs/build-deps.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ openssl_ver="1.1.1w"
spicegtk_ver="0.37"
spiceprotocol_ver="0.12.15"
gstreamer_ver="1.18.6" # Need to synchronize gstreamer version with gnutls version/abi
freerdp_ver="5d58c2ceb39030bb0880de4da12563c927164f24" # HEAD of branch stable-2.0 2023-12-02
freerdp_ver="f1121b0812f992918b56998df8141ea0ca785def" # HEAD of branch stable-2.0 2024-02-19
setuptools_ver="v44.1.1"
soup_ver="2.41.2"
rest_ver="0.8.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,15 @@ public class RdpCommunicator extends RfbConnectable implements RdpKeyboardMapper
private boolean disconnectRequested = false;
private final String username, password, domain;

public RdpCommunicator(
private Connection connection;

public RdpCommunicator(Connection connection,
Context context, Handler handler, Viewable viewable,
String username, String domain, String password,
boolean debugLogging
) {
super(debugLogging, handler);
this.connection = connection;
// This is necessary because it initializes a synchronizedMap referenced later.
this.freeRdpApp = new GlobalApp();
patchFreeRdpCore();
Expand Down Expand Up @@ -318,9 +321,7 @@ public void setConnectionParameters(

// Set screen settings to native res if instructed to, or if height or width are too small.
BookmarkBase.ScreenSettings screenSettings = bookmark.getActiveScreenSettings();
screenSettings.setWidth(remoteWidth);
screenSettings.setHeight(remoteHeight);
screenSettings.setColors(colors);
setResolutionAndColor(remoteWidth, remoteHeight, colors, screenSettings);

// Set performance flags.
BookmarkBase.PerformanceFlags performanceFlags = bookmark.getPerformanceFlags();
Expand Down Expand Up @@ -427,9 +428,27 @@ public void OnDisconnected(long instance) {
@Override
public void OnSettingsChanged(int width, int height, int bpp) {
android.util.Log.d(TAG, "OnSettingsChanged called, wxh: " + width + "x" + height);
BookmarkBase.ScreenSettings settings = session.getBookmark().getActiveScreenSettings();
if (settings.getWidth() != width || settings.getHeight() != height) {
setResolutionAndColor(width, height, bpp, settings);
connection.setRdpResType(RemoteClientLibConstants.RDP_GEOM_SELECT_CUSTOM);
connection.setRdpWidth(width);
connection.setRdpHeight(height);
connection.setRdpColor(bpp);
connection.save(context);
close();
initSession(username, domain, password);
connect();
}
viewable.reallocateDrawable(width, height);
}

private static void setResolutionAndColor(int width, int height, int bpp, BookmarkBase.ScreenSettings settings) {
settings.setWidth(width);
settings.setHeight(height);
settings.setColors(bpp);
}

//////////////////////////////////////////////////////////////////////////////////
// Implementation of LibFreeRDP.UIEventListener. Through the functions implemented
// below libspice and FreeRDP communicate remote desktop size and updates.
Expand Down Expand Up @@ -511,7 +530,7 @@ public void OnGraphicsUpdate(int x, int y, int width, int height) {
//android.util.Log.v(TAG, "OnGraphicsUpdate called: " + x +", " + y + " + " + width + "x" + height );
if (viewable != null && session != null) {
Bitmap bitmap = viewable.getBitmap();
if (bitmap != null) {
if (bitmap != null && x + width <= bitmap.getWidth() && y + height <= bitmap.getHeight()) {
LibFreeRDP.updateGraphics(session.getInstance(), bitmap, x, y, width, height);
viewable.reDraw(x, y, width, height);
}
Expand All @@ -520,7 +539,7 @@ public void OnGraphicsUpdate(int x, int y, int width, int height) {

@Override
public void OnGraphicsResize(int width, int height, int bpp) {
android.util.Log.d(TAG, "OnGraphicsResize called.");
android.util.Log.d(TAG, "OnGraphicsResize called " + width + "x" + height + ", bpp:" + bpp);
OnSettingsChanged(width, height, bpp);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public class RemoteClientLibConstants {

public static final int SDK_INT = android.os.Build.VERSION.SDK_INT;

public final static int RDP_GEOM_SELECT_NATIVE_LANDSCAPE = 0;
public final static int RDP_GEOM_SELECT_NATIVE_PORTRAIT = 1;
public final static int RDP_GEOM_SELECT_CUSTOM = 2;
public final static int RDP_GEOM_SELECT_AUTO = 3;

public static final int DIALOG_X509_CERT = 1;
public static final int DIALOG_SSH_CERT = 2;
public static final int DIALOG_RDP_CERT = 3;
Expand Down

0 comments on commit 54731e8

Please sign in to comment.