Merge "Return true only if the userManager belongs to private profile" into main

This commit is contained in:
Manish Singh
2024-03-05 09:46:40 +00:00
committed by Android (Google) Code Review
3 changed files with 9 additions and 18 deletions

View File

@@ -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();
}
}

View File

@@ -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);

View File

@@ -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();
}