diff options
26 files changed, 875 insertions, 0 deletions
diff --git a/obd2-lib/src/com/android/car/obd2/Obd2Connection.java b/obd2-lib/src/com/android/car/obd2/Obd2Connection.java index bfdb9c0f..577b7989 100644 --- a/obd2-lib/src/com/android/car/obd2/Obd2Connection.java +++ b/obd2-lib/src/com/android/car/obd2/Obd2Connection.java | |||
@@ -72,6 +72,10 @@ public class Obd2Connection { | |||
72 | return true; | 72 | return true; |
73 | } | 73 | } |
74 | 74 | ||
75 | public boolean isConnected() { | ||
76 | return mConnection.isConnected(); | ||
77 | } | ||
78 | |||
75 | static int toDigitValue(char c) { | 79 | static int toDigitValue(char c) { |
76 | if ((c >= '0') && (c <= '9')) return c - '0'; | 80 | if ((c >= '0') && (c <= '9')) return c - '0'; |
77 | switch (c) { | 81 | switch (c) { |
diff --git a/obd2-lib/src/com/android/car/obd2/Obd2LiveFrameGenerator.java b/obd2-lib/src/com/android/car/obd2/Obd2LiveFrameGenerator.java index 121b54aa..3fffd22b 100644 --- a/obd2-lib/src/com/android/car/obd2/Obd2LiveFrameGenerator.java +++ b/obd2-lib/src/com/android/car/obd2/Obd2LiveFrameGenerator.java | |||
@@ -56,6 +56,16 @@ public class Obd2LiveFrameGenerator { | |||
56 | mFloatCommands.add( | 56 | mFloatCommands.add( |
57 | Obd2Command.getLiveFrameCommand( | 57 | Obd2Command.getLiveFrameCommand( |
58 | Obd2Command.getFloatCommand(pid)))); | 58 | Obd2Command.getFloatCommand(pid)))); |
59 | Log.i( | ||
60 | TAG, | ||
61 | String.format( | ||
62 | "connectionPids = %s\napiIntegerPids=%s\napiFloatPids = %s\n" | ||
63 | + "mIntegerCommands = %s\nmFloatCommands = %s\n", | ||
64 | connectionPids, | ||
65 | apiIntegerPids, | ||
66 | apiFloatPids, | ||
67 | mIntegerCommands, | ||
68 | mFloatCommands)); | ||
59 | } | 69 | } |
60 | 70 | ||
61 | public JsonWriter generate(JsonWriter jsonWriter) throws IOException { | 71 | public JsonWriter generate(JsonWriter jsonWriter) throws IOException { |
diff --git a/tests/obd2_app/Android.mk b/tests/obd2_app/Android.mk new file mode 100644 index 00000000..7e1e22fa --- /dev/null +++ b/tests/obd2_app/Android.mk | |||
@@ -0,0 +1,40 @@ | |||
1 | # Copyright (C) 2017 The Android Open Source Project | ||
2 | # | ||
3 | # Licensed under the Apache License, Version 2.0 (the "License"); | ||
4 | # you may not use this file except in compliance with the License. | ||
5 | # You may obtain a copy of the License at | ||
6 | # | ||
7 | # http://www.apache.org/licenses/LICENSE-2.0 | ||
8 | # | ||
9 | # Unless required by applicable law or agreed to in writing, software | ||
10 | # distributed under the License is distributed on an "AS IS" BASIS, | ||
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
12 | # See the License for the specific language governing permissions and | ||
13 | # limitations under the License. | ||
14 | # | ||
15 | # | ||
16 | |||
17 | LOCAL_PATH:= $(call my-dir) | ||
18 | |||
19 | include $(CLEAR_VARS) | ||
20 | |||
21 | LOCAL_SRC_FILES := $(call all-java-files-under, src) | ||
22 | |||
23 | LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res | ||
24 | |||
25 | LOCAL_PACKAGE_NAME := Obd2App | ||
26 | |||
27 | LOCAL_AAPT_FLAGS := --auto-add-overlay | ||
28 | |||
29 | LOCAL_MODULE_TAGS := optional | ||
30 | |||
31 | LOCAL_PROGUARD_ENABLED := disabled | ||
32 | |||
33 | LOCAL_DEX_PREOPT := false | ||
34 | |||
35 | LOCAL_STATIC_JAVA_LIBRARIES += \ | ||
36 | com.android.car.obd2 \ | ||
37 | |||
38 | LOCAL_JAVA_VERSION := 1.8 | ||
39 | |||
40 | include $(BUILD_PACKAGE) | ||
diff --git a/tests/obd2_app/AndroidManifest.xml b/tests/obd2_app/AndroidManifest.xml new file mode 100644 index 00000000..184d939c --- /dev/null +++ b/tests/obd2_app/AndroidManifest.xml | |||
@@ -0,0 +1,38 @@ | |||
1 | <?xml version="1.0" encoding="utf-8"?> | ||
2 | |||
3 | <!-- Copyright (C) 2017 The Android Open Source Project | ||
4 | |||
5 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
6 | you may not use this file except in compliance with the License. | ||
7 | You may obtain a copy of the License at | ||
8 | |||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | --> | ||
16 | <manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
17 | package="com.google.android.car.obd2app"> | ||
18 | |||
19 | <uses-permission android:name="android.permission.BLUETOOTH"/> | ||
20 | <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | ||
21 | <application | ||
22 | android:allowBackup="true" | ||
23 | android:debuggable="true" | ||
24 | android:icon="@mipmap/ic_launcher" | ||
25 | android:label="@string/app_name" | ||
26 | android:supportsRtl="true" | ||
27 | android:theme="@style/AppTheme"> | ||
28 | <activity android:name=".MainActivity"> | ||
29 | <intent-filter> | ||
30 | <action android:name="android.intent.action.MAIN" /> | ||
31 | |||
32 | <category android:name="android.intent.category.LAUNCHER" /> | ||
33 | </intent-filter> | ||
34 | </activity> | ||
35 | <activity android:name=".SettingsActivity"/> | ||
36 | </application> | ||
37 | |||
38 | </manifest> | ||
diff --git a/tests/obd2_app/res/drawable/ic_info_black_24dp.xml b/tests/obd2_app/res/drawable/ic_info_black_24dp.xml new file mode 100644 index 00000000..b9139d16 --- /dev/null +++ b/tests/obd2_app/res/drawable/ic_info_black_24dp.xml | |||
@@ -0,0 +1,24 @@ | |||
1 | <?xml version="1.0" encoding="utf-8"?> | ||
2 | <!-- Copyright (C) 2017 The Android Open Source Project | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | --> | ||
16 | <vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
17 | android:height="24dp" | ||
18 | android:viewportHeight="24.0" | ||
19 | android:viewportWidth="24.0" | ||
20 | android:width="24dp"> | ||
21 | <path | ||
22 | android:fillColor="#FF000000" | ||
23 | android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zm1,15h-2v-6h2v6zm0,-8h-2V7h2v2z"/> | ||
24 | </vector> | ||
diff --git a/tests/obd2_app/res/drawable/ic_notifications_black_24dp.xml b/tests/obd2_app/res/drawable/ic_notifications_black_24dp.xml new file mode 100644 index 00000000..486956c5 --- /dev/null +++ b/tests/obd2_app/res/drawable/ic_notifications_black_24dp.xml | |||
@@ -0,0 +1,24 @@ | |||
1 | <?xml version="1.0" encoding="utf-8"?> | ||
2 | <!-- Copyright (C) 2017 The Android Open Source Project | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | --> | ||
16 | <vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
17 | android:height="24dp" | ||
18 | android:viewportHeight="24.0" | ||
19 | android:viewportWidth="24.0" | ||
20 | android:width="24dp"> | ||
21 | <path | ||
22 | android:fillColor="#FF000000" | ||
23 | android:pathData="M11.5,22c1.1,0 2,-0.9 2,-2h-4c0,1.1 0.9,2 2,2zm6.5,-6v-5.5c0,-3.07 -2.13,-5.64 -5,-6.32V3.5c0,-0.83 -0.67,-1.5 -1.5,-1.5S10,2.67 10,3.5v0.68c-2.87,0.68 -5,3.25 -5,6.32V16l-2,2v1h17v-1l-2,-2z"/> | ||
24 | </vector> | ||
diff --git a/tests/obd2_app/res/drawable/ic_sync_black_24dp.xml b/tests/obd2_app/res/drawable/ic_sync_black_24dp.xml new file mode 100644 index 00000000..8511efac --- /dev/null +++ b/tests/obd2_app/res/drawable/ic_sync_black_24dp.xml | |||
@@ -0,0 +1,24 @@ | |||
1 | <?xml version="1.0" encoding="utf-8"?> | ||
2 | <!-- Copyright (C) 2017 The Android Open Source Project | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | --> | ||
16 | <vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
17 | android:height="24dp" | ||
18 | android:viewportHeight="24.0" | ||
19 | android:viewportWidth="24.0" | ||
20 | android:width="24dp"> | ||
21 | <path | ||
22 | android:fillColor="#FF000000" | ||
23 | android:pathData="M12 4V1L8 5l4 4V6c3.31 0 6 2.69 6 6 0 1.01,-.25 1.97,-.7 2.8l1.46 1.46C19.54 15.03 20 13.57 20 12c0,-4.42,-3.58,-8,-8,-8zm0 14c-3.31 0,-6,-2.69,-6,-6 0,-1.01.25,-1.97.7,-2.8L5.24 7.74C4.46 8.97 4 10.43 4 12c0 4.42 3.58 8 8 8v3l4,-4,-4,-4v3z"/> | ||
24 | </vector> \ No newline at end of file | ||
diff --git a/tests/obd2_app/res/layout/activity_main.xml b/tests/obd2_app/res/layout/activity_main.xml new file mode 100644 index 00000000..29d7bd2f --- /dev/null +++ b/tests/obd2_app/res/layout/activity_main.xml | |||
@@ -0,0 +1,52 @@ | |||
1 | <?xml version="1.0" encoding="utf-8"?> | ||
2 | <!-- Copyright (C) 2017 The Android Open Source Project | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | --> | ||
16 | <RelativeLayout | ||
17 | xmlns:android="http://schemas.android.com/apk/res/android" | ||
18 | xmlns:tools="http://schemas.android.com/tools" | ||
19 | android:id="@+id/activity_main" | ||
20 | android:layout_width="match_parent" | ||
21 | android:layout_height="match_parent" | ||
22 | android:paddingTop="@dimen/activity_vertical_margin" | ||
23 | android:paddingBottom="@dimen/activity_vertical_margin" | ||
24 | android:paddingLeft="@dimen/activity_horizontal_margin" | ||
25 | android:paddingRight="@dimen/activity_horizontal_margin" | ||
26 | tools:context="com.google.android.car.obd2app.MainActivity"> | ||
27 | |||
28 | <TextView | ||
29 | android:layout_width="wrap_content" | ||
30 | android:layout_height="wrap_content" | ||
31 | android:layout_alignParentTop="true" | ||
32 | android:layout_alignParentStart="true" | ||
33 | android:id="@+id/statusBar" | ||
34 | android:layout_alignParentEnd="true" | ||
35 | android:text="Nothing to say" | ||
36 | android:minLines="10"/> | ||
37 | <Button | ||
38 | android:text="Connect" | ||
39 | android:layout_width="wrap_content" | ||
40 | android:layout_height="wrap_content" | ||
41 | android:layout_alignParentBottom="true" | ||
42 | android:layout_alignParentEnd="true" | ||
43 | android:id="@+id/connection"/> | ||
44 | <Button | ||
45 | android:text="Settings" | ||
46 | android:layout_width="wrap_content" | ||
47 | android:layout_height="wrap_content" | ||
48 | android:id="@+id/settings" | ||
49 | android:layout_alignParentBottom="true" | ||
50 | android:layout_alignParentStart="true" | ||
51 | android:onClick="doSettings"/> | ||
52 | </RelativeLayout> | ||
diff --git a/tests/obd2_app/res/mipmap-hdpi/ic_launcher.png b/tests/obd2_app/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 00000000..cde69bcc --- /dev/null +++ b/tests/obd2_app/res/mipmap-hdpi/ic_launcher.png | |||
Binary files differ | |||
diff --git a/tests/obd2_app/res/mipmap-mdpi/ic_launcher.png b/tests/obd2_app/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 00000000..c133a0cb --- /dev/null +++ b/tests/obd2_app/res/mipmap-mdpi/ic_launcher.png | |||
Binary files differ | |||
diff --git a/tests/obd2_app/res/mipmap-xhdpi/ic_launcher.png b/tests/obd2_app/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 00000000..bfa42f0e --- /dev/null +++ b/tests/obd2_app/res/mipmap-xhdpi/ic_launcher.png | |||
Binary files differ | |||
diff --git a/tests/obd2_app/res/mipmap-xxhdpi/ic_launcher.png b/tests/obd2_app/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 00000000..324e72cd --- /dev/null +++ b/tests/obd2_app/res/mipmap-xxhdpi/ic_launcher.png | |||
Binary files differ | |||
diff --git a/tests/obd2_app/res/mipmap-xxxhdpi/ic_launcher.png b/tests/obd2_app/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 00000000..aee44e13 --- /dev/null +++ b/tests/obd2_app/res/mipmap-xxxhdpi/ic_launcher.png | |||
Binary files differ | |||
diff --git a/tests/obd2_app/res/values-w820dp/dimens.xml b/tests/obd2_app/res/values-w820dp/dimens.xml new file mode 100644 index 00000000..1da96589 --- /dev/null +++ b/tests/obd2_app/res/values-w820dp/dimens.xml | |||
@@ -0,0 +1,21 @@ | |||
1 | <?xml version="1.0" encoding="utf-8"?> | ||
2 | <!-- Copyright (C) 2017 The Android Open Source Project | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | --> | ||
16 | <resources> | ||
17 | <!-- Example customization of dimensions originally defined in res/values/dimens.xml | ||
18 | (such as screen margins) for screens with more than 820dp of available width. This | ||
19 | would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). --> | ||
20 | <dimen name="activity_horizontal_margin">64dp</dimen> | ||
21 | </resources> | ||
diff --git a/tests/obd2_app/res/values/arrays.xml b/tests/obd2_app/res/values/arrays.xml new file mode 100644 index 00000000..2bd7ce38 --- /dev/null +++ b/tests/obd2_app/res/values/arrays.xml | |||
@@ -0,0 +1,27 @@ | |||
1 | <?xml version="1.0" encoding="utf-8"?> | ||
2 | <!-- Copyright (C) 2017 The Android Open Source Project | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | --> | ||
16 | <resources> | ||
17 | <string-array name="scan_delay_entries"> | ||
18 | <item>2 seconds</item> | ||
19 | <item>5 seconds</item> | ||
20 | <item>10 seconds</item> | ||
21 | </string-array> | ||
22 | <string-array name="scan_delay_entryValues"> | ||
23 | <item>2</item> | ||
24 | <item>5</item> | ||
25 | <item>10</item> | ||
26 | </string-array> | ||
27 | </resources> | ||
diff --git a/tests/obd2_app/res/values/colors.xml b/tests/obd2_app/res/values/colors.xml new file mode 100644 index 00000000..49a370ab --- /dev/null +++ b/tests/obd2_app/res/values/colors.xml | |||
@@ -0,0 +1,21 @@ | |||
1 | <?xml version="1.0" encoding="utf-8"?> | ||
2 | <!-- Copyright (C) 2017 The Android Open Source Project | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | --> | ||
16 | |||
17 | <resources> | ||
18 | <color name="colorPrimary">#3F51B5</color> | ||
19 | <color name="colorPrimaryDark">#303F9F</color> | ||
20 | <color name="colorAccent">#FF4081</color> | ||
21 | </resources> | ||
diff --git a/tests/obd2_app/res/values/dimens.xml b/tests/obd2_app/res/values/dimens.xml new file mode 100644 index 00000000..261477ec --- /dev/null +++ b/tests/obd2_app/res/values/dimens.xml | |||
@@ -0,0 +1,20 @@ | |||
1 | <?xml version="1.0" encoding="utf-8"?> | ||
2 | <!-- Copyright (C) 2017 The Android Open Source Project | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | --> | ||
16 | <resources> | ||
17 | <!-- Default screen margins, per the Android Design guidelines. --> | ||
18 | <dimen name="activity_horizontal_margin">16dp</dimen> | ||
19 | <dimen name="activity_vertical_margin">16dp</dimen> | ||
20 | </resources> | ||
diff --git a/tests/obd2_app/res/values/strings.xml b/tests/obd2_app/res/values/strings.xml new file mode 100644 index 00000000..c615c4f2 --- /dev/null +++ b/tests/obd2_app/res/values/strings.xml | |||
@@ -0,0 +1,91 @@ | |||
1 | <?xml version="1.0" encoding="utf-8"?> | ||
2 | <!-- Copyright (C) 2017 The Android Open Source Project | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | --> | ||
16 | <resources> | ||
17 | <string name="app_name">Obd2App</string> | ||
18 | <string name="title_activity_settings">Settings</string> | ||
19 | |||
20 | <!-- Strings related to Settings --> | ||
21 | |||
22 | <!-- Example General settings --> | ||
23 | <string name="pref_header_general">General</string> | ||
24 | |||
25 | <string name="pref_title_social_recommendations">Enable social recommendations</string> | ||
26 | <string name="pref_description_social_recommendations">Recommendations for people to contact based | ||
27 | on your message history | ||
28 | </string> | ||
29 | |||
30 | <string name="pref_title_display_name">Display name</string> | ||
31 | <string name="pref_default_display_name">John Smith</string> | ||
32 | |||
33 | <string name="pref_title_add_friends_to_messages">Add friends to messages</string> | ||
34 | <string-array name="pref_example_list_titles"> | ||
35 | <item>Always</item> | ||
36 | <item>When possible</item> | ||
37 | <item>Never</item> | ||
38 | </string-array> | ||
39 | <string-array name="pref_example_list_values"> | ||
40 | <item>1</item> | ||
41 | <item>0</item> | ||
42 | <item>-1</item> | ||
43 | </string-array> | ||
44 | |||
45 | <!-- Example settings for Data & Sync --> | ||
46 | <string name="pref_header_data_sync">Data & sync</string> | ||
47 | |||
48 | <string name="pref_title_sync_frequency">Sync frequency</string> | ||
49 | <string-array name="pref_sync_frequency_titles"> | ||
50 | <item>15 minutes</item> | ||
51 | <item>30 minutes</item> | ||
52 | <item>1 hour</item> | ||
53 | <item>3 hours</item> | ||
54 | <item>6 hours</item> | ||
55 | <item>Never</item> | ||
56 | </string-array> | ||
57 | <string-array name="pref_sync_frequency_values"> | ||
58 | <item>15</item> | ||
59 | <item>30</item> | ||
60 | <item>60</item> | ||
61 | <item>180</item> | ||
62 | <item>360</item> | ||
63 | <item>-1</item> | ||
64 | </string-array> | ||
65 | |||
66 | <string-array name="list_preference_entries"> | ||
67 | <item>Entry 1</item> | ||
68 | <item>Entry 2</item> | ||
69 | <item>Entry 3</item> | ||
70 | </string-array> | ||
71 | |||
72 | <string-array name="list_preference_entry_values"> | ||
73 | <item>1</item> | ||
74 | <item>2</item> | ||
75 | <item>3</item> | ||
76 | </string-array> | ||
77 | |||
78 | <string-array name="multi_select_list_preference_default_value"/> | ||
79 | |||
80 | <string name="pref_title_system_sync_settings">System sync settings</string> | ||
81 | |||
82 | <!-- Example settings for Notifications --> | ||
83 | <string name="pref_header_notifications">Notifications</string> | ||
84 | |||
85 | <string name="pref_title_new_message_notifications">New message notifications</string> | ||
86 | |||
87 | <string name="pref_title_ringtone">Ringtone</string> | ||
88 | <string name="pref_ringtone_silent">Silent</string> | ||
89 | |||
90 | <string name="pref_title_vibrate">Vibrate</string> | ||
91 | </resources> | ||
diff --git a/tests/obd2_app/res/values/styles.xml b/tests/obd2_app/res/values/styles.xml new file mode 100644 index 00000000..c21c0ac4 --- /dev/null +++ b/tests/obd2_app/res/values/styles.xml | |||
@@ -0,0 +1,20 @@ | |||
1 | <?xml version="1.0" encoding="utf-8"?> | ||
2 | <!-- Copyright (C) 2017 The Android Open Source Project | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | --> | ||
16 | <resources> | ||
17 | <style name="AppTheme" parent="android:Theme.Material"> | ||
18 | </style> | ||
19 | |||
20 | </resources> | ||
diff --git a/tests/obd2_app/res/xml/preferences.xml b/tests/obd2_app/res/xml/preferences.xml new file mode 100644 index 00000000..0c6f5340 --- /dev/null +++ b/tests/obd2_app/res/xml/preferences.xml | |||
@@ -0,0 +1,28 @@ | |||
1 | <?xml version="1.0" encoding="utf-8"?> | ||
2 | <!-- Copyright (C) 2017 The Android Open Source Project | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | --> | ||
16 | <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> | ||
17 | <com.google.android.car.obd2app.BluetoothPreference | ||
18 | android:key="bluetooth_mac" | ||
19 | android:title="OBD2 Dongle" | ||
20 | android:dialogTitle="Select OBD2 Scanner" /> | ||
21 | <com.google.android.car.obd2app.IntegerListPreference | ||
22 | android:key="scan_delay" | ||
23 | android:title="Time between queries" | ||
24 | android:dialogTitle="Select Delay" | ||
25 | android:entries="@array/scan_delay_entries" | ||
26 | android:entryValues="@array/scan_delay_entryValues" | ||
27 | android:defaultValue="2"/> | ||
28 | </PreferenceScreen> | ||
diff --git a/tests/obd2_app/src/com/google/android/car/obd2app/BluetoothPreference.java b/tests/obd2_app/src/com/google/android/car/obd2app/BluetoothPreference.java new file mode 100644 index 00000000..59da4c07 --- /dev/null +++ b/tests/obd2_app/src/com/google/android/car/obd2app/BluetoothPreference.java | |||
@@ -0,0 +1,66 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2017 The Android Open Source Project | ||
3 | * | ||
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | * you may not use this file except in compliance with the License. | ||
6 | * You may obtain a copy of the License at | ||
7 | * | ||
8 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | * | ||
10 | * Unless required by applicable law or agreed to in writing, software | ||
11 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | * See the License for the specific language governing permissions and | ||
14 | * limitations under the License. | ||
15 | */ | ||
16 | |||
17 | package com.google.android.car.obd2app; | ||
18 | |||
19 | import android.bluetooth.BluetoothAdapter; | ||
20 | import android.bluetooth.BluetoothDevice; | ||
21 | import android.content.Context; | ||
22 | import android.preference.ListPreference; | ||
23 | import android.util.AttributeSet; | ||
24 | |||
25 | import java.util.ArrayList; | ||
26 | import java.util.List; | ||
27 | |||
28 | public class BluetoothPreference extends ListPreference { | ||
29 | private static final class DeviceEntry { | ||
30 | private final String mName; | ||
31 | private final String mAddress; | ||
32 | |||
33 | DeviceEntry(BluetoothDevice device) { | ||
34 | mAddress = device.getAddress(); | ||
35 | if (device.getName() == null) { | ||
36 | mName = mAddress; | ||
37 | } else { | ||
38 | mName = device.getName(); | ||
39 | } | ||
40 | } | ||
41 | |||
42 | String getName() { | ||
43 | return mName; | ||
44 | } | ||
45 | |||
46 | String getAddress() { | ||
47 | return mAddress; | ||
48 | } | ||
49 | } | ||
50 | |||
51 | public BluetoothPreference(Context context, AttributeSet attrs) { | ||
52 | super(context, attrs); | ||
53 | |||
54 | BluetoothAdapter defaultAdapter = BluetoothAdapter.getDefaultAdapter(); | ||
55 | List<DeviceEntry> pairedDevices = new ArrayList<>(); | ||
56 | defaultAdapter | ||
57 | .getBondedDevices() | ||
58 | .forEach((BluetoothDevice device) -> pairedDevices.add(new DeviceEntry(device))); | ||
59 | setEntries(pairedDevices.stream().map(DeviceEntry::getName).toArray(String[]::new)); | ||
60 | setEntryValues(pairedDevices.stream().map(DeviceEntry::getAddress).toArray(String[]::new)); | ||
61 | } | ||
62 | |||
63 | public BluetoothPreference(Context context) { | ||
64 | this(context, null); | ||
65 | } | ||
66 | } | ||
diff --git a/tests/obd2_app/src/com/google/android/car/obd2app/IntegerListPreference.java b/tests/obd2_app/src/com/google/android/car/obd2app/IntegerListPreference.java new file mode 100644 index 00000000..6e9e9dce --- /dev/null +++ b/tests/obd2_app/src/com/google/android/car/obd2app/IntegerListPreference.java | |||
@@ -0,0 +1,45 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2017 The Android Open Source Project | ||
3 | * | ||
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | * you may not use this file except in compliance with the License. | ||
6 | * You may obtain a copy of the License at | ||
7 | * | ||
8 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | * | ||
10 | * Unless required by applicable law or agreed to in writing, software | ||
11 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | * See the License for the specific language governing permissions and | ||
14 | * limitations under the License. | ||
15 | */ | ||
16 | |||
17 | package com.google.android.car.obd2app; | ||
18 | |||
19 | import android.content.Context; | ||
20 | import android.preference.ListPreference; | ||
21 | import android.util.AttributeSet; | ||
22 | |||
23 | public class IntegerListPreference extends ListPreference { | ||
24 | public IntegerListPreference(Context context, AttributeSet attrs) { | ||
25 | super(context, attrs); | ||
26 | } | ||
27 | |||
28 | public IntegerListPreference(Context context) { | ||
29 | super(context); | ||
30 | } | ||
31 | |||
32 | @Override | ||
33 | protected boolean persistString(String value) { | ||
34 | return value != null && persistInt(Integer.valueOf(value)); | ||
35 | } | ||
36 | |||
37 | @Override | ||
38 | protected String getPersistedString(String defaultReturnValue) { | ||
39 | if (getSharedPreferences().contains(getKey())) { | ||
40 | return String.valueOf(getPersistedInt(2)); | ||
41 | } else { | ||
42 | return defaultReturnValue; | ||
43 | } | ||
44 | } | ||
45 | } | ||
diff --git a/tests/obd2_app/src/com/google/android/car/obd2app/MainActivity.java b/tests/obd2_app/src/com/google/android/car/obd2app/MainActivity.java new file mode 100644 index 00000000..dc38b5c6 --- /dev/null +++ b/tests/obd2_app/src/com/google/android/car/obd2app/MainActivity.java | |||
@@ -0,0 +1,116 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2017 The Android Open Source Project | ||
3 | * | ||
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | * you may not use this file except in compliance with the License. | ||
6 | * You may obtain a copy of the License at | ||
7 | * | ||
8 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | * | ||
10 | * Unless required by applicable law or agreed to in writing, software | ||
11 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | * See the License for the specific language governing permissions and | ||
14 | * limitations under the License. | ||
15 | */ | ||
16 | |||
17 | package com.google.android.car.obd2app; | ||
18 | |||
19 | import android.app.Activity; | ||
20 | import android.content.Intent; | ||
21 | import android.content.SharedPreferences; | ||
22 | import android.content.pm.ActivityInfo; | ||
23 | import android.os.Bundle; | ||
24 | import android.preference.PreferenceManager; | ||
25 | import android.text.TextUtils; | ||
26 | import android.util.Log; | ||
27 | import android.view.View; | ||
28 | import android.view.View.OnClickListener; | ||
29 | import android.widget.Button; | ||
30 | import android.widget.TextView; | ||
31 | import java.util.Timer; | ||
32 | |||
33 | public class MainActivity extends Activity implements StatusNotification { | ||
34 | public static final String TAG = MainActivity.class.getSimpleName(); | ||
35 | |||
36 | private static final String BLUETOOTH_MAC_PREFERENCE_ID = "bluetooth_mac"; | ||
37 | private static final String SCAN_DELAY_PREFERENCE_ID = "scan_delay"; | ||
38 | |||
39 | private Obd2CollectionTask mCollectionTask = null; | ||
40 | private final Timer mTimer = new Timer("com.google.android.car.obd2app.collection"); | ||
41 | |||
42 | private String getBluetoothDongleMacFromPreferences(String defaultValue) { | ||
43 | SharedPreferences appPreferences = PreferenceManager.getDefaultSharedPreferences(this); | ||
44 | return appPreferences.getString(BLUETOOTH_MAC_PREFERENCE_ID, defaultValue); | ||
45 | } | ||
46 | |||
47 | private int getScanDelayFromPreferences(int defaultValue) { | ||
48 | SharedPreferences appPreferences = PreferenceManager.getDefaultSharedPreferences(this); | ||
49 | return appPreferences.getInt(SCAN_DELAY_PREFERENCE_ID, defaultValue); | ||
50 | } | ||
51 | |||
52 | @Override | ||
53 | protected void onCreate(Bundle savedInstanceState) { | ||
54 | super.onCreate(savedInstanceState); | ||
55 | setContentView(R.layout.activity_main); | ||
56 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR); | ||
57 | String bluetoothDongleMac = getBluetoothDongleMacFromPreferences(""); | ||
58 | if (TextUtils.isEmpty(bluetoothDongleMac)) { | ||
59 | notifyNoDongle(); | ||
60 | } else { | ||
61 | notifyPaired(bluetoothDongleMac); | ||
62 | } | ||
63 | findViewById(R.id.connection) | ||
64 | .setOnClickListener( | ||
65 | new OnClickListener() { | ||
66 | @Override | ||
67 | public void onClick(View v) { | ||
68 | handleConnection(v); | ||
69 | } | ||
70 | }); | ||
71 | Log.i(TAG, "I did all the things"); | ||
72 | } | ||
73 | |||
74 | private void stopConnection() { | ||
75 | mCollectionTask.cancel(); | ||
76 | mTimer.purge(); | ||
77 | mCollectionTask = null; | ||
78 | } | ||
79 | |||
80 | @Override | ||
81 | protected void onDestroy() { | ||
82 | stopConnection(); | ||
83 | } | ||
84 | |||
85 | public void doSettings(View view) { | ||
86 | Intent launchSettings = new Intent(this, SettingsActivity.class); | ||
87 | startActivity(launchSettings); | ||
88 | } | ||
89 | |||
90 | @Override | ||
91 | public void notify(String status) { | ||
92 | Log.i(TAG, status); | ||
93 | runOnUiThread(() -> ((TextView) findViewById(R.id.statusBar)).setText(status)); | ||
94 | } | ||
95 | |||
96 | public void handleConnection(View view) { | ||
97 | String deviceAddress = getBluetoothDongleMacFromPreferences(""); | ||
98 | Log.i(TAG, "Considering a connection to " + deviceAddress); | ||
99 | if (TextUtils.isEmpty(deviceAddress)) { | ||
100 | notifyNoDongle(); | ||
101 | } | ||
102 | if (mCollectionTask == null) { | ||
103 | mCollectionTask = Obd2CollectionTask.create(this, this, deviceAddress); | ||
104 | if (null == mCollectionTask) { | ||
105 | notifyConnectionFailed(); | ||
106 | return; | ||
107 | } | ||
108 | final int delay = 1000 * getScanDelayFromPreferences(2); | ||
109 | mTimer.scheduleAtFixedRate(mCollectionTask, delay, delay); | ||
110 | ((Button) view).setText("Disconnect"); | ||
111 | } else { | ||
112 | stopConnection(); | ||
113 | ((Button) view).setText("Connect"); | ||
114 | } | ||
115 | } | ||
116 | } | ||
diff --git a/tests/obd2_app/src/com/google/android/car/obd2app/Obd2CollectionTask.java b/tests/obd2_app/src/com/google/android/car/obd2app/Obd2CollectionTask.java new file mode 100644 index 00000000..31c3db2f --- /dev/null +++ b/tests/obd2_app/src/com/google/android/car/obd2app/Obd2CollectionTask.java | |||
@@ -0,0 +1,118 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2017 The Android Open Source Project | ||
3 | * | ||
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | * you may not use this file except in compliance with the License. | ||
6 | * You may obtain a copy of the License at | ||
7 | * | ||
8 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | * | ||
10 | * Unless required by applicable law or agreed to in writing, software | ||
11 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | * See the License for the specific language governing permissions and | ||
14 | * limitations under the License. | ||
15 | */ | ||
16 | |||
17 | package com.google.android.car.obd2app; | ||
18 | |||
19 | import android.annotation.Nullable; | ||
20 | import android.content.Context; | ||
21 | import android.os.Environment; | ||
22 | import android.os.SystemClock; | ||
23 | import android.util.JsonWriter; | ||
24 | import android.util.Log; | ||
25 | |||
26 | import com.android.car.obd2.Obd2Connection; | ||
27 | import com.android.car.obd2.Obd2LiveFrameGenerator; | ||
28 | import com.android.car.obd2.connections.BluetoothConnection; | ||
29 | |||
30 | import java.io.File; | ||
31 | import java.io.FileOutputStream; | ||
32 | import java.io.IOException; | ||
33 | import java.io.OutputStreamWriter; | ||
34 | import java.util.Objects; | ||
35 | import java.util.TimerTask; | ||
36 | |||
37 | public class Obd2CollectionTask extends TimerTask { | ||
38 | private final Obd2Connection mConnection; | ||
39 | private final Obd2LiveFrameGenerator mLiveFrameGenerator; | ||
40 | private final StatusNotification mStatusNotification; | ||
41 | private final JsonWriter mJsonWriter; | ||
42 | |||
43 | public static @Nullable Obd2CollectionTask create( | ||
44 | Context context, StatusNotification statusNotification, String deviceAddress) { | ||
45 | try { | ||
46 | return new Obd2CollectionTask( | ||
47 | Objects.requireNonNull(context), | ||
48 | Objects.requireNonNull(statusNotification), | ||
49 | Objects.requireNonNull(deviceAddress)); | ||
50 | } catch (IOException | InterruptedException | IllegalStateException e) { | ||
51 | Log.i(MainActivity.TAG, "Connection failed due to exception", e); | ||
52 | return null; | ||
53 | } | ||
54 | } | ||
55 | |||
56 | @Override | ||
57 | public boolean cancel() { | ||
58 | synchronized (mJsonWriter) { | ||
59 | try { | ||
60 | mJsonWriter.endArray(); | ||
61 | mJsonWriter.flush(); | ||
62 | mJsonWriter.close(); | ||
63 | } catch (IOException e) { | ||
64 | Log.w(MainActivity.TAG, "IOException during close", e); | ||
65 | } | ||
66 | return super.cancel(); | ||
67 | } | ||
68 | } | ||
69 | |||
70 | @Override | ||
71 | public void run() { | ||
72 | if (!mConnection.isConnected()) { | ||
73 | if (!mConnection.reconnect()) { | ||
74 | mStatusNotification.notifyDisconnected(); | ||
75 | return; | ||
76 | } | ||
77 | } | ||
78 | |||
79 | try { | ||
80 | synchronized (mJsonWriter) { | ||
81 | mLiveFrameGenerator.generate(mJsonWriter); | ||
82 | mJsonWriter.flush(); | ||
83 | } | ||
84 | mStatusNotification.notifyDataCapture(); | ||
85 | } catch (Exception e) { | ||
86 | mStatusNotification.notifyException(e); | ||
87 | } | ||
88 | } | ||
89 | |||
90 | Obd2CollectionTask(Context context, StatusNotification statusNotification, String deviceAddress) | ||
91 | throws IOException, InterruptedException { | ||
92 | if (!isExternalStorageWriteable()) | ||
93 | throw new IOException("Cannot write data to external storage"); | ||
94 | mStatusNotification = statusNotification; | ||
95 | BluetoothConnection bluetoothConnection = new BluetoothConnection(deviceAddress); | ||
96 | if (!bluetoothConnection.isConnected()) { | ||
97 | statusNotification.notifyConnectionFailed(); | ||
98 | throw new IllegalStateException("Unable to connect to remote end."); | ||
99 | } | ||
100 | mConnection = new Obd2Connection(bluetoothConnection); | ||
101 | mLiveFrameGenerator = new Obd2LiveFrameGenerator(mConnection); | ||
102 | mJsonWriter = | ||
103 | new JsonWriter( | ||
104 | new OutputStreamWriter( | ||
105 | new FileOutputStream(getFilenameForStorage(context)))); | ||
106 | mJsonWriter.beginArray(); | ||
107 | } | ||
108 | |||
109 | private static boolean isExternalStorageWriteable() { | ||
110 | String state = Environment.getExternalStorageState(); | ||
111 | return (Environment.MEDIA_MOUNTED.equals(state)); | ||
112 | } | ||
113 | |||
114 | private static File getFilenameForStorage(Context context) { | ||
115 | String basename = String.format("obd2app.capture.%d", SystemClock.elapsedRealtimeNanos()); | ||
116 | return new File(context.getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS), basename); | ||
117 | } | ||
118 | } | ||
diff --git a/tests/obd2_app/src/com/google/android/car/obd2app/SettingsActivity.java b/tests/obd2_app/src/com/google/android/car/obd2app/SettingsActivity.java new file mode 100644 index 00000000..23f120e2 --- /dev/null +++ b/tests/obd2_app/src/com/google/android/car/obd2app/SettingsActivity.java | |||
@@ -0,0 +1,28 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2017 The Android Open Source Project | ||
3 | * | ||
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | * you may not use this file except in compliance with the License. | ||
6 | * You may obtain a copy of the License at | ||
7 | * | ||
8 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | * | ||
10 | * Unless required by applicable law or agreed to in writing, software | ||
11 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | * See the License for the specific language governing permissions and | ||
14 | * limitations under the License. | ||
15 | */ | ||
16 | |||
17 | package com.google.android.car.obd2app; | ||
18 | |||
19 | import android.os.Bundle; | ||
20 | import android.preference.PreferenceActivity; | ||
21 | |||
22 | public class SettingsActivity extends PreferenceActivity { | ||
23 | @Override | ||
24 | public void onCreate(Bundle savedInstanceState) { | ||
25 | super.onCreate(savedInstanceState); | ||
26 | addPreferencesFromResource(R.xml.preferences); | ||
27 | } | ||
28 | } | ||
diff --git a/tests/obd2_app/src/com/google/android/car/obd2app/StatusNotification.java b/tests/obd2_app/src/com/google/android/car/obd2app/StatusNotification.java new file mode 100644 index 00000000..185c384f --- /dev/null +++ b/tests/obd2_app/src/com/google/android/car/obd2app/StatusNotification.java | |||
@@ -0,0 +1,58 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2017 The Android Open Source Project | ||
3 | * | ||
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | * you may not use this file except in compliance with the License. | ||
6 | * You may obtain a copy of the License at | ||
7 | * | ||
8 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | * | ||
10 | * Unless required by applicable law or agreed to in writing, software | ||
11 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | * See the License for the specific language governing permissions and | ||
14 | * limitations under the License. | ||
15 | */ | ||
16 | |||
17 | package com.google.android.car.obd2app; | ||
18 | |||
19 | import java.io.PrintWriter; | ||
20 | import java.io.StringWriter; | ||
21 | import java.time.LocalDateTime; | ||
22 | import java.time.format.DateTimeFormatter; | ||
23 | |||
24 | interface StatusNotification { | ||
25 | void notify(String status); | ||
26 | |||
27 | default void notifyNoDongle() { | ||
28 | notify("No OBD2 dongle paired. Go to Settings."); | ||
29 | } | ||
30 | |||
31 | default void notifyPaired(String deviceAddress) { | ||
32 | notify("Paired to " + deviceAddress + ". Ready to capture data."); | ||
33 | } | ||
34 | |||
35 | default void notifyConnectionFailed() { | ||
36 | notify("Unable to connect."); | ||
37 | } | ||
38 | |||
39 | default void notifyConnected(String deviceAddress) { | ||
40 | notify("Connected to " + deviceAddress + ". Starting data capture."); | ||
41 | } | ||
42 | |||
43 | default void notifyDataCapture() { | ||
44 | LocalDateTime now = LocalDateTime.now(); | ||
45 | DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MMMM dd yyyy hh:mm:ssa"); | ||
46 | notify("Successfully captured data at " + now.format(dateTimeFormatter)); | ||
47 | } | ||
48 | |||
49 | default void notifyException(Exception e) { | ||
50 | StringWriter stringWriter = new StringWriter(1024); | ||
51 | e.printStackTrace(new PrintWriter(stringWriter)); | ||
52 | notify("Exception occurred.\n" + stringWriter.toString()); | ||
53 | } | ||
54 | |||
55 | default void notifyDisconnected() { | ||
56 | notify("Lost connection to remote end. Will try to reconnect."); | ||
57 | } | ||
58 | } | ||