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

Commit 0a7e5b85 authored by Fabian Kozynski's avatar Fabian Kozynski
Browse files

Implement UserTracker

This implements a new UserTracker for SystemUI that is meant to
centralize information about current user and current profiles.

It will serve the same function as CurrentUserContextTracker (replaced),
CurrentUserTracker (to be removed), and ACTION_USER_SWITCHED broadcasts
(to be removed). It'll also serve to remove all other calls to
ActivityManager.getCurrentUser().

Test: SystemUITests
Test: manual
Bug: 163579262

Change-Id: I6a7251485d88ce9b9131b9aff3b4343c3e8c823b
parent d2e2eda8
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;

import com.android.systemui.settings.CurrentUserContextTracker;
import com.android.systemui.settings.UserContextProvider;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -38,7 +38,7 @@ import java.util.Set;
 *
 * NOTE: Clients of this class should take care to pass in the correct user context when querying
 * settings, otherwise you will always read/write for user 0 which is almost never what you want.
 * See {@link CurrentUserContextTracker} for a simple way to get the current context
 * See {@link UserContextProvider} for a simple way to get the current context
 */
public final class Prefs {
    private Prefs() {} // no instantation
+5 −5
Original line number Diff line number Diff line
@@ -130,7 +130,7 @@ import com.android.systemui.model.SysUiState;
import com.android.systemui.plugins.ActivityStarter;
import com.android.systemui.plugins.GlobalActions.GlobalActionsManager;
import com.android.systemui.plugins.GlobalActionsPanelPlugin;
import com.android.systemui.settings.CurrentUserContextTracker;
import com.android.systemui.settings.UserContextProvider;
import com.android.systemui.statusbar.NotificationShadeDepthController;
import com.android.systemui.statusbar.NotificationShadeWindowController;
import com.android.systemui.statusbar.policy.ConfigurationController;
@@ -252,7 +252,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
    private final RingerModeTracker mRingerModeTracker;
    private int mDialogPressDelay = DIALOG_PRESS_DELAY; // ms
    private Handler mMainHandler;
    private CurrentUserContextTracker mCurrentUserContextTracker;
    private UserContextProvider mUserContextProvider;
    @VisibleForTesting
    boolean mShowLockScreenCardsAndControls = false;

@@ -313,7 +313,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
            UiEventLogger uiEventLogger,
            RingerModeTracker ringerModeTracker, SysUiState sysUiState, @Main Handler handler,
            ControlsComponent controlsComponent,
            CurrentUserContextTracker currentUserContextTracker) {
            UserContextProvider userContextProvider) {
        mContext = context;
        mWindowManagerFuncs = windowManagerFuncs;
        mAudioManager = audioManager;
@@ -342,7 +342,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
        mControlsControllerOptional = controlsComponent.getControlsController();
        mSysUiState = sysUiState;
        mMainHandler = handler;
        mCurrentUserContextTracker = currentUserContextTracker;
        mUserContextProvider = userContextProvider;

        // receive broadcasts
        IntentFilter filter = new IntentFilter();
@@ -436,7 +436,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
        String[] preferredControlsPackages = mContext.getResources()
                .getStringArray(com.android.systemui.R.array.config_controlsPreferredPackages);

        SharedPreferences prefs = mCurrentUserContextTracker.getCurrentUserContext()
        SharedPreferences prefs = mUserContextProvider.getUserContext()
                .getSharedPreferences(PREFS_CONTROLS_FILE, Context.MODE_PRIVATE);
        Set<String> seededPackages = prefs.getStringSet(PREFS_CONTROLS_SEEDING_COMPLETED,
                Collections.emptySet());
+6 −6
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.UiEventLogger;
import com.android.systemui.R;
import com.android.systemui.dagger.qualifiers.LongRunning;
import com.android.systemui.settings.CurrentUserContextTracker;
import com.android.systemui.settings.UserContextProvider;
import com.android.systemui.statusbar.phone.KeyguardDismissUtil;

import java.io.IOException;
@@ -79,12 +79,12 @@ public class RecordingService extends Service implements MediaRecorder.OnInfoLis
    private final Executor mLongExecutor;
    private final UiEventLogger mUiEventLogger;
    private final NotificationManager mNotificationManager;
    private final CurrentUserContextTracker mUserContextTracker;
    private final UserContextProvider mUserContextTracker;

    @Inject
    public RecordingService(RecordingController controller, @LongRunning Executor executor,
            UiEventLogger uiEventLogger, NotificationManager notificationManager,
            CurrentUserContextTracker userContextTracker, KeyguardDismissUtil keyguardDismissUtil) {
            UserContextProvider userContextTracker, KeyguardDismissUtil keyguardDismissUtil) {
        mController = controller;
        mLongExecutor = executor;
        mUiEventLogger = uiEventLogger;
@@ -120,7 +120,7 @@ public class RecordingService extends Service implements MediaRecorder.OnInfoLis
        String action = intent.getAction();
        Log.d(TAG, "onStartCommand " + action);

        int mCurrentUserId = mUserContextTracker.getCurrentUserContext().getUserId();
        int mCurrentUserId = mUserContextTracker.getUserContext().getUserId();
        UserHandle currentUser = new UserHandle(mCurrentUserId);
        switch (action) {
            case ACTION_START:
@@ -136,7 +136,7 @@ public class RecordingService extends Service implements MediaRecorder.OnInfoLis
                setTapsVisible(mShowTaps);

                mRecorder = new ScreenMediaRecorder(
                        mUserContextTracker.getCurrentUserContext(),
                        mUserContextTracker.getUserContext(),
                        mCurrentUserId,
                        mAudioSource,
                        this
@@ -156,7 +156,7 @@ public class RecordingService extends Service implements MediaRecorder.OnInfoLis
                // we want to post the notifications for that user, which is NOT current user
                int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
                if (userId == -1) {
                    userId = mUserContextTracker.getCurrentUserContext().getUserId();
                    userId = mUserContextTracker.getUserContext().getUserId();
                }
                Log.d(TAG, "notifying for user " + userId);
                stopRecording(userId);
+5 −5
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ import android.widget.Spinner;
import android.widget.Switch;

import com.android.systemui.R;
import com.android.systemui.settings.CurrentUserContextTracker;
import com.android.systemui.settings.UserContextProvider;

import java.util.ArrayList;
import java.util.List;
@@ -51,7 +51,7 @@ public class ScreenRecordDialog extends Activity {
    private static final String TAG = "ScreenRecordDialog";

    private final RecordingController mController;
    private final CurrentUserContextTracker mCurrentUserContextTracker;
    private final UserContextProvider mUserContextProvider;
    private Switch mTapsSwitch;
    private Switch mAudioSwitch;
    private Spinner mOptions;
@@ -59,9 +59,9 @@ public class ScreenRecordDialog extends Activity {

    @Inject
    public ScreenRecordDialog(RecordingController controller,
            CurrentUserContextTracker currentUserContextTracker) {
            UserContextProvider userContextProvider) {
        mController = controller;
        mCurrentUserContextTracker = currentUserContextTracker;
        mUserContextProvider = userContextProvider;
    }

    @Override
@@ -108,7 +108,7 @@ public class ScreenRecordDialog extends Activity {
    }

    private void requestScreenCapture() {
        Context userContext = mCurrentUserContextTracker.getCurrentUserContext();
        Context userContext = mUserContextProvider.getUserContext();
        boolean showTaps = mTapsSwitch.isChecked();
        ScreenRecordingAudioSource audioMode = mAudioSwitch.isChecked()
                ? (ScreenRecordingAudioSource) mOptions.getSelectedItem()
+5 −2
Original line number Diff line number Diff line
@@ -18,7 +18,10 @@ package com.android.systemui.settings

import android.content.ContentResolver

interface CurrentUserContentResolverProvider {
/**
 * Implemented by [UserTrackerImpl].
 */
interface UserContentResolverProvider {

    val currentUserContentResolver: ContentResolver
    val userContentResolver: ContentResolver
}
 No newline at end of file
Loading