Skip to content

Commit

Permalink
add new command : remove force upgrade prompt on gogles after using d…
Browse files Browse the repository at this point in the history
…ji fly app
  • Loading branch information
fredakilla committed May 7, 2022
1 parent 789d287 commit 4946a4e
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 27 deletions.
4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
Expand Down
101 changes: 75 additions & 26 deletions app/src/main/java/com/htetznaing/adbotg/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,8 @@ private void test(){
// djeye-tools new stuff from here
// ---------------------------------------------------

private AlertDialog dialog;
private String commandResult = ""; // result of command shell
private AlertDialog dialog; // alert dialog

void show(String title, String message)
{
Expand Down Expand Up @@ -585,17 +586,24 @@ public void onClick(View v) {
});
}

private String runShellCommand(String singleCommand) {
/*private String runShellCommand(String singleCommand) {
logs.append("\n" + singleCommand + "\n");
String result = "";
try {
AdbStream stream = adbConnection.open(singleCommand);
while (!stream.isClosed()) {
try {
result = new String(stream.read(), "US-ASCII");
result += new String(stream.read(), "US-ASCII");
System.out.println("reading stream...");
System.out.println(result);
logs.append(result);
final String[] output = {new String(stream.read(), "US-ASCII")};
System.out.println(output[0]);
logs.append(output[0]);
} finally {
// there must be a Stream Close Exception
break;
Expand All @@ -614,12 +622,21 @@ private String runShellCommand(String singleCommand) {
return result;
}
return result;
}*/


// Wrapping interface
private interface FunctionPointer {
// Method signatures of pointed method
void methodSignature(String commandResult);
}

private void findMyDjiFpvDrone_command() {
String command = "shell: cat /blackbox/last_drone_info";
private void runShellCommand(String command, FunctionPointer func) {
logs.setText("# " + command + "\n");

// clear result string
commandResult = "";

// Open the shell stream of ADB
try {
stream = adbConnection.open(command);
Expand All @@ -634,14 +651,17 @@ private void findMyDjiFpvDrone_command() {
return;
}

// Start the receiving thread
new Thread(new Runnable() {
new Thread(new Runnable() {
@Override
public void run() {
while (!stream.isClosed()) {
try {
// Print each thing we read from the shell stream
final String[] output = {new String(stream.read(), "US-ASCII")};

// append thing we read to the result command string
commandResult += output[0];

runOnUiThread(new Runnable() {
@Override
public void run() {
Expand All @@ -651,15 +671,10 @@ public void run() {
System.out.println("End => " + user);
}

// append string to logs text view
logs.append(output[0]);

// get result
try {
if(findMyDjiFpvDrone(logs.getText().toString()))
stream.close();
} catch (IOException e) {
}

// scroll view
scrollView.post(new Runnable() {
@Override
public void run() {
Expand All @@ -668,6 +683,7 @@ public void run() {
});
}
});

} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return;
Expand All @@ -676,17 +692,45 @@ public void run() {
return;
} catch (IOException e) {
e.printStackTrace();
return;
// the stream may be closed
}
}

// stream was closed,
runOnUiThread(new Runnable() {
@Override
public void run() {
// call the FunctionPointer method
System.out.println("commandResult");
func.methodSignature(commandResult);
}
});

}
}).start();
}

private boolean findMyDjiFpvDrone(String result) {
//------------------------------------------------------------------------------------
// Find My DJI FPV drone
// - get last gps location in /blackbox/last_drone_info file
// - open google maps and locate
//------------------------------------------------------------------------------------

private void findMyDjiFpvDrone_command() {
logs.setText("# Find my DJI FPV drone\n");
runShellCommand("shell: cat /blackbox/last_drone_info", this::findMyDjiFpvDrone);
}

private void findMyDjiFpvDrone(String result) {
double latitude = 0;
double longitude = 0;

// check if command result contains the gps info
if (!result.contains("lantitude") || !result.contains("longitude")) {
logs.append("findMyDjiFpvDrone : Unable to get last gps drone information");
return;
}

// get last gps coord in result
String[] lines = result.split("\\r?\\n");
for (String line : lines){
Expand All @@ -710,24 +754,29 @@ private boolean findMyDjiFpvDrone(String result) {
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);

return true;
}
else {
// longitude or latitude == 0
logs.append("\nWarning : last latitude or longitude is null, unable to find the drone");
}

return false;
}

//------------------------------------------------------------------------------------
// Remove Force Upgrade Prompt
// - remove force upgrade prompt on goggles after using dji fly app
//------------------------------------------------------------------------------------

private void doNothing(String result) {
// nothing special here
}

// option to remove force upgrade prompt on goggles after using dji fly app
private void removeForceUpgradePrompt_command() {
logs.setText("# Remove force upgrade prompt\n");
runShellCommand("shell: rm /cache/force_upgrade");
runShellCommand("shell: setprop dji.prop.enforce_upgrade 0");
runShellCommand("shell: reboot");
runShellCommand("shell: rm /cache/force_upgrade", this::doNothing);
runShellCommand("shell: setprop dji.prop.enforce_upgrade 0", this::doNothing);
runShellCommand("shell: reboot", (String) -> { logs.append("Reboot..."); });
}




}

4 changes: 3 additions & 1 deletion app/src/main/java/com/htetznaing/adbotg/UsbReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager;
import android.util.Log;

Expand All @@ -14,7 +15,8 @@ public void onReceive(Context context, Intent intent) {
String action;
if (intent!=null && (action = intent.getAction()) !=null && action.equals(UsbManager.ACTION_USB_DEVICE_ATTACHED)){
Intent intent1 = new Intent(USB_PERMISSION);
intent1.putExtra(UsbManager.EXTRA_DEVICE,intent.getParcelableExtra(UsbManager.EXTRA_DEVICE));
UsbDevice usbDevice = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
intent1.putExtra(UsbManager.EXTRA_DEVICE, usbDevice);
Log.d("UsbReceiver","Broadcasting USB_CONNECTED");
context.sendBroadcast(intent1);
}
Expand Down

0 comments on commit 4946a4e

Please # to comment.