summaryrefslogtreecommitdiff
path: root/location/lib/java
diff options
context:
space:
mode:
author Soonil Nagarkar <sooniln@google.com> 2024-04-29 10:23:58 -0700
committer Soonil Nagarkar <sooniln@google.com> 2024-05-01 10:11:11 -0700
commit7e8fea2b8df3c4c0759d1786a16350c4b422bf0e (patch)
treef21dfaff07625a964c3a25c812e53f6fff223a45 /location/lib/java
parentb28430af138de1c127c83547dfa555634f394483 (diff)
Create significant place interfaces
Interfaces can be used to define the operations a significant place provider must fulfill and what operations it can take. Bug: 337870680 Test: na Change-Id: I27ba0e3c9e48138c871bbaed3864956116ee39df
Diffstat (limited to 'location/lib/java')
-rw-r--r--location/lib/java/com/android/location/provider/SignificantPlaceProvider.java95
1 files changed, 95 insertions, 0 deletions
diff --git a/location/lib/java/com/android/location/provider/SignificantPlaceProvider.java b/location/lib/java/com/android/location/provider/SignificantPlaceProvider.java
new file mode 100644
index 000000000000..0b39a9a8bc4e
--- /dev/null
+++ b/location/lib/java/com/android/location/provider/SignificantPlaceProvider.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.location.provider;
+
+import android.annotation.Nullable;
+import android.app.trust.TrustManager;
+import android.hardware.location.ISignificantPlaceProvider;
+import android.hardware.location.ISignificantPlaceProviderManager;
+import android.os.Binder;
+import android.os.IBinder;
+import android.os.Process;
+import android.os.RemoteException;
+
+import com.android.internal.annotations.GuardedBy;
+
+/** @hide */
+public class SignificantPlaceProvider {
+
+ public static final String ACTION = TrustManager.ACTION_BIND_SIGNIFICANT_PLACE_PROVIDER;
+
+ private final IBinder mBinder;
+
+ // write locked on mBinder, read lock is optional depending on atomicity requirements
+ @Nullable private volatile ISignificantPlaceProviderManager mManager;
+
+ @GuardedBy("mBinder")
+ private boolean mInSignificantPlace = false;
+
+ public SignificantPlaceProvider() {
+ mBinder = new Service();
+ mManager = null;
+ }
+
+ public IBinder getBinder() {
+ return mBinder;
+ }
+
+ /** Set whether the device is currently in a trusted location. */
+ public void setInSignificantPlace(boolean inSignificantPlace) {
+ synchronized (mBinder) {
+ if (inSignificantPlace == mInSignificantPlace) {
+ return;
+ }
+
+ mInSignificantPlace = inSignificantPlace;
+ }
+
+ ISignificantPlaceProviderManager manager = mManager;
+ if (manager != null) {
+ try {
+ manager.setInSignificantPlace(inSignificantPlace);
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+ }
+
+ private final class Service extends ISignificantPlaceProvider.Stub {
+
+ Service() {}
+
+ @Override
+ public void setSignificantPlaceProviderManager(ISignificantPlaceProviderManager manager) {
+ if (Binder.getCallingUid() != Process.SYSTEM_UID) {
+ return;
+ }
+
+ synchronized (mBinder) {
+ if (mInSignificantPlace) {
+ try {
+ manager.setInSignificantPlace(true);
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
+ mManager = manager;
+ }
+ }
+ }
+}