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

Commit 9d28eee7 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Allowing base class for ResourceBasedOverride to have Context based constructors

Bug: 330920490
Flag: None
Test: Presubmit
Change-Id: Ib4d1ef80133596a114a4fb32ea8ae918852a77f5
parent e0330e17
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -111,12 +111,11 @@ public class QuickstepModelDelegate extends ModelDelegate {
    private final InvariantDeviceProfile mIDP;
    private final AppEventProducer mAppEventProducer;
    private final StatsManager mStatsManager;
    private final Context mContext;

    protected boolean mActive = false;

    public QuickstepModelDelegate(Context context) {
        mContext = context;
        super(context);
        mAppEventProducer = new AppEventProducer(context, this::onAppTargetEvent);

        mIDP = InvariantDeviceProfile.INSTANCE.get(context);
+1 −1
Original line number Diff line number Diff line
@@ -113,7 +113,7 @@ public class StatsLogCompatManager extends StatsLogManager {
            new CopyOnWriteArrayList<>();

    public StatsLogCompatManager(Context context) {
        mContext = context;
        super(context);
    }

    @Override
+12 −7
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCH
import android.content.Context;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.slice.SliceItem;

@@ -53,11 +54,18 @@ public class StatsLogManager implements ResourceBasedOverride {
    public static final int LAUNCHER_STATE_ALLAPPS = 4;
    public static final int LAUNCHER_STATE_UNCHANGED = 5;

    private InstanceId mInstanceId;
    @NonNull
    protected final Context mContext;
    @Nullable
    protected final ActivityContext mActivityContext;

    protected @Nullable ActivityContext mActivityContext = null;
    protected @Nullable Context mContext = null;
    private KeyboardStateManager mKeyboardStateManager;
    private InstanceId mInstanceId;

    public StatsLogManager(@NonNull Context context) {
        mContext = context;
        mActivityContext = ActivityContext.lookupContextNoThrow(context);
    }

    /**
     * Returns event enum based on the two state transition information when swipe
@@ -1194,10 +1202,7 @@ public class StatsLogManager implements ResourceBasedOverride {
     * Creates a new instance of {@link StatsLogManager} based on provided context.
     */
    public static StatsLogManager newInstance(Context context) {
        StatsLogManager manager = Overrides.getObject(StatsLogManager.class,
        return Overrides.getObject(StatsLogManager.class,
                context.getApplicationContext(), R.string.stats_log_manager_class);
        manager.mActivityContext = ActivityContext.lookupContextNoThrow(context);
        manager.mContext = context;
        return manager;
    }
}
+6 −5
Original line number Diff line number Diff line
@@ -45,28 +45,29 @@ public class ModelDelegate implements ResourceBasedOverride {
            boolean isPrimaryInstance) {
        ModelDelegate delegate = Overrides.getObject(
                ModelDelegate.class, context, R.string.model_delegate_class);
        delegate.init(context, app, appsList, dataModel, isPrimaryInstance);
        delegate.init(app, appsList, dataModel, isPrimaryInstance);
        return delegate;
    }

    protected Context mContext;
    protected final Context mContext;
    protected LauncherAppState mApp;
    protected AllAppsList mAppsList;
    protected BgDataModel mDataModel;
    protected boolean mIsPrimaryInstance;

    public ModelDelegate() { }
    public ModelDelegate(Context context) {
        mContext = context;
    }

    /**
     * Initializes the object with the given params.
     */
    private void init(Context context, LauncherAppState app, AllAppsList appsList,
    private void init(LauncherAppState app, AllAppsList appsList,
            BgDataModel dataModel, boolean isPrimaryInstance) {
        this.mApp = app;
        this.mAppsList = appsList;
        this.mDataModel = dataModel;
        this.mIsPrimaryInstance = isPrimaryInstance;
        this.mContext = context;
    }

    /** Called periodically to validate and update any data */
+10 −6
Original line number Diff line number Diff line
@@ -34,16 +34,20 @@ public interface ResourceBasedOverride {
        public static <T extends ResourceBasedOverride> T getObject(
                Class<T> clazz, Context context, int resId) {
            String className = context.getString(resId);
            if (!TextUtils.isEmpty(className)) {
            boolean isOverridden = !TextUtils.isEmpty(className);

            // First try to load the class with "Context" param
            try {
                    Class<?> cls = Class.forName(className);
                Class<?> cls = isOverridden ? Class.forName(className) : clazz;
                return (T) cls.getDeclaredConstructor(Context.class).newInstance(context);
            } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
                     | ClassCastException | NoSuchMethodException | InvocationTargetException e) {
                if (isOverridden) {
                    Log.e(TAG, "Bad overriden class", e);
                }
            }

            // Load the base class with no parameter
            try {
                return clazz.newInstance();
            } catch (InstantiationException|IllegalAccessException e) {