Skip to content

Commit

Permalink
[android] Fix "FORWARD_RESULT_FLAG used while also requesting a result"
Browse files Browse the repository at this point in the history
Fixes organicmaps#8984
See c90c6bb "Fix SecurityException ..." (organicmaps#7287)
See b2a6dd2 "Fix the crosshair (PICK_POINT) API" (organicmaps#8910)

Signed-off-by: Roman Tsisyk <[email protected]>
rtsisyk authored and biodranik committed Aug 16, 2024
1 parent d41181d commit fe3d937
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 6 additions & 3 deletions android/app/src/main/java/app/organicmaps/SplashActivity.java
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@

import static android.Manifest.permission.ACCESS_COARSE_LOCATION;
import static android.Manifest.permission.ACCESS_FINE_LOCATION;
import static app.organicmaps.api.Const.EXTRA_PICK_POINT;

import android.content.ComponentName;
import android.content.Context;
@@ -174,13 +175,15 @@ public void processNavigation()
return;
}

// Re-use original intent to retain all flags and payload.
// Re-use original intent with the known safe subset of flags to retain security permissions.
// https://github.com/organicmaps/organicmaps/issues/6944
final Intent intent = Objects.requireNonNull(getIntent());
intent.setComponent(new ComponentName(this, DownloadResourcesLegacyActivity.class));
// Flags like FLAG_ACTIVITY_NEW_TASK and FLAG_ACTIVITY_RESET_TASK_IF_NEEDED will break the cold start of the app.
// FLAG_ACTIVITY_NEW_TASK and FLAG_ACTIVITY_RESET_TASK_IF_NEEDED break the cold start.
// https://github.com/organicmaps/organicmaps/pull/7287
intent.setFlags(intent.getFlags() & (Intent.FLAG_ACTIVITY_FORWARD_RESULT | Intent.FLAG_GRANT_READ_URI_PERMISSION));
// FORWARD_RESULT_FLAG conflicts with the ActivityResultLauncher.
// https://github.com/organicmaps/organicmaps/issues/8984
intent.setFlags(intent.getFlags() & Intent.FLAG_GRANT_READ_URI_PERMISSION);

if (Factory.isStartedForApiResult(intent))
{
7 changes: 5 additions & 2 deletions android/app/src/main/java/app/organicmaps/intent/Factory.java
Original file line number Diff line number Diff line change
@@ -34,8 +34,11 @@ public class Factory
{
public static boolean isStartedForApiResult(@NonNull Intent intent)
{
return ((intent.getFlags() & Intent.FLAG_ACTIVITY_FORWARD_RESULT) != 0)
|| intent.getBooleanExtra(EXTRA_PICK_POINT, false);
// Previously, we relied on the implicit FORWARD_RESULT_FLAG to detect if the caller was
// waiting for a result. However, this approach proved to be less reliable than using
// the explicit EXTRA_PICK_POINT flag.
// https://github.com/organicmaps/organicmaps/pull/8910
return intent.getBooleanExtra(EXTRA_PICK_POINT, false);
}

public static class KmzKmlProcessor implements IntentProcessor

0 comments on commit fe3d937

Please sign in to comment.