Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2727a913 authored by Soonil Nagarkar's avatar Soonil Nagarkar Committed by Android (Google) Code Review
Browse files

Merge "Implement stationary location throttling" into sc-dev

parents 1792b2e7 9627429f
Loading
Loading
Loading
Loading
+7 −0
Original line number Original line Diff line number Diff line
@@ -10779,6 +10779,13 @@ public final class Settings {
        public static final String LOCATION_IGNORE_SETTINGS_PACKAGE_WHITELIST =
        public static final String LOCATION_IGNORE_SETTINGS_PACKAGE_WHITELIST =
                "location_ignore_settings_package_whitelist";
                "location_ignore_settings_package_whitelist";
        /**
         * Whether to throttle location when the device is in doze and still.
         * @hide
         */
        public static final String LOCATION_ENABLE_STATIONARY_THROTTLE =
                "location_enable_stationary_throttle";
        /**
        /**
        * Whether TV will switch to MHL port when a mobile device is plugged in.
        * Whether TV will switch to MHL port when a mobile device is plugged in.
        * (0 = false, 1 = true)
        * (0 = false, 1 = true)
+6 −1
Original line number Original line Diff line number Diff line
@@ -569,7 +569,12 @@ public class Location implements Parcelable {


    /** @hide */
    /** @hide */
    public long getElapsedRealtimeAgeMillis() {
    public long getElapsedRealtimeAgeMillis() {
        return NANOSECONDS.toMillis(getElapsedRealtimeAgeNanos());
        return getElapsedRealtimeAgeMillis(SystemClock.elapsedRealtime());
    }

    /** @hide */
    public long getElapsedRealtimeAgeMillis(long referenceRealtimeMs) {
        return referenceRealtimeMs - NANOSECONDS.toMillis(mElapsedRealtimeNanos);
    }
    }


    /**
    /**
+1 −0
Original line number Original line Diff line number Diff line
@@ -323,6 +323,7 @@ public class SettingsBackupTest {
                    Settings.Global.LOCATION_BACKGROUND_THROTTLE_INTERVAL_MS,
                    Settings.Global.LOCATION_BACKGROUND_THROTTLE_INTERVAL_MS,
                    Settings.Global.LOCATION_BACKGROUND_THROTTLE_PROXIMITY_ALERT_INTERVAL_MS,
                    Settings.Global.LOCATION_BACKGROUND_THROTTLE_PROXIMITY_ALERT_INTERVAL_MS,
                    Settings.Global.LOCATION_BACKGROUND_THROTTLE_PACKAGE_WHITELIST,
                    Settings.Global.LOCATION_BACKGROUND_THROTTLE_PACKAGE_WHITELIST,
                    Settings.Global.LOCATION_ENABLE_STATIONARY_THROTTLE,
                    Settings.Global.LOCATION_IGNORE_SETTINGS_PACKAGE_WHITELIST,
                    Settings.Global.LOCATION_IGNORE_SETTINGS_PACKAGE_WHITELIST,
                    Settings.Global.LOCATION_SETTINGS_LINK_TO_PERMISSIONS_ENABLED,
                    Settings.Global.LOCATION_SETTINGS_LINK_TO_PERMISSIONS_ENABLED,
                    Settings.Global.LOCK_SOUND,
                    Settings.Global.LOCK_SOUND,
+32 −0
Original line number Original line Diff line number Diff line
@@ -78,6 +78,7 @@ import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserHandle;
import android.os.WorkSource;
import android.os.WorkSource;
import android.os.WorkSource.WorkChain;
import android.os.WorkSource.WorkChain;
import android.provider.Settings;
import android.stats.location.LocationStatsEnums;
import android.stats.location.LocationStatsEnums;
import android.util.ArrayMap;
import android.util.ArrayMap;
import android.util.IndentingPrintWriter;
import android.util.IndentingPrintWriter;
@@ -97,6 +98,8 @@ import com.android.server.location.gnss.hal.GnssNative;
import com.android.server.location.injector.AlarmHelper;
import com.android.server.location.injector.AlarmHelper;
import com.android.server.location.injector.AppForegroundHelper;
import com.android.server.location.injector.AppForegroundHelper;
import com.android.server.location.injector.AppOpsHelper;
import com.android.server.location.injector.AppOpsHelper;
import com.android.server.location.injector.DeviceIdleHelper;
import com.android.server.location.injector.DeviceStationaryHelper;
import com.android.server.location.injector.EmergencyHelper;
import com.android.server.location.injector.EmergencyHelper;
import com.android.server.location.injector.Injector;
import com.android.server.location.injector.Injector;
import com.android.server.location.injector.LocationAttributionHelper;
import com.android.server.location.injector.LocationAttributionHelper;
@@ -108,6 +111,8 @@ import com.android.server.location.injector.SettingsHelper;
import com.android.server.location.injector.SystemAlarmHelper;
import com.android.server.location.injector.SystemAlarmHelper;
import com.android.server.location.injector.SystemAppForegroundHelper;
import com.android.server.location.injector.SystemAppForegroundHelper;
import com.android.server.location.injector.SystemAppOpsHelper;
import com.android.server.location.injector.SystemAppOpsHelper;
import com.android.server.location.injector.SystemDeviceIdleHelper;
import com.android.server.location.injector.SystemDeviceStationaryHelper;
import com.android.server.location.injector.SystemEmergencyHelper;
import com.android.server.location.injector.SystemEmergencyHelper;
import com.android.server.location.injector.SystemLocationPermissionsHelper;
import com.android.server.location.injector.SystemLocationPermissionsHelper;
import com.android.server.location.injector.SystemLocationPowerSaveModeHelper;
import com.android.server.location.injector.SystemLocationPowerSaveModeHelper;
@@ -120,6 +125,7 @@ import com.android.server.location.provider.LocationProviderManager;
import com.android.server.location.provider.MockLocationProvider;
import com.android.server.location.provider.MockLocationProvider;
import com.android.server.location.provider.PassiveLocationProvider;
import com.android.server.location.provider.PassiveLocationProvider;
import com.android.server.location.provider.PassiveLocationProviderManager;
import com.android.server.location.provider.PassiveLocationProviderManager;
import com.android.server.location.provider.StationaryThrottlingLocationProvider;
import com.android.server.location.provider.proxy.ProxyLocationProvider;
import com.android.server.location.provider.proxy.ProxyLocationProvider;
import com.android.server.pm.permission.LegacyPermissionManagerInternal;
import com.android.server.pm.permission.LegacyPermissionManagerInternal;


@@ -313,6 +319,18 @@ public class LocationManagerService extends ILocationManager.Stub {


            manager.startManager();
            manager.startManager();
            if (realProvider != null) {
            if (realProvider != null) {

                // custom logic wrapping all non-passive providers
                if (manager != mPassiveManager) {
                    boolean enableStationaryThrottling = Settings.Global.getInt(
                            mContext.getContentResolver(),
                            Settings.Global.LOCATION_ENABLE_STATIONARY_THROTTLE, 1) != 0;
                    if (enableStationaryThrottling) {
                        realProvider = new StationaryThrottlingLocationProvider(manager.getName(),
                                mInjector, realProvider, mEventLog);
                    }
                }

                manager.setRealProvider(realProvider);
                manager.setRealProvider(realProvider);
            }
            }
            mProviderManagers.add(manager);
            mProviderManagers.add(manager);
@@ -1368,6 +1386,8 @@ public class LocationManagerService extends ILocationManager.Stub {
        private final SystemAppForegroundHelper mAppForegroundHelper;
        private final SystemAppForegroundHelper mAppForegroundHelper;
        private final SystemLocationPowerSaveModeHelper mLocationPowerSaveModeHelper;
        private final SystemLocationPowerSaveModeHelper mLocationPowerSaveModeHelper;
        private final SystemScreenInteractiveHelper mScreenInteractiveHelper;
        private final SystemScreenInteractiveHelper mScreenInteractiveHelper;
        private final SystemDeviceStationaryHelper mDeviceStationaryHelper;
        private final SystemDeviceIdleHelper mDeviceIdleHelper;
        private final LocationAttributionHelper mLocationAttributionHelper;
        private final LocationAttributionHelper mLocationAttributionHelper;
        private final LocationUsageLogger mLocationUsageLogger;
        private final LocationUsageLogger mLocationUsageLogger;


@@ -1391,6 +1411,8 @@ public class LocationManagerService extends ILocationManager.Stub {
            mAppForegroundHelper = new SystemAppForegroundHelper(context);
            mAppForegroundHelper = new SystemAppForegroundHelper(context);
            mLocationPowerSaveModeHelper = new SystemLocationPowerSaveModeHelper(context, eventLog);
            mLocationPowerSaveModeHelper = new SystemLocationPowerSaveModeHelper(context, eventLog);
            mScreenInteractiveHelper = new SystemScreenInteractiveHelper(context);
            mScreenInteractiveHelper = new SystemScreenInteractiveHelper(context);
            mDeviceStationaryHelper = new SystemDeviceStationaryHelper();
            mDeviceIdleHelper = new SystemDeviceIdleHelper(context);
            mLocationAttributionHelper = new LocationAttributionHelper(mAppOpsHelper);
            mLocationAttributionHelper = new LocationAttributionHelper(mAppOpsHelper);
            mLocationUsageLogger = new LocationUsageLogger();
            mLocationUsageLogger = new LocationUsageLogger();
        }
        }
@@ -1450,6 +1472,16 @@ public class LocationManagerService extends ILocationManager.Stub {
            return mScreenInteractiveHelper;
            return mScreenInteractiveHelper;
        }
        }


        @Override
        public DeviceStationaryHelper getDeviceStationaryHelper() {
            return mDeviceStationaryHelper;
        }

        @Override
        public DeviceIdleHelper getDeviceIdleHelper() {
            return mDeviceIdleHelper;
        }

        @Override
        @Override
        public LocationAttributionHelper getLocationAttributionHelper() {
        public LocationAttributionHelper getLocationAttributionHelper() {
            return mLocationAttributionHelper;
            return mLocationAttributionHelper;
+27 −1
Original line number Original line Diff line number Diff line
@@ -60,7 +60,8 @@ public class LocationEventLog extends LocalEventLog {
    private static final int EVENT_PROVIDER_UPDATE_REQUEST = 6;
    private static final int EVENT_PROVIDER_UPDATE_REQUEST = 6;
    private static final int EVENT_PROVIDER_RECEIVE_LOCATION = 7;
    private static final int EVENT_PROVIDER_RECEIVE_LOCATION = 7;
    private static final int EVENT_PROVIDER_DELIVER_LOCATION = 8;
    private static final int EVENT_PROVIDER_DELIVER_LOCATION = 8;
    private static final int EVENT_LOCATION_POWER_SAVE_MODE_CHANGE = 9;
    private static final int EVENT_PROVIDER_STATIONARY_THROTTLED = 9;
    private static final int EVENT_LOCATION_POWER_SAVE_MODE_CHANGE = 10;


    @GuardedBy("mAggregateStats")
    @GuardedBy("mAggregateStats")
    private final ArrayMap<String, ArrayMap<String, AggregateStats>> mAggregateStats;
    private final ArrayMap<String, ArrayMap<String, AggregateStats>> mAggregateStats;
@@ -167,6 +168,11 @@ public class LocationEventLog extends LocalEventLog {
        getAggregateStats(provider, identity.getPackageName()).markLocationDelivered();
        getAggregateStats(provider, identity.getPackageName()).markLocationDelivered();
    }
    }


    /** Logs that a provider has entered or exited stationary throttling. */
    public void logProviderStationaryThrottled(String provider, boolean throttled) {
        addLogEvent(EVENT_PROVIDER_STATIONARY_THROTTLED, provider, throttled);
    }

    /** Logs that the location power save mode has changed. */
    /** Logs that the location power save mode has changed. */
    public void logLocationPowerSaveMode(
    public void logLocationPowerSaveMode(
            @LocationPowerSaveMode int locationPowerSaveMode) {
            @LocationPowerSaveMode int locationPowerSaveMode) {
@@ -198,6 +204,9 @@ public class LocationEventLog extends LocalEventLog {
            case EVENT_PROVIDER_DELIVER_LOCATION:
            case EVENT_PROVIDER_DELIVER_LOCATION:
                return new ProviderDeliverLocationEvent(timeDelta, (String) args[0],
                return new ProviderDeliverLocationEvent(timeDelta, (String) args[0],
                        (Integer) args[1], (CallerIdentity) args[2]);
                        (Integer) args[1], (CallerIdentity) args[2]);
            case EVENT_PROVIDER_STATIONARY_THROTTLED:
                return new ProviderStationaryThrottledEvent(timeDelta, (String) args[0],
                        (Boolean) args[1]);
            case EVENT_LOCATION_POWER_SAVE_MODE_CHANGE:
            case EVENT_LOCATION_POWER_SAVE_MODE_CHANGE:
                return new LocationPowerSaveModeEvent(timeDelta, (Integer) args[0]);
                return new LocationPowerSaveModeEvent(timeDelta, (Integer) args[0]);
            default:
            default:
@@ -332,6 +341,23 @@ public class LocationEventLog extends LocalEventLog {
        }
        }
    }
    }


    private static final class ProviderStationaryThrottledEvent extends ProviderEvent {

        private final boolean mStationaryThrottled;

        private ProviderStationaryThrottledEvent(long timeDelta, String provider,
                boolean stationaryThrottled) {
            super(timeDelta, provider);
            mStationaryThrottled = stationaryThrottled;
        }

        @Override
        public String getLogString() {
            return mProvider + " provider stationary/idle " + (mStationaryThrottled ? "throttled"
                    : "unthrottled");
        }
    }

    private static final class LocationPowerSaveModeEvent extends LogEvent {
    private static final class LocationPowerSaveModeEvent extends LogEvent {


        @LocationPowerSaveMode
        @LocationPowerSaveMode
Loading