Skip to content

Commit

Permalink
chore: forward-port to compileSdk 35
Browse files Browse the repository at this point in the history
most of the changes performed at same time are nullability-related

there are two specific things deferred via suppression annotation:
- all the targetSdk 35 edge-to-edge behavior changes - this is a big one
- one compute bounds thing for graphics, minor but API change is confusing
  • Loading branch information
mikehardy committed Oct 31, 2024
1 parent c59627a commit 0a86515
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 10 deletions.
1 change: 1 addition & 0 deletions AnkiDroid/src/main/java/com/ichi2/anki/AnkiActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,7 @@ open class AnkiActivity : AppCompatActivity, SimpleMessageDialogListener, Shortc
)

/** @see Window.setNavigationBarColor */
@Suppress("deprecation", "API35 properly handle edge-to-edge")
fun setNavigationBarColor(@AttrRes attr: Int) {
window.navigationBarColor = Themes.getColorFromAttr(this, attr)
}
Expand Down
2 changes: 2 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/anki/AnkiFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ open class AnkiFragment(@LayoutRes layout: Int) : Fragment(layout), AnkiActivity
hideProgressBar()
}

@Suppress("deprecation", "API35 properly handle edge-to-edge")
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
requireActivity().window.statusBarColor = Themes.getColorFromAttr(requireContext(), R.attr.appBarColor)
super.onViewCreated(view, savedInstanceState)
Expand Down Expand Up @@ -96,6 +97,7 @@ open class AnkiFragment(@LayoutRes layout: Int) : Fragment(layout), AnkiActivity
*/
protected suspend fun userAcceptsSchemaChange() = ankiActivity.userAcceptsSchemaChange()

