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

Commit 0d1d483d authored by Manish Singh's avatar Manish Singh Committed by Android (Google) Code Review
Browse files

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

parents 25737c7e 55e9f41b
Loading
Loading
Loading
Loading
+1 −9
Original line number Diff line number Diff line
@@ -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();
    }
}
+7 −8
Original line number Diff line number Diff line
@@ -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);
+1 −1
Original line number Diff line number Diff line
@@ -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();
    }