/*
 * Copyright (C) 2017 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";

package android.app;

option java_outer_classname = "AppProtoEnums";
option java_multiple_files = true;

// ActivityManagerInternal.java's APP_TRANSITION reasons.
enum AppTransitionReasonEnum {
    APP_TRANSITION_REASON_UNKNOWN = 0;
    // The transition was started because we drew the splash screen.
    APP_TRANSITION_SPLASH_SCREEN = 1;
    // The transition was started because all app windows were drawn.
    APP_TRANSITION_WINDOWS_DRAWN = 2;
    // The transition was started because of a timeout.
    APP_TRANSITION_TIMEOUT = 3;
    // The transition was started because we drew a task snapshot.
    APP_TRANSITION_SNAPSHOT = 4;
    // The transition was started because it was a recents animation and we only needed to wait on
    // the wallpaper.
    APP_TRANSITION_RECENTS_ANIM = 5;
}

// ActivityManager.java PROCESS_STATEs
enum ProcessStateEnum {
    PROCESS_STATE_UNSPECIFIED = 0;
    // Process state that is unknown to this proto file (i.e. is not mapped
    // by ActivityManager.processStateAmToProto()). Can only happen if there's a bug in the mapping.
    PROCESS_STATE_UNKNOWN_TO_PROTO = 998;
    // Not a real process state.
    PROCESS_STATE_UNKNOWN = 999;
    // Process is a persistent system process.
    PROCESS_STATE_PERSISTENT = 1000;
    // Process is a persistent system process and is doing UI.
    PROCESS_STATE_PERSISTENT_UI = 1001;
    // Process is hosting the current top activities. Note that this covers
    // all activities that are visible to the user.
    PROCESS_STATE_TOP = 1002;
    // Process is bound to a TOP app.
    PROCESS_STATE_BOUND_TOP = 1020;
    // Process is hosting a foreground service.
    PROCESS_STATE_FOREGROUND_SERVICE = 1003;
    // Process is hosting a service bound by the system or another foreground app.
    PROCESS_STATE_BOUND_FOREGROUND_SERVICE = 1004;
    // Process is important to the user, and something they are aware of.
    PROCESS_STATE_IMPORTANT_FOREGROUND = 1005;
    // Process is important to the user, but not something they are aware of.
    PROCESS_STATE_IMPORTANT_BACKGROUND = 1006;
    // Process is in the background transient so we will try to keep running.
    PROCESS_STATE_TRANSIENT_BACKGROUND = 1007;
    // Process is in the background running a backup/restore operation.
    PROCESS_STATE_BACKUP = 1008;
    // Process is in the background running a service. Unlike oom_adj, this
    // level is used for both the normal running in background state and the
    // executing operations state.
    PROCESS_STATE_SERVICE = 1009;
    // Process is in the background running a receiver. Note that from the
    // perspective of oom_adj, receivers run at a higher foreground level, but
    // for our prioritization here that is not necessary and putting them
    // below services means many fewer changes in some process states as they
    // receive broadcasts.
    PROCESS_STATE_RECEIVER = 1010;
    // Same as PROCESS_STATE_TOP but while device is sleeping.
    PROCESS_STATE_TOP_SLEEPING = 1011;
    // Process is in the background, but it can't restore its state so we want
    // to try to avoid killing it.
    PROCESS_STATE_HEAVY_WEIGHT = 1012;
    // Process is in the background but hosts the home activity.
    PROCESS_STATE_HOME = 1013;
    // Process is in the background but hosts the last shown activity.
    PROCESS_STATE_LAST_ACTIVITY = 1014;
    // Process is being cached for later use and contains activities.
    PROCESS_STATE_CACHED_ACTIVITY = 1015;
    // Process is being cached for later use and is a client of another cached
    // process that contains activities.
    PROCESS_STATE_CACHED_ACTIVITY_CLIENT = 1016;
    // Process is being cached for later use and has an activity that corresponds
    // to an existing recent task.
    PROCESS_STATE_CACHED_RECENT = 1017;
    // Process is being cached for later use and is empty.
    PROCESS_STATE_CACHED_EMPTY = 1018;
    // Process does not exist.
    PROCESS_STATE_NONEXISTENT = 1019;
}

// frameworks/base/core/java/android/app/ActivityManager.java
// Proto enum equivalents for Capabilities
enum ProcessCapabilityEnum{
    PROCESS_CAPABILITY_UNKNOWN = 0;
    PROCESS_CAPABILITY_FOREGROUND_LOCATION = 1;
    PROCESS_CAPABILITY_FOREGROUND_CAMERA = 2;
    PROCESS_CAPABILITY_FOREGROUND_MICROPHONE = 3;
    PROCESS_CAPABILITY_POWER_RESTRICTED_NETWORK = 4;
    PROCESS_CAPABILITY_BFSL = 5;
    PROCESS_CAPABILITY_USER_RESTRICTED_NETWORK = 6;
    PROCESS_CAPABILITY_FOREGROUND_AUDIO_CONTROL = 7;
    PROCESS_CAPABILITY_CPU_TIME = 8;
    PROCESS_CAPABILITY_IMPLICIT_CPU_TIME = 9;
}

// frameworks/base/services/core/java/com/android/server/am/OomAdjuster.java
// Proto enum equivalents for "OomAdjReason"
enum OomChangeReasonEnum {
    OOM_ADJ_REASON_UNKNOWN_TO_PROTO = -1;
    OOM_ADJ_REASON_NONE = 0;
    OOM_ADJ_REASON_ACTIVITY = 1;
    OOM_ADJ_REASON_FINISH_RECEIVER = 2;
    OOM_ADJ_REASON_START_RECEIVER = 3;
    OOM_ADJ_REASON_BIND_SERVICE = 4;
    OOM_ADJ_REASON_UNBIND_SERVICE = 5;
    OOM_ADJ_REASON_START_SERVICE = 6;
    OOM_ADJ_REASON_GET_PROVIDER = 7;
    OOM_ADJ_REASON_REMOVE_PROVIDER = 8;
    OOM_ADJ_REASON_UI_VISIBILITY = 9;
    OOM_ADJ_REASON_ALLOWLIST = 10;
    OOM_ADJ_REASON_PROCESS_BEGIN = 11;
    OOM_ADJ_REASON_PROCESS_END = 12;
    OOM_ADJ_REASON_SHORT_FGS_TIMEOUT = 13;
    OOM_ADJ_REASON_SYSTEM_INIT = 14;
    OOM_ADJ_REASON_BACKUP = 15;
    OOM_ADJ_REASON_SHELL = 16;
    OOM_ADJ_REASON_REMOVE_TASK = 17;
    OOM_ADJ_REASON_UID_IDLE = 18;
    OOM_ADJ_REASON_STOP_SERVICE = 19;
    OOM_ADJ_REASON_EXECUTING_SERVICE = 20;
    OOM_ADJ_REASON_RESTRICTION_CHANGE = 21;
    OOM_ADJ_REASON_COMPONENT_DISABLED = 22;
    OOM_ADJ_REASON_FOLLOW_UP = 23;
    OOM_ADJ_REASON_RECONFIGURATION = 24;
    OOM_ADJ_REASON_SERVICE_BINDER_CALL = 25;
    OOM_ADJ_REASON_BATCH_UPDATE_REQUEST = 26;
}

/**
 * The reason code that why app process is killed.
 */
