From c7c698412cf741203bdccef2210172c7673b1d31 Mon Sep 17 00:00:00 2001 From: hais Date: Wed, 27 Jul 2022 16:15:45 -0700 Subject: [PATCH] Presence ScanRequest type def PiperOrigin-RevId: 463703748 --- presence/BUILD | 4 +- presence/power_mode.h | 35 ++++++++++++++ presence/scan_request.h | 102 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 presence/power_mode.h create mode 100644 presence/scan_request.h diff --git a/presence/BUILD b/presence/BUILD index 261e2864..f6ad9feb 100644 --- a/presence/BUILD +++ b/presence/BUILD @@ -48,17 +48,19 @@ cc_library( "discovery_filter.h", "discovery_options.h", "listeners.h", + "power_mode.h", "presence_action.h", "presence_client.h", "presence_device.h", "presence_identity.h", "presence_zone.h", + "scan_request.h", "status.h", ], deps = [ + ":credential", "//internal/platform:base", "@com_google_absl//absl/strings", - "@com_google_absl//absl/types:variant", "@com_google_glog//:glog", ], ) diff --git a/presence/power_mode.h b/presence/power_mode.h new file mode 100644 index 00000000..229c59fd --- /dev/null +++ b/presence/power_mode.h @@ -0,0 +1,35 @@ +// Copyright 2020 Google LLC +// +// 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 +// +// https://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. + +#ifndef THIRD_PARTY_NEARBY_PRESENCE_POWER_MODE_H_ +#define THIRD_PARTY_NEARBY_PRESENCE_POWER_MODE_H_ + +namespace nearby { +namespace presence { + +// High level concept of Power mode for Scan and Broadcast. +// More frequent, more power consumption, but less interval and latency. +// Native platforms would decide the specific interval based on their own +// configs. +enum class PowerMode { + kNoPower = 0, + kLowPower = 1, + kBalanced = 2, + kLowLatency = 3, +}; + +} // namespace presence +} // namespace nearby + +#endif // THIRD_PARTY_NEARBY_PRESENCE_POWER_MODE_H_ diff --git a/presence/scan_request.h b/presence/scan_request.h new file mode 100644 index 00000000..07804135 --- /dev/null +++ b/presence/scan_request.h @@ -0,0 +1,102 @@ +// Copyright 2020 Google LLC +// +// 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 +// +// https://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. + +#ifndef THIRD_PARTY_NEARBY_PRESENCE_SCAN_REQUEST_H_ +#define THIRD_PARTY_NEARBY_PRESENCE_SCAN_REQUEST_H_ + +#include +#include + +#include "third_party/nearby/presence/credential.h" +#include "third_party/nearby/presence/data_element.h" +#include "third_party/nearby/presence/power_mode.h" +#include "third_party/nearby/presence/presence_identity.h" + +namespace nearby { +namespace presence { + +enum class ScanType { + kUnspecifiedScan = 0, + kFastPairScan = 1, + kPresenceScan = 2, +}; + +/** + * Filter for scanning a nearby presence device. + */ +struct ScanFilter { + ScanType scan_type; +}; + +/** + * Filter for scanning a nearby presence device. + * Supports Android U and above. + */ +struct PresenceScanFilter : public ScanFilter { + // A bundle of extended properties for matching. + std::vector extended_properties; +}; + +/** + * Used to support legacy Android T. Filter for scanning a nearby presence + * device. + */ +struct LegacyPresenceScanFilter : public ScanFilter { + // Minimum path loss threshold of the received scan result. + int path_loss_threshold; + + // Android T needs clients to provide remote public credentials in scan + // requests. + std::vector remote_public_credentials; + + // A list of presence actions for matching. Matching condition is met as + // long as there’s one or more equal actions between Scan actions and + // Broadcast actions. + // Considered to use enum, and team agreed to use int to support potential + // un-reserved values. Already existing reserved interger values are defined + // in {@code ActionFactory}. + std::vector actions; + + // A bundle of extended properties for matching. + std::vector extended_properties; +}; + +/** + * An encapsulation of various parameters for requesting nearby scans. + */ +struct ScanRequest { + // Same as DeviceMetadata.account_name, to fetch private credential + // to broadcast. + std::string account_name; + + // Used to specify which types of remote PublicCredential to use during the + // scan. If empty, use all available types of remote PublicCredential. + std::vector identity_types; + + // For new Nearby SDK client (like chromeOs and Android U), use + // PresenceScanFilter; for Android T, use LegacyPresenceScanFilter. + std::vector scan_filters; + + // Whether to use BLE in the scan. + bool use_ble; + + ScanType scan_type; + PowerMode power_mode; + bool scan_only_when_screen_on; +}; + +} // namespace presence +} // namespace nearby + +#endif // THIRD_PARTY_NEARBY_PRESENCE_SCAN_REQUEST_H_