Gate work profile code path in StylusDeviceController.

If the default notes app setting is disabled for work profile, preference changes should automatically apply to the current user.

Test: Robolectric tests, plus manually check the settings on tangorpro.
Bug: 356361307
Flag: EXEMPT minor bug fix
Change-Id: Ib00a3b8287e1be327c57a47594114dad0232f2d4
This commit is contained in:
My Name
2024-08-19 15:47:57 +00:00
parent 877d07be46
commit e987816eed
2 changed files with 92 additions and 64 deletions

View File

@@ -79,6 +79,8 @@ public class StylusDevicesController extends AbstractPreferenceController implem
private static final String TAG = "StylusDevicesController";
private final boolean mConfigEnableDefaultNotesForWorkProfile;
@Nullable
private final InputDevice mInputDevice;
@@ -97,6 +99,8 @@ public class StylusDevicesController extends AbstractPreferenceController implem
mInputDevice = inputDevice;
mCachedBluetoothDevice = cachedBluetoothDevice;
lifecycle.addObserver(this);
mConfigEnableDefaultNotesForWorkProfile = mContext.getResources().getBoolean(
android.R.bool.config_enableDefaultNotesForWorkProfile);
}
@Override
@@ -317,25 +321,27 @@ public class StylusDevicesController extends AbstractPreferenceController implem
final List<UserHandle> userProfiles = new ArrayList<>();
userProfiles.add(currentUser);
final List<UserInfo> userInfos = um.getProfiles(currentUser.getIdentifier());
for (UserInfo userInfo : userInfos) {
if (userInfo.isManagedProfile()
|| (android.os.Flags.allowPrivateProfile()
&& android.multiuser.Flags.enablePrivateSpaceFeatures()
&& android.multiuser.Flags.handleInterleavedSettingsForPrivateSpace()
&& userInfo.isPrivateProfile())) {
userProfiles.add(userInfo.getUserHandle());
if (mConfigEnableDefaultNotesForWorkProfile) {
final List<UserInfo> userInfos = um.getProfiles(currentUser.getIdentifier());
for (UserInfo userInfo : userInfos) {
if (userInfo.isManagedProfile()) {
userProfiles.add(userInfo.getUserHandle());
}
}
}
return userProfiles;
}
private UserHandle getDefaultNoteTaskProfile() {
final int userId = Secure.getInt(
mContext.getContentResolver(),
Secure.DEFAULT_NOTE_TASK_PROFILE,
UserHandle.myUserId());
return UserHandle.of(userId);
final int currentUserId = UserHandle.myUserId();
if (mConfigEnableDefaultNotesForWorkProfile) {
final int userId = Secure.getInt(
mContext.getContentResolver(),
Secure.DEFAULT_NOTE_TASK_PROFILE,
currentUserId);
return UserHandle.of(userId);
}
return UserHandle.of(currentUserId);
}
@VisibleForTesting