enum AppExitReasonCode {
    /**
     * Application process died due to unknown reason.
     */
    REASON_UNKNOWN = 0;

    /**
     * Application process exit normally by itself, for example,
     * via {@link android.os.Process#exit}; {@link #status} will specify the exit code.
     *
     * <p>Applications should normally not do this, as the system has a better knowledge
     * in terms of process management.</p>
     */
    REASON_EXIT_SELF = 1;

    /**
     * Application process died due to the result of an OS signal; for example,
     * {@link android.os.Process#SIGNAL_KILL}; {@link #status} will specify the signum.
     */
    REASON_SIGNALED = 2;

    /**
     * Application process was killed by the system low memory killer, meaning the system was
     * under memory pressure at the time of kill.
     */
    REASON_LOW_MEMORY = 3;

    /**
     * Application process died because of an unhandled exception in Java code.
     */
    REASON_CRASH = 4;

    /**
     * Application process died because it's crashed due to a native code crash.
     */
    REASON_CRASH_NATIVE = 5;

    /**
     * Application process was killed due to being unresponsive (ANR).
     */
    REASON_ANR = 6;

    /**
     * Application process was killed because it took too long to attach to the system
     * during the start.
     */
    REASON_INITIALIZATION_FAILURE = 7;

    /**
     * Application process was killed because of initialization failure,
     * for example, it took too long to attach to the system during the start,
     * or there was an error during initialization.
     */
    REASON_PERMISSION_CHANGE = 8;

