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

Commit 0d11c4a7 authored by Archisha Baranwal's avatar Archisha Baranwal Committed by archisha
Browse files

Adding programmatic provision of WRITE_SECURE_SETTINGS permission to

Launcher3Tests.

Bug: 361222449
Test: atest Launcher3Tests
Flag: EXEMPT test fixes

Change-Id: I4226c4c50047d71a99944fc4e5d70080d134c3d3
parent fafecabb
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentat
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
import static com.android.launcher3.util.TestUtil.runOnExecutorSync;
import static com.android.launcher3.util.TestUtil.grantWriteSecurePermission;

import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
@@ -185,6 +186,8 @@ public class LauncherModelHelper {
     */
    public LauncherModelHelper setupDefaultLayoutProvider(LauncherLayoutBuilder builder)
            throws Exception {
        grantWriteSecurePermission();

        InvariantDeviceProfile idp = InvariantDeviceProfile.INSTANCE.get(sandboxContext);
        if (idp.numRows == 0 && idp.numColumns == 0) {
            idp.numRows = idp.numColumns = idp.numDatabaseHotseatIcons = DEFAULT_GRID_SIZE;
+11 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import static com.android.launcher3.LauncherSettings.Settings.LAYOUT_DIGEST_TAG;

import static org.junit.Assert.assertTrue;

import android.Manifest;
import android.app.Instrumentation;
import android.app.blob.BlobHandle;
import android.app.blob.BlobStoreManager;
@@ -169,6 +170,8 @@ public class TestUtil {
        }

        String key = Base64.encodeToString(digest, NO_WRAP | NO_PADDING);

        grantWriteSecurePermission();
        Settings.Secure.putString(context.getContentResolver(), LAYOUT_DIGEST_KEY, key);
        wait.await();
        return () ->
@@ -224,6 +227,14 @@ public class TestUtil {
        assertTrue(message, failed);
    }

    /**
     * Grants [WRITE_SECURE_SETTINGS] permission in runtime.
     */
    public static void grantWriteSecurePermission() {
        getInstrumentation().getUiAutomation()
                .adoptShellPermissionIdentity(Manifest.permission.WRITE_SECURE_SETTINGS);
    }

    /** Interface to indicate a runnable which can throw any exception. */
    public interface UncheckedRunnable {
        /** Method to run the task */
+3 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import com.android.launcher3.ui.TestViewHelpers
import com.android.launcher3.util.Executors.MODEL_EXECUTOR
import com.android.launcher3.util.LauncherModelHelper.SandboxModelContext
import com.android.launcher3.util.LooperIdleLock
import com.android.launcher3.util.TestUtil
import com.android.launcher3.util.UserIconInfo
import com.google.common.truth.Truth
import java.util.concurrent.CountDownLatch
@@ -116,6 +117,8 @@ class LoaderTaskTest {
        `when`(idleLock.awaitLocked(1000)).thenReturn(false)
        `when`(iconCache.updateHandler).thenReturn(iconCacheUpdateHandler)
        context.putObject(UserCache.INSTANCE, userCache)

        TestUtil.grantWriteSecurePermission()
    }

    @After
+5 −0
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

package com.android.launcher3.util.rule;

import static com.android.launcher3.util.TestUtil.grantWriteSecurePermission;

import android.app.Instrumentation;
import android.content.ContentResolver;
import android.provider.Settings;
import android.util.Log;
@@ -51,6 +54,7 @@ public class ExtendedLongPressTimeoutRule implements TestRule {
                try {
                    Log.d(TAG, "In try-block: Setting long press timeout from "
                            + prevLongPressTimeout + "ms to " + newLongPressTimeout + "ms");
                    grantWriteSecurePermission();
                    Settings.Secure.putInt(
                            contentResolver,
                            Settings.Secure.LONG_PRESS_TIMEOUT,
@@ -63,6 +67,7 @@ public class ExtendedLongPressTimeoutRule implements TestRule {
                } finally {
                    Log.d(TAG, "In finally-block: resetting long press timeout to "
                            + prevLongPressTimeout + "ms");
                    grantWriteSecurePermission();
                    Settings.Secure.putInt(
                            contentResolver,
                            Settings.Secure.LONG_PRESS_TIMEOUT,