Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
Target Android 11 (DEV) (#3310)
Browse files Browse the repository at this point in the history
* Target Android 11

* Update QrCodeFullScreenFragment.kt

* Consistency on different versions

* Move to IntentBuilder constructor

* Run screenshots

* Fix notification test

* Update ScreenShotter.kt

* Delete ScreenshotUnderTest.kt

* Update ScreenShotter.kt

* Docs

* Revert

Co-authored-by: harambasicluka <64483219+harambasicluka@users.noreply.github.com>
Co-authored-by: BMItter <Berndus@gmx.de>
  • Loading branch information
3 people committed Jun 1, 2021
1 parent dd381e7 commit 36e77c9
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 106 deletions.
6 changes: 3 additions & 3 deletions Corona-Warn-App/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ android {
println("Current VERSION_PATCH: ${VERSION_PATCH}")
println("Current VERSION_BUILD: ${VERSION_BUILD}")

compileSdkVersion 29
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId 'de.rki.coronawarnapp'
minSdkVersion 23
targetSdkVersion 29
targetSdkVersion 30

ndkVersion "21.2.6472646"

Expand Down Expand Up @@ -314,7 +314,7 @@ dependencies {
// ANDROID STANDARD
def nav_version = "2.3.3"
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.core:core-ktx:1.5.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
Expand Down
14 changes: 12 additions & 2 deletions Corona-Warn-App/src/androidTest/java/testhelpers/ScreenShotter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package testhelpers

import android.app.Activity
import android.graphics.Bitmap
import android.os.Build
import android.os.Bundle
import android.util.Log
import androidx.annotation.StyleRes
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentFactory
import androidx.test.espresso.ViewAction
import androidx.test.platform.app.InstrumentationRegistry
import de.rki.coronawarnapp.BuildConfig
import de.rki.coronawarnapp.R
import java.io.BufferedOutputStream
import java.io.File
Expand Down Expand Up @@ -47,14 +49,15 @@ inline fun <reified F : Fragment> captureScreenshot(
* Saves screenshots on the device's sdcard
*/
object SDCard {
private const val ROOT_DIRECTORY = "/sdcard"
private const val SDCARD_DIRECTORY = "/sdcard"
private const val DATA_DIRECTORY = "/data/data/${BuildConfig.APPLICATION_ID}"
private const val SCREENSHOTS_DIRECTORY = "screenshots"
private const val SCREENSHOT_FORMAT = ".png"
private const val IMAGE_QUALITY = 100

fun screenshotCaptured(screenshotName: String, screenshot: Bitmap) {
try {
val directory = File(ROOT_DIRECTORY, SCREENSHOTS_DIRECTORY)
val directory = File(rootDir, SCREENSHOTS_DIRECTORY)
if (!directory.exists()) {
directory.mkdirs()
}
Expand All @@ -72,4 +75,11 @@ object SDCard {
throw RuntimeException("Unable to capture screenshot.", e)
}
}

private val rootDir: String by lazy {
// Screenshots are saved in local directory on API 30+ due to scoped storage changes.
// Developer can explore screenshots taken locally using "Device File Explorer" in Android studio.
// Firebase TL runs screenshots on API 29 and pulls them from sdcard.
if (Build.VERSION.SDK_INT < 30) SDCARD_DIRECTORY else DATA_DIRECTORY
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ class SettingsCrashReportDetailsFragment :

private fun shareCrashReport() {
activity?.let { activity ->
val shareIntent = ShareCompat.IntentBuilder
.from(activity)
val shareIntent = ShareCompat.IntentBuilder(activity)
.setType("text/plain")
.setText(fragmentSettingsCrashReportDetailsBinding.textViewCrashReportDetails.text)
.createChooserIntent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,20 @@ class DataDonationTestFragment : Fragment(R.layout.fragment_test_datadonation),
}

vm.copyJWSEvent.observe2(this) { jws ->
val intent = ShareCompat.IntentBuilder.from(requireActivity()).apply {
setType("text/plain")
setSubject("JWS")
setText(jws)
}.createChooserIntent()
val intent = ShareCompat.IntentBuilder(requireActivity())
.setType("text/plain")
.setSubject("JWS")
.setText(jws)
.createChooserIntent()
startActivity(intent)
}

vm.copyAnalyticsEvent.observe2(this) { analytics ->
val intent = ShareCompat.IntentBuilder.from(requireActivity()).apply {
setType("text/plain")
setSubject("Analytics")
setText(analytics)
}.createChooserIntent()
val intent = ShareCompat.IntentBuilder(requireActivity())
.setType("text/plain")
.setSubject("Analytics")
.setText(analytics)
.createChooserIntent()
startActivity(intent)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ class TestRiskLevelCalculationFragment :
Timber.d("Opening Share-Intent for Exposure Windows")
val shareFileUri =
FileProvider.getUriForFile(requireContext(), requireContext().packageName + ".fileProvider", file)
val shareIntent = ShareCompat.IntentBuilder
.from(requireActivity())
val shareIntent = ShareCompat.IntentBuilder(requireActivity())
.setStream(shareFileUri)
.setType("text/plain")
.intent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class DebugLogFragment : Fragment(R.layout.bugreporting_debuglog_fragment), Auto
MaterialAlertDialogBuilder(requireContext()).apply {
setTitle(R.string.errors_generic_headline_short)
setMessage(R.string.debugging_debuglog_start_low_storage_error)
setPositiveButton(android.R.string.yes) { _, _ -> /* dismiss */ }
setPositiveButton(android.R.string.ok) { _, _ -> /* dismiss */ }
setNeutralButton(R.string.menu_settings) { _, _ ->
try {
startActivity(Intent(Settings.ACTION_INTERNAL_STORAGE_SETTINGS))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ class ContactDiaryOverviewFragment : Fragment(R.layout.contact_diary_overview_fr
private fun exportLocationsAndPersons(exportString: String) {
Timber.d("exportLocationsAndPersons(exportString=$exportString)")
activity?.let { activity ->
val shareIntent = ShareCompat.IntentBuilder
.from(activity)
val shareIntent = ShareCompat.IntentBuilder(activity)
.setType("text/plain")
.setSubject(getString(R.string.contact_diary_export_subject))
.setText(exportString)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package de.rki.coronawarnapp.presencetracing.common

import android.annotation.TargetApi
import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.os.Build
import androidx.core.app.NotificationChannelCompat
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.navigation.NavDeepLinkBuilder
Expand Down Expand Up @@ -37,13 +36,13 @@ class PresenceTracingNotifications @Inject constructor(
fun setupChannel() {
Timber.d("setupChannel()")

val channel = NotificationChannel(
val channel = NotificationChannelCompat.Builder(
channelId,
context.getString(R.string.tracelocation_notification_channel_title),
NotificationManager.IMPORTANCE_DEFAULT
).apply {
description = context.getString(R.string.tracelocation_notification_channel_description)
}
NotificationManagerCompat.IMPORTANCE_DEFAULT
)
.setName(context.getString(R.string.tracelocation_notification_channel_title))
.setDescription(context.getString(R.string.tracelocation_notification_channel_description))
.build()

notificationManagerCompat.createNotificationChannel(channel)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
package de.rki.coronawarnapp.ui.qrcode.fullscreen

import android.graphics.Color
import android.os.Build
import android.os.Bundle
import android.view.View
import android.view.View.SYSTEM_UI_FLAG_FULLSCREEN
import android.view.View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
import android.view.View.SYSTEM_UI_FLAG_IMMERSIVE
import android.view.View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
import android.view.View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
import android.view.View.SYSTEM_UI_FLAG_LAYOUT_STABLE
import android.view.View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
import android.view.View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
import android.view.View.SYSTEM_UI_FLAG_VISIBLE
import android.view.animation.AccelerateInterpolator
import androidx.core.view.WindowInsetsCompat.Type
import androidx.core.view.WindowInsetsControllerCompat
import androidx.core.view.WindowInsetsControllerCompat.BEHAVIOR_SHOW_BARS_BY_SWIPE
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.navArgs
import com.google.android.material.transition.MaterialContainerTransform
Expand All @@ -29,10 +22,9 @@ import javax.inject.Inject
class QrCodeFullScreenFragment : Fragment(R.layout.fragment_qr_code_full_screen), AutoInject {

@Inject lateinit var viewModelFactory: CWAViewModelFactoryProvider.Factory

private val binding: FragmentQrCodeFullScreenBinding by viewBinding()
private val binding by viewBinding<FragmentQrCodeFullScreenBinding>()
private val args by navArgs<QrCodeFullScreenFragmentArgs>()
private val viewModel: QrCodeFullScreenViewModel by cwaViewModelsAssisted(
private val viewModel by cwaViewModelsAssisted<QrCodeFullScreenViewModel>(
factoryProducer = { viewModelFactory },
constructorCall = { factory, _ ->
factory as QrCodeFullScreenViewModel.Factory
Expand All @@ -43,6 +35,8 @@ class QrCodeFullScreenFragment : Fragment(R.layout.fragment_qr_code_full_screen)
}
)

private val insetsController by lazy { insetsController() }

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val containerTransform = MaterialContainerTransform()
Expand Down Expand Up @@ -72,53 +66,24 @@ class QrCodeFullScreenFragment : Fragment(R.layout.fragment_qr_code_full_screen)
override fun onStop() {
super.onStop()

clearSystemUiFlags()
}

private fun clearSystemUiFlags() {
decorView.systemUiVisibility = withLightUiFlags(SYSTEM_UI_FLAG_VISIBLE)
binding.toolbar.animate().translationY(0.0f)
exitImmersiveMode()
}

private fun exitImmersiveMode() {
binding.toolbar.animate().translationY(0.0f)
showSystemUI()
binding.toolbar.animate().alpha(1.0f)
insetsController.show(Type.systemBars())
}

private fun enterImmersiveMode() {
hideSystemUI()
binding.toolbar.apply {
animate().translationY(-height.toFloat())
}
}

private fun hideSystemUI() {
decorView.systemUiVisibility = withLightUiFlags(
SYSTEM_UI_FLAG_IMMERSIVE
or SYSTEM_UI_FLAG_LAYOUT_STABLE
or SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
or SYSTEM_UI_FLAG_HIDE_NAVIGATION
or SYSTEM_UI_FLAG_FULLSCREEN
)
insetsController.hide(Type.systemBars())
binding.toolbar.animate().alpha(0.0f)
}

private fun showSystemUI() {
decorView.systemUiVisibility = withLightUiFlags(
SYSTEM_UI_FLAG_LAYOUT_STABLE
or SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
)
}

private val decorView: View get() = requireActivity().window.decorView

private fun withLightUiFlags(flags: Int): Int {
var uiFlags = flags
if (resources.getBoolean(R.bool.lightSystemUI)) {
uiFlags = uiFlags or SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) uiFlags = uiFlags or SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
}
return uiFlags
private fun insetsController(): WindowInsetsControllerCompat {
val window = requireActivity().window
return WindowInsetsControllerCompat(window, window.decorView)
.apply {
systemBarsBehavior = BEHAVIOR_SHOW_BARS_BY_SWIPE
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ class FileSharing @Inject constructor(
createChooserIntent: Boolean = false
): FileIntentProvider = object : FileIntentProvider {
override fun intent(activity: Activity): Intent {
val builder = ShareCompat.IntentBuilder.from(activity).apply {
setType(path.determineMimeType())
setStream(getFileUri(path))
setSubject(title)
}
val builder = ShareCompat.IntentBuilder(activity)
.setType(path.determineMimeType())
.setStream(getFileUri(path))
.setSubject(title)

val intent = if (createChooserIntent) {
builder.createChooserIntent()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.rki.coronawarnapp.presencetracing.common

import android.content.Context
import androidx.core.app.NotificationChannelCompat
import androidx.core.app.NotificationManagerCompat
import de.rki.coronawarnapp.util.BuildVersionWrap
import io.mockk.MockKAnnotations
Expand Down Expand Up @@ -33,7 +34,7 @@ class TraceLocationNotificationsTest : BaseTest() {
every { BuildVersionWrap.SDK_INT } returns 42

notificationManager.apply {
every { createNotificationChannel(any()) } just Runs
every { createNotificationChannel(any<NotificationChannelCompat>()) } just Runs
every { notify(any(), any()) } just Runs
}
}
Expand All @@ -49,7 +50,7 @@ class TraceLocationNotificationsTest : BaseTest() {
instance.sendNotification(1, mockk())

verify {
notificationManager.createNotificationChannel(any())
notificationManager.createNotificationChannel(any<NotificationChannelCompat>())
notificationManager.notify(1, any())
}
}
Expand All @@ -60,7 +61,7 @@ class TraceLocationNotificationsTest : BaseTest() {
val instance = createInstance()
instance.sendNotification(1, mockk())

verify(exactly = 0) { notificationManager.createNotificationChannel(any()) }
verify(exactly = 0) { notificationManager.createNotificationChannel(any<NotificationChannelCompat>()) }
verify { notificationManager.notify(1, any()) }
}
}

0 comments on commit 36e77c9

Please sign in to comment.