Skip to content

Commit

Permalink
Workaround log writing on Android 10
Browse files Browse the repository at this point in the history
  • Loading branch information
rubengees committed Nov 7, 2020
1 parent c7e6d6f commit 018467a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
4 changes: 4 additions & 0 deletions src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />

<application
android:requestLegacyExternalStorage="true"
tools:ignore="GoogleAppIndexingWarning" />
</manifest>
12 changes: 3 additions & 9 deletions src/logRelease/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />

<application tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".ui.crash.CrashActivity"
android:process=":error_activity">
<intent-filter>
<action android:name="cat.ereza.customactivityoncrash.ERROR" />
</intent-filter>
</activity>
</application>
<application
android:requestLegacyExternalStorage="true"
tools:ignore="GoogleAppIndexingWarning" />
</manifest>
7 changes: 5 additions & 2 deletions src/main/kotlin/me/proxer/app/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,12 @@ class MainActivity : DrawerActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

// Request storage permission for writing logs in debug variants.
if (BuildConfig.LOG && VERSION.SDK_INT >= VERSION_CODES.M) {
if (ContextCompat.checkSelfPermission(this, WRITE_EXTERNAL_STORAGE) != PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, arrayOf(WRITE_EXTERNAL_STORAGE), 1)
if (VERSION.SDK_INT >= VERSION_CODES.M) {
if (ContextCompat.checkSelfPermission(this, WRITE_EXTERNAL_STORAGE) != PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, arrayOf(WRITE_EXTERNAL_STORAGE), 1)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class TimberFileTree : Timber.Tree() {
@Suppress("DEPRECATION") // What is Android even doing?
private val downloadsDirectory
get() = Environment.getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS)

private val resolvedLogsDirectory get() = File(downloadsDirectory, LOGS_DIRECTORY).also { it.mkdirs() }

override fun isLoggable(tag: String?, priority: Int) = priority >= Log.INFO
Expand Down

0 comments on commit 018467a

Please sign in to comment.