Browse Source

dist: Set various AndroidManifest.xml attribs, support appCategory

rdb 1 year ago
parent
commit
7d753d479f
2 changed files with 35 additions and 6 deletions
  1. 4 1
      direct/src/dist/_android.py
  2. 31 5
      direct/src/dist/commands.py

+ 4 - 1
direct/src/dist/_android.py

@@ -168,6 +168,7 @@ ANDROID_ATTRIBUTES = {
     'allowSingleTap': bool_resource(0x1010259),
     'allowTaskReparenting': bool_resource(0x1010204),
     'alwaysRetainTaskState': bool_resource(0x1010203),
+    'appCategory': enum_resource(0x01010545, "game", "audio", "video", "image", "social", "news", "maps", "productivity", "accessibility"),
     'clearTaskOnLaunch': bool_resource(0x1010015),
     'configChanges': flag_resource(0x0101001f, mcc=0x0001, mnc=0x0002, locale=0x0004, touchscreen=0x0008, keyboard=0x0010, keyboardHidden=0x0020, navigation=0x0040, orientation=0x0080, screenLayout=0x0100, uiMode=0x0200, screenSize=0x0400, smallestScreenSize=0x0800, layoutDirection=0x2000, colorMode=0x4000, grammaticalGender=0x8000, fontScale=0x40000000, fontWeightAdjustment=0x10000000),
     'debuggable': bool_resource(0x0101000f),
@@ -179,6 +180,7 @@ ANDROID_ATTRIBUTES = {
     'finishOnTaskLaunch': bool_resource(0x1010014),
     'fullBackupContent': bool_resource(0x10104eb),
     'glEsVersion': int_resource(0x1010281),
+    'hardwareAccelerated': bool_resource(0x10102d3),
     'hasCode': bool_resource(0x101000c),
     'host': str_resource(0x1010028),
     'icon': ref_resource(0x1010002),
@@ -194,8 +196,9 @@ ANDROID_ATTRIBUTES = {
     'name': str_resource(0x1010003),
     'noHistory': bool_resource(0x101022d),
     'pathPattern': str_resource(0x101002c),
-    'resizeableActivity': bool_resource(0x10104f6),
+    'preferMinimalPostProcessing': bool_resource(0x101060c),
     'required': bool_resource(0x101028e),
+    'resizeableActivity': bool_resource(0x10104f6),
     'scheme': str_resource(0x1010027),
     'screenOrientation': enum_resource(0x101001e, 'landscape', 'portrait', 'user', 'behind', 'sensor', 'nosensor', 'sensorLandscape', 'sensorPortrait', 'reverseLandscape', 'reversePortrait', 'fullSensor', 'userLandscape', 'userPortrait', 'fullUser', 'locked'),
     'stateNotNeeded': bool_resource(0x1010016),

+ 31 - 5
direct/src/dist/commands.py

@@ -296,6 +296,7 @@ class build_apps(setuptools.Command):
         self.application_id = None
         self.android_abis = None
         self.android_debuggable = False
+        self.android_app_category = None
         self.android_version_code = 1
         self.android_min_sdk_version = 21
         self.android_max_sdk_version = None
@@ -784,10 +785,29 @@ class build_apps(setuptools.Command):
         version = self.distribution.get_version()
         classifiers = self.distribution.get_classifiers()
 
-        is_game = False
-        for classifier in classifiers:
-            if classifier == 'Topic :: Games/Entertainment' or classifier.startswith('Topic :: Games/Entertainment ::'):
-                is_game = True
+        # If we have no app category, determine it based on the classifiers.
+        category = self.android_app_category
+        if not category:
+            for classifier in classifiers:
+                classifier = tuple(classifier.split(' :: '))
+                if len(classifier) < 2 or classifier[0] != 'Topic':
+                    continue
+
+                if classifier[:2] == ('Topic', 'Games/Entertainment'):
+                    category = 'game'
+                    break
+                elif classifier[:3] == ('Topic', 'Multimedia', 'Audio'):
+                    category = 'audio'
+                elif classifier[:4] == ('Topic', 'Multimedia', 'Graphics', 'Editors'):
+                    category = 'image'
+                elif classifier[:2] == ('Topic', 'Communications', 'Usenet News'):
+                    category = 'news'
+                elif classifier[:2] == ('Topic', 'Office/Business'):
+                    category = 'productivity'
+                elif classifier[:3] == ('Topic', 'Communications', 'Chat'):
+                    category = 'social'
+                elif classifier[:3] == ('Topic', 'Multimedia', 'Video'):
+                    category = 'video'
 
         manifest = ET.Element('manifest')
         manifest.set('xmlns:android', 'http://schemas.android.com/apk/res/android')
@@ -818,9 +838,13 @@ class build_apps(setuptools.Command):
 
         application = ET.SubElement(manifest, 'application')
         application.set('android:label', name)
-        application.set('android:isGame', ('false', 'true')[is_game])
+        if category == 'game':
+            application.set('android:isGame', 'true')
+        if category:
+            application.set('android:appCategory', category)
         application.set('android:debuggable', ('false', 'true')[self.android_debuggable])
         application.set('android:extractNativeLibs', 'true')
+        application.set('android:hardwareAccelerated', 'true')
 
         app_icon = self.icon_objects.get('*', self.icon_objects.get(self.macos_main_app))
         if app_icon:
@@ -831,8 +855,10 @@ class build_apps(setuptools.Command):
             activity.set('android:name', 'org.panda3d.android.PythonActivity')
             activity.set('android:label', appname)
             activity.set('android:theme', '@android:style/Theme.NoTitleBar')
+            activity.set('android:alwaysRetainTaskState', 'true')
             activity.set('android:configChanges', 'layoutDirection|locale|grammaticalGender|fontScale|fontWeightAdjustment|orientation|uiMode|screenLayout|screenSize|smallestScreenSize|keyboard|keyboardHidden|navigation')
             activity.set('android:launchMode', 'singleInstance')
+            activity.set('android:preferMinimalPostProcessing', 'true')
 
             act_icon = self.icon_objects.get(appname)
             if act_icon and act_icon is not app_icon: