Rather than check for the state of the work profile in LockScreenNotificationPreferenceController#handlePreferenceTreeClick, do so in the RestrictedListPreference#performClick. The drawback of checking the state in handlePreferenceTreeClick is that the preferences are displayed first and then the requirement to unlock/enable the work profile is displayed on top of it. This is rather poor UX, so switch to doing the check in performClick and returning early if the work profile needs to be unlocked/enabled. This is similar to Patchset 1 from ag/3805482. The main difference is that the user is returned to the settings screen both after enabling the work profile and unlocking it. Test: Manually with TestDPC Test: atest SettingsRoboTests:RestrictedListPreferenceTest Bug: 77408805 Merged-In: Id168911b082fffac193cd7c7a658ab92d6ce2c15 Change-Id: I0a3a4ec4dda78e28ee88a11d383eda49e9cf50a6
Running Settings Robolectric tests
The full suite
$ croot
$ make RunSettingsRoboTests
Running a single test class
$ croot
$ make RunSettingsRoboTests ROBOTEST_FILTER=<ClassName>
For example:
make RunSettingsRoboTests ROBOTEST_FILTER=CodeInspectionTest
You can also use partial class name in ROBOTEST_FILTER. If the partial class name matches multiple file names, all of them will be executed.