Return true only if the userManager belongs to private profile
The existing code asks the main user's userManager if there's a private profile belonging to it. If a private profile exists then the answer to that question will always be true. So, we always end up showing the apps from the private profile for the personal case. We should instead ask the userManager if it belongs to the private profile or not. Bug: 327598131 Test: manual Change-Id: I7bc9d58c371341235579d3456b54ea85f598892b
This commit is contained in:
@@ -17,7 +17,6 @@
|
||||
package com.android.settings.applications.credentials;
|
||||
|
||||
import android.os.UserManager;
|
||||
import android.util.Slog;
|
||||
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.dashboard.profileselector.ProfileSelectFragment.ProfileType;
|
||||
@@ -33,13 +32,6 @@ public class DefaultCombinedPickerPrivate extends DefaultCombinedPicker {
|
||||
|
||||
/** Returns whether the user is handled by this fragment. */
|
||||
public static boolean isUserHandledByFragment(UserManager userManager) {
|
||||
try {
|
||||
// If there is no private profile then this will throw an exception.
|
||||
Utils.getCurrentUserIdOfType(userManager, ProfileType.PRIVATE);
|
||||
return true;
|
||||
} catch (IllegalStateException e) {
|
||||
Slog.e(TAG, "Failed to get private profile user id", e);
|
||||
return false;
|
||||
}
|
||||
return android.os.Flags.allowPrivateProfile() && userManager.isPrivateProfile();
|
||||
}
|
||||
}
|
||||
|
@@ -19,21 +19,21 @@ package com.android.settings.applications.credentials;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.os.UserHandle;
|
||||
import android.os.Flags;
|
||||
import android.os.UserManager;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
@@ -41,6 +41,7 @@ import org.mockito.MockitoAnnotations;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class CredentialsPickerActivityTest {
|
||||
@Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||
|
||||
@Mock private UserManager mUserManager;
|
||||
|
||||
@@ -76,13 +77,11 @@ public class CredentialsPickerActivityTest {
|
||||
|
||||
@Test
|
||||
public void testInjectFragmentIntoIntent_privateProfile() {
|
||||
mSetFlagsRule.enableFlags(Flags.FLAG_ALLOW_PRIVATE_PROFILE);
|
||||
Intent intent = new Intent();
|
||||
|
||||
// Simulate private profile.
|
||||
UserHandle privateUser = new UserHandle(100);
|
||||
when(mUserManager.getUserInfo(100))
|
||||
.thenReturn(new UserInfo(100, "", "", 0, UserManager.USER_TYPE_PROFILE_PRIVATE));
|
||||
when(mUserManager.getUserProfiles()).thenReturn(Lists.newArrayList(privateUser));
|
||||
doReturn(true).when(mUserManager).isPrivateProfile();
|
||||
assertThat(DefaultCombinedPickerPrivate.isUserHandledByFragment(mUserManager)).isTrue();
|
||||
|
||||
CredentialsPickerActivity.injectFragmentIntoIntent(mMockContext, intent);
|
||||
|
@@ -117,7 +117,7 @@ public class DefaultCombinedPreferenceControllerTest {
|
||||
|
||||
// Set the preference back to none and make sure the view was updated.
|
||||
dcpc.updatePreferenceForProvider(ppp, null, null, null, null, null);
|
||||
assertThat(ppp.getTitle().toString()).isEqualTo("None");
|
||||
assertThat(ppp.getTitle().toString()).isEqualTo("None selected");
|
||||
assertThat(ppp.getSummary()).isNull();
|
||||
assertThat(ppp.getIcon()).isNull();
|
||||
}
|
||||
|
Reference in New Issue
Block a user