-
-
Notifications
You must be signed in to change notification settings - Fork 45
Backmerge Commcare 2.61.3 #3504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…n coordinates from logs due to firebase policies
…crash-reports Fix user info missing in Crashlytics reports (Hotfix)
[Hotfix] Discard stale locations based on an App Setting
…erations-perf-monitoring-trace [Hotfix] Add perf monitoring trace for file encryption time
…ng-trace Make trace nullable when stopping tracing
📝 WalkthroughWalkthroughThis PR introduces performance monitoring for file encryption operations and improves location freshness handling. It adds tracing instrumentation around file-encryption writes in multiple storage layers, updates location controller logic to check for stale locations before processing, extracts location freshness utilities into top-level functions in CommCareLocationController, modifies crash reporting to return actual user information instead of null, adds a preference key for controlling stale location behavior, and bumps the app version. Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@app/src/org/commcare/models/encryption/EncryptionIO.java`:
- Line 42: In EncryptionIO, replace the use of InputStream.available() to
determine file size (the line assigning fileSize from is.available()) with the
actual File.length() on the File used to open that InputStream (e.g., use
inputFile.length()), converting or validating the long-to-int cast if the code
expects an int and guarding against null/zero files; ensure you reference the
same File instance that produced the InputStream and update any related logic
that assumes available() semantics.
- Around line 35-46: The method EncryptionIO.encryptFile starts a trace (trace)
but does not guarantee CCPerfMonitoring.INSTANCE.stopFileEncryptionTracing(...)
is called if StreamsUtil.writeFromInputToOutputNew throws; wrap the file I/O and
write call in a try-finally where in finally you always call
stopFileEncryptionTracing(trace, fileSize, sourceFilePath) and also ensure both
streams (os from createFileOutputStream(...) and is = new FileInputStream(...))
are closed safely (null-check and close inside finally or use try-with-resources
equivalent) so the trace is stopped and resources are released on exceptions as
well.
🧹 Nitpick comments (2)
app/src/org/commcare/location/CommCareLocationController.kt (1)
34-40: Consider the side effect of unconditional logging.
shouldDiscardLocationlogs a non-fatal exception every time a stale location is received, regardless of whether the location will be discarded. This is likely intentional for monitoring purposes, but worth confirming this is the desired behavior—especially sincelogStaleLocationSavedmay log again downstream if the location is not discarded and subsequently saved.Also, minor style nit: add a space after
ifon line 35.Minor style fix
fun shouldDiscardLocation(location: Location): Boolean { - if(!isLocationFresh(location)) { + if (!isLocationFresh(location)) { Logger.exception("Received a stale location", getStaleLocationException(location)) return HiddenPreferences.shouldDiscardStaleLocations() } return false }app/src/org/commcare/location/CommCareFusedLocationController.kt (1)
38-45: CapturelastLocationin a local variable to avoid multiple property accesses.
result.lastLocationis accessed twice (line 39 and line 41). While it's likely stable, accessing it once and storing in a local variable is safer and cleaner.Proposed fix
object : LocationCallback() { override fun onLocationResult(result: LocationResult) { - result.lastLocation ?: return + val location = result.lastLocation ?: return Logger.log(LogTypes.TYPE_MAINTENANCE, "Received location update") - if (shouldDiscardLocation(result.lastLocation!!)) { + if (shouldDiscardLocation(location)) { return } - mCurrentLocation = result.lastLocation + mCurrentLocation = location mListener?.onLocationResult(mCurrentLocation!!) } }
| public static void encryptFile(String sourceFilePath, String destPath, SecretKeySpec symetricKey) throws IOException { | ||
| Trace trace = CCPerfMonitoring.INSTANCE.startTracing(CCPerfMonitoring.TRACE_FILE_ENCRYPTION_TIME); | ||
|
|
||
| OutputStream os; | ||
| FileInputStream is; | ||
| os = createFileOutputStream(destPath, symetricKey); | ||
| is = new FileInputStream(sourceFilePath); | ||
| int fileSize = is.available(); | ||
| StreamsUtil.writeFromInputToOutputNew(is, os); | ||
|
|
||
| CCPerfMonitoring.INSTANCE.stopFileEncryptionTracing(trace, fileSize, sourceFilePath); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trace not stopped on exception path.
If an exception occurs during the write operation, the trace will never be stopped. Consider wrapping in a try-finally to ensure the trace is always stopped.
Proposed fix
public static void encryptFile(String sourceFilePath, String destPath, SecretKeySpec symetricKey) throws IOException {
Trace trace = CCPerfMonitoring.INSTANCE.startTracing(CCPerfMonitoring.TRACE_FILE_ENCRYPTION_TIME);
OutputStream os;
FileInputStream is;
- os = createFileOutputStream(destPath, symetricKey);
- is = new FileInputStream(sourceFilePath);
- int fileSize = is.available();
- StreamsUtil.writeFromInputToOutputNew(is, os);
-
- CCPerfMonitoring.INSTANCE.stopFileEncryptionTracing(trace, fileSize, sourceFilePath);
+ File sourceFile = new File(sourceFilePath);
+ long fileSize = sourceFile.length();
+ try {
+ os = createFileOutputStream(destPath, symetricKey);
+ is = new FileInputStream(sourceFilePath);
+ StreamsUtil.writeFromInputToOutputNew(is, os);
+ } finally {
+ CCPerfMonitoring.INSTANCE.stopFileEncryptionTracing(trace, fileSize, sourceFilePath);
+ }
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| public static void encryptFile(String sourceFilePath, String destPath, SecretKeySpec symetricKey) throws IOException { | |
| Trace trace = CCPerfMonitoring.INSTANCE.startTracing(CCPerfMonitoring.TRACE_FILE_ENCRYPTION_TIME); | |
| OutputStream os; | |
| FileInputStream is; | |
| os = createFileOutputStream(destPath, symetricKey); | |
| is = new FileInputStream(sourceFilePath); | |
| int fileSize = is.available(); | |
| StreamsUtil.writeFromInputToOutputNew(is, os); | |
| CCPerfMonitoring.INSTANCE.stopFileEncryptionTracing(trace, fileSize, sourceFilePath); | |
| } | |
| public static void encryptFile(String sourceFilePath, String destPath, SecretKeySpec symetricKey) throws IOException { | |
| Trace trace = CCPerfMonitoring.INSTANCE.startTracing(CCPerfMonitoring.TRACE_FILE_ENCRYPTION_TIME); | |
| OutputStream os; | |
| FileInputStream is; | |
| File sourceFile = new File(sourceFilePath); | |
| long fileSize = sourceFile.length(); | |
| try { | |
| os = createFileOutputStream(destPath, symetricKey); | |
| is = new FileInputStream(sourceFilePath); | |
| StreamsUtil.writeFromInputToOutputNew(is, os); | |
| } finally { | |
| CCPerfMonitoring.INSTANCE.stopFileEncryptionTracing(trace, fileSize, sourceFilePath); | |
| } | |
| } |
🤖 Prompt for AI Agents
In `@app/src/org/commcare/models/encryption/EncryptionIO.java` around lines 35 -
46, The method EncryptionIO.encryptFile starts a trace (trace) but does not
guarantee CCPerfMonitoring.INSTANCE.stopFileEncryptionTracing(...) is called if
StreamsUtil.writeFromInputToOutputNew throws; wrap the file I/O and write call
in a try-finally where in finally you always call
stopFileEncryptionTracing(trace, fileSize, sourceFilePath) and also ensure both
streams (os from createFileOutputStream(...) and is = new FileInputStream(...))
are closed safely (null-check and close inside finally or use try-with-resources
equivalent) so the trace is stopped and resources are released on exceptions as
well.
| FileInputStream is; | ||
| os = createFileOutputStream(destPath, symetricKey); | ||
| is = new FileInputStream(sourceFilePath); | ||
| int fileSize = is.available(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use File.length() instead of InputStream.available() for accurate file size.
is.available() returns an estimate of bytes that can be read without blocking, not the actual file size. For accurate file size metrics, use the file's length directly.
Proposed fix
public static void encryptFile(String sourceFilePath, String destPath, SecretKeySpec symetricKey) throws IOException {
Trace trace = CCPerfMonitoring.INSTANCE.startTracing(CCPerfMonitoring.TRACE_FILE_ENCRYPTION_TIME);
OutputStream os;
FileInputStream is;
+ File sourceFile = new File(sourceFilePath);
+ long fileSize = sourceFile.length();
os = createFileOutputStream(destPath, symetricKey);
is = new FileInputStream(sourceFilePath);
- int fileSize = is.available();
StreamsUtil.writeFromInputToOutputNew(is, os);
CCPerfMonitoring.INSTANCE.stopFileEncryptionTracing(trace, fileSize, sourceFilePath);
}🤖 Prompt for AI Agents
In `@app/src/org/commcare/models/encryption/EncryptionIO.java` at line 42, In
EncryptionIO, replace the use of InputStream.available() to determine file size
(the line assigning fileSize from is.available()) with the actual File.length()
on the File used to open that InputStream (e.g., use inputFile.length()),
converting or validating the long-to-int cast if the code expects an int and
guarding against null/zero files; ensure you reference the same File instance
that produced the InputStream and update any related logic that assumes
available() semantics.
|
@damagatchi retest this please |
1 similar comment
|
@damagatchi retest this please |
|
@damagatchi retest this please |
ec194ee
Product Description
Backmerge Commcare 2.61.3