    /**
     * Application process was killed by the activity manager due to excessive resource usage.
     */
    REASON_EXCESSIVE_RESOURCE_USAGE = 9;

    /**
     * Application process was killed because of the user request, for example,
     * user clicked the "Force stop" button of the application in the Settings,
     * or swiped away the application from Recents.
     * <p>
     * Prior to {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE}, one of the uses of this
     * reason was indicate that an app was killed due to it being updated or any of its component states
     * have changed without {@link android.content.pm.PackageManager#DONT_KILL_APP}
     */
    REASON_USER_REQUESTED = 10;

    /**
     * Application process was killed, because the user they are running as on devices
     * with mutlple users, was stopped.
     */
    REASON_USER_STOPPED = 11;

    /**
     * Application process was killed because its dependency was going away, for example,
     * a stable content provider connection's client will be killed if the provider is killed.
     */
    REASON_DEPENDENCY_DIED = 12;

    /**
     * Application process was killed by the system for various other reasons,
     * for example, the application package got disabled by the user;
     * {@link #description} will specify the cause given by the system.
     */
    REASON_OTHER = 13;

    /**
     * Application process was killed by App Freezer, for example, because it receives
     * sync binder transactions while being frozen.
     */
    REASON_FREEZER = 14;

    /**
     * Application process was killed because the app was uninstalled, disabled, or any of its
     * component states have changed without {@link android.content.pm.PackageManager#DONT_KILL_APP}
     * <p>
     * Prior to {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE},
     * {@link #REASON_USER_REQUESTED} was used to indicate that an app was updated.
     */
    REASON_PACKAGE_STATE_CHANGE = 15;

    /**
     * Application process was killed because it was updated.
     * <p>
     * Prior to {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE},
     * {@link #REASON_USER_REQUESTED} was used to indicate that an app was updated.
     */
    REASON_PACKAGE_UPDATED = 16;
}

/**
 * The supplemental reason code that why app process is killed
 */
enum AppExitSubReasonCode {
    /**
     * Application process kills subReason is unknown.
     */
    SUBREASON_UNKNOWN = 0;

    /**
     * Application process was killed because user quit it on the "wait for debugger" dialog.
     */
    SUBREASON_WAIT_FOR_DEBUGGER = 1;

    /**
     * Application process was killed by the activity manager because there were too many cached
     * processes.
     */
    SUBREASON_TOO_MANY_CACHED = 2;

    /**
     * Application process was killed by the activity manager because there were too many empty
     * processes.
     */
    SUBREASON_TOO_MANY_EMPTY = 3;

    /**
     * Application process was killed by the activity manager because there were too many cached
     * processes and this process had been in empty state for a long time.
     */
    SUBREASON_TRIM_EMPTY = 4;

    /**
     * Application process was killed by the activity manager because system was on
     * memory pressure and this process took large amount of cached memory.
     */
    SUBREASON_LARGE_CACHED = 5;

    /**
     * Application process was killed by the activity manager because the system was on
     * low memory pressure for a significant amount of time since last idle.
     */
    SUBREASON_MEMORY_PRESSURE = 6;

