Replace SystemUser checks with MainUser.

Bug: 257333623
Test: atest CommunalPreferenceControllerTest, atest UtilsTest, atest
TimeoutToDockUserPreferenceControllerTest

Change-Id: I5d2a818f9f35968ced1db7f9fa4b79432a502023
This commit is contained in:
Victor Truong
2023-01-20 10:49:41 -05:00
parent 4e03bc2133
commit f3c9a09cac
7 changed files with 78 additions and 29 deletions

View File

@@ -1277,4 +1277,16 @@ public final class Utils extends com.android.settingslib.Utils {
}
return -1;
}
/**
* Returns if the current user is able to use Dreams.
*/
public static boolean canCurrentUserDream(Context context) {
final UserHandle mainUser = context.getSystemService(UserManager.class).getMainUser();
if (mainUser == null) {
return false;
}
return context.createContextAsUser(mainUser, 0).getSystemService(UserManager.class)
.isUserForeground();
}
}