diff options
author | Grant Menke <grantmenke@google.com> | 2023-04-26 16:12:46 -0700 |
---|---|---|
committer | Grant Menke <grantmenke@google.com> | 2023-04-26 23:35:35 +0000 |
commit | d24120081434e3f4d06a74c82ef50bae6eb636f5 (patch) | |
tree | ea3960be2a150bf1177c04bb4eba7507b511c7e9 | |
parent | 5709ab2926d6fba696af9a27031f07bcc8215a00 (diff) | |
download | CallLogProvider-d24120081434e3f4d06a74c82ef50bae6eb636f5.tar.gz |
Catch all types of exceptions in CallLogBackupAgent#runBackup.
By the current implementation, CallLogBackupAgent#runBackup could be invoked with a null value passed in for BackupDataOutput. This would result in a fatal NPE that is not currently being caught or handled anywhere. There is no non-null check at a higher level (such as BackupAgent#onBackup) to prevent this issue either. This CL ensures that all types of exceptions are caught and handled correctly.
Fixes: 279649049
Test: atest CallLogBackupAgentTest#testRunBackup_OneNewCall_NullBackupDataOutput
Change-Id: Ibddbb86b97ff5e00ee2e31527df7a1a0e5bdcbda
-rw-r--r-- | src/com/android/calllogbackup/CallLogBackupAgent.java | 2 | ||||
-rw-r--r-- | tests/src/com/android/calllogbackup/CallLogBackupAgentTest.java | 15 |
2 files changed, 16 insertions, 1 deletions
diff --git a/src/com/android/calllogbackup/CallLogBackupAgent.java b/src/com/android/calllogbackup/CallLogBackupAgent.java index 02adacc..b0b0c1c 100644 --- a/src/com/android/calllogbackup/CallLogBackupAgent.java +++ b/src/com/android/calllogbackup/CallLogBackupAgent.java @@ -646,7 +646,7 @@ public class CallLogBackupAgent extends BackupAgent { if (isDebug()) { Log.d(TAG, "Wrote call to backup: " + call + " with byte array: " + baos); } - } catch (IOException e) { + } catch (Exception e) { mBackupRestoreEventLoggerProxy.logItemsBackupFailed( CALLLOGS, /* count */ 1, ERROR_BACKUP_CALL_FAILED); Log.e(TAG, "Failed to backup call: " + call, e); diff --git a/tests/src/com/android/calllogbackup/CallLogBackupAgentTest.java b/tests/src/com/android/calllogbackup/CallLogBackupAgentTest.java index d768dbd..96ac049 100644 --- a/tests/src/com/android/calllogbackup/CallLogBackupAgentTest.java +++ b/tests/src/com/android/calllogbackup/CallLogBackupAgentTest.java @@ -233,6 +233,21 @@ public class CallLogBackupAgentTest extends AndroidTestCase { assertEquals(backupRestoreLoggerFailCount, 1); } + public void testRunBackup_OneNewCall_NullBackupDataOutput() throws Exception { + CallLogBackupState state = new CallLogBackupState(); + state.version = CallLogBackupAgent.VERSION; + state.callIds = new TreeSet<>(); + List<Call> calls = new LinkedList<>(); + calls.add(makeCall(101, 0L, 0L, "555-5555")); + + // Invoke runBackup() with a null value for BackupDataOutput causing an exception: + mCallLogBackupAgent.runBackup(state, null, calls); + + // Ensure the {@link BackupRestoreEventLogger} is informed of the failed backed up call: + assertEquals(backupRestoreLoggerSuccessCount, 0); + assertEquals(backupRestoreLoggerFailCount, 1); + } + public void testRunBackup_OneNewCall() throws Exception { CallLogBackupState state = new CallLogBackupState(); state.version = CallLogBackupAgent.VERSION; |