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

Commit 576f7a5e authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Removing some usage of shared prefs

Bug: 301661768
Test: Presubmit
Flag: N/A
Change-Id: I158e9a5148d2c9404ea4d2e9e239696b29dbeb20
parent 447b0905
Loading
Loading
Loading
Loading
+4 −7
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ package com.android.launcher3;
import static com.android.launcher3.CellLayout.SPRING_LOADED_PROGRESS;
import static com.android.launcher3.LauncherAnimUtils.LAYOUT_HEIGHT;
import static com.android.launcher3.LauncherAnimUtils.LAYOUT_WIDTH;
import static com.android.launcher3.LauncherPrefs.RECONFIGURABLE_WIDGET_EDUCATION_TIP_SEEN;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_WIDGET_RESIZE_COMPLETED;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_WIDGET_RESIZE_STARTED;
import static com.android.launcher3.views.BaseDragLayer.LAYOUT_X;
@@ -55,8 +56,6 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
    private static final float RESIZE_THRESHOLD = 0.66f;
    private static final int RESIZE_TRANSITION_DURATION_MS = 150;

    private static final String KEY_RECONFIGURABLE_WIDGET_EDUCATION_TIP_SEEN =
            "launcher.reconfigurable_widget_education_tip_seen";
    private static final Rect sTmpRect = new Rect();
    private static final Rect sTmpRect2 = new Rect();

@@ -276,9 +275,8 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
            if (!hasSeenReconfigurableWidgetEducationTip()) {
                post(() -> {
                    if (showReconfigurableWidgetEducationTip() != null) {
                        mLauncher.getSharedPrefs().edit()
                                .putBoolean(KEY_RECONFIGURABLE_WIDGET_EDUCATION_TIP_SEEN,
                                        true).apply();
                        LauncherPrefs.get(getContext()).put(
                                RECONFIGURABLE_WIDGET_EDUCATION_TIP_SEEN, true);
                    }
                });
            }
@@ -872,8 +870,7 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
    }

    private boolean hasSeenReconfigurableWidgetEducationTip() {
        return mLauncher.getSharedPrefs()
                .getBoolean(KEY_RECONFIGURABLE_WIDGET_EDUCATION_TIP_SEEN, false)
        return LauncherPrefs.get(getContext()).get(RECONFIGURABLE_WIDGET_EDUCATION_TIP_SEEN)
                || Utilities.isRunningInTestHarness();
    }
}
+4 −12
Original line number Diff line number Diff line
@@ -237,7 +237,6 @@ import com.android.launcher3.widget.model.WidgetsListBaseEntry;
import com.android.launcher3.widget.picker.WidgetsFullSheet;
import com.android.systemui.plugins.LauncherOverlayPlugin;
import com.android.systemui.plugins.PluginListener;
import com.android.systemui.plugins.shared.LauncherExterns;
import com.android.systemui.plugins.shared.LauncherOverlayManager;
import com.android.systemui.plugins.shared.LauncherOverlayManager.LauncherOverlay;

@@ -259,7 +258,7 @@ import java.util.stream.Stream;
 * Default launcher application.
 */
public class Launcher extends StatefulActivity<LauncherState>
        implements LauncherExterns, Callbacks, InvariantDeviceProfile.OnIDPChangeListener,
        implements Callbacks, InvariantDeviceProfile.OnIDPChangeListener,
        PluginListener<LauncherOverlayPlugin> {
    public static final String TAG = "Launcher";

@@ -696,7 +695,7 @@ public class Launcher extends StatefulActivity<LauncherState>

    @Override
    public void onPluginConnected(LauncherOverlayPlugin overlayManager, Context context) {
        switchOverlay(() -> overlayManager.createOverlayManager(this, this));
        switchOverlay(() -> overlayManager.createOverlayManager(this));
    }

    @Override
@@ -2971,7 +2970,7 @@ public class Launcher extends StatefulActivity<LauncherState>
                for (int j = 0; j < layout.getChildCount(); j++) {
                    Object tag = layout.getChildAt(j).getTag();
                    if (tag != null) {
                        writer.println(prefix + "    " + tag.toString());
                        writer.println(prefix + "    " + tag);
                    }
                }
            }
@@ -2981,7 +2980,7 @@ public class Launcher extends StatefulActivity<LauncherState>
            for (int j = 0; j < layout.getChildCount(); j++) {
                Object tag = layout.getChildAt(j).getTag();
                if (tag != null) {
                    writer.println(prefix + "    " + tag.toString());
                    writer.println(prefix + "    " + tag);
                }
            }
        }
@@ -3247,7 +3246,6 @@ public class Launcher extends StatefulActivity<LauncherState>
    /**
     * Call this after onCreate to set or clear overlay.
     */
    @Override
    public void setLauncherOverlay(LauncherOverlay overlay) {
        mWorkspace.setLauncherOverlay(overlay);
    }
