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

Commit d34a378e authored by Fabian Kozynski's avatar Fabian Kozynski Committed by Automerger Merge Worker
Browse files

Merge "Extract SharedPreferences interaction from QSHost" into udc-dev am: 33372bf0

parents 30d3c2c6 33372bf0
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import com.android.systemui.R;
import com.android.systemui.plugins.qs.QSFactory;
import com.android.systemui.plugins.qs.QSTile;
import com.android.systemui.plugins.qs.QSTileView;
import com.android.systemui.qs.pipeline.data.repository.CustomTileAddedRepository;
import com.android.systemui.qs.pipeline.domain.interactor.PanelInteractor;
import com.android.systemui.util.leak.GarbageMonitor;

@@ -34,7 +35,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.List;

public interface QSHost extends PanelInteractor {
public interface QSHost extends PanelInteractor, CustomTileAddedRepository {
    String TILES_SETTING = Settings.Secure.QS_TILES;
    int POSITION_AT_END = -1;

@@ -102,9 +103,6 @@ public interface QSHost extends PanelInteractor {
    void removeTileByUser(ComponentName tile);
    void changeTilesByUser(List<String> previousTiles, List<String> newTiles);

    boolean isTileAdded(ComponentName componentName, int userId);
    void setTileAdded(ComponentName componentName, int userId, boolean added);

    int indexOf(String tileSpec);

    InstanceId getNewInstanceId();
+16 −0
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ import com.android.systemui.flags.FeatureFlags
import com.android.systemui.flags.Flags
import com.android.systemui.qs.QSHost
import com.android.systemui.qs.QSTileHost
import com.android.systemui.qs.pipeline.data.repository.CustomTileAddedRepository
import com.android.systemui.qs.pipeline.data.repository.CustomTileAddedSharedPrefsRepository
import com.android.systemui.qs.pipeline.domain.interactor.PanelInteractor
import com.android.systemui.qs.pipeline.domain.interactor.PanelInteractorImpl
import dagger.Binds
@@ -46,5 +48,19 @@ interface QSHostModule {
                qsHost
            }
        }

        @Provides
        @JvmStatic
        fun provideCustomTileAddedRepository(
            featureFlags: FeatureFlags,
            qsHost: QSHost,
            customTileAddedRepository: CustomTileAddedSharedPrefsRepository
        ): CustomTileAddedRepository {
            return if (featureFlags.isEnabled(Flags.QS_PIPELINE_NEW_HOST)) {
                customTileAddedRepository
            } else {
                qsHost
            }
        }
    }
}
+10 −5
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import androidx.annotation.VisibleForTesting;

import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.qs.external.TileLifecycleManager.TileChangeListener;
import com.android.systemui.qs.pipeline.data.repository.CustomTileAddedRepository;
import com.android.systemui.settings.UserTracker;

