// Message wrapper

enum MessageType {
  CopyMessage                = 33;
  DeviceAbsentMessage        = 1;
  DeviceIdentityMessage      = 2;
  DeviceLogcatEntryMessage   = 3;
  DeviceLogMessage           = 4;
  DevicePokeMessage          = 5;
  DevicePresentMessage       = 6;
  DevicePropertiesMessage    = 7;
  DeviceRegisteredMessage    = 8;
  DeviceStatusMessage        = 9;
  GroupMessage               = 10;
  InstallMessage             = 30;
  PhysicalIdentifyMessage    = 29;
  JoinGroupMessage           = 11;
  KeyDownMessage             = 12;
  KeyPressMessage            = 13;
  KeyUpMessage               = 14;
  LaunchActivityMessage      = 31;
  LeaveGroupMessage          = 15;
  LogcatApplyFiltersMessage  = 16;
  PasteMessage               = 32;
  ProbeMessage               = 17;
  ShellCommandMessage        = 18;
  ShellKeepAliveMessage      = 19;
  TapMessage                 = 20;
  TouchDownMessage           = 21;
  TouchMoveMessage           = 22;
  TouchUpMessage             = 23;
  TransactionDoneMessage     = 24;
  TransactionProgressMessage = 25;
  TypeMessage                = 26;
  UngroupMessage             = 27;
  UninstallMessage           = 34;
  RotateMessage              = 35;
  ForwardTestMessage         = 36;
  ForwardCreateMessage       = 37;
  ForwardRemoveMessage       = 38;
  LogcatStartMessage         = 39;
  LogcatStopMessage          = 40;
  BrowserOpenMessage         = 41;
  BrowserClearMessage        = 42;
  AirplaneModeEvent          = 43;
  BatteryEvent               = 44;
  DeviceBrowserMessage       = 45;
  ConnectivityEvent          = 46;
  PhoneStateEvent            = 47;
  RotationEvent              = 48;
  StoreOpenMessage           = 49;
  ScreenCaptureMessage       = 50;
  ProviderHeartbeatMessage   = 51;
}

message Envelope {
  required MessageType type = 1;
  required bytes message = 2;
  optional string channel = 3;
}

message TransactionProgressMessage {
  required string source = 1;
  required uint32 seq = 2;
  optional string data = 3;
  optional uint32 progress = 4 [default = 0];
}

message TransactionDoneMessage {
  required string source = 1;
  required uint32 seq = 2;
  required bool success = 3;
  optional string data = 4;
  optional string body = 5;
}

// Logging

message DeviceLogMessage {
  required string serial = 1;
  required double timestamp = 2;
  required uint32 priority = 3;
  required string tag = 4;
  required uint32 pid = 5;
  required string message = 6;
  required string identifier = 7;
}

// Introductions

message ProviderMessage {
  required string channel = 1;
  required string name = 2;
}

message ProviderHeartbeatMessage {
  required string channel = 1;
}

message DevicePresentMessage {
  required string serial = 1;
  required DeviceStatus status = 2;
  required ProviderMessage provider = 3;
}

message DeviceRegisteredMessage {
  required string serial = 1;
}

message DeviceAbsentMessage {
  required string serial = 1;
}

message DevicePokeMessage {
  required string serial = 1;
  required string channel = 2;
}

message ProbeMessage {
}

enum DeviceStatus {
  OFFLINE = 1;
  UNAUTHORIZED = 2;
  ONLINE = 3;
}

message DeviceStatusMessage {
  required string serial = 1;
  required DeviceStatus status = 2;
}

message DeviceDisplayMessage {
  required uint32 id = 1;
  required uint32 width = 2;
  required uint32 height = 3;
  required uint32 orientation = 4;
  required uint32 xdpi = 5;
  required uint32 ydpi = 6;
  required double fps = 7;
  required double density = 8;
  required bool secure = 9;
  required string url = 10;
}

message DeviceBrowserAppMessage {
  required string id = 1;
  required string type = 2;
  required string name = 3;
  required bool selected = 4;
  required bool system = 5;
}

message DeviceBrowserMessage {
  required string serial = 1;
  required bool selected = 2;
  repeated DeviceBrowserAppMessage apps = 3;
}

message DevicePhoneMessage {
  optional string imei = 1;
  optional string phoneNumber = 2;
  optional string iccid = 3;
  optional string network = 4;
}

