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 34logger = logging.getLogger(__name__) 35 36 37class AndroidVirtualDevice(object): 38 """Represent an Android device.""" 39 40 def __init__(self, instance_name, ip=None): 41 """Initialize. 42 43 Args: 44 instance_name: Name of the gce instance, e.g. "instance-1" 45 ip: namedtuple (internal, external) that holds IP address of the 46 gce instance, e.g. "external:140.110.20.1, internal:10.0.0.1" 47 """ 48 self._ip = ip 49 self._instance_name = instance_name 50 51 @property 52 def ip(self): 53 """Getter of _ip.""" 54 if not self._ip: 55 raise ValueError( 56 "IP of instance %s is unknown yet." % self._instance_name) 57 return self._ip 58 59 @ip.setter 60 def ip(self, value): 61 self._ip = value 62 63 @property 64 def instance_name(self): 65 """Getter of _instance_name.""" 66 return self._instance_name 67 68 def __str__(self): 69 """Return a string representation.""" 70 return "<ip: (internal: %s, external: %s), instance_name: %s >" % ( 71 self._ip.internal if self._ip else "", 72 self._ip.external if self._ip else "", 73 self._instance_name) 74