Skip to content

Commit b00e1cb

Browse files
committed
Merge pull request #97631 from m4gr3d/prompt_apk_install_after_generation
[Android editor] Enable automatic install of exported apks for the Android editor
2 parents 88d9903 + af2423b commit b00e1cb

File tree

7 files changed

+42
-10
lines changed

7 files changed

+42
-10
lines changed

platform/android/export/export.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ void register_android_exporter() {
4949
EDITOR_DEF_BASIC("export/android/debug_keystore_pass", DEFAULT_ANDROID_KEYSTORE_DEBUG_PASSWORD);
5050
EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "export/android/debug_keystore_pass", PROPERTY_HINT_PASSWORD));
5151

52-
#ifndef ANDROID_ENABLED
52+
#ifdef ANDROID_ENABLED
53+
EDITOR_DEF_BASIC("export/android/install_exported_apk", true);
54+
#else
5355
EDITOR_DEF_BASIC("export/android/java_sdk_path", OS::get_singleton()->get_environment("JAVA_HOME"));
5456
EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "export/android/java_sdk_path", PROPERTY_HINT_GLOBAL_DIR));
5557
EDITOR_DEF_BASIC("export/android/android_sdk_path", OS::get_singleton()->get_environment("ANDROID_HOME"));

platform/android/export/export_plugin.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2893,6 +2893,14 @@ Error EditorExportPlatformAndroid::sign_apk(const Ref<EditorExportPreset> &p_pre
28932893
#endif
28942894

28952895
print_verbose("Successfully completed signing build.");
2896+
2897+
#ifdef ANDROID_ENABLED
2898+
bool prompt_apk_install = EDITOR_GET("export/android/install_exported_apk");
2899+
if (prompt_apk_install) {
2900+
OS_Android::get_singleton()->shell_open(apk_path);
2901+
}
2902+
#endif
2903+
28962904
return OK;
28972905
}
28982906

platform/android/java/editor/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<uses-permission android:name="android.permission.INTERNET" />
2626
<uses-permission android:name="android.permission.RECORD_AUDIO" />
2727
<uses-permission android:name="android.permission.VIBRATE" />
28+
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
2829

2930
<application
3031
android:allowBackup="false"

