chromium/chromeos/ash/services/nearby/public/mojom/nearby_share_settings.mojom

// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module nearby_share.mojom;

import "url/mojom/url.mojom";

// TODO(crbug.com/1110098): Remove kUnknown.
// Represents the data usage preference when sharing.
enum DataUsage {
  kUnknown = 0,
  // User is never willing to use the Internet
  kOffline = 1,
  // User is always willing to use the Internet
  kOnline = 2,
  // User is willing to use the Internet on an un-metered connection.
  // NOTE: This matches Android Nearby Share's naming for now.
  kWifiOnly = 3
};

// TODO(crbug.com/1110098): Remove kUnknown.
// Represents who the user has chosen to be visible to. Note: These values are
// persisted to logs. Entries should not be renumbered and numeric values
// should never be reused.
enum Visibility {
  kUnknown = 0,
  // The user is not advertising to anyone.
  kNoOne = 1,
  // The user is visible to all contacts.
  kAllContacts = 2,
  // The user is only visible to selected contacts.
  kSelectedContacts = 3,
  // The user is only visible to their own devices.
  kYourDevices = 4
};

// Represents the error result when validating the device name.
enum DeviceNameValidationResult {
  // The device name was valid.
  kValid = 0,
  // The device name must not be empty.
  kErrorEmpty = 1,
  // The device name is too long.
  kErrorTooLong = 2,
  // The device name is not valid UTF-8.
  kErrorNotValidUtf8 = 3
};

// Represents the Fast Initiation Notification feature state. This feature
// shows a notification when a nearby device is trying to share. It can be
// enabled/disabed independently from the Nearby Share feature.
enum FastInitiationNotificationState {
  kEnabled = 0,
  // User manually disabled the Fast Initiation Notification feature. If
  // Nearby Share feature is toggled the notification feature will remain
  // disabled.
  kDisabledByUser = 1,
  // User turned off Nearby Share which disables the Fast Initiation
  // Notification feature. If Nearby Share is enabled while Fast Initiation
  // Notification is in this state then notifications will be re-enabled.
  kDisabledByFeature = 2,
};

// This observer interface allows clients to be notified whenever key Nearby
// Share settings are changed.
interface NearbyShareSettingsObserver {
  // Called when the nearby feature is enabled or disabled.
  OnEnabledChanged(bool enabled);
  // Called when Fast Initiation notification feature state changes.
  OnFastInitiationNotificationStateChanged(FastInitiationNotificationState state);
  // Called when the fast initiation hardware offloading support state changes.
  OnIsFastInitiationHardwareSupportedChanged(bool is_supported);
  // Called when the device name changes.
  OnDeviceNameChanged(string device_name);
  // Called when data usage changes.
  OnDataUsageChanged(DataUsage data_usage);
  // Called when visibility changed.
  OnVisibilityChanged(Visibility visibility);
  // Called when the contacts the user wants to be visible to changes.
  OnAllowedContactsChanged(array<string> visible_contact_ids);
  // Called when the onboarded state changes.
  OnIsOnboardingCompleteChanged(bool is_complete);
};

// An interface over Nearby Share's user settings which will need to be used
// in browser settings, os_settings as well as during the on boarding flow which
// is hosted in a separate WebUI where settingsPrivate is not available.
interface NearbyShareSettings {
  // Add an observer which can monitor settings changes and new contacts.
  AddSettingsObserver(pending_remote<NearbyShareSettingsObserver> observer);

  // Get the enabled state for the Nearby Share feature.
  GetEnabled() => (bool enabled);
  // Set the enabled state for the Nearby Share feature.
  SetEnabled(bool enabled);
  // Get the onboarding completion state for the Nearby Share feature.
  IsOnboardingComplete() => (bool completed);
  // Set the onboarding completion state for the Nearby Share feature.
  SetIsOnboardingComplete(bool completed);

  // Get the feature state for Fast Initiation notification.
  GetFastInitiationNotificationState() => (FastInitiationNotificationState state);
  // Set the feature state for Fast Initiation notification.
  SetFastInitiationNotificationState(FastInitiationNotificationState state);
  // Get the supported state for fast initiation hardware offloading
  // support.
  GetIsFastInitiationHardwareSupported() => (bool supported);

