chromium/chromeos/ash/components/phonehub/proto/phonehub_api.proto

// 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.

syntax = "proto3";

package ash.phonehub.proto;

option optimize_for = LITE_RUNTIME;

// This enum is tied directly to the PhoneHubMessageType enum defined in
// //tools/metrics/histograms/metadata/phonehub/enums.xml, and should always
// reflect it (do not change one without changing the other). Entries should be
// never modified or deleted. Only additions possible.
enum MessageType {
  PROVIDE_CROS_STATE = 0;
  PHONE_STATUS_SNAPSHOT = 1;
  PHONE_STATUS_UPDATE = 2;
  UPDATE_NOTIFICATION_MODE_REQUEST = 3;
  UPDATE_NOTIFICATION_MODE_RESPONSE = 4;
  RING_DEVICE_REQUEST = 5;
  RING_DEVICE_RESPONSE = 6;
  UPDATE_BATTERY_MODE_REQUEST = 7;
  UPDATE_BATTERY_MODE_RESPONSE = 8;
  DISMISS_NOTIFICATION_REQUEST = 9;
  DISMISS_NOTIFICATION_RESPONSE = 10;
  NOTIFICATION_INLINE_REPLY_REQUEST = 11;
  NOTIFICATION_INLINE_REPLY_RESPONSE = 12;
  SHOW_NOTIFICATION_ACCESS_SETUP_REQUEST = 13;
  SHOW_NOTIFICATION_ACCESS_SETUP_RESPONSE = 14;
  FETCH_CAMERA_ROLL_ITEMS_REQUEST = 15;
  FETCH_CAMERA_ROLL_ITEMS_RESPONSE = 16;
  FETCH_CAMERA_ROLL_ITEM_DATA_REQUEST = 17;
  FETCH_CAMERA_ROLL_ITEM_DATA_RESPONSE = 18;
  INITIATE_CAMERA_ROLL_ITEM_TRANSFER_REQUEST = 19;
  DECLINE_INCOMING_CALL_REQUEST = 20;
  DECLINE_INCOMING_CALL_RESPONSE = 21;
  HANGUP_ONGOING_CALL_REQUEST = 22;
  HANGUP_ONGOING_CALL_RESPONSE = 23;
  FEATURE_SETUP_REQUEST = 24;
  FEATURE_SETUP_RESPONSE = 25;
  PING_REQUEST = 26;
  PING_RESPONSE = 27;
  APP_STREAM_UPDATE = 28;
  APP_LIST_UPDATE = 29;
  APP_LIST_INCREMENTAL_UPDATE = 30;
}

enum NotificationSetting {
  NOTIFICATIONS_OFF = 0;
  NOTIFICATIONS_ON = 1;
}

enum CameraRollSetting {
  CAMERA_ROLL_OFF = 0;
  CAMERA_ROLL_ON = 1;
}

enum AppStreamabilityStatus {
  STREAMABLE = 0;
  BLOCK_LISTED = 1;
  BLOCKED_BY_APP = 2;
}

enum ChargingState {
  NOT_CHARGING = 0;
  CHARGING_AC = 1;
  CHARGING_USB = 2;
  CHARGING_WIRELESS = 3;
}

enum BatteryMode {
  BATTERY_SAVER_OFF = 0;
  BATTERY_SAVER_ON = 1;
}

enum NotificationMode {
  DO_NOT_DISTURB_OFF = 0;
  DO_NOT_DISTURB_ON = 1;
}

enum NotificationAccessState {
  ACCESS_NOT_GRANTED = 0;
  ACCESS_GRANTED = 1;
}

enum FindMyDeviceRingStatus {
  NOT_RINGING = 0;
  RINGING = 1;
}

enum SignalStrength {
  ZERO_BARS = 0;
  ONE_BAR = 1;
  TWO_BARS = 2;
  THREE_BARS = 3;
  FOUR_BARS = 4;
}

enum MobileConnectionState {
  NO_SIM = 0;
  SIM_BUT_NO_RECEPTION = 1;
  SIM_WITH_RECEPTION = 2;
}

enum NotificationImportance {
  UNSPECIFIED = 0;
  NONE = 1;
  MIN = 2;
  LOW = 3;
  DEFAULT = 4;
  HIGH = 5;
}

