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(object): 39 """Represent an Android device.""" 40 41 def __init__(self, instance_name, ip=None, time_info=None, stage=None): 42 """Initialize. 43 44 Args: 45 instance_name: Name of the gce instance, e.g. "instance-1" 46 ip: namedtuple (internal, external) that holds IP address of the 47 gce instance, e.g. "external:140.110.20.1, internal:10.0.0.1" 48 time_info: Dict of time cost information, e.g. {"launch_cvd": 5} 49 stage: Integer of AVD in which stage, e.g. STAGE_GCE, STAGE_BOOT_UP 50 """ 51 self._ip = ip 52 self._instance_name = instance_name 53 54 # Time info that the AVD device is created with. It will be assigned 55 # by the inherited AndroidVirtualDevice. For example: 56 # {"artifact": "100", 57 # "launch_cvd": "120"} 58 self._time_info = time_info 59 60 # Build info that the AVD device is created with. It will be assigned 61 # by the inherited AndroidVirtualDevice. For example: 62 # {"branch": "git_master-release", 63 # "build_id": "5325535", 64 # "build_target": "cf_x86_phone-userdebug", 65 # "gcs_bucket_build_id": "AAAA.190220.001-5325535"} 66 # It can alo have mixed builds' info. For example: 67 # {"branch": "git_master-release", 68 # "build_id": "5325535", 69 # "build_target": "cf_x86_phone-userdebug", 70 # "gcs_bucket_build_id": "AAAA.190220.001-5325535", 71 # "system_branch": "git_master", 72 # "system_build_id": "12345", 73 # "system_build_target": "cf_x86_phone-userdebug", 74 # "system_gcs_bucket_build_id": "12345"} 75 self._build_info = {} 76 self._stage = stage 77 78 @property 79 def ip(self): 80 """Getter of _ip.""" 81 if not self._ip: 82 raise ValueError( 83 "IP of instance %s is unknown yet." % self._instance_name) 84 return self._ip 85 86 @ip.setter 87 def ip(self, value): 88 self._ip = value 89 90 @property 91 def instance_name(self): 92 """Getter of _instance_name.""" 93 return self._instance_name 94 95 @property 96 def build_info(self): 97 """Getter of _build_info.""" 98 return self._build_info 99 100 @property 101 def time_info(self): 102 """Getter of _time_info.""" 103 return self._time_info 104 105 @property 106 def stage(self): 107 """Getter of _stage.""" 108 return self._stage 109 110 @build_info.setter 111 def build_info(self, value): 112 self._build_info = value 113 114 def __str__(self): 115 """Return a string representation.""" 116 return "<ip: (internal: %s, external: %s), instance_name: %s >" % ( 117 self._ip.internal if self._ip else "", 118 self._ip.external if self._ip else "", 119 self._instance_name) 120