From 6b02225810bde2f7a492926165b3c67b284c027a Mon Sep 17 00:00:00 2001 From: Yanting Yang Date: Tue, 1 Aug 2023 20:49:24 +0800 Subject: [PATCH] Support App details for work profile apps App info page stopped supporting the App details feature for work profile apps in Android N but there is no exact reason from the history. Try supporting it again to fulfill users' requests and check for exceptions. Bug: 264932611 Test: manual & robo and unit tests Change-Id: I1227cff5e25313905952ba54ab0270cdf4f00fd4 --- .../AppInstallerInfoPreferenceController.java | 5 ----- .../app/appinfo/AppInstallerInfoPreference.kt | 8 ++------ ...pInstallerInfoPreferenceControllerTest.java | 16 ---------------- .../appinfo/AppInstallerInfoPreferenceTest.kt | 18 ------------------ 4 files changed, 2 insertions(+), 45 deletions(-) diff --git a/src/com/android/settings/applications/appinfo/AppInstallerInfoPreferenceController.java b/src/com/android/settings/applications/appinfo/AppInstallerInfoPreferenceController.java index 5e99e8bedb1..1216ae8cc36 100644 --- a/src/com/android/settings/applications/appinfo/AppInstallerInfoPreferenceController.java +++ b/src/com/android/settings/applications/appinfo/AppInstallerInfoPreferenceController.java @@ -18,7 +18,6 @@ package com.android.settings.applications.appinfo; import android.content.Context; import android.content.Intent; -import android.os.UserManager; import androidx.preference.Preference; @@ -39,10 +38,6 @@ public class AppInstallerInfoPreferenceController extends AppInfoPreferenceContr @Override public int getAvailabilityStatus() { - if (UserManager.get(mContext).isManagedProfile()) { - return DISABLED_FOR_USER; - } - if (AppUtils.isMainlineModule(mContext.getPackageManager(), mPackageName)) { return DISABLED_FOR_USER; } diff --git a/src/com/android/settings/spa/app/appinfo/AppInstallerInfoPreference.kt b/src/com/android/settings/spa/app/appinfo/AppInstallerInfoPreference.kt index b89d76857af..c89c504fd81 100644 --- a/src/com/android/settings/spa/app/appinfo/AppInstallerInfoPreference.kt +++ b/src/com/android/settings/spa/app/appinfo/AppInstallerInfoPreference.kt @@ -32,9 +32,7 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.android.settingslib.spa.widget.preference.Preference import com.android.settingslib.spa.widget.preference.PreferenceModel import com.android.settingslib.spaprivileged.framework.common.asUser -import com.android.settingslib.spaprivileged.framework.common.userManager import com.android.settingslib.spaprivileged.model.app.userHandle -import com.android.settingslib.spaprivileged.model.app.userId import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.Flow @@ -71,7 +69,6 @@ private class AppInstallerInfoPresenter( ) { private val userContext = context.asUser(app.userHandle) private val packageManager = userContext.packageManager - private val userManager = context.userManager private val installerPackageFlow = flow { emit(withContext(Dispatchers.IO) { @@ -88,9 +85,8 @@ private class AppInstallerInfoPresenter( val isAvailableFlow = installerLabelFlow.map { installerLabel -> withContext(Dispatchers.IO) { - !userManager.isManagedProfile(app.userId) && - !AppUtils.isMainlineModule(packageManager, app.packageName) && - installerLabel != null + !AppUtils.isMainlineModule(packageManager, app.packageName) && + installerLabel != null } } diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/AppInstallerInfoPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/AppInstallerInfoPreferenceControllerTest.java index deb5a3f816a..ada7ef203a6 100644 --- a/tests/robotests/src/com/android/settings/applications/appinfo/AppInstallerInfoPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/applications/appinfo/AppInstallerInfoPreferenceControllerTest.java @@ -37,7 +37,6 @@ import android.content.pm.ModuleInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; -import android.os.UserManager; import androidx.preference.Preference; @@ -54,8 +53,6 @@ import org.robolectric.RuntimeEnvironment; @RunWith(RobolectricTestRunner.class) public class AppInstallerInfoPreferenceControllerTest { - @Mock - private UserManager mUserManager; @Mock private PackageManager mPackageManager; @Mock @@ -74,7 +71,6 @@ public class AppInstallerInfoPreferenceControllerTest { public void setUp() throws PackageManager.NameNotFoundException { MockitoAnnotations.initMocks(this); mContext = spy(RuntimeEnvironment.application); - when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager); when(mContext.getPackageManager()).thenReturn(mPackageManager); final String installerPackage = "Installer1"; when(mPackageManager.getInstallSourceInfo(anyString())).thenReturn(mInstallSourceInfo); @@ -86,18 +82,8 @@ public class AppInstallerInfoPreferenceControllerTest { mController.setParentFragment(mFragment); } - @Test - public void getAvailabilityStatus_managedProfile_shouldReturnDisabled() { - when(mUserManager.isManagedProfile()).thenReturn(true); - - assertThat(mController.getAvailabilityStatus()) - .isEqualTo(BasePreferenceController.DISABLED_FOR_USER); - } - @Test public void getAvailabilityStatus_noAppLabel_shouldReturnDisabled() { - when(mUserManager.isManagedProfile()).thenReturn(false); - assertThat(mController.getAvailabilityStatus()) .isEqualTo(BasePreferenceController.DISABLED_FOR_USER); } @@ -106,7 +92,6 @@ public class AppInstallerInfoPreferenceControllerTest { public void getAvailabilityStatus_hasAppLabel_shouldReturnAvailable() throws PackageManager.NameNotFoundException { final String packageName = "Package1"; - when(mUserManager.isManagedProfile()).thenReturn(false); when(mAppInfo.loadLabel(mPackageManager)).thenReturn("Label1"); mController = new AppInstallerInfoPreferenceController(mContext, "test_key"); mController.setPackageName(packageName); @@ -161,7 +146,6 @@ public class AppInstallerInfoPreferenceControllerTest { public void getAvailabilityStatus_isMainlineModule_shouldReturnDisabled() throws PackageManager.NameNotFoundException { final String packageName = "Package"; - when(mUserManager.isManagedProfile()).thenReturn(false); when(mAppInfo.loadLabel(mPackageManager)).thenReturn("Label"); mController.setPackageName(packageName); mockMainlineModule(packageName, true /* isMainlineModule */); diff --git a/tests/spa_unit/src/com/android/settings/spa/app/appinfo/AppInstallerInfoPreferenceTest.kt b/tests/spa_unit/src/com/android/settings/spa/app/appinfo/AppInstallerInfoPreferenceTest.kt index 53a18683a7d..0deeaf7c041 100644 --- a/tests/spa_unit/src/com/android/settings/spa/app/appinfo/AppInstallerInfoPreferenceTest.kt +++ b/tests/spa_unit/src/com/android/settings/spa/app/appinfo/AppInstallerInfoPreferenceTest.kt @@ -19,7 +19,6 @@ package com.android.settings.spa.app.appinfo import android.content.Context import android.content.Intent import android.content.pm.ApplicationInfo -import android.os.UserManager import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.test.assertIsDisplayed @@ -40,16 +39,13 @@ import com.android.settings.Utils import com.android.settings.applications.AppStoreUtil import com.android.settingslib.applications.AppUtils import com.android.settingslib.spa.testutils.waitUntilExists -import com.android.settingslib.spaprivileged.framework.common.userManager import com.android.settingslib.spaprivileged.model.app.userHandle import org.junit.After import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith -import org.mockito.Mock import org.mockito.Mockito.any -import org.mockito.Mockito.anyInt import org.mockito.Mockito.eq import org.mockito.Mockito.verify import org.mockito.MockitoSession @@ -67,9 +63,6 @@ class AppInstallerInfoPreferenceTest { @Spy private val context: Context = ApplicationProvider.getApplicationContext() - @Mock - private lateinit var userManager: UserManager - @Before fun setUp() { mockSession = mockitoSession() @@ -79,8 +72,6 @@ class AppInstallerInfoPreferenceTest { .mockStatic(AppUtils::class.java) .strictness(Strictness.LENIENT) .startMocking() - whenever(context.userManager).thenReturn(userManager) - whenever(userManager.isManagedProfile(anyInt())).thenReturn(false) whenever(AppStoreUtil.getInstallerPackageName(any(), eq(PACKAGE_NAME))) .thenReturn(INSTALLER_PACKAGE_NAME) whenever(AppStoreUtil.getAppStoreLink(context, INSTALLER_PACKAGE_NAME, PACKAGE_NAME)) @@ -114,15 +105,6 @@ class AppInstallerInfoPreferenceTest { composeTestRule.onRoot().assertIsNotDisplayed() } - @Test - fun whenIsManagedProfile_notDisplayed() { - whenever(userManager.isManagedProfile(anyInt())).thenReturn(true) - - setContent() - - composeTestRule.onRoot().assertIsNotDisplayed() - } - @Test fun whenIsMainlineModule_notDisplayed() { whenever(AppUtils.isMainlineModule(any(), eq(PACKAGE_NAME))).thenReturn(true)