def test_finds_default_emulator(mocker, fake_emu_pid_file):
    path = os.path.dirname(fake_emu_pid_file)
    pid_file = os.path.basename(fake_emu_pid_file)
    mocker.patch.object(aemu.discovery.emulator_discovery,
                        "get_discovery_directory",
                        return_value=path)
    mocker.patch.object(os, "listdir", return_value=[pid_file])
    assert get_default_emulator() is not None
    assert get_default_emulator().name() == "emulator-5554"
def test_get_default_channel(mocker, fake_emu_pid_file):
    """Test you gets a standard insecure channel."""
    path = os.path.dirname(fake_emu_pid_file)
    pid_file = os.path.basename(fake_emu_pid_file)
    mocker.patch.object(aemu.discovery.emulator_discovery,
                        "get_discovery_directory",
                        return_value=path)
    mocker.patch.object(os, "listdir", return_value=[pid_file])
    channel = get_default_emulator().get_grpc_channel()
    assert channel is not None
    assert channel.__class__.__name__ == "Channel"
def test_get_token_channel(mocker, fake_emu_pid_file_with_token):
    """Test you gets a standard insecure channel with interceptor."""
    path = os.path.dirname(fake_emu_pid_file_with_token)
    pid_file = os.path.basename(fake_emu_pid_file_with_token)
    mocker.patch.object(aemu.discovery.emulator_discovery,
                        "get_discovery_directory",
                        return_value=path)
    mocker.patch.object(os, "listdir", return_value=[pid_file])
    channel = get_default_emulator().get_grpc_channel()
    assert channel is not None
    # Note the hijacked channel class!
    assert channel.__class__.__name__ == "_Channel"
Exemplo n.º 4
0
    def __init__(self,
                 port=None,
                 snapshot_service=None,
                 logger=logging.getLogger()):
        """Connect to the emulator on the given port, and log on the given logger."""
        if port and not snapshot_service:
            snapshot_service = (EmulatorDiscovery().find_emulator(
                "grpc.port", port).get_snapshot_service())
        if not snapshot_service:
            snapshot_service = get_default_emulator().get_snapshot_service()

        self.stub = snapshot_service
        self.logger = logger
def streamAudioToWave(wavefile, bitrate=44100):
    """Produces the audio stream, from the gRPC endpoint."""

    # Create a client
    stub = get_default_emulator().get_emulator_controller()

    # Desired format.
    fmt = AudioFormat(
        format=AudioFormat.AUD_FMT_S16,
        channels=AudioFormat.Stereo,
        samplingRate=bitrate,
    )

    with wave.open(wavefile, "wb") as wav:
        wav.setnchannels(2)
        wav.setframerate(fmt.samplingRate)
        wav.setsampwidth(2)
        for frame in stub.streamAudio(fmt):
            fmt = google.protobuf.text_format.MessageToString(
                frame.format, as_one_line=True
            )
            print("Packet: {} - {}".format(frame.timestamp, fmt))
            wav.writeframes(frame.audio)
def main():
    parser = argparse.ArgumentParser(
        description="Sample to interact with clipboard")
    parser.add_argument(
        "-v",
        "--verbose",
        dest="verbose",
        action="store_true",
        help="Set verbose logging",
    )

    subparsers = parser.add_subparsers()
    set_clip = subparsers.add_parser("send",
                                     help="Set the emulator clipboard.")
    set_clip.add_argument(
        "text",
        help="Utf-8 encoded string to be send to the clipboard.",
    )
    set_clip.set_defaults(func=set_clipboard)

    get_clip = subparsers.add_parser(
        "read", help="Retrieve the contents of the clipboard.")
    get_clip.set_defaults(func=get_clipboard)

    stream_clip = subparsers.add_parser("stream",
                                        help="Stream the emulator clipboard")
    stream_clip.set_defaults(func=stream_clipboard)

    # Create a client
    stub = get_default_emulator().get_emulator_controller()

    args = parser.parse_args()
    if hasattr(args, "func"):
        args.func(stub, args)
    else:
        parser.print_help()
Exemplo n.º 7
0
# 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.
import grpc
from google.protobuf import empty_pb2

from aemu.discovery.emulator_discovery import get_default_emulator
from aemu.proto.waterfall_pb2 import Message


def gen():
    for i in range(10):
        yield Message(payload="Message: {}".format(i))
        time.sleep(0.1)


# Create a client
stub = get_default_emulator().get_waterfall_service()

# Let's do some echoing..
it = stub.Echo(gen())
try:
    for msg in it:
        print("Echo: {}".format(msg.payload))
except grpc._channel._Rendezvous as err:
    print(err)
#  Copyright (C) 2019 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.
# -*- coding: utf-8 -*-
import sys
import time

from aemu.discovery.emulator_discovery import get_default_emulator
from aemu.proto.emulator_controller_pb2 import KeyboardEvent

# Create a client
stub = get_default_emulator().get_emulator_controller()

# Let's type some text..
for l in sys.argv[1]:
    textEvent = KeyboardEvent(text=l)
    print("Typing: {}".format(l))
    response = stub.sendKey(textEvent)
    time.sleep(0.2)
Exemplo n.º 9
0
#  Copyright (C) 2019 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.
# -*- coding: utf-8 -*-

import sys

from aemu.discovery.emulator_discovery import get_default_emulator
from aemu.proto.snapshot_service_pb2 import IceboxTarget

target = IceboxTarget(processName=sys.argv[1])
snap = get_default_emulator().get_snapshot_service()
print(snap.trackProcess(target))
Exemplo n.º 10
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.

# -*- coding: utf-8 -*-
import sys
import grpc
from google.protobuf import empty_pb2
from aemu.proto.ui_controller_service_pb2 import ThemingStyle

from aemu.discovery.emulator_discovery import get_default_emulator

# Create a client
stub = get_default_emulator().get_ui_controller_service()

_EMPTY_ = empty_pb2.Empty()


def setUiTheme(theme):
    stub.setUiTheme(theme)


def main(args):
    print("Set Emulator's theme to DARK")
    theme = ThemingStyle(style="DARK")
    setUiTheme(theme)
    print("Set Emulator's theme to LIGHT")
    theme = ThemingStyle(style="LIGHT")
    setUiTheme(theme)