Loading services/core/java/com/android/server/location/LocationManagerService.java +58 −26 Original line number Diff line number Diff line Loading @@ -79,6 +79,7 @@ import android.os.UserHandle; import android.os.WorkSource; import android.os.WorkSource.WorkChain; import android.stats.location.LocationStatsEnums; import android.util.ArrayMap; import android.util.IndentingPrintWriter; import android.util.Log; Loading @@ -87,6 +88,7 @@ import com.android.internal.util.DumpUtils; import com.android.internal.util.Preconditions; import com.android.server.LocalServices; import com.android.server.SystemService; import com.android.server.location.eventlog.LocationEventLog; import com.android.server.location.geofence.GeofenceManager; import com.android.server.location.geofence.GeofenceProxy; import com.android.server.location.gnss.GnssConfiguration; Loading @@ -98,7 +100,6 @@ import com.android.server.location.injector.AppOpsHelper; import com.android.server.location.injector.EmergencyHelper; import com.android.server.location.injector.Injector; import com.android.server.location.injector.LocationAttributionHelper; import com.android.server.location.injector.LocationEventLog; import com.android.server.location.injector.LocationPermissionsHelper; import com.android.server.location.injector.LocationPowerSaveModeHelper; import com.android.server.location.injector.LocationUsageLogger; Loading Loading @@ -147,9 +148,10 @@ public class LocationManagerService extends ILocationManager.Stub { public Lifecycle(Context context) { super(context); LocationEventLog eventLog = new LocationEventLog(); mUserInfoHelper = new LifecycleUserInfoHelper(context); mSystemInjector = new SystemInjector(context, mUserInfoHelper); mService = new LocationManagerService(context, mSystemInjector); mSystemInjector = new SystemInjector(context, mUserInfoHelper, eventLog); mService = new LocationManagerService(context, mSystemInjector, eventLog); } @Override Loading @@ -159,7 +161,7 @@ public class LocationManagerService extends ILocationManager.Stub { // client caching behavior is only enabled after seeing the first invalidate LocationManager.invalidateLocalLocationEnabledCaches(); // disable caching for our own process Objects.requireNonNull(mService.mContext.getSystemService(LocationManager.class)) Objects.requireNonNull(getContext().getSystemService(LocationManager.class)) .disableLocalLocationEnabledCaches(); } Loading Loading @@ -221,6 +223,7 @@ public class LocationManagerService extends ILocationManager.Stub { private final Context mContext; private final Injector mInjector; private final LocationEventLog mEventLog; private final LocalService mLocalService; private final GeofenceManager mGeofenceManager; Loading @@ -245,10 +248,10 @@ public class LocationManagerService extends ILocationManager.Stub { private final CopyOnWriteArrayList<LocationProviderManager> mProviderManagers = new CopyOnWriteArrayList<>(); LocationManagerService(Context context, Injector injector) { LocationManagerService(Context context, Injector injector, LocationEventLog eventLog) { mContext = context.createAttributionContext(ATTRIBUTION_TAG); mInjector = injector; mEventLog = eventLog; mLocalService = new LocalService(); LocalServices.addService(LocationManagerInternal.class, mLocalService); Loading @@ -256,7 +259,7 @@ public class LocationManagerService extends ILocationManager.Stub { // set up passive provider first since it will be required for all other location providers, // which are loaded later once the system is ready. mPassiveManager = new PassiveLocationProviderManager(mContext, injector); mPassiveManager = new PassiveLocationProviderManager(mContext, injector, mEventLog); addLocationProviderManager(mPassiveManager, new PassiveLocationProvider(mContext)); // TODO: load the gps provider here as well, which will require refactoring Loading Loading @@ -297,7 +300,7 @@ public class LocationManagerService extends ILocationManager.Stub { } LocationProviderManager manager = new LocationProviderManager(mContext, mInjector, providerName, mPassiveManager); mEventLog, providerName, mPassiveManager); addLocationProviderManager(manager, null); return manager; } Loading Loading @@ -341,7 +344,7 @@ public class LocationManagerService extends ILocationManager.Stub { com.android.internal.R.string.config_networkLocationProviderPackageName); if (networkProvider != null) { LocationProviderManager networkManager = new LocationProviderManager(mContext, mInjector, NETWORK_PROVIDER, mPassiveManager); mInjector, mEventLog, NETWORK_PROVIDER, mPassiveManager); addLocationProviderManager(networkManager, networkProvider); } else { Log.w(TAG, "no network location provider found"); Loading @@ -360,7 +363,7 @@ public class LocationManagerService extends ILocationManager.Stub { com.android.internal.R.string.config_fusedLocationProviderPackageName); if (fusedProvider != null) { LocationProviderManager fusedManager = new LocationProviderManager(mContext, mInjector, FUSED_PROVIDER, mPassiveManager); mEventLog, FUSED_PROVIDER, mPassiveManager); addLocationProviderManager(fusedManager, fusedProvider); } else { Log.wtf(TAG, "no fused location provider found"); Loading @@ -375,7 +378,7 @@ public class LocationManagerService extends ILocationManager.Stub { mGnssManagerService.onSystemReady(); LocationProviderManager gnssManager = new LocationProviderManager(mContext, mInjector, GPS_PROVIDER, mPassiveManager); mEventLog, GPS_PROVIDER, mPassiveManager); addLocationProviderManager(gnssManager, mGnssManagerService.getGnssLocationProvider()); } Loading Loading @@ -431,7 +434,7 @@ public class LocationManagerService extends ILocationManager.Stub { Log.d(TAG, "[u" + userId + "] location enabled = " + enabled); } mInjector.getLocationEventLog().logLocationEnabled(userId, enabled); mEventLog.logLocationEnabled(userId, enabled); Intent intent = new Intent(LocationManager.MODE_CHANGED_ACTION) .putExtra(LocationManager.EXTRA_LOCATION_ENABLED, enabled) Loading Loading @@ -1193,10 +1196,28 @@ public class LocationManagerService extends ILocationManager.Stub { IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " "); if (mGnssManagerService != null && args.length > 0 && args[0].equals("--gnssmetrics")) { if (args.length > 0) { LocationProviderManager manager = getLocationProviderManager(args[0]); if (manager != null) { ipw.println("Provider:"); ipw.increaseIndent(); manager.dump(fd, ipw, args); ipw.decreaseIndent(); ipw.println("Event Log:"); ipw.increaseIndent(); mEventLog.iterate(manager.getName(), ipw::println); ipw.decreaseIndent(); return; } if ("--gnssmetrics".equals(args[0])) { if (mGnssManagerService != null) { mGnssManagerService.dump(fd, ipw, args); } return; } } ipw.println("Location Manager State:"); ipw.increaseIndent(); Loading Loading @@ -1227,6 +1248,25 @@ public class LocationManagerService extends ILocationManager.Stub { } ipw.decreaseIndent(); ipw.println("Historical Aggregate Location Provider Data:"); ipw.increaseIndent(); ArrayMap<String, ArrayMap<String, LocationEventLog.AggregateStats>> aggregateStats = mEventLog.copyAggregateStats(); for (int i = 0; i < aggregateStats.size(); i++) { ipw.println(aggregateStats.keyAt(i)); ipw.increaseIndent(); ArrayMap<String, LocationEventLog.AggregateStats> providerStats = aggregateStats.valueAt(i); for (int j = 0; j < providerStats.size(); j++) { ipw.print(providerStats.keyAt(j)); ipw.print(": "); providerStats.valueAt(j).updateTotals(); ipw.println(providerStats.valueAt(j)); } ipw.decreaseIndent(); } ipw.decreaseIndent(); if (mGnssManagerService != null) { ipw.println("GNSS Manager:"); ipw.increaseIndent(); Loading @@ -1241,7 +1281,7 @@ public class LocationManagerService extends ILocationManager.Stub { ipw.println("Event Log:"); ipw.increaseIndent(); mInjector.getLocationEventLog().iterate(ipw::println); mEventLog.iterate(ipw::println); ipw.decreaseIndent(); } Loading Loading @@ -1320,7 +1360,6 @@ public class LocationManagerService extends ILocationManager.Stub { private final Context mContext; private final UserInfoHelper mUserInfoHelper; private final LocationEventLog mLocationEventLog; private final AlarmHelper mAlarmHelper; private final SystemAppOpsHelper mAppOpsHelper; private final SystemLocationPermissionsHelper mLocationPermissionsHelper; Loading @@ -1339,19 +1378,17 @@ public class LocationManagerService extends ILocationManager.Stub { @GuardedBy("this") private boolean mSystemReady; SystemInjector(Context context, UserInfoHelper userInfoHelper) { SystemInjector(Context context, UserInfoHelper userInfoHelper, LocationEventLog eventLog) { mContext = context; mUserInfoHelper = userInfoHelper; mLocationEventLog = new LocationEventLog(); mAlarmHelper = new SystemAlarmHelper(context); mAppOpsHelper = new SystemAppOpsHelper(context); mLocationPermissionsHelper = new SystemLocationPermissionsHelper(context, mAppOpsHelper); mSettingsHelper = new SystemSettingsHelper(context); mAppForegroundHelper = new SystemAppForegroundHelper(context); mLocationPowerSaveModeHelper = new SystemLocationPowerSaveModeHelper(context, mLocationEventLog); mLocationPowerSaveModeHelper = new SystemLocationPowerSaveModeHelper(context, eventLog); mScreenInteractiveHelper = new SystemScreenInteractiveHelper(context); mLocationAttributionHelper = new LocationAttributionHelper(mAppOpsHelper); mLocationUsageLogger = new LocationUsageLogger(); Loading Loading @@ -1429,11 +1466,6 @@ public class LocationManagerService extends ILocationManager.Stub { return mEmergencyCallHelper; } @Override public LocationEventLog getLocationEventLog() { return mLocationEventLog; } @Override public LocationUsageLogger getLocationUsageLogger() { return mLocationUsageLogger; Loading services/core/java/com/android/server/location/eventlog/LocalEventLog.java +56 −74 Original line number Diff line number Diff line Loading @@ -16,12 +16,13 @@ package com.android.server.location.eventlog; import android.annotation.Nullable; import android.os.SystemClock; import android.util.TimeUtils; import com.android.internal.util.Preconditions; import java.util.ListIterator; import java.util.Iterator; import java.util.NoSuchElementException; import java.util.function.Consumer; Loading @@ -35,6 +36,7 @@ public abstract class LocalEventLog { boolean isFiller(); long getTimeDeltaMs(); String getLogString(); boolean filter(@Nullable String filter); } private static final class FillerEvent implements Log { Loading Loading @@ -62,6 +64,11 @@ public abstract class LocalEventLog { public String getLogString() { throw new AssertionError(); } @Override public boolean filter(String filter) { return false; } } /** Loading @@ -87,6 +94,11 @@ public abstract class LocalEventLog { public final long getTimeDeltaMs() { return Integer.toUnsignedLong(mTimeDelta); } @Override public boolean filter(String filter) { return false; } } // circular buffer of log entries Loading Loading @@ -198,6 +210,17 @@ public abstract class LocalEventLog { } } /** * Iterates over the event log, passing each filter-matching log string to the given * consumer. */ public synchronized void iterate(String filter, Consumer<String> consumer) { LogIterator it = new LogIterator(filter); while (it.hasNext()) { consumer.accept(it.next()); } } // returns the index of the first element private int startIndex() { return wrapIndex(mLogEndIndex - mLogSize); Loading @@ -205,12 +228,13 @@ public abstract class LocalEventLog { // returns the index after this one private int incrementIndex(int index) { if (index == -1) { return startIndex(); } else if (index >= 0) { return wrapIndex(index + 1); } else { throw new IllegalArgumentException(); } // returns the index before this one private int decrementIndex(int index) { return wrapIndex(index - 1); } // rolls over the given index if necessary Loading @@ -219,7 +243,9 @@ public abstract class LocalEventLog { return (index % mLog.length + mLog.length) % mLog.length; } private class LogIterator implements ListIterator<String> { private class LogIterator implements Iterator<String> { private final @Nullable String mFilter; private final long mSystemTimeDeltaMs; Loading @@ -228,10 +254,17 @@ public abstract class LocalEventLog { private int mCount; LogIterator() { this(null); } LogIterator(@Nullable String filter) { mFilter = filter; mSystemTimeDeltaMs = System.currentTimeMillis() - SystemClock.elapsedRealtime(); mCurrentRealtimeMs = mStartRealtimeMs; mIndex = startIndex(); mCount = 0; mIndex = -1; mCount = -1; increment(); } @Override Loading @@ -239,75 +272,17 @@ public abstract class LocalEventLog { return mCount < mLogSize; } @Override public boolean hasPrevious() { return mCount > 0; } @Override // return then increment public String next() { if (!hasNext()) { throw new NoSuchElementException(); } Log log = mLog[mIndex]; long nextDeltaMs = log.getTimeDeltaMs(); long realtimeMs = mCurrentRealtimeMs + nextDeltaMs; long timeMs = mCurrentRealtimeMs + log.getTimeDeltaMs() + mSystemTimeDeltaMs; // calculate next index, skipping filler events do { mCurrentRealtimeMs += nextDeltaMs; mIndex = incrementIndex(mIndex); if (++mCount < mLogSize) { nextDeltaMs = mLog[mIndex].getTimeDeltaMs(); } } while (mCount < mLogSize && mLog[mIndex].isFiller()); increment(); return getTimePrefix(realtimeMs + mSystemTimeDeltaMs) + log.getLogString(); } @Override // decrement then return public String previous() { Log log; long currentDeltaMs; long realtimeMs; // calculate previous index, skipping filler events with MAX_TIME_DELTA do { if (!hasPrevious()) { throw new NoSuchElementException(); } mIndex = decrementIndex(mIndex); mCount--; log = mLog[mIndex]; realtimeMs = mCurrentRealtimeMs; if (mCount > 0) { currentDeltaMs = log.getTimeDeltaMs(); mCurrentRealtimeMs -= currentDeltaMs; } } while (mCount >= 0 && log.isFiller()); return getTimePrefix(realtimeMs + mSystemTimeDeltaMs) + log.getLogString(); } @Override public int nextIndex() { throw new UnsupportedOperationException(); } @Override public int previousIndex() { throw new UnsupportedOperationException(); } @Override public void add(String s) { throw new UnsupportedOperationException(); return getTimePrefix(timeMs) + log.getLogString(); } @Override Loading @@ -315,9 +290,16 @@ public abstract class LocalEventLog { throw new UnsupportedOperationException(); } @Override public void set(String s) { throw new UnsupportedOperationException(); private void increment() { long nextDeltaMs = mIndex == -1 ? 0 : mLog[mIndex].getTimeDeltaMs(); do { mCurrentRealtimeMs += nextDeltaMs; mIndex = incrementIndex(mIndex); if (++mCount < mLogSize) { nextDeltaMs = mLog[mIndex].getTimeDeltaMs(); } } while (mCount < mLogSize && (mLog[mIndex].isFiller() || (mFilter != null && !mLog[mIndex].filter(mFilter)))); } } } Loading services/core/java/com/android/server/location/injector/LocationEventLog.java→services/core/java/com/android/server/location/eventlog/LocationEventLog.java +209 −31 File changed and moved.Preview size limit exceeded, changes collapsed. Show changes services/core/java/com/android/server/location/injector/Injector.java +0 −3 Original line number Diff line number Diff line Loading @@ -56,7 +56,4 @@ public interface Injector { /** Returns a LocationUsageLogger. */ LocationUsageLogger getLocationUsageLogger(); /** Returns a LocationEventLog. */ LocationEventLog getLocationEventLog(); } services/core/java/com/android/server/location/injector/LocationPowerSaveModeHelper.java +2 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,8 @@ import static com.android.server.location.LocationManagerService.TAG; import android.os.PowerManager.LocationPowerSaveMode; import android.util.Log; import com.android.server.location.eventlog.LocationEventLog; import java.util.concurrent.CopyOnWriteArrayList; /** Loading Loading
services/core/java/com/android/server/location/LocationManagerService.java +58 −26 Original line number Diff line number Diff line Loading @@ -79,6 +79,7 @@ import android.os.UserHandle; import android.os.WorkSource; import android.os.WorkSource.WorkChain; import android.stats.location.LocationStatsEnums; import android.util.ArrayMap; import android.util.IndentingPrintWriter; import android.util.Log; Loading @@ -87,6 +88,7 @@ import com.android.internal.util.DumpUtils; import com.android.internal.util.Preconditions; import com.android.server.LocalServices; import com.android.server.SystemService; import com.android.server.location.eventlog.LocationEventLog; import com.android.server.location.geofence.GeofenceManager; import com.android.server.location.geofence.GeofenceProxy; import com.android.server.location.gnss.GnssConfiguration; Loading @@ -98,7 +100,6 @@ import com.android.server.location.injector.AppOpsHelper; import com.android.server.location.injector.EmergencyHelper; import com.android.server.location.injector.Injector; import com.android.server.location.injector.LocationAttributionHelper; import com.android.server.location.injector.LocationEventLog; import com.android.server.location.injector.LocationPermissionsHelper; import com.android.server.location.injector.LocationPowerSaveModeHelper; import com.android.server.location.injector.LocationUsageLogger; Loading Loading @@ -147,9 +148,10 @@ public class LocationManagerService extends ILocationManager.Stub { public Lifecycle(Context context) { super(context); LocationEventLog eventLog = new LocationEventLog(); mUserInfoHelper = new LifecycleUserInfoHelper(context); mSystemInjector = new SystemInjector(context, mUserInfoHelper); mService = new LocationManagerService(context, mSystemInjector); mSystemInjector = new SystemInjector(context, mUserInfoHelper, eventLog); mService = new LocationManagerService(context, mSystemInjector, eventLog); } @Override Loading @@ -159,7 +161,7 @@ public class LocationManagerService extends ILocationManager.Stub { // client caching behavior is only enabled after seeing the first invalidate LocationManager.invalidateLocalLocationEnabledCaches(); // disable caching for our own process Objects.requireNonNull(mService.mContext.getSystemService(LocationManager.class)) Objects.requireNonNull(getContext().getSystemService(LocationManager.class)) .disableLocalLocationEnabledCaches(); } Loading Loading @@ -221,6 +223,7 @@ public class LocationManagerService extends ILocationManager.Stub { private final Context mContext; private final Injector mInjector; private final LocationEventLog mEventLog; private final LocalService mLocalService; private final GeofenceManager mGeofenceManager; Loading @@ -245,10 +248,10 @@ public class LocationManagerService extends ILocationManager.Stub { private final CopyOnWriteArrayList<LocationProviderManager> mProviderManagers = new CopyOnWriteArrayList<>(); LocationManagerService(Context context, Injector injector) { LocationManagerService(Context context, Injector injector, LocationEventLog eventLog) { mContext = context.createAttributionContext(ATTRIBUTION_TAG); mInjector = injector; mEventLog = eventLog; mLocalService = new LocalService(); LocalServices.addService(LocationManagerInternal.class, mLocalService); Loading @@ -256,7 +259,7 @@ public class LocationManagerService extends ILocationManager.Stub { // set up passive provider first since it will be required for all other location providers, // which are loaded later once the system is ready. mPassiveManager = new PassiveLocationProviderManager(mContext, injector); mPassiveManager = new PassiveLocationProviderManager(mContext, injector, mEventLog); addLocationProviderManager(mPassiveManager, new PassiveLocationProvider(mContext)); // TODO: load the gps provider here as well, which will require refactoring Loading Loading @@ -297,7 +300,7 @@ public class LocationManagerService extends ILocationManager.Stub { } LocationProviderManager manager = new LocationProviderManager(mContext, mInjector, providerName, mPassiveManager); mEventLog, providerName, mPassiveManager); addLocationProviderManager(manager, null); return manager; } Loading Loading @@ -341,7 +344,7 @@ public class LocationManagerService extends ILocationManager.Stub { com.android.internal.R.string.config_networkLocationProviderPackageName); if (networkProvider != null) { LocationProviderManager networkManager = new LocationProviderManager(mContext, mInjector, NETWORK_PROVIDER, mPassiveManager); mInjector, mEventLog, NETWORK_PROVIDER, mPassiveManager); addLocationProviderManager(networkManager, networkProvider); } else { Log.w(TAG, "no network location provider found"); Loading @@ -360,7 +363,7 @@ public class LocationManagerService extends ILocationManager.Stub { com.android.internal.R.string.config_fusedLocationProviderPackageName); if (fusedProvider != null) { LocationProviderManager fusedManager = new LocationProviderManager(mContext, mInjector, FUSED_PROVIDER, mPassiveManager); mEventLog, FUSED_PROVIDER, mPassiveManager); addLocationProviderManager(fusedManager, fusedProvider); } else { Log.wtf(TAG, "no fused location provider found"); Loading @@ -375,7 +378,7 @@ public class LocationManagerService extends ILocationManager.Stub { mGnssManagerService.onSystemReady(); LocationProviderManager gnssManager = new LocationProviderManager(mContext, mInjector, GPS_PROVIDER, mPassiveManager); mEventLog, GPS_PROVIDER, mPassiveManager); addLocationProviderManager(gnssManager, mGnssManagerService.getGnssLocationProvider()); } Loading Loading @@ -431,7 +434,7 @@ public class LocationManagerService extends ILocationManager.Stub { Log.d(TAG, "[u" + userId + "] location enabled = " + enabled); } mInjector.getLocationEventLog().logLocationEnabled(userId, enabled); mEventLog.logLocationEnabled(userId, enabled); Intent intent = new Intent(LocationManager.MODE_CHANGED_ACTION) .putExtra(LocationManager.EXTRA_LOCATION_ENABLED, enabled) Loading Loading @@ -1193,10 +1196,28 @@ public class LocationManagerService extends ILocationManager.Stub { IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " "); if (mGnssManagerService != null && args.length > 0 && args[0].equals("--gnssmetrics")) { if (args.length > 0) { LocationProviderManager manager = getLocationProviderManager(args[0]); if (manager != null) { ipw.println("Provider:"); ipw.increaseIndent(); manager.dump(fd, ipw, args); ipw.decreaseIndent(); ipw.println("Event Log:"); ipw.increaseIndent(); mEventLog.iterate(manager.getName(), ipw::println); ipw.decreaseIndent(); return; } if ("--gnssmetrics".equals(args[0])) { if (mGnssManagerService != null) { mGnssManagerService.dump(fd, ipw, args); } return; } } ipw.println("Location Manager State:"); ipw.increaseIndent(); Loading Loading @@ -1227,6 +1248,25 @@ public class LocationManagerService extends ILocationManager.Stub { } ipw.decreaseIndent(); ipw.println("Historical Aggregate Location Provider Data:"); ipw.increaseIndent(); ArrayMap<String, ArrayMap<String, LocationEventLog.AggregateStats>> aggregateStats = mEventLog.copyAggregateStats(); for (int i = 0; i < aggregateStats.size(); i++) { ipw.println(aggregateStats.keyAt(i)); ipw.increaseIndent(); ArrayMap<String, LocationEventLog.AggregateStats> providerStats = aggregateStats.valueAt(i); for (int j = 0; j < providerStats.size(); j++) { ipw.print(providerStats.keyAt(j)); ipw.print(": "); providerStats.valueAt(j).updateTotals(); ipw.println(providerStats.valueAt(j)); } ipw.decreaseIndent(); } ipw.decreaseIndent(); if (mGnssManagerService != null) { ipw.println("GNSS Manager:"); ipw.increaseIndent(); Loading @@ -1241,7 +1281,7 @@ public class LocationManagerService extends ILocationManager.Stub { ipw.println("Event Log:"); ipw.increaseIndent(); mInjector.getLocationEventLog().iterate(ipw::println); mEventLog.iterate(ipw::println); ipw.decreaseIndent(); } Loading Loading @@ -1320,7 +1360,6 @@ public class LocationManagerService extends ILocationManager.Stub { private final Context mContext; private final UserInfoHelper mUserInfoHelper; private final LocationEventLog mLocationEventLog; private final AlarmHelper mAlarmHelper; private final SystemAppOpsHelper mAppOpsHelper; private final SystemLocationPermissionsHelper mLocationPermissionsHelper; Loading @@ -1339,19 +1378,17 @@ public class LocationManagerService extends ILocationManager.Stub { @GuardedBy("this") private boolean mSystemReady; SystemInjector(Context context, UserInfoHelper userInfoHelper) { SystemInjector(Context context, UserInfoHelper userInfoHelper, LocationEventLog eventLog) { mContext = context; mUserInfoHelper = userInfoHelper; mLocationEventLog = new LocationEventLog(); mAlarmHelper = new SystemAlarmHelper(context); mAppOpsHelper = new SystemAppOpsHelper(context); mLocationPermissionsHelper = new SystemLocationPermissionsHelper(context, mAppOpsHelper); mSettingsHelper = new SystemSettingsHelper(context); mAppForegroundHelper = new SystemAppForegroundHelper(context); mLocationPowerSaveModeHelper = new SystemLocationPowerSaveModeHelper(context, mLocationEventLog); mLocationPowerSaveModeHelper = new SystemLocationPowerSaveModeHelper(context, eventLog); mScreenInteractiveHelper = new SystemScreenInteractiveHelper(context); mLocationAttributionHelper = new LocationAttributionHelper(mAppOpsHelper); mLocationUsageLogger = new LocationUsageLogger(); Loading Loading @@ -1429,11 +1466,6 @@ public class LocationManagerService extends ILocationManager.Stub { return mEmergencyCallHelper; } @Override public LocationEventLog getLocationEventLog() { return mLocationEventLog; } @Override public LocationUsageLogger getLocationUsageLogger() { return mLocationUsageLogger; Loading
services/core/java/com/android/server/location/eventlog/LocalEventLog.java +56 −74 Original line number Diff line number Diff line Loading @@ -16,12 +16,13 @@ package com.android.server.location.eventlog; import android.annotation.Nullable; import android.os.SystemClock; import android.util.TimeUtils; import com.android.internal.util.Preconditions; import java.util.ListIterator; import java.util.Iterator; import java.util.NoSuchElementException; import java.util.function.Consumer; Loading @@ -35,6 +36,7 @@ public abstract class LocalEventLog { boolean isFiller(); long getTimeDeltaMs(); String getLogString(); boolean filter(@Nullable String filter); } private static final class FillerEvent implements Log { Loading Loading @@ -62,6 +64,11 @@ public abstract class LocalEventLog { public String getLogString() { throw new AssertionError(); } @Override public boolean filter(String filter) { return false; } } /** Loading @@ -87,6 +94,11 @@ public abstract class LocalEventLog { public final long getTimeDeltaMs() { return Integer.toUnsignedLong(mTimeDelta); } @Override public boolean filter(String filter) { return false; } } // circular buffer of log entries Loading Loading @@ -198,6 +210,17 @@ public abstract class LocalEventLog { } } /** * Iterates over the event log, passing each filter-matching log string to the given * consumer. */ public synchronized void iterate(String filter, Consumer<String> consumer) { LogIterator it = new LogIterator(filter); while (it.hasNext()) { consumer.accept(it.next()); } } // returns the index of the first element private int startIndex() { return wrapIndex(mLogEndIndex - mLogSize); Loading @@ -205,12 +228,13 @@ public abstract class LocalEventLog { // returns the index after this one private int incrementIndex(int index) { if (index == -1) { return startIndex(); } else if (index >= 0) { return wrapIndex(index + 1); } else { throw new IllegalArgumentException(); } // returns the index before this one private int decrementIndex(int index) { return wrapIndex(index - 1); } // rolls over the given index if necessary Loading @@ -219,7 +243,9 @@ public abstract class LocalEventLog { return (index % mLog.length + mLog.length) % mLog.length; } private class LogIterator implements ListIterator<String> { private class LogIterator implements Iterator<String> { private final @Nullable String mFilter; private final long mSystemTimeDeltaMs; Loading @@ -228,10 +254,17 @@ public abstract class LocalEventLog { private int mCount; LogIterator() { this(null); } LogIterator(@Nullable String filter) { mFilter = filter; mSystemTimeDeltaMs = System.currentTimeMillis() - SystemClock.elapsedRealtime(); mCurrentRealtimeMs = mStartRealtimeMs; mIndex = startIndex(); mCount = 0; mIndex = -1; mCount = -1; increment(); } @Override Loading @@ -239,75 +272,17 @@ public abstract class LocalEventLog { return mCount < mLogSize; } @Override public boolean hasPrevious() { return mCount > 0; } @Override // return then increment public String next() { if (!hasNext()) { throw new NoSuchElementException(); } Log log = mLog[mIndex]; long nextDeltaMs = log.getTimeDeltaMs(); long realtimeMs = mCurrentRealtimeMs + nextDeltaMs; long timeMs = mCurrentRealtimeMs + log.getTimeDeltaMs() + mSystemTimeDeltaMs; // calculate next index, skipping filler events do { mCurrentRealtimeMs += nextDeltaMs; mIndex = incrementIndex(mIndex); if (++mCount < mLogSize) { nextDeltaMs = mLog[mIndex].getTimeDeltaMs(); } } while (mCount < mLogSize && mLog[mIndex].isFiller()); increment(); return getTimePrefix(realtimeMs + mSystemTimeDeltaMs) + log.getLogString(); } @Override // decrement then return public String previous() { Log log; long currentDeltaMs; long realtimeMs; // calculate previous index, skipping filler events with MAX_TIME_DELTA do { if (!hasPrevious()) { throw new NoSuchElementException(); } mIndex = decrementIndex(mIndex); mCount--; log = mLog[mIndex]; realtimeMs = mCurrentRealtimeMs; if (mCount > 0) { currentDeltaMs = log.getTimeDeltaMs(); mCurrentRealtimeMs -= currentDeltaMs; } } while (mCount >= 0 && log.isFiller()); return getTimePrefix(realtimeMs + mSystemTimeDeltaMs) + log.getLogString(); } @Override public int nextIndex() { throw new UnsupportedOperationException(); } @Override public int previousIndex() { throw new UnsupportedOperationException(); } @Override public void add(String s) { throw new UnsupportedOperationException(); return getTimePrefix(timeMs) + log.getLogString(); } @Override Loading @@ -315,9 +290,16 @@ public abstract class LocalEventLog { throw new UnsupportedOperationException(); } @Override public void set(String s) { throw new UnsupportedOperationException(); private void increment() { long nextDeltaMs = mIndex == -1 ? 0 : mLog[mIndex].getTimeDeltaMs(); do { mCurrentRealtimeMs += nextDeltaMs; mIndex = incrementIndex(mIndex); if (++mCount < mLogSize) { nextDeltaMs = mLog[mIndex].getTimeDeltaMs(); } } while (mCount < mLogSize && (mLog[mIndex].isFiller() || (mFilter != null && !mLog[mIndex].filter(mFilter)))); } } } Loading
services/core/java/com/android/server/location/injector/LocationEventLog.java→services/core/java/com/android/server/location/eventlog/LocationEventLog.java +209 −31 File changed and moved.Preview size limit exceeded, changes collapsed. Show changes
services/core/java/com/android/server/location/injector/Injector.java +0 −3 Original line number Diff line number Diff line Loading @@ -56,7 +56,4 @@ public interface Injector { /** Returns a LocationUsageLogger. */ LocationUsageLogger getLocationUsageLogger(); /** Returns a LocationEventLog. */ LocationEventLog getLocationEventLog(); }
services/core/java/com/android/server/location/injector/LocationPowerSaveModeHelper.java +2 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,8 @@ import static com.android.server.location.LocationManagerService.TAG; import android.os.PowerManager.LocationPowerSaveMode; import android.util.Log; import com.android.server.location.eventlog.LocationEventLog; import java.util.concurrent.CopyOnWriteArrayList; /** Loading