    /**
     * Application process was killed by the activity manager due to excessive CPU usage.
     */
    SUBREASON_EXCESSIVE_CPU = 7;

    /**
     * System update has done (so the system update process should be killed).
     */
    SUBREASON_SYSTEM_UPDATE_DONE = 8;

    /**
     * Kill all foreground services, for now it only occurs when enabling the quiet
     * mode for the managed profile.
     */
    SUBREASON_KILL_ALL_FG = 9;

    /**
     * All background processes except certain ones were killed, for now it only occurs
     * when the density of the default display is changed.
     */
    SUBREASON_KILL_ALL_BG_EXCEPT = 10;

    /**
     * The process associated with the UID was explicitly killed, for example,
     * it could be because of permission changes.
     */
    SUBREASON_KILL_UID = 11;

    /**
     * The process was explicitly killed with its PID, typically because of
     * the low memory for surfaces.
     */
    SUBREASON_KILL_PID = 12;

    /**
     * The start of the process was invalid.
     */
    SUBREASON_INVALID_START = 13;

    /**
     * The process was killed because it's in an invalid state, typically
     * it's triggered from SHELL.
     */
    SUBREASON_INVALID_STATE = 14;

    /**
     * The process was killed when it's imperceptible to user, because it was
     * in a bad state.
     */
    SUBREASON_IMPERCEPTIBLE = 15;

    /**
     * The process was killed because it's being moved out from LRU list.
     */
    SUBREASON_REMOVE_LRU = 16;

    /**
     * The process was killed because it's isolated and was in a cached state.
     */
    SUBREASON_ISOLATED_NOT_NEEDED = 17;

    /**
     * The process was killed because it's in forced-app-standby state, and it's cached and
     * its uid state is idle; this would be set only when the reason is {@link #REASON_OTHER}.
     */
    SUBREASON_CACHED_IDLE_FORCED_APP_STANDBY = 18;

    /**
     * The process was killed because it fails to freeze/unfreeze binder
     * or query binder frozen info while being frozen.
     */
    SUBREASON_FREEZER_BINDER_IOCTL = 19;

    /**
     * The process was killed because it receives sync binder transactions
     * while being frozen.
     */
    SUBREASON_FREEZER_BINDER_TRANSACTION = 20;

    /**
     * The process was killed because of force-stop, it could be due to that
     * the user clicked the "Force stop" button of the application in the Settings;
     * this would be set only when the reason is {@link #REASON_USER_REQUESTED}.
     */
    SUBREASON_FORCE_STOP = 21;

    /**
     * The process was killed because the user removed the application away from Recents;
     * this would be set only when the reason is {@link #REASON_USER_REQUESTED}.
     */
    SUBREASON_REMOVE_TASK = 22;

    /**
     * The process was killed because the user stopped the application from the task manager;
     * this would be set only when the reason is {@link #REASON_USER_REQUESTED}.
     */
    SUBREASON_STOP_APP = 23;

    /**
     * The process was killed because the user stopped the application from developer options,
     * or via the adb shell commmand interface; this would be set only when the reason is
     * {@link #REASON_USER_REQUESTED}.
     */
    SUBREASON_KILL_BACKGROUND = 24;

    /**
     * The process was killed because of package update; this would be set only when the reason is
     * {@link #REASON_PACKAGE_STATE_CHANGE}.
     *
     * @deprecated starting {@link android.os.Build.VERSION_CODES#TIRAMISU},
     * an app being killed due to a package update will have the reason
     * {@link #REASON_PACKAGE_UPDATED}
     */
    SUBREASON_PACKAGE_UPDATE = 25;

    /**
     * The process was killed because of undelivered broadcasts; this would be set only when the
     * reason is {@link #REASON_OTHER}.
     */
    SUBREASON_UNDELIVERED_BROADCAST = 26;

    /**
     * The process was killed because its associated SDK sandbox process (where it had loaded SDKs)
     * had died; this would be set only when the reason is {@link #REASON_DEPENDENCY_DIED}.
     */
    SUBREASON_SDK_SANDBOX_DIED = 27;

