aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2024-03-15 23:19:57 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2024-03-15 23:19:57 +0000
commitc6e90dd69e820ce8e2891808c319258854224a87 (patch)
tree092350789408bc3f053b7d60b63de28a9ec58703
parent6d651134d6b6eac0edb4b2f713a23da5a535ffb7 (diff)
parentd65c9d44122b8e2d6545b93c392408d4d0de1ea8 (diff)
downloadsupport-androidx-health-release.tar.gz
Merge "Merge cherrypicks of ['android-review.googlesource.com/3002449', 'android-review.googlesource.com/2855210', 'android-review.googlesource.com/3005364', 'android-review.googlesource.com/3005962', 'android-review.googlesource.com/3005967', 'android-review.googlesource.com/2961897', 'android-review.googlesource.com/3006003'] into androidx-health-release." into androidx-health-releaseandroidx-health-release
-rw-r--r--health/health-services-client/src/main/java/androidx/health/services/client/VersionApiService.kt25
-rw-r--r--health/health-services-client/src/main/java/androidx/health/services/client/data/HealthEvent.kt19
-rw-r--r--health/health-services-client/src/main/proto/data.proto6
-rw-r--r--health/health-services-client/src/main/proto/requests.proto2
-rw-r--r--health/health-services-client/src/main/stableAidl/androidx/health/services/client/impl/IVersionApiService.aidl8
-rw-r--r--health/health-services-client/src/test/java/androidx/health/services/client/VersionApiServiceTest.kt33
-rw-r--r--health/health-services-client/src/test/java/androidx/health/services/client/impl/ServiceBackedPassiveMonitoringClientTest.kt5
7 files changed, 79 insertions, 19 deletions
diff --git a/health/health-services-client/src/main/java/androidx/health/services/client/VersionApiService.kt b/health/health-services-client/src/main/java/androidx/health/services/client/VersionApiService.kt
index 91d58a2f2ab..f098caf986d 100644
--- a/health/health-services-client/src/main/java/androidx/health/services/client/VersionApiService.kt
+++ b/health/health-services-client/src/main/java/androidx/health/services/client/VersionApiService.kt
@@ -40,12 +40,31 @@ public class VersionApiService : Service() {
return stub
}
- private class VersionApiServiceStub : IVersionApiService.Stub() {
- override fun getVersionApiServiceVersion(): Int = VERSION_API_SERVICE_VERSION
- override fun getSdkVersion(): Int = CANONICAL_SDK_VERSION
+ internal class VersionApiServiceStub : IVersionApiService.Stub() {
+ override fun getVersionApiServiceVersion(): Int =
+ VersionApiService.VERSION_API_SERVICE_VERSION
+ override fun getSdkVersion(): Int = VersionApiService.CANONICAL_SDK_VERSION
}
private companion object {
private const val TAG = "VersionApiService"
+
+ /**
+ * API version of _this_ service's AIDL interface. Should be incremented every time a new
+ * method is added.
+ *
+ * Note: This is also defined within the IVersionApiService AIDL file. However, we cannot
+ * update the value there due to migrating to stableAidl, so this one must be preferred.
+ */
+ private const val VERSION_API_SERVICE_VERSION = 1
+
+ /**
+ * Version of the SDK as a whole. Should be incremented on each release, regardless of
+ * whether the API surface has changed.
+ *
+ * Note: This is also defined within the IVersionApiService AIDL file. However, we cannot
+ * update the value there due to migrating to stableAidl, so this one should be preferred.
+ */
+ private const val CANONICAL_SDK_VERSION = 28
}
}
diff --git a/health/health-services-client/src/main/java/androidx/health/services/client/data/HealthEvent.kt b/health/health-services-client/src/main/java/androidx/health/services/client/data/HealthEvent.kt
index 19bdd36fca4..1265b701dfa 100644
--- a/health/health-services-client/src/main/java/androidx/health/services/client/data/HealthEvent.kt
+++ b/health/health-services-client/src/main/java/androidx/health/services/client/data/HealthEvent.kt
@@ -47,11 +47,10 @@ public class HealthEvent(
override fun toString(): String = name
- internal fun toProto(): DataProto.HealthEvent.HealthEventType =
- DataProto.HealthEvent.HealthEventType.forNumber(id)
- ?: DataProto.HealthEvent.HealthEventType.HEALTH_EVENT_TYPE_UNKNOWN
+ internal fun toProto(): Int = id
public companion object {
+ private const val CUSTOM_TYPE_NAME_PREFIX = "health_services.device_private."
/**
* The Health Event is unknown, or is represented by a value too new for this library
* version to parse.
@@ -68,20 +67,30 @@ public class HealthEvent(
internal fun fromProto(proto: DataProto.HealthEvent.HealthEventType): Type =
VALUES.firstOrNull { it.id == proto.number } ?: UNKNOWN
+
+ internal fun fromProto(typeId: Int): Type {
+ if (isInCustomHealthEventRange(typeId)) {
+ return Type(typeId, CUSTOM_TYPE_NAME_PREFIX + typeId)
+ }
+
+ return VALUES.firstOrNull { it.id == typeId } ?: UNKNOWN
+ }
+
+ private fun isInCustomHealthEventRange(id: Int) = id in 0x40000..0x4ffff
}
}
internal constructor(
proto: DataProto.HealthEvent
) : this(
- Type.fromProto(proto.type),
+ Type.fromProto(proto.healthEventTypeId),
Instant.ofEpochMilli(proto.eventTimeEpochMs),
fromHealthEventProto(proto)
)
internal val proto: DataProto.HealthEvent =
DataProto.HealthEvent.newBuilder()
- .setType(type.toProto())
+ .setHealthEventTypeId(type.toProto())
.setEventTimeEpochMs(eventTime.toEpochMilli())
.addAllMetrics(toEventProtoList(metrics))
.build()
diff --git a/health/health-services-client/src/main/proto/data.proto b/health/health-services-client/src/main/proto/data.proto
index f75427684d1..1440581d695 100644
--- a/health/health-services-client/src/main/proto/data.proto
+++ b/health/health-services-client/src/main/proto/data.proto
@@ -446,7 +446,7 @@ message HealthEvent {
reserved 3 to max; // Next ID
}
- optional HealthEventType type = 1;
+ optional int32 health_event_type_id = 1;
optional int64 event_time_epoch_ms = 2;
repeated MetricsEntry metrics = 3;
reserved 4 to max; // Next ID
@@ -508,7 +508,7 @@ message PassiveMonitoringCapabilities {
repeated DataType supported_data_types_passive_monitoring = 1;
repeated DataType supported_data_types_passive_goals = 2;
repeated int32 supported_hr_sampling_intervals_seconds = 3 [packed = true];
- repeated HealthEvent.HealthEventType supported_health_event_types = 4
+ repeated int32 supported_health_event_types = 4
[packed = true];
repeated UserActivityState supported_user_activity_states = 5 [packed = true];
reserved 6 to max; // Next ID
@@ -518,7 +518,7 @@ message PassiveListenerConfig {
repeated DataType data_types = 1;
optional bool include_user_activity_state = 2;
repeated PassiveGoal passive_goals = 3;
- repeated HealthEvent.HealthEventType health_event_types = 4;
+ repeated int32 health_event_types = 4;
reserved 5 to max; // Next ID
}
diff --git a/health/health-services-client/src/main/proto/requests.proto b/health/health-services-client/src/main/proto/requests.proto
index 0a6d865bd94..b548312666e 100644
--- a/health/health-services-client/src/main/proto/requests.proto
+++ b/health/health-services-client/src/main/proto/requests.proto
@@ -63,7 +63,7 @@ message FlushRequest {
message HealthEventsRegistrationRequest {
optional string package_name = 1;
optional string receiver_class_name = 2;
- repeated HealthEvent.HealthEventType event_types = 3;
+ repeated int32 event_types = 3;
reserved 4 to max; // Next ID
}
diff --git a/health/health-services-client/src/main/stableAidl/androidx/health/services/client/impl/IVersionApiService.aidl b/health/health-services-client/src/main/stableAidl/androidx/health/services/client/impl/IVersionApiService.aidl
index 19f7389ea85..7a528158d8b 100644
--- a/health/health-services-client/src/main/stableAidl/androidx/health/services/client/impl/IVersionApiService.aidl
+++ b/health/health-services-client/src/main/stableAidl/androidx/health/services/client/impl/IVersionApiService.aidl
@@ -29,14 +29,14 @@ import androidx.health.services.client.impl.response.MeasureCapabilitiesResponse
@JavaPassthrough(annotation="@androidx.annotation.RestrictTo(androidx.annotation.RestrictTo.Scope.LIBRARY)")
interface IVersionApiService {
/**
- * API version of _this_ AIDL interface. Should be incremented every time a
- * new method is added.
+ * Deprecated. Now defined within VersionApiService.kt due to stable AIDL preventing this from
+ being modified.
*/
const int VERSION_API_SERVICE_VERSION = 1;
/**
- * Version of the SDK as a whole. Should be incremented on each release,
- * regardless of whether the API surface has changed.
+ * Deprecated. Now defined within VersionApiService.kt due to stable AIDL preventing this from
+ being modified.
*/
const int CANONICAL_SDK_VERSION = 27;
diff --git a/health/health-services-client/src/test/java/androidx/health/services/client/VersionApiServiceTest.kt b/health/health-services-client/src/test/java/androidx/health/services/client/VersionApiServiceTest.kt
new file mode 100644
index 00000000000..11df90894b4
--- /dev/null
+++ b/health/health-services-client/src/test/java/androidx/health/services/client/VersionApiServiceTest.kt
@@ -0,0 +1,33 @@
+package androidx.health.services.client
+
+import android.content.Intent
+import androidx.health.services.client.impl.IpcConstants
+import com.google.common.truth.Truth.assertThat
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.robolectric.Robolectric
+import org.robolectric.RobolectricTestRunner
+
+@RunWith(RobolectricTestRunner::class)
+class VersionApiServiceTest {
+ private lateinit var stub: VersionApiService.VersionApiServiceStub
+
+ @Before
+ fun setUp() {
+ val intent = Intent(IpcConstants.VERSION_API_BIND_ACTION)
+
+ stub = Robolectric.buildService(VersionApiService::class.java).create().get()
+ .onBind(intent) as VersionApiService.VersionApiServiceStub
+ }
+
+ @Test
+ fun canonicalSdkVersionIsCorrect() {
+ assertThat(stub.sdkVersion).isEqualTo(28)
+ }
+
+ @Test
+ fun versionApiServiceVersionIsCorrect() {
+ assertThat(stub.versionApiServiceVersion).isEqualTo(1)
+ }
+}
diff --git a/health/health-services-client/src/test/java/androidx/health/services/client/impl/ServiceBackedPassiveMonitoringClientTest.kt b/health/health-services-client/src/test/java/androidx/health/services/client/impl/ServiceBackedPassiveMonitoringClientTest.kt
index 7d5dd56ec1c..31c8df8aa4c 100644
--- a/health/health-services-client/src/test/java/androidx/health/services/client/impl/ServiceBackedPassiveMonitoringClientTest.kt
+++ b/health/health-services-client/src/test/java/androidx/health/services/client/impl/ServiceBackedPassiveMonitoringClientTest.kt
@@ -48,7 +48,6 @@ import androidx.health.services.client.impl.response.PassiveMonitoringGoalRespon
import androidx.health.services.client.impl.response.PassiveMonitoringUpdateResponse
import androidx.health.services.client.proto.DataProto
import androidx.health.services.client.proto.DataProto.ComparisonType.COMPARISON_TYPE_GREATER_THAN
-import androidx.health.services.client.proto.DataProto.HealthEvent.HealthEventType.HEALTH_EVENT_TYPE_FALL_DETECTED
import androidx.health.services.client.proto.DataProto.PassiveGoal.TriggerFrequency.TRIGGER_FREQUENCY_ONCE
import androidx.health.services.client.proto.DataProto.UserActivityState.USER_ACTIVITY_STATE_PASSIVE
import androidx.health.services.client.proto.ResponsesProto
@@ -209,7 +208,7 @@ class ServiceBackedPassiveMonitoringClientTest {
assertThat(fakeService.registeredCallbacks).hasSize(2)
// Stub is not reused.
assertThat(fakeService.registeredCallbacks[0]).isNotSameInstanceAs(
- fakeService.registeredCallbacks[1]);
+ fakeService.registeredCallbacks[1])
}
@Test
@@ -315,7 +314,7 @@ class ServiceBackedPassiveMonitoringClientTest {
HealthEventResponse(
ResponsesProto.HealthEventResponse.newBuilder().setHealthEvent(
DataProto.HealthEvent.newBuilder()
- .setType(HEALTH_EVENT_TYPE_FALL_DETECTED)
+ .setHealthEventTypeId(FALL_DETECTED.id)
.build()
).build()
)