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

Commit d56b4715 authored by Piyush Singhania's avatar Piyush Singhania Committed by Android (Google) Code Review
Browse files

Merge "Fix: Add configuration to cache nulls in annotations." into main

parents 8138fcec 0501575b
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ public class CacheConfig {
    private int mNumberOfParams = 0;
    private String mInputType = Constants.JAVA_LANG_VOID;
    private String mResultType;
    private final boolean mCacheNulls;

    public CacheConfig(TypeElement classElement, ExecutableElement method) {
        CachedPropertyDefaults classAnnotation = classElement.getAnnotation(
@@ -61,6 +62,7 @@ public class CacheConfig {
        }
        mResultType = primitiveTypeToObjectEquivalent(method.getReturnType().toString());
        mGeneratedClassName = classAnnotation.name().isEmpty() ? mClassName + "Cache" : mClassName;
        mCacheNulls = methodAnnotation.cacheNulls();
    }

    public CacheModifiers getModifiers() {
@@ -113,6 +115,10 @@ public class CacheConfig {
        }
    }

    public boolean getCacheNulls() {
        return mCacheNulls;
    }

    public int getNumberOfParams() {
        return mNumberOfParams;
    }
+3 −1
Original line number Diff line number Diff line
@@ -124,8 +124,10 @@ public class IpcDataCacheComposer {
                mCacheConfig.getPropertyVariable(), queryCall);
        result += "\n  synchronized (" + lockObject + " ) {";
        result += "\n    if (" + mCacheConfig.getPropertyVariable() + " == null) {";
        result += "\n    IpcDataCache.Config config = " + generateCreateIpcConfig() + ";";
        result += "\n    config = config.cacheNulls(" + mCacheConfig.getCacheNulls() + ");";
        result += "\n      " + mCacheConfig.getPropertyVariable() + " = new IpcDataCache" + "("
                + generateCreateIpcConfig() + ", " + binderParam.getName()
                + "config" + ", " + binderParam.getName()
                + bypassParam.getNextName() + ");\n";
        result += "\n   }";
        result += "\n  }";
+7 −0
Original line number Diff line number Diff line
@@ -21,6 +21,13 @@ public class IpcDataCache<Input, Output> {
    public static class Config {
        public Config(int max, String module, String api, String name) {
        }

        /**
         * Set the cacheNull behavior.
         */
        public Config cacheNulls(boolean enable) {
            return this;
        }
    }

    /** Shadow method for generated code compilation tests purposes only.
+2 −2
Original line number Diff line number Diff line
@@ -32,12 +32,12 @@ public class Custom {
    }

    /**
     * Testing custom class values to generate static IpcDataCache
     * Testing custom class values to generate static IpcDataCache and caching nulls
     *
     * @param userId - user Id
     * @return birthday date of given user Id
     */
    @CachedProperty()
    @CachedProperty(cacheNulls = true)
    public Date getBirthday(int userId) {
        return TestCache.getBirthday(mService::getBirthday, userId);
    }
+42 −44
Original line number Diff line number Diff line
@@ -45,11 +45,10 @@ public class DefaultCache {
        }
        synchronized (sBirthdayLock) {
            if (sBirthday == null) {
                sBirthday = new IpcDataCache(
                        new IpcDataCache.Config(32, "system_server",
                                "default_birthday", "Birthday"),
                        binderCall, bypassPredicate);

                IpcDataCache.Config config = new IpcDataCache.Config(32, "system_server",
                        "default_birthday", "Birthday");
                config = config.cacheNulls(false);
                sBirthday = new IpcDataCache(config, binderCall, bypassPredicate);
            }
        }
        return sBirthday.query(query);
@@ -73,11 +72,10 @@ public class DefaultCache {
        }
        synchronized (sBirthdayLock) {
            if (sBirthday == null) {
                sBirthday = new IpcDataCache(
                        new IpcDataCache.Config(32, "system_server",
                                "default_birthday", "Birthday"),
                        binderCall);

                IpcDataCache.Config config = new IpcDataCache.Config(32, "system_server",
                        "default_birthday", "Birthday");
                config = config.cacheNulls(false);
                sBirthday = new IpcDataCache(config, binderCall);
            }
        }
        return sBirthday.query(query);
@@ -116,10 +114,10 @@ public class DefaultCache {
        }
        synchronized (sDaysTillBirthdayLock) {
            if (sDaysTillBirthday == null) {
                sDaysTillBirthday = new IpcDataCache(
                        new IpcDataCache.Config(32, "system_server", "default_days_till_birthday",
                                "DaysTillBirthday"), binderCall, bypassPredicate);

                IpcDataCache.Config config = new IpcDataCache.Config(32, "system_server",
                        "default_days_till_birthday", "DaysTillBirthday");
                config = config.cacheNulls(false);
                sDaysTillBirthday = new IpcDataCache(config, binderCall, bypassPredicate);
            }
        }
        return sDaysTillBirthday.query(query);
@@ -144,10 +142,10 @@ public class DefaultCache {
        }
        synchronized (sDaysTillBirthdayLock) {
            if (sDaysTillBirthday == null) {
                sDaysTillBirthday = new IpcDataCache(
                        new IpcDataCache.Config(32, "system_server", "default_days_till_birthday",
                                "DaysTillBirthday"), binderCall);

                IpcDataCache.Config config = new IpcDataCache.Config(32, "system_server",
                        "default_days_till_birthday", "DaysTillBirthday");
                config = config.cacheNulls(false);
                sDaysTillBirthday = new IpcDataCache(config, binderCall);
            }
        }
        return sDaysTillBirthday.query(query);
@@ -186,10 +184,10 @@ public class DefaultCache {
        }
        synchronized (mDaysSinceBirthdayLock) {
            if (mDaysSinceBirthday == null) {
                mDaysSinceBirthday = new IpcDataCache(
                        new IpcDataCache.Config(32, "system_server", "default_days_since_birthday",
                                "DaysSinceBirthday"), binderCall, bypassPredicate);

                IpcDataCache.Config config = new IpcDataCache.Config(32, "system_server",
                        "default_days_since_birthday", "DaysSinceBirthday");
                config = config.cacheNulls(false);
                mDaysSinceBirthday = new IpcDataCache(config, binderCall, bypassPredicate);
            }
        }
        return mDaysSinceBirthday.query(query);
@@ -214,10 +212,10 @@ public class DefaultCache {
        }
        synchronized (mDaysSinceBirthdayLock) {
            if (mDaysSinceBirthday == null) {
                mDaysSinceBirthday = new IpcDataCache(
                        new IpcDataCache.Config(32, "system_server", "default_days_since_birthday",
                                "DaysSinceBirthday"), binderCall);

                IpcDataCache.Config config = new IpcDataCache.Config(32, "system_server",
                        "default_days_since_birthday", "DaysSinceBirthday");
                config = config.cacheNulls(false);
                mDaysSinceBirthday = new IpcDataCache(config, binderCall);
            }
        }
        return mDaysSinceBirthday.query(query);
@@ -253,10 +251,10 @@ public class DefaultCache {
        }
        synchronized (sDaysTillMyBirthdayLock) {
            if (sDaysTillMyBirthday == null) {
                sDaysTillMyBirthday = new IpcDataCache(
                        new IpcDataCache.Config(1, "system_server", "default_days_till_my_birthday",
                                "DaysTillMyBirthday"), binderCall);

                IpcDataCache.Config config = new IpcDataCache.Config(1, "system_server",
                        "default_days_till_my_birthday", "DaysTillMyBirthday");
                config = config.cacheNulls(false);
                sDaysTillMyBirthday = new IpcDataCache(config, binderCall);
            }
        }
        return sDaysTillMyBirthday.query(null);
@@ -292,10 +290,10 @@ public class DefaultCache {
        }
        synchronized (mDaysSinceMyBirthdayLock) {
            if (mDaysSinceMyBirthday == null) {
                mDaysSinceMyBirthday = new IpcDataCache(
                        new IpcDataCache.Config(1, "system_server", "my_unique_key",
                                "DaysSinceMyBirthday"), binderCall);

                IpcDataCache.Config config = new IpcDataCache.Config(1, "system_server",
                        "my_unique_key", "DaysSinceMyBirthday");
                config = config.cacheNulls(false);
                mDaysSinceMyBirthday = new IpcDataCache(config, binderCall);
            }
        }
        return mDaysSinceMyBirthday.query(null);
@@ -336,11 +334,11 @@ public class DefaultCache {
        }
        synchronized (sBirthdayWishesFromUserLock) {
            if (sBirthdayWishesFromUser == null) {
                sBirthdayWishesFromUser = new IpcDataCache(
                        new IpcDataCache.Config(32, "telephony",
                IpcDataCache.Config config = new IpcDataCache.Config(32, "telephony",
                        "default_birthday_wishes_from_user",
                                "BirthdayWishesFromUser"), binderCall, bypassPredicate);

                        "BirthdayWishesFromUser");
                config = config.cacheNulls(false);
                sBirthdayWishesFromUser = new IpcDataCache(config, binderCall, bypassPredicate);
            }
        }
        return sBirthdayWishesFromUser.query(query);
@@ -365,11 +363,11 @@ public class DefaultCache {
        }
        synchronized (sBirthdayWishesFromUserLock) {
            if (sBirthdayWishesFromUser == null) {
                sBirthdayWishesFromUser = new IpcDataCache(
                        new IpcDataCache.Config(32, "telephony",
                IpcDataCache.Config config = new IpcDataCache.Config(32, "telephony",
                        "default_birthday_wishes_from_user",
                                "BirthdayWishesFromUser"), binderCall);

                        "BirthdayWishesFromUser");
                config = config.cacheNulls(false);
                sBirthdayWishesFromUser = new IpcDataCache(config, binderCall);
            }
        }
        return sBirthdayWishesFromUser.query(query);
Loading