// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Request and reply to the "checkin server" devices poll every few hours.

syntax = "proto2";

option optimize_for = LITE_RUNTIME;

package checkin_proto;

import "android_checkin.proto";

// A concrete name/value pair sent to the device's Gservices database.
message GservicesSetting {
  required bytes name = 1;
  required bytes value = 2;
}

// Devices send this every few hours to tell us how they're doing.
message AndroidCheckinRequest {
  // IMEI (used by GSM phones) is sent and stored as 15 decimal
  // digits; the 15th is a check digit.
  optional string imei = 1;       // IMEI, reported but not logged.

  // MEID (used by CDMA phones) is sent and stored as 14 hexadecimal
  // digits (no check digit).
  optional string meid = 10;      // MEID, reported but not logged.

  // MAC address (used by non-phone devices).  12 hexadecimal digits;
  // no separators (eg "0016E6513AC2", not "00:16:E6:51:3A:C2").
  repeated string mac_addr = 9;   // MAC address, reported but not logged.

  // An array parallel to mac_addr, describing the type of interface.
  // Currently accepted values: "wifi", "ethernet", "bluetooth".  If
  // not present, "wifi" is assumed.
  repeated string mac_addr_type = 19;

  // Serial number (a manufacturer-defined unique hardware
  // identifier).  Alphanumeric, case-insensitive.
  optional string serial_number = 16;

  // Older CDMA networks use an ESN (8 hex digits) instead of an MEID.
  optional string esn = 17;       // ESN, reported but not logged

  optional int64 id = 2;          // Android device ID, not logged
  optional int64 logging_id = 7;  // Pseudonymous logging ID for Sawmill
  optional string digest = 3;     // Digest of device provisioning, not logged.
  optional string locale = 6;     // Current locale in standard (xx_XX) format
  required AndroidCheckinProto checkin = 4;

  // DEPRECATED, see AndroidCheckinProto.requested_group
  optional string desired_build = 5;

  // Blob of data from the Market app to be passed to Market API server
  optional string market_checkin = 8;

  // SID cookies of any google accounts stored on the phone.  Not logged.
  repeated string account_cookie = 11;

  // Time zone.  Not currently logged.
  optional string time_zone = 12;

  // Security token used to validate the checkin request.
  // Required for android IDs issued to Froyo+ devices, not for legacy IDs.
  optional fixed64 security_token = 13;

  // Version of checkin protocol.
  //
  // There are currently two versions:
  //
  // - version field missing: android IDs are assigned based on
  //   hardware identifiers.  unsecured in the sense that you can
  //   "unregister" someone's phone by sending a registration request
  //   with their IMEI/MEID/MAC.
  //
  // - version=2: android IDs are assigned randomly.  The device is
  //   sent a security token that must be included in all future
  //   checkins for that android id.
  //
  // - version=3: same as version 2, but the 'fragment' field is
  //   provided, and the device understands incremental updates to the
  //   gservices table (ie, only returning the keys whose values have
  //   changed.)
  //
  // (version=1 was skipped to avoid confusion with the "missing"
  // version field that is effectively version 1.)
  optional int32 version = 14;

  // OTA certs accepted by device (base-64 SHA-1 of cert files).  Not
  // logged.
  repeated string ota_cert = 15;

  // Honeycomb and newer devices send configuration data with their checkin.
  // optional DeviceConfigurationProto device_configuration = 18;

  // A single CheckinTask on the device may lead to multiple checkin
  // requests if there is too much log data to upload in a single
  // request.  For version 3 and up, this field will be filled in with
  // the number of the request, starting with 0.
  optional int32 fragment = 20;

  // For devices supporting multiple users, the name of the current
  // profile (they all check in independently, just as if they were
  // multiple physical devices).  This may not be set, even if the
  // device is using multiuser.  (checkin.user_number should be set to
  // the ordinal of the user.)
  optional string user_name = 21;

  // For devices supporting multiple user profiles, the serial number
  // for the user checking in.  Not logged.  May not be set, even if
  // the device supportes multiuser.  checkin.user_number is the
  // ordinal of the user (0, 1, 2, ...), which may be reused if users
  // are deleted and re-created.  user_serial_number is never reused
  // (unless the device is wiped).
  optional int32 user_serial_number = 22;

  // NEXT TAG: 23
}

// The response to the device.
message AndroidCheckinResponse {
  required bool stats_ok = 1;    // Whether statistics were recorded properly.
  optional int64 time_msec = 3;  // Time of day from server (Java epoch).
  // repeated AndroidIntentProto intent = 2;

  // Provisioning is sent if the request included an obsolete digest.
  //
  // For version <= 2, 'digest' contains the digest that should be
  // sent back to the server on the next checkin, and 'setting'
  // contains the entire gservices table (which replaces the entire
  // current table on the device).
  //
  // for version >= 3, 'digest' will be absent.  If 'settings_diff'
  // is false, then 'setting' contains the entire table, as in version
  // 2.  If 'settings_diff' is true, then 'delete_setting' contains
  // the keys to delete, and 'setting' contains only keys to be added
  // or for which the value has changed.  All other keys in the
  // current table should be left untouched.  If 'settings_diff' is
  // absent, don't touch the existing gservices table.
  //
  optional string digest = 4;
  optional bool settings_diff = 9;
  repeated string delete_setting = 10;
  repeated GservicesSetting setting = 5;

  optional bool market_ok = 6;   // If Market got the market_checkin data OK.

  optional fixed64 android_id = 7;      // From the request, or newly assigned
  optional fixed64 security_token = 8;  // The associated security token

  optional string version_info = 11;
  // NEXT TAG: 12
}
