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

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

Merge "Add onSignificantPlaceCheck() API" into main

parents d43735b3 f77ce1ca
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
@@ -1870,6 +1870,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;
        }