123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- import file_utils
- import xml_utils
- import common_utils
- import os.path
- import xml.etree.ElementTree as ET
- encoding = 'UTF-8'
- namespaces = {'android' : 'http://schemas.android.com/apk/res/android'}
- def execute(game, sdk, config):
- if not checkConfig(config):
- return 1
- subChannel = config['subChannel']
- createJmhyProperties(game, sdk, subChannel, config)
- decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
- manifest = os.path.join(decompliePath, 'AndroidManifest.xml')
- # xml_utils.changeLauncherAttr(manifest, 'configChanges', 'orientation|screenSize|keyboardHidden')
- activitys = xml_utils.getLauncherActivitys(manifest)
- attrName = xml_utils.getNamespacesFormat('android:name', namespaces)
- #修改原启动Activity
- for activity in activitys:
- activityName = activity.attrib[attrName]
- print ('activityName ----> ' + activityName)
- if activityName == 'com.lenovo.lsf.gamesdk.ui.WelcomeActivity':
- continue
- else : #游戏、渠道共2个启动类 非渠道WelcomeActivity的 则执行操作 目的:launcher属性改掉 默认启动渠道的闪屏欢迎页 跳到action为Lenovo.MAIN的游戏启动类
- removeLauncherActivity = changeLauncherActivityByName(manifest,activityName)
- print('removeLauncherAct---------> ' + removeLauncherActivity)
- return 0
- def changeLauncherActivityByName(manifest,name):
- for key in namespaces:
- ET.register_namespace(key, namespaces[key])
- tree = ET.parse(manifest)
- root = tree.getroot()
- attrName = xml_utils.getNamespacesFormat('android:name', namespaces)
- for node in root.findall('application/activity'):
- print('node ----> ' + node.attrib[attrName])
- if node.attrib[attrName] != name:
- continue
- for sub in node.getchildren():
- if sub.tag != 'intent-filter':
- continue
- for sub2 in sub.getchildren():
- if (sub2.tag == 'action' and sub2.attrib[attrName] == 'android.intent.action.MAIN'):
- sub2.attrib[attrName]='lenovoid.MAIN'
- if (sub2.tag == 'category' and sub2.attrib[attrName] == 'android.intent.category.LAUNCHER'):
- sub2.attrib[attrName]='android.intent.category.DEFAULT'
- tree.write(manifest, encoding)
- return node.attrib[attrName]
- return 0
- def checkConfig(config):
- '''
- 检查配置
- '''
- if 'properties' not in config:
- print('properties not exists in config')
- return False
- properties = config['properties']
- if 'agent' not in properties or 'version' not in properties:
- print('agent or version not exists in properties')
- return False
- '''if 'appid' not in config or 'appkey' not in config:
- print('appid or appkey not exists in config')
- return False'''
- return True
- def createJmhyProperties(game, sdk, subChannel, config):
- '''
- 创建jmhy.properties
- '''
- print('create jmhy.properties')
- propValue = config['properties']
- decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
- properties = os.path.join(decompliePath, 'assets', 'jmhy.properties')
- content = ''
- for key in propValue:
- content = '%s%s=%s\n' % (content, key, propValue[key])
- file_utils.createFile(properties, content)
- return 0
- def addMetaData(game, sdk, subChannel, config, path):
- '''
- 添加meta-data
- '''
- if 'metaData' not in config:
- return 0
- print('add meta-data...')
- decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, path)
- manifest = os.path.join(decompliePath, 'AndroidManifest.xml')
- xml_utils.addMetaData(manifest, config['metaData'])
- return 0
- def addLauncherActivity(manifest, screenOrientation, activity):
- '''
- 添加启动的activity
- '''
- for key in namespaces:
- ET.register_namespace(key, namespaces[key])
- tree = ET.parse(manifest)
- root = tree.getroot()
- # activity
- '''<activity android:name=".LauncherActivity"
- android:theme="@style/LauncherStyle">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>'''
- activity = ET.Element('activity', {'android:name' : activity,
- 'android:theme' : '@android:style/Theme.Holo.Light.NoActionBar.Fullscreen',
- 'android:launchMode' : 'singleTop',
- 'android:configChanges' : 'orientation|screenSize|keyboardHidden',
- 'android:screenOrientation' : screenOrientation})
- intent = ET.Element('intent-filter')
- action = ET.Element('action', {'android:name' : 'lenovoid.MAIN'})
- category = ET.Element('category', {'android:name' : 'android.intent.category.DEFAULT'})
- intent.append(action)
- intent.append(category)
- activity.append(intent)
- application = root.find('application')
- application.insert(0, activity)
- tree.write(manifest, encoding)
|