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

Commit f725824f authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Refactoring getPreferenceKey method

This method was returnning a constant and getting inlined by proguard.

Change-Id: I87348e25b21483adc1b27d16f99dec4b73205701
parent 705b4abd
Loading
Loading
Loading
Loading
+3 −7
Original line number Diff line number Diff line
@@ -92,8 +92,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
        if (packageNames.isEmpty()) {
            return;
        }
        String spKey = LauncherAppState.getSharedPreferencesKey();
        SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
        SharedPreferences sp = Utilities.getPrefs(context);
        synchronized(sLock) {
            Set<String> strings = sp.getStringSet(APPS_PENDING_INSTALL, null);
            if (DBG) {
@@ -176,9 +175,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
        LauncherAppState app = LauncherAppState.getInstance();
        boolean launcherNotLoaded = app.getModel().getCallback() == null;

        String spKey = LauncherAppState.getSharedPreferencesKey();
        SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
        addToInstallQueue(sp, info);
        addToInstallQueue(Utilities.getPrefs(context), info);
        if (!mUseInstallQueue && !launcherNotLoaded) {
            flushInstallQueue(context);
        }
@@ -192,8 +189,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
        flushInstallQueue(context);
    }
    static void flushInstallQueue(Context context) {
        String spKey = LauncherAppState.getSharedPreferencesKey();
        SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
        SharedPreferences sp = Utilities.getPrefs(context);
        ArrayList<PendingInstallShortcutInfo> installQueue = getAndClearInstallQueue(sp, context);
        if (!installQueue.isEmpty()) {
            Iterator<PendingInstallShortcutInfo> iter = installQueue.iterator();
+4 −7
Original line number Diff line number Diff line
@@ -426,8 +426,7 @@ public class Launcher extends Activity
                app.getInvariantDeviceProfile().landscapeProfile
                : app.getInvariantDeviceProfile().portraitProfile;

        mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
                Context.MODE_PRIVATE);
        mSharedPrefs = Utilities.getPrefs(this);
        mIsSafeModeEnabled = getPackageManager().isSafeMode();
        mModel = app.setLauncher(this);
        mIconCache = app.getIconCache();
@@ -3636,12 +3635,10 @@ public class Launcher extends Activity
                opts.putAll(mLauncherCallbacks.getAdditionalSearchWidgetOptions());
            }

            SharedPreferences sp = getSharedPreferences(
                    LauncherAppState.getSharedPreferencesKey(), MODE_PRIVATE);
            int widgetId = sp.getInt(QSB_WIDGET_ID, -1);
            int widgetId = mSharedPrefs.getInt(QSB_WIDGET_ID, -1);
            AppWidgetProviderInfo widgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
            if (!searchProvider.provider.flattenToString().equals(
                    sp.getString(QSB_WIDGET_PROVIDER, null))
                    mSharedPrefs.getString(QSB_WIDGET_PROVIDER, null))
                    || (widgetInfo == null)
                    || !widgetInfo.provider.equals(searchProvider.provider)) {
                // A valid widget is not already bound.
@@ -3659,7 +3656,7 @@ public class Launcher extends Activity
                    widgetId = -1;
                }

                sp.edit()
                mSharedPrefs.edit()
                    .putInt(QSB_WIDGET_ID, widgetId)
                    .putString(QSB_WIDGET_PROVIDER, searchProvider.provider.flattenToString())
                    .commit();
+1 −5
Original line number Diff line number Diff line
@@ -153,10 +153,6 @@ public class LauncherAppState {
        return sLauncherProvider.get();
    }

    public static String getSharedPreferencesKey() {
        return LauncherFiles.SHARED_PREFERENCES_KEY;
    }

    public WidgetPreviewLoader getWidgetCache() {
        return mWidgetCache;
    }
+2 −6
Original line number Diff line number Diff line
@@ -73,9 +73,7 @@ class LauncherClings implements OnClickListener {
                    LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE
                            | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS);
            // Set the flag to skip the folder cling
            String spKey = LauncherAppState.getSharedPreferencesKey();
            SharedPreferences sp = mLauncher.getSharedPreferences(spKey, Context.MODE_PRIVATE);
            SharedPreferences.Editor editor = sp.edit();
            SharedPreferences.Editor editor = Utilities.getPrefs(mLauncher).edit();
            editor.putBoolean(Launcher.USER_HAS_MIGRATED, true);
            editor.apply();
            // Disable the migration cling