enum ProfileType {
  DEFAULT_PROFILE = 0;
  WORK_PROFILE = 1;
}

enum ProfileDisableReason {
  DISABLE_REASON_UNKNOWN = 0;
  DISABLE_REASON_NOT_SUPPORTED = 1;
  DISABLE_REASON_DISABLED_BY_POLICY = 2;
}

enum DoNotDisturbCapability {
  DO_NOT_DISTURB_NORMAL = 0;
  DO_NOT_DISTURB_NOT_ALLOWED = 1;
}

enum FindMyDeviceCapability {
  NORMAL = 0;
  NOT_ALLOWED = 1;
}

enum FeatureStatus {
  FEATURE_STATUS_UNSPECIFIED = 0;
  FEATURE_STATUS_UNSUPPORTED = 1;
  FEATURE_STATUS_SUPPORTED = 2;
  FEATURE_STATUS_ENABLED = 3;

  // Feature is supported, but disabled by enterprise policy setting.
  FEATURE_STATUS_PROHIBITED_BY_POLICY = 4;

  // Feature is supported but requires attestation, and the connected device
  // can not be verified.
  FEATURE_STATUS_ATTESTATION_FAILED = 5;
}

// Information about the phone whether is secured with a PIN, pattern or
// password.
enum ScreenLockState {
  SCREEN_LOCK_UNKNOWN = 0;
  SCREEN_LOCK_OFF = 1;
  SCREEN_LOCK_ON = 2;
}

enum FeatureSetupResult {
  RESULT_NOT_ATTEMPTED = 0;
  RESULT_PERMISSION_GRANTED = 1;
  RESULT_ERROR_USER_REJECT = 2;
  RESULT_ERROR_ACTION_TIMEOUT = 3;
  RESULT_ERROR_ACTION_CANCELED = 4;
}

// Information about access to the camera roll feature on a connected Android
// device
message CameraRollAccessState {
  // Whether the user has explicitly granted permission to enable the Camera
  // Roll feature which allows connected Chromebooks to access the phone's
  // recent photos and media.
  bool feature_enabled = 1;
  // Whether necessary Android storage permissions have been granted to access
  // camera roll items.
  bool storage_permission_granted = 2;
}

// Information about the phone's support for cross-device feature setup.
message FeatureSetupConfig {
  // Whether the phone supports setting up multiple features at the same time
  // using the FeatureSetupRequest. When this is false, the notification
  // feature will be set up using the legacy
  // ShowNotificationAccessSetupRequest.
  bool feature_setup_request_supported = 1;
  // Supports responding to ping requests from the Chromebook. When this is
  // false, the Chromebook should not send pings to the Phone.
  bool ping_capability_supported = 2;
}

enum NetworkStatus {
  DISCONNECTED = 0;
  CELLULAR = 1;
  WIFI = 2;
}

message PhoneProperties {
  int32 battery_percentage = 1;
  ChargingState charging_state = 2;
  BatteryMode battery_mode = 3;

  // Note: If |connection_state| is not SIM_WITH_RECEPTION,
  // |signal_strength| and |mobile_provider| should be ignored.
  MobileConnectionState connection_state = 4;
  SignalStrength signal_strength = 5;
  string mobile_provider = 6;

  NotificationMode notification_mode = 7;
  NotificationAccessState notification_access_state = 8;

  FindMyDeviceRingStatus ring_status = 9;

  ProfileType profile_type = 10;
  ProfileDisableReason profile_disable_reason = 17;

  FindMyDeviceCapability find_my_device_capability = 11;

  DoNotDisturbCapability do_not_disturb_capability = 12;

  int32 android_version = 13;
  int64 gmscore_version = 14;

  CameraRollAccessState camera_roll_access_state = 15;
  // Note: This is whether the phone uses a lock screen(and not whether the
  // phone is currently locked).
  ScreenLockState screen_lock_state = 16;
  // To hide recent apps for users that turn on quiet mode.
  repeated UserState user_states = 18;

  FeatureSetupConfig feature_setup_config = 19;

  FeatureStatus eche_feature_status = 20;

  // Used for Phone Hub Structured Metrics
  optional string phone_manufacturer = 21;
  optional string phone_model = 22;
  optional int64 ambient_version = 23;
  optional NetworkStatus network_status = 24;
  optional bytes ssid = 25;
  optional string locale = 26;
  optional string phone_pseudonymous_id = 27;
  optional int64 pseudonymous_id_next_rotation_date = 28;

  // Next ID: 29
}

