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

Commit 76f815f7 authored by Vania Januar's avatar Vania Januar Committed by Android (Google) Code Review
Browse files

Merge "Minor fixes and tests for multiple full users for stylus notes app" into udc-qpr-dev

parents ebea3504 3042747d
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -258,10 +258,10 @@
    <!-- Title for stylus device details page [CHAR LIMIT=50] -->
    <string name="stylus_device_details_title">Stylus</string>
    <!-- Preference title for setting the app that opens when stylus button is pressed [CHAR LIMIT=none] -->
    <!-- Preference title for setting the app that opens user presses stylus button [CHAR LIMIT=none] -->
    <string name="stylus_default_notes_app">Tail button press</string>
    <!-- Summary for the app that opens when tail button is pressed, if set to a work profile app [CHAR LIMIT=none] -->
    <string name="stylus_default_notes_summary_work"><xliff:g id="app_name" example="WhatsApp">%s</xliff:g> (Work profile)</string>
    <!-- Summary for the app that opens when user presses stylus tail button, if set to a work profile app [CHAR LIMIT=none] -->
    <string name="stylus_default_notes_summary_work"><xliff:g id="app_name" example="Mail">%s</xliff:g> (Work profile)</string>
    <!-- Preference title for toggling whether handwriting in textfields is enabled [CHAR LIMIT=none] -->
    <string name="stylus_textfield_handwriting">Write in text fields</string>
    <!-- Preference title for toggling whether stylus button presses are ignored [CHAR LIMIT=none] -->
+5 −4
Original line number Diff line number Diff line
@@ -254,16 +254,17 @@ public class StylusDevicesController extends AbstractPreferenceController implem

    private List<UserHandle> getUserAndManagedProfiles() {
        UserManager um = mContext.getSystemService(UserManager.class);
        final ArrayList<UserHandle> userManagedProfiles = new ArrayList<>();
        final List<UserHandle> userManagedProfiles = new ArrayList<>();
        // Add the current user, then add all the associated managed profiles.
        final UserHandle currentUser = Process.myUserHandle();
        userManagedProfiles.add(currentUser);

        final List<UserInfo> userInfos = um.getUsers();
        for (UserInfo info : userInfos) {
            if (um.isManagedProfile(info.id)
                    && um.getProfileParent(info.id).id == currentUser.getIdentifier()) {
                userManagedProfiles.add(UserHandle.of(info.id));
            int userId = info.id;
            if (um.isManagedProfile(userId)
                    && um.getProfileParent(userId).id == currentUser.getIdentifier()) {
                userManagedProfiles.add(UserHandle.of(userId));
            }
        }
        return userManagedProfiles;
+33 −3
Original line number Diff line number Diff line
@@ -315,7 +315,7 @@ public class StylusDevicesControllerTest {
    }

    @Test
    public void defaultNotesPreferenceClick_multiUser_showsProfileSelectorDialog() {
    public void defaultNotesPreferenceClick_multiUserManagedProfile_showsProfileSelectorDialog() {
        mContext.setTheme(R.style.Theme_AppCompat);
        final String permissionPackageName = "permissions.package";
        final UserHandle currentUser = Process.myUserHandle();
@@ -337,13 +337,43 @@ public class StylusDevicesControllerTest {
        assertTrue(mController.mDialog.isShowing());
    }

    @Test
    public void defaultNotesPreferenceClick_noManagedProfile_sendsManageDefaultRoleIntent() {
        final ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
        mContext.setTheme(R.style.Theme_AppCompat);
        final String permissionPackageName = "permissions.package";
        final UserHandle currentUser = Process.myUserHandle();
        List<UserInfo> userInfos = Arrays.asList(
                new UserInfo(currentUser.getIdentifier(), "current", 0),
                new UserInfo(1, "other", UserInfo.FLAG_FULL)
        );
        when(mUserManager.getUsers()).thenReturn(userInfos);
        when(mUserManager.isManagedProfile(1)).thenReturn(false);
        when(mUserManager.getUserInfo(currentUser.getIdentifier())).thenReturn(userInfos.get(0));
        when(mUserManager.getUserInfo(1)).thenReturn(userInfos.get(1));
        when(mUserManager.getProfileParent(any())).thenReturn(null);
        when(mPm.getPermissionControllerPackageName()).thenReturn(permissionPackageName);

        showScreen(mController);
        Preference defaultNotesPref = mPreferenceContainer.getPreference(0);
        mController.onPreferenceClick(defaultNotesPref);

        verify(mContext).startActivity(captor.capture());
        Intent intent = captor.getValue();
        assertThat(intent.getAction()).isEqualTo(Intent.ACTION_MANAGE_DEFAULT_APP);
        assertThat(intent.getPackage()).isEqualTo(permissionPackageName);
        assertThat(intent.getStringExtra(Intent.EXTRA_ROLE_NAME)).isEqualTo(
                RoleManager.ROLE_NOTES);
        assertNull(mController.mDialog);
    }

    @Test
    public void profileSelectDialogClickCallback_onClick_sendsIntent() {
        Intent intent = new Intent();
        UserHandle user1 = mock(UserHandle.class);
        UserHandle user2 = mock(UserHandle.class);
        List<UserHandle> users = Arrays.asList(new UserHandle[] {user1, user2});
        mController.mDialog = mock(Dialog.class);
        List<UserHandle> users = Arrays.asList(user1, user2);
        mController.mDialog = new Dialog(mContext);
        UserAdapter.OnClickListener callback = mController
                .createProfileDialogClickCallback(intent, users);