• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2#
3# Copyright 2016 - The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#     http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16"""This module defines an AVD instance.
17
18TODO:
19  The current implementation only initialize an object
20  with IP and instance name. A complete implementation
21  will include the following features.
22  - Connect
23  - Disconnect
24  - HasApp
25  - InstallApp
26  - UninstallApp
27  - GrantAppPermission
28  Merge cloud/android/platform/devinfra/caci/framework/app_manager.py
29  with this module and updated any callers.
30"""
31
32import logging
33
34
35logger = logging.getLogger(__name__)
36
37
38class AndroidVirtualDevice():
39    """Represent an Android device."""
40
41    def __init__(self, instance_name, ip=None, time_info=None, stage=None,
42                 openwrt=None):
43        """Initialize.
44
45        Args:
46            instance_name: Name of the gce instance, e.g. "instance-1"
47            ip: namedtuple (internal, external) that holds IP address of the
48                gce instance, e.g. "external:140.110.20.1, internal:10.0.0.1"
49            time_info: Dict of time cost information, e.g. {"launch_cvd": 5}
50            stage: Integer of AVD in which stage, e.g. STAGE_GCE, STAGE_BOOT_UP
51            openwrt: Boolean of the instance creates the OpenWrt device.
52        """
53        self._ip = ip
54        self._instance_name = instance_name
55
56        # Time info that the AVD device is created with. It will be assigned
57        # by the inherited AndroidVirtualDevice. For example:
58        # {"artifact": "100",
59        #  "launch_cvd": "120"}
60        self._time_info = time_info
61
62        # Build info that the AVD device is created with. It will be assigned
63        # by the inherited AndroidVirtualDevice. For example:
64        # {"branch": "git_master-release",
65        #  "build_id": "5325535",
66        #  "build_target": "cf_x86_phone-userdebug",
67        #  "gcs_bucket_build_id": "AAAA.190220.001-5325535"}
68        # It can alo have mixed builds' info. For example:
69        # {"branch": "git_master-release",
70        #  "build_id": "5325535",
71        #  "build_target": "cf_x86_phone-userdebug",
72        #  "gcs_bucket_build_id": "AAAA.190220.001-5325535",
73        #  "system_branch": "git_master",
74        #  "system_build_id": "12345",
75        #  "system_build_target": "cf_x86_phone-userdebug",
76        #  "system_gcs_bucket_build_id": "12345"}
77        self._build_info = {}
78        self._stage = stage
79        self._openwrt = openwrt
80
81    @property
82    def ip(self):
83        """Getter of _ip."""
84        if not self._ip:
85            raise ValueError(
86                "IP of instance %s is unknown yet." % self._instance_name)
87        return self._ip
88
89    @ip.setter
90    def ip(self, value):
91        self._ip = value
92
93    @property
94    def instance_name(self):
95        """Getter of _instance_name."""
96        return self._instance_name
97
98    @property
99    def build_info(self):
100        """Getter of _build_info."""
101        return self._build_info
102
103    @property
104    def time_info(self):
105        """Getter of _time_info."""
106        return self._time_info
107
108    @property
109    def stage(self):
110        """Getter of _stage."""
111        return self._stage
112
113    @property
114    def openwrt(self):
115        """Getter of _openwrt."""
116        return self._openwrt
117
118    @build_info.setter
119    def build_info(self, value):
120        self._build_info = value
121
122    def __str__(self):
123        """Return a string representation."""
124        return "<ip: (internal: %s, external: %s), instance_name: %s >" % (
125            self._ip.internal if self._ip else "",
126            self._ip.external if self._ip else "",
127            self._instance_name)
128