[client,android] fix crasher bugs

This commit is contained in:
akallabeth
2025-01-23 20:50:45 +01:00
parent e28302eaab
commit 600768a637
25 changed files with 106 additions and 92 deletions

View File

@@ -96,7 +96,8 @@
<provider
android:name="com.freerdp.freerdpcore.services.FreeRDPSuggestionProvider"
android:authorities="com.freerdp.afreerdp.services.freerdpsuggestionprovider"></provider>
android:authorities="com.freerdp.afreerdp.services.freerdpsuggestionprovider"
android:exported="false"></provider>
<meta-data android:name="com.samsung.android.keepalive.density" android:value="true"/>

View File

@@ -18,7 +18,7 @@ android {
ndk {
File jniLibsDirectory = new File(project.projectDir, "src/main/jniLibs")
ArrayList<String> abiFiltersList = new ArrayList<String>();
ArrayList<String> abiFiltersList = new ArrayList<String>()
if (new File(jniLibsDirectory, "arm64-v8a/libfreerdp3.so").exists())
abiFiltersList.add("arm64-v8a")
if (new File(jniLibsDirectory, "armeabi-v7a/libfreerdp3.so").exists())

View File

@@ -55,7 +55,7 @@
</activity-alias>
<activity
android:exported="true"
android:exported="false"
android:name=".presentation.BookmarkActivity"
android:label="@string/title_bookmark_settings"
android:theme="@style/Theme.Settings">

View File

@@ -74,7 +74,7 @@ public class GlobalApp extends Application implements LibFreeRDP.EventListener
{
// start disconnect timeout...
disconnectTimer = new Timer();
disconnectTimer.schedule(new DisconnectTask(), timeoutMinutes * 60 * 1000);
disconnectTimer.schedule(new DisconnectTask(), (long)timeoutMinutes * 60 * 1000);
}
}
@@ -148,7 +148,7 @@ public class GlobalApp extends Application implements LibFreeRDP.EventListener
// http://thinkandroid.wordpress.com/2010/01/24/handling-screen-off-and-screen-on-intents/
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
registerReceiver(new ScreenReceiver(), filter);
registerReceiver(new ScreenReceiver(), filter, RECEIVER_EXPORTED);
}
// helper to send FreeRDP notifications

View File

@@ -17,6 +17,8 @@ import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;
import androidx.annotation.NonNull;
public class NetworkStateReceiver extends BroadcastReceiver
{
@@ -34,8 +36,13 @@ public class NetworkStateReceiver extends BroadcastReceiver
info.getType() != ConnectivityManager.TYPE_WIMAX);
}
@Override public void onReceive(Context context, Intent intent)
@Override public void onReceive(@NonNull Context context, @NonNull Intent intent)
{
String action = intent.getAction();
if (!action.equals("android.net.conn.CONNECTIVITY_CHANGE"))
{
return;
}
// check if we are connected via 3g or wlan
if (intent.getExtras() != null)
@@ -44,15 +51,18 @@ public class NetworkStateReceiver extends BroadcastReceiver
(NetworkInfo)intent.getExtras().get(ConnectivityManager.EXTRA_NETWORK_INFO);
// are we connected at all?
if (info != null && info.isConnected())
if (info != null)
{
// see if we are connected through 3G or WiFi
Log.d("app", "Connected via type " + info.getTypeName());
GlobalApp.ConnectedTo3G = (info.getType() != ConnectivityManager.TYPE_WIFI &&
info.getType() != ConnectivityManager.TYPE_WIMAX);
}
if (info.isConnected())
{
// see if we are connected through 3G or WiFi
Log.d("app", "Connected via type " + info.getTypeName());
GlobalApp.ConnectedTo3G = (info.getType() != ConnectivityManager.TYPE_WIFI &&
info.getType() != ConnectivityManager.TYPE_WIMAX);
}
Log.v("NetworkState", info.toString());
Log.v("NetworkState", info.toString());
}
}
}
}

View File

@@ -25,6 +25,6 @@ public class ScreenReceiver extends BroadcastReceiver
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF))
app.startDisconnectTimer();
else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON))
app.cancelDisconnectTimer();
GlobalApp.cancelDisconnectTimer();
}
}

View File

@@ -34,9 +34,9 @@ public class SessionState implements Parcelable
return new SessionState[size];
}
};
private long instance;
private BookmarkBase bookmark;
private Uri openUri;
private final long instance;
private final BookmarkBase bookmark;
private final Uri openUri;
private BitmapDrawable surface;
private LibFreeRDP.UIEventListener uiEventListener;

