Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add device setting to control privacy permissions #423

Merged
merged 4 commits into from
Jul 8, 2024

Conversation

kmagiera
Copy link
Member

@kmagiera kmagiera commented Jul 5, 2024

This PR adds a device setting that allows for resetting privacy permissions.

The new setting helps with scenarios where you want to test flows that rely on asking users for different types of permissions.

The current implementations supports resetting the following permissions on iOS:

  • all
  • location
  • photos
  • contatcs
  • calendar

On Android due to the limitations of the method we currently use, only resetting all permissions is supported.

On top of the above, the app may behave differently depending on the system. On Android, the app process is always terminated when we reset permission if at least one permission was granted prior to reset. On iOS the app never restarts.

An important consideration here is that we may want to restart the app regardless of the operating system, as the behavior where the app keeps running may lead to some unpredictable behavior. This may also end up getting the app in a state that is not expected by the developers. Typically for end-users on Android and iOS it is not possible to reset the privacy settings – you can change the setting to disallow or grant the permission later on, but you can never get it back to the state when it's unknown unless you uninstall the app. So this new option we are adding here may get the app into a state that will never be possible to replicate in real-life and therefore there is no need to handle such state for the developer.

The biggest downside of the current implementation is that we use the restart flow for the case when the permission is reset on Android. This leads to a longer than necessary time to interact with the app, as the current restart flow will also reboot the emulator, potentially trigger build and also restart metro. I plan to address this in a follow up PR, where we will add a new quicker flow for handling restarts that doesn't reset the emulator and metro.

Here's how the new dropdown menu look for iOS:
image

Test plan:
We're adding new location screen to expo-router example and extending that example to ask for location permission.
This has been tested on this new example with two scenarios: 1) get location info, allow, reset, get again 2) get location info, disallow, reset permission, get again. In both scenarios it is expected to get the permission popup. On Android the app will always restart when resetting the permission.

@kmagiera kmagiera requested a review from jakub-gonet July 5, 2024 09:13
Copy link

vercel bot commented Jul 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-native-ide ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 5, 2024 11:23am

@@ -395,3 +412,18 @@ function convertToSimctlSize(size: DeviceSettings["contentSize"]): string {
return "extra-extra-extra-large";
}
}

function convertToSimctlPermission(permissionType: AppPermissionType): string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we expect more to come? Right this function is doing nothing as far as I can see.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated it such that I have a separate list of accepted service names. The idea was that we levarage typescript to catch the case when we add new item in the future and it isn't mapping directly to the name that we can use with simctl

test-apps/expo-router/app/location.js Show resolved Hide resolved
test-apps/expo-router/app/location.js Show resolved Hide resolved
test-apps/expo-router/app/location.js Outdated Show resolved Hide resolved
test-apps/expo-router/app/location.js Outdated Show resolved Hide resolved
test-apps/expo-router/app/location.js Outdated Show resolved Hide resolved
Comment on lines +254 to +256
if (build.platform !== Platform.IOS) {
throw new Error("Invalid platform");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we need this check?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to narrow down the type of build from BuildResult to IosBuildResult which has some fields that we need

@kmagiera kmagiera merged commit dddddd6 into main Jul 8, 2024
3 checks passed
@kmagiera kmagiera deleted the kmagiera/permissions branch July 8, 2024 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants