From 0f98c4e8bfaedc010b8845470fd3493d28541d5e Mon Sep 17 00:00:00 2001 From: bob joe Date: Sun, 21 Jul 2024 20:39:29 -0700 Subject: [PATCH] fix null pointer in CoT debug mode for some drone cameras --- .../com/openathena/CursorOnTargetSender.java | 2 ++ .../main/java/com/openathena/MainActivity.java | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/openathena/CursorOnTargetSender.java b/app/src/main/java/com/openathena/CursorOnTargetSender.java index f911faf..53577a8 100644 --- a/app/src/main/java/com/openathena/CursorOnTargetSender.java +++ b/app/src/main/java/com/openathena/CursorOnTargetSender.java @@ -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)); diff --git a/app/src/main/java/com/openathena/MainActivity.java b/app/src/main/java/com/openathena/MainActivity.java index 52c9a4e..caf1a36 100644 --- a/app/src/main/java/com/openathena/MainActivity.java +++ b/app/src/main/java/com/openathena/MainActivity.java @@ -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) { @@ -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); @@ -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