@Suppress("deprecation", "API35 properly handle edge-to-edge")
fun setNavigationBarColor(@AttrRes attr: Int) {
requireActivity().window.navigationBarColor =
Themes.getColorFromAttr(requireContext(), attr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ object CrashReportService {
Timber.w("Could not get WebView package information")
return webViewInfo
}
webViewInfo[WEBVIEW_VER_NAME] = pi.versionName
pi.versionName?.let { webViewInfo[WEBVIEW_VER_NAME] = it }
webViewInfo["WEBVIEW_VER_CODE"] = PackageInfoCompat.getLongVersionCode(pi).toString()
} catch (e: Throwable) {
Timber.w(e)
Expand Down
6 changes: 5 additions & 1 deletion AnkiDroid/src/main/java/com/ichi2/anki/InitialActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,11 @@ object InitialActivity {
*/
fun checkWebviewVersion(packageManager: PackageManager, activity: AnkiActivity) {
val webviewPackageInfo = getAndroidSystemWebViewPackageInfo(packageManager) ?: return
val versionCode = webviewPackageInfo.versionName.split(".")[0].toInt()
val webviewVersion = webviewPackageInfo.versionName ?: run {
Timber.w("Failed to obtain WebView version")
return
}
val versionCode = webviewVersion.split(".")[0].toInt()
if (versionCode >= OLDEST_WORKING_WEBVIEW_VERSION) {
Timber.d("WebView is up to date. %s: %s", webviewPackageInfo.packageName, webviewPackageInfo.versionName)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ abstract class NavigationDrawerActivity :
}

// Navigation drawer initialisation
@Suppress("deprecation", "API35 properly handle edge-to-edge")
protected fun initNavigationDrawer(mainView: View) {
// Create inherited navigation drawer layout here so that it can be used by parent class
drawerLayout = mainView.findViewById(R.id.drawer_layout)
Expand Down
1 change: 1 addition & 0 deletions AnkiDroid/src/main/java/com/ichi2/anki/Whiteboard.kt
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ class Whiteboard(activity: AnkiActivity, private val handleMultiTouch: Boolean,
invalidate()
}

@Suppress("deprecation", "API35 computeBounds - maybe compat, but...new API is Flagged?")
fun erase(x: Int, y: Int): Boolean {
var didErase = false
val clip = Region(0, 0, displayDimensions.x, displayDimensions.y)
Expand Down
1 change: 1 addition & 0 deletions AnkiDroid/src/main/java/com/ichi2/anki/pages/Statistics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Statistics :
private lateinit var deckSpinnerSelection: DeckSpinnerSelection
private lateinit var spinner: Spinner

@Suppress("deprecation", "API35 properly handle edge-to-edge")
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
webView.isNestedScrollingEnabled = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import kotlin.reflect.jvm.jvmName
* @see TemplatePreviewerFragment
*/
class CardViewerActivity : SingleFragmentActivity() {
@Suppress("deprecation", "API35 properly handle edge-to-edge")
override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge() // TODO assess moving this to SingleFragmentActivity
super.onCreate(savedInstanceState)
Expand Down
1 change: 1 addition & 0 deletions AnkiDroid/src/main/java/com/ichi2/themes/Themes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ object Themes {
}
}

@Suppress("deprecation", "API35 properly handle edge-to-edge")
fun FragmentActivity.setTransparentStatusBar() {
WindowInsetsControllerCompat(window, window.decorView).isAppearanceLightStatusBars =
!Themes.currentTheme.isNightMode
Expand Down
4 changes: 2 additions & 2 deletions AnkiDroid/src/main/java/com/ichi2/utils/AdaptionUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ object AdaptionUtil {
return if (packageName != null) {
try {
val info = pm.getPackageInfoCompat(packageName, PackageInfoFlagsCompat.EMPTY) ?: return false
info.applicationInfo != null &&
info.applicationInfo.flags and ApplicationInfo.FLAG_SYSTEM != 0
val appInfo = info.applicationInfo ?: return false
appInfo.flags and ApplicationInfo.FLAG_SYSTEM != 0
} catch (e: PackageManager.NameNotFoundException) {
Timber.w(e)
false
Expand Down
8 changes: 5 additions & 3 deletions AnkiDroid/src/main/java/com/ichi2/utils/VersionUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ object VersionUtils {
Timber.w("Couldn't find package named %s", context.packageName)
return pkgName
}
pkgName = context.getString(pInfo.applicationInfo.labelRes)
pInfo.applicationInfo?.let {
pkgName = context.getString(it.labelRes)
}
} catch (e: PackageManager.NameNotFoundException) {
Timber.e(e, "Couldn't find package named %s", context.packageName)
}
Expand All @@ -59,9 +61,9 @@ object VersionUtils {
val context: Context = applicationInstance ?: return pkgVersion
try {
val pInfo = context.getPackageInfoCompat(context.packageName, PackageInfoFlagsCompat.EMPTY) ?: return pkgVersion
pkgVersion = pInfo.versionName
return pInfo.versionName ?: pkgVersion
} catch (e: PackageManager.NameNotFoundException) {
Timber.e(e, "Couldn't find package named %s", context.packageName)
Timber.w(e, "Couldn't find package named %s", context.packageName)
}
return pkgVersion
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import com.ichi2.compat.CompatHelper.Companion.getPackageInfoCompat
import com.ichi2.compat.PackageInfoFlagsCompat
import com.ichi2.testutils.ActivityList
import com.ichi2.utils.emptyStringArray
import org.hamcrest.MatcherAssert
import org.hamcrest.Matchers
import org.junit.Test
Expand All @@ -33,9 +34,11 @@ class ActivityStartupMetaTest : RobolectricTest() {

// we can't access this in a static context
val packageInfo = targetContext.getPackageInfoCompat(targetContext.packageName, PackageInfoFlagsCompat.of(PackageManager.GET_ACTIVITIES.toLong())) ?: throw IllegalStateException("getPackageInfo failed")
val manifestActivities = packageInfo.activities

val manifestActivities = packageInfo.activities ?: throw IllegalStateException("activity list")
val testedActivityClassNames = ActivityList.allActivitiesAndIntents().map { it.className }.toSet()
val manifestActivityNames = manifestActivities
var manifestActivityNames: Array<String> = emptyStringArray(0)
manifestActivityNames = manifestActivities
.map { it.name }
.filter { it != "com.ichi2.anki.TestCardTemplatePreviewer" }
.filter { it != "com.ichi2.anki.AnkiCardContextMenuAction" }
Expand All @@ -45,6 +48,7 @@ class ActivityStartupMetaTest : RobolectricTest() {
.filter { !it.startsWith("leakcanary.internal") }
.filter { it != "com.canhub.cropper.CropImageActivity" }
.toTypedArray()

MatcherAssert.assertThat(testedActivityClassNames, Matchers.containsInAnyOrder(*manifestActivityNames))
}
}
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
compileSdk = "34"
compileSdk = "35"
minSdk = "23" # also in testlib/build.gradle.kts
targetSdk = "34" # also in ../robolectricDownloader.gradle
acra = '5.11.4'
Expand Down

0 comments on commit 0a86515

Please sign in to comment.