message DeviceIdentityMessage {
  required string serial = 1;
  required string platform = 2;
  required string manufacturer = 3;
  optional string operator = 4;
  required string model = 5;
  required string version = 6;
  required string abi = 7;
  required string sdk = 8;
  required DeviceDisplayMessage display = 9;
  required DevicePhoneMessage phone = 11;
}

message DeviceProperty {
  required string name = 1;
  required string value = 2;
}

message DevicePropertiesMessage {
  required string serial = 1;
  repeated DeviceProperty properties = 2;
}

// Grouping

enum RequirementType {
  SEMVER = 1;
  GLOB = 2;
  EXACT = 3;
}

message DeviceRequirement {
  required string name = 1;
  required string value = 2;
  required RequirementType type = 3;
}

message OwnerMessage {
  required string email = 1;
  required string name = 2;
  required string group = 3;
}

message GroupMessage {
  required OwnerMessage owner = 1;
  optional uint32 timeout = 2;
  repeated DeviceRequirement requirements = 3;
}

message UngroupMessage {
  repeated DeviceRequirement requirements = 2;
}

message JoinGroupMessage {
  required string serial = 1;
  required OwnerMessage owner = 2;
}

message LeaveGroupMessage {
  required string serial = 1;
  required OwnerMessage owner = 2;
}

// Input

message PhysicalIdentifyMessage {
}

message TouchDownMessage {
  required uint32 seq = 1;
  required float x = 2;
  required float y = 3;
}

message TouchMoveMessage {
  required uint32 seq = 1;
  required float x = 2;
  required float y = 3;
}

message TouchUpMessage {
  required uint32 seq = 1;
  required float x = 2;
  required float y = 3;
}

message TapMessage {
  required float x = 1;
  required float y = 2;
}

message TypeMessage {
  required string text = 1;
}

message PasteMessage {
  required string text = 1;
}

message CopyMessage {
}

message KeyDownMessage {
  required string key = 1;
}

message KeyUpMessage {
  required string key = 1;
}

message KeyPressMessage {
  required string key = 1;
}

// Output

message DeviceLogcatEntryMessage {
  required string serial = 1;
  required double date = 2;
  required uint32 pid = 3;
  required uint32 tid = 4;
  required uint32 priority = 5;
  required string tag = 6;
  required string message = 7;
}

message LogcatFilter {
  required string tag = 1;
  required uint32 priority = 2;
}

message LogcatStartMessage {
  repeated LogcatFilter filters = 1;
}

message LogcatStopMessage {
}

message LogcatApplyFiltersMessage {
  repeated LogcatFilter filters = 1;
}

// Commands

message ShellCommandMessage {
  required string command = 1;
  required uint32 timeout = 2;
}

message ShellKeepAliveMessage {
  required uint32 timeout = 1;
}

message InstallMessage {
  required string href = 1;
  required bool launch = 2;
  optional string manifest = 3;
}

message UninstallMessage {
  required string packageName = 1;
}

message LaunchActivityMessage {
  required string action = 1;
  required string component = 2;
  repeated string category = 3;
  optional uint32 flags = 4;
}

message RotateMessage {
  required int32 rotation = 1;
}

message ForwardTestMessage {
  required string targetHost = 1;
  required uint32 targetPort = 2;
}

message ForwardCreateMessage {
  required uint32 devicePort = 1;
  required string targetHost = 2;
  required uint32 targetPort = 3;
  optional bool system = 4;
}

message ForwardRemoveMessage {
  required uint32 devicePort = 1;
}

message BrowserOpenMessage {
  required string url = 1;
  optional string browser = 2;
}

message BrowserClearMessage {
  optional string browser = 1;
}

message StoreOpenMessage {
}

message ScreenCaptureMessage {
}

// Events, these must be kept in sync with STFService/wire.proto

message AirplaneModeEvent {
  required string serial = 1;
  required bool enabled = 2;
}

message BatteryEvent {
  required string serial = 1;
  required string status = 2;
  required string health = 3;
  required string source = 4;
  required uint32 level = 5;
  required uint32 scale = 6;
  required double temp = 7;
  required double voltage = 8;
}

message ConnectivityEvent {
  required string serial = 1;
  required bool connected = 2;
  optional string type = 3;
  optional string subtype = 4;
  optional bool failover = 5;
  optional bool roaming = 6;
}

message PhoneStateEvent {
  required string serial = 1;
  required string state = 2;
  required bool manual = 3;
  optional string operator = 4;
}

message RotationEvent {
  required string serial = 1;
  required int32 rotation = 2;
}
