From 4f1aaa6aea98b91335fd3ddf4d168adb33ccc542 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sat, 15 Aug 2020 22:42:58 -0400 Subject: [PATCH] Android progress --- android/app/build.gradle | 1 + .../src/main/java/com/rusefi/app/rusEFI.java | 28 +++++++++++++++++-- .../main/java/com/rusefi/config/Field.java | 1 + 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index baf28ad1f7..803dc8af52 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -34,6 +34,7 @@ android { dependencies { implementation project(':ecu_io') + implementation project(':autoupdate') implementation project(':logging-api') implementation project(':shared_io') implementation project(':models') diff --git a/android/app/src/main/java/com/rusefi/app/rusEFI.java b/android/app/src/main/java/com/rusefi/app/rusEFI.java index 94d8a6c549..6459730bfa 100644 --- a/android/app/src/main/java/com/rusefi/app/rusEFI.java +++ b/android/app/src/main/java/com/rusefi/app/rusEFI.java @@ -23,10 +23,12 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.SharedPreferences; import android.hardware.usb.UsbDevice; import android.hardware.usb.UsbManager; import android.os.Build; import android.os.Bundle; +import android.preference.PreferenceManager; import android.text.Editable; import android.text.TextWatcher; import android.view.View; @@ -50,6 +52,10 @@ import com.rusefi.io.DfuHelper; import com.rusefi.io.IoStream; import com.rusefi.io.LinkManager; import com.rusefi.io.serial.StreamConnector; +import com.rusefi.proxy.NetworkConnector; +import com.rusefi.proxy.NetworkConnectorContext; + +import static com.rusefi.ui.storage.PersistentConfiguration.getConfig; public class rusEFI extends Activity { private static final String ACTION_USB_PERMISSION = "com.android.example.USB_PERMISSION"; @@ -99,7 +105,10 @@ public class rusEFI extends Activity { public void afterTextChanged(Editable editable) { String text = authToken.getText().toString(); if (AutoTokenUtil.isToken(text)) { - AutoTokenUtil.setAuthToken(text); + SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(rusEFI.this); + SharedPreferences.Editor editor = preferences.edit(); + editor.putString(AutoTokenUtil.AUTH_TOKEN, text); + editor.commit(); } } }); @@ -112,13 +121,18 @@ public class rusEFI extends Activity { dfuUpload = new DfuUpload(this); dfuUpload.fileOperation(mResultView); - authToken.setText(AutoTokenUtil.getAuthToken()); + authToken.setText(getAuthToken()); switchOrProgramDfu(); SoundBroadcast.checkOrRequestPermission(this); } + private String getAuthToken() { + SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(rusEFI.this); + return preferences.getString(AutoTokenUtil.AUTH_TOKEN, AutoTokenUtil.TOKEN_WARNING); + } + @Override protected void onDestroy() { super.onDestroy(); @@ -238,9 +252,17 @@ public class rusEFI extends Activity { } }); - Snackbar mySnackbar = Snackbar.make(view, "Broadcasting with " + AutoTokenUtil.getAuthToken(), BaseTransientBottomBar.LENGTH_LONG); + Snackbar mySnackbar = Snackbar.make(view, "Broadcasting with " + getAuthToken(), BaseTransientBottomBar.LENGTH_LONG); mySnackbar.show(); + NetworkConnectorContext context = new NetworkConnectorContext(); + new NetworkConnector().start(getAuthToken(), context, new NetworkConnector.ReconnectListener() { + @Override + public void onReconnect() { + + } + }, linkManager); + } } diff --git a/java_console/inifile/src/main/java/com/rusefi/config/Field.java b/java_console/inifile/src/main/java/com/rusefi/config/Field.java index 5aff9e9a12..0e08fe8fde 100644 --- a/java_console/inifile/src/main/java/com/rusefi/config/Field.java +++ b/java_console/inifile/src/main/java/com/rusefi/config/Field.java @@ -208,6 +208,7 @@ public class Field { } public String getStringValue(ConfigurationImage image) { + Objects.requireNonNull(image, "image"); if (type != STRING) throw new IllegalStateException("Not a string parameter " + name); ByteBuffer bb = image.getByteBuffer(offset, stringSize);