|
| 1 | +#!/usr/bin/python |
| 2 | +# coding=utf-8 |
| 3 | +import sys |
| 4 | +import zipfile |
| 5 | +import shutil |
| 6 | +import os |
| 7 | +import os.path |
| 8 | +import time |
| 9 | +import datetime |
| 10 | +import json |
| 11 | + |
| 12 | +from xml.dom.minidom import parse |
| 13 | +import xml.dom.minidom |
| 14 | +import codecs |
| 15 | + |
| 16 | + |
| 17 | +sys.path.insert(0,os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
| 18 | +from Common.Platform import Platform |
| 19 | + |
| 20 | +from Common.File.FileUtil import FileUtil |
| 21 | + |
| 22 | +class AndroidManifest(): |
| 23 | + dom=None |
| 24 | + rootXml=None |
| 25 | + application=None |
| 26 | + |
| 27 | + def Load(self,filepath): |
| 28 | + #加载真个文件到内存 |
| 29 | + self.dom=xml.dom.minidom.parse(filepath) |
| 30 | + self.rootXml=self.dom.documentElement |
| 31 | + |
| 32 | + self.application = self.dom.getElementsByTagName('application')[0] |
| 33 | + print("self.application nodeName=",self.application.nodeName) |
| 34 | + |
| 35 | + # root.setAttribute('android:versionCode', versionCode) |
| 36 | + # root.setAttribute('android:versionName', versionName) |
| 37 | + |
| 38 | + #得到包名 |
| 39 | + # package=root.getAttribute('package') |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | + def GetMainActivity(self): |
| 45 | + # #得到所有的Activity |
| 46 | + listActivity= self.dom.getElementsByTagName('activity') |
| 47 | + node = None |
| 48 | + for activity in listActivity: |
| 49 | + if activity.toxml().find("android.intent.action.MAIN")>0 and activity.toxml().find("android.intent.category.LAUNCHER")>0: |
| 50 | + node = activity |
| 51 | + break |
| 52 | + |
| 53 | + print("GetMainActivity nodeName=",node.nodeName) |
| 54 | + return node |
| 55 | + |
| 56 | + |
| 57 | + |
| 58 | + def AddUsesPermission(self,permission,isProtectionLevel = False): |
| 59 | + # # <uses-permission android:name="android.permission.INTERNET"/> |
| 60 | + node = self.dom.createElement("uses-permission") |
| 61 | + #这个属性类似map中key,value |
| 62 | + node.setAttribute("android:name", permission) |
| 63 | + if isProtectionLevel: |
| 64 | + node.setAttribute("android:protectionLevel", "signature") |
| 65 | + # 把大节点info_node挂到根节点root_node下面 |
| 66 | + self.rootXml.appendChild(node) |
| 67 | + |
| 68 | + |
| 69 | + def AddActivity(self,name,isMain,theme): |
| 70 | + nodeActivity = self.dom.createElement("activity") |
| 71 | + |
| 72 | + nodeActivity.setAttribute("android:name", name) |
| 73 | + if len(theme)>0: |
| 74 | + nodeActivity.setAttribute("android:theme", theme) |
| 75 | + |
| 76 | + if isMain: |
| 77 | + node_intent_filter = self.dom.createElement("activity") |
| 78 | + |
| 79 | + node_action = self.dom.createElement("action") |
| 80 | + node_action.setAttribute("android:name", "android.intent.action.MAIN") |
| 81 | + node_intent_filter.appendChild(node_action) |
| 82 | + |
| 83 | + |
| 84 | + node_category = self.dom.createElement("category") |
| 85 | + node_category.setAttribute("android:name", "android.intent.category.LAUNCHER") |
| 86 | + node_intent_filter.appendChild(node_category) |
| 87 | + |
| 88 | + |
| 89 | + nodeActivity.appendChild(node_intent_filter) |
| 90 | + |
| 91 | + |
| 92 | + # <intent-filter> |
| 93 | + # <action android:name="android.intent.action.MAIN"/> |
| 94 | + # <category android:name="android.intent.category.LAUNCHER"/> |
| 95 | + # </intent-filter> |
| 96 | + |
| 97 | + |
| 98 | + self.application.appendChild(nodeActivity) |
| 99 | + |
| 100 | + |
| 101 | + def ConfigSellMyApp(self,package): |
| 102 | + self.application.setAttribute('android:usesCleartextTraffic', "true") |
| 103 | + |
| 104 | + # <uses-permission android:name="android.permission.INTERNET"/> |
| 105 | + # <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> |
| 106 | + # <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> |
| 107 | + # <uses-permission android:name="android.permission.READ_PHONE_STATE"/> |
| 108 | + # <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> |
| 109 | + # <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> |
| 110 | + # <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/> |
| 111 | + # <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/> |
| 112 | + # <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/> |
| 113 | + |
| 114 | + # <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> |
| 115 | + # <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> |
| 116 | + |
| 117 | + listPermission =["INTERNET","ACCESS_NETWORK_STATE","ACCESS_WIFI_STATE","READ_PHONE_STATE","ACCESS_COARSE_LOCATION","ACCESS_FINE_LOCATION","REQUEST_INSTALL_PACKAGES","CHANGE_NETWORK_STATE","QUERY_ALL_PACKAGES","READ_EXTERNAL_STORAGE","WRITE_EXTERNAL_STORAGE"] |
| 118 | + for strtmp in listPermission: |
| 119 | + self.AddUsesPermission("android.permission."+strtmp) |
| 120 | + |
| 121 | + |
| 122 | + # <permission android:name="com.unconditionalgames.waterpuzzle.permission.KW_SDK_BROADCAST" android:protectionLevel="signature"/> |
| 123 | + self.AddUsesPermission(package+".permission."+"KW_SDK_BROADCAST",True) |
| 124 | + # <uses-permission android:name="com.unconditionalgames.waterpuzzle.permission.KW_SDK_BROADCAST"/> |
| 125 | + self.AddUsesPermission(package+".permission."+"KW_SDK_BROADCAST",False) |
| 126 | + |
| 127 | + |
| 128 | + |
| 129 | + |
| 130 | + # <activity android:name=".AdSplashActivity" android:theme="@style/UnityThemeSelector"> |
| 131 | + # <intent-filter> |
| 132 | + # <action android:name="android.intent.action.MAIN"/> |
| 133 | + # <category android:name="android.intent.category.LAUNCHER"/> |
| 134 | + # </intent-filter> |
| 135 | + # </activity> |
| 136 | + |
| 137 | + mainAc = self.GetMainActivity() |
| 138 | + # child = mainAc.getElementsByTagName('intent-filter')[0] |
| 139 | + child = mainAc.childNodes[0] |
| 140 | + # author=dom.getElementsByTagName('author')[0].childNodes[0].data |
| 141 | + if child is not None: |
| 142 | + mainAc.removeChild(child) |
| 143 | + |
| 144 | + self.AddActivity(".AdSplashActivity",True,"@style/UnityThemeSelector") |
| 145 | + |
| 146 | + |
| 147 | + |
| 148 | + |
| 149 | + # <!-- gdt ad --> |
| 150 | + # <service android:exported="false" android:multiprocess="true" android:name="com.qq.e.comm.DownloadService"/> |
| 151 | + # <activity android:configChanges="keyboard|keyboardHidden|orientation|screenSize" android:multiprocess="true" android:name="com.qq.e.ads.ADActivity"/> |
| 152 | + # <activity android:configChanges="keyboard|keyboardHidden|orientation|screenSize" android:multiprocess="true" android:name="com.qq.e.ads.PortraitADActivity" android:screenOrientation="portrait"/> |
| 153 | + # <activity android:configChanges="keyboard|keyboardHidden|orientation|screenSize" android:multiprocess="true" android:name="com.qq.e.ads.LandscapeADActivity" android:screenOrientation="sensorLandscape"/> |
| 154 | + # <activity android:configChanges="keyboard|keyboardHidden|orientation|screenSize" android:multiprocess="true" android:name="com.qq.e.ads.RewardvideoPortraitADActivity" android:theme="@android:style/Theme.Light.NoTitleBar"> |
| 155 | + # <meta-data android:name="android.notch_support" android:value="true"/> |
| 156 | + # </activity> |
| 157 | + # <activity android:configChanges="keyboard|keyboardHidden|orientation|screenSize" android:multiprocess="true" android:name="com.qq.e.ads.RewardvideoLandscapeADActivity" android:screenOrientation="landscape" android:theme="@android:style/Theme.Light.NoTitleBar"> |
| 158 | + # <meta-data android:name="android.notch_support" android:value="true"/> |
| 159 | + # </activity> |
| 160 | + # <activity android:configChanges="keyboardHidden|orientation|screenSize" android:name="com.kwad.sdk.page.KsAdWebViewActivity" android:screenOrientation="portrait"/> |
| 161 | + # <activity android:configChanges="keyboardHidden|orientation|screenSize" android:name="com.kwad.sdk.page.VideoWebViewActivity" android:screenOrientation="portrait" android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen"/> |
| 162 | + # <activity android:configChanges="keyboardHidden|orientation|screenSize" android:name="com.kwad.sdk.page.KsFullScreenVideoActivity" android:screenOrientation="portrait" android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen"/> |
| 163 | + # <activity android:configChanges="keyboardHidden|orientation|screenSize" android:name="com.kwad.sdk.page.KSRewardVideoActivity" android:screenOrientation="portrait" android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen"/> |
| 164 | + # <provider android:authorities="com.unconditionalgames.waterpuzzle.adFileProvider" android:exported="false" android:grantUriPermissions="true" android:name="com.kwad.sdk.widget.AdSdkFileProvider"> |
| 165 | + # <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/ksad_file_paths"/> |
| 166 | + # </provider> |
| 167 | + # <receiver android:exported="true" android:name="com.ksad.download.DownloadReceiver"> |
| 168 | + # <intent-filter> |
| 169 | + # <action android:name="download.intent.action.DOWNLOAD_PAUSE"/> |
| 170 | + # </intent-filter> |
| 171 | + # <intent-filter> |
| 172 | + # <action android:name="download.intent.action.DOWNLOAD_RESUME"/> |
| 173 | + # </intent-filter> |
| 174 | + # <intent-filter> |
| 175 | + # <action android:name="download.intent.action.DOWNLOAD_CANCEL"/> |
| 176 | + # </intent-filter> |
| 177 | + # </receiver> |
| 178 | + # <service android:name="com.kwai.filedownloader.services.FileDownloadService$SharedMainProcessService"/> |
| 179 | + # <service android:name="com.kwai.filedownloader.services.FileDownloadService$SeparateProcessService" android:process=":filedownloader"/> |
| 180 | + # <service android:exported="false" android:name="com.ksad.download.service.DownloadService"/> |
| 181 | + # <service android:enabled="false" android:name="com.squareup.leakcanary.internal.HeapAnalyzerService" android:process=":leakcanary"/> |
| 182 | + # <service android:enabled="false" android:name="com.squareup.leakcanary.DisplayLeakService" android:process=":leakcanary"/> |
| 183 | + # <provider android:authorities="com.squareup.leakcanary.fileprovider.com.unconditionalgames.waterpuzzle" android:exported="false" android:grantUriPermissions="true" android:name="com.squareup.leakcanary.internal.LeakCanaryFileProvider"> |
| 184 | + # <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/leak_canary_file_paths"/> |
| 185 | + # </provider> |
| 186 | + # <activity android:enabled="false" android:icon="@mipmap/app_icon" android:label="@string/app_name" android:name="com.squareup.leakcanary.internal.DisplayLeakActivity" android:process=":leakcanary" android:taskAffinity="com.squareup.leakcanary.com.unconditionalgames.waterpuzzle" > |
| 187 | + # <intent-filter> |
| 188 | + # <action android:name="android.intent.action.MAIN"/> |
| 189 | + # <category android:name="android.intent.category.LAUNCHER"/> |
| 190 | + # </intent-filter> |
| 191 | + # </activity> |
| 192 | + # <activity android:enabled="false" android:excludeFromRecents="true" android:icon="@mipmap/app_icon" android:label="@string/app_name" android:name="com.squareup.leakcanary.internal.RequestStoragePermissionActivity" android:process=":leakcanary" android:roundIcon="@mipmap/app_icon" android:taskAffinity="com.squareup.leakcanary.com.unconditionalgames.waterpuzzle" /> |
| 193 | + |
| 194 | + # <!-- gdt ad end--> |
| 195 | + |
| 196 | + |
| 197 | + |
| 198 | + def SaveXml(self,filepath): |
| 199 | + # FileUtil.SaveString2File(self.dom.toxml(),filepath) |
| 200 | + # f = open(filepath, "w") |
| 201 | + # writer = codecs.lookup('utf-8')[3](f) |
| 202 | + # self.dom.writexml(writer, newl='', indent='\n', encoding='utf-8') |
| 203 | + # writer.close() |
| 204 | + # f.close() |
| 205 | + fileHandle = open(filepath, 'w') |
| 206 | + # 写入操作,第二个参数为缩进(加在每行结束后),第三个为增量缩进(加在每行开始前并增量) |
| 207 | + self.dom.writexml(fileHandle, '\n', ' ', '', 'UTF-8') |
| 208 | + fileHandle.close() |
| 209 | + |
| 210 | +mainAndroidManifest = AndroidManifest() |
0 commit comments