版权声明:本文为博主原创文章,未经博主允许可以转载。 https://blog.csdn.net/guokaigdg/article/details/82586090
import commands
import string
import random
import os
'''
Created on May 31, 2018
@author: lihui
'''
def getSimType(self, sim):
'''
Get call number according to sim type.
@param sim: sim1 or sim2
@return: sim type
'''
operator_type = commands.getoutput('adb shell getprop gsm.operator.alpha').split('\r')[0]
print operator_type
operator_type.split(',')
if sim == 'sim1':
sim = operator_type.split(',')[0]
elif sim == 'sim2':
sim = operator_type.split(',')[1]
if sim == 'CHN-UNICOM' or sim == 'China Unicom':
return '10010'
elif sim == 'CMCC':
return '10086'
elif sim == '\xe4\xb8\xad\xe5\x9b\xbd\xe7\x94\xb5\xe4\xbf\xa1':
return '10000'
else:
raise Exception,'Unkonwn operator type, please check your sim card!'
def getFileCount(folder, ext):
'''
Get file count.
@param folder: file path
ext: file type
@return: file count
'''
cmd = 'adb shell ls %s'%(folder)
pipe = os.popen(cmd, 'r')
result = pipe.read()
num = result.count(ext)
print '-----------', num, '-----------'
return num
def getPID(name):
'''
Get process pid.
@param name: process name
@return: pid
'''
pid = commands.getoutput("adb shell ps | grep %s | awk '{print $2}'"%name)
return pid
def getRandomString(strLenght = 6):
'''
Get a random string.
@param strLenght: length of string
@return: a random string
'''
a = list(string.ascii_letters)
random.shuffle(a)
return ''.join(a[:strLenght])
def clearData(app):
'''
Clear app database.
@param app: related app name
available: Notes, Notification, Calendar, Alarm, Mms, Contact, CallLog, Bookmark, Downloads
'''
os.system("adb shell am startservice -a smartisan.datahelper.InitData --es type %s --es method 'clear'" % app)