Skip to content
Open
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
97 changes: 96 additions & 1 deletion app/src/main/java/com/openipc/pixelpilot/VideoActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ public void run() {
private ConstraintSet constraintSet;
private WfbNgLink wfbLink;

private static final String PREF_DRONE_USERNAME = "drone_username";
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd prefer to have it working by default - i.e. having the root/12345 if nothing else was chosen

Copy link
Collaborator

Choose a reason for hiding this comment

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

since root/12345 is publicly disclosed as the default OpenIPC password, I believe it doesn't make sense to hide it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A few days ago I opened Drone Settings, and the WebUI page required me to set a new password, so I set 123456 (not knowing 12345 is the default). I could never open Drone Settings ever since... the root/12345 will still be default, the credentials option is added just in case.

private static final String PREF_DRONE_PASSWORD = "drone_password";

public boolean getVRSetting() {
return getSharedPreferences("general", Context.MODE_PRIVATE).getBoolean("vr-mode", false);
}
Expand Down Expand Up @@ -888,6 +891,13 @@ private void setupDroneSubMenu(PopupMenu popup) {
startBrowser();
return true;
});

// Add a new option to manage login credentials
MenuItem loginCredentials = drone.add("Login Credentials");
loginCredentials.setOnMenuItemClickListener(item -> {
showLoginCredentialsDialog();
return true;
});
}

/**
Expand Down Expand Up @@ -1495,6 +1505,88 @@ private void copyGSKey() {
}
}

private void showLoginCredentialsDialog() {
// Create a LinearLayout to hold our EditText fields
android.widget.LinearLayout layout = new android.widget.LinearLayout(this);
layout.setOrientation(android.widget.LinearLayout.VERTICAL);
layout.setPadding(50, 30, 50, 30); // Add some padding around the content

// EditText for username
final android.widget.EditText usernameEditText = new android.widget.EditText(this);
usernameEditText.setHint("Username");
usernameEditText.setText(getDroneUsername()); // Pre-fill with current saved username
layout.addView(usernameEditText);

// EditText for password
final android.widget.EditText passwordEditText = new android.widget.EditText(this);
passwordEditText.setHint("Password");
// Mask the password input
passwordEditText.setInputType(android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_PASSWORD);
passwordEditText.setText(getDronePassword()); // Pre-fill with current saved password
layout.addView(passwordEditText);

// CheckBox to toggle password visibility
final android.widget.CheckBox showPasswordCheckBox = new android.widget.CheckBox(this);
showPasswordCheckBox.setText("Show Password");
layout.addView(showPasswordCheckBox);

// Set a listener for the CheckBox
showPasswordCheckBox.setOnCheckedChangeListener((buttonView, isChecked) -> {
if (isChecked) {
// If checked, show the password (visible_password)
passwordEditText.setInputType(android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
} else {
// If unchecked, hide the password (password)
passwordEditText.setInputType(android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_PASSWORD);
}
// Move the cursor to the end of the text to prevent it from jumping to the beginning
passwordEditText.setSelection(passwordEditText.getText().length());
});

// Build and show the AlertDialog
new android.app.AlertDialog.Builder(this)
.setTitle("Drone Login Credentials")
.setView(layout) // Set our custom layout
.setPositiveButton("Save", (dialog, which) -> {
// Save the new values to SharedPreferences
setDroneUsername(usernameEditText.getText().toString());
setDronePassword(passwordEditText.getText().toString());
Toast.makeText(this, "Drone credentials saved.", Toast.LENGTH_SHORT).show();
})
.setNegativeButton("Cancel", (dialog, which) -> {
dialog.cancel(); // Dismiss the dialog
})
.show();
}

// Helper method to retrieve the drone username
// Provides a default "root" if not yet set, for initial compatibility.
private String getDroneUsername() {
return getSharedPreferences("general", Context.MODE_PRIVATE).getString(PREF_DRONE_USERNAME, "root");
}

// Helper method to save the drone username
private void setDroneUsername(String username) {
SharedPreferences prefs = getSharedPreferences("general", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
editor.putString(PREF_DRONE_USERNAME, username);
editor.apply();
}

// Helper method to retrieve the drone password
// Provides a default "12345" if not yet set, for initial compatibility.
private String getDronePassword() {
return getSharedPreferences("general", Context.MODE_PRIVATE).getString(PREF_DRONE_PASSWORD, "12345");
}

// Helper method to save the drone password
private void setDronePassword(String password) {
SharedPreferences prefs = getSharedPreferences("general", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
editor.putString(PREF_DRONE_PASSWORD, password);
editor.apply();
}

@SuppressLint("SetJavaScriptEnabled")
public void startBrowser() {
WebView view = new WebView(this);
Expand All @@ -1518,7 +1610,10 @@ public void startBrowser() {
@Override
public void onReceivedHttpAuthRequest(
WebView view, HttpAuthHandler handler, String host, String realm) {
handler.proceed("root", "12345");
// Retrieve username and password from SharedPreferences
String username = getDroneUsername();
String password = getDronePassword();
handler.proceed(username, password);
}
});
}
Expand Down