{"id":819,"date":"2025-01-24T15:53:37","date_gmt":"2025-01-24T07:53:37","guid":{"rendered":"https:\/\/iichen.cn\/?p=819"},"modified":"2025-01-24T15:53:38","modified_gmt":"2025-01-24T07:53:38","slug":"python-manifest%e6%96%87%e4%bb%b6%e6%b3%a8%e5%85%a5%e5%92%8c%e6%89%b9%e9%87%8fadb%e5%ae%89%e8%a3%85%e5%ba%94%e7%94%a8","status":"publish","type":"post","link":"https:\/\/iichen.cn\/?p=819","title":{"rendered":"Python-Manifest\u6587\u4ef6\u6ce8\u5165\u548c\u6279\u91cfADB\u5b89\u88c5\u5e94\u7528"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Manifest.xml\u6587\u4ef6\u6ce8\u5165\u4fee\u6539<\/h2>\n\n\n\n<pre class=\"wp-block-code language-dart lines-number has-small-font-size\"><code>def injectManifest(dump: GameDump):\n    # \u89e3\u5305\u540e\u7684 AndroidManifest.xml \u8def\u5f84\n    manifest_path = dump.get_android_manifest_xml_path()\n    ET.register_namespace('android', 'http:\/\/schemas.android.com\/apk\/res\/android')\n    # manifest_path = r'C:\\Users\\shubao67\\Desktop\\ybtjd\\AndroidManifest.xml'\n\n    print(manifest_path)\n\n    # # \u89e3\u6790 XML \u6587\u4ef6\n    tree = ET.parse(manifest_path)\n    root = tree.getroot()\n\n    manifest = dump.get_manifest()\n    print('injectManifest package_name:', manifest.get_package_name())\n\n    # \u5b9a\u4e49\u8981\u6dfb\u52a0\u7684 &lt;provider> \u5143\u7d20\uff0c\u66ff\u6362\u547d\u540d\u7a7a\u95f4\u524d\u7f00 \u7528\u4e8e\u611f\u77e5\u751f\u547d\u5468\u671f\n    provider = ET.Element('provider')\n    provider.set(f'android:name', 'com.ssy185.sdk.common.base.lifecycle.GmLifecycleInitializer')\n    provider.set(f'android:authorities', f'{manifest.get_package_name()}.GmLifecycleInitializer')\n    provider.set(f'android:exported', 'false')\n    provider.set(f'android:multiprocess', 'true')\n\n    service = ET.Element('service')\n    service.set(f'android:name', 'com.ssy185.sdk.feature.record.ScreenRecordService')\n    service.set(f'android:foregroundServiceType', 'mediaProjection')\n    # service.set(f'tools:targetApi', 'q')\n\n    # &lt; uses - permission android: name = \"android.permission.SYSTEM_ALERT_WINDOW\" \/ >\n    alert_window_permission = ET.Element('uses-permission')\n    alert_window_permission.set(f'android:name', 'android.permission.SYSTEM_ALERT_WINDOW')\n\n    record_audio_permission = ET.Element('uses-permission')\n    record_audio_permission.set(f'android:name', 'android.permission.RECORD_AUDIO')\n\n    foreground_service_permission = ET.Element('uses-permission')\n    foreground_service_permission.set(f'android:name', 'android.permission.FOREGROUND_SERVICE')\n\n    foreground_service_media_projection_permission = ET.Element('uses-permission')\n    foreground_service_media_projection_permission.set(f'android:name', 'android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION')\n\n\n    # \u67e5\u627e &lt;application> \u6807\u7b7e\u5e76\u6dfb\u52a0 &lt;provider> \u5143\u7d20\n    application = root.find('application')\n    if application is not None:\n        application.append(provider)\n        application.append(service)\n        request_legacy_external_storage = application.attrib.get(\"{http:\/\/schemas.android.com\/apk\/res\/android}requestLegacyExternalStorage\")\n        if request_legacy_external_storage is None:\n            # \u5982\u679c\u6ca1\u6709\u8be5\u5c5e\u6027\uff0c\u6dfb\u52a0\u5e76\u8bbe\u7f6e\u4e3a true\n            application.set('android:requestLegacyExternalStorage', 'true')\n            print(\"\u5c5e\u6027 'android:requestLegacyExternalStorage' \u5df2\u6dfb\u52a0\u5e76\u8bbe\u7f6e\u4e3a true\")\n        else:\n            print(\"\u5c5e\u6027 'android:requestLegacyExternalStorage' \u5df2\u5b58\u5728\")\n    root.append(alert_window_permission)\n    root.append(record_audio_permission)\n    root.append(foreground_service_permission)\n    root.append(foreground_service_media_projection_permission)\n\n    activities = application.findall('activity')\n    # \u904d\u5386\u6240\u6709Activity \u5c0f\u7a97\u6a21\u5f0f\u9700\u8981resizeableActivity \u4e3a true\n    for activity in activities:\n        resizeable_activity_attr = '{http:\/\/schemas.android.com\/apk\/res\/android}resizeableActivity'\n        if resizeable_activity_attr in activity.attrib:\n            print('injectManifest modify resizeableActivity to true is success!')\n            activity.set(resizeable_activity_attr, 'true')\n\n    # \u5c06\u4fee\u6539\u540e\u7684 XML \u4fdd\u5b58\u56de\u6587\u4ef6\n    tree.write(manifest_path, encoding='utf-8', xml_declaration=True)\n    print(f\"Provider added successfully to AndroidManifest.xml\")\nif __name__ == '__main__':\n    injectManifest(None)\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u6279\u91cfADB\u5b89\u88c5\u5e94\u7528<\/h2>\n\n\n\n<pre class=\"wp-block-code language-dart lines-number has-small-font-size\"><code>def process_file(file_path):\n    \"\"\"\n    \u5904\u7406\u6bcf\u4e2a\u6587\u4ef6\u7684\u51fd\u6570\uff0c\u6267\u884c inject_web.main \u547d\u4ee4\n    \"\"\"\n    command = &#91;\"adb\", \"install\", file_path]\n    print(f\"\u6b63\u5728\u5904\u7406: {file_path}\")\n    subprocess.run(command)\n\n\ndef foldInject(folder_paths, max_concurrent_tasks):\n    \"\"\"\n    \u904d\u5386\u591a\u4e2a\u6587\u4ef6\u5939\u8def\u5f84\uff0c\u6279\u91cf\u5904\u7406 APK \u6587\u4ef6\uff0c\u9650\u5236\u6bcf\u6b21\u6700\u591a\u5e76\u53d1\u6267\u884c `max_concurrent_tasks` \u4e2a\u4efb\u52a1\u3002\n    \"\"\"\n    # \u521b\u5efa\u4e00\u4e2a\u7ebf\u7a0b\u6c60\uff0cmax_concurrent_tasks \u786e\u5b9a\u6bcf\u6b21\u6700\u591a\u5e76\u53d1\u7684\u4efb\u52a1\u6570\n    with ThreadPoolExecutor(max_workers=max_concurrent_tasks) as executor:\n        futures = &#91;]  # \u7528\u4e8e\u5b58\u50a8\u6240\u6709\u4efb\u52a1\u7684\u672a\u6765\u5bf9\u8c61\n\n        for folder_path in folder_paths:\n            # \u786e\u4fdd folder_path \u662f\u4e00\u4e2a\u6709\u6548\u8def\u5f84\n            folder_path = Path(folder_path)\n            if not folder_path.is_dir():\n                print(f\"\u8b66\u544a: \u8def\u5f84 {folder_path} \u4e0d\u662f\u6709\u6548\u7684\u76ee\u5f55\u3002\u8df3\u8fc7...\")\n                continue\n\n            # \u904d\u5386\u76ee\u5f55\u4e2d\u7684\u6587\u4ef6\n            for root, dirs, files in os.walk(folder_path):\n                for file in files:\n                    # \u8fd9\u91cc\u53ef\u4ee5\u6839\u636e\u9700\u8981\u7b5b\u9009\u6587\u4ef6\u7c7b\u578b\uff0c\u4f8b\u5982\u53ea\u5904\u7406 .apk \u6587\u4ef6\n                    if file.endswith(\"_patched_signed.apk\"):\n                        file_path = os.path.join(root, file)\n                        # \u63d0\u4ea4\u6bcf\u4e2a\u6587\u4ef6\u7684\u5904\u7406\u4efb\u52a1\u5230\u7ebf\u7a0b\u6c60\n                        futures.append(executor.submit(process_file, file_path))\n\n        # \u4f7f\u7528 wait \u6765\u786e\u4fdd\u6bcf\u6279\u4efb\u52a1\u5b8c\u6210\u540e\u518d\u7ee7\u7eed\u4e0b\u4e00\u6279\n        while futures:\n            # \u7b49\u5f85\u6700\u591a `max_concurrent_tasks` \u4e2a\u4efb\u52a1\u5b8c\u6210\n            done, futures = wait(futures, return_when=\"FIRST_COMPLETED\")\nif __name__ == '__main__':\n    # \u6587\u4ef6\u5939\u8def\u5f84\u6570\u7ec4\n    folder_paths = &#91;\n        r\"E:\\game\\webView2\\test\",\n        # r\"E:\\game\\webView3\"\n    ]\n    # \u8bbe\u7f6e\u6bcf\u6279\u6700\u591a\u5e76\u53d1\u6267\u884c 5 \u4e2a\u4efb\u52a1\n    foldInject(folder_paths, max_concurrent_tasks=5)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Manifest.xml\u6587\u4ef6\u6ce8\u5165\u4fee\u6539 \u6279\u91cfADB\u5b89\u88c5\u5e94\u7528<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15,8],"tags":[],"class_list":["post-819","post","type-post","status-publish","format-standard","hentry","category-python","category-8"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python-Manifest\u6587\u4ef6\u6ce8\u5165\u548c\u6279\u91cfADB\u5b89\u88c5\u5e94\u7528 - IIchen<\/title>\n<meta name=\"description\" content=\"Python-Manifest\u6587\u4ef6\u6ce8\u5165\u548c\u6279\u91cfADB\u5b89\u88c5\u5e94\u7528\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/iichen.cn\/?p=819\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python-Manifest\u6587\u4ef6\u6ce8\u5165\u548c\u6279\u91cfADB\u5b89\u88c5\u5e94\u7528 - IIchen\" \/>\n<meta property=\"og:description\" content=\"Python-Manifest\u6587\u4ef6\u6ce8\u5165\u548c\u6279\u91cfADB\u5b89\u88c5\u5e94\u7528\" \/>\n<meta property=\"og:url\" content=\"https:\/\/iichen.cn\/?p=819\" \/>\n<meta property=\"og:site_name\" content=\"IIchen\" \/>\n<meta property=\"article:published_time\" content=\"2025-01-24T07:53:37+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-01-24T07:53:38+00:00\" \/>\n<meta name=\"author\" content=\"iichen\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"iichen\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/iichen.cn\/?p=819#article\",\"isPartOf\":{\"@id\":\"https:\/\/iichen.cn\/?p=819\"},\"author\":{\"name\":\"iichen\",\"@id\":\"https:\/\/iichen.cn\/#\/schema\/person\/4a47edf85ab49841df9e8f6aee40b77c\"},\"headline\":\"Python-Manifest\u6587\u4ef6\u6ce8\u5165\u548c\u6279\u91cfADB\u5b89\u88c5\u5e94\u7528\",\"datePublished\":\"2025-01-24T07:53:37+00:00\",\"dateModified\":\"2025-01-24T07:53:38+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/iichen.cn\/?p=819\"},\"wordCount\":5,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/iichen.cn\/#\/schema\/person\/4a47edf85ab49841df9e8f6aee40b77c\"},\"articleSection\":[\"Python\",\"\u7b14\u8bb0\"],\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/iichen.cn\/?p=819#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/iichen.cn\/?p=819\",\"url\":\"https:\/\/iichen.cn\/?p=819\",\"name\":\"Python-Manifest\u6587\u4ef6\u6ce8\u5165\u548c\u6279\u91cfADB\u5b89\u88c5\u5e94\u7528 - IIchen\",\"isPartOf\":{\"@id\":\"https:\/\/iichen.cn\/#website\"},\"datePublished\":\"2025-01-24T07:53:37+00:00\",\"dateModified\":\"2025-01-24T07:53:38+00:00\",\"description\":\"Python-Manifest\u6587\u4ef6\u6ce8\u5165\u548c\u6279\u91cfADB\u5b89\u88c5\u5e94\u7528\",\"breadcrumb\":{\"@id\":\"https:\/\/iichen.cn\/?p=819#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/iichen.cn\/?p=819\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/iichen.cn\/?p=819#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/iichen.cn\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python-Manifest\u6587\u4ef6\u6ce8\u5165\u548c\u6279\u91cfADB\u5b89\u88c5\u5e94\u7528\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/iichen.cn\/#website\",\"url\":\"https:\/\/iichen.cn\/\",\"name\":\"IIchen\",\"description\":\"Just do it!\",\"publisher\":{\"@id\":\"https:\/\/iichen.cn\/#\/schema\/person\/4a47edf85ab49841df9e8f6aee40b77c\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/iichen.cn\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"zh-Hans\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/iichen.cn\/#\/schema\/person\/4a47edf85ab49841df9e8f6aee40b77c\",\"name\":\"iichen\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/iichen.cn\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/iichen.cn\/wp-content\/uploads\/2025\/01\/avatar.jpg\",\"contentUrl\":\"https:\/\/iichen.cn\/wp-content\/uploads\/2025\/01\/avatar.jpg\",\"width\":940,\"height\":940,\"caption\":\"iichen\"},\"logo\":{\"@id\":\"https:\/\/iichen.cn\/#\/schema\/person\/image\/\"},\"sameAs\":[\"https:\/\/www.iichen.cn\"],\"url\":\"https:\/\/iichen.cn\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python-Manifest\u6587\u4ef6\u6ce8\u5165\u548c\u6279\u91cfADB\u5b89\u88c5\u5e94\u7528 - IIchen","description":"Python-Manifest\u6587\u4ef6\u6ce8\u5165\u548c\u6279\u91cfADB\u5b89\u88c5\u5e94\u7528","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/iichen.cn\/?p=819","og_locale":"zh_CN","og_type":"article","og_title":"Python-Manifest\u6587\u4ef6\u6ce8\u5165\u548c\u6279\u91cfADB\u5b89\u88c5\u5e94\u7528 - IIchen","og_description":"Python-Manifest\u6587\u4ef6\u6ce8\u5165\u548c\u6279\u91cfADB\u5b89\u88c5\u5e94\u7528","og_url":"https:\/\/iichen.cn\/?p=819","og_site_name":"IIchen","article_published_time":"2025-01-24T07:53:37+00:00","article_modified_time":"2025-01-24T07:53:38+00:00","author":"iichen","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"iichen","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/iichen.cn\/?p=819#article","isPartOf":{"@id":"https:\/\/iichen.cn\/?p=819"},"author":{"name":"iichen","@id":"https:\/\/iichen.cn\/#\/schema\/person\/4a47edf85ab49841df9e8f6aee40b77c"},"headline":"Python-Manifest\u6587\u4ef6\u6ce8\u5165\u548c\u6279\u91cfADB\u5b89\u88c5\u5e94\u7528","datePublished":"2025-01-24T07:53:37+00:00","dateModified":"2025-01-24T07:53:38+00:00","mainEntityOfPage":{"@id":"https:\/\/iichen.cn\/?p=819"},"wordCount":5,"commentCount":0,"publisher":{"@id":"https:\/\/iichen.cn\/#\/schema\/person\/4a47edf85ab49841df9e8f6aee40b77c"},"articleSection":["Python","\u7b14\u8bb0"],"inLanguage":"zh-Hans","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/iichen.cn\/?p=819#respond"]}]},{"@type":"WebPage","@id":"https:\/\/iichen.cn\/?p=819","url":"https:\/\/iichen.cn\/?p=819","name":"Python-Manifest\u6587\u4ef6\u6ce8\u5165\u548c\u6279\u91cfADB\u5b89\u88c5\u5e94\u7528 - IIchen","isPartOf":{"@id":"https:\/\/iichen.cn\/#website"},"datePublished":"2025-01-24T07:53:37+00:00","dateModified":"2025-01-24T07:53:38+00:00","description":"Python-Manifest\u6587\u4ef6\u6ce8\u5165\u548c\u6279\u91cfADB\u5b89\u88c5\u5e94\u7528","breadcrumb":{"@id":"https:\/\/iichen.cn\/?p=819#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/iichen.cn\/?p=819"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/iichen.cn\/?p=819#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/iichen.cn\/"},{"@type":"ListItem","position":2,"name":"Python-Manifest\u6587\u4ef6\u6ce8\u5165\u548c\u6279\u91cfADB\u5b89\u88c5\u5e94\u7528"}]},{"@type":"WebSite","@id":"https:\/\/iichen.cn\/#website","url":"https:\/\/iichen.cn\/","name":"IIchen","description":"Just do it!","publisher":{"@id":"https:\/\/iichen.cn\/#\/schema\/person\/4a47edf85ab49841df9e8f6aee40b77c"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/iichen.cn\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"zh-Hans"},{"@type":["Person","Organization"],"@id":"https:\/\/iichen.cn\/#\/schema\/person\/4a47edf85ab49841df9e8f6aee40b77c","name":"iichen","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/iichen.cn\/#\/schema\/person\/image\/","url":"https:\/\/iichen.cn\/wp-content\/uploads\/2025\/01\/avatar.jpg","contentUrl":"https:\/\/iichen.cn\/wp-content\/uploads\/2025\/01\/avatar.jpg","width":940,"height":940,"caption":"iichen"},"logo":{"@id":"https:\/\/iichen.cn\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/www.iichen.cn"],"url":"https:\/\/iichen.cn\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/iichen.cn\/index.php?rest_route=\/wp\/v2\/posts\/819","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/iichen.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/iichen.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/iichen.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/iichen.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=819"}],"version-history":[{"count":1,"href":"https:\/\/iichen.cn\/index.php?rest_route=\/wp\/v2\/posts\/819\/revisions"}],"predecessor-version":[{"id":820,"href":"https:\/\/iichen.cn\/index.php?rest_route=\/wp\/v2\/posts\/819\/revisions\/820"}],"wp:attachment":[{"href":"https:\/\/iichen.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=819"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/iichen.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=819"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/iichen.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=819"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}