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

Commit 5482637f authored by Fan Zhang's avatar Fan Zhang
Browse files

Refactor bindPreferenceToTile to properly handle multi-user

Change-Id: I751eb645663b3546c212925e2ba4a0a94714013b
Fixes: 32470791
Test: RunSettingsRoboTests
parent aa12b4d2
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -98,16 +98,17 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
        }
        if (!TextUtils.isEmpty(clsName)) {
            pref.setFragment(clsName);
        } else if (tile.userHandle != null && tile.userHandle.size() > 1) {
            pref.setOnPreferenceClickListener(preference -> {
                ProfileSelectDialog.updateUserHandlesIfNeeded(activity, tile);
                ProfileSelectDialog.show(activity.getFragmentManager(), tile);
                return true;
            });
        } else if (tile.intent != null) {
            final Intent intent = new Intent(tile.intent);
            pref.setOnPreferenceClickListener(preference -> {
                ProfileSelectDialog.updateUserHandlesIfNeeded(mContext, tile);
                if (tile.userHandle == null) {
                    activity.startActivityForResult(intent, 0);
                } else if (tile.userHandle.size() == 1) {
                    activity.startActivityForResultAsUser(intent, 0, tile.userHandle.get(0));
                } else {
                    ProfileSelectDialog.show(activity.getFragmentManager(), tile);
                }
                return true;
            });
        }
+3 −1
Original line number Diff line number Diff line
@@ -112,7 +112,9 @@ public class DashboardFeatureProviderImplTest {
        tile.userHandle.add(mock(UserHandle.class));
        tile.userHandle.add(mock(UserHandle.class));
        tile.intent = new Intent();
        when(mActivity.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);

        when(mActivity.getApplicationContext().getSystemService(Context.USER_SERVICE))
                .thenReturn(mUserManager);

        mImpl.bindPreferenceToTile(mActivity, preference, tile, "123");
        preference.getOnPreferenceClickListener().onPreferenceClick(null);