Skip to content
Open
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
14 changes: 8 additions & 6 deletions AnkiDroid/src/main/java/com/ichi2/anki/AnkiActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.view.Window
import android.view.WindowInsetsController
import android.view.WindowManager
import android.widget.ProgressBar
import androidx.activity.result.ActivityResult
Expand All @@ -46,6 +47,7 @@ import androidx.core.app.ShareCompat
import androidx.core.content.ContextCompat
import androidx.core.content.FileProvider
import androidx.core.net.toUri
import androidx.core.view.WindowInsetsCompat
import androidx.fragment.app.Fragment
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
Expand Down Expand Up @@ -131,7 +133,6 @@ open class AnkiActivity(
}
}

@Suppress("deprecation") // #9332: UI Visibility -> Insets
override fun onCreate(savedInstanceState: Bundle?) {
// The hardware buttons should control the music volume
volumeControlStream = AudioManager.STREAM_MUSIC
Expand All @@ -140,13 +141,14 @@ open class AnkiActivity(
Themes.disableXiaomiForceDarkMode(this)
super.onCreate(savedInstanceState)
// Disable the notifications bar if running under the test monkey.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Context (please add a comment):

In ~2020, the issue with the money was that it could pull down on the status bar, and start interacting with real apps on a physical device 😅

This was a quick hack to get it back on track in an emulator-based context

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly, I'm not sure if this is a full fix for the monkey on a physical device (I had a similar issue on my physical device, although iirc it was triggered by the app crashing).

if (AdaptionUtil.isUserATestClient) {
window.setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN,
)
// This is a work-around for aa issue with the monkey feature of adb - when the
// monkey runs on a physical device, it can pull the status bar down, and escape the app
// under test.
if (AdaptionUtil.isUserATestClient && window != null) {
CompatHelper.compat.hideStatusBar(window)
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
@Suppress("deprecation")
window.navigationBarColor = getColor(R.color.transparent)
}
supportFragmentManager.setFragmentResultListener(REQUEST_EXPORT_SAVE, this) { _, bundle ->
Expand Down
10 changes: 10 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/compat/BaseCompat.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import android.os.Environment
import android.os.Vibrator
import android.provider.MediaStore
import android.view.View
import android.view.Window
import android.view.WindowManager
import androidx.appcompat.widget.TooltipCompat
import com.ichi2.anki.common.utils.annotation.KotlinCleanup
import timber.log.Timber
Expand All @@ -52,6 +54,14 @@ open class BaseCompat : Compat {
TooltipCompat.setTooltipText(view, view.contentDescription)
}

// Until API36, `setFlags` is the recommended method to hide status controller
override fun hideStatusBar(window: Window) {
window.setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN,
)
}

// Until API 26 just specify time, after that specify effect also
override fun vibrate(
context: Context,
Expand Down
3 changes: 3 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/compat/Compat.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import android.net.Uri
import android.os.Bundle
import android.os.Environment
import android.view.View
import android.view.Window
import java.io.File
import java.io.FileNotFoundException
import java.io.IOException
Expand Down Expand Up @@ -86,6 +87,8 @@ interface Compat {

fun getMediaRecorder(context: Context): MediaRecorder

fun hideStatusBar(window: Window)

fun resolveActivity(
packageManager: PackageManager,
intent: Intent,
Expand Down
2 changes: 2 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/compat/CompatHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ class CompatHelper private constructor() {
@SuppressLint("NewApi")
private val compatValue: Compat =
when {
sdkVersion >= Build.VERSION_CODES.R -> CompatV36()
sdkVersion >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE -> CompatV34()
sdkVersion >= Build.VERSION_CODES.TIRAMISU -> CompatV33()
sdkVersion >= Build.VERSION_CODES.S -> CompatV31()
sdkVersion >= Build.VERSION_CODES.Q -> CompatV29()
sdkVersion >= Build.VERSION_CODES.O -> CompatV26()
sdkVersion >= Build.VERSION_CODES.R -> CompatV26()
Comment on lines +51 to +57
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks wrong

else -> BaseCompat()
}

Expand Down
32 changes: 32 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/compat/CompatV36.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2023 David Allison <davidallisongithub@gmail.com>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't my copyright, use yours. Pseudonyms are fine

*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.ichi2.compat

import android.view.MotionEvent
import android.view.Window
import android.view.WindowManager
import androidx.annotation.RequiresApi
import androidx.core.view.WindowInsetsCompat

@RequiresApi(34)
@Suppress("ktlint:standard:property-naming")
open class CompatV36 : CompatV34() {
// As of API36, insetsController is the correct way to hide the status bar
override fun hideStatusBar(window: Window) {
window.insetsController?.hide(WindowInsetsCompat.Type.statusBars())
}
}