@@ -861,6 +861,10 @@ def _get_launchable_activity(self) -> str:
861
861
Determines the class name for the activity that is
862
862
launched on application startup.
863
863
864
+ This is done by first trying to parse the output of
865
+ aapt dump badging, then falling back to manually
866
+ parsing the AndroidManifest for activity-alias tags.
867
+
864
868
:return:
865
869
"""
866
870
@@ -872,11 +876,44 @@ def _get_launchable_activity(self) -> str:
872
876
# ['launchable-activity: name=', 'com.app.activity', ' label=', 'bob']
873
877
activity = line .split ('\' ' )[1 ]
874
878
875
- if activity == '' :
876
- click .secho ('Unable to determine the launchable activity for this app.' , fg = 'red' )
877
- raise Exception ('Unable to determine launchable activity' )
879
+ # If we got the activity using aapt, great, return that.
880
+ if activity != '' :
881
+ return activity
882
+
883
+ # if we dont have the activity yet, check out activity aliases
884
+
885
+ click .secho (('Unable to determine the launchable activity using aapt, trying '
886
+ 'to manually parse the AndroidManifest for activity aliases...' ), dim = True , fg = 'yellow' )
887
+
888
+ # Try and parse the manifest manually
889
+ manifest = self ._get_android_manifest ()
890
+ root = manifest .getroot ()
891
+
892
+ # grab all of the activity-alias tags
893
+ for alias in root .findall ('./application/activity-alias' ):
894
+
895
+ # Take not of the current activity
896
+ current_activity = alias .get ('{http://schemas.android.com/apk/res/android}targetActivity' )
897
+ categories = alias .findall ('./intent-filter/category' )
898
+
899
+ # make sure we have categories for this alias
900
+ if categories is None :
901
+ continue
902
+
903
+ for category in categories :
904
+
905
+ # check if the name of this category is that of LAUNCHER
906
+ # its possible to have multiples, but once we determine one
907
+ # that fits we can just return and move on
908
+ category_name = category .get ('{http://schemas.android.com/apk/res/android}name' )
909
+
910
+ if category_name == 'android.intent.category.LAUNCHER' :
911
+ return current_activity
878
912
879
- return activity
913
+ # getting here means we were unable to determine what the launchable
914
+ # activity is
915
+ click .secho ('Unable to determine the launchable activity for this app.' , fg = 'red' )
916
+ raise Exception ('Unable to determine launchable activity' )
880
917
881
918
def get_patched_apk_path (self ) -> str :
882
919
"""
@@ -1118,6 +1155,7 @@ def __del__(self):
1118
1155
1119
1156
:return:
1120
1157
"""
1158
+ return
1121
1159
1122
1160
click .secho ('Cleaning up temp files...' , dim = True )
1123
1161
0 commit comments