platform/android/java/editor/src/main/java/org/godotengine/editor/BaseGodotEditor.kt

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ abstract class BaseGodotEditor : GodotActivity() {
390390
* If the launch policy is [LaunchPolicy.AUTO], resolve it into a specific policy based on the
391391
* editor setting or device and screen metrics.
392392
*
393-
* If the launch policy is [LaunchPolicy.PIP] but PIP is not supported, fallback to the default
393+
* If the launch policy is [LaunchPolicy.SAME_AND_LAUNCH_IN_PIP_MODE] but PIP is not supported, fallback to the default
394394
* launch policy.
395395
*/
396396
private fun resolveLaunchPolicyIfNeeded(policy: LaunchPolicy): LaunchPolicy {
@@ -453,16 +453,26 @@ abstract class BaseGodotEditor : GodotActivity() {
453453
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
454454
super.onActivityResult(requestCode, resultCode, data)
455455
// Check if we got the MANAGE_EXTERNAL_STORAGE permission
456-
if (requestCode == PermissionsUtil.REQUEST_MANAGE_EXTERNAL_STORAGE_REQ_CODE) {
457-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
458-
if (!Environment.isExternalStorageManager()) {
456+
when (requestCode) {
457+
PermissionsUtil.REQUEST_MANAGE_EXTERNAL_STORAGE_REQ_CODE -> {
458+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && !Environment.isExternalStorageManager()) {
459459
Toast.makeText(
460460
this,
461461
R.string.denied_storage_permission_error_msg,
462462
Toast.LENGTH_LONG
463463
).show()
464464
}
465465
}
466+
467+
PermissionsUtil.REQUEST_INSTALL_PACKAGES_REQ_CODE -> {
468+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !packageManager.canRequestPackageInstalls()) {
469+
Toast.makeText(
470+
this,
471+
R.string.denied_install_packages_permission_error_msg,
472+
Toast.LENGTH_LONG
473+
).show()
474+
}
475+
}
466476
}
467477
}
468478

@@ -514,7 +524,7 @@ abstract class BaseGodotEditor : GodotActivity() {
514524

515525
override fun supportsFeature(featureTag: String): Boolean {
516526
if (featureTag == "xr_editor") {
517-
return isNativeXRDevice();
527+
return isNativeXRDevice()
518528
}
519529

520530
if (featureTag == "horizonos") {

platform/android/java/editor/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
<resources>
33
<string name="godot_game_activity_name">Godot Play window</string>
44
<string name="denied_storage_permission_error_msg">Missing storage access permission!</string>
5+
<string name="denied_install_packages_permission_error_msg">Missing install packages permission!</string>
56
<string name="pip_button_description">Button used to toggle picture-in-picture mode for the Play window</string>
67
</resources>

platform/android/java/lib/src/org/godotengine/godot/utils/PermissionsUtil.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949

5050
import java.util.ArrayList;
5151
import java.util.Arrays;
52-
import java.util.Collections;
5352
import java.util.HashSet;
5453
import java.util.List;
5554
import java.util.Set;
@@ -66,6 +65,7 @@ public final class PermissionsUtil {
6665
public static final int REQUEST_ALL_PERMISSION_REQ_CODE = 1001;
6766
public static final int REQUEST_SINGLE_PERMISSION_REQ_CODE = 1002;
6867
public static final int REQUEST_MANAGE_EXTERNAL_STORAGE_REQ_CODE = 2002;
68+
public static final int REQUEST_INSTALL_PACKAGES_REQ_CODE = 3002;
6969

7070
private PermissionsUtil() {
7171
}
@@ -105,6 +105,16 @@ public static boolean requestPermissions(Activity activity, List<String> permiss
105105
activity.startActivityForResult(intent, REQUEST_MANAGE_EXTERNAL_STORAGE_REQ_CODE);
106106
}
107107
}
108+
} else if (permission.equals(Manifest.permission.REQUEST_INSTALL_PACKAGES)) {
109+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !activity.getPackageManager().canRequestPackageInstalls()) {
110+
try {
111+
Intent intent = new Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES);
112+
intent.setData(Uri.parse(String.format("package:%s", activity.getPackageName())));
113+
activity.startActivityForResult(intent, REQUEST_INSTALL_PACKAGES_REQ_CODE);
114+
} catch (Exception e) {
115+
Log.e(TAG, "Unable to request permission " + Manifest.permission.REQUEST_INSTALL_PACKAGES);
116+
}
117+
}
108118
} else {
109119
PermissionInfo permissionInfo = getPermissionInfo(activity, permission);
110120
int protectionLevel = Build.VERSION.SDK_INT >= Build.VERSION_CODES.P ? permissionInfo.getProtection() : permissionInfo.protectionLevel;
@@ -215,7 +225,7 @@ public static boolean requestManifestPermissions(Activity activity, @Nullable Se
215225
try {
216226
manifestPermissions = getManifestPermissions(activity);
217227
} catch (PackageManager.NameNotFoundException e) {
218-
e.printStackTrace();
228+
Log.e(TAG, "Unable to retrieve manifest permissions", e);
219229
return false;
220230
}
221231

@@ -242,7 +252,7 @@ public static String[] getGrantedPermissions(Context context) {
242252
try {
243253
manifestPermissions = getManifestPermissions(context);
244254
} catch (PackageManager.NameNotFoundException e) {
245-
e.printStackTrace();
255+
Log.e(TAG, "Unable to retrieve manifest permissions", e);
246256
return new String[0];
247257
}
248258
if (manifestPermissions.isEmpty()) {

platform/android/java/nativeSrcsConfigs/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ target_include_directories(${PROJECT_NAME}
2121
${ANDROID_ROOT_DIR}
2222
${OPENXR_INCLUDE_DIR})
2323

24-
add_definitions(-DUNIX_ENABLED -DVULKAN_ENABLED -DANDROID_ENABLED -DGLES3_ENABLED -DTOOLS_ENABLED)
24+
add_definitions(-DUNIX_ENABLED -DVULKAN_ENABLED -DANDROID_ENABLED -DGLES3_ENABLED -DTOOLS_ENABLED -DDEBUG_ENABLED)

0 commit comments

Comments
 (0)