diff options
author | Alexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com> | 2023-08-13 21:06:09 +0300 |
---|---|---|
committer | Alexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com> | 2023-08-13 21:06:09 +0300 |
commit | aa8aa784f89929cd615771bc3f61307fc3631c4a (patch) | |
tree | 98df092fbf822528b9ecbf8b548ef1af8fc4b6f2 | |
parent | e8f38fb08649ebb6069818de0ebfa605d566912a (diff) |
Libraries and SDK upgrade
-rw-r--r-- | .idea/compiler.xml | 2 | ||||
-rw-r--r-- | .idea/misc.xml | 3 | ||||
-rw-r--r-- | app/build.gradle | 19 | ||||
-rw-r--r-- | app/src/main/AndroidManifest.xml | 6 | ||||
-rw-r--r-- | app/src/main/java/com/clusterrr/usbserialtelnetserver/BootCompletedReceiver.java | 2 | ||||
-rw-r--r-- | app/src/main/java/com/clusterrr/usbserialtelnetserver/MainActivity.java | 44 | ||||
-rw-r--r-- | app/src/main/java/com/clusterrr/usbserialtelnetserver/UsbSerialTelnetService.java | 47 | ||||
-rw-r--r-- | app/src/main/java/com/clusterrr/usbserialtelnetserver/UsbSerialThread.java | 2 | ||||
-rw-r--r-- | app/src/main/res/xml/usb_device_filter.xml | 58 | ||||
-rw-r--r-- | build.gradle | 4 | ||||
-rw-r--r-- | gradle.properties | 4 | ||||
-rw-r--r-- | gradle/wrapper/gradle-wrapper.properties | 2 |
12 files changed, 110 insertions, 83 deletions
diff --git a/.idea/compiler.xml b/.idea/compiler.xml index fb7f4a8..b589d56 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <project version="4"> <component name="CompilerConfiguration"> - <bytecodeTargetLevel target="11" /> + <bytecodeTargetLevel target="17" /> </component> </project>
\ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index a0f7380..e4decd9 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,3 @@ -<?xml version="1.0" encoding="UTF-8"?> <project version="4"> <component name="DesignSurface"> <option name="filePathToZoomLevelMap"> @@ -10,7 +9,7 @@ </map> </option> </component> - <component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="Android Studio default JDK" project-jdk-type="JavaSDK"> + <component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK"> <output url="file://$PROJECT_DIR$/build/classes" /> </component> <component name="ProjectType"> diff --git a/app/build.gradle b/app/build.gradle index 2a76a8c..5d5adff 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -3,14 +3,14 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.clusterrr.usbserialtelnetserver" minSdk 19 - targetSdk 32 - versionCode 7 - versionName "1.4" + targetSdk 33 + versionCode 8 + versionName "1.5" } buildTypes { @@ -24,8 +24,9 @@ android { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } + namespace 'com.clusterrr.usbserialtelnetserver' - applicationVariants.all { variant -> + applicationVariants.configureEach { variant -> variant.outputs.all { output -> def formattedDate = new Date().format('yyMMdd-HHmmss') outputFileName = "UsbSerialTelnetServer-v${defaultConfig.versionCode}-${formattedDate}.apk" @@ -34,8 +35,8 @@ android { } dependencies { - implementation 'androidx.appcompat:appcompat:1.4.1' - implementation 'com.google.android.material:material:1.6.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' - implementation 'com.github.mik3y:usb-serial-for-android:3.4.3' + implementation 'androidx.appcompat:appcompat:1.6.1' + implementation 'com.google.android.material:material:1.9.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' + implementation 'com.github.mik3y:usb-serial-for-android:3.5.1' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9c80c86..facc8b0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,10 +1,12 @@ <?xml version="1.0" encoding="utf-8"?> -<manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.clusterrr.usbserialtelnetserver"> +<manifest xmlns:android="http://schemas.android.com/apk/res/android"> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" /> + <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> + + <uses-feature android:name="android.hardware.usb.host" /> <application android:allowBackup="true" diff --git a/app/src/main/java/com/clusterrr/usbserialtelnetserver/BootCompletedReceiver.java b/app/src/main/java/com/clusterrr/usbserialtelnetserver/BootCompletedReceiver.java index aa2268b..3a80fba 100644 --- a/app/src/main/java/com/clusterrr/usbserialtelnetserver/BootCompletedReceiver.java +++ b/app/src/main/java/com/clusterrr/usbserialtelnetserver/BootCompletedReceiver.java @@ -17,7 +17,7 @@ public class BootCompletedReceiver extends BroadcastReceiver { boolean needToStart = prefs.getBoolean(UsbSerialTelnetService.KEY_LAST_STATE, false); if (needToStart) { Intent mainActivityStartIntent = new Intent(context, MainActivity.class); - mainActivityStartIntent.setAction(UsbSerialTelnetService.ACTION_NEED_TO_START); + context.startActivity(mainActivityStartIntent); } } }
\ No newline at end of file diff --git a/app/src/main/java/com/clusterrr/usbserialtelnetserver/MainActivity.java b/app/src/main/java/com/clusterrr/usbserialtelnetserver/MainActivity.java index cdb8454..6d539ee 100644 --- a/app/src/main/java/com/clusterrr/usbserialtelnetserver/MainActivity.java +++ b/app/src/main/java/com/clusterrr/usbserialtelnetserver/MainActivity.java @@ -17,7 +17,6 @@ import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; -import android.os.Looper; import android.os.PowerManager; import android.provider.Settings; import android.util.Log; @@ -56,12 +55,16 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe private Switch mNoLocalEcho; private Switch mRemoveLF; + private boolean isStarted() { + return mServiceBinder != null && mServiceBinder.isStarted(); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - mHandler = new Handler(Looper.getMainLooper()); + mHandler = new Handler(); mStartButton = findViewById(R.id.buttonStart); mStopButton = findViewById(R.id.buttonStop); @@ -78,15 +81,19 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe mStopButton.setOnClickListener(this); Intent serviceIntent = new Intent(this, UsbSerialTelnetService.class); - bindService(serviceIntent, serviceConnection, 0); // in case it's service already started + bindService(serviceIntent, serviceConnection, 0); // in case if service already started updateSettings(); - boolean started = mServiceBinder != null && mServiceBinder.isStarted(); - if (!started) { - SharedPreferences prefs = getApplicationContext().getSharedPreferences(getString(R.string.app_name), Context.MODE_PRIVATE); - boolean needToStart = prefs.getBoolean(UsbSerialTelnetService.KEY_LAST_STATE, false); - if (needToStart) start(); + SharedPreferences prefs = getApplicationContext().getSharedPreferences(getString(R.string.app_name), Context.MODE_PRIVATE); + boolean needToStart = prefs.getBoolean(UsbSerialTelnetService.KEY_LAST_STATE, false); + if (needToStart) { + mHandler.postDelayed(() -> { + boolean started = mServiceBinder != null && mServiceBinder.isStarted(); + if (!started) { + start(); + } + }, 5000); } } @@ -161,16 +168,22 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe startService(serviceIntent); } bindService(serviceIntent, serviceConnection, 0); + + // Save last state + mHandler.postDelayed(() -> { + boolean started = mServiceBinder != null && mServiceBinder.isStarted(); + SharedPreferences prefsShared = getApplicationContext().getSharedPreferences(getString(R.string.app_name), Context.MODE_PRIVATE); + prefsShared.edit().putBoolean(UsbSerialTelnetService.KEY_LAST_STATE, started).commit(); + Log.d(UsbSerialTelnetService.TAG, "Last state saved: " + started); + }, 500); } private void stop() { Intent serviceIntent = new Intent(this, UsbSerialTelnetService.class); stopService(serviceIntent); mServiceBinder = null; - mHandler.postDelayed(() -> { - SharedPreferences prefs = getApplicationContext().getSharedPreferences(getString(R.string.app_name), Context.MODE_PRIVATE); - prefs.edit().putBoolean(UsbSerialTelnetService.KEY_LAST_STATE, false).commit(); - }, 50); + SharedPreferences prefs = getApplicationContext().getSharedPreferences(getString(R.string.app_name), Context.MODE_PRIVATE); + prefs.edit().putBoolean(UsbSerialTelnetService.KEY_LAST_STATE, false).commit(); updateSettings(); } @@ -181,11 +194,8 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe mServiceBinder = (UsbSerialTelnetService.ServiceBinder) service; mServiceBinder.setOnStopListener(MainActivity.this); updateSettings(); - mHandler.postDelayed(() -> { - boolean started = mServiceBinder != null && mServiceBinder.isStarted(); - SharedPreferences prefs = getApplicationContext().getSharedPreferences(getString(R.string.app_name), Context.MODE_PRIVATE); - prefs.edit().putBoolean(UsbSerialTelnetService.KEY_LAST_STATE, started).commit(); - }, 50); + SharedPreferences prefs = getApplicationContext().getSharedPreferences(getString(R.string.app_name), Context.MODE_PRIVATE); + prefs.edit().putBoolean(UsbSerialTelnetService.KEY_LAST_STATE, isStarted()).commit(); Log.d(UsbSerialTelnetService.TAG, "Service connected"); } diff --git a/app/src/main/java/com/clusterrr/usbserialtelnetserver/UsbSerialTelnetService.java b/app/src/main/java/com/clusterrr/usbserialtelnetserver/UsbSerialTelnetService.java index 409027c..b90d445 100644 --- a/app/src/main/java/com/clusterrr/usbserialtelnetserver/UsbSerialTelnetService.java +++ b/app/src/main/java/com/clusterrr/usbserialtelnetserver/UsbSerialTelnetService.java @@ -70,6 +70,30 @@ public class UsbSerialTelnetService extends Service { } String message = getString(R.string.app_name) + " " + getString(R.string.started); + + Intent mainActivityIntent = new Intent(this, MainActivity.class); + PendingIntent mainActivityPendingIntent = PendingIntent.getActivity(this, 0, mainActivityIntent, PendingIntent.FLAG_IMMUTABLE); + NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { + NotificationChannel channel = new NotificationChannel(TAG, + getString(R.string.app_name), + NotificationManager.IMPORTANCE_DEFAULT); + channel.setDescription(getString(R.string.app_name)); + nm.createNotificationChannel(channel); + } + Notification notification = new NotificationCompat.Builder(this, TAG) + .setOngoing(true) + .setSmallIcon(R.drawable.ic_notification) + .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.mipmap.ic_launcher)) + .setContentTitle(message) + .setPriority(NotificationCompat.PRIORITY_DEFAULT) + .setCategory(Notification.CATEGORY_SERVICE) + .setShowWhen(false) + .setContentIntent(mainActivityPendingIntent) + .build(); + + startForeground(1, notification); + boolean success = false; try { @@ -112,34 +136,11 @@ public class UsbSerialTelnetService extends Service { ex.printStackTrace(); } - Intent mainActivityIntent = new Intent(this, MainActivity.class); - PendingIntent mainActivityPendingIntent = PendingIntent.getActivity(this, 0, mainActivityIntent, PendingIntent.FLAG_IMMUTABLE); - NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { - NotificationChannel channel = new NotificationChannel(TAG, - getString(R.string.app_name), - NotificationManager.IMPORTANCE_DEFAULT); - channel.setDescription(getString(R.string.app_name)); - nm.createNotificationChannel(channel); - } - Notification notification = new NotificationCompat.Builder(this, TAG) - .setOngoing(true) - .setSmallIcon(R.drawable.ic_notification) - .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.mipmap.ic_launcher)) - .setContentTitle(message) - .setPriority(NotificationCompat.PRIORITY_DEFAULT) - .setCategory(Notification.CATEGORY_SERVICE) - .setShowWhen(false) - .setContentIntent(mainActivityPendingIntent) - .build(); - if (message != null) { final String msg = message; new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(UsbSerialTelnetService.this.getApplicationContext(), msg, Toast.LENGTH_SHORT).show()); } - startForeground(1, notification); - if (success) { if (message != null) Log.i(TAG, message); diff --git a/app/src/main/java/com/clusterrr/usbserialtelnetserver/UsbSerialThread.java b/app/src/main/java/com/clusterrr/usbserialtelnetserver/UsbSerialThread.java index c2a0adf..97b9738 100644 --- a/app/src/main/java/com/clusterrr/usbserialtelnetserver/UsbSerialThread.java +++ b/app/src/main/java/com/clusterrr/usbserialtelnetserver/UsbSerialThread.java @@ -22,7 +22,7 @@ public class UsbSerialThread extends Thread { public UsbSerialThread(UsbSerialTelnetService usbSerialTelnetService, UsbSerialPort serialPort) { mUsbSerialTelnetService = usbSerialTelnetService; mSerialPort = serialPort; - mHandler = new Handler(Looper.getMainLooper()); + mHandler = new Handler(); } @Override diff --git a/app/src/main/res/xml/usb_device_filter.xml b/app/src/main/res/xml/usb_device_filter.xml index f0608aa..b2a252c 100644 --- a/app/src/main/res/xml/usb_device_filter.xml +++ b/app/src/main/res/xml/usb_device_filter.xml @@ -1,26 +1,38 @@ <?xml version="1.0" encoding="utf-8"?> <resources> - <usb-device product-id="24577" vendor-id="1027" /> - <usb-device product-id="24592" vendor-id="1027" /> - <usb-device product-id="24593" vendor-id="1027" /> - <usb-device product-id="24596" vendor-id="1027" /> - <usb-device product-id="24597" vendor-id="1027" /> - <usb-device product-id="60000" vendor-id="4292" /> - <usb-device product-id="60016" vendor-id="4292" /> - <usb-device product-id="60017" vendor-id="4292" /> - <usb-device product-id="8963" vendor-id="1659" /> - <usb-device product-id="9123" vendor-id="1659" /> - <usb-device product-id="9139" vendor-id="1659" /> - <usb-device product-id="9155" vendor-id="1659" /> - <usb-device product-id="9171" vendor-id="1659" /> - <usb-device product-id="9187" vendor-id="1659" /> - <usb-device product-id="9203" vendor-id="1659" /> - <usb-device product-id="21795" vendor-id="6790" /> - <usb-device product-id="29987" vendor-id="6790" /> - <usb-device vendor-id="9025" /> - <usb-device product-id="1155" vendor-id="5824" /> - <usb-device product-id="8260" vendor-id="1003" /> - <usb-device product-id="4" vendor-id="7855" /> - <usb-device product-id="516" vendor-id="3368" /> - <usb-device product-id="22336" vendor-id="1155" /> + <!-- 0x0403 / 0x60??: FTDI --> + <usb-device vendor-id="1027" product-id="24577" /> <!-- 0x6001: FT232R --> + <usb-device vendor-id="1027" product-id="24592" /> <!-- 0x6010: FT2232H --> + <usb-device vendor-id="1027" product-id="24593" /> <!-- 0x6011: FT4232H --> + <usb-device vendor-id="1027" product-id="24596" /> <!-- 0x6014: FT232H --> + <usb-device vendor-id="1027" product-id="24597" /> <!-- 0x6015: FT230X, FT231X, FT234XD --> + + <!-- 0x10C4 / 0xEA??: Silabs CP210x --> + <usb-device vendor-id="4292" product-id="60000" /> <!-- 0xea60: CP2102 and other CP210x single port devices --> + <usb-device vendor-id="4292" product-id="60016" /> <!-- 0xea70: CP2105 --> + <usb-device vendor-id="4292" product-id="60017" /> <!-- 0xea71: CP2108 --> + + <!-- 0x067B / 0x23?3: Prolific PL2303x --> + <usb-device vendor-id="1659" product-id="8963" /> <!-- 0x2303: PL2303HX, HXD, TA, ... --> + <usb-device vendor-id="1659" product-id="9123" /> <!-- 0x23a3: PL2303GC --> + <usb-device vendor-id="1659" product-id="9139" /> <!-- 0x23b3: PL2303GB --> + <usb-device vendor-id="1659" product-id="9155" /> <!-- 0x23c3: PL2303GT --> + <usb-device vendor-id="1659" product-id="9171" /> <!-- 0x23d3: PL2303GL --> + <usb-device vendor-id="1659" product-id="9187" /> <!-- 0x23e3: PL2303GE --> + <usb-device vendor-id="1659" product-id="9203" /> <!-- 0x23f3: PL2303GS --> + + <!-- 0x1a86 / 0x?523: Qinheng CH34x --> + <usb-device vendor-id="6790" product-id="21795" /> <!-- 0x5523: CH341A --> + <usb-device vendor-id="6790" product-id="29987" /> <!-- 0x7523: CH340 --> + + <!-- CDC driver --> + <usb-device vendor-id="9025" /> <!-- 0x2341 / ......: Arduino --> + <usb-device vendor-id="5824" product-id="1155" /> <!-- 0x16C0 / 0x0483: Teensyduino --> + <usb-device vendor-id="1003" product-id="8260" /> <!-- 0x03EB / 0x2044: Atmel Lufa --> + <usb-device vendor-id="7855" product-id="4" /> <!-- 0x1eaf / 0x0004: Leaflabs Maple --> + <usb-device vendor-id="3368" product-id="516" /> <!-- 0x0d28 / 0x0204: ARM mbed --> + <usb-device vendor-id="1155" product-id="22336" /><!-- 0x0483 / 0x5740: ST CDC --> + <usb-device vendor-id="11914" product-id="5" /> <!-- 0x2E8A / 0x0005: Raspberry Pi Pico Micropython --> + <usb-device vendor-id="11914" product-id="10" /> <!-- 0x2E8A / 0x000A: Raspberry Pi Pico SDK --> + <usb-device vendor-id="6790" product-id="21972" /><!-- 0x1A86 / 0x55D4: Qinheng CH9102F --> </resources> diff --git a/build.gradle b/build.gradle index 2fcc7ef..56b5a41 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { - id 'com.android.application' version '7.1.2' apply false - id 'com.android.library' version '7.1.2' apply false + id 'com.android.application' version '8.1.0' apply false + id 'com.android.library' version '8.1.0' apply false } task clean(type: Delete) { diff --git a/gradle.properties b/gradle.properties index dab7c28..ec63151 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,4 +18,6 @@ android.useAndroidX=true # Enables namespacing of each library's R class so that its R class includes only the # resources declared in the library itself and none from the library's dependencies, # thereby reducing the size of the R class for that library -android.nonTransitiveRClass=true
\ No newline at end of file +android.nonTransitiveRClass=true +android.defaults.buildfeatures.buildconfig=true +android.nonFinalResIds=false
\ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 38fefc9..89b6ace 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Fri May 27 11:38:17 MSK 2022 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME |