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

Commit 781047c0 authored by Daniel Akinola's avatar Daniel Akinola
Browse files

Update files for Shade Dialog linter

Added a new linter which shows places which use the wrong context for
dialogs created through the QS shade, so updating these few occurences
to ensure the relevant components work properly on an external display

Bug: 385331017
Test: running linter
Test: atest BiometricNotificationDialogFactoryTest
Test: atest DataSaverDialogDelegateTest
Test: atest DataSaverTileActionInteractorTest
Flag: EXEMPT refactor only
Change-Id: I50b15ae5c0e73f4797bbd2db6afcde3267cb040a
parent 400e09b4
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -32784,4 +32784,15 @@
            column="23"/>
    </issue>
    <issue
        id="ShadeDisplayAwareContextChecker"
        message="UI elements of the shade window should use ShadeDisplayAware-annotated Context, as the shade might move between windows, and only @ShadeDisplayAware resources are updated with the new configuration correctly. Failures to do so might result in wrong dimensions for shade window classes (e.g. using the wrong density or theme). If the usage of Context is not related to display specific configuration or UI, then there is technically no need to use the annotation, and you can annotate the class with @SuppressLint(&quot;ShadeDisplayAwareContextChecker&quot;)/@Suppress(&quot;ShadeDisplayAwareContextChecker&quot;)"
        errorLine1="            @QSThemedContext Context context,"
        errorLine2="                                     ~~~~~~~">
        <location
            file="frameworks/base/packages/SystemUI/src/com/android/systemui/qs/customize/TileAdapter.java"
            line="126"
            column="38"/>
    </issue>
</issues>
+7 −2
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
@@ -39,6 +40,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;

import com.android.systemui.SysuiTestCase;
import com.android.systemui.shade.domain.interactor.FakeShadeDialogContextInteractor;
import com.android.systemui.statusbar.phone.SystemUIDialog;

import org.junit.Before;
@@ -65,22 +67,25 @@ public class BiometricNotificationDialogFactoryTest extends SysuiTestCase {
    @Mock SystemUIDialog.Factory mSystemUIDialogFactory;
    @Mock SystemUIDialog mDialog;
    @Mock BiometricNotificationDialogFactory.ActivityStarter mActivityStarter;

    private final ArgumentCaptor<DialogInterface.OnClickListener> mOnClickListenerArgumentCaptor =
            ArgumentCaptor.forClass(DialogInterface.OnClickListener.class);
    private final ArgumentCaptor<Intent> mIntentArgumentCaptor =
            ArgumentCaptor.forClass(Intent.class);
    private BiometricNotificationDialogFactory mDialogFactory;
    private FakeShadeDialogContextInteractor mDialogContextInteractor;

    @Before
    public void setUp() throws ExecutionException, InterruptedException {
        when(mFingerprintManager.hasEnrolledTemplates(anyInt())).thenReturn(true);
        when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(true);
        when(mSystemUIDialogFactory.create()).thenReturn(mDialog);
        when(mSystemUIDialogFactory.create(any(Context.class))).thenReturn(mDialog);

        mDialogContextInteractor = new FakeShadeDialogContextInteractor(mContext);

        mDialogFactory = new BiometricNotificationDialogFactory(
                mResources,
                mSystemUIDialogFactory,
                mDialogContextInteractor,
                mFingerprintManager,
                mFaceManager
        );
+6 −2
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.internal.R
import com.android.systemui.SysuiTestCase
import com.android.systemui.shade.domain.interactor.FakeShadeDialogContextInteractor
import com.android.systemui.statusbar.phone.SystemUIDialog
import com.android.systemui.util.mockito.any
import com.android.systemui.util.mockito.eq
@@ -46,24 +47,27 @@ class DataSaverDialogDelegateTest : SysuiTestCase() {
    private lateinit var sysuiDialogFactory: SystemUIDialog.Factory
    private lateinit var sysuiDialog: SystemUIDialog
    private lateinit var dataSaverDialogDelegate: DataSaverDialogDelegate
    private lateinit var contextInteractor: FakeShadeDialogContextInteractor

    @Before
    fun setup() {
        sysuiDialog = mock<SystemUIDialog>()
        sysuiDialogFactory = mock<SystemUIDialog.Factory>()
        contextInteractor = FakeShadeDialogContextInteractor(context)

        dataSaverDialogDelegate =
            DataSaverDialogDelegate(
                sysuiDialogFactory,
                context,
                contextInteractor,
                EmptyCoroutineContext,
                dataSaverController,
                mock<SharedPreferences>()
                mock<SharedPreferences>(),
            )

        whenever(sysuiDialogFactory.create(eq(dataSaverDialogDelegate), eq(context)))
            .thenReturn(sysuiDialog)
    }

    @Test
    fun delegateSetsDialogTitleCorrectly() {
        val expectedResId = R.string.data_saver_enable_title
+9 −5
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import com.android.systemui.qs.tiles.base.actions.intentInputs
import com.android.systemui.qs.tiles.base.interactor.QSTileInputTestKtx
import com.android.systemui.qs.tiles.impl.saver.domain.model.DataSaverTileModel
import com.android.systemui.settings.UserFileManager
import com.android.systemui.shade.domain.interactor.FakeShadeDialogContextInteractor
import com.android.systemui.statusbar.phone.SystemUIDialog
import com.android.systemui.util.mockito.any
import com.android.systemui.util.mockito.eq
@@ -53,17 +54,19 @@ class DataSaverTileUserActionInteractorTest : SysuiTestCase() {
    private lateinit var sharedPreferences: SharedPreferences
    private lateinit var dialogFactory: SystemUIDialog.Factory
    private lateinit var underTest: DataSaverTileUserActionInteractor
    private lateinit var contextInteractor: FakeShadeDialogContextInteractor

    @Before
    fun setup() {
        userFileManager = mock<UserFileManager>()
        sharedPreferences = mock<SharedPreferences>()
        dialogFactory = mock<SystemUIDialog.Factory>()
        contextInteractor = FakeShadeDialogContextInteractor(mContext)
        whenever(
                userFileManager.getSharedPreferences(
                    eq(DataSaverTileUserActionInteractor.PREFS),
                    eq(Context.MODE_PRIVATE),
                    eq(context.userId)
                    eq(context.userId),
                )
            )
            .thenReturn(sharedPreferences)
@@ -71,6 +74,7 @@ class DataSaverTileUserActionInteractorTest : SysuiTestCase() {
        underTest =
            DataSaverTileUserActionInteractor(
                context,
                contextInteractor,
                EmptyCoroutineContext,
                EmptyCoroutineContext,
                dataSaverController,
@@ -87,7 +91,7 @@ class DataSaverTileUserActionInteractorTest : SysuiTestCase() {
        whenever(
                sharedPreferences.getBoolean(
                    eq(DataSaverTileUserActionInteractor.DIALOG_SHOWN),
                    any()
                    any(),
                )
            )
            .thenReturn(true)
@@ -107,7 +111,7 @@ class DataSaverTileUserActionInteractorTest : SysuiTestCase() {
        whenever(
                sharedPreferences.getBoolean(
                    eq(DataSaverTileUserActionInteractor.DIALOG_SHOWN),
                    any()
                    any(),
                )
            )
            .thenReturn(false)
@@ -128,7 +132,7 @@ class DataSaverTileUserActionInteractorTest : SysuiTestCase() {
        whenever(
                sharedPreferences.getBoolean(
                    eq(DataSaverTileUserActionInteractor.DIALOG_SHOWN),
                    any()
                    any(),
                )
            )
            .thenReturn(false)
@@ -144,7 +148,7 @@ class DataSaverTileUserActionInteractorTest : SysuiTestCase() {
        whenever(
                sharedPreferences.getBoolean(
                    eq(DataSaverTileUserActionInteractor.DIALOG_SHOWN),
                    any()
                    any(),
                )
            )
            .thenReturn(true)
+8 −2
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.util.Log;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.res.R;
import com.android.systemui.shade.domain.interactor.ShadeDialogContextInteractor;
import com.android.systemui.statusbar.phone.SystemUIDialog;

import javax.inject.Inject;
@@ -44,6 +45,7 @@ public class BiometricNotificationDialogFactory {
    private static final String TAG = "BiometricNotificationDialogFactory";
    private final Resources mResources;
    private final SystemUIDialog.Factory mSystemUIDialogFactory;
    private final ShadeDialogContextInteractor mDialogContextInteractor;
    @Nullable private final FingerprintManager mFingerprintManager;
    @Nullable private final FaceManager mFaceManager;

@@ -51,10 +53,12 @@ public class BiometricNotificationDialogFactory {
    BiometricNotificationDialogFactory(
            @Main Resources resources,
            SystemUIDialog.Factory systemUIDialogFactory,
            ShadeDialogContextInteractor shadeDialogContextInteractor,
            @Nullable FingerprintManager fingerprintManager,
            @Nullable FaceManager faceManager) {
        mResources = resources;
        mSystemUIDialogFactory = systemUIDialogFactory;
        mDialogContextInteractor = shadeDialogContextInteractor;
        mFingerprintManager = fingerprintManager;
        mFaceManager = faceManager;
    }
@@ -62,7 +66,8 @@ public class BiometricNotificationDialogFactory {
    Dialog createReenrollDialog(
            int userId, ActivityStarter activityStarter, BiometricSourceType biometricSourceType,
            boolean isReenrollForced) {
        SystemUIDialog sysuiDialog = mSystemUIDialogFactory.create();
        SystemUIDialog sysuiDialog =
                mSystemUIDialogFactory.create(mDialogContextInteractor.getContext());
        if (biometricSourceType == BiometricSourceType.FACE) {
            sysuiDialog.setTitle(mResources.getString(R.string.face_re_enroll_dialog_title));
            sysuiDialog.setMessage(mResources.getString(R.string.face_re_enroll_dialog_content));
@@ -90,7 +95,8 @@ public class BiometricNotificationDialogFactory {
    }

    private Dialog createReenrollFailureDialog(BiometricSourceType biometricType) {
        final SystemUIDialog sysuiDialog = mSystemUIDialogFactory.create();
        final SystemUIDialog sysuiDialog =
                mSystemUIDialogFactory.create(mDialogContextInteractor.getContext());

        if (biometricType == BiometricSourceType.FACE) {
            sysuiDialog.setMessage(mResources.getString(
Loading