Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features for disappearing prompt and MasterPassword Lock Editing Conn… #480

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bVNC/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ dependencies {
implementation group: 'androidx.legacy', name: 'legacy-support-v4', version: '1.0.0'
implementation group: 'androidx.vectordrawable', name: 'vectordrawable', version: '1.1.0'
implementation group: 'androidx.preference', name: 'preference-ktx', version: '1.2.0'
implementation group: 'androidx.preference', name: 'preference-ktx', version: '1.2.0'
implementation group: 'at.favre.lib', name: 'bcrypt', version: '0.10.2'
implementation 'net.zetetic:android-database-sqlcipher:4.5.1@aar'
implementation "androidx.sqlite:sqlite-ktx:2.2.0"
implementation group: 'org.yaml', name: 'snakeyaml', version: '1.23'
Expand Down
5 changes: 3 additions & 2 deletions bVNC/src/main/java/com/iiordanov/bVNC/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,10 @@ public class Constants {
public static final String preferSendingUnicode = "preferSendingUnicode";
public static final String doNotShowDesktopThumbnails = "doNotShowDesktopThumbnails";
public static final String showOnlyConnectionNicknames = "showOnlyConnectionNicknames";

public static final String softwareKeyboardType = "softwareKeyboardType";
public static final String masterPassword = "masterPassword";
public static final String onlyLockConnectionEditing = "onlyLockConnectionEditing";
public static final int HASH_COST = 6;

public static final String ACTION_USB_PERMISSION = "com.iiordanov.aSPICE.USB_PERMISSION";
public static final int usbDeviceTimeout = 5000;
Expand All @@ -220,7 +222,6 @@ public class Constants {
public static final int REMOTE_SOUND_DISABLED = 2;
public static final int REMOTE_SOUND_ON_SERVER = 1;
public static final int REMOTE_SOUND_ON_DEVICE = 0;

public static final int SHORT_VIBRATION = 1;


Expand Down
11 changes: 10 additions & 1 deletion bVNC/src/main/java/com/iiordanov/bVNC/RemoteCanvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,15 @@ public void run() {
});
}

public void showFatalMessageAndQuitTimer(final String error) {
closeConnection();
handler.post(new Runnable() {
public void run() {
Utils.showFatalErrorMessageTimer(getContext(), error);
}
});
}


/**
* If necessary, initializes an SSH tunnel and returns local forwarded port, or
Expand Down Expand Up @@ -1970,7 +1979,7 @@ public String retrievevvFileName() {
}

@Override
public void onTextObtained(String dialogId, String[] obtainedString, boolean dialogCancelled, boolean save) {
public void onTextObtained(String dialogId, String[] obtainedString, boolean dialogCancelled, boolean save, boolean obtainedBooleans[]) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these square brackets in the right place?

if (dialogCancelled) {
handler.sendEmptyMessage(RemoteClientLibConstants.DISCONNECT_NO_MESSAGE);
return;
Expand Down
2 changes: 1 addition & 1 deletion bVNC/src/main/java/com/iiordanov/bVNC/SSHConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ public String[] replyToChallenge(String name, String instruction,
}

@Override
public void onTextObtained(String dialogId, String[] obtainedStrings, boolean dialogCancelled, boolean keep) {
public void onTextObtained(String dialogId, String[] obtainedStrings, boolean dialogCancelled, boolean keep, boolean[] obtainedBooleans) {
if (dialogCancelled) {
handler.sendEmptyMessage(RemoteClientLibConstants.DISCONNECT_NO_MESSAGE);
return;
Expand Down
53 changes: 51 additions & 2 deletions bVNC/src/main/java/com/iiordanov/bVNC/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import android.content.ContextWrapper;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface.OnShowListener;
import android.widget.Button;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
Expand All @@ -39,6 +41,7 @@
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Message;
import android.text.ClipboardManager;
import android.text.Html;
Expand All @@ -58,6 +61,7 @@
import com.google.android.play.core.review.ReviewManager;
import com.google.android.play.core.review.ReviewManagerFactory;
import com.undatech.opaque.ConnectionSetupActivity;
import com.undatech.opaque.RemoteClientLibConstants;
import com.undatech.remoteClientUi.R;

import net.sqlcipher.database.SQLiteDatabase;
Expand All @@ -79,6 +83,8 @@
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.Locale;

public class Utils {
private final static String TAG = "Utils";
Expand Down Expand Up @@ -137,7 +143,7 @@ public static void showErrorMessage(Context _context, String message) {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
}, null);
}

public static void showFatalErrorMessage(final Context _context, String message) {
Expand All @@ -150,10 +156,50 @@ public void onClick(DialogInterface dialog, int which) {
Utils.justFinish(activity);
}
}
}, null);
}

public static void showFatalErrorMessageTimer(final Context _context, String message) {
showMessage(_context, _context.getString(R.string.error) + "!", message, android.R.drawable.ic_dialog_alert, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
Activity activity = Utils.getActivity(_context);
if (activity != null) {
Utils.justFinish(activity);
}
}
}, new DialogInterface.OnShowListener() {
private static final int AUTO_DISMISS_MILLIS = RemoteClientLibConstants.ON_SHOW_LISTENER_TIMER;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just import ON_SHOW_LISTENER_TIMER from RemoteClientLibConstants?

@Override
public void onShow(final DialogInterface dialog) {
final Button defaultButton = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE);
final CharSequence negativeButtonText = defaultButton.getText();
new CountDownTimer(AUTO_DISMISS_MILLIS, RemoteClientLibConstants.ON_SHOW_LISTENER_CHECK_INTERVAL) {
@Override
public void onTick(long millisUntilFinished) {
defaultButton.setText(String.format(
Locale.getDefault(), "%s (%d)",
negativeButtonText,
TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) + 1 //add one so it never displays zero
));
}
@Override
public void onFinish() {
if (((AlertDialog) dialog).isShowing()) {
dialog.dismiss();
Activity activity = Utils.getActivity(_context);
if (activity != null) {
Utils.justFinish(activity);
}
}
}
}.start();
}
});
}

public static void showMessage(Context _context, String title, String message, int icon, DialogInterface.OnClickListener ackHandler) {
public static void showMessage(Context _context, String title, String message, int icon, DialogInterface.OnClickListener ackHandler, DialogInterface.OnShowListener showHandler) {
try {
if (alertDialog != null && alertDialog.isShowing() && !isContextActivityThatIsFinishing(_context)) {
alertDialog.dismiss();
Expand All @@ -166,6 +212,9 @@ public static void showMessage(Context _context, String title, String message, i
builder.setIcon(icon);
if (!(alertDialog != null && alertDialog.isShowing()) && !isContextActivityThatIsFinishing(_context)) {
alertDialog = builder.create();
if ( showHandler != null ) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove spacing around parentheses.

alertDialog.setOnShowListener(showHandler);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setOnShowListener shows its parameter is nullable, so maybe you can just pass showHandler even if it's null?

}
alertDialog.show();
}
} catch (IllegalArgumentException e) {
Expand Down
31 changes: 22 additions & 9 deletions bVNC/src/main/java/com/iiordanov/bVNC/dialogs/GetTextFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Switch;
import android.widget.TextView;

import androidx.fragment.app.DialogFragment;
Expand Down Expand Up @@ -68,7 +69,7 @@ public class GetTextFragment extends DialogFragment {
public static final String DIALOG_ID_GET_OPAQUE_OTP_CODE = "DIALOG_ID_GET_OPAQUE_OTP_CODE";

public interface OnFragmentDismissedListener {
void onTextObtained(String dialogId, String[] obtainedStrings, boolean dialogCancelled, boolean save);
void onTextObtained(String dialogId, String[] obtainedStrings, boolean dialogCancelled, boolean save, boolean[] obtainedBools);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please name obtainedBools vs obtainedBooleans consistently.

}

private class TextMatcher implements TextWatcher {
Expand All @@ -90,6 +91,7 @@ public void afterTextChanged(Editable arg0) {}
private EditText textBox;
private EditText textBox2;
private EditText textBox3;
private Switch switch1;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this switch numbered? Is there a specific function that it fulfills or is its function generic? If there is a specific function, let's please name it more specifically!

private Button buttonConfirm;
private Button buttonCancel;
private CheckBox checkboxKeepPassword;
Expand All @@ -100,7 +102,7 @@ public void afterTextChanged(Editable arg0) {}
private String t2;
private String t3;
private boolean keepPassword;

private boolean sw1;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are keeping the switch name, let's make this variable named with a full word.

private int dialogType = 0;
private int messageNum = 0;
private int errorNum = 0;
Expand All @@ -111,7 +113,8 @@ public GetTextFragment () {
public static GetTextFragment newInstance(String dialogId, String title,
OnFragmentDismissedListener dismissalListener,
int dialogType, int messageNum, int errorNum,
String t1, String t2, String t3, boolean keepPassword) {
String t1, String t2, String t3, boolean keepPassword,
boolean sw1) {
android.util.Log.i(TAG, "newInstance called");
GetTextFragment f = new GetTextFragment();
f.setDismissalListener(dismissalListener);
Expand All @@ -126,6 +129,7 @@ public static GetTextFragment newInstance(String dialogId, String title,
args.putString("t2", t2);
args.putString("t3", t3);
args.putBoolean("keepPassword", keepPassword);
args.putBoolean("sw1", sw1);
f.setArguments(args);
f.setRetainInstance(false);

Expand All @@ -145,6 +149,7 @@ public void onCreate(Bundle savedInstanceState) {
t2 = getArguments().getString("t2");
t3 = getArguments().getString("t3");
keepPassword = getArguments().getBoolean("keepPassword");
sw1 = getArguments().getBoolean("sw1");
}

@Override
Expand Down Expand Up @@ -192,12 +197,15 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
error = (TextView) v.findViewById(R.id.error);
textBox = (EditText) v.findViewById(R.id.textBox);
textBox2 = (EditText) v.findViewById(R.id.textBox2);
switch1 = (Switch) v.findViewById(R.id.switch1);
switch1.setVisibility(View.VISIBLE);
switch1.setText(R.string.master_password_only_lock_connection_editing);
hideText(textBox);
hideText(textBox2);
buttonConfirm = (Button) v.findViewById(R.id.buttonConfirm);
buttonCancel = (Button) v.findViewById(R.id.buttonCancel);
dismissOnCancel(buttonCancel);
ensureMatchingDismissOnConfirm (buttonConfirm, textBox, textBox2, error);
ensureMatchingDismissOnConfirm (buttonConfirm, textBox, textBox2, switch1, error);
break;
case CredentialsWithDomain:
v = inflater.inflate(R.layout.get_credentials_with_domain, container, false);
Expand Down Expand Up @@ -252,10 +260,10 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
textBox2.setText(t2);
if (textBox3 != null && t3 != null)
textBox3.setText(t3);

if (checkboxKeepPassword != null) {
if (checkboxKeepPassword != null)
checkboxKeepPassword.setChecked(keepPassword);
}
if (switch1 != null)
switch1.setChecked(sw1);

message = (TextView) v.findViewById(R.id.message);
message.setText(messageNum);
Expand Down Expand Up @@ -293,7 +301,7 @@ public void onClick(View v) {
});
}

private void ensureMatchingDismissOnConfirm (Button buttonConfirm, final EditText textBox1, final EditText textBox2, final TextView error) {
private void ensureMatchingDismissOnConfirm (Button buttonConfirm, final EditText textBox1, final EditText textBox2, final Switch switch1, final TextView error) {
buttonConfirm.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Expand All @@ -316,6 +324,7 @@ public void onClick(View v) {
public void onDismiss (DialogInterface dialog) {
android.util.Log.i(TAG, "onDismiss called: Sending data back to Activity");
String[] results = new String[3];
boolean[] b_results = new boolean[3];
if (textViewBox != null) {
results[0] = textViewBox.getText().toString();
textViewBox.setText("");
Expand All @@ -335,11 +344,15 @@ public void onDismiss (DialogInterface dialog) {
if (checkboxKeepPassword != null) {
keepPassword = checkboxKeepPassword.isChecked();
}
if (switch1 != null) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not quite certain why you have decided to make this an array of booleans and not opted out for a more specific naming convention that does not require for us to unpack booleans from an array by index.

b_results[0] = switch1.isChecked();
switch1.setChecked(false);
}
if (dismissalListener != null && (wasConfirmed||wasCancelled)) {
boolean cancelled = wasCancelled;
wasCancelled = false;
wasConfirmed = false;
dismissalListener.onTextObtained(dialogId, results, cancelled, keepPassword);
dismissalListener.onTextObtained(dialogId, results, cancelled, keepPassword, b_results);
}
super.onDismiss(dialog);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private void showGetTextFragment(String tag, String dialogId, String title,
c.pd.dismiss();
}
GetTextFragment frag = GetTextFragment.newInstance(dialogId, title, dismissalListener,
dialogType, messageNum, errorNum, t1, t2, t3, keep);
dialogType, messageNum, errorNum, t1, t2, t3, keep, false);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is always false, why is it a constructor parameter and not a constant?

frag.setCancelable(false);
frag.show(fm, tag);
}
Expand All @@ -124,7 +124,7 @@ private void showGetTextFragmentRemoteCanvas(String tag, String dialogId, String
c.pd.dismiss();
}
GetTextFragment frag = GetTextFragment.newInstance(dialogId, title, dismissalListener,
dialogType, messageNum, errorNum, t1, t2, t3, keep);
dialogType, messageNum, errorNum, t1, t2, t3, keep, false);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is always false, why is it a constructor parameter and not a constant?

frag.setCancelable(false);
frag.show(fm, tag);
}
Expand Down Expand Up @@ -452,7 +452,7 @@ public void handleMessage(final Message msg) {
break;
case RemoteClientLibConstants.RDP_CONNECT_FAILURE:
if (c.maintainConnection) {
c.showFatalMessageAndQuit(context.getString(R.string.error_rdp_connection_failed));
c.showFatalMessageAndQuitTimer(context.getString(R.string.error_rdp_connection_failed));
}
break;
case RemoteClientLibConstants.RDP_UNABLE_TO_CONNECT:
Expand Down
Loading