Skip to content

Commit

Permalink
fix null pointer in CoT debug mode for some drone cameras
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrupczak3 committed Jul 22, 2024
1 parent b04ad09 commit 0f98c4e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions app/src/main/java/com/openathena/CursorOnTargetSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ public static String buildCoT(String uid, String imageISO, String nowAsISO, Stri
detail.appendChild(precisionlocation);

if (!oaInfoMap.isEmpty()) {
// Log.d("CursorOnTargetSender", "oaInfoMap keySet: " + oaInfoMap.keySet().toString());
// Log.d("CursorOnTargetSender", "oaInfoMap values: " + oaInfoMap.values().toString());
Element openAthenaCalculationInfo = doc.createElement("openAthenaCalculationInfo");
double theta = Math.toDegrees(Math.atan2(Double.parseDouble(le),Double.parseDouble(ce)));
openAthenaCalculationInfo.setAttribute("raySlantAngleDeg", String.valueOf(theta));
Expand Down
16 changes: 12 additions & 4 deletions app/src/main/java/com/openathena/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ protected void onCreate(Bundle savedInstanceState) {
// Restore the user's custom droneModels.json drone camera intrinsics database (if so configured)
String storedDroneModelsJsonUriString = sharedPreferences.getString("droneModelsJsonUri", null);
DroneParametersFromJSON droneModelsParser = MetadataExtractor.parameterProvider;
if (storedDroneModelsJsonUriString != null && !storedDroneModelsJsonUriString.isBlank()) {
if (storedDroneModelsJsonUriString != null && !storedDroneModelsJsonUriString.isEmpty()) {
try {
droneModelsParser.loadJSONFromUri(Uri.parse(storedDroneModelsJsonUriString));
} catch (IOException | JSONException e) {
Expand Down Expand Up @@ -707,9 +707,9 @@ public void calculateImage(View view, boolean shouldISendCoT)
// yikes
if (IS_EXTENDED_COT_MODE_ACTIVE) {
openAthenaCalculationInfo.put("focalLength", roundDouble(MetadataExtractor.rationalToFloat(exif.getAttribute(ExifInterface.TAG_FOCAL_LENGTH))));
openAthenaCalculationInfo.put("digitalZoomRatio", exif.getAttribute(ExifInterface.TAG_DIGITAL_ZOOM_RATIO));
openAthenaCalculationInfo.put("imageWidth", exif.getAttribute(ExifInterface.TAG_IMAGE_WIDTH));
openAthenaCalculationInfo.put("imageLength", exif.getAttribute(ExifInterface.TAG_IMAGE_LENGTH));
openAthenaCalculationInfo.put("digitalZoomRatio", zeroStringIfNull(exif.getAttribute(ExifInterface.TAG_DIGITAL_ZOOM_RATIO)));
openAthenaCalculationInfo.put("imageWidth", zeroStringIfNull(exif.getAttribute(ExifInterface.TAG_IMAGE_WIDTH)));
openAthenaCalculationInfo.put("imageLength", zeroStringIfNull(exif.getAttribute(ExifInterface.TAG_IMAGE_LENGTH)));
}

double[] intrinsics = MetadataExtractor.getIntrinsicMatrixFromExif(exif);
Expand Down Expand Up @@ -1165,6 +1165,14 @@ private static String roundDouble(double d) {
return df.format(d);
}

private static String zeroStringIfNull(String s) {
if (s == null || s.isEmpty()) {
return "0.0";
} else {
return s;
}
}

private void appendText(final String aStr) {
runOnUiThread(new Runnable() {
@Override
Expand Down

0 comments on commit 0f98c4e

Please sign in to comment.