diff options
author | 2024-04-29 10:23:58 -0700 | |
---|---|---|
committer | 2024-05-01 10:11:11 -0700 | |
commit | 7e8fea2b8df3c4c0759d1786a16350c4b422bf0e (patch) | |
tree | f21dfaff07625a964c3a25c812e53f6fff223a45 | |
parent | b28430af138de1c127c83547dfa555634f394483 (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
4 files changed, 123 insertions, 0 deletions
diff --git a/core/java/android/app/trust/TrustManager.java b/core/java/android/app/trust/TrustManager.java index e5f2976417ab..23b2ea4dc537 100644 --- a/core/java/android/app/trust/TrustManager.java +++ b/core/java/android/app/trust/TrustManager.java @@ -18,6 +18,7 @@ package android.app.trust; import android.Manifest; import android.annotation.RequiresPermission; +import android.annotation.SdkConstant; import android.annotation.SystemService; import android.compat.annotation.UnsupportedAppUsage; import android.content.Context; @@ -40,6 +41,15 @@ import java.util.List; @SystemService(Context.TRUST_SERVICE) public class TrustManager { + /** + * Intent action used to identify services that can serve as significant providers. + * + * @hide + */ + @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION) + public static final String ACTION_BIND_SIGNIFICANT_PLACE_PROVIDER = + "com.android.trust.provider.SignificantPlaceProvider.BIND"; + private static final int MSG_TRUST_CHANGED = 1; private static final int MSG_TRUST_MANAGED_CHANGED = 2; private static final int MSG_TRUST_ERROR = 3; diff --git a/core/java/android/hardware/location/ISignificantPlaceProvider.aidl b/core/java/android/hardware/location/ISignificantPlaceProvider.aidl new file mode 100644 index 000000000000..e02169ef2c4d --- /dev/null +++ b/core/java/android/hardware/location/ISignificantPlaceProvider.aidl @@ -0,0 +1,10 @@ +package android.hardware.location; + +import android.hardware.location.ISignificantPlaceProviderManager; + +/** + * @hide + */ +oneway interface ISignificantPlaceProvider { + void setSignificantPlaceProviderManager(in ISignificantPlaceProviderManager manager); +} diff --git a/core/java/android/hardware/location/ISignificantPlaceProviderManager.aidl b/core/java/android/hardware/location/ISignificantPlaceProviderManager.aidl new file mode 100644 index 000000000000..76eefe72b45d --- /dev/null +++ b/core/java/android/hardware/location/ISignificantPlaceProviderManager.aidl @@ -0,0 +1,8 @@ +package android.hardware.location; + +/** + * @hide + */ +interface ISignificantPlaceProviderManager { + void setInSignificantPlace(in boolean inSignificantPlace); +} 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; + } + } + } +} |