From 0e6748449304c1d1b39292a85d2c881987e8a6d2 Mon Sep 17 00:00:00 2001 From: Peter Hasse Date: Tue, 5 Nov 2024 12:01:25 +0100 Subject: [PATCH] added build information to logging --- .../DataProvider/BuildInformation.java | 21 ++++-- .../DataProvider/DataProvider.java | 8 +++ .../LoggingService.java | 5 ++ .../DataProvider/BatteryInformationTest.java | 72 +++++++++++++++++++ 4 files changed, 102 insertions(+), 4 deletions(-) create mode 100644 app/src/test/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/DataProvider/BatteryInformationTest.java diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/DataProvider/BuildInformation.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/DataProvider/BuildInformation.java index c376a106..28814499 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/DataProvider/BuildInformation.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/DataProvider/BuildInformation.java @@ -1,8 +1,8 @@ package de.fraunhofer.fokus.OpenMobileNetworkToolkit.DataProvider; -import android.content.Context; import android.util.Log; -import android.widget.TableLayout; + +import com.influxdb.client.write.Point; import org.json.JSONObject; @@ -39,7 +39,7 @@ public boolean isDebug() { return BuildConfig.DEBUG; } - public JSONObject toJSON(){ + public JSONObject toJSON() { JSONObject json = new JSONObject(); try { @@ -49,9 +49,22 @@ public JSONObject toJSON(){ json.put("ApplicationId", getApplicationId()); json.put("Debug", isDebug()); } catch (Exception e) { - Log.d(TAG,e.toString()); + Log.d(TAG, e.toString()); } return json; } + public Point getPoint(Point point) { + if (point == null) { + Log.e(TAG, "getPoint: given point == null!"); + point = Point.measurement("BuildInformation"); + } + point.addField("BuildType", getBuildType()); + point.addField("VersionCode", getVersionCode()); + point.addField("VersionName", getVersionName()); + point.addField("ApplicationID", getApplicationId()); + point.addField("Debug", isDebug()); + return point; + } + } diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/DataProvider/DataProvider.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/DataProvider/DataProvider.java index 2751bd17..a6b83bf0 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/DataProvider/DataProvider.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/DataProvider/DataProvider.java @@ -357,6 +357,14 @@ public BuildInformation getBuildInformation() { return buildInformation; } + public Point getBuildInformationPoint() { + Point point = new Point("BuildInformation"); + point.time(ts, WritePrecision.MS); + point = buildInformation.getPoint(point); + return point; + } + + /** * Get CellInformation object * diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/LoggingService.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/LoggingService.java index 4cdf5bc4..c0d9bd5d 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/LoggingService.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/LoggingService.java @@ -349,6 +349,11 @@ private ArrayList getPoints() { logPoints.add(bp); } + Point bi = dp.getBuildInformationPoint(); + bi.time(time, WritePrecision.MS); + bi.addTags(tags_map); + logPoints.add(bi); + Point p = dp.getLocationPoint(); p.time(time, WritePrecision.MS); p.addTags(tags_map); diff --git a/app/src/test/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/DataProvider/BatteryInformationTest.java b/app/src/test/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/DataProvider/BatteryInformationTest.java new file mode 100644 index 00000000..e5ed3722 --- /dev/null +++ b/app/src/test/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/DataProvider/BatteryInformationTest.java @@ -0,0 +1,72 @@ +/* + * SPDX-FileCopyrightText: 2023 Peter Hasse + * SPDX-FileCopyrightText: 2023 Johann Hackler + * SPDX-FileCopyrightText: 2023 Fraunhofer FOKUS + * + * SPDX-License-Identifier: apache2 + */ + +package de.fraunhofer.fokus.OpenMobileNetworkToolkit.DataProvider; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; + +public class BatteryInformationTest { + + private BatteryInformation batteryInformation; + + @Before + public void setUp() throws Exception { + batteryInformation = new BatteryInformation(); + + } + @Test + public void getScale() { + assertEquals( "Should return null", 0, batteryInformation.getScale()); + batteryInformation.setScale(10); + assertEquals( "Should return 10", 10, batteryInformation.getScale()); + } + + @Test + public void setScale() { + batteryInformation.setScale(10); + assertEquals( "Should return 10", 10, batteryInformation.getScale()); + } + + @Test + public void getLevel() { + assertEquals("Should return 0", 0, batteryInformation.getLevel()); + batteryInformation.setLevel(10); + assertEquals("Should return 10", 10, batteryInformation.getLevel()); + } + + @Test + public void setLevel() { + batteryInformation.setLevel(10); + assertEquals("Should return 10", 10, batteryInformation.getLevel()); + } + + @Test + public void getCharge_type() { + assertEquals("Should return 0", 0, batteryInformation.getCharge_type()); + batteryInformation.setCharge_type(10); + assertEquals("Should return 10", 10, batteryInformation.getCharge_type()); + } + + @Test + public void setCharge_type() { + batteryInformation.setCharge_type(10); + assertEquals("Should return 10", 10, batteryInformation.getCharge_type()); + } + + @Test + public void getPercent() { + assertEquals("Should return NaN", Double.NaN, batteryInformation.getPercent(),0.0); + batteryInformation.setScale(10); + batteryInformation.setLevel(10); + assertEquals("Should return 100.0", 100.0, batteryInformation.getPercent(),0.0); + } + +} \ No newline at end of file