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

Commit 2307be9c authored by Lifu Tang's avatar Lifu Tang Committed by android-build-merger
Browse files

Merge "Throttle location update rate in proximity alert" into oc-dev

am: 23a66d44

Change-Id: Ie3ece0718017984004ef4fd8303a730c47bd8907
parents ed6ebc5b 23a66d44
Loading
Loading
Loading
Loading
+8 −0
Original line number Original line Diff line number Diff line
@@ -7716,6 +7716,14 @@ public final class Settings {
       public static final String LOCATION_BACKGROUND_THROTTLE_INTERVAL_MS =
       public static final String LOCATION_BACKGROUND_THROTTLE_INTERVAL_MS =
                "location_background_throttle_interval_ms";
                "location_background_throttle_interval_ms";


        /**
         * Most frequent location update interval in milliseconds that proximity alert is allowed
         * to request.
         * @hide
         */
        public static final String LOCATION_BACKGROUND_THROTTLE_PROXIMITY_ALERT_INTERVAL_MS =
                "location_background_throttle_proximity_alert_interval_ms";

        /**
        /**
         * Packages that are whitelisted for background throttling (throttling will not be applied).
         * Packages that are whitelisted for background throttling (throttling will not be applied).
         * @hide
         * @hide
+1 −0
Original line number Original line Diff line number Diff line
@@ -213,6 +213,7 @@ public class SettingsBackupTest {
                    Settings.Global.LANG_ID_UPDATE_CONTENT_URL,
                    Settings.Global.LANG_ID_UPDATE_CONTENT_URL,
                    Settings.Global.LANG_ID_UPDATE_METADATA_URL,
                    Settings.Global.LANG_ID_UPDATE_METADATA_URL,
                    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_PACKAGE_WHITELIST,
                    Settings.Global.LOCATION_BACKGROUND_THROTTLE_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,
+36 −4
Original line number Original line Diff line number Diff line
@@ -23,8 +23,10 @@ import java.util.List;


import android.app.AppOpsManager;
import android.app.AppOpsManager;
import android.app.PendingIntent;
import android.app.PendingIntent;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.database.ContentObserver;
import android.location.Geofence;
import android.location.Geofence;
import android.location.Location;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationListener;
@@ -35,6 +37,8 @@ import android.os.Handler;
import android.os.Message;
import android.os.Message;
import android.os.PowerManager;
import android.os.PowerManager;
import android.os.SystemClock;
import android.os.SystemClock;
import android.os.UserHandle;
import android.provider.Settings;
import android.util.Slog;
import android.util.Slog;


import com.android.server.LocationManagerService;
import com.android.server.LocationManagerService;
@@ -58,9 +62,9 @@ public class GeofenceManager implements LocationListener, PendingIntent.OnFinish
    private static final long MAX_AGE_NANOS = 5 * 60 * 1000000000L; // five minutes
    private static final long MAX_AGE_NANOS = 5 * 60 * 1000000000L; // five minutes


    /**
    /**
     * Most frequent update interval allowed.
     * The default value of most frequent update interval allowed.
     */
     */
    private static final long MIN_INTERVAL_MS = 1 * 60 * 1000; // one minute
    private static final long DEFAULT_MIN_INTERVAL_MS = 30 * 60 * 1000; // 30 minutes


    /**
    /**
     * Least frequent update interval allowed.
     * Least frequent update interval allowed.
@@ -106,6 +110,12 @@ public class GeofenceManager implements LocationListener, PendingIntent.OnFinish
     */
     */
    private boolean mPendingUpdate;
    private boolean mPendingUpdate;


    /**
     * The actual value of most frequent update interval allowed.
     */
    private long mEffectiveMinIntervalMs;
    private ContentResolver mResolver;

    public GeofenceManager(Context context, LocationBlacklist blacklist) {
    public GeofenceManager(Context context, LocationBlacklist blacklist) {
        mContext = context;
        mContext = context;
        mLocationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
        mLocationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
@@ -114,6 +124,28 @@ public class GeofenceManager implements LocationListener, PendingIntent.OnFinish
        mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
        mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
        mHandler = new GeofenceHandler();
        mHandler = new GeofenceHandler();
        mBlacklist = blacklist;
        mBlacklist = blacklist;
        mResolver = mContext.getContentResolver();
        updateMinInterval();
        mResolver.registerContentObserver(
            Settings.Global.getUriFor(
                    Settings.Global.LOCATION_BACKGROUND_THROTTLE_PROXIMITY_ALERT_INTERVAL_MS),
            true,
            new ContentObserver(mHandler) {
                @Override
                public void onChange(boolean selfChange) {
                    synchronized (mLock) {
                        updateMinInterval();
                    }
                }
            }, UserHandle.USER_ALL);
    }

    /**
     * Updates the minimal location request frequency.
     */
    private void updateMinInterval() {
        mEffectiveMinIntervalMs = Settings.Global.getLong(mResolver,
                Settings.Global.LOCATION_BACKGROUND_THROTTLE_INTERVAL_MS, DEFAULT_MIN_INTERVAL_MS);
    }
    }


    public void addFence(LocationRequest request, Geofence geofence, PendingIntent intent,
    public void addFence(LocationRequest request, Geofence geofence, PendingIntent intent,
@@ -301,10 +333,10 @@ public class GeofenceManager implements LocationListener, PendingIntent.OnFinish
                // Compute a location update interval based on the distance to the nearest fence.
                // Compute a location update interval based on the distance to the nearest fence.
                long intervalMs;
                long intervalMs;
                if (location != null && Double.compare(minFenceDistance, Double.MAX_VALUE) != 0) {
                if (location != null && Double.compare(minFenceDistance, Double.MAX_VALUE) != 0) {
                    intervalMs = (long)Math.min(MAX_INTERVAL_MS, Math.max(MIN_INTERVAL_MS,
                    intervalMs = (long)Math.min(MAX_INTERVAL_MS, Math.max(mEffectiveMinIntervalMs,
                            minFenceDistance * 1000 / MAX_SPEED_M_S));
                            minFenceDistance * 1000 / MAX_SPEED_M_S));
                } else {
                } else {
                    intervalMs = MIN_INTERVAL_MS;
                    intervalMs = mEffectiveMinIntervalMs;
                }
                }
                if (!mReceivingLocationUpdates || mLocationUpdateInterval != intervalMs) {
                if (!mReceivingLocationUpdates || mLocationUpdateInterval != intervalMs) {
                    mReceivingLocationUpdates = true;
                    mReceivingLocationUpdates = true;