Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[expo-permissions] Fix permissions in the headless mode (#7962)
* [expo-permissions] Fix in headless mode * [expo-permissions] Fix lateinit * [expo-permissions] Update changelog * [expo-permissions] Apply requested changes
- Loading branch information
Showing
8 changed files
with
74 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 25 additions & 1 deletion
26
...w/src/main/java/versioned/host/exp/exponent/modules/universal/ScopedPermissionsService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,37 @@ | ||
package versioned.host.exp.exponent.modules.universal | ||
|
||
import android.content.Context | ||
import android.content.pm.PackageManager | ||
import androidx.core.content.ContextCompat | ||
import expo.modules.permissions.PermissionsService | ||
import host.exp.exponent.di.NativeModuleDepsProvider | ||
import host.exp.exponent.kernel.ExperienceId | ||
import host.exp.exponent.kernel.services.ExpoKernelServiceRegistry | ||
import org.unimodules.core.ModuleRegistry | ||
import org.unimodules.interfaces.permissions.PermissionsResponseListener | ||
import javax.inject.Inject | ||
|
||
class ScopedPermissionsService(context: Context, val experienceId: ExperienceId) : PermissionsService(context) { | ||
|
||
// This variable cannot be lateinit, cause the Location module gets permissions before this module is initialized. | ||
@Inject | ||
var mExpoKernelServiceRegistry: ExpoKernelServiceRegistry? = null | ||
|
||
override fun onCreate(moduleRegistry: ModuleRegistry) { | ||
super.onCreate(moduleRegistry) | ||
NativeModuleDepsProvider.getInstance().inject(ScopedPermissionsService::class.java, this) | ||
} | ||
|
||
class ScopedPermissionsService(context: Context) : PermissionsService(context) { | ||
// We override this to inject scoped permissions even if the device doesn't support the runtime permissions. | ||
override fun askForManifestPermissions(permissions: Array<out String>, listener: PermissionsResponseListener) { | ||
delegateRequestToActivity(permissions, listener) | ||
} | ||
|
||
// We override this to scoped permissions in the headless mode. | ||
override fun getManifestPermissionFromContext(permission: String): Int { | ||
val globalPermissions = ContextCompat.checkSelfPermission(context, permission) | ||
return mExpoKernelServiceRegistry?.permissionsKernelService?.getPermissions(globalPermissions, context.packageManager, permission, experienceId) | ||
?: PackageManager.PERMISSION_DENIED | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters