/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

syntax = "proto2";
option java_multiple_files = true;

import "frameworks/base/core/proto/android/nfc/nfc_service.proto";
import "frameworks/base/core/proto/android/os/backtrace.proto";
import "frameworks/base/core/proto/android/os/batterytype.proto";
import "frameworks/base/core/proto/android/os/cpufreq.proto";
import "frameworks/base/core/proto/android/os/cpuinfo.proto";
import "frameworks/base/core/proto/android/os/cpu_usage.proto";
import "frameworks/base/core/proto/android/os/data.proto";
import "frameworks/base/core/proto/android/os/header.proto";
import "frameworks/base/core/proto/android/os/kernelwake.proto";
import "frameworks/base/core/proto/android/os/metadata.proto";
import "frameworks/base/core/proto/android/os/pagetypeinfo.proto";
import "frameworks/base/core/proto/android/os/procrank.proto";
import "frameworks/base/core/proto/android/os/ps.proto";
import "frameworks/base/core/proto/android/os/statsdata.proto";
import "frameworks/base/core/proto/android/os/system_properties.proto";
import "frameworks/base/core/proto/android/providers/settings.proto";
import "frameworks/base/core/proto/android/server/activitymanagerservice.proto";
import "frameworks/base/core/proto/android/server/alarm/alarmmanagerservice.proto";
import "frameworks/base/core/proto/android/server/bluetooth_manager_service.proto";
import "frameworks/base/core/proto/android/server/fingerprint.proto";
import "frameworks/base/core/proto/android/server/jobscheduler.proto";
import "frameworks/base/core/proto/android/server/location/context_hub.proto";
import "frameworks/base/core/proto/android/server/powermanagerservice.proto";
import "frameworks/base/core/proto/android/server/powerstatsservice.proto";
import "frameworks/base/core/proto/android/server/windowmanagerservice.proto";
import "frameworks/base/core/proto/android/service/appwidget.proto";
import "frameworks/base/core/proto/android/service/battery.proto";
import "frameworks/base/core/proto/android/service/batterystats.proto";
import "frameworks/base/core/proto/android/service/diskstats.proto";
import "frameworks/base/core/proto/android/service/dropbox.proto";
import "frameworks/base/core/proto/android/service/graphicsstats.proto";
import "frameworks/base/core/proto/android/service/notification.proto";
import "frameworks/base/core/proto/android/service/package.proto";
import "frameworks/base/core/proto/android/service/print.proto";
import "frameworks/base/core/proto/android/service/procstats.proto";
import "frameworks/base/core/proto/android/service/restricted_image.proto";
import "frameworks/base/core/proto/android/service/sensor_service.proto";
import "frameworks/base/core/proto/android/service/usb.proto";
import "frameworks/base/core/proto/android/util/event_log_tags.proto";
import "frameworks/base/core/proto/android/util/log.proto";
import "frameworks/base/core/proto/android/util/textdump.proto";
import "frameworks/base/core/proto/android/privacy.proto";
import "frameworks/base/core/proto/android/section.proto";
import "frameworks/base/proto/src/ipconnectivity.proto";
import "packages/modules/Connectivity/framework/proto/netstats.proto";
import "packages/modules/Permission/service/proto/role_service.proto";

package android.os;

