/*
 * 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.service.pm;

import "frameworks/base/core/proto/android/content/featureinfo.proto";
import "frameworks/base/core/proto/android/privacy.proto";

option java_multiple_files = true;
option java_outer_classname = "PackageServiceProto";

message PackageServiceDumpProto {
    option (android.msg_privacy).dest = DEST_AUTOMATIC;

    message PackageShortProto {
        option (android.msg_privacy).dest = DEST_AUTOMATIC;

        // Name of package. e.g. "com.android.providers.telephony".
        optional string name = 1;
        // UID for this package as assigned by Android OS.
        optional int32 uid = 2;
    }
    message SharedLibraryProto {
        option (android.msg_privacy).dest = DEST_AUTOMATIC;

        optional string name = 1;
        // True if library path is not null (jar), false otherwise (apk)
        optional bool is_jar = 2;
        // Should be filled if is_jar is true
        optional string path = 3;
        // Should be filled if is_jar is false
        optional string apk = 4;
    }
    message SharedUserProto {
        option (android.msg_privacy).dest = DEST_AUTOMATIC;

        optional int32 uid = 1;
        // Name of the shared UID. eg: android.uid.bluetooth
        optional string name = 2;
    }

    // Installed packages.
    optional PackageShortProto required_verifier_package = 1;
    optional PackageShortProto verifier_package = 2;
    repeated SharedLibraryProto shared_libraries = 3;
    repeated android.content.pm.FeatureInfoProto features = 4;
    repeated PackageProto packages = 5;
    repeated SharedUserProto shared_users = 6;
    // Messages from the settings problem file
    repeated string messages = 7 [ (android.privacy).dest = DEST_EXPLICIT ];
}

message PackageProto {
    option (android.msg_privacy).dest = DEST_AUTOMATIC;

    message SplitProto {
        option (android.msg_privacy).dest = DEST_AUTOMATIC;

        // The split name of package, e.g. base
        optional string name = 1;
        optional int32 revision_code = 2;
    }
    message UserInfoProto {
        option (android.msg_privacy).dest = DEST_AUTOMATIC;

        enum InstallType {
            NOT_INSTALLED_FOR_USER = 0;
            FULL_APP_INSTALL = 1;
            INSTANT_APP_INSTALL = 2;
        }
        // Enum values gotten from PackageManger.java
        enum EnabledState {
            // This component or application is in its default enabled state
            // (as specified in its manifest).
            COMPONENT_ENABLED_STATE_DEFAULT = 0;
            // This component or application has been explictily enabled, regardless
            // of what it has specified in its manifest.
            COMPONENT_ENABLED_STATE_ENABLED = 1;
            // This component or application has been explicitly disabled, regardless of
            // what it has specified in its manifest.
            COMPONENT_ENABLED_STATE_DISABLED = 2;
            // The user has explicitly disabled the application, regardless of what it has
            // specified in its manifest.
            COMPONENT_ENABLED_STATE_DISABLED_USER = 3;
            // This application should be considered, until the point where the user actually
            // wants to use it.
            COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED = 4;
        }

        optional int32 id = 1;
        optional InstallType install_type = 2;
        // Is the app restricted by owner / admin
        optional bool is_hidden = 3;
        optional bool is_suspended = 4;
        optional bool is_stopped = 5;
        optional bool is_launched = 6;
        optional EnabledState enabled_state = 7;
        optional string last_disabled_app_caller = 8;
        repeated string suspending_package = 9;
        optional int32 distraction_flags = 10;
        // UTC timestamp of first install for the user
        optional int32 first_install_time_ms = 11;
    }

    message InstallSourceProto {
        option (android.msg_privacy).dest = DEST_AUTOMATIC;

        // The package that requested the installation of this one.
        optional string initiating_package_name = 1;

        // The package on behalf of which the initiiating package requested the install.
        optional string originating_package_name = 2;
    }

    message StatesProto {
        reserved 1;
        optional bool is_loading = 2;
    }

    // TODO (b/170263003) refactor to permissiongr
    // Runtime permission state that are granted for users.
    message UserPermissionsProto {
        option (android.msg_privacy).dest = DEST_AUTOMATIC;
        // User id.
        optional int32 id = 1;
        // Pre-granted Android permissions.
        repeated string granted_permissions = 2;
    }

    // Name of package. e.g. "com.android.providers.telephony".
    optional string name = 1;
    // UID for this package as assigned by Android OS.
    optional int32 uid = 2;
    // Package's reported version.
    optional int32 version_code = 3;
    // Package's reported version string (what's displayed to the user).
    optional string version_string = 4;
    reserved 5;
    // Millisecond UTC timestamp of latest update adjusted to Google's server clock.
    optional int64 update_time_ms = 6;
    // From "dumpsys package" - name of package which installed this one.
    // Typically "" if system app or "com.android.vending" if Play Store.
    optional string installer_name = 7;
    // Split APKs.
    repeated SplitProto splits = 8;
    // Per-user package info.
    repeated UserInfoProto users = 9;
    // Where the request to install this package came from,
    optional InstallSourceProto install_source = 10;
    // Whether the package is still loading
    optional StatesProto states = 11;
    // Granted runtime permissions for users.
    repeated UserPermissionsProto user_permissions = 12;
}
