Allow partners to config the maximum number of call logs for Sim
Bug: 352235494
Test: atest android.provider.cts.contacts.CallLogTest
Flag: android.provider.allow_config_maximum_call_log_entries_per_sim
Change-Id: I2c4ec6c84600880a6d93a9fe020a1bdcd6f54283
diff --git a/core/java/android/provider/CallLog.java b/core/java/android/provider/CallLog.java
index 708c196..192afb1 100644
--- a/core/java/android/provider/CallLog.java
+++ b/core/java/android/provider/CallLog.java
@@ -28,6 +28,7 @@
import android.annotation.SystemApi;
import android.annotation.UserHandleAware;
import android.compat.annotation.UnsupportedAppUsage;
+import android.content.ComponentName;
import android.content.ContentProvider;
import android.content.ContentResolver;
import android.content.ContentValues;
@@ -1624,6 +1625,19 @@
"is_call_log_phone_account_migration_pending";
/**
+ * The default maximum number of call log entries stored in the call log provider for each
+ * {@link PhoneAccountHandle}.
+ */
+ private static final int DEFAULT_MAX_CALL_LOG_SIZE = 500;
+
+ /**
+ * Expected component name of Telephony phone accounts.
+ */
+ private static final ComponentName TELEPHONY_COMPONENT_NAME =
+ new ComponentName("com.android.phone",
+ "com.android.services.telephony.TelephonyConnectionService");
+
+ /**
* Adds a call to the call log.
*
* @param ci the CallerInfo object to get the target contact from. Can be null
@@ -2084,25 +2098,35 @@
}
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))) {
+ final String phoneAccountId =
+ values.containsKey(PHONE_ACCOUNT_ID)
+ ? values.getAsString(PHONE_ACCOUNT_ID) : null;
+ final String phoneAccountComponentName =
+ values.containsKey(PHONE_ACCOUNT_COMPONENT_NAME)
+ ? values.getAsString(PHONE_ACCOUNT_COMPONENT_NAME) : null;
+ int maxCallLogSize = DEFAULT_MAX_CALL_LOG_SIZE;
+ if (!TextUtils.isEmpty(phoneAccountId)
+ && !TextUtils.isEmpty(phoneAccountComponentName)) {
+ if (android.provider.Flags.allowConfigMaximumCallLogEntriesPerSim()
+ && TELEPHONY_COMPONENT_NAME
+ .flattenToString().equals(phoneAccountComponentName)) {
+ maxCallLogSize = context.getResources().getInteger(
+ com.android.internal.R.integer.config_maximumCallLogEntriesPerSim);
+ }
// Only purge entries for the same phone account.
numDeleted = resolver.delete(uri, "_id IN "
+ "(SELECT _id FROM calls"
+ " WHERE " + PHONE_ACCOUNT_COMPONENT_NAME + " = ?"
+ " AND " + PHONE_ACCOUNT_ID + " = ?"
+ " ORDER BY " + DEFAULT_SORT_ORDER
- + " LIMIT -1 OFFSET 500)", new String[] {
- values.getAsString(PHONE_ACCOUNT_COMPONENT_NAME),
- values.getAsString(PHONE_ACCOUNT_ID)
- });
+ + " LIMIT -1 OFFSET " + maxCallLogSize + ")",
+ new String[] { phoneAccountComponentName, phoneAccountId }
+ );
} else {
// No valid phone account specified, so default to the old behavior.
numDeleted = resolver.delete(uri, "_id IN "
+ "(SELECT _id FROM calls ORDER BY " + DEFAULT_SORT_ORDER
- + " LIMIT -1 OFFSET 500)", null);
+ + " LIMIT -1 OFFSET " + maxCallLogSize + ")", null);
}
Log.i(LOG_TAG, "addEntry: cleaned up " + numDeleted + " old entries");
diff --git a/core/java/android/provider/flags.aconfig b/core/java/android/provider/flags.aconfig
index ff98fc4..53d0c62 100644
--- a/core/java/android/provider/flags.aconfig
+++ b/core/java/android/provider/flags.aconfig
@@ -30,4 +30,16 @@
namespace: "backstage_power"
description: "Add a new settings page for the RUN_BACKUP_JOBS permission."
bug: "320563660"
-}
\ No newline at end of file
+}
+
+# OWNER = tgunn TARGET=25Q1
+flag {
+ name: "allow_config_maximum_call_log_entries_per_sim"
+ is_exported: true
+ namespace: "telecom"
+ description: "Allow partners to modify the maximum number of call log size for each sim card."
+ bug: "352235494"
+ metadata {
+ purpose: PURPOSE_FEATURE
+ }
+}