message UserState {
  // Records each user's ID for filter in ChromeOS.
  int64 user_id = 1;
  // The state when user turn on/off apps/notification, e.g. in work profile.
  bool is_quiet_mode_enabled = 2;
}

message App {
  string package_name = 1;
  string visible_name = 2;
  bytes icon = 3;
  int64 user_id = 4;

  // When unset, the ChromeOS side uses the system theme's default color.
  ColorRgb monochrome_icon_color = 6;
  AppStreamabilityStatus app_streamability_status = 7;
  optional bytes monochrome_icon_mask = 8;

  reserved 5;  // deprecated icon_stying field.
}

// Data required to verify the remote device.
// Next ID: 3
message AttestationData {
  enum Type {
    UNKNOWN = 0;

    // A Chrome OS "soft-bind" certificate chain.
    // The |certificates| field holds a PEM encoded X.509 certificate chain
    // ordered from leaf to root.
    CROS_SOFT_BIND_CERT_CHAIN = 1;
  }

  Type type = 1;

  // The certificate data as specified by |type|.
  repeated bytes certificates = 2;
}

message CrosState {
  NotificationSetting notification_setting = 1;
  CameraRollSetting camera_roll_setting = 2;
  // Optional for older Chromebooks pre-attestation.
  AttestationData attestation_data = 4;
  // Request Eche feature status info from the phone through Phone hub.
  bool should_provide_eche_status = 5;

  optional int64 pseudonymous_id_next_rotation_date = 6;
  optional string phone_hub_session_id = 7;

  reserved 3;  // deprecated notification_icon_styling field.
}

message Action {
  enum InputType {
    UNKNOWN = 0;
    TEXT = 1;
    CONFIRMATION = 2;
    OPEN = 3;
    CANNED_REPLY = 4;
  }

  enum CallAction {
    UNSPECIFIED = 0;
    ANSWER = 1;   // User can answer call for the CallStyle notification
    DECLINE = 2;  // User can decline call for the CallStyle notification
    HANGUP = 3;   // User can hang up call for the CallStyle notification
    // User can start the screening call for the CallStyle notification
    SCREENING = 4;
  }

  int64 id = 1;
  string title = 2;
  // Optional, but not specifying a type implies no response can be sent.
  InputType type = 3;
  // Only specified for actions in phone call notifications.
  CallAction call_action = 4;
}

message Notification {
  enum Category {
    UNSPECIFIED = 0;
    CONVERSATION = 1;
    INCOMING_CALL = 2;
    ONGOING_CALL = 3;
    SCREEN_CALL = 4;
  }

  int64 id = 1;
  int64 epoch_time_millis = 2;
  App origin_app = 3;
  NotificationImportance importance = 4;
  string title = 5;
  string text_content = 6;
  repeated Action actions = 7;

  // Optionals:
  bytes contact_image = 8;     // for messages
  bytes background_image = 9;  // for media
  bytes shared_image = 10;     // for messages
  // The category of the notification, phone hub in CrOS will decide which
  // category will be processed and display on CrOS notification,
  Category category = 11;
}

// Stores the information about the apps that are ready to be streamed.
// We used a dedicated proto for this instead of inlining this to make it
// future proof.
message StreamableApps {
  // List of apps that are ready to be streamed.
  // The order of the apps in the list is important and is set by the source.
  // The client should show the apps in the same order.
  repeated App apps = 1;
}

message PhoneStatusSnapshot {
  PhoneProperties properties = 1;
  repeated Notification notifications = 2;
  // TODO(nayebi): remove this and use AppListUpdate.recent_apps instead
  StreamableApps streamable_apps = 3;
}

message PhoneStatusUpdate {
  PhoneProperties properties = 1;
  // Notifications which have changed since the last update.
  repeated Notification updated_notifications = 2;
  // IDs of notification which have been removed since the last update.
  repeated int64 removed_notification_ids = 3;
  // Whether camera roll items has changed on the Android device and need to be
  // refeteched.
  bool has_camera_roll_updates = 4;
}

message UpdateNotificationModeRequest {
  NotificationMode notification_mode = 1;
}

message UpdateNotificationModeResponse {}

