Check whether the user is a sub profile before starting Settings homepage

Fix: 336449492
Test: atest SettingsHomepageActivityTest LocationInjectedServicesPreferenceControllerTest UserDetailsSettingsTest ActionDisabledByAdminDialogHelperTest ProfileSelectFragmentTest ProfileSelectLocationFragmentTest
- Start a managed app's info page
- Start a private app's info page
- Switch to a secondary user and start Settings
- Switch to the guest user and start Settings

Change-Id: I1c7c95d95c4739d70839a742ebc4e72b59b1d555
This commit is contained in:
Jason Chiu
2024-04-29 18:16:51 +08:00
parent dade97f27c
commit bd74caeb99
4 changed files with 100 additions and 24 deletions

View File

@@ -20,6 +20,7 @@ import android.app.Activity
import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.content.pm.UserInfo
import android.provider.Settings
import android.util.Log
import com.android.settings.SettingsActivity
@@ -93,9 +94,17 @@ object EmbeddedDeepLinkUtils {
}
}
/**
* Returns whether the user is a sub profile.
*/
@JvmStatic
fun isSubProfile(userInfo: UserInfo): Boolean =
userInfo.isManagedProfile || userInfo.isPrivateProfile
private fun Context.startTrampolineIntent(trampolineIntent: Intent): Boolean = try {
val userInfo = userManager.getUserInfo(user.identifier)
if (userInfo.isManagedProfile) {
if (isSubProfile(userInfo)) {
trampolineIntent.setClass(this, DeepLinkHomepageActivityInternal::class.java)
.putExtra(SettingsActivity.EXTRA_USER_HANDLE, user)
startActivityAsUser(