    /**
     * The process was killed because it was an SDK sandbox process that was either not usable or
     * was no longer being used; this would be set only when the reason is {@link #REASON_OTHER}.
     */
     SUBREASON_SDK_SANDBOX_NOT_NEEDED = 28;

    /**
     * The process was killed because the binder proxy limit for system server was exceeded.
     */
     SUBREASON_EXCESSIVE_BINDER_OBJECTS = 29;

    /**
     * The process was killed by the [kernel] Out-of-memory (OOM) killer; this
     * would be set only when the reason is {@link #REASON_LOW_MEMORY}.
     */
    SUBREASON_OOM_KILL = 30;

    /**
     * The process was killed because its async kernel binder buffer is running out
     * while being frozen.
     */
    SUBREASON_FREEZER_BINDER_ASYNC_FULL = 31;

    /**
     * The process was killed because it was sending too many broadcasts while it is in the
     * Cached state.
     */
    SUBREASON_EXCESSIVE_OUTGOING_BROADCASTS_WHILE_CACHED = 32;
}

/**
 * The relative importance level that the system places on a process.
 * Keep sync with the definitions in
 * {@link android.app.ActivityManager.RunningAppProcessInfo}
 */
enum Importance {
    option allow_alias = true;

    IMPORTANCE_FOREGROUND = 100;
    IMPORTANCE_FOREGROUND_SERVICE = 125;
    IMPORTANCE_TOP_SLEEPING_PRE_28 = 150;
    IMPORTANCE_VISIBLE = 200;
    IMPORTANCE_PERCEPTIBLE_PRE_26 = 130;
    IMPORTANCE_PERCEPTIBLE = 230;
    IMPORTANCE_CANT_SAVE_STATE_PRE_26 = 170;
    IMPORTANCE_SERVICE = 300;
    IMPORTANCE_TOP_SLEEPING = 325;
    IMPORTANCE_CANT_SAVE_STATE = 350;
    IMPORTANCE_CACHED = 400;
    IMPORTANCE_BACKGROUND = 400;
    IMPORTANCE_EMPTY = 500;
    IMPORTANCE_GONE = 1000;
}

/**
 * The Resource APIs that are monitored.
 */
enum ResourceApiEnum {

  RESOURCE_API_NONE = 0;
  RESOURCE_API_GET_VALUE = 1;
  RESOURCE_API_RETRIEVE_ATTRIBUTES = 2;
}

/**
 * The game modes used by GameManager.
 *
 * <p>Also see {@link android.app.GameManager#GameMode}.
 */
enum GameMode {
    GAME_MODE_UNSPECIFIED = 0;
    GAME_MODE_UNSUPPORTED = 1;
    GAME_MODE_STANDARD = 2;
    GAME_MODE_PERFORMANCE = 3;
    GAME_MODE_BATTERY = 4;
    GAME_MODE_CUSTOM = 5;
}

/**
 * The result code of foreground service type policy check.
 */
enum FgsTypePolicyCheckEnum {
    FGS_TYPE_POLICY_CHECK_UNKNOWN = 0;
    FGS_TYPE_POLICY_CHECK_OK = 1;
    FGS_TYPE_POLICY_CHECK_DEPRECATED = 2;
    FGS_TYPE_POLICY_CHECK_DISABLED = 3;
    FGS_TYPE_POLICY_CHECK_PERMISSION_DENIED_PERMISSIVE = 4;
    FGS_TYPE_POLICY_CHECK_PERMISSION_DENIED_ENFORCED = 5;
}

/**
 * The type of the component this process is hosting.
 */