@@ -3355,16 +3353,10 @@ public class Launcher extends StatefulActivity<LauncherState>
        return mModelWriter;
    }

    @Override
    public SharedPreferences getSharedPrefs() {
        return mSharedPrefs;
    }

    @Override
    public SharedPreferences getDevicePrefs() {
        return LauncherPrefs.getDevicePrefs(this);
    }

    public int getOrientation() {
        return mOldConfig.orientation;
    }
+11 −2
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import androidx.annotation.VisibleForTesting
import com.android.launcher3.BuildConfig.WIDGET_ON_FIRST_SCREEN
import com.android.launcher3.LauncherFiles.DEVICE_PREFERENCES_KEY
import com.android.launcher3.LauncherFiles.SHARED_PREFERENCES_KEY
import com.android.launcher3.allapps.WorkProfileManager
import com.android.launcher3.model.DeviceGridState
import com.android.launcher3.pm.InstallSessionHelper
import com.android.launcher3.provider.RestoreDbTask
@@ -312,7 +311,7 @@ class LauncherPrefs(private val encryptedContext: Context) {
        val THEMED_ICONS =
            backedUpItem(Themes.KEY_THEMED_ICONS, false, EncryptionType.MOVE_TO_DEVICE_PROTECTED)
        @JvmField val PROMISE_ICON_IDS = backedUpItem(InstallSessionHelper.PROMISE_ICON_IDS, "")
        @JvmField val WORK_EDU_STEP = backedUpItem(WorkProfileManager.KEY_WORK_EDU_STEP, 0)
        @JvmField val WORK_EDU_STEP = backedUpItem("showed_work_profile_edu", 0)
        @JvmField
        val WORKSPACE_SIZE =
            backedUpItem(
@@ -380,6 +379,16 @@ class LauncherPrefs(private val encryptedContext: Context) {
                encryptionType = EncryptionType.DEVICE_PROTECTED
            )

        // Preferences for widget configurations
        @JvmField
        val RECONFIGURABLE_WIDGET_EDUCATION_TIP_SEEN =
            backedUpItem("launcher.reconfigurable_widget_education_tip_seen", false)
        @JvmField
        val WIDGETS_EDUCATION_DIALOG_SEEN =
            backedUpItem("launcher.widgets_education_dialog_seen", false)
        @JvmField
        val WIDGETS_EDUCATION_TIP_SEEN = backedUpItem("launcher.widgets_education_tip_seen", false)

        @VisibleForTesting
        @JvmStatic
        fun <T> backedUpItem(
+0 −2
Original line number Diff line number Diff line
@@ -62,8 +62,6 @@ import java.util.stream.Stream;
public class WorkProfileManager implements PersonalWorkSlidingTabStrip.OnActivePageChangedListener {
    private static final String TAG = "WorkProfileManager";

    public static final String KEY_WORK_EDU_STEP = "showed_work_profile_edu";

    public static final int STATE_ENABLED = 1;
    public static final int STATE_DISABLED = 2;
    public static final int STATE_TRANSITION = 3;
+4 −5
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
package com.android.launcher3.widget;

import static com.android.app.animation.Interpolators.EMPHASIZED;
import static com.android.launcher3.LauncherPrefs.WIDGETS_EDUCATION_TIP_SEEN;

import android.content.Context;
import android.graphics.Canvas;
@@ -40,6 +41,7 @@ import com.android.launcher3.DragSource;
import com.android.launcher3.DropTarget.DragObject;
import com.android.launcher3.Insettable;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherPrefs;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.dragndrop.DragOptions;
@@ -63,8 +65,6 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView<Launcher>
    /** The default number of cells that can fit horizontally in a widget sheet. */
    public static final int DEFAULT_MAX_HORIZONTAL_SPANS = 4;

    protected static final String KEY_WIDGETS_EDUCATION_TIP_SEEN =
            "launcher.widgets_education_tip_seen";
    protected final Rect mInsets = new Rect();

    /* Touch handling related member variables. */
@@ -330,15 +330,14 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView<Launcher>
                        /* arrowXCoord= */coords[0] + view.getWidth() / 2,
                        /* yCoord= */coords[1]);
        if (arrowTipView != null) {
            mActivityContext.getSharedPrefs().edit()
                    .putBoolean(KEY_WIDGETS_EDUCATION_TIP_SEEN, true).apply();
            LauncherPrefs.get(getContext()).put(WIDGETS_EDUCATION_TIP_SEEN, true);
        }
        return arrowTipView;
    }

    /** Returns {@code true} if tip has previously been shown on any of {@link BaseWidgetSheet}. */
    protected boolean hasSeenEducationTip() {
        return mActivityContext.getSharedPrefs().getBoolean(KEY_WIDGETS_EDUCATION_TIP_SEEN, false)
        return LauncherPrefs.get(getContext()).get(WIDGETS_EDUCATION_TIP_SEEN)
                || Utilities.isRunningInTestHarness();
    }

Loading