• 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, gce_hostname=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            gce_hostname: String of the GCE hostname.
53        """
54        self._ip = ip
55        self._instance_name = instance_name
56
57        # Time info that the AVD device is created with. It will be assigned
58        # by the inherited AndroidVirtualDevice. For example:
59        # {"artifact": "100",
60        #  "launch_cvd": "120"}
61        self._time_info = time_info
62
63        # Build info that the AVD device is created with. It will be assigned
64        # by the inherited AndroidVirtualDevice. For example:
65        # {"branch": "git_master-release",
66        #  "build_id": "5325535",
67        #  "build_target": "cf_x86_phone-userdebug",
68        #  "gcs_bucket_build_id": "AAAA.190220.001-5325535"}
69        # It can alo have mixed builds' info. For example:
70        # {"branch": "git_master-release",
71        #  "build_id": "5325535",
72        #  "build_target": "cf_x86_phone-userdebug",
73        #  "gcs_bucket_build_id": "AAAA.190220.001-5325535",
74        #  "system_branch": "git_master",
75        #  "system_build_id": "12345",
76        #  "system_build_target": "cf_x86_phone-userdebug",
77        #  "system_gcs_bucket_build_id": "12345"}
78        self._build_info = {}
79        self._stage = stage
80        self._openwrt = openwrt
81        self._gce_hostname = gce_hostname
82
83    @property
84    def ip(self):
85        """Getter of _ip."""
86        if not self._ip:
87            raise ValueError(
88                "IP of instance %s is unknown yet." % self._instance_name)
89        return self._ip
90
91    @ip.setter
92    def ip(self, value):
93        self._ip = value
94
95    @property
96    def instance_name(self):
97        """Getter of _instance_name."""
98        return self._instance_name
99
100    @property
101    def build_info(self):
102        """Getter of _build_info."""
103        return self._build_info
104
105    @property
106    def time_info(self):
107        """Getter of _time_info."""
108        return self._time_info
109
110    @property
111    def stage(self):
112        """Getter of _stage."""
113        return self._stage
114
115    @property
116    def openwrt(self):
117        """Getter of _openwrt."""
118        return self._openwrt
119
120    @property
121    def gce_hostname(self):
122        """Getter of _gce_hostname."""
123        return self._gce_hostname
124
125    @build_info.setter
126    def build_info(self, value):
127        self._build_info = value
128
129    def __str__(self):
130        """Return a string representation."""
131        return "<ip: (internal: %s, external: %s), instance_name: %s >" % (
132            self._ip.internal if self._ip else "",
133            self._ip.external if self._ip else "",
134            self._instance_name)
135