Skip to content

Commit

Permalink
Disable the requestLegacyExternalStorage attribute when there are n…
Browse files Browse the repository at this point in the history
…o storage permissions.
  • Loading branch information
m4gr3d committed Apr 16, 2021
1 parent 00d087e commit bc68872
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
12 changes: 11 additions & 1 deletion platform/android/export/export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,10 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
return OK;
}

bool _has_storage_permission(const Vector<String> &p_permissions) {
return p_permissions.find("android.permission.READ_EXTERNAL_STORAGE") != -1 || p_permissions.find("android.permission.WRITE_EXTERNAL_STORAGE") != -1;
}

void _get_permissions(const Ref<EditorExportPreset> &p_preset, bool p_give_internet, Vector<String> &r_permissions) {
const char **aperms = android_perms;
while (*aperms) {
Expand Down Expand Up @@ -819,7 +823,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {

manifest_text += _get_xr_features_tag(p_preset);
manifest_text += _get_instrumentation_tag(p_preset);
manifest_text += _get_application_tag(p_preset);
manifest_text += _get_application_tag(p_preset, _has_storage_permission(perms));
manifest_text += "</manifest>\n";
String manifest_path = vformat("res://android/build/src/%s/AndroidManifest.xml", (p_debug ? "debug" : "release"));

Expand Down Expand Up @@ -873,6 +877,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
Vector<String> perms;
// Write permissions into the perms variable.
_get_permissions(p_preset, p_give_internet, perms);
bool has_storage_permission = _has_storage_permission(perms);

while (ofs < (uint32_t)p_manifest.size()) {

Expand Down Expand Up @@ -968,6 +973,11 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
string_table.write[attr_value] = version_name;
}

if (tname == "application" && attrname == "requestLegacyExternalStorage") {

encode_uint32(has_storage_permission ? 0xFFFFFFFF : 0, &p_manifest.write[iofs + 16]);
}

if (tname == "instrumentation" && attrname == "targetPackage") {
string_table.write[attr_value] = get_package_name(package_name);
}
Expand Down
9 changes: 6 additions & 3 deletions platform/android/export/gradle_export_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,16 @@ String _get_activity_tag(const Ref<EditorExportPreset> &p_preset) {
return manifest_activity_text;
}

String _get_application_tag(const Ref<EditorExportPreset> &p_preset) {
String _get_application_tag(const Ref<EditorExportPreset> &p_preset, bool p_has_storage_permission) {
bool uses_xr = (int)(p_preset->get("xr_features/xr_mode")) == 1;
String manifest_application_text =
String manifest_application_text = vformat(
" <application android:label=\"@string/godot_project_name_string\"\n"
" android:allowBackup=\"false\" tools:ignore=\"GoogleAppIndexingWarning\"\n"
" tools:replace=\"android:requestLegacyExternalStorage\" "
" android:requestLegacyExternalStorage=\"%s\"\n"
" android:icon=\"@mipmap/icon\">\n\n"
" <meta-data tools:node=\"remove\" android:name=\"xr_mode_metadata_name\" />\n";
" <meta-data tools:node=\"remove\" android:name=\"xr_mode_metadata_name\" />\n",
bool_to_string(p_has_storage_permission));

if (uses_xr) {
manifest_application_text += " <meta-data tools:node=\"replace\" android:name=\"com.samsung.android.vr.application.mode\" android:value=\"vr_only\" />\n";
Expand Down
3 changes: 2 additions & 1 deletion platform/android/java/app/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
<!-- Any tag in this line after android:icon will be erased when doing custom builds. -->
<!-- If you want to add tags manually, do before it. -->
<!-- WARNING: This should stay on a single line until the parsing code is improved. See GH-32414. -->
<application android:label="@string/godot_project_name_string" android:allowBackup="false" tools:ignore="GoogleAppIndexingWarning" android:icon="@mipmap/icon" >
<!-- TODO: Remove the 'requestLegacyExternalStorage' attribute when https://github.com/godotengine/godot/issues/38913 is resolved -->
<application android:label="@string/godot_project_name_string" android:allowBackup="false" tools:ignore="GoogleAppIndexingWarning" android:requestLegacyExternalStorage="false" android:icon="@mipmap/icon" >

<!-- Records the version of the Godot editor used for building -->
<meta-data
Expand Down
3 changes: 1 addition & 2 deletions platform/android/java/lib/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
android:versionCode="1"
android:versionName="1.0">

<!-- TODO: Remove the 'requestLegacyExternalStorage' attribute when https://github.com/godotengine/godot/issues/38913 is resolved -->
<application android:requestLegacyExternalStorage="true">
<application>

<!-- Records the version of the Godot library -->
<meta-data
Expand Down

0 comments on commit bc68872

Please sign in to comment.