From bb3e0b23f9fbd932a6f988f0162b84e5c7541169 Mon Sep 17 00:00:00 2001 From: Tyler Gunn Date: Fri, 21 Jul 2023 23:39:42 +0000 Subject: [PATCH] Add logging to indicate how many call log rows are cleaned up on insert. When call log entries are added we'll potentially clean up a call log entry if we've hit the cap of 500 rows per phone account. We log this and also log errors with a higher log level. Bug: 290557274 Test: Manual testing to verify the new logging information is present as expected. Change-Id: Ic816983941bccad62246bb58e1e6fa15b01f3791 --- core/java/android/provider/CallLog.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/core/java/android/provider/CallLog.java b/core/java/android/provider/CallLog.java index ac6b2b23cdf56..3c5757dd5615e 100644 --- a/core/java/android/provider/CallLog.java +++ b/core/java/android/provider/CallLog.java @@ -1985,13 +1985,14 @@ public class CallLog { Log.w(LOG_TAG, "Failed to insert into call log; null result uri."); } + int numDeleted; if (values.containsKey(PHONE_ACCOUNT_ID) && !TextUtils.isEmpty(values.getAsString(PHONE_ACCOUNT_ID)) && values.containsKey(PHONE_ACCOUNT_COMPONENT_NAME) && !TextUtils.isEmpty(values.getAsString(PHONE_ACCOUNT_COMPONENT_NAME))) { // Only purge entries for the same phone account. - resolver.delete(uri, "_id IN " + - "(SELECT _id FROM calls" + numDeleted = resolver.delete(uri, "_id IN " + + "(SELECT _id FROM calls" + " WHERE " + PHONE_ACCOUNT_COMPONENT_NAME + " = ?" + " AND " + PHONE_ACCOUNT_ID + " = ?" + " ORDER BY " + DEFAULT_SORT_ORDER @@ -2001,14 +2002,15 @@ public class CallLog { }); } else { // No valid phone account specified, so default to the old behavior. - resolver.delete(uri, "_id IN " + - "(SELECT _id FROM calls ORDER BY " + DEFAULT_SORT_ORDER + numDeleted = resolver.delete(uri, "_id IN " + + "(SELECT _id FROM calls ORDER BY " + DEFAULT_SORT_ORDER + " LIMIT -1 OFFSET 500)", null); } + Log.i(LOG_TAG, "addEntry: cleaned up " + numDeleted + " old entries"); return result; } catch (IllegalArgumentException e) { - Log.w(LOG_TAG, "Failed to insert calllog", e); + Log.e(LOG_TAG, "Failed to insert calllog", e); // Even though we make sure the target user is running and decrypted before calling // this method, there's a chance that the user just got shut down, in which case // we'll still get "IllegalArgumentException: Unknown URL content://call_log/calls".