Disable location for headless system user.
Bug: 79535369
Test: Unit test
Change-Id: If93a9aedd69588dbc939fe7fa1c963ae91a85dc6
diff --git a/service/src/com/android/car/user/CarUserService.java b/service/src/com/android/car/user/CarUserService.java
index cc30588..3898e74 100644
--- a/service/src/com/android/car/user/CarUserService.java
+++ b/service/src/com/android/car/user/CarUserService.java
@@ -23,6 +23,7 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.UserInfo;
+import android.location.LocationManager;
import android.os.UserHandle;
import android.os.UserManager;
import android.util.Log;
@@ -91,9 +92,7 @@
if (Intent.ACTION_LOCKED_BOOT_COMPLETED.equals(intent.getAction())) {
if (mCarUserManagerHelper.getAllUsers().size() == 0) {
- // Disable adding accounts for user 0.
- mCarUserManagerHelper.setUserRestriction(mCarUserManagerHelper.getSystemUserInfo(),
- UserManager.DISALLOW_MODIFY_ACCOUNTS, true);
+ setSystemUserRestrictions();
// On very first boot, create an admin user and switch to that user.
UserInfo admin = mCarUserManagerHelper.createNewAdminUser(OWNER_NAME);
mCarUserManagerHelper.switchToUser(admin);
@@ -112,4 +111,16 @@
}
}
}
+
+ private void setSystemUserRestrictions() {
+ // Disable adding accounts for system user.
+ mCarUserManagerHelper.setUserRestriction(mCarUserManagerHelper.getSystemUserInfo(),
+ UserManager.DISALLOW_MODIFY_ACCOUNTS, /* enable= */ true);
+
+ // Disable Location service for system user.
+ LocationManager locationManager =
+ (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
+ locationManager.setLocationEnabledForUser(
+ /* enabled= */ false, UserHandle.of(UserHandle.USER_SYSTEM));
+ }
}