enum HostingComponentType {
    HOSTING_COMPONENT_TYPE_EMPTY = 0x0;
    HOSTING_COMPONENT_TYPE_SYSTEM = 0x0001;
    HOSTING_COMPONENT_TYPE_PERSISTENT = 0x0002;
    HOSTING_COMPONENT_TYPE_BACKUP = 0x0004;
    HOSTING_COMPONENT_TYPE_INSTRUMENTATION = 0x0008;
    HOSTING_COMPONENT_TYPE_ACTIVITY = 0x0010;
    HOSTING_COMPONENT_TYPE_BROADCAST_RECEIVER = 0x0020;
    HOSTING_COMPONENT_TYPE_PROVIDER = 0x0040;
    HOSTING_COMPONENT_TYPE_STARTED_SERVICE = 0x0080;
    HOSTING_COMPONENT_TYPE_FOREGROUND_SERVICE = 0x0100;
    HOSTING_COMPONENT_TYPE_BOUND_SERVICE = 0x0200;
}

/**
 * Types of broadcast.
 */
enum BroadcastType {
    BROADCAST_TYPE_NONE                           = 0;
    BROADCAST_TYPE_BACKGROUND                     = 0x0001; // 1 << 0
    BROADCAST_TYPE_FOREGROUND                     = 0x0002; // 1 << 1
    BROADCAST_TYPE_ALARM                          = 0x0004; // 1 << 2
    BROADCAST_TYPE_INTERACTIVE                    = 0x0008; // 1 << 3
    BROADCAST_TYPE_ORDERED                        = 0x0010; // 1 << 4
    BROADCAST_TYPE_PRIORITIZED                    = 0x0020; // 1 << 5
    BROADCAST_TYPE_RESULT_TO                      = 0x0040; // 1 << 6
    BROADCAST_TYPE_DEFERRABLE_UNTIL_ACTIVE        = 0x0080; // 1 << 7
    BROADCAST_TYPE_PUSH_MESSAGE                   = 0x0100; // 1 << 8
    BROADCAST_TYPE_PUSH_MESSAGE_OVER_QUOTA        = 0x0200; // 1 << 9
    BROADCAST_TYPE_STICKY                         = 0x0400; // 1 << 10
    BROADCAST_TYPE_INITIAL_STICKY                 = 0x0800; // 1 << 11
}

/**
 * Delivery group policy applied to a broadcast.
 * Keep it in sync with BroadcastOptions#DeliveryGroupPolicy.
 */
enum BroadcastDeliveryGroupPolicy {
    BROADCAST_DELIVERY_GROUP_POLICY_ALL = 0;
    BROADCAST_DELIVERY_GROUP_POLICY_MOST_RECENT = 1;
    BROADCAST_DELIVERY_GROUP_POLICY_MERGED = 2;
}

/**
 * Most recent state of startup.
 */
enum AppStartStartupState {
    STARTUP_STATE_STARTED = 0;
    STARTUP_STATE_ERROR = 1;
    STARTUP_STATE_FIRST_FRAME_DRAWN = 2;
}

/**
 * The reason code of what triggered the process's start.
 */
enum AppStartReasonCode {
    START_REASON_ALARM = 0;
    START_REASON_BACKUP = 1;
    START_REASON_BOOT_COMPLETE = 2;
    START_REASON_BROADCAST = 3;
    START_REASON_CONTENT_PROVIDER = 4;
    START_REASON_JOB = 5;
    START_REASON_LAUNCHER = 6;
    START_REASON_OTHER = 7;
    START_REASON_PUSH = 8;
    START_REASON_RESUMED_ACTIVITY = 9;
    START_REASON_SERVICE = 10;
    START_REASON_START_ACTIVITY = 11;
}

/**
 * Type of process start.
 */
enum AppStartStartType {
    START_TYPE_COLD = 0;
    START_TYPE_WARM = 1;
    START_TYPE_HOT = 2;
}

/**
 * An instruction on how the activity should be launched.
 */
enum AppStartLaunchMode {
    LAUNCH_MODE_STANDARD = 0;
    LAUNCH_MODE_SINGLE_TOP = 1;
    LAUNCH_MODE_SINGLE_INSTANCE = 2;
    LAUNCH_MODE_SINGLE_TASK = 3;
    LAUNCH_MODE_SINGLE_INSTANCE_PER_TASK = 4;
}