  // Get the device name shown to a sender when this device is available as
  // a share target. |device_name| is the new device name.
  GetDeviceName() => (string device_name);
  // Validate the device name shown to a sender when this device is available
  // as a share target. This is a separate function so that we can call it to
  // validate input as a user types.
  ValidateDeviceName(string device_name) => (DeviceNameValidationResult result);
  // Set the device name shown to a sender when this device is available as
  // a share target. Before saving the new name this will validate it and
  // respond with an error if it is invalid.
  SetDeviceName(string device_name) => (DeviceNameValidationResult result);

  // Get which type of network connectivity Nearby Share can operate on.
  GetDataUsage() => (DataUsage data_usage);
  // Set which type of network connectivity Nearby Share can operate on.
  SetDataUsage(DataUsage data_usage);

  // Get the visibility of this device with respect to the user's contacts.
  GetVisibility() => (Visibility visibility);
  // Set the visibility of this device with respect to the user's contacts.
  SetVisibility(Visibility visibility);

  // TODO(crbug.com/1128110): This functionality has been moved to
  //     ContactManger and will be removed in a follow up CL.
  //
  // Get all contact ids that this device should be visible to when visibility
  // is |kSelectedContacts|.
  GetAllowedContacts() => (array<string> allowed_contacts);
  // Set all contact ids that this device should be visible to when visibility
  // is |kSelectedContacts|.
  SetAllowedContacts(array<string> allowed_contacts);
};


// Translated from the proto file (Contact.Identifier):
// https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/nearby_sharing/proto/rpc_resources.proto
// A single contact identifier.
union ContactIdentifier {
  string obfuscated_gaia;
  string phone_number;
  string account_name;
};

// Translated from the proto file (ContactRecord):
// https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/nearby_sharing/proto/rpc_resources.proto
// A contact record from People backend.
struct ContactRecord {
  // The stable id of this contact record.
  string id;
  // The contact record's name.
  string person_name;
  // The URL of an image displayed to the user when selecting a share
  // target.
  url.mojom.Url image_url;
  array<ContactIdentifier> identifiers;
};

// Allows a client of |ContactManager| to observe contacts downloading results.
// These events can be in response to direct requests or due to periodic
// updates.
//
// This interface is implemented in a shared Polymer component that is used in
// two WebUIs: chrome://nearby and chrome://os-settings.
interface DownloadContactsObserver {
  // Notifies the observer that contacts have been downloaded successfully and
  // gives the most recent allowed contact ids at the same time.
  //
  // |allowed_contacts| is a set of contacts ids used when visibility is
  //    |Visibility::kSelectedContacts|. This can be set explicitly with
  //    SetAllowedContacts() on |ContactManager|. This array may be empty if the
  //    user has not selected any contacts yet.
  // |contacts| is a full set of a user's GAIA contacts from the the people
  //    api. The list is pre-sorted by person_name server side. Any ids present
  //    in allowed_contacts will have a corresponding contact record here. This
  //    array may be empty if the user has no contacts (in which case
  //    |allowed_contacts| will also be empty).
  OnContactsDownloaded(array<string> allowed_contacts,
                       array<ContactRecord> contacts,
                       uint32 num_unreachable_contacts_filtered_out);

  // Notifies the observer that contacts have failed to download.
  // NOTE: At the moment we don't provide a specific reason as to why this
  // failed, it is just a signal for the UI to show a generic error/retry page.
  OnContactsDownloadFailed();
};

// The contacts manager allows clients to observe contacts downloading status
// and results. Contact downloads can happen periodically or on demand with
// DownloadContacts(). The results are not returned directly on DownloadContacts
// because multiple queued download requests may result in only a single
// response and a client is likely interested in getting any contacts download
// even if they did not explicitly request it (i.e. periodic update).
//
// Implemented in the browser process and owned by a keyed service.
interface ContactManager {
  // Adds an observer which can listen for the success or failure of contact
  // downloading.
  AddDownloadContactsObserver(pending_remote<DownloadContactsObserver>
      observer);

  // Request a download of contacts from the server. This will queue the call
  // with the scheduler which may or may not execute right away depending on the
  // online state of the device.
  DownloadContacts();

  // Set all contact ids that this device should be visible to when visibility
  // is |Visibility::kSelectedContacts|. Once set, this will update the device's
  // private certificates. The latest value of this will be sent on the next
  // OnContactsDownloaded event on the observer interface, but it will not
  // trigger an immediate OnContactsDownloaded() event.
  SetAllowedContacts(array<string> allowed_contacts);
};