123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- import file_utils
- import common_utils
- import xml_utils
- import os.path
- import xml.etree.ElementTree as ET
- import zipfile
- namespaces = {'android' : 'http://schemas.android.com/apk/res/android'}
- encoding = 'UTF-8'
- def execute(game, sdk, config):
- if not checkConfig(config):
- return 1
- subChannel = config['subChannel']
- createJmhyProperties(game, sdk, subChannel, config)
- common_utils.changeApplication(game, sdk, subChannel, config, 'com.jmhy.sdk.common.JMXmyApplication')
- decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
- manifest = os.path.join(decompliePath, 'AndroidManifest.xml')
- 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 == 'fusion.mj.communal.element.SplashScreenActivity':
- continue
- removeLauncherActivity = xml_utils.removeLauncherActivityByName(manifest,activityName)
- print('222----> ' + removeLauncherActivity)
- #添加meta-data
- jsonConfig = {}
- meta = {}
- meta['fusion_entryactivity'] = removeLauncherActivity
- jsonConfig['metaData'] = meta
- addMetaData(game, sdk, subChannel, jsonConfig, config['cache'])
- 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
- 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 copySmaliCode(game, sdk, subChannel, config):
- '''
- 拷贝代码
- '''
- print('copy xingmuyou smali')
- sdkPath = file_utils.getFullSDKPath(sdk)
- xmyFile = os.path.join(sdkPath, 'smali')
- decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
- smaliPath = os.path.join(decompliePath, 'smali')
- ret = file_utils.copyFile(xmyFile, smaliPath)
- return ret
|