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

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

Add onSignificantPlaceCheck() API

Add API that will be invoked whenever anyone checks if the device is in
a significant place. This will allow us some latitude in implementation
of SignificantPlaceProvider (for example by avoiding geofences if
necessary) in the event of significant power burn without needing to
commit further changes in the framework. This gives us the flexiblity to
fix potential future issues with just implementaion changes. Ideally
this will never need to be used.

Flag: significant_places
Bug: 337870680
Test: manual
Change-Id: If25b328dd8140dedb972489c5363e4d0c7102310
parent 401d4245
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -7,4 +7,5 @@ import android.hardware.location.ISignificantPlaceProviderManager;
 */
oneway interface ISignificantPlaceProvider {
    void setSignificantPlaceProviderManager(in ISignificantPlaceProviderManager manager);
    void onSignificantPlaceCheck();
}
+27 −2
Original line number Diff line number Diff line
@@ -21,17 +21,22 @@ import android.app.trust.TrustManager;
import android.hardware.location.ISignificantPlaceProvider;
import android.hardware.location.ISignificantPlaceProviderManager;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.Process;
import android.os.RemoteException;
import android.util.Log;

import com.android.internal.annotations.GuardedBy;

/** @hide */
public class SignificantPlaceProvider {
public abstract class SignificantPlaceProvider {

    public static final String ACTION = TrustManager.ACTION_BIND_SIGNIFICANT_PLACE_PROVIDER;

    private static final String TAG = "SignificantPlaceProvider";

    private final IBinder mBinder;

    // write locked on mBinder, read lock is optional depending on atomicity requirements
@@ -69,6 +74,9 @@ public class SignificantPlaceProvider {
        }
    }

    /** Invoked when some client has checked whether the device is in a significant place. */
    public abstract void onSignificantPlaceCheck();

    private final class Service extends ISignificantPlaceProvider.Stub {

        Service() {}
@@ -76,7 +84,7 @@ public class SignificantPlaceProvider {
        @Override
        public void setSignificantPlaceProviderManager(ISignificantPlaceProviderManager manager) {
            if (Binder.getCallingUid() != Process.SYSTEM_UID) {
                return;
                throw new SecurityException();
            }

            synchronized (mBinder) {
@@ -91,5 +99,22 @@ public class SignificantPlaceProvider {
                mManager = manager;
            }
        }

        @Override
        public void onSignificantPlaceCheck() {
            if (Binder.getCallingUid() != Process.SYSTEM_UID) {
                throw new SecurityException();
            }

            try {
                SignificantPlaceProvider.this.onSignificantPlaceCheck();
            } catch (RuntimeException e) {
                // exceptions on one-way binder threads are dropped - move to a different thread
                Log.w(TAG, e);
                new Handler(Looper.getMainLooper()).post(() -> {
                    throw new AssertionError(e);
                });
            }
        }
    }
}
+5 −0
Original line number Diff line number Diff line
@@ -1693,6 +1693,11 @@ public class TrustManagerService extends SystemService {

        @Override
        public boolean isInSignificantPlace() {
            if (android.security.Flags.significantPlaces()) {
                mSignificantPlaceServiceWatcher.runOnBinder(
                        binder -> ISignificantPlaceProvider.Stub.asInterface(binder)
                                .onSignificantPlaceCheck());
            }
            return mIsInSignificantPlace;
        }