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

Commit df2c9247 authored by Soonil Nagarkar's avatar Soonil Nagarkar
Browse files

Add location PIs to temporary app whitelist

Allows location PI clients to start a FG service for some time after
receiving a location.

Test: none
Change-Id: I36bea3f2b5cd3f30db5998a1f1cbab7bbc874ec4
parent 96292972
Loading
Loading
Loading
Loading
+18 −6
Original line number Original line Diff line number Diff line
@@ -43,6 +43,7 @@ import static java.lang.Math.min;
import android.annotation.IntDef;
import android.annotation.IntDef;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.app.AlarmManager.OnAlarmListener;
import android.app.AlarmManager.OnAlarmListener;
import android.app.BroadcastOptions;
import android.app.PendingIntent;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
@@ -86,7 +87,6 @@ import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.Preconditions;
import com.android.internal.util.Preconditions;
import com.android.server.FgThread;
import com.android.server.FgThread;
import com.android.server.LocalServices;
import com.android.server.LocalServices;
import com.android.server.PendingIntentUtils;
import com.android.server.location.LocationPermissions;
import com.android.server.location.LocationPermissions;
import com.android.server.location.LocationPermissions.PermissionLevel;
import com.android.server.location.LocationPermissions.PermissionLevel;
import com.android.server.location.fudger.LocationFudger;
import com.android.server.location.fudger.LocationFudger;
@@ -131,6 +131,9 @@ public class LocationProviderManager extends
    private static final String WAKELOCK_TAG = "*location*";
    private static final String WAKELOCK_TAG = "*location*";
    private static final long WAKELOCK_TIMEOUT_MS = 30 * 1000;
    private static final long WAKELOCK_TIMEOUT_MS = 30 * 1000;


    // duration PI location clients are put on the allowlist to start a fg service
    private static final long TEMPORARY_APP_ALLOWLIST_DURATION_MS = 10 * 1000;

    // fastest interval at which clients may receive coarse locations
    // fastest interval at which clients may receive coarse locations
    private static final long MIN_COARSE_INTERVAL_MS = 10 * 60 * 1000;
    private static final long MIN_COARSE_INTERVAL_MS = 10 * 60 * 1000;


@@ -215,6 +218,11 @@ public class LocationProviderManager extends
        public void deliverOnLocationChanged(LocationResult locationResult,
        public void deliverOnLocationChanged(LocationResult locationResult,
                @Nullable Runnable onCompleteCallback)
                @Nullable Runnable onCompleteCallback)
                throws PendingIntent.CanceledException {
                throws PendingIntent.CanceledException {
            BroadcastOptions options = BroadcastOptions.makeBasic();
            options.setDontSendToRestrictedApps(true);
            // allows apps to start a fg service in response to a location PI
            options.setTemporaryAppWhitelistDuration(TEMPORARY_APP_ALLOWLIST_DURATION_MS);

            mPendingIntent.send(
            mPendingIntent.send(
                    mContext,
                    mContext,
                    0,
                    0,
@@ -225,22 +233,26 @@ public class LocationProviderManager extends
                            : null,
                            : null,
                    null,
                    null,
                    null,
                    null,
                    PendingIntentUtils.createDontSendToRestrictedAppsBundle(null));
                    options.toBundle());
        }
        }


        @Override
        @Override
        public void deliverOnFlushComplete(int requestCode) throws PendingIntent.CanceledException {
        public void deliverOnFlushComplete(int requestCode) throws PendingIntent.CanceledException {
            BroadcastOptions options = BroadcastOptions.makeBasic();
            options.setDontSendToRestrictedApps(true);

            mPendingIntent.send(mContext, 0, new Intent().putExtra(KEY_FLUSH_COMPLETE, requestCode),
            mPendingIntent.send(mContext, 0, new Intent().putExtra(KEY_FLUSH_COMPLETE, requestCode),
                    null, null, null,
                    null, null, null, options.toBundle());
                    PendingIntentUtils.createDontSendToRestrictedAppsBundle(null));
        }
        }


        @Override
        @Override
        public void deliverOnProviderEnabledChanged(String provider, boolean enabled)
        public void deliverOnProviderEnabledChanged(String provider, boolean enabled)
                throws PendingIntent.CanceledException {
                throws PendingIntent.CanceledException {
            BroadcastOptions options = BroadcastOptions.makeBasic();
            options.setDontSendToRestrictedApps(true);

            mPendingIntent.send(mContext, 0, new Intent().putExtra(KEY_PROVIDER_ENABLED, enabled),
            mPendingIntent.send(mContext, 0, new Intent().putExtra(KEY_PROVIDER_ENABLED, enabled),
                    null, null, null,
                    null, null, null, options.toBundle());
                    PendingIntentUtils.createDontSendToRestrictedAppsBundle(null));
        }
        }
    }
    }