stub_multidevice_util.cc 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ash/components/multidevice/stub_multidevice_util.h"
  5. #include <map>
  6. #include <vector>
  7. #include "ash/components/multidevice/beacon_seed.h"
  8. #include "ash/constants/ash_features.h"
  9. #include "base/base64.h"
  10. #include "base/base64url.h"
  11. #include "base/no_destructor.h"
  12. #include "base/system/sys_info.h"
  13. #include "base/time/time.h"
  14. namespace ash::multidevice {
  15. namespace {
  16. // Attributes of the default stub device.
  17. const char kStubDeviceUserId[] = "example@gmail.com";
  18. const char kStubDevicePiiFreeName[] = "no-pii device";
  19. const char kStubDevicePSK[] = "remote device psk";
  20. const int64_t kStubDeviceLastUpdateTimeMillis = 0L;
  21. const char kBeaconSeedData[] = "beacon seed data";
  22. const int64_t kBeaconSeedStartTimeMillis = 100L;
  23. const int64_t kBeaconSeedEndTimeMillis = 200L;
  24. } // namespace
  25. // Attributes of the default stub devices.
  26. const char kStubHostPhoneName[] = "Fake Phone";
  27. const char kStubClientComputerName[] = "Fake Computer";
  28. const char kStubHostPhoneInstanceId[] = "1234";
  29. const char kStubClientComputerInstanceId[] = "5678";
  30. const char kStubHostPhonePublicKey[] = "public key phone";
  31. const char kStubClientComputerPublicKey[] = "public key computer";
  32. const char kStubDeviceBluetoothPublicAddress[] = "01:23:45:67:89:AB";
  33. RemoteDevice CreateStubHostPhone() {
  34. static const base::NoDestructor<RemoteDevice> host_phone([] {
  35. // Stub host phone defaults to all host features enabled.
  36. std::map<SoftwareFeature, SoftwareFeatureState> software_features;
  37. software_features[SoftwareFeature::kBetterTogetherHost] =
  38. SoftwareFeatureState::kEnabled;
  39. software_features[SoftwareFeature::kSmartLockHost] =
  40. SoftwareFeatureState::kEnabled;
  41. software_features[SoftwareFeature::kInstantTetheringHost] =
  42. SoftwareFeatureState::kEnabled;
  43. software_features[SoftwareFeature::kMessagesForWebHost] =
  44. SoftwareFeatureState::kEnabled;
  45. software_features[SoftwareFeature::kPhoneHubHost] =
  46. SoftwareFeatureState::kEnabled;
  47. software_features[SoftwareFeature::kWifiSyncHost] =
  48. SoftwareFeatureState::kEnabled;
  49. software_features[SoftwareFeature::kEcheHost] =
  50. SoftwareFeatureState::kEnabled;
  51. software_features[SoftwareFeature::kPhoneHubCameraRollHost] =
  52. SoftwareFeatureState::kEnabled;
  53. std::vector<BeaconSeed> beacon_seeds = {multidevice::BeaconSeed(
  54. kBeaconSeedData, base::Time::FromJavaTime(kBeaconSeedStartTimeMillis),
  55. base::Time::FromJavaTime(kBeaconSeedEndTimeMillis))};
  56. return RemoteDevice(kStubDeviceUserId, kStubHostPhoneInstanceId,
  57. kStubHostPhoneName, kStubDevicePiiFreeName,
  58. kStubHostPhonePublicKey, kStubDevicePSK,
  59. kStubDeviceLastUpdateTimeMillis, software_features,
  60. beacon_seeds, kStubDeviceBluetoothPublicAddress);
  61. }());
  62. return *host_phone;
  63. }
  64. RemoteDevice CreateStubClientComputer() {
  65. static const base::NoDestructor<RemoteDevice> client_computer([] {
  66. // Stub client computer relies on flags.
  67. std::map<SoftwareFeature, SoftwareFeatureState> software_features;
  68. software_features[SoftwareFeature::kBetterTogetherClient] =
  69. SoftwareFeatureState::kSupported;
  70. software_features[SoftwareFeature::kSmartLockClient] =
  71. SoftwareFeatureState::kSupported;
  72. software_features[SoftwareFeature::kMessagesForWebClient] =
  73. SoftwareFeatureState::kSupported;
  74. software_features[SoftwareFeature::kInstantTetheringClient] =
  75. base::FeatureList::IsEnabled(features::kInstantTethering)
  76. ? SoftwareFeatureState::kSupported
  77. : SoftwareFeatureState::kNotSupported;
  78. software_features[SoftwareFeature::kPhoneHubClient] =
  79. features::IsPhoneHubEnabled() ? SoftwareFeatureState::kSupported
  80. : SoftwareFeatureState::kNotSupported;
  81. software_features[SoftwareFeature::kWifiSyncClient] =
  82. features::IsWifiSyncAndroidEnabled()
  83. ? SoftwareFeatureState::kSupported
  84. : SoftwareFeatureState::kNotSupported;
  85. software_features[SoftwareFeature::kEcheClient] =
  86. features::IsEcheSWAEnabled() ? SoftwareFeatureState::kSupported
  87. : SoftwareFeatureState::kNotSupported;
  88. software_features[SoftwareFeature::kPhoneHubCameraRollClient] =
  89. features::IsPhoneHubCameraRollEnabled()
  90. ? SoftwareFeatureState::kSupported
  91. : SoftwareFeatureState::kNotSupported;
  92. std::vector<BeaconSeed> beacon_seeds = {multidevice::BeaconSeed(
  93. kBeaconSeedData, base::Time::FromJavaTime(kBeaconSeedStartTimeMillis),
  94. base::Time::FromJavaTime(kBeaconSeedEndTimeMillis))};
  95. return RemoteDevice(kStubDeviceUserId, kStubClientComputerInstanceId,
  96. kStubClientComputerName, kStubDevicePiiFreeName,
  97. kStubClientComputerPublicKey, kStubDevicePSK,
  98. kStubDeviceLastUpdateTimeMillis, software_features,
  99. beacon_seeds, kStubDeviceBluetoothPublicAddress);
  100. }());
  101. return *client_computer;
  102. }
  103. bool ShouldUseMultideviceStubs() {
  104. // Should use multidevice stubs if running on Linux CrOS build which doesn't
  105. // support making authenticated network requests to the back-end.
  106. return !base::SysInfo::IsRunningOnChromeOS();
  107. }
  108. } // namespace ash::multidevice