@@ -254,9 +252,7 @@ class LauncherClings implements OnClickListener {
    }

    public static void synchonouslyMarkFirstRunClingDismissed(Context ctx) {
        SharedPreferences prefs = ctx.getSharedPreferences(
                LauncherAppState.getSharedPreferencesKey(), Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = prefs.edit();
        SharedPreferences.Editor editor = Utilities.getPrefs(ctx).edit();
        editor.putBoolean(WORKSPACE_CLING_DISMISSED_KEY, true);
        editor.commit();
    }
+7 −20
Original line number Diff line number Diff line
@@ -257,17 +257,13 @@ public class LauncherProvider extends ContentProvider {
            case LauncherSettings.Settings.METHOD_GET_BOOLEAN: {
                Bundle result = new Bundle();
                result.putBoolean(LauncherSettings.Settings.EXTRA_VALUE,
                        getContext().getSharedPreferences(
                                LauncherAppState.getSharedPreferencesKey(), Context.MODE_PRIVATE)
                                .getBoolean(arg, extras.getBoolean(
                        Utilities.getPrefs(getContext()).getBoolean(arg, extras.getBoolean(
                                LauncherSettings.Settings.EXTRA_DEFAULT_VALUE)));
                return result;
            }
            case LauncherSettings.Settings.METHOD_SET_BOOLEAN: {
                boolean value = extras.getBoolean(LauncherSettings.Settings.EXTRA_VALUE);
                getContext().getSharedPreferences(
                        LauncherAppState.getSharedPreferencesKey(), Context.MODE_PRIVATE)
                        .edit().putBoolean(arg, value).apply();
                Utilities.getPrefs(getContext()).edit().putBoolean(arg, value).apply();
                if (mListener != null) {
                    mListener.onSettingsChanged(arg, value);
                }
@@ -343,11 +339,7 @@ public class LauncherProvider extends ContentProvider {
    }

    public void clearFlagEmptyDbCreated() {
        String spKey = LauncherAppState.getSharedPreferencesKey();
        getContext().getSharedPreferences(spKey, Context.MODE_PRIVATE)
            .edit()
            .remove(EMPTY_DATABASE_CREATED)
            .commit();
        Utilities.getPrefs(getContext()).edit().remove(EMPTY_DATABASE_CREATED).commit();
    }

    /**
@@ -358,8 +350,7 @@ public class LauncherProvider extends ContentProvider {
     *   4) The default configuration for the particular device
     */
    synchronized public void loadDefaultFavoritesIfNecessary() {
        String spKey = LauncherAppState.getSharedPreferencesKey();
        SharedPreferences sp = getContext().getSharedPreferences(spKey, Context.MODE_PRIVATE);
        SharedPreferences sp = Utilities.getPrefs(getContext());

        if (sp.getBoolean(EMPTY_DATABASE_CREATED, false)) {
            Log.d(TAG, "loading default workspace");
@@ -635,15 +626,11 @@ public class LauncherProvider extends ContentProvider {
        }

        private void setFlagJustLoadedOldDb() {
            String spKey = LauncherAppState.getSharedPreferencesKey();
            SharedPreferences sp = mContext.getSharedPreferences(spKey, Context.MODE_PRIVATE);
            sp.edit().putBoolean(EMPTY_DATABASE_CREATED, false).commit();
            Utilities.getPrefs(mContext).edit().putBoolean(EMPTY_DATABASE_CREATED, false).commit();
        }

        private void setFlagEmptyDbCreated() {
            String spKey = LauncherAppState.getSharedPreferencesKey();
            SharedPreferences sp = mContext.getSharedPreferences(spKey, Context.MODE_PRIVATE);
            sp.edit().putBoolean(EMPTY_DATABASE_CREATED, true).commit();
            Utilities.getPrefs(mContext).edit().putBoolean(EMPTY_DATABASE_CREATED, true).commit();
        }

        @Override
Loading