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