Loading services/core/java/com/android/server/location/LocationManagerService.java +48 −53 Original line number Diff line number Diff line Loading @@ -109,8 +109,13 @@ import com.android.server.location.gnss.GnssManagerService; import com.android.server.location.util.AppForegroundHelper; import com.android.server.location.util.AppOpsHelper; import com.android.server.location.util.Injector; import com.android.server.location.util.LocationAttributionHelper; import com.android.server.location.util.LocationUsageLogger; import com.android.server.location.util.SettingsHelper; import com.android.server.location.util.SystemAppForegroundHelper; import com.android.server.location.util.SystemAppOpsHelper; import com.android.server.location.util.SystemSettingsHelper; import com.android.server.location.util.SystemUserInfoHelper; import com.android.server.location.util.UserInfoHelper; import com.android.server.location.util.UserInfoHelper.UserListener; import com.android.server.pm.permission.PermissionManagerServiceInternal; Loading Loading @@ -141,14 +146,15 @@ public class LocationManagerService extends ILocationManager.Stub { */ public static class Lifecycle extends SystemService { private final SystemUserInfoHelper mUserInfoHelper; private final LifecycleUserInfoHelper mUserInfoHelper; private final SystemInjector mSystemInjector; private final LocationManagerService mService; public Lifecycle(Context context) { super(context); context = context.createAttributionContext(ATTRIBUTION_TAG); mUserInfoHelper = new SystemUserInfoHelper(context); mService = new LocationManagerService(new SystemInjector(context, mUserInfoHelper)); mUserInfoHelper = new LifecycleUserInfoHelper(context); mSystemInjector = new SystemInjector(context, mUserInfoHelper); mService = new LocationManagerService(context, mSystemInjector); } @Override Loading @@ -166,6 +172,7 @@ public class LocationManagerService extends ILocationManager.Stub { public void onBootPhase(int phase) { if (phase == PHASE_SYSTEM_SERVICES_READY) { // the location service must be functioning after this boot phase mSystemInjector.onSystemReady(); mService.onSystemReady(); } else if (phase == PHASE_THIRD_PARTY_APPS_CAN_START) { // some providers rely on third party code, so we wait to initialize Loading @@ -176,39 +183,36 @@ public class LocationManagerService extends ILocationManager.Stub { @Override public void onUserStarting(TargetUser user) { mUserInfoHelper.dispatchOnUserStarted(user.getUserIdentifier()); mUserInfoHelper.onUserStarted(user.getUserIdentifier()); } @Override public void onUserSwitching(TargetUser from, TargetUser to) { mUserInfoHelper.dispatchOnCurrentUserChanged(from.getUserIdentifier(), mUserInfoHelper.onCurrentUserChanged(from.getUserIdentifier(), to.getUserIdentifier()); } @Override public void onUserStopped(TargetUser user) { mUserInfoHelper.dispatchOnUserStopped(user.getUserIdentifier()); mUserInfoHelper.onUserStopped(user.getUserIdentifier()); } private static class SystemUserInfoHelper extends UserInfoHelper { private static class LifecycleUserInfoHelper extends SystemUserInfoHelper { SystemUserInfoHelper(Context context) { LifecycleUserInfoHelper(Context context) { super(context); } @Override protected void dispatchOnUserStarted(int userId) { super.dispatchOnUserStarted(userId); void onUserStarted(int userId) { dispatchOnUserStarted(userId); } @Override protected void dispatchOnUserStopped(int userId) { super.dispatchOnUserStopped(userId); void onUserStopped(int userId) { dispatchOnUserStopped(userId); } @Override protected void dispatchOnCurrentUserChanged(int fromUserId, int toUserId) { super.dispatchOnCurrentUserChanged(fromUserId, toUserId); void onCurrentUserChanged(int fromUserId, int toUserId) { dispatchOnCurrentUserChanged(fromUserId, toUserId); } } } Loading Loading @@ -247,6 +251,8 @@ public class LocationManagerService extends ILocationManager.Stub { private final Handler mHandler; private final LocalService mLocalService; private final Injector mInjector; private final Context mContext; private final AppOpsHelper mAppOpsHelper; private final UserInfoHelper mUserInfoHelper; Loading Loading @@ -285,20 +291,22 @@ public class LocationManagerService extends ILocationManager.Stub { @PowerManager.LocationPowerSaveMode private int mBatterySaverMode; LocationManagerService(Injector injector) { LocationManagerService(Context context, Injector injector) { mHandler = FgThread.getHandler(); mLocalService = new LocalService(); LocalServices.addService(LocationManagerInternal.class, mLocalService); mContext = injector.getContext(); mInjector = injector; mContext = context.createAttributionContext(ATTRIBUTION_TAG); mUserInfoHelper = injector.getUserInfoHelper(); mAppOpsHelper = injector.getAppOpsHelper(); mSettingsHelper = injector.getSettingsHelper(); mAppForegroundHelper = injector.getAppForegroundHelper(); mLocationUsageLogger = injector.getLocationUsageLogger(); mGeofenceManager = new GeofenceManager(injector); mGeofenceManager = new GeofenceManager(mContext, injector); // set up passive provider - we do this early because it has no dependencies on system // services or external code that isn't ready yet, and because this allows the variable to Loading @@ -323,12 +331,6 @@ public class LocationManagerService extends ILocationManager.Stub { } void onSystemReady() { mAppOpsHelper.onSystemReady(); mSettingsHelper.onSystemReady(); mAppForegroundHelper.onSystemReady(); mGeofenceManager.onSystemReady(); synchronized (mLock) { mPowerManager = mContext.getSystemService(PowerManager.class); Loading Loading @@ -635,8 +637,7 @@ public class LocationManagerService extends ILocationManager.Stub { private void initializeGnss() { // Do not hold mLock when calling GnssManagerService#isGnssSupported() which calls into HAL. if (GnssManagerService.isGnssSupported()) { mGnssManagerService = new GnssManagerService(mContext, mUserInfoHelper, mSettingsHelper, mAppOpsHelper, mAppForegroundHelper, mLocationUsageLogger); mGnssManagerService = new GnssManagerService(mContext, mInjector); mGnssManagerService.onSystemReady(); LocationProviderManager gnssManager = new LocationProviderManager(GPS_PROVIDER); Loading Loading @@ -2881,37 +2882,26 @@ public class LocationManagerService extends ILocationManager.Stub { private static class SystemInjector implements Injector { private final Context mContext; private final UserInfoHelper mUserInfoHelper; private final AppOpsHelper mAppOpsHelper; private final SettingsHelper mSettingsHelper; private final AppForegroundHelper mAppForegroundHelper; private final SystemAppOpsHelper mAppOpsHelper; private final SystemSettingsHelper mSettingsHelper; private final SystemAppForegroundHelper mAppForegroundHelper; private final LocationUsageLogger mLocationUsageLogger; private final LocationAttributionHelper mLocationAttributionHelper; SystemInjector(Context context, UserInfoHelper userInfoHelper) { this( context, userInfoHelper, new AppOpsHelper(context), new SettingsHelper(context), new AppForegroundHelper(context), new LocationUsageLogger()); } SystemInjector(Context context, UserInfoHelper userInfoHelper, AppOpsHelper appOpsHelper, SettingsHelper settingsHelper, AppForegroundHelper appForegroundHelper, LocationUsageLogger locationUsageLogger) { mContext = context; mUserInfoHelper = userInfoHelper; mAppOpsHelper = appOpsHelper; mSettingsHelper = settingsHelper; mAppForegroundHelper = appForegroundHelper; mLocationUsageLogger = locationUsageLogger; mAppOpsHelper = new SystemAppOpsHelper(context); mSettingsHelper = new SystemSettingsHelper(context); mAppForegroundHelper = new SystemAppForegroundHelper(context); mLocationUsageLogger = new LocationUsageLogger(); mLocationAttributionHelper = new LocationAttributionHelper(mAppOpsHelper); } @Override public Context getContext() { return mContext; void onSystemReady() { mAppOpsHelper.onSystemReady(); mSettingsHelper.onSystemReady(); mAppForegroundHelper.onSystemReady(); } @Override Loading @@ -2938,5 +2928,10 @@ public class LocationManagerService extends ILocationManager.Stub { public LocationUsageLogger getLocationUsageLogger() { return mLocationUsageLogger; } @Override public LocationAttributionHelper getLocationAttributionHelper() { return mLocationAttributionHelper; } } } services/core/java/com/android/server/location/geofence/GeofenceManager.java +15 −32 Original line number Diff line number Diff line Loading @@ -40,7 +40,6 @@ import android.stats.location.LocationStatsEnums; import android.util.ArraySet; import com.android.internal.annotations.GuardedBy; import com.android.internal.util.Preconditions; import com.android.server.PendingIntentUtils; import com.android.server.location.LocationPermissions; import com.android.server.location.listeners.ListenerMultiplexer; Loading @@ -53,6 +52,7 @@ import com.android.server.location.util.UserInfoHelper; import com.android.server.location.util.UserInfoHelper.UserListener; import java.util.Collection; import java.util.Objects; /** * Manages all geofences. Loading Loading @@ -99,12 +99,8 @@ public class GeofenceManager extends mCenter.setLatitude(geofence.getLatitude()); mCenter.setLongitude(geofence.getLongitude()); synchronized (mLock) { // don't register geofences before the system is ready Preconditions.checkState(mPowerManager != null); } mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, mWakeLock = Objects.requireNonNull(mContext.getSystemService(PowerManager.class)) .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG + ":" + identity.getPackageName()); mWakeLock.setReferenceCounted(true); mWakeLock.setWorkSource(identity.addToWorkSource(null)); Loading Loading @@ -236,32 +232,28 @@ public class GeofenceManager extends protected final SettingsHelper mSettingsHelper; protected final LocationUsageLogger mLocationUsageLogger; protected PowerManager mPowerManager; protected LocationManager mLocationManager; @GuardedBy("mLock") private LocationManager mLocationManager; @GuardedBy("mLock") private @Nullable Location mLastLocation; public GeofenceManager(Injector injector) { mContext = injector.getContext().createAttributionContext(ATTRIBUTION_TAG); public GeofenceManager(Context context, Injector injector) { mContext = context.createAttributionContext(ATTRIBUTION_TAG); mUserInfoHelper = injector.getUserInfoHelper(); mSettingsHelper = injector.getSettingsHelper(); mAppOpsHelper = injector.getAppOpsHelper(); mLocationUsageLogger = injector.getLocationUsageLogger(); } /** Called when system is ready. */ public void onSystemReady() { private LocationManager getLocationManager() { synchronized (mLock) { if (mLocationManager != null) { return; if (mLocationManager == null) { mLocationManager = Objects.requireNonNull( mContext.getSystemService(LocationManager.class)); } mSettingsHelper.onSystemReady(); mAppOpsHelper.onSystemReady(); mPowerManager = mContext.getSystemService(PowerManager.class); mLocationManager = mContext.getSystemService(LocationManager.class); return mLocationManager; } } Loading Loading @@ -343,19 +335,14 @@ public class GeofenceManager extends @Override protected boolean registerWithService(LocationRequest locationRequest) { synchronized (mLock) { Preconditions.checkState(mLocationManager != null); } mLocationManager.requestLocationUpdates(locationRequest, DIRECT_EXECUTOR, this); getLocationManager().requestLocationUpdates(locationRequest, DIRECT_EXECUTOR, this); return true; } @Override protected void unregisterWithService() { synchronized (mLock) { Preconditions.checkState(mLocationManager != null); mLocationManager.removeUpdates(this); getLocationManager().removeUpdates(this); mLastLocation = null; } } Loading Loading @@ -422,11 +409,7 @@ public class GeofenceManager extends } if (location == null) { synchronized (mLock) { Preconditions.checkState(mLocationManager != null); } location = mLocationManager.getLastLocation(); location = getLocationManager().getLastLocation(); } if (location != null) { Loading services/core/java/com/android/server/location/gnss/GnssAntennaInfoProvider.java +5 −12 Original line number Diff line number Diff line Loading @@ -26,10 +26,7 @@ import android.util.Log; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.Preconditions; import com.android.server.location.util.AppForegroundHelper; import com.android.server.location.util.AppOpsHelper; import com.android.server.location.util.SettingsHelper; import com.android.server.location.util.UserInfoHelper; import com.android.server.location.util.Injector; import java.util.List; Loading @@ -41,17 +38,13 @@ public class GnssAntennaInfoProvider extends private final GnssAntennaInfoProviderNative mNative; public GnssAntennaInfoProvider(UserInfoHelper userInfoHelper, SettingsHelper settingsHelper, AppOpsHelper appOpsHelper, AppForegroundHelper appForegroundHelper) { this(userInfoHelper, settingsHelper, appOpsHelper, appForegroundHelper, new GnssAntennaInfoProviderNative()); public GnssAntennaInfoProvider(Injector injector) { this(injector, new GnssAntennaInfoProviderNative()); } @VisibleForTesting public GnssAntennaInfoProvider(UserInfoHelper userInfoHelper, SettingsHelper settingsHelper, AppOpsHelper appOpsHelper, AppForegroundHelper appForegroundHelper, GnssAntennaInfoProviderNative aNative) { super(userInfoHelper, settingsHelper, appOpsHelper, appForegroundHelper); public GnssAntennaInfoProvider(Injector injector, GnssAntennaInfoProviderNative aNative) { super(injector); mNative = aNative; } Loading services/core/java/com/android/server/location/gnss/GnssListenerMultiplexer.java +6 −6 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ import com.android.server.location.listeners.BinderListenerRegistration; import com.android.server.location.listeners.ListenerMultiplexer; import com.android.server.location.util.AppForegroundHelper; import com.android.server.location.util.AppOpsHelper; import com.android.server.location.util.Injector; import com.android.server.location.util.SettingsHelper; import com.android.server.location.util.UserInfoHelper; import com.android.server.location.util.UserInfoHelper.UserListener; Loading Loading @@ -157,12 +158,11 @@ public abstract class GnssListenerMultiplexer<TRequest, TListener extends IInter private final AppForegroundHelper.AppForegroundListener mAppForegroundChangedListener = this::onAppForegroundChanged; protected GnssListenerMultiplexer(UserInfoHelper userInfoHelper, SettingsHelper settingsHelper, AppOpsHelper appOpsHelper, AppForegroundHelper appForegroundHelper) { mUserInfoHelper = userInfoHelper; mSettingsHelper = settingsHelper; mAppOpsHelper = appOpsHelper; mAppForegroundHelper = appForegroundHelper; protected GnssListenerMultiplexer(Injector injector) { mUserInfoHelper = injector.getUserInfoHelper(); mSettingsHelper = injector.getSettingsHelper(); mAppOpsHelper = injector.getAppOpsHelper(); mAppForegroundHelper = injector.getAppForegroundHelper(); mLocationManagerInternal = Objects.requireNonNull( LocalServices.getService(LocationManagerInternal.class)); } Loading services/core/java/com/android/server/location/gnss/GnssLocationProvider.java +6 −16 Original line number Diff line number Diff line Loading @@ -81,11 +81,7 @@ import com.android.server.LocalServices; import com.android.server.location.AbstractLocationProvider; import com.android.server.location.gnss.GnssSatelliteBlacklistHelper.GnssSatelliteBlacklistCallback; import com.android.server.location.gnss.NtpTimeHelper.InjectNtpTimeCallback; import com.android.server.location.util.AppForegroundHelper; import com.android.server.location.util.AppOpsHelper; import com.android.server.location.util.LocationUsageLogger; import com.android.server.location.util.SettingsHelper; import com.android.server.location.util.UserInfoHelper; import com.android.server.location.util.Injector; import java.io.FileDescriptor; import java.io.PrintWriter; Loading Loading @@ -588,9 +584,7 @@ public class GnssLocationProvider extends AbstractLocationProvider implements } } public GnssLocationProvider(Context context, UserInfoHelper userInfoHelper, SettingsHelper settingsHelper, AppOpsHelper appOpsHelper, AppForegroundHelper appForegroundHelper, LocationUsageLogger logger) { public GnssLocationProvider(Context context, Injector injector) { super(FgThread.getExecutor(), CallerIdentity.fromContext(context)); mContext = context; Loading Loading @@ -634,15 +628,11 @@ public class GnssLocationProvider extends AbstractLocationProvider implements mNetworkConnectivityHandler = new GnssNetworkConnectivityHandler(context, GnssLocationProvider.this::onNetworkAvailable, mLooper, mNIHandler); mGnssStatusListenerHelper = new GnssStatusProvider(userInfoHelper, settingsHelper, appOpsHelper, appForegroundHelper, logger); mGnssMeasurementsProvider = new GnssMeasurementsProvider(userInfoHelper, settingsHelper, appOpsHelper, appForegroundHelper, logger); mGnssStatusListenerHelper = new GnssStatusProvider(injector); mGnssMeasurementsProvider = new GnssMeasurementsProvider(injector); mGnssMeasurementCorrectionsProvider = new GnssMeasurementCorrectionsProvider(mHandler); mGnssAntennaInfoProvider = new GnssAntennaInfoProvider(userInfoHelper, settingsHelper, appOpsHelper, appForegroundHelper); mGnssNavigationMessageProvider = new GnssNavigationMessageProvider(userInfoHelper, settingsHelper, appOpsHelper, appForegroundHelper); mGnssAntennaInfoProvider = new GnssAntennaInfoProvider(injector); mGnssNavigationMessageProvider = new GnssNavigationMessageProvider(injector); mGnssMetrics = new GnssMetrics(mContext, mBatteryStats); mNtpTimeHelper = new NtpTimeHelper(mContext, mLooper, this); Loading Loading
services/core/java/com/android/server/location/LocationManagerService.java +48 −53 Original line number Diff line number Diff line Loading @@ -109,8 +109,13 @@ import com.android.server.location.gnss.GnssManagerService; import com.android.server.location.util.AppForegroundHelper; import com.android.server.location.util.AppOpsHelper; import com.android.server.location.util.Injector; import com.android.server.location.util.LocationAttributionHelper; import com.android.server.location.util.LocationUsageLogger; import com.android.server.location.util.SettingsHelper; import com.android.server.location.util.SystemAppForegroundHelper; import com.android.server.location.util.SystemAppOpsHelper; import com.android.server.location.util.SystemSettingsHelper; import com.android.server.location.util.SystemUserInfoHelper; import com.android.server.location.util.UserInfoHelper; import com.android.server.location.util.UserInfoHelper.UserListener; import com.android.server.pm.permission.PermissionManagerServiceInternal; Loading Loading @@ -141,14 +146,15 @@ public class LocationManagerService extends ILocationManager.Stub { */ public static class Lifecycle extends SystemService { private final SystemUserInfoHelper mUserInfoHelper; private final LifecycleUserInfoHelper mUserInfoHelper; private final SystemInjector mSystemInjector; private final LocationManagerService mService; public Lifecycle(Context context) { super(context); context = context.createAttributionContext(ATTRIBUTION_TAG); mUserInfoHelper = new SystemUserInfoHelper(context); mService = new LocationManagerService(new SystemInjector(context, mUserInfoHelper)); mUserInfoHelper = new LifecycleUserInfoHelper(context); mSystemInjector = new SystemInjector(context, mUserInfoHelper); mService = new LocationManagerService(context, mSystemInjector); } @Override Loading @@ -166,6 +172,7 @@ public class LocationManagerService extends ILocationManager.Stub { public void onBootPhase(int phase) { if (phase == PHASE_SYSTEM_SERVICES_READY) { // the location service must be functioning after this boot phase mSystemInjector.onSystemReady(); mService.onSystemReady(); } else if (phase == PHASE_THIRD_PARTY_APPS_CAN_START) { // some providers rely on third party code, so we wait to initialize Loading @@ -176,39 +183,36 @@ public class LocationManagerService extends ILocationManager.Stub { @Override public void onUserStarting(TargetUser user) { mUserInfoHelper.dispatchOnUserStarted(user.getUserIdentifier()); mUserInfoHelper.onUserStarted(user.getUserIdentifier()); } @Override public void onUserSwitching(TargetUser from, TargetUser to) { mUserInfoHelper.dispatchOnCurrentUserChanged(from.getUserIdentifier(), mUserInfoHelper.onCurrentUserChanged(from.getUserIdentifier(), to.getUserIdentifier()); } @Override public void onUserStopped(TargetUser user) { mUserInfoHelper.dispatchOnUserStopped(user.getUserIdentifier()); mUserInfoHelper.onUserStopped(user.getUserIdentifier()); } private static class SystemUserInfoHelper extends UserInfoHelper { private static class LifecycleUserInfoHelper extends SystemUserInfoHelper { SystemUserInfoHelper(Context context) { LifecycleUserInfoHelper(Context context) { super(context); } @Override protected void dispatchOnUserStarted(int userId) { super.dispatchOnUserStarted(userId); void onUserStarted(int userId) { dispatchOnUserStarted(userId); } @Override protected void dispatchOnUserStopped(int userId) { super.dispatchOnUserStopped(userId); void onUserStopped(int userId) { dispatchOnUserStopped(userId); } @Override protected void dispatchOnCurrentUserChanged(int fromUserId, int toUserId) { super.dispatchOnCurrentUserChanged(fromUserId, toUserId); void onCurrentUserChanged(int fromUserId, int toUserId) { dispatchOnCurrentUserChanged(fromUserId, toUserId); } } } Loading Loading @@ -247,6 +251,8 @@ public class LocationManagerService extends ILocationManager.Stub { private final Handler mHandler; private final LocalService mLocalService; private final Injector mInjector; private final Context mContext; private final AppOpsHelper mAppOpsHelper; private final UserInfoHelper mUserInfoHelper; Loading Loading @@ -285,20 +291,22 @@ public class LocationManagerService extends ILocationManager.Stub { @PowerManager.LocationPowerSaveMode private int mBatterySaverMode; LocationManagerService(Injector injector) { LocationManagerService(Context context, Injector injector) { mHandler = FgThread.getHandler(); mLocalService = new LocalService(); LocalServices.addService(LocationManagerInternal.class, mLocalService); mContext = injector.getContext(); mInjector = injector; mContext = context.createAttributionContext(ATTRIBUTION_TAG); mUserInfoHelper = injector.getUserInfoHelper(); mAppOpsHelper = injector.getAppOpsHelper(); mSettingsHelper = injector.getSettingsHelper(); mAppForegroundHelper = injector.getAppForegroundHelper(); mLocationUsageLogger = injector.getLocationUsageLogger(); mGeofenceManager = new GeofenceManager(injector); mGeofenceManager = new GeofenceManager(mContext, injector); // set up passive provider - we do this early because it has no dependencies on system // services or external code that isn't ready yet, and because this allows the variable to Loading @@ -323,12 +331,6 @@ public class LocationManagerService extends ILocationManager.Stub { } void onSystemReady() { mAppOpsHelper.onSystemReady(); mSettingsHelper.onSystemReady(); mAppForegroundHelper.onSystemReady(); mGeofenceManager.onSystemReady(); synchronized (mLock) { mPowerManager = mContext.getSystemService(PowerManager.class); Loading Loading @@ -635,8 +637,7 @@ public class LocationManagerService extends ILocationManager.Stub { private void initializeGnss() { // Do not hold mLock when calling GnssManagerService#isGnssSupported() which calls into HAL. if (GnssManagerService.isGnssSupported()) { mGnssManagerService = new GnssManagerService(mContext, mUserInfoHelper, mSettingsHelper, mAppOpsHelper, mAppForegroundHelper, mLocationUsageLogger); mGnssManagerService = new GnssManagerService(mContext, mInjector); mGnssManagerService.onSystemReady(); LocationProviderManager gnssManager = new LocationProviderManager(GPS_PROVIDER); Loading Loading @@ -2881,37 +2882,26 @@ public class LocationManagerService extends ILocationManager.Stub { private static class SystemInjector implements Injector { private final Context mContext; private final UserInfoHelper mUserInfoHelper; private final AppOpsHelper mAppOpsHelper; private final SettingsHelper mSettingsHelper; private final AppForegroundHelper mAppForegroundHelper; private final SystemAppOpsHelper mAppOpsHelper; private final SystemSettingsHelper mSettingsHelper; private final SystemAppForegroundHelper mAppForegroundHelper; private final LocationUsageLogger mLocationUsageLogger; private final LocationAttributionHelper mLocationAttributionHelper; SystemInjector(Context context, UserInfoHelper userInfoHelper) { this( context, userInfoHelper, new AppOpsHelper(context), new SettingsHelper(context), new AppForegroundHelper(context), new LocationUsageLogger()); } SystemInjector(Context context, UserInfoHelper userInfoHelper, AppOpsHelper appOpsHelper, SettingsHelper settingsHelper, AppForegroundHelper appForegroundHelper, LocationUsageLogger locationUsageLogger) { mContext = context; mUserInfoHelper = userInfoHelper; mAppOpsHelper = appOpsHelper; mSettingsHelper = settingsHelper; mAppForegroundHelper = appForegroundHelper; mLocationUsageLogger = locationUsageLogger; mAppOpsHelper = new SystemAppOpsHelper(context); mSettingsHelper = new SystemSettingsHelper(context); mAppForegroundHelper = new SystemAppForegroundHelper(context); mLocationUsageLogger = new LocationUsageLogger(); mLocationAttributionHelper = new LocationAttributionHelper(mAppOpsHelper); } @Override public Context getContext() { return mContext; void onSystemReady() { mAppOpsHelper.onSystemReady(); mSettingsHelper.onSystemReady(); mAppForegroundHelper.onSystemReady(); } @Override Loading @@ -2938,5 +2928,10 @@ public class LocationManagerService extends ILocationManager.Stub { public LocationUsageLogger getLocationUsageLogger() { return mLocationUsageLogger; } @Override public LocationAttributionHelper getLocationAttributionHelper() { return mLocationAttributionHelper; } } }
services/core/java/com/android/server/location/geofence/GeofenceManager.java +15 −32 Original line number Diff line number Diff line Loading @@ -40,7 +40,6 @@ import android.stats.location.LocationStatsEnums; import android.util.ArraySet; import com.android.internal.annotations.GuardedBy; import com.android.internal.util.Preconditions; import com.android.server.PendingIntentUtils; import com.android.server.location.LocationPermissions; import com.android.server.location.listeners.ListenerMultiplexer; Loading @@ -53,6 +52,7 @@ import com.android.server.location.util.UserInfoHelper; import com.android.server.location.util.UserInfoHelper.UserListener; import java.util.Collection; import java.util.Objects; /** * Manages all geofences. Loading Loading @@ -99,12 +99,8 @@ public class GeofenceManager extends mCenter.setLatitude(geofence.getLatitude()); mCenter.setLongitude(geofence.getLongitude()); synchronized (mLock) { // don't register geofences before the system is ready Preconditions.checkState(mPowerManager != null); } mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, mWakeLock = Objects.requireNonNull(mContext.getSystemService(PowerManager.class)) .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG + ":" + identity.getPackageName()); mWakeLock.setReferenceCounted(true); mWakeLock.setWorkSource(identity.addToWorkSource(null)); Loading Loading @@ -236,32 +232,28 @@ public class GeofenceManager extends protected final SettingsHelper mSettingsHelper; protected final LocationUsageLogger mLocationUsageLogger; protected PowerManager mPowerManager; protected LocationManager mLocationManager; @GuardedBy("mLock") private LocationManager mLocationManager; @GuardedBy("mLock") private @Nullable Location mLastLocation; public GeofenceManager(Injector injector) { mContext = injector.getContext().createAttributionContext(ATTRIBUTION_TAG); public GeofenceManager(Context context, Injector injector) { mContext = context.createAttributionContext(ATTRIBUTION_TAG); mUserInfoHelper = injector.getUserInfoHelper(); mSettingsHelper = injector.getSettingsHelper(); mAppOpsHelper = injector.getAppOpsHelper(); mLocationUsageLogger = injector.getLocationUsageLogger(); } /** Called when system is ready. */ public void onSystemReady() { private LocationManager getLocationManager() { synchronized (mLock) { if (mLocationManager != null) { return; if (mLocationManager == null) { mLocationManager = Objects.requireNonNull( mContext.getSystemService(LocationManager.class)); } mSettingsHelper.onSystemReady(); mAppOpsHelper.onSystemReady(); mPowerManager = mContext.getSystemService(PowerManager.class); mLocationManager = mContext.getSystemService(LocationManager.class); return mLocationManager; } } Loading Loading @@ -343,19 +335,14 @@ public class GeofenceManager extends @Override protected boolean registerWithService(LocationRequest locationRequest) { synchronized (mLock) { Preconditions.checkState(mLocationManager != null); } mLocationManager.requestLocationUpdates(locationRequest, DIRECT_EXECUTOR, this); getLocationManager().requestLocationUpdates(locationRequest, DIRECT_EXECUTOR, this); return true; } @Override protected void unregisterWithService() { synchronized (mLock) { Preconditions.checkState(mLocationManager != null); mLocationManager.removeUpdates(this); getLocationManager().removeUpdates(this); mLastLocation = null; } } Loading Loading @@ -422,11 +409,7 @@ public class GeofenceManager extends } if (location == null) { synchronized (mLock) { Preconditions.checkState(mLocationManager != null); } location = mLocationManager.getLastLocation(); location = getLocationManager().getLastLocation(); } if (location != null) { Loading
services/core/java/com/android/server/location/gnss/GnssAntennaInfoProvider.java +5 −12 Original line number Diff line number Diff line Loading @@ -26,10 +26,7 @@ import android.util.Log; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.Preconditions; import com.android.server.location.util.AppForegroundHelper; import com.android.server.location.util.AppOpsHelper; import com.android.server.location.util.SettingsHelper; import com.android.server.location.util.UserInfoHelper; import com.android.server.location.util.Injector; import java.util.List; Loading @@ -41,17 +38,13 @@ public class GnssAntennaInfoProvider extends private final GnssAntennaInfoProviderNative mNative; public GnssAntennaInfoProvider(UserInfoHelper userInfoHelper, SettingsHelper settingsHelper, AppOpsHelper appOpsHelper, AppForegroundHelper appForegroundHelper) { this(userInfoHelper, settingsHelper, appOpsHelper, appForegroundHelper, new GnssAntennaInfoProviderNative()); public GnssAntennaInfoProvider(Injector injector) { this(injector, new GnssAntennaInfoProviderNative()); } @VisibleForTesting public GnssAntennaInfoProvider(UserInfoHelper userInfoHelper, SettingsHelper settingsHelper, AppOpsHelper appOpsHelper, AppForegroundHelper appForegroundHelper, GnssAntennaInfoProviderNative aNative) { super(userInfoHelper, settingsHelper, appOpsHelper, appForegroundHelper); public GnssAntennaInfoProvider(Injector injector, GnssAntennaInfoProviderNative aNative) { super(injector); mNative = aNative; } Loading
services/core/java/com/android/server/location/gnss/GnssListenerMultiplexer.java +6 −6 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ import com.android.server.location.listeners.BinderListenerRegistration; import com.android.server.location.listeners.ListenerMultiplexer; import com.android.server.location.util.AppForegroundHelper; import com.android.server.location.util.AppOpsHelper; import com.android.server.location.util.Injector; import com.android.server.location.util.SettingsHelper; import com.android.server.location.util.UserInfoHelper; import com.android.server.location.util.UserInfoHelper.UserListener; Loading Loading @@ -157,12 +158,11 @@ public abstract class GnssListenerMultiplexer<TRequest, TListener extends IInter private final AppForegroundHelper.AppForegroundListener mAppForegroundChangedListener = this::onAppForegroundChanged; protected GnssListenerMultiplexer(UserInfoHelper userInfoHelper, SettingsHelper settingsHelper, AppOpsHelper appOpsHelper, AppForegroundHelper appForegroundHelper) { mUserInfoHelper = userInfoHelper; mSettingsHelper = settingsHelper; mAppOpsHelper = appOpsHelper; mAppForegroundHelper = appForegroundHelper; protected GnssListenerMultiplexer(Injector injector) { mUserInfoHelper = injector.getUserInfoHelper(); mSettingsHelper = injector.getSettingsHelper(); mAppOpsHelper = injector.getAppOpsHelper(); mAppForegroundHelper = injector.getAppForegroundHelper(); mLocationManagerInternal = Objects.requireNonNull( LocalServices.getService(LocationManagerInternal.class)); } Loading
services/core/java/com/android/server/location/gnss/GnssLocationProvider.java +6 −16 Original line number Diff line number Diff line Loading @@ -81,11 +81,7 @@ import com.android.server.LocalServices; import com.android.server.location.AbstractLocationProvider; import com.android.server.location.gnss.GnssSatelliteBlacklistHelper.GnssSatelliteBlacklistCallback; import com.android.server.location.gnss.NtpTimeHelper.InjectNtpTimeCallback; import com.android.server.location.util.AppForegroundHelper; import com.android.server.location.util.AppOpsHelper; import com.android.server.location.util.LocationUsageLogger; import com.android.server.location.util.SettingsHelper; import com.android.server.location.util.UserInfoHelper; import com.android.server.location.util.Injector; import java.io.FileDescriptor; import java.io.PrintWriter; Loading Loading @@ -588,9 +584,7 @@ public class GnssLocationProvider extends AbstractLocationProvider implements } } public GnssLocationProvider(Context context, UserInfoHelper userInfoHelper, SettingsHelper settingsHelper, AppOpsHelper appOpsHelper, AppForegroundHelper appForegroundHelper, LocationUsageLogger logger) { public GnssLocationProvider(Context context, Injector injector) { super(FgThread.getExecutor(), CallerIdentity.fromContext(context)); mContext = context; Loading Loading @@ -634,15 +628,11 @@ public class GnssLocationProvider extends AbstractLocationProvider implements mNetworkConnectivityHandler = new GnssNetworkConnectivityHandler(context, GnssLocationProvider.this::onNetworkAvailable, mLooper, mNIHandler); mGnssStatusListenerHelper = new GnssStatusProvider(userInfoHelper, settingsHelper, appOpsHelper, appForegroundHelper, logger); mGnssMeasurementsProvider = new GnssMeasurementsProvider(userInfoHelper, settingsHelper, appOpsHelper, appForegroundHelper, logger); mGnssStatusListenerHelper = new GnssStatusProvider(injector); mGnssMeasurementsProvider = new GnssMeasurementsProvider(injector); mGnssMeasurementCorrectionsProvider = new GnssMeasurementCorrectionsProvider(mHandler); mGnssAntennaInfoProvider = new GnssAntennaInfoProvider(userInfoHelper, settingsHelper, appOpsHelper, appForegroundHelper); mGnssNavigationMessageProvider = new GnssNavigationMessageProvider(userInfoHelper, settingsHelper, appOpsHelper, appForegroundHelper); mGnssAntennaInfoProvider = new GnssAntennaInfoProvider(injector); mGnssNavigationMessageProvider = new GnssNavigationMessageProvider(injector); mGnssMetrics = new GnssMetrics(mContext, mBatteryStats); mNtpTimeHelper = new NtpTimeHelper(mContext, mLooper, this); Loading