Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 69fc8d93 authored by Rhed Jao's avatar Rhed Jao
Browse files

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
parent 83ce4c2d
Loading
Loading
Loading
Loading
+33 −9
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.annotation.SuppressLint;
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;
@@ -1623,6 +1624,19 @@ public class CallLog {
        public static final String IS_PHONE_ACCOUNT_MIGRATION_PENDING =
                "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.
         *
@@ -2084,25 +2098,35 @@ public class CallLog {
                }

                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");

+13 −1
Original line number Diff line number Diff line
@@ -31,3 +31,15 @@ flag {
    description: "Add a new settings page for the RUN_BACKUP_JOBS permission."
    bug: "320563660"
}

# 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
    }
}