123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- from V2 import file_utils
- import os
- from V2.print_log import printlog
- from xml.etree import ElementTree as ET
- from xml.etree.ElementTree import SubElement
- androidNS = 'http://schemas.android.com/apk/res/android'
- scheme = '{' + androidNS + '}scheme'
- name_key = '{' + androidNS + '}name'
- def HuaweiReplace(prj_path, key, value):
- if key == 'agconnect-services.json':
- printlog('replace huawei agconnect-services.json')
- huawei_sdk_config_path = os.path.join(prj_path, 'assets', key)
- file_utils.copy_file(value, huawei_sdk_config_path)
- pass
- def YingYongBaoReplace(prj_path, key, value):
- if key == "IS_SAND_BOX":
- ysdk_sand_url = "https://ysdktest.qq.com"
- ysdk_online_url = "https://ysdk.qq.com"
- if value == "1":
- ysdk_url = ysdk_sand_url
- else:
- ysdk_url = ysdk_online_url
- file_utils.replace_assets_param("%s/assets/ysdkconf.ini" % prj_path, "YSDK_URL", ysdk_url)
- return
- if key == "QQ_APP_ID" or key == "WX_APP_ID":
- manifest = os.path.join(prj_path, 'AndroidManifest.xml')
- ysdk_conf_path = os.path.join(prj_path, 'assets', 'ysdkconf.ini')
- ET.register_namespace('android', androidNS)
- tree = ET.parse(manifest)
- root = tree.getroot()
- appNode = root.find('application')
- if appNode is None:
- return 1
- metaNodeList = appNode.findall('meta-data')
- if metaNodeList is None:
- return 1
- activityNodeList = appNode.findall('activity')
- if activityNodeList is None:
- return 1
- for activityNode in activityNodeList:
- activityName = activityNode.get(name_key)
- if activityName == 'com.tencent.tauth.AuthActivity' and key == "QQ_APP_ID":
- intentFilters = activityNode.findall('intent-filter')
- if intentFilters is not None and len(intentFilters) > 0:
- for intentNode in intentFilters:
- dataNode = intentNode.find('data')
- intentNode.remove(dataNode)
- dataNode = SubElement(intentNode, 'data')
- dataNode.set(scheme, 'tencent' + value)
- printlog("path ysdkconfig.ini:%s" % ysdk_conf_path)
- file_utils.replace_assets_param(ysdk_conf_path, key, value)
- file_utils.replace_assets_param(ysdk_conf_path, 'OFFER_ID', value)
- for metaNode in metaNodeList:
- name = metaNode.get(key)
- if name == 'MAIN_ACTIVITY':
- metaNode.set(value, 'com.ftt.hwal2.gl.cn.chinamain.ChinaMainActivity')
- break
- if activityName == 'com.tencent.ysdk.module.user.impl.freelogin.FreeLoginInfoActivity'\
- and key == "QQ_APP_ID":
- intentFilters = activityNode.findall('intent-filter')
- if intentFilters is not None and len(intentFilters) > 0:
- for intentNode in intentFilters:
- dataNode = intentNode.find('data')
- intentNode.remove(dataNode)
- dataNode = SubElement(intentNode, 'data')
- dataNode.set(scheme, 'tencentysdk' + value)
- if activityName == 'com.tencent.ysdk.module.user.impl.freelogin.FreeLoginInfoActivity'\
- and key == "WX_APP_ID":
- intentFilters = activityNode.findall('intent-filter')
- if intentFilters is not None and len(intentFilters) > 0:
- for intentNode in intentFilters:
- dataNode = intentNode.find('data')
- intentNode.remove(dataNode)
- dataNode = SubElement(intentNode, 'data')
- dataNode.set(scheme, 'tencentysdk' + value)
- if activityName.endswith('WXEntryActivity') and key == "WX_APP_ID":
- intentFilters = activityNode.findall('intent-filter')
- if intentFilters is not None and len(intentFilters) > 0:
- for intentNode in intentFilters:
- dataNode = intentNode.find('data')
- intentNode.remove(dataNode)
- dataNode = SubElement(intentNode, 'data')
- dataNode.set(scheme, value)
- file_utils.replace_assets_param(ysdk_conf_path, key, value)
- tree.write(manifest, 'UTF-8')
- specialReplace = {
- "huawei": HuaweiReplace,
- "yingyongbao": YingYongBaoReplace
- }
- def get_special_replace(sdk_name):
- if sdk_name in specialReplace:
- return specialReplace[sdk_name]
- else:
- return None
- pass
|