import java.util.List;
@@ -59,6 +60,7 @@ public class TileServiceManager {
    private final TileLifecycleManager mStateManager;
    private final Handler mHandler;
    private final UserTracker mUserTracker;
    private final CustomTileAddedRepository mCustomTileAddedRepository;
    private boolean mBindRequested;
    private boolean mBindAllowed;
    private boolean mBound;
@@ -72,9 +74,10 @@ public class TileServiceManager {
    private boolean mStarted = false;

    TileServiceManager(TileServices tileServices, Handler handler, ComponentName component,
            BroadcastDispatcher broadcastDispatcher, UserTracker userTracker) {
        this(tileServices, handler, userTracker, new TileLifecycleManager(handler,
                tileServices.getContext(), tileServices,
            BroadcastDispatcher broadcastDispatcher, UserTracker userTracker,
            CustomTileAddedRepository customTileAddedRepository) {
        this(tileServices, handler, userTracker, customTileAddedRepository,
                new TileLifecycleManager(handler, tileServices.getContext(), tileServices,
                new PackageManagerAdapter(tileServices.getContext()), broadcastDispatcher,
                new Intent(TileService.ACTION_QS_TILE).setComponent(component),
                userTracker.getUserHandle()));
@@ -82,11 +85,13 @@ public class TileServiceManager {

    @VisibleForTesting
    TileServiceManager(TileServices tileServices, Handler handler, UserTracker userTracker,
            CustomTileAddedRepository customTileAddedRepository,
            TileLifecycleManager tileLifecycleManager) {
        mServices = tileServices;
        mHandler = handler;
        mStateManager = tileLifecycleManager;
        mUserTracker = userTracker;
        mCustomTileAddedRepository = customTileAddedRepository;

        IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
@@ -111,8 +116,8 @@ public class TileServiceManager {
        mStarted = true;
        ComponentName component = mStateManager.getComponent();
        final int userId = mStateManager.getUserId();
        if (!mServices.getHost().isTileAdded(component, userId)) {
            mServices.getHost().setTileAdded(component, userId, true);
        if (!mCustomTileAddedRepository.isTileAdded(component, userId)) {
            mCustomTileAddedRepository.setTileAdded(component, userId, true);
            mStateManager.onTileAdded();
            mStateManager.flushMessagesAndUnbind();
        }
+6 −2
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.qs.QSHost;
import com.android.systemui.qs.pipeline.data.repository.CustomTileAddedRepository;
import com.android.systemui.qs.pipeline.domain.interactor.PanelInteractor;
import com.android.systemui.settings.UserTracker;
import com.android.systemui.statusbar.CommandQueue;
@@ -77,6 +78,7 @@ public class TileServices extends IQSService.Stub {
    private final UserTracker mUserTracker;
    private final StatusBarIconController mStatusBarIconController;
    private final PanelInteractor mPanelInteractor;
    private final CustomTileAddedRepository mCustomTileAddedRepository;

    private int mMaxBound = DEFAULT_MAX_BOUND;

@@ -89,7 +91,8 @@ public class TileServices extends IQSService.Stub {
            KeyguardStateController keyguardStateController,
            CommandQueue commandQueue,
            StatusBarIconController statusBarIconController,
            PanelInteractor panelInteractor) {
            PanelInteractor panelInteractor,
            CustomTileAddedRepository customTileAddedRepository) {
        mHost = host;
        mKeyguardStateController = keyguardStateController;
        mContext = mHost.getContext();
@@ -101,6 +104,7 @@ public class TileServices extends IQSService.Stub {
        mStatusBarIconController = statusBarIconController;
        mCommandQueue.addCallback(mRequestListeningCallback);
        mPanelInteractor = panelInteractor;
        mCustomTileAddedRepository = customTileAddedRepository;
    }

    public Context getContext() {
@@ -128,7 +132,7 @@ public class TileServices extends IQSService.Stub {
    protected TileServiceManager onCreateTileService(ComponentName component,
            BroadcastDispatcher broadcastDispatcher) {
        return new TileServiceManager(this, mHandlerProvider.get(), component,
                broadcastDispatcher, mUserTracker);
                broadcastDispatcher, mUserTracker, mCustomTileAddedRepository);
    }

    public void freeService(CustomTile tile, TileServiceManager service) {
+65 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.qs.pipeline.data.repository

import android.content.ComponentName
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.settings.UserFileManager
import javax.inject.Inject

/**
 * Repository for keeping track of whether a given [CustomTile] [ComponentName] has been added to
 * the set of current tiles for a user. This is used to determine when lifecycle methods in
 * `TileService` about the tile being added/removed need to be called.
 */
interface CustomTileAddedRepository {
    /**
     * Check if a particular [CustomTile] associated with [componentName] has been added for
     * [userId] and has not been removed since.
     */
    fun isTileAdded(componentName: ComponentName, userId: Int): Boolean

    /**
     * Persists whether a particular [CustomTile] associated with [componentName] has been added and
     * it's currently in the set of selected tiles for [userId].
     */
    fun setTileAdded(componentName: ComponentName, userId: Int, added: Boolean)
}

@SysUISingleton
class CustomTileAddedSharedPrefsRepository
@Inject
constructor(private val userFileManager: UserFileManager) : CustomTileAddedRepository {

    override fun isTileAdded(componentName: ComponentName, userId: Int): Boolean {
        return userFileManager
            .getSharedPreferences(TILES, 0, userId)
            .getBoolean(componentName.flattenToString(), false)
    }

    override fun setTileAdded(componentName: ComponentName, userId: Int, added: Boolean) {
        userFileManager
            .getSharedPreferences(TILES, 0, userId)
            .edit()
            .putBoolean(componentName.flattenToString(), added)
            .apply()
    }

    companion object {
        private const val TILES = "tiles_prefs"
    }
}
Loading