Skip to content

Commit c5a4b5e

Browse files
authored
Merge pull request #14 from superus8r/hotfix/superuser/FixCrashOnConnectionLost
[Hotfix] fix crash on device connection lost event
2 parents e939d63 + 9354ea3 commit c5a4b5e

File tree

8 files changed

+104
-7
lines changed

8 files changed

+104
-7
lines changed

.circleci/config.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
version: 2.1
2+
3+
jobs:
4+
android-test:
5+
macos:
6+
xcode: "11.2.0"
7+
working_directory: ~/repo/App
8+
steps:
9+
- checkout:
10+
path: ~/repo
11+
12+
- run:
13+
name: set ANDROID_SDK_ROOT
14+
command: |
15+
echo 'export ANDROID_SDK_ROOT=$HOME/android-tools' >> $BASH_ENV
16+
17+
- restore_cache:
18+
key: android=tools-v1-{{ checksum "scripts/install-android-tools.sh" }}-{{ arch }}
19+
20+
- run:
21+
name: install android tools
22+
command: |
23+
sh scripts/install-android-tools.sh
24+
echo 'export PATH=$ANDROID_SDK_ROOT/tools/bin:$PATH' >> $BASH_ENV
25+
echo 'export PATH=$ANDROID_SDK_ROOT/tools:$PATH' >> $BASH_ENV
26+
echo 'export PATH=$ANDROID_SDK_ROOT/platform-tools:$PATH' >> $BASH_ENV
27+
echo 'export PATH=$ANDROID_SDK_ROOT/emulator:$PATH' >> $BASH_ENV
28+
source $BASH_ENV
29+
sdkmanager --list
30+
31+
- save_cache:
32+
key: android=tools-v1-{{ checksum "scripts/install-android-tools.sh" }}-{{ arch }}
33+
paths:
34+
- /Users/distiller/android-tools
35+
36+
- run:
37+
name: create AVD
38+
command: make create-avd
39+
40+
- run:
41+
name: start AVD
42+
command: emulator-headless -avd android-tablet
43+
background: true
44+
45+
- run:
46+
name: wait for emulator
47+
command: adb wait-for-device shell 'while [[ -z $(getprop dev.bootcomplete) ]]; do sleep 1; done;'
48+
49+
- run: adb shell screencap -p > screenshots/before.png
50+
51+
# (insert testing here)
52+
53+
- store_artifacts:
54+
path: screenshots
55+
56+
workflows:
57+
workflow:
58+
jobs:
59+
- android-test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,4 @@ app/build.gradle
9595
.idea/misc.xml
9696
.idea/.name
9797
.idea/codeStyles/Project.xml
98+
.idea/misc.xml

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
The Joystick is removed for the first release.
2525

2626
## Tests
27-
Under Construction
27+
Currently, there are some basic tests to run on the CI, but needs improvements.
28+
UI tests will be completed once the project is migrated to Jetpack Compose.
2829

2930
## Sentry Reports
3031
The project uses Sentry for the crash reports, if this is not needed, you can remove the following line in `AndroidManifest.xml`:

app/build.gradle

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ apply plugin: 'kotlin-android'
33
apply plugin: 'koin'
44

55
repositories {
6-
jcenter()
76
}
87

98
android {
@@ -18,9 +17,8 @@ android {
1817
applicationId "org.kabiri.android.usbterminal"
1918
minSdkVersion 23
2019
targetSdkVersion 30
21-
versionCode 8
22-
versionName "0.7.1"
23-
20+
versionCode 9
21+
versionName "0.7.9"
2422
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
2523
}
2624

app/src/main/java/org/kabiri/android/usbterminal/arduino/ArduinoHelper.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,17 @@ class ArduinoHelper(private val context: Context,
6262
_liveInfoOutput.postValue(context.getString(R.string.helper_info_usb_permission_requested))
6363
} else {
6464
_liveErrorOutput.postValue(context.getString(R.string.helper_error_device_not_found))
65-
connection.close()
65+
try {
66+
connection.close()
67+
} catch (e: UninitializedPropertyAccessException) {
68+
_liveErrorOutput.postValue(context.getString(
69+
R.string.helper_error_connection_not_ready_to_close))
70+
_liveErrorOutput.postValue(e.message)
71+
} catch (e: Exception) {
72+
_liveErrorOutput.postValue(context.getString(
73+
R.string.helper_error_connection_failed_to_close))
74+
_liveErrorOutput.postValue(e.message)
75+
}
6676
}
6777
}
6878
} else {

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
<string name="helper_error_serial_connection_not_opened">\nPort not opened - There might be a problem with the serial connection to Arduino</string>
1919
<string name="helper_error_write_problem">Serial Write encountered an error:</string>
2020
<string name="helper_error_connection_closed_unexpectedly">Device connection was closed unexpectedly</string>
21+
<string name="helper_error_connection_not_ready_to_close">No device connection to close</string>
22+
<string name="helper_error_connection_failed_to_close">Device connection failed to close</string>
2123
<string name="helper_info_serial_connection_opened">\nSerial Connection Opened</string>
2224
<string name="helper_info_usb_permission_requested">Requested permission to access the USB device…</string>
2325
<string name="helper_info_checking_attached_usb_devices">\nChecking attached USB devices…</string>

scripts/install-android-tools.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
if [ -d $ANDROID_SDK_ROOT ]
2+
then
3+
echo "Directory $ANDROID_SDK_ROOT already exists so we're skipping the install. If you'd like to install fresh tools, edit this script to invalidate the CI cache."
4+
exit 0
5+
fi
6+
7+
mkdir -p $ANDROID_SDK_ROOT
8+
cd $ANDROID_SDK_ROOT
9+
curl https://dl.google.com/android/repository/sdk-tools-darwin-4333796.zip -o sdk-tools.zip
10+
11+
unzip sdk-tools.zip
12+
13+
mkdir -p "$ANDROID_SDK_ROOT/licenses"
14+
15+
echo "24333f8a63b6825ea9c5514f83c2829b004d1fee" > "$ANDROID_SDK_ROOT/licenses/android-sdk-license"
16+
echo "84831b9409646a918e30573bab4c9c91346d8abd" > "$ANDROID_SDK_ROOT/licenses/android-sdk-preview-license"
17+
echo "d975f751698a77b662f1254ddbeed3901e976f5a" > "$ANDROID_SDK_ROOT/licenses/intel-android-extra-license"
18+
19+
SDKMANAGER=$ANDROID_SDK_ROOT/tools/bin/sdkmanager
20+
21+
$SDKMANAGER "platform-tools"
22+
$SDKMANAGER "platforms;android-29"
23+
$SDKMANAGER "build-tools;29.0.2"
24+
$SDKMANAGER "ndk-bundle"
25+
$SDKMANAGER "system-images;android-29;google_apis;x86_64"
26+
$SDKMANAGER "emulator"

0 commit comments

Comments
 (0)