Skip to content

Commit

Permalink
added build information to logging
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterHasse committed Nov 5, 2024
1 parent 38db5b9 commit 0e67484
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -39,7 +39,7 @@ public boolean isDebug() {
return BuildConfig.DEBUG;
}

public JSONObject toJSON(){
public JSONObject toJSON() {

JSONObject json = new JSONObject();
try {
Expand All @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,11 @@ private ArrayList<Point> 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* SPDX-FileCopyrightText: 2023 Peter Hasse <[email protected]>
* SPDX-FileCopyrightText: 2023 Johann Hackler <[email protected]>
* 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);
}

}

0 comments on commit 0e67484

Please sign in to comment.