diff options
| author | Eugene Susla <eugenesusla@google.com> | 2021-02-09 00:47:08 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2021-02-09 00:47:08 +0000 |
| commit | 2d29d34fe069dcac2792b0f2d76027bdb1493e4c (patch) | |
| tree | b1381ed30dcd643a3c05581cfaba4b467f8b7615 /core/java/android | |
| parent | abffec262db8816ab3955276816ec895490c64b5 (diff) | |
| parent | 6ce1f4109fc2b78b1ca91a721ae1021a3af6c5c7 (diff) | |
Merge "[DO NOT MERGE] Scan and notify apps when their companion devices are nearby" into sc-dev
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/bluetooth/BluetoothAdapter.java | 55 | ||||
| -rw-r--r-- | core/java/android/companion/Association.java | 30 |
2 files changed, 70 insertions, 15 deletions
diff --git a/core/java/android/bluetooth/BluetoothAdapter.java b/core/java/android/bluetooth/BluetoothAdapter.java index 7eda50e5c9cb..ea7e5ea7c802 100644 --- a/core/java/android/bluetooth/BluetoothAdapter.java +++ b/core/java/android/bluetooth/BluetoothAdapter.java @@ -3198,6 +3198,61 @@ public final class BluetoothAdapter { } /** + * Register a callback to receive events whenever the bluetooth stack goes down and back up, + * e.g. in the event the bluetooth is turned off/on via settings. + * + * If the bluetooth stack is currently up, there will not be an initial callback call. + * You can use the return value as an indication of this being the case. + * + * Callbacks will be delivered on a binder thread. + * + * @return whether bluetooth is already up currently + * + * @hide + */ + public boolean registerServiceLifecycleCallback(ServiceLifecycleCallback callback) { + return getBluetoothService(callback.mRemote) != null; + } + + /** + * Unregister a callback registered via {@link #registerServiceLifecycleCallback} + * + * @hide + */ + public void unregisterServiceLifecycleCallback(ServiceLifecycleCallback callback) { + removeServiceStateCallback(callback.mRemote); + } + + /** + * A callback for {@link #registerServiceLifecycleCallback} + * + * @hide + */ + public abstract static class ServiceLifecycleCallback { + + /** Called when the bluetooth stack is up */ + public abstract void onBluetoothServiceUp(); + + /** Called when the bluetooth stack is down */ + public abstract void onBluetoothServiceDown(); + + IBluetoothManagerCallback mRemote = new IBluetoothManagerCallback.Stub() { + @Override + public void onBluetoothServiceUp(IBluetooth bluetoothService) { + ServiceLifecycleCallback.this.onBluetoothServiceUp(); + } + + @Override + public void onBluetoothServiceDown() { + ServiceLifecycleCallback.this.onBluetoothServiceDown(); + } + + @Override + public void onBrEdrDown() {} + }; + } + + /** * Starts a scan for Bluetooth LE devices. * * <p>Results of the scan are reported using the diff --git a/core/java/android/companion/Association.java b/core/java/android/companion/Association.java index 17bf11b3d4ef..960a08755cb8 100644 --- a/core/java/android/companion/Association.java +++ b/core/java/android/companion/Association.java @@ -38,7 +38,7 @@ public final class Association implements Parcelable { private final @NonNull String mDeviceMacAddress; private final @NonNull String mPackageName; private final @Nullable String mDeviceProfile; - private final boolean mKeepProfilePrivilegesWhenDeviceAway; + private final boolean mNotifyOnDeviceNearby; /** @hide */ public int getUserId() { @@ -47,7 +47,7 @@ public final class Association implements Parcelable { - // Code below generated by codegen v1.0.21. + // Code below generated by codegen v1.0.22. // // DO NOT MODIFY! // CHECKSTYLE:OFF Generated code @@ -71,7 +71,7 @@ public final class Association implements Parcelable { @NonNull String deviceMacAddress, @NonNull String packageName, @Nullable String deviceProfile, - boolean keepProfilePrivilegesWhenDeviceAway) { + boolean notifyOnDeviceNearby) { this.mUserId = userId; com.android.internal.util.AnnotationValidations.validate( UserIdInt.class, null, mUserId); @@ -82,7 +82,7 @@ public final class Association implements Parcelable { com.android.internal.util.AnnotationValidations.validate( NonNull.class, null, mPackageName); this.mDeviceProfile = deviceProfile; - this.mKeepProfilePrivilegesWhenDeviceAway = keepProfilePrivilegesWhenDeviceAway; + this.mNotifyOnDeviceNearby = notifyOnDeviceNearby; // onConstructed(); // You can define this method to get a callback } @@ -103,8 +103,8 @@ public final class Association implements Parcelable { } @DataClass.Generated.Member - public boolean isKeepProfilePrivilegesWhenDeviceAway() { - return mKeepProfilePrivilegesWhenDeviceAway; + public boolean isNotifyOnDeviceNearby() { + return mNotifyOnDeviceNearby; } @Override @@ -118,7 +118,7 @@ public final class Association implements Parcelable { "deviceMacAddress = " + mDeviceMacAddress + ", " + "packageName = " + mPackageName + ", " + "deviceProfile = " + mDeviceProfile + ", " + - "keepProfilePrivilegesWhenDeviceAway = " + mKeepProfilePrivilegesWhenDeviceAway + + "notifyOnDeviceNearby = " + mNotifyOnDeviceNearby + " }"; } @@ -139,7 +139,7 @@ public final class Association implements Parcelable { && Objects.equals(mDeviceMacAddress, that.mDeviceMacAddress) && Objects.equals(mPackageName, that.mPackageName) && Objects.equals(mDeviceProfile, that.mDeviceProfile) - && mKeepProfilePrivilegesWhenDeviceAway == that.mKeepProfilePrivilegesWhenDeviceAway; + && mNotifyOnDeviceNearby == that.mNotifyOnDeviceNearby; } @Override @@ -153,7 +153,7 @@ public final class Association implements Parcelable { _hash = 31 * _hash + Objects.hashCode(mDeviceMacAddress); _hash = 31 * _hash + Objects.hashCode(mPackageName); _hash = 31 * _hash + Objects.hashCode(mDeviceProfile); - _hash = 31 * _hash + Boolean.hashCode(mKeepProfilePrivilegesWhenDeviceAway); + _hash = 31 * _hash + Boolean.hashCode(mNotifyOnDeviceNearby); return _hash; } @@ -164,7 +164,7 @@ public final class Association implements Parcelable { // void parcelFieldName(Parcel dest, int flags) { ... } byte flg = 0; - if (mKeepProfilePrivilegesWhenDeviceAway) flg |= 0x10; + if (mNotifyOnDeviceNearby) flg |= 0x10; if (mDeviceProfile != null) flg |= 0x8; dest.writeByte(flg); dest.writeInt(mUserId); @@ -185,7 +185,7 @@ public final class Association implements Parcelable { // static FieldType unparcelFieldName(Parcel in) { ... } byte flg = in.readByte(); - boolean keepProfilePrivilegesWhenDeviceAway = (flg & 0x10) != 0; + boolean notifyOnDeviceNearby = (flg & 0x10) != 0; int userId = in.readInt(); String deviceMacAddress = in.readString(); String packageName = in.readString(); @@ -201,7 +201,7 @@ public final class Association implements Parcelable { com.android.internal.util.AnnotationValidations.validate( NonNull.class, null, mPackageName); this.mDeviceProfile = deviceProfile; - this.mKeepProfilePrivilegesWhenDeviceAway = keepProfilePrivilegesWhenDeviceAway; + this.mNotifyOnDeviceNearby = notifyOnDeviceNearby; // onConstructed(); // You can define this method to get a callback } @@ -221,10 +221,10 @@ public final class Association implements Parcelable { }; @DataClass.Generated( - time = 1606940835778L, - codegenVersion = "1.0.21", + time = 1610482674799L, + codegenVersion = "1.0.22", sourceFile = "frameworks/base/core/java/android/companion/Association.java", - inputSignatures = "private final @android.annotation.UserIdInt int mUserId\nprivate final @android.annotation.NonNull java.lang.String mDeviceMacAddress\nprivate final @android.annotation.NonNull java.lang.String mPackageName\nprivate final @android.annotation.Nullable java.lang.String mDeviceProfile\nprivate final boolean mKeepProfilePrivilegesWhenDeviceAway\npublic int getUserId()\nclass Association extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genEqualsHashCode=true, genToString=true, genHiddenConstructor=true)") + inputSignatures = "private final @android.annotation.UserIdInt int mUserId\nprivate final @android.annotation.NonNull java.lang.String mDeviceMacAddress\nprivate final @android.annotation.NonNull java.lang.String mPackageName\nprivate final @android.annotation.Nullable java.lang.String mDeviceProfile\nprivate final boolean mNotifyOnDeviceNearby\npublic int getUserId()\nclass Association extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genEqualsHashCode=true, genToString=true, genHiddenConstructor=true)") @Deprecated private void __metadata() {} |