// Privacy tag can be marked to override UNSET messages so generic
// message type can be handled case by case, e.g. GZippedFileProto.
message IncidentProto {
    reserved 1001;

    // Incident header from callers
    repeated IncidentHeaderProto header = 1;
    // Internal metadata of incidentd
    optional IncidentMetadata metadata = 2;

    // Device information
    optional SystemPropertiesProto system_properties = 1000 [
        (section).type = SECTION_COMMAND,
        (section).args = "getprop"
    ];

    optional string kernel_version = 1002 [
        (section).type = SECTION_FILE,
        (section).args = "/proc/version",
        (privacy).dest = DEST_AUTOMATIC
    ];

    // Device Logs
    optional android.util.EventLogTagMapProto event_log_tag_map = 1100 [
        (section).type = SECTION_FILE,
        (section).args = "/system/etc/event-log-tags"
    ];

    optional android.util.LogProto main_logs = 1101 [
        (section).type = SECTION_LOG,
        (section).args = "main"
    ];

    optional android.util.LogProto radio_logs = 1102 [
        (section).type = SECTION_LOG,
        (section).args = "radio"
    ];

    optional android.util.LogProto events_logs = 1103 [
        (section).type = SECTION_LOG,
        (section).args = "events"
    ];

    optional android.util.LogProto system_logs = 1104 [
        (section).type = SECTION_LOG,
        (section).args = "system"
    ];

    optional android.util.LogProto crash_logs = 1105 [
        (section).type = SECTION_LOG,
        (section).args = "crash"
    ];

    optional android.util.LogProto stats_logs = 1106 [
        (section).type = SECTION_LOG,
        (section).args = "stats"
    ];

    optional android.util.LogProto security_logs = 1107 [
        (section).type = SECTION_LOG,
        (section).args = "security"
    ];

    optional android.util.LogProto kernel_logs = 1108 [
        (section).type = SECTION_LOG,
        (section).args = "kernel"
    ];

    // Last logcat sections.
    // Note that kernel logs is not persisted since it's contained in last kmsg.
    optional android.util.LogProto last_main_logs = 1109 [
        (section).type = SECTION_LOG,
        (section).args = "main -L"
    ];

    optional android.util.LogProto last_radio_logs = 1110 [
        (section).type = SECTION_LOG,
        (section).args = "radio -L"
    ];

    optional android.util.LogProto last_events_logs = 1111 [
        (section).type = SECTION_LOG,
        (section).args = "events -L"
    ];

    optional android.util.LogProto last_system_logs = 1112 [
        (section).type = SECTION_LOG,
        (section).args = "system -L"
    ];

    optional android.util.LogProto last_crash_logs = 1113 [
        (section).type = SECTION_LOG,
        (section).args = "crash -L"
    ];

    optional android.util.LogProto last_stats_logs = 1114 [
        (section).type = SECTION_LOG,
        (section).args = "stats -L"
    ];

    // security logs is only available with "Device Owner" mode
    optional android.util.LogProto last_security_logs = 1115 [
        (section).type = SECTION_LOG,
        (section).args = "security -L"
    ];

    optional android.util.PersistedLogProto persisted_logs = 1116 [
        (section).type = SECTION_COMMAND,
        (section).args = "/system/bin/sh /system/bin/incident-helper-cmd -l run persisted_logs --limit 10MB"
    ];

    // Stack dumps
    optional android.os.BackTraceProto native_traces = 1200 [
        (section).type = SECTION_TOMBSTONE,
        (section).args = "native"
    ];

    optional android.os.BackTraceProto hal_traces = 1201 [
        (section).type = SECTION_TOMBSTONE,
        (section).args = "hal"
    ];

    optional android.os.BackTraceProto java_traces = 1202 [
        (section).type = SECTION_TOMBSTONE,
        (section).args = "java"
    ];

    // Linux services
    optional ProcrankProto procrank = 2000 [
        // Disable procrank for reasons below:
        // 1. incidentd can't execute `procrank` because it don't have DAC perms
        //    since it is running as its own uid, no root access.
        // 2. the same information is able to be accessed by meminfo dumpsys.
        // 3. leave this one here to show case of how to disable a section
        //    (no removal allowed if you are familiar with PROTOBUF).
        (section).type = SECTION_NONE,
        (section).args = "procrank"
    ];

    optional PageTypeInfoProto page_type_info = 2001 [
        (section).type = SECTION_FILE,
        (section).args = "/proc/pagetypeinfo"
    ];

    optional KernelWakeSourcesProto kernel_wake_sources = 2002 [
        (section).type = SECTION_FILE,
        (section).args = "/d/wakeup_sources"
    ];

    optional CpuInfoProto cpu_info = 2003 [
        (section).type = SECTION_COMMAND,
        (section).args = "top -b -n 1 -H -s 6 -o pid,tid,user,pr,ni,%cpu,s,virt,res,pcy,cmd,name"
    ];

    optional CpuFreqProto cpu_freq = 2004 [
        (section).type = SECTION_FILE,
        (section).args = "/sys/devices/system/cpu/cpufreq/all_time_in_state"
    ];

    optional PsProto processes_and_threads = 2005 [
        (section).type = SECTION_COMMAND,
        (section).args = "ps -A -T -Z -O pri,nice,rtprio,sched,pcy,time"
    ];

    optional BatteryTypeProto battery_type = 2006 [
        (section).type = SECTION_FILE,
        (section).args = "/sys/class/power_supply/bms/battery_type"
    ];

    optional GZippedFileProto last_kmsg = 2007 [
        (section).type = SECTION_GZIP,
        (section).args = "/sys/fs/pstore/console-ramoops /sys/fs/pstore/console-ramoops-0 /proc/last_kmsg",
        (privacy).dest = DEST_EXPLICIT
    ];

    // System Services
    optional com.android.server.biometrics.fingerprint.FingerprintServiceDumpProto fingerprint = 3000 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "fingerprint --proto --incident"
    ];

    optional android.service.NetworkStatsServiceDumpProto netstats = 3001 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "netstats --proto",
        (section).userdebug_and_eng_only = true
    ];

    optional android.providers.settings.SettingsServiceDumpProto settings = 3002 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "settings --proto"
    ];

    optional android.service.appwidget.AppWidgetServiceDumpProto appwidget = 3003;
    optional android.service.notification.NotificationServiceDumpProto notification = 3004 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "notification --proto"
    ];

    optional android.service.batterystats.BatteryStatsServiceDumpProto batterystats = 3005 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "batterystats --proto"
    ];

    optional android.service.battery.BatteryServiceDumpProto battery = 3006 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "battery --proto"
    ];

    optional android.service.diskstats.DiskStatsServiceDumpProto diskstats = 3007 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "diskstats --proto"
    ];

    optional android.service.pm.PackageServiceDumpProto package = 3008 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "package --proto"
    ];

    optional com.android.server.power.PowerManagerServiceDumpProto power = 3009 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "power --proto"
    ];

    optional android.service.print.PrintServiceDumpProto print = 3010 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "print --proto"
    ];

    optional android.service.procstats.ProcessStatsServiceDumpProto procstats = 3011 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "procstats --proto"
    ];

    optional com.android.server.am.ActivityManagerServiceDumpActivitiesProto activities = 3012 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "activity --proto activities"
    ];

    optional com.android.server.am.ActivityManagerServiceDumpBroadcastsProto broadcasts = 3013 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "activity --proto broadcasts"
    ];

    optional com.android.server.am.ActivityManagerServiceDumpServicesProto amservices = 3014 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "activity --proto service"
    ];

    optional com.android.server.am.ActivityManagerServiceDumpProcessesProto amprocesses = 3015 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "activity --proto processes"
    ];

    optional com.android.server.alarm.AlarmManagerServiceDumpProto alarm = 3016 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "alarm --proto"
    ];

    optional com.android.server.wm.WindowManagerServiceDumpProto window = 3017 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "window --proto"
    ];

    optional com.android.server.am.MemInfoDumpProto meminfo = 3018 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "meminfo -a --proto"
    ];

    optional android.service.GraphicsStatsServiceDumpProto graphicsstats = 3019 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "graphicsstats --proto"
    ];

    optional com.android.server.job.JobSchedulerServiceDumpProto jobscheduler = 3020 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "jobscheduler --proto"
    ];

    optional android.service.usb.UsbServiceDumpProto usb = 3021 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "usb --proto"
    ];

    // The history can be large and may cause issues in consumers, so put the
    // history in a separate section to compensate.
    optional android.service.batterystats.BatteryStatsServiceDumpHistoryProto battery_history = 3022 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "batterystats --proto --history",
        (section).userdebug_and_eng_only = true
    ];

    optional android.os.StatsDataDumpProto stats_data = 3023 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "stats --proto",
        (section).userdebug_and_eng_only = true
    ];

    optional com.android.role.RoleServiceDumpProto role = 3024 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "role --proto"
    ];

    optional android.service.restricted_image.RestrictedImagesDumpProto restricted_images = 3025 [
        (section).type = SECTION_DUMPSYS,
        (section).userdebug_and_eng_only = true,
        (section).args = "incidentcompanion --restricted_image"
    ];

    // System trace as a serialized protobuf.
    optional bytes system_trace = 3026 [
        (section).type = SECTION_FILE,
        (section).args = "/data/misc/perfetto-traces/incident-trace",
        (privacy).dest = DEST_AUTOMATIC
    ];

    // Dropbox entries split by tags.
    optional android.service.dropbox.DropBoxManagerServiceDumpProto dropbox_data_app_crash = 3027 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "dropbox --proto data_app_crash"
    ];

    optional android.service.dropbox.DropBoxManagerServiceDumpProto dropbox_data_app_anr = 3028 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "dropbox --proto data_app_anr"
    ];

    optional android.service.dropbox.DropBoxManagerServiceDumpProto dropbox_data_app_native_crash = 3029 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "dropbox --proto data_app_native_crash"
    ];

    optional android.service.dropbox.DropBoxManagerServiceDumpProto dropbox_data_app_strictmode = 3030 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "dropbox --proto data_app_strictmode"
    ];

    optional android.service.dropbox.DropBoxManagerServiceDumpProto dropbox_data_app_wtf = 3031 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "dropbox --proto data_app_wtf"
    ];

    optional android.service.dropbox.DropBoxManagerServiceDumpProto dropbox_system_app_crash = 3032 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "dropbox --proto system_app_crash"
    ];

    optional android.service.dropbox.DropBoxManagerServiceDumpProto dropbox_system_app_anr = 3033 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "dropbox --proto system_app_anr"
    ];

    optional android.service.dropbox.DropBoxManagerServiceDumpProto dropbox_system_app_native_crash = 3034 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "dropbox --proto system_app_native_crash"
    ];

    optional android.service.dropbox.DropBoxManagerServiceDumpProto dropbox_system_app_strictmode = 3035 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "dropbox --proto system_app_strictmode"
    ];

    optional android.service.dropbox.DropBoxManagerServiceDumpProto dropbox_system_app_wtf = 3036 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "dropbox --proto system_app_wtf"
    ];

    optional android.service.dropbox.DropBoxManagerServiceDumpProto dropbox_system_server_crash = 3037 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "dropbox --proto system_server_crash"
    ];

    optional android.service.dropbox.DropBoxManagerServiceDumpProto dropbox_system_server_anr = 3038 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "dropbox --proto system_server_anr"
    ];

    optional android.service.dropbox.DropBoxManagerServiceDumpProto dropbox_system_server_native_crash = 3039 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "dropbox --proto system_server_native_crash"
    ];

    optional android.service.dropbox.DropBoxManagerServiceDumpProto dropbox_system_server_lowmem= 3040 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "dropbox --proto system_server_lowmem"
    ];

    optional android.service.dropbox.DropBoxManagerServiceDumpProto dropbox_system_server_strictmode = 3041 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "dropbox --proto system_server_strictmode"
    ];

    optional android.service.dropbox.DropBoxManagerServiceDumpProto dropbox_system_server_watchdog = 3042 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "dropbox --proto system_server_watchdog"
    ];

    optional android.service.dropbox.DropBoxManagerServiceDumpProto dropbox_system_server_wtf = 3043 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "dropbox --proto system_server_wtf"
    ];

    optional android.service.dropbox.DropBoxManagerServiceDumpProto dropbox_system_recovery_log = 3044 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "dropbox --proto SYSTEM_RECOVERY_LOG"
    ];

    optional android.service.dropbox.DropBoxManagerServiceDumpProto dropbox_system_tombstone = 3045 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "dropbox --proto SYSTEM_TOMBSTONE"
    ];

    optional android.service.dropbox.DropBoxManagerServiceDumpProto dropbox_subsystem_restart = 3046 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "dropbox --proto SubsystemRestart"
    ];

    optional CpuUsageProto process_cpu_usage = 3047 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "cpuinfo --proto"
    ];

    optional .clearcut.connectivity.IpConnectivityLog ip_connectivity_metrics = 3049 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "connmetrics --proto"
    ];

    optional com.android.server.BluetoothManagerServiceDumpProto bluetooth_manager = 3050 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "bluetooth_manager --proto"
    ];

    optional com.android.server.location.ContextHubServiceProto context_hub = 3051 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "contexthub --proto"
    ];

    optional com.android.nfc.NfcServiceDumpProto nfc_service  = 3052 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "nfc --proto"
    ];

    optional android.service.SensorServiceProto sensor_service = 3053 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "sensorservice --proto"
    ];

    optional com.android.server.powerstats.PowerStatsServiceMeterProto powerstats_meter = 3054 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "powerstats --proto meter"
    ];

    optional com.android.server.powerstats.PowerStatsServiceModelProto powerstats_model = 3055 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "powerstats --proto model"
    ];

    optional com.android.server.powerstats.PowerStatsServiceResidencyProto powerstats_residency = 3056 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "powerstats --proto residency"
    ];

    // Dumps in text format (on userdebug and eng builds only): 4000 ~ 4999
    optional android.util.TextDumpProto textdump_wifi = 4000 [
        (section).type = SECTION_TEXT_DUMPSYS,
        (section).args = "wifi"
    ];

    optional android.util.TextDumpProto textdump_bluetooth = 4001 [
        (section).type = SECTION_TEXT_DUMPSYS,
        (section).args = "bluetooth_manager"
    ];

    // Reserved for OEMs.
    extensions 50000 to 100000;
}
