Allow SYSTEM user in Automotive instead of main user.

There are devices where main user is not defined, such as Automotive,
and no uid could pass enforceUid(). Allow SYSTEM user for such cases.

Bug: 285758762

Test: atest com.google.android.gts.persistentdata.PersistentDataHostTest

Change-Id: Ieef580962e12f70ef429ebc2532312a5008167a2
This commit is contained in:
bkchoi
2023-07-19 16:01:35 -07:00
parent 9625284371
commit 1589a661af

View File

@@ -159,9 +159,10 @@ public class PersistentDataBlockService extends SystemService {
private int getAllowedUid() {
final UserManagerInternal umInternal = LocalServices.getService(UserManagerInternal.class);
final int mainUserId = umInternal.getMainUserId();
int mainUserId = umInternal.getMainUserId();
if (mainUserId < 0) {
return -1;
// If main user is not defined. Use the SYSTEM user instead.
mainUserId = UserHandle.USER_SYSTEM;
}
String allowedPackage = mContext.getResources()
.getString(R.string.config_persistentDataPackageName);