Skip to content

Commit

Permalink
Gallery: Strip all files permission for google play release (does not…
Browse files Browse the repository at this point in the history
… pass review)

Signed-off-by: IacobIonut01 <[email protected]>
  • Loading branch information
IacobIonut01 committed Mar 23, 2024
1 parent 0654424 commit c8513ae
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 13 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/stable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ jobs:
run: git config --global user.email "[email protected]" &&
git config --global user.name "IacobIonut01" &&
git fetch https://github.com/IacobIonut01/Gallery.git main_play &&
git cherry-pick e63cd751baa1dc733222d5a3ce135cb7bc52868b
git cherry-pick e63cd751baa1dc733222d5a3ce135cb7bc52868b &&
chmod +x ./strip_allfiles_permission.sh && ./strip_allfiles_permission.sh &&
echo ALL_FILES_ACCESS=false > ./app.properties
- name: Build Google Play Bundle
run: ./gradlew bundleGplay
env:
Expand Down
3 changes: 2 additions & 1 deletion app/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/build
/release
/release
*.jks
16 changes: 15 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ android {
applicationId = "com.dot.gallery"
minSdk = 30
targetSdk = 34
versionCode = 21107
versionCode = 21108
versionName = "2.1.1"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
Expand Down Expand Up @@ -69,6 +69,7 @@ android {
)
)
signingConfig = signingConfigs.getByName("release")
buildConfigField("Boolean", "ALLOW_ALL_FILES_ACCESS", allowAllFilesAccess)
buildConfigField("String", "MAPS_TOKEN", getApiKey())
buildConfigField("String", "CONTENT_AUTHORITY", "\"com.dot.gallery.media_provider\"")
}
Expand Down Expand Up @@ -222,6 +223,19 @@ fun getApiKey(): String {
}
}

val allowAllFilesAccess: String
get() {
val fl = rootProject.file("app.properties")

return try {
val properties = Properties()
properties.load(FileInputStream(fl))
properties.getProperty("ALL_FILES_ACCESS")
} catch (e: Exception) {
"true"
}
}

@Suppress("UnstableApiUsage")
val gitHeadVersion: String
get() {
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
(OPTIONAL)
Requested to create albums outside Internal Storage/Pictures or Internal Storage/DCIM
-->
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>

<queries>
<intent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import com.dot.gallery.BuildConfig
import com.dot.gallery.R
import com.dot.gallery.core.Constants
import com.dot.gallery.core.Settings.Misc.rememberIsMediaManager
import com.dot.gallery.feature_node.presentation.util.isManageFilesAllowed
import com.dot.gallery.feature_node.presentation.util.launchManageFiles
import com.dot.gallery.feature_node.presentation.util.launchManageMedia
import com.dot.gallery.ui.theme.GalleryTheme
Expand Down Expand Up @@ -189,13 +190,15 @@ fun SetupScreen(
withStyle(style = style) {
append(stringResource(R.string.permission_manage_media_summary))
}
appendLine()
withStyle(style = style.copy(fontWeight = FontWeight.Bold)) {
append(stringResource(R.string.permission_manage_files_title))
}
appendLine()
withStyle(style = style) {
append(stringResource(R.string.permission_manage_files_summary))
if (isManageFilesAllowed) {
appendLine()
withStyle(style = style.copy(fontWeight = FontWeight.Bold)) {
append(stringResource(R.string.permission_manage_files_title))
}
appendLine()
withStyle(style = style) {
append(stringResource(R.string.permission_manage_files_summary))
}
}
}
}
Expand All @@ -219,7 +222,7 @@ fun SetupScreen(
Text(text = stringResource(R.string.allow_to_manage_media))
}
}
if (!isStorageManager) {
if (!isStorageManager && isManageFilesAllowed) {
Button(
onClick = {
scope.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* Original from
* https://stackoverflow.com/a/70853761/12978728
*/
@file:Suppress("KotlinConstantConditions")

package com.dot.gallery.feature_node.presentation.util

import android.app.Activity
Expand Down Expand Up @@ -135,6 +137,9 @@ fun Context.launchManageMedia() {
startActivity(intent)
}

val isManageFilesAllowed: Boolean
get() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && BuildConfig.ALLOW_ALL_FILES_ACCESS

@RequiresApi(Build.VERSION_CODES.S)
fun Context.launchManageFiles() {
val intent = Intent().apply {
Expand Down
2 changes: 2 additions & 0 deletions strip_allfiles_permission.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sed -n '/<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"\/>/!p' app/src/main/AndroidManifest.xml > app/src/main/AndroidManifest2.xml
mv app/src/main/AndroidManifest2.xml app/src/main/AndroidManifest.xml

0 comments on commit c8513ae

Please sign in to comment.