View File

@@ -40,7 +40,7 @@ public class ManualBookmark extends BookmarkBase
hostname = parcel.readString();
port = parcel.readInt();
enableGatewaySettings = (parcel.readInt() == 1 ? true : false);
enableGatewaySettings = (parcel.readInt() == 1);
gatewaySettings = parcel.readParcelable(GatewaySettings.class.getClassLoader());
}

View File

@@ -31,7 +31,7 @@ public class AboutActivity extends AppCompatActivity
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
mWebView = (WebView)findViewById(R.id.activity_about_webview);
mWebView = findViewById(R.id.activity_about_webview);
}
@Override protected void onResume()

View File

@@ -209,7 +209,7 @@ public class BookmarkActivity extends PreferenceActivity implements OnSharedPref
{
if (!LibFreeRDP.hasH264Support())
{
final int preferenceIdList[] = { R.string.preference_key_h264,
final int[] preferenceIdList = { R.string.preference_key_h264,
R.string.preference_key_h264_3g };
PreferenceManager mgr = getPreferenceManager();
@@ -609,11 +609,9 @@ public class BookmarkActivity extends PreferenceActivity implements OnSharedPref
private boolean verifySettings(SharedPreferences sharedPreferences)
{
boolean verifyFailed = false;
boolean verifyFailed = sharedPreferences.getString("bookmark.label", "").length() == 0;
// perform sanity checks on settings
// Label set
if (sharedPreferences.getString("bookmark.label", "").length() == 0)
verifyFailed = true;
// Server and port specified
if (!verifyFailed && sharedPreferences.getString("bookmark.hostname", "").length() == 0)
@@ -671,8 +669,6 @@ public class BookmarkActivity extends PreferenceActivity implements OnSharedPref
}
})
.show();
return;
}
else
{

View File

@@ -101,10 +101,10 @@ public class HomeActivity extends AppCompatActivity
}
// load views
clearTextButton = (Button)findViewById(R.id.clear_search_btn);
superBarEditText = (EditText)findViewById(R.id.superBarEditText);
clearTextButton = findViewById(R.id.clear_search_btn);
superBarEditText = findViewById(R.id.superBarEditText);
listViewBookmarks = (ListView)findViewById(R.id.listViewBookmarks);
listViewBookmarks = findViewById(R.id.listViewBookmarks);
// set listeners for the list view
listViewBookmarks.setOnItemClickListener(new AdapterView.OnItemClickListener() {

View File

@@ -1344,6 +1344,6 @@ public class ScrollView2D extends FrameLayout
// interface to receive notifications when the view is scrolled
public interface ScrollView2DListener {
abstract void onScrollChanged(ScrollView2D scrollView, int x, int y, int oldx, int oldy);
void onScrollChanged(ScrollView2D scrollView, int x, int y, int oldx, int oldy);
}
}

View File

@@ -255,13 +255,13 @@ public class SessionActivity extends AppCompatActivity
}
});
sessionView = (SessionView)findViewById(R.id.sessionView);
sessionView = findViewById(R.id.sessionView);
sessionView.setScaleGestureDetector(
new ScaleGestureDetector(this, new PinchZoomListener()));
sessionView.setSessionViewListener(this);
sessionView.requestFocus();
touchPointerView = (TouchPointerView)findViewById(R.id.touchPointerView);
touchPointerView = findViewById(R.id.touchPointerView);
touchPointerView.setTouchPointerListener(this);
keyboardMapper = new KeyboardMapper();
@@ -274,20 +274,20 @@ public class SessionActivity extends AppCompatActivity
cursorKeyboard = new Keyboard(getApplicationContext(), R.xml.cursor_keyboard);
// hide keyboard below the sessionView
keyboardView = (KeyboardView)findViewById(R.id.extended_keyboard);
keyboardView = findViewById(R.id.extended_keyboard);
keyboardView.setKeyboard(specialkeysKeyboard);
keyboardView.setOnKeyboardActionListener(this);
modifiersKeyboardView = (KeyboardView)findViewById(R.id.extended_keyboard_header);
modifiersKeyboardView = findViewById(R.id.extended_keyboard_header);
modifiersKeyboardView.setKeyboard(modifiersKeyboard);
modifiersKeyboardView.setOnKeyboardActionListener(this);
scrollView = (ScrollView2D)findViewById(R.id.sessionScrollView);
scrollView = findViewById(R.id.sessionScrollView);
scrollView.setScrollViewListener(this);
uiHandler = new UIHandler();
libFreeRDPBroadcastReceiver = new LibFreeRDPBroadcastReceiver();
zoomControls = (ZoomControls)findViewById(R.id.zoomControls);
zoomControls = findViewById(R.id.zoomControls);
zoomControls.hide();
zoomControls.setOnZoomInClickListener(new View.OnClickListener() {
@Override public void onClick(View v)
@@ -313,7 +313,7 @@ public class SessionActivity extends AppCompatActivity
// register freerdp events broadcast receiver
IntentFilter filter = new IntentFilter();
filter.addAction(GlobalApp.ACTION_EVENT_FREERDP);
registerReceiver(libFreeRDPBroadcastReceiver, filter);
registerReceiver(libFreeRDPBroadcastReceiver, filter, RECEIVER_EXPORTED);
mClipboardManager = ClipboardManagerProxy.getClipboardManager(this);
mClipboardManager.addClipboardChangedListener(this);
@@ -501,8 +501,8 @@ public class SessionActivity extends AppCompatActivity
static class ConnectThread extends Thread
{
private SessionState runnableSession;
private Context context;
private final SessionState runnableSession;
private final Context context;
public ConnectThread(@NonNull Context context, @NonNull SessionState session)
{
@@ -1161,10 +1161,13 @@ public class SessionActivity extends AppCompatActivity
{
int mappedX = (int)((float)(x + scrollView.getScrollX()) / sessionView.getZoom());
int mappedY = (int)((float)(y + scrollView.getScrollY()) / sessionView.getZoom());
if (mappedX > bitmap.getWidth())
mappedX = bitmap.getWidth();
if (mappedY > bitmap.getHeight())
mappedY = bitmap.getHeight();
if (bitmap != null)
{
if (mappedX > bitmap.getWidth())
mappedX = bitmap.getWidth();
if (mappedY > bitmap.getHeight())
mappedY = bitmap.getHeight();
}
return new Point(mappedX, mappedY);
}

View File

@@ -28,6 +28,8 @@ import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import androidx.annotation.NonNull;
import com.freerdp.freerdpcore.application.SessionState;
import com.freerdp.freerdpcore.services.LibFreeRDP;
import com.freerdp.freerdpcore.utils.DoubleGestureDetector;
@@ -228,14 +230,17 @@ public class SessionView extends View
(int)(height * scaleFactor) + touchPointerPaddingHeight);
}
@Override public void onDraw(Canvas canvas)
@Override public void onDraw(@NonNull Canvas canvas)
{
super.onDraw(canvas);
canvas.save();
canvas.concat(scaleMatrix);
canvas.drawColor(Color.BLACK);
surface.draw(canvas);
if (surface != null)
{
surface.draw(canvas);
}
canvas.restore();
}
@@ -278,17 +283,17 @@ public class SessionView extends View
}
public interface SessionViewListener {
abstract void onSessionViewBeginTouch();
void onSessionViewBeginTouch();
abstract void onSessionViewEndTouch();
void onSessionViewEndTouch();
abstract void onSessionViewLeftTouch(int x, int y, boolean down);
void onSessionViewLeftTouch(int x, int y, boolean down);
abstract void onSessionViewRightTouch(int x, int y, boolean down);
void onSessionViewRightTouch(int x, int y, boolean down);
abstract void onSessionViewMove(int x, int y);
void onSessionViewMove(int x, int y);
abstract void onSessionViewScroll(boolean down);
void onSessionViewScroll(boolean down);
}
private class SessionGestureListener extends GestureDetector.SimpleOnGestureListener

View File

@@ -52,12 +52,12 @@ public class TouchPointerView extends ImageView
private static final float SCROLL_DELTA = 10.0f;
private static final int DEFAULT_TOUCH_POINTER_RESTORE_DELAY = 150;
private RectF pointerRect;
private RectF pointerAreaRects[] = new RectF[9];
private final RectF[] pointerAreaRects = new RectF[9];
private Matrix translationMatrix;
private boolean pointerMoving = false;
private boolean pointerScrolling = false;
private TouchPointerListener listener = null;
private UIHandler uiHandler = new UIHandler();
private final UIHandler uiHandler = new UIHandler();
// gesture detection
private GestureDetector gestureDetector;
public TouchPointerView(Context context)
@@ -174,18 +174,14 @@ public class TouchPointerView extends ImageView
{
RectF transRect = new RectF(pointerAreaRects[area]);
translationMatrix.mapRect(transRect);
if (transRect.contains(event.getX(), event.getY()))
return true;
return false;
return transRect.contains(event.getX(), event.getY());
}
private boolean pointerTouched(MotionEvent event)
{
RectF transRect = new RectF(pointerRect);
translationMatrix.mapRect(transRect);
if (transRect.contains(event.getX(), event.getY()))
return true;
return false;
return transRect.contains(event.getX(), event.getY());
}
@Override public boolean onTouchEvent(MotionEvent event)
@@ -205,21 +201,21 @@ public class TouchPointerView extends ImageView
// touch pointer listener - is triggered if an action field is
public interface TouchPointerListener {
abstract void onTouchPointerClose();
void onTouchPointerClose();
abstract void onTouchPointerLeftClick(int x, int y, boolean down);
void onTouchPointerLeftClick(int x, int y, boolean down);
abstract void onTouchPointerRightClick(int x, int y, boolean down);
void onTouchPointerRightClick(int x, int y, boolean down);
abstract void onTouchPointerMove(int x, int y);
void onTouchPointerMove(int x, int y);
abstract void onTouchPointerScroll(boolean down);
void onTouchPointerScroll(boolean down);
abstract void onTouchPointerToggleKeyboard();
void onTouchPointerToggleKeyboard();
abstract void onTouchPointerToggleExtKeyboard();
void onTouchPointerToggleExtKeyboard();
abstract void onTouchPointerResetScrollZoom();
void onTouchPointerResetScrollZoom();
}
private class UIHandler extends Handler

View File

@@ -25,7 +25,7 @@ import java.util.ArrayList;
public abstract class BookmarkBaseGateway
{
private final static String TAG = "BookmarkBaseGateway";
private SQLiteOpenHelper bookmarkDB;
private final SQLiteOpenHelper bookmarkDB;
private static final String JOIN_PREFIX = "join_";
private static final String KEY_BOOKMARK_ID = "bookmarkId";

View File

@@ -111,7 +111,7 @@ public class BookmarkDB extends SQLiteOpenHelper
{
if (i != 0)
buf.append(delim);
buf.append((String)list.get(i));
buf.append(list.get(i));
}
return buf.toString();
}

View File

@@ -59,7 +59,7 @@ public class LibFreeRDP
}
catch (UnsatisfiedLinkError e)
{
Log.e(TAG, "Failed to load library " + lib + ": " + e.toString());
Log.e(TAG, "Failed to load library " + lib + ": " + e);
success = false;
break;
}
@@ -111,7 +111,7 @@ public class LibFreeRDP
}
catch (UnsatisfiedLinkError e)
{
Log.e(TAG, "Failed to load library: " + e.toString());
Log.e(TAG, "Failed to load library: " + e);
throw e;
}
}
@@ -260,7 +260,7 @@ public class LibFreeRDP
String hostname = bookmark.<ManualBookmark>get().getHostname();
args.add("/v:" + hostname);
args.add("/port:" + String.valueOf(port));
args.add("/port:" + port);
arg = bookmark.getUsername();
if (!arg.isEmpty())
@@ -280,7 +280,7 @@ public class LibFreeRDP
args.add(
String.format("/size:%dx%d", screenSettings.getWidth(), screenSettings.getHeight()));
args.add("/bpp:" + String.valueOf(screenSettings.getColors()));
args.add("/bpp:" + screenSettings.getColors());
if (advanced.getConsoleMode())
{
@@ -380,7 +380,7 @@ public class LibFreeRDP
/* 0 ... local
1 ... remote
2 ... disable */
args.add("/audio-mode:" + String.valueOf(advanced.getRedirectSound()));
args.add("/audio-mode:" + advanced.getRedirectSound());
if (advanced.getRedirectSound() == 0)
{
args.add("/sound");
@@ -420,7 +420,7 @@ public class LibFreeRDP
int port = openUri.getPort();
if (hostname != null)
{
hostname = hostname + ((port == -1) ? "" : (":" + String.valueOf(port)));
hostname = hostname + ((port == -1) ? "" : (":" + port));
args.add("/v:" + hostname);
}
@@ -636,7 +636,8 @@ public class LibFreeRDP
return freerdp_get_version();
}
public static interface EventListener {
public interface EventListener
{
void OnPreConnect(long instance);
void OnConnectionSuccess(long instance);
@@ -648,7 +649,8 @@ public class LibFreeRDP
void OnDisconnected(long instance);
}
public static interface UIEventListener {
public interface UIEventListener
{
void OnSettingsChanged(int width, int height, int bpp);
boolean OnAuthenticate(StringBuilder username, StringBuilder domain,

View File

@@ -25,7 +25,7 @@ import java.util.ArrayList;
public class QuickConnectHistoryGateway
{
private final static String TAG = "QuickConnectHistoryGateway";
private SQLiteOpenHelper historyDB;
private final SQLiteOpenHelper historyDB;
public QuickConnectHistoryGateway(SQLiteOpenHelper historyDB)
{

View File

@@ -49,9 +49,9 @@ public class BookmarkArrayAdapter extends ArrayAdapter<BookmarkBase>
}
BookmarkBase bookmark = getItem(position);
TextView label = (TextView)curView.findViewById(R.id.bookmark_text1);
TextView hostname = (TextView)curView.findViewById(R.id.bookmark_text2);
ImageView star_icon = (ImageView)curView.findViewById(R.id.bookmark_icon2);
TextView label = curView.findViewById(R.id.bookmark_text1);
TextView hostname = curView.findViewById(R.id.bookmark_text2);
ImageView star_icon = curView.findViewById(R.id.bookmark_icon2);
assert label != null;
assert hostname != null;

View File

@@ -57,7 +57,7 @@ public class ButtonPreference extends Preference
@Override public View getView(View convertView, ViewGroup parent)
{
View v = super.getView(convertView, parent);
button = (Button)v.findViewById(R.id.preference_button);
button = v.findViewById(R.id.preference_button);
if (buttonText != null)
button.setText(buttonText);
if (buttonOnClickListener != null)
@@ -66,7 +66,7 @@ public class ButtonPreference extends Preference
// additional init for ICS - make widget frame visible
// refer to
// http://stackoverflow.com/questions/8762984/custom-preference-broken-in-honeycomb-ics
LinearLayout widgetFrameView = ((LinearLayout)v.findViewById(android.R.id.widget_frame));
LinearLayout widgetFrameView = v.findViewById(android.R.id.widget_frame);
widgetFrameView.setVisibility(View.VISIBLE);
return v;

View File

@@ -26,7 +26,8 @@ public abstract class ClipboardManagerProxy
public abstract void getPrimaryClipManually();
public static interface OnClipboardChangedListener {
public interface OnClipboardChangedListener
{
void onClipboardChanged(String data);
}
@@ -59,7 +60,7 @@ public abstract class ClipboardManagerProxy
private static class HCClipboardManager
extends ClipboardManagerProxy implements ClipboardManager.OnPrimaryClipChangedListener
{
private ClipboardManager mClipboardManager;
private final ClipboardManager mClipboardManager;
private OnClipboardChangedListener mListener;
public HCClipboardManager(Context ctx)

View File

@@ -234,7 +234,7 @@ public class DoubleGestureDetector
break;
}
if ((action == MotionEvent.ACTION_MOVE) && handled == false)
if ((action == MotionEvent.ACTION_MOVE) && !handled)
handled = true;
return handled;

View File

@@ -229,7 +229,7 @@ public class KeyboardMapper
public void init(Context context)
{
if (initialized == true)
if (initialized)
return;
keymapAndroid = new int[256];
@@ -714,12 +714,12 @@ public class KeyboardMapper
// interface that gets called for input handling
public interface KeyProcessingListener {
abstract void processVirtualKey(int virtualKeyCode, boolean down);
void processVirtualKey(int virtualKeyCode, boolean down);
abstract void processUnicodeKey(int unicodeKey);
void processUnicodeKey(int unicodeKey);
abstract void switchKeyboard(int keyboardType);
void switchKeyboard(int keyboardType);
abstract void modifiersChanged();
void modifiersChanged();
}
}

View File

@@ -14,7 +14,7 @@
android:layout_height="match_parent">
<!-- children are specified bottom-up so that we have a correct z-order in our final layout -->
<android.inputmethodservice.KeyboardView xmlns:android="http://schemas.android.com/apk/res/android"
<android.inputmethodservice.KeyboardView
android:id="@+id/extended_keyboard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@@ -56,7 +56,7 @@
android:layout_alignBottom="@id/sessionScrollView"
android:layout_centerHorizontal="true" />
<android.inputmethodservice.KeyboardView xmlns:android="http://schemas.android.com/apk/res/android"
<android.inputmethodservice.KeyboardView
android:id="@+id/extended_keyboard_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"