message RingDeviceRequest {
  FindMyDeviceRingStatus ring_status = 1;
}

message RingDeviceResponse {}

message UpdateBatteryModeRequest {
  BatteryMode battery_mode = 1;
}

message UpdateBatteryModeResponse {}

message DismissNotificationRequest {
  int64 notification_id = 1;
}

message DismissNotificationResponse {}

message NotificationInlineReplyRequest {
  int64 notification_id = 1;
  string reply_text = 2;
}

message NotificationInlineReplyResponse {}

message ShowNotificationAccessSetupRequest {}

message ShowNotificationAccessSetupResponse {}

message FeatureSetupRequest {
  bool notification_setup_requested = 1;
  bool camera_roll_setup_requested = 2;
}

message FeatureSetupResponse {
  FeatureSetupResult notification_setup_result = 1;
  FeatureSetupResult camera_roll_setup_result = 2;
}

message AppStreamUpdate {
  // This is optional by design and is set when the streamed app is changed.
  optional App foreground_app = 1;
}

message AppListUpdate {
  // List of apps available to stream, sorted by recency.
  optional StreamableApps all_apps = 1;
  optional StreamableApps recent_apps = 2;
}

message AppListIncrementalUpdate {
  // For removed apps, only package_names and user_ids are populated in the
  // apps.
  optional StreamableApps removed_apps = 3;
  optional StreamableApps installed_apps = 4;
}

// When adding new fields to this message, update CameraRollItem#operator==
// Located in chromeos/ash/components/phonehub/camera_roll_item.cc.
message CameraRollItemMetadata {
  // A unique and stable identifier for camera roll items on the Android device.
  string key = 1;
  string file_name = 5;
  string mime_type = 2;
  int64 last_modified_millis = 3;
  int64 file_size_bytes = 4;
  // Next ID: 6
}

// Contains data needed to display the thumbnail of a camera roll item.
message CameraRollItemThumbnail {
  enum Format {
    UNKNOWN = 0;
    JPEG = 1;
    PNG = 2;
  }
  // The format in which the thumbnail is encoded.
  Format format = 1;
  // Encoded thumbnail bytes.
  bytes data = 2;
}

// Represents a photo or video from a connected Android device's gallery.
message CameraRollItem {
  CameraRollItemMetadata metadata = 1;
  // Thumbnail data of the item. May not be set by the Android device if the
  // up-to-date thumbnail is already available on the Chrome OS device.
  CameraRollItemThumbnail thumbnail = 2;
}

// A command used by the Chrome OS device to fetch the up-to-date set of camera
// roll items that should be displayed.
message FetchCameraRollItemsRequest {
  // The maximum number of camera roll items that can be displayed.
  int32 max_item_count = 1;
  // Metadata of camera roll items already available on the Chrome OS device.
  repeated CameraRollItemMetadata current_item_metadata = 2;
}

message FetchCameraRollItemsResponse {
  // The up-to-date set of camera roll items that should be displayed.
  repeated CameraRollItem items = 1;
}

// A command to request a full-quality photo or video file from the connected
// Android device.
message FetchCameraRollItemDataRequest {
  // Metadata of the requested camera roll item.
  CameraRollItemMetadata metadata = 1;
}

// Next ID: 4
message FetchCameraRollItemDataResponse {
  CameraRollItemMetadata metadata = 3;
  enum FileAvailability {
    UNKNOWN = 0;
    AVAILABLE = 1;
    NOT_FOUND = 2;
  }
  // Indicates whether the requested file is available and can be sent to the
  // Chrome OS device.
  FileAvailability file_availability = 1;
  // A payload ID that the Chrome OS device should use to create a new local
  // file for storing the incoming file content via the Nearby Connections API.
  int64 payload_id = 2;
}

// A command to let the connected Android device start transferring the
// requested camera roll item via Nearby Connections. This should be issued
// after the Chrome OS device has allocated a new file with the provided payload
// ID.
message InitiateCameraRollItemTransferRequest {
  // Metadata of the camera roll item requested.
  CameraRollItemMetadata metadata = 1;
  // The payload ID provided by the connected Android device for the requested
  // camera roll item.
  int64 payload_id = 2;
}

message PingRequest {}

message PingResponse {}

message ColorRgb {
  uint32 red = 1;
  uint32 green = 2;
  uint32 blue = 3;
};