// Copyright 2020 Google LLC
//
// 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 = "proto3";

option java_multiple_files = true;
option java_package = "com.android.emulator.control";
option objc_class_prefix = "AEC";

package android.emulation.control;
import "google/protobuf/empty.proto";

service UiController {
    // PaneEntry specifies which pane will be selected when
    // the extended control is shown. If the extended is visible already,
    // this method will set visibilityChangedto to false.
    rpc showExtendedControls(PaneEntry) returns (ExtendedControlsStatus) {}
    // this method has no effect if the extended controls are hidden.
    // In that case, visibilityChanged will be set to false;
    rpc closeExtendedControls(google.protobuf.Empty)
            returns (ExtendedControlsStatus) {}
    rpc setUiTheme(ThemingStyle) returns (google.protobuf.Empty) {}

    // Returns the user configuration of the running emulator. The user
    // configuration contains information about the user interface.
    rpc getUserConfig(google.protobuf.Empty) returns (UserConfig) {}
}

message UserConfigEntry {
    string key = 1;
    string value = 2;
}

// The user configuration of the running emulator as
// key value pairs. This contains the data you normally find
// in emulator-user.ini
message UserConfig {
    repeated UserConfigEntry entries = 1;
}

message ThemingStyle {
    enum Style {
        LIGHT = 0;
        DARK = 1;
        CONTRAST = 2;
    }
    Style style = 1;
}

message ExtendedControlsStatus {
    bool visibilityChanged = 1;
}

// The pixel coordinates are resolution independent, meaning the coordinates
// are independent from the pixel grid, resulting in a graphical user
// interface that is displayed at a consistent location, regardless of the
// resolution of the screen.
//
// For technical details: https://doc.qt.io/qt-5/highdpi.html
//
// Some things to note:
//
// - You cannot move a window offscreen.
// - There is a padding of around 10px around the frame.
//
// This means that moving to (0, 0) or (10, 10) will have the same result.
// This means that anchoring might not exactly behave as requested.
message WindowPosition {
    // Anchor that is used to determine horizontal window placement.
    enum HorizontalAnchor {
        LEFT = 0;  // The x coordinate will be treated as the left edge of the
                   // window.
        HCENTER = 1;  // The x coordinate will be treated as the middle between
                      // the left and right edges of the window.
        RIGHT = 2;    // The x coordinate will be treated as the right edge of
                      // the window.
    }

    // Anchor that is used to determine vertical window placement.
    enum VerticalAnchor {
        TOP = 0;      // The y coordinate will be treated as the top edge of the
                      // window.
        VCENTER = 1;  // The y coordinate will be treated as the middle between
                      // the top and bottom edges of the window.
        BOTTOM = 3;   // The y coordinate will be treated as the bottom edge of
                      // the window.
    }

    // Corresponds to the x and y coordinate of the window geometry. The window
    // geometry includes the window frame.
    // See: https://doc.qt.io/qt-5/application-windows.html#window-geometry for
    // details and pecularities on linux.
    uint32 x = 1;
    uint32 y = 2;

    HorizontalAnchor horizontalAnchor = 3;
    VerticalAnchor verticalAnchor = 4;
}

message PaneEntry {
    enum PaneIndex {
        // When specified as KEEP_CURRENT, extended controls will display the
        // current pane.
        // If it is the first time for extended controls to be shown, LOCATION
        // will be used.
        KEEP_CURRENT = 0;
        // Referenced from
        // external/qemu/android/android-emu/android/skin/qt/extended-window-styles.h
        LOCATION = 1;
        MULTIDISPLAY = 2;
        CELLULAR = 3;
        BATTERY = 4;
        CAMERA = 5;
        TELEPHONE = 6;
        DPAD = 7;
        TV_REMOTE = 8;
        ROTARY = 9;
        MICROPHONE = 10;
        FINGER = 11;
        VIRT_SENSORS = 12;
        SNAPSHOT = 13;
        BUGREPORT = 14;
        RECORD = 15;
        GOOGLE_PLAY = 16;
        SETTINGS = 17;
        HELP = 18;
        CAR = 19;
        CAR_ROTARY = 20;
        SENSOR_REPLAY = 21;
    };
    PaneIndex index = 1;

    // Set the window position to the specified coordinates if no coordinates are
    // present in the AVD, otherwise this value will be igonred.
    WindowPosition position = 2;
}
