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 #8984
See c90c6bb "Fix SecurityException ..." (#7287)
See b2a6dd2 "Fix the crosshair (PICK_POINT) API" (#8910)

Signed-off-by: Roman Tsisyk <roman@tsisyk.com>
  • Loading branch information
rtsisyk authored and biodranik committed Aug 16, 2024
1 parent 48018db commit bfc555f
Show file tree
Hide file tree
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
Expand Up @@ -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;
Expand Down Expand Up @@ -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))
{
Expand Down
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
Expand Up @@ -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
Expand Down

0 comments on commit bfc555f

Please sign in to comment.