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

Commit 8debbac6 authored by Arthur Wang's avatar Arthur Wang
Browse files

Add flags to retrieve values from phenotype for DynamicShortcuts.

Add getInteger to Flags class.

bug:30189449
Change-Id: Ie74ae57cd8b0010f7ec6bb8a916fbf42cee8ab40
parent 9482bd12
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ public final class Flags {

    private static Flags sInstance;

    private Map<String,Boolean> mMap;
    private Map<String, Object> mMap;

    public static Flags getInstance(Context context) {
        if (sInstance == null) {
@@ -44,6 +44,10 @@ public final class Flags {
    }

    public boolean getBoolean(String flagName) {
        return mMap.containsKey(flagName) ? mMap.get(flagName) : false;
        return mMap.containsKey(flagName) ? (boolean) mMap.get(flagName) : false;
    }

    public int getInteger(String flagName) {
        return mMap.containsKey(flagName) ? ((Integer) mMap.get(flagName)).intValue() : 0;
    }
}
+8 −19
Original line number Diff line number Diff line
@@ -78,23 +78,6 @@ public class DynamicShortcuts {
    private static final int LONG_LABEL_MAX_LENGTH = 30;
    private static final int MAX_SHORTCUTS = 3;

    /**
     * How long  to wait after a change to the contacts content uri before updating the shortcuts
     * This increases the likelihood that multiple updates will be coalesced in the case that
     * the updates are happening rapidly
     *
     * TODO: this should probably be externally configurable to make it easier to manually test the
     * behavior
     */
    private static final int CONTENT_CHANGE_MIN_UPDATE_DELAY_MILLIS = 10000; // 10 seconds
    /**
     * The maximum time to wait before updating the shortcuts that may have changed.
     *
     * TODO: this should probably be externally configurable to make it easier to manually test the
     * behavior
     */
    private static final int CONTENT_CHANGE_MAX_UPDATE_DELAY_MILLIS = 24*60*60*1000; // 1 day

    // The spec specifies that it should be 44dp @ xxxhdpi
    // Note that ShortcutManager.getIconMaxWidth and ShortcutManager.getMaxHeight return different
    // (larger) values.
@@ -110,6 +93,8 @@ public class DynamicShortcuts {
    private final ShortcutManager mShortcutManager;
    private int mShortLabelMaxLength = SHORT_LABEL_MAX_LENGTH;
    private int mLongLabelMaxLength = LONG_LABEL_MAX_LENGTH;
    private final int mContentChangeMinUpdateDelay;
    private final int mContentChangeMaxUpdateDelay;

    public DynamicShortcuts(Context context) {
        this(context, context.getContentResolver(), (ShortcutManager)
@@ -121,6 +106,10 @@ public class DynamicShortcuts {
        mContext = context;
        mContentResolver = contentResolver;
        mShortcutManager = shortcutManager;
        mContentChangeMinUpdateDelay = Flags.getInstance(mContext)
                .getInteger(Experiments.DYNAMIC_MIN_CONTENT_CHANGE_UPDATE_DELAY_MILLIS);
        mContentChangeMaxUpdateDelay = Flags.getInstance(mContext)
                .getInteger(Experiments.DYNAMIC_MAX_CONTENT_CHANGE_UPDATE_DELAY_MILLIS);
    }

    @VisibleForTesting
@@ -365,8 +354,8 @@ public class DynamicShortcuts {
                // that complexity.
                .addTriggerContentUri(new JobInfo.TriggerContentUri(ContactsContract.AUTHORITY_URI,
                        JobInfo.TriggerContentUri.FLAG_NOTIFY_FOR_DESCENDANTS))
                .setTriggerContentUpdateDelay(CONTENT_CHANGE_MIN_UPDATE_DELAY_MILLIS)
                .setTriggerContentMaxDelay(CONTENT_CHANGE_MAX_UPDATE_DELAY_MILLIS).build();
                .setTriggerContentUpdateDelay(mContentChangeMinUpdateDelay)
                .setTriggerContentMaxDelay(mContentChangeMaxUpdateDelay).build();
        final JobScheduler scheduler = (JobScheduler)
                mContext.getSystemService(Context.JOB_SCHEDULER_SERVICE);
        scheduler.schedule(job);
+13 −0
Original line number Diff line number Diff line
@@ -25,6 +25,19 @@ public final class Experiments {
     */
    public static final String DYNAMIC_SHORTCUTS = "Shortcuts__dynamic_shortcuts";

    /**
     * Flags for minimum content update time
     */
    public static final String DYNAMIC_MIN_CONTENT_CHANGE_UPDATE_DELAY_MILLIS =
            "Shortcuts__dynamic_min_content_change_update_delay_millis";

    /**
     * Flags for maximum content update time
     */
    public static final String DYNAMIC_MAX_CONTENT_CHANGE_UPDATE_DELAY_MILLIS =
            "Shortcuts__dynamic_max_content_change_update_delay_millis";


    private Experiments() {
    }
}