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

Android 13 fix media permissions #731

Merged
merged 3 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission-sdk-23 android:name="android.permission.RECORD_AUDIO"/>
<!-- Allows for storing and retrieving screenshots, photos, videos and audios -->
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="29" />
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />

<uses-feature
android:name="android.hardware.camera"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.Manifest.permission;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcelable;
import android.view.LayoutInflater;
Expand Down Expand Up @@ -502,8 +503,12 @@ public void onDestroyActionMode(ActionMode mode) {
}

private boolean hasStoragePermission() {
return ContextCompat.checkSelfPermission(
getActivity(), permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
return ContextCompat.checkSelfPermission(
requireActivity(), permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
} else {
return true;
}
}

///*
Expand Down
13 changes: 10 additions & 3 deletions photoeditor/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@
package="com.automattic.photoeditor">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission-sdk-23 android:name="android.permission.RECORD_AUDIO"/>
<!-- Allows for storing and retrieving screenshots, photos, videos and audios -->
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="29" />
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />

<uses-feature
android:name="android.hardware.camera"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.app.Activity
import android.content.Context
import android.content.SharedPreferences
import android.content.pm.PackageManager
import android.os.Build
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat

Expand All @@ -15,9 +16,11 @@ class PermissionUtils {
companion object {
val PERMISSION_REQUEST_CODE = 5200
val IS_PERMISSION_REQUESTED_PREFS = "is_permission_requested_prefs"
val REQUIRED_PERMISSIONS = arrayOf(
Manifest.permission.CAMERA
)
val REQUIRED_PERMISSIONS = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
arrayOf(Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE)
} else {
arrayOf(Manifest.permission.CAMERA)
}

// Video requires access to recording audio (microphone).
val REQUIRED_PERMISSIONS_WITH_AUDIO = arrayOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.ServiceConnection
import android.graphics.drawable.Drawable
import android.graphics.Matrix
import android.graphics.Rect
import android.graphics.drawable.ColorDrawable
import android.graphics.Matrix
import android.graphics.drawable.Drawable
import android.media.MediaScannerConnection
import android.net.Uri
import android.os.Build
Expand Down Expand Up @@ -71,8 +71,8 @@ import com.bumptech.glide.Glide
import com.bumptech.glide.load.DataSource
import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation
import com.bumptech.glide.load.resource.bitmap.FitCenter
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.FitCenter
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.RequestListener
import com.bumptech.glide.request.target.Target
Expand All @@ -88,12 +88,12 @@ import com.wordpress.stories.compose.ScreenTouchBlockMode.BLOCK_TOUCH_MODE_PHOTO
import com.wordpress.stories.compose.ScreenTouchBlockMode.BLOCK_TOUCH_MODE_PHOTO_EDITOR_READY
import com.wordpress.stories.compose.emoji.EmojiPickerFragment
import com.wordpress.stories.compose.emoji.EmojiPickerFragment.EmojiListener
import com.wordpress.stories.compose.frame.StoryLoadEvents.StoryLoadEnd
import com.wordpress.stories.compose.frame.StoryLoadEvents.StoryLoadStart
import com.wordpress.stories.compose.frame.FrameIndex
import com.wordpress.stories.compose.frame.FrameSaveManager
import com.wordpress.stories.compose.frame.FrameSaveNotifier
import com.wordpress.stories.compose.frame.FrameSaveService
import com.wordpress.stories.compose.frame.StoryLoadEvents.StoryLoadEnd
import com.wordpress.stories.compose.frame.StoryLoadEvents.StoryLoadStart
import com.wordpress.stories.compose.frame.StoryNotificationType
import com.wordpress.stories.compose.frame.StorySaveEvents
import com.wordpress.stories.compose.frame.StorySaveEvents.SaveResultReason.SaveError
Expand Down Expand Up @@ -1172,7 +1172,9 @@ abstract class ComposeLoopFrameActivity : AppCompatActivity(), OnStoryFrameSelec
// fresh intent, go fully save the Story
if (storyViewModel.getCurrentStorySize() > 0) {
// save all composed frames
if (PermissionUtils.checkAndRequestPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R ||
PermissionUtils.checkAndRequestPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
) {
storyFrameIndexToRetry = StoryRepository.DEFAULT_NONE_SELECTED
saveStory()
}
Expand Down Expand Up @@ -1560,7 +1562,9 @@ abstract class ComposeLoopFrameActivity : AppCompatActivity(), OnStoryFrameSelec

@SuppressLint("MissingPermission")
private fun saveVideo(inputFile: Uri) {
if (PermissionUtils.checkPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R ||
PermissionUtils.checkPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
) {
showLoading()
try {
val file = getLoopFrameFile(this, true)
Expand Down Expand Up @@ -1617,7 +1621,9 @@ abstract class ComposeLoopFrameActivity : AppCompatActivity(), OnStoryFrameSelec

@SuppressLint("MissingPermission")
private fun saveVideoWithStaticBackground() {
if (PermissionUtils.checkPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R ||
PermissionUtils.checkPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
) {
showLoading()
try {
val file = getLoopFrameFile(this, true, "tmp")
Expand Down