1# Copyright 2013 The Android Open Source Project 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15import subprocess 16import unittest 17 18 19class Error(Exception): 20 pass 21 22 23class SocketError(Error): 24 25 def __init__(self, device_id, message): 26 """Exception raised for socket errors. 27 28 Args: 29 device_id (str): device id 30 message (str): explanation of the error 31 """ 32 Error.__init__(self) 33 self.message = message 34 locale = self.get_device_locale(device_id) 35 if locale != "en-US": 36 print "Unsupported default language %s" % locale 37 print "Please set the default language to English (United States)" 38 print "in Settings > Language & input > Languages\n" 39 40 def get_device_locale(self, device_id): 41 """Return the default locale of a given device. 42 43 Args: 44 device_id (str): device id 45 46 Returns: 47 str: Device locale. 48 """ 49 locale_property = "persist.sys.locale" 50 51 com = ("adb -s %s shell getprop %s" % (device_id, locale_property)) 52 proc = subprocess.Popen(com.split(), stdout=subprocess.PIPE) 53 output, error = proc.communicate() 54 assert error is None 55 56 return output 57 58 59class __UnitTest(unittest.TestCase): 60 """Run a suite of unit tests on this module. 61 """ 62 63if __name__ == "__main__": 64 unittest.main() 65 66