diff options
author | 2024-06-10 15:58:23 -0700 | |
---|---|---|
committer | 2024-06-11 12:31:58 -0700 | |
commit | f77ce1ca16f50414d42089c506b755317594feb0 (patch) | |
tree | 011a16ddade7ea7b57f41402fc842d0a217bbd71 | |
parent | 401d4245cd9cd76590b84abe725a11d06b732df4 (diff) |
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
3 files changed, 33 insertions, 2 deletions
diff --git a/core/java/android/hardware/location/ISignificantPlaceProvider.aidl b/core/java/android/hardware/location/ISignificantPlaceProvider.aidl index e02169ef2c4d..992dbff4e3ca 100644 --- a/core/java/android/hardware/location/ISignificantPlaceProvider.aidl +++ b/core/java/android/hardware/location/ISignificantPlaceProvider.aidl @@ -7,4 +7,5 @@ import android.hardware.location.ISignificantPlaceProviderManager; */ oneway interface ISignificantPlaceProvider { void setSignificantPlaceProviderManager(in ISignificantPlaceProviderManager manager); + void onSignificantPlaceCheck(); } diff --git a/location/lib/java/com/android/location/provider/SignificantPlaceProvider.java b/location/lib/java/com/android/location/provider/SignificantPlaceProvider.java index 0b39a9a8bc4e..df4b90393fbd 100644 --- a/location/lib/java/com/android/location/provider/SignificantPlaceProvider.java +++ b/location/lib/java/com/android/location/provider/SignificantPlaceProvider.java @@ -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); + }); + } + } } } diff --git a/services/core/java/com/android/server/trust/TrustManagerService.java b/services/core/java/com/android/server/trust/TrustManagerService.java index e00e81371853..07b6e5fb48e0 100644 --- a/services/core/java/com/android/server/trust/TrustManagerService.java +++ b/services/core/java/com/android/server/trust/TrustManagerService.java @@ -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; } |