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

Commit 80859523 authored by Yvonne Jiang's avatar Yvonne Jiang
Browse files

Update SupervisionIntentProvider#getSettingsIntent to return null if supervision is disabled.

This fixes a bug where the implementation did not match the documented
and expected behavior.

Bug: 438120434
Test: atest SupervisionIntentProviderTest
Flag: android.app.supervision.flags.enable_supervision_settings_screen

Change-Id: I3544437240af361988471e8ea00d0c65009bfe51
parent 1d5e772d
Loading
Loading
Loading
Loading
+9 −3
Original line number Original line Diff line number Diff line
@@ -58,13 +58,19 @@ object SupervisionIntentProvider {
     */
     */
    @JvmStatic
    @JvmStatic
    fun getSettingsIntent(context: Context): Intent? {
    fun getSettingsIntent(context: Context): Intent? {
        val supervisionManager =
            context.getSystemService(SupervisionManager::class.java) ?: return null
        val (intentAction, intentPackage) =
        val (intentAction, intentPackage) =
            if (Flags.enableSupervisionSettingsScreen()) {
            if (Flags.enableSupervisionSettingsScreen()) {
                val settingsAppPackage = getSettingsAppPackage(context)
                val settingsAppPackage =
                    if (supervisionManager.isSupervisionEnabled()) {
                        getSettingsAppPackage(context)
                    } else {
                        null
                    }
                ACTION_SUPERVISION_SETTINGS to settingsAppPackage
                ACTION_SUPERVISION_SETTINGS to settingsAppPackage
            } else {
            } else {
                val supervisionManager = context.getSystemService(SupervisionManager::class.java)
                val supervisionAppPackage = supervisionManager.activeSupervisionAppPackage
                val supervisionAppPackage = supervisionManager?.activeSupervisionAppPackage
                ACTION_SHOW_PARENTAL_CONTROLS to supervisionAppPackage
                ACTION_SHOW_PARENTAL_CONTROLS to supervisionAppPackage
            }
            }


+18 −3
Original line number Original line Diff line number Diff line
@@ -23,7 +23,6 @@ import android.content.Context
import android.content.ContextWrapper
import android.content.ContextWrapper
import android.content.Intent
import android.content.Intent
import android.content.pm.ActivityInfo
import android.content.pm.ActivityInfo
import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
import android.content.pm.PackageManager
import android.content.pm.ResolveInfo
import android.content.pm.ResolveInfo
import android.platform.test.annotations.EnableFlags
import android.platform.test.annotations.EnableFlags
@@ -66,6 +65,20 @@ class SupervisionIntentProviderTest {
            }
            }
    }
    }


    @Test
    @EnableFlags(Flags.FLAG_ENABLE_SUPERVISION_SETTINGS_SCREEN)
    fun getSettingsIntent_supervisionDisabled_returnsNull() {
        mockPackageManager.stub {
            on { queryIntentActivitiesAsUser(any<Intent>(), any<Int>(), any<Int>()) } doReturn
                listOf(ResolveInfo())
        }
        mockSupervisionManager.stub { on { isSupervisionEnabled() } doReturn false }

        val intent = SupervisionIntentProvider.getSettingsIntent(context)

        assertThat(intent).isNull()
    }

    @Test
    @Test
    @EnableFlags(Flags.FLAG_ENABLE_SUPERVISION_SETTINGS_SCREEN)
    @EnableFlags(Flags.FLAG_ENABLE_SUPERVISION_SETTINGS_SCREEN)
    fun getSettingsIntent_unresolvedIntent() {
    fun getSettingsIntent_unresolvedIntent() {
@@ -73,6 +86,7 @@ class SupervisionIntentProviderTest {
            on { queryIntentActivitiesAsUser(any<Intent>(), any<Int>(), any<Int>()) } doReturn
            on { queryIntentActivitiesAsUser(any<Intent>(), any<Int>(), any<Int>()) } doReturn
                emptyList<ResolveInfo>()
                emptyList<ResolveInfo>()
        }
        }
        mockSupervisionManager.stub { on { isSupervisionEnabled() } doReturn true }


        val intent = SupervisionIntentProvider.getSettingsIntent(context)
        val intent = SupervisionIntentProvider.getSettingsIntent(context)


@@ -86,6 +100,7 @@ class SupervisionIntentProviderTest {
            on { queryIntentActivitiesAsUser(any<Intent>(), any<Int>(), any<Int>()) } doReturn
            on { queryIntentActivitiesAsUser(any<Intent>(), any<Int>(), any<Int>()) } doReturn
                listOf(ResolveInfo())
                listOf(ResolveInfo())
        }
        }
        mockSupervisionManager.stub { on { isSupervisionEnabled() } doReturn true }


        val intent = SupervisionIntentProvider.getSettingsIntent(context)
        val intent = SupervisionIntentProvider.getSettingsIntent(context)


@@ -102,8 +117,7 @@ class SupervisionIntentProviderTest {
            ResolveInfo().apply {
            ResolveInfo().apply {
                this.activityInfo =
                this.activityInfo =
                    ActivityInfo().apply {
                    ActivityInfo().apply {
                        applicationInfo =
                        packageName = expectedSettingsPackage
                            ApplicationInfo().apply { packageName = expectedSettingsPackage }
                    }
                    }
            }
            }
        mockPackageManager.stub {
        mockPackageManager.stub {
@@ -111,6 +125,7 @@ class SupervisionIntentProviderTest {
                listOf(ResolveInfo())
                listOf(ResolveInfo())
            on { queryIntentActivities(any<Intent>(), any<Int>()) } doReturn listOf(resolveInfo)
            on { queryIntentActivities(any<Intent>(), any<Int>()) } doReturn listOf(resolveInfo)
        }
        }
        mockSupervisionManager.stub { on { isSupervisionEnabled() } doReturn true }


        val intent = SupervisionIntentProvider.getSettingsIntent(context)
        val intent = SupervisionIntentProvider.getSettingsIntent(context)