0

[FastPair] Migrate companion app device IDs to feature parameter

The list of devices IDs that support a companion app are currently
hardcoded in the source code. This change adds a new parameter to
the existing feature and consumes it in the code. The hardcoded
device IDs will be removed in a follow up.

Bug:b/340680663
Tested: Overrode defaults and verified expected devices caused the notification to appear and other devices did not.

Change-Id: Ib0bc7917657436fca94d724639d01d6a35a5938a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5690061
Reviewed-by: Daniel Classon <dclasson@google.com>
Reviewed-by: Jack Shira <jackshira@google.com>
Commit-Queue: Navpreet Singh Khalsa <navpreetb@google.com>
Cr-Commit-Position: refs/heads/main@{#1325768}
This commit is contained in:
Navpreet Singh Khalsa
2024-07-10 21:47:55 +00:00
committed by Chromium LUCI CQ
parent 514293063b
commit 91a60437e1
4 changed files with 74 additions and 1 deletions

@ -1034,6 +1034,13 @@ const base::FeatureParam<std::string> kFastPairPwaCompanionPlayStoreUri{
&kFastPairPwaCompanion, "pwa-companion-play-store-uri",
/*default*/ ""};
// Comma separated list of Device IDs that the companion app supports
// e.g.
// "C8D56AB,D24F34F,9C7B5A"
const base::FeatureParam<std::string> kFastPairPwaCompanionDeviceIds{
&kFastPairPwaCompanion, "pwa-companion-device-ids",
/*default*/ ""};
// Enables support for software-based scanning on devices that don't support
// hardware-based BLE advertisement filtering.
BASE_FEATURE(kFastPairSoftwareScanningSupport,

@ -320,6 +320,8 @@ extern const base::FeatureParam<std::string> kFastPairPwaCompanionAppId;
COMPONENT_EXPORT(ASH_CONSTANTS)
extern const base::FeatureParam<std::string> kFastPairPwaCompanionPlayStoreUri;
COMPONENT_EXPORT(ASH_CONSTANTS)
extern const base::FeatureParam<std::string> kFastPairPwaCompanionDeviceIds;
COMPONENT_EXPORT(ASH_CONSTANTS)
extern const base::FeatureParam<double>
kFastPairDeviceLostNotificationTimeoutMinutes;
COMPONENT_EXPORT(ASH_CONSTANTS) BASE_DECLARE_FEATURE(kEnterpriseReportingUI);

@ -4,6 +4,7 @@
#include "ash/quick_pair/companion_app/companion_app_broker_impl.h"
#include <algorithm>
#include <set>
#include <string>
@ -54,12 +55,17 @@ bool CompanionAppBrokerImpl::MaybeShowCompanionAppActions(
// TODO(b/274973687): Make this logic more generalized once metadata
// includes companion app ID.
const auto metadata_id = device->metadata_id();
const std::string& device_ids =
ash::features::kFastPairPwaCompanionDeviceIds.Get();
std::set<std::string> target_ids{
"08A97F", "5A36A5", "6EDAF7", "9ADB11", "A7D7A0", "C8E228",
"D87A3E", "F2020E", "F58DE7", "30346C", "7862CE",
};
if (!target_ids.contains(metadata_id)) {
if (!target_ids.contains(metadata_id) &&
device_ids.find(metadata_id) == std::string::npos) {
return false;
}

@ -22,6 +22,8 @@ namespace {
const std::string kUserEmail = "test@test.test";
constexpr char kTestDeviceAddress[] = "11:12:13:14:15:16";
constexpr char kValidModelId[] = "6EDAF7";
constexpr char kInvalidModelId[] = "000000";
constexpr char kFeatureParamModelId[] = "AAAAAA";
constexpr char kValidCompanionBrowserUri[] = "https://photos.google.com/";
constexpr char kEmptyCompanionBrowserUri[] = "";
constexpr char kCompanionAppId[] = "ncmjhecbjeaamljdfahankockkkdmedg";
@ -29,6 +31,7 @@ constexpr char kValidCompanionPlayStoreUri[] =
"https://play.google.com/store/apps/"
"details?id=com.google.android.apps.photos";
constexpr char kEmptyCompanionPlayStoreUri[] = "";
constexpr char kFeatureParamDeviceIds[] = "111111,AAAAAA,BBBBBB,CCCCCC,DDDDDD";
} // namespace
@ -296,5 +299,60 @@ TEST_F(CompanionAppBrokerImplUnitTest, LaunchCompanionApp_Enabled) {
companion_app_broker_->LaunchCompanionApp(test_device_);
}
// If the app is not yet installed, the install playstore app prompt will be
// shown
TEST_F(CompanionAppBrokerImplUnitTest,
ShowsInstallCompanionApp_UsingFeatureParamDeviceId) {
base::test::ScopedFeatureList feature_list;
feature_list.InitAndEnableFeatureWithParameters(
ash::features::kFastPairPwaCompanion,
{{ash::features::kFastPairPwaCompanionInstallUri.name,
kValidCompanionBrowserUri},
{ash::features::kFastPairPwaCompanionPlayStoreUri.name,
kValidCompanionPlayStoreUri},
{ash::features::kFastPairPwaCompanionAppId.name, kCompanionAppId},
{ash::features::kFastPairPwaCompanionDeviceIds.name,
kFeatureParamDeviceIds}});
test_device_ = base::MakeRefCounted<Device>(
kFeatureParamModelId, kTestDeviceAddress, Protocol::kFastPairInitial);
SetIdentityManager(identity_manager_);
SetCompanionAppInstalled(kCompanionAppId, false);
Login(user_manager::UserType::kRegular);
EXPECT_FALSE(install_companion_app_notification_shown_);
EXPECT_FALSE(launch_companion_app_notification_shown_);
companion_app_broker_->MaybeShowCompanionAppActions(test_device_);
EXPECT_TRUE(install_companion_app_notification_shown_);
EXPECT_FALSE(launch_companion_app_notification_shown_);
}
// If the device ID isn't supported the install app prompt will not be shown
TEST_F(CompanionAppBrokerImplUnitTest,
SkipsInstallCompanionApp_UsingInvalidDeviceId) {
base::test::ScopedFeatureList feature_list;
feature_list.InitAndEnableFeatureWithParameters(
ash::features::kFastPairPwaCompanion,
{{ash::features::kFastPairPwaCompanionInstallUri.name,
kValidCompanionBrowserUri},
{ash::features::kFastPairPwaCompanionPlayStoreUri.name,
kValidCompanionPlayStoreUri},
{ash::features::kFastPairPwaCompanionAppId.name, kCompanionAppId},
{ash::features::kFastPairPwaCompanionDeviceIds.name,
kFeatureParamDeviceIds}});
test_device_ = base::MakeRefCounted<Device>(
kInvalidModelId, kTestDeviceAddress, Protocol::kFastPairInitial);
SetIdentityManager(identity_manager_);
SetCompanionAppInstalled(kCompanionAppId, false);
Login(user_manager::UserType::kRegular);
EXPECT_FALSE(install_companion_app_notification_shown_);
EXPECT_FALSE(launch_companion_app_notification_shown_);
companion_app_broker_->MaybeShowCompanionAppActions(test_device_);
EXPECT_FALSE(install_companion_app_notification_shown_);
EXPECT_FALSE(launch_companion_app_notification_shown_);
}
} // namespace quick_pair
} // namespace ash