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

Commit 83e84b8d authored by Hyunho's avatar Hyunho
Browse files

After saving the capability information in the EAB DB, the invalid data is...

After saving the capability information in the EAB DB, the invalid data is immediately deleted from the EAB DB.

However, if you request the information just saved in DB, EabControllerImpl can generate information based on invalid data.

Bug: b/227862302
Test: atest CtsTelephonyTestCases:EabControllerTest and EabControllerTest
Change-Id: I357cbc22821bf8847ba3ac5fb8a98da15fd4d53a
Merged-In: I357cbc22821bf8847ba3ac5fb8a98da15fd4d53a
parent b031bbb5
Loading
Loading
Loading
Loading
+27 −22
Original line number Diff line number Diff line
@@ -126,6 +126,7 @@ public class EabControllerImpl implements EabController {
        // Pick up changes to CarrierConfig and run any applicable cleanup tasks associated with
        // that configuration.
        mCapabilityCleanupRunnable.run();
        cleanupOrphanedRows();
        if (!mIsSetDestroyedFlag) {
            mEabBulkCapabilityUpdater.onCarrierConfigChanged();
        }
@@ -268,7 +269,7 @@ public class EabControllerImpl implements EabController {
                c.close();
            }
        }

        cleanupOrphanedRows();
        mEabBulkCapabilityUpdater.updateExpiredTimeAlert();

        if (mHandler.hasCallbacks(mCapabilityCleanupRunnable)) {
@@ -278,6 +279,25 @@ public class EabControllerImpl implements EabController {
                CLEAN_UP_LEGACY_CAPABILITY_DELAY_MILLI_SEC);
    }

    /**
     * Cleanup the entry of common table that can't map to presence or option table
     */
    @VisibleForTesting
    public void cleanupOrphanedRows() {
        String presenceSelection =
                " (SELECT " + EabProvider.PresenceTupleColumns.EAB_COMMON_ID +
                        " FROM " + EAB_PRESENCE_TUPLE_TABLE_NAME + ") ";
        String optionSelection =
                " (SELECT " + EabProvider.OptionsColumns.EAB_COMMON_ID +
                        " FROM " + EAB_OPTIONS_TABLE_NAME + ") ";

        mContext.getContentResolver().delete(
                EabProvider.COMMON_URI,
                EabProvider.EabCommonColumns._ID + " NOT IN " + presenceSelection +
                        " AND " + EabProvider.EabCommonColumns._ID+ " NOT IN " + optionSelection,
                null);
    }

    private List<EabCapabilityResult> generateDestroyedResult(List<Uri> contactUri) {
        List<EabCapabilityResult> destroyedResult = new ArrayList<>();
        for (Uri uri : contactUri) {
@@ -390,8 +410,12 @@ public class EabControllerImpl implements EabController {
                RcsUceCapabilityBuilderWrapper builderWrapper) {
        if (builderWrapper.getMechanism() == CAPABILITY_MECHANISM_PRESENCE) {
            PresenceBuilder builder = builderWrapper.getPresenceBuilder();
            if (builder != null) {
                builder.addCapabilityTuple(createPresenceTuple(contactUri, cursor));
            if (builder == null) {
                return;
            }
            RcsContactPresenceTuple presenceTuple = createPresenceTuple(contactUri, cursor);
            if (presenceTuple != null) {
                builder.addCapabilityTuple(presenceTuple);
            }
        } else {
            OptionsBuilder builder = builderWrapper.getOptionsBuilder();
@@ -797,7 +821,6 @@ public class EabControllerImpl implements EabController {

        cleanupCapabilities(rcsCapabilitiesExpiredTime, getRcsCommonIdList());
        cleanupCapabilities(nonRcsCapabilitiesExpiredTime, getNonRcsCommonIdList());
        cleanupOrphanedRows();
    }

    private void cleanupCapabilities(long rcsCapabilitiesExpiredTime, List<Integer> commonIdList) {
@@ -865,24 +888,6 @@ public class EabControllerImpl implements EabController {
        return list;
    }

    /**
     * Cleanup the entry of common table that can't map to presence or option table
     */
    private void cleanupOrphanedRows() {
        String presenceSelection =
                " (SELECT " + EabProvider.PresenceTupleColumns.EAB_COMMON_ID +
                        " FROM " + EAB_PRESENCE_TUPLE_TABLE_NAME + ") ";
        String optionSelection =
                " (SELECT " + EabProvider.OptionsColumns.EAB_COMMON_ID +
                        " FROM " + EAB_OPTIONS_TABLE_NAME + ") ";

        mContext.getContentResolver().delete(
                EabProvider.COMMON_URI,
                EabProvider.EabCommonColumns._ID + " NOT IN " + presenceSelection +
                        " AND " + EabProvider.EabCommonColumns._ID+ " NOT IN " + optionSelection,
                null);
    }

    private String getStringValue(Cursor cursor, String column) {
        return cursor.getString(cursor.getColumnIndex(column));
    }
+31 −0
Original line number Diff line number Diff line
@@ -208,6 +208,34 @@ public class EabControllerTest extends ImsTestBase {
                mEabControllerSub1.getCapabilities(contactUriList).get(0).getStatus());
    }

    @Test
    @SmallTest
    public void testSaveCapabilityAndCleanupInvalidDataInCommonTable() throws InterruptedException {
        // Insert invalid data in common table
        ContentValues data = new ContentValues();
        data.put(EabProvider.EabCommonColumns.EAB_CONTACT_ID, -1);
        data.put(EabProvider.EabCommonColumns.MECHANISM, CAPABILITY_MECHANISM_PRESENCE);
        data.put(EabProvider.EabCommonColumns.REQUEST_RESULT, REQUEST_RESULT_FOUND);
        data.put(EabProvider.EabCommonColumns.SUBSCRIPTION_ID, -1);
        mContext.getContentResolver().insert(COMMON_URI, data);

        List<RcsContactUceCapability> contactList = new ArrayList<>();
        contactList.add(createPresenceCapability());
        mEabControllerSub1.saveCapabilities(contactList);

        mExecutor.awaitTermination(TIME_OUT_IN_SEC, TimeUnit.SECONDS);

        // Verify the entry that cannot map to presence/option table has been removed
        Cursor cursor = mContext.getContentResolver().query(COMMON_URI, null, null, null, null);
        while(cursor.moveToNext()) {
            int contactId = cursor.getInt(
                    cursor.getColumnIndex(EabProvider.EabCommonColumns.EAB_CONTACT_ID));
            if (contactId == -1) {
                fail("Invalid data didn't been cleared");
            }
        }
    }

    @Test
    @SmallTest
    public void testCleanupInvalidDataInCommonTable() throws InterruptedException {
@@ -219,6 +247,7 @@ public class EabControllerTest extends ImsTestBase {
        data.put(EabProvider.EabCommonColumns.SUBSCRIPTION_ID, -1);
        mContext.getContentResolver().insert(COMMON_URI, data);

        mEabControllerSub1.cleanupOrphanedRows();
        mExecutor.execute(mEabControllerSub1.mCapabilityCleanupRunnable);
        mExecutor.awaitTermination(TIME_OUT_IN_SEC, TimeUnit.SECONDS);

@@ -252,6 +281,7 @@ public class EabControllerTest extends ImsTestBase {
                expiredDate.getTime().getTime() / 1000);
        mContext.getContentResolver().insert(PRESENCE_URI, data);

        mEabControllerSub1.cleanupOrphanedRows();
        mExecutor.execute(mEabControllerSub1.mCapabilityCleanupRunnable);
        mExecutor.awaitTermination(TIME_OUT_IN_SEC, TimeUnit.SECONDS);

@@ -285,6 +315,7 @@ public class EabControllerTest extends ImsTestBase {
                expiredDate.getTime().getTime() / 1000);
        mContext.getContentResolver().insert(OPTIONS_URI, data);

        mEabControllerSub1.cleanupOrphanedRows();
        mExecutor.execute(mEabControllerSub1.mCapabilityCleanupRunnable);
        mExecutor.awaitTermination(TIME_OUT_IN_SEC, TimeUnit.SECONDS);