Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update target and compile sdk version to v29 #12947

Merged
merged 11 commits into from
Sep 24, 2020
16 changes: 8 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ jobs:
test:
executor:
name: android/default
api-version: "28"
api-version: "29"
steps:
- git/shallow-checkout:
init-submodules: true
Expand Down Expand Up @@ -141,7 +141,7 @@ jobs:
lint:
executor:
name: android/default
api-version: "28"
api-version: "29"
steps:
- git/shallow-checkout:
init-submodules: true
Expand Down Expand Up @@ -187,7 +187,7 @@ jobs:
Installable Build:
executor:
name: android/default
api-version: "28"
api-version: "29"
steps:
- git/shallow-checkout:
init-submodules: true
Expand Down Expand Up @@ -233,7 +233,7 @@ jobs:
Release Build:
executor:
name: android/default
api-version: "28"
api-version: "29"
environment:
JVM_OPTS: -Xmx2048m
steps:
Expand Down Expand Up @@ -313,7 +313,7 @@ jobs:
default: false
executor:
name: android/default
api-version: "28"
api-version: "29"
steps:
- git/shallow-checkout:
init-submodules: true
Expand Down Expand Up @@ -358,7 +358,7 @@ jobs:
raw-screenshots:
executor:
name: android/default
api-version: "28"
api-version: "29"
working_directory: /tmp/workspace
steps:
- git/shallow-checkout:
Expand Down Expand Up @@ -474,7 +474,7 @@ jobs:
WordPressUtils Connected Tests:
executor:
name: android/default
api-version: "28"
api-version: "29"
steps:
- git/shallow-checkout:
init-submodules: true
Expand Down Expand Up @@ -524,7 +524,7 @@ jobs:
translation-review-build:
executor:
name: android/default
api-version: "28"
api-version: "29"
environment:
APP_VERSION_PREFIX: << pipeline.parameters.translation_review_lang_id >>
steps:
Expand Down
48 changes: 48 additions & 0 deletions WordPress/lint-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4197,4 +4197,52 @@
column="13"/>
</issue>

<issue
id="InlinedApi"
severity="Error"
message="Field requires API level 29 (current min is 21): `android.provider.MediaStore.MediaColumns#ORIENTATION`"
category="Correctness"
priority="6"
summary="Using inlined constants on older versions"
explanation="This check scans through all the Android API field references in the application and flags certain constants, such as static final integers and Strings, which were introduced in later versions. These will actually be copied into the class files rather than being referenced, which means that the value is available even when running on older devices. In some cases that&apos;s fine, and in other cases it can result in a runtime crash or incorrect behavior. It depends on the context, so consider the code carefully and decide whether it&apos;s safe and can be suppressed or whether the code needs to be guarded.&#xA;&#xA;If you really want to use this API and don&apos;t need to support older devices just set the `minSdkVersion` in your `build.gradle` or `AndroidManifest.xml` files.&#xA;&#xA;If your code is **deliberately** accessing newer APIs, and you have ensured (e.g. with conditional execution) that this code will only ever be called on a supported platform, then you can annotate your class or method with the `@TargetApi` annotation specifying the local minimum SDK to apply, such as `@TargetApi(11)`, such that this check considers 11 rather than your manifest file&apos;s minimum SDK as the required API level."
errorLine1=" .query(curStream, new String[]{MediaStore.Images.Media.ORIENTATION}, null, null, null);"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="/home/circleci/project/libs/utils/WordPressUtils/src/main/java/org/wordpress/android/util/ImageUtils.java"
line="101"
column="60"/>
</issue>

<issue
id="InlinedApi"
severity="Error"
message="Field requires API level 29 (current min is 21): `android.provider.MediaStore.MediaColumns#ORIENTATION`"
category="Correctness"
priority="6"
summary="Using inlined constants on older versions"
explanation="This check scans through all the Android API field references in the application and flags certain constants, such as static final integers and Strings, which were introduced in later versions. These will actually be copied into the class files rather than being referenced, which means that the value is available even when running on older devices. In some cases that&apos;s fine, and in other cases it can result in a runtime crash or incorrect behavior. It depends on the context, so consider the code carefully and decide whether it&apos;s safe and can be suppressed or whether the code needs to be guarded.&#xA;&#xA;If you really want to use this API and don&apos;t need to support older devices just set the `minSdkVersion` in your `build.gradle` or `AndroidManifest.xml` files.&#xA;&#xA;If your code is **deliberately** accessing newer APIs, and you have ensured (e.g. with conditional execution) that this code will only ever be called on a supported platform, then you can annotate your class or method with the `@TargetApi` annotation specifying the local minimum SDK to apply, such as `@TargetApi(11)`, such that this check considers 11 rather than your manifest file&apos;s minimum SDK as the required API level."
errorLine1=" orientation = cur.getInt(cur.getColumnIndex(MediaStore.Images.Media.ORIENTATION));"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="/home/circleci/project/libs/utils/WordPressUtils/src/main/java/org/wordpress/android/util/ImageUtils.java"
line="104"
column="65"/>
</issue>

<issue
id="InlinedApi"
severity="Error"
message="Field requires API level 29 (current min is 21): `android.provider.MediaStore.MediaColumns#DATE_TAKEN`"
category="Correctness"
priority="6"
summary="Using inlined constants on older versions"
explanation="This check scans through all the Android API field references in the application and flags certain constants, such as static final integers and Strings, which were introduced in later versions. These will actually be copied into the class files rather than being referenced, which means that the value is available even when running on older devices. In some cases that&apos;s fine, and in other cases it can result in a runtime crash or incorrect behavior. It depends on the context, so consider the code carefully and decide whether it&apos;s safe and can be suppressed or whether the code needs to be guarded.&#xA;&#xA;If you really want to use this API and don&apos;t need to support older devices just set the `minSdkVersion` in your `build.gradle` or `AndroidManifest.xml` files.&#xA;&#xA;If your code is **deliberately** accessing newer APIs, and you have ensured (e.g. with conditional execution) that this code will only ever be called on a supported platform, then you can annotate your class or method with the `@TargetApi` annotation specifying the local minimum SDK to apply, such as `@TargetApi(11)`, such that this check considers 11 rather than your manifest file&apos;s minimum SDK as the required API level."
errorLine1=" String sortOrder = MediaStore.Video.VideoColumns.DATE_TAKEN + &quot; DESC&quot;;"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="/home/circleci/project/libs/utils/WordPressUtils/src/main/java/org/wordpress/android/util/MediaUtils.java"
line="111"
column="28"/>
</issue>

</issues>
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class ActivityLogDetailFragment : Fragment() {
val (site, activityLogId) = when {
savedInstanceState != null -> {
val site = savedInstanceState.getSerializable(WordPress.SITE) as SiteModel
val activityLogId = savedInstanceState.getString(ACTIVITY_LOG_ID_KEY)
val activityLogId = requireNotNull(savedInstanceState.getString(ACTIVITY_LOG_ID_KEY))
site to activityLogId
}
intent != null -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ class DomainRegistrationDetailsFragment : Fragment() {
.get(DomainRegistrationDetailsViewModel::class.java)
setupObservers()

val domainProductDetails = arguments?.getParcelable(EXTRA_DOMAIN_PRODUCT_DETAILS) as DomainProductDetails
val domainProductDetails = requireNotNull(
arguments?.getParcelable<DomainProductDetails?>(EXTRA_DOMAIN_PRODUCT_DETAILS)
)
val site = requireActivity().intent?.getSerializableExtra(WordPress.SITE) as SiteModel

viewModel.start(site, domainProductDetails)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class HistoryDetailActivity : LocaleAwareActivity() {
setSupportActionBar(toolbar_main)
supportActionBar?.setDisplayHomeAsUpEnabled(true)

val extras = intent.extras
val revision = extras.getParcelable(HistoryDetailContainerFragment.EXTRA_REVISION) as Revision
val extras = requireNotNull(intent.extras)
val revision = extras.getParcelable<Revision>(HistoryDetailContainerFragment.EXTRA_REVISION)
val revisions = extras.getParcelableArrayList<Revision>(HistoryDetailContainerFragment.EXTRA_REVISIONS)

var historyDetailContainerFragment = supportFragmentManager.findFragmentByTag(KEY_HISTORY_DETAIL_FRAGMENT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ class BasicFragmentDialog : AppCompatDialogFragment() {
setStyle(STYLE_NORMAL, theme)

if (savedInstanceState != null) {
mTag = savedInstanceState.getString(STATE_KEY_TAG)
mTag = requireNotNull(savedInstanceState.getString(STATE_KEY_TAG))
mTitle = savedInstanceState.getCharSequence(STATE_KEY_TITLE)
mMessage = savedInstanceState.getCharSequence(STATE_KEY_MESSAGE)
mPositiveButtonLabel = savedInstanceState.getCharSequence(STATE_KEY_POSITIVE_BUTTON_LABEL)
mMessage = requireNotNull(savedInstanceState.getCharSequence(STATE_KEY_MESSAGE))
mPositiveButtonLabel = requireNotNull(savedInstanceState.getCharSequence(STATE_KEY_POSITIVE_BUTTON_LABEL))
mNegativeButtonLabel = savedInstanceState.getCharSequence(STATE_KEY_NEGATIVE_BUTTON_LABEL)
mCancelButtonLabel = savedInstanceState.getCharSequence(STATE_KEY_CANCEL_BUTTON_LABEL)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class PostDatePickerDialogFragment : DialogFragment() {
}

val datePickerDialog = DatePickerDialog(
activity,
requireContext(),
null,
viewModel.year ?: 0,
viewModel.month ?: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ class PromoDialog : AppCompatDialogFragment() {
super.onCreate(savedInstanceState)

if (savedInstanceState != null) {
fragmentTag = savedInstanceState.getString(STATE_KEY_TAG)
title = savedInstanceState.getString(STATE_KEY_TITLE)
message = savedInstanceState.getString(STATE_KEY_MESSAGE)
positiveButtonLabel = savedInstanceState.getString(STATE_KEY_POSITIVE_BUTTON_LABEL)
negativeButtonLabel = savedInstanceState.getString(STATE_KEY_NEGATIVE_BUTTON_LABEL)
neutralButtonLabel = savedInstanceState.getString(STATE_KEY_NEUTRAL_BUTTON_LABEL)
linkLabel = savedInstanceState.getString(STATE_KEY_LINK_LABEL)
fragmentTag = requireNotNull(savedInstanceState.getString(STATE_KEY_TAG))
title = requireNotNull(savedInstanceState.getString(STATE_KEY_TITLE))
message = requireNotNull(savedInstanceState.getString(STATE_KEY_MESSAGE))
positiveButtonLabel = requireNotNull(savedInstanceState.getString(STATE_KEY_POSITIVE_BUTTON_LABEL))
negativeButtonLabel = requireNotNull(savedInstanceState.getString(STATE_KEY_NEGATIVE_BUTTON_LABEL))
neutralButtonLabel = requireNotNull(savedInstanceState.getString(STATE_KEY_NEUTRAL_BUTTON_LABEL))
linkLabel = requireNotNull(savedInstanceState.getString(STATE_KEY_LINK_LABEL))
drawableResId = savedInstanceState.getInt(STATE_KEY_DRAWABLE_RES_ID)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class SiteCreationMainVM @Inject constructor(
tracker.trackSiteCreationAccessed()
siteCreationState = SiteCreationState()
} else {
siteCreationState = savedInstanceState.getParcelable(KEY_SITE_CREATION_STATE)
siteCreationState = requireNotNull(savedInstanceState.getParcelable(KEY_SITE_CREATION_STATE))
val currentStepIndex = savedInstanceState.getInt(KEY_CURRENT_STEP)
wizardManager.setCurrentStepIndex(currentStepIndex)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ sealed class SiteCreationDomainViewHolder(internal val parent: ViewGroup, @Layou
}

private fun addRetryCompoundDrawable() {
val drawable = itemView.context.getDrawable(R.drawable.retry_icon)
drawable.setTint(ContextCompat.getColor(itemView.context, R.color.primary))
retry.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null)
itemView.context.getDrawable(R.drawable.retry_icon)?.let { drawable ->
drawable.setTint(ContextCompat.getColor(itemView.context, R.color.primary))
retry.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null)
}
}

override fun onBind(uiState: DomainsListItemUiState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,9 @@ class SelectedDateProvider
} else {
null
}
val availableTimeStamps = mutableListOf<Long>()
val availableTimeStamps = mutableListOf<Any?>()
parcel.readList(availableTimeStamps, null)
val availableDates = availableTimeStamps.map { Date(it) }
val availableDates = availableTimeStamps.map { Date(it as Long) }
val loading = parcel.readValue(null) as Boolean
val error = parcel.readValue(null) as Boolean
return SelectedDate(date, availableDates, loading, error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ class TextViewHolder(parent: ViewGroup) : BlockListItemViewHolder(
onClickListener: (Context) -> Unit
): SpannableString {
val clickableSpan = object : ClickableSpan() {
override fun onClick(widget: View?) {
widget?.context?.let { onClickListener.invoke(it) }
override fun onClick(widget: View) {
widget.context?.let { onClickListener.invoke(it) }
}

override fun updateDrawState(ds: TextPaint?) {
ds?.color = context.getColorFromAttribute(R.attr.colorPrimary)
ds?.typeface = Typeface.create(
override fun updateDrawState(ds: TextPaint) {
ds.color = context.getColorFromAttribute(R.attr.colorPrimary)
ds.typeface = Typeface.create(
Typeface.DEFAULT_BOLD,
Typeface.NORMAL
)
ds?.isUnderlineText = false
ds.isUnderlineText = false
}
}
val clickablePartStart = indexOf(clickablePart)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@ private inline fun <reified T : Enum<T>> Intent.putEnumExtra(key: String, victim
private inline fun <reified T : Enum<T>> Intent.getEnumExtra(key: String, default: T): T =
getIntExtra(key, -1)
.takeUnless { it == -1 }
?.let { T::class.java.enumConstants[it] } ?: default
?.let {
@Suppress("UNNECESSARY_SAFE_CALL")
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this @Suppress needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Android studio complains when it's not there - I believe it's a false positive.
Screenshot 2020-09-23 at 11 37 40

Copy link
Contributor

@mchowning mchowning Sep 23, 2020

Choose a reason for hiding this comment

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

Interestingly Android Studio doesn't seem to give me any warning if I remove the @Suppress line like you did in the screenshot. 🤔

Certainly makes sense to include the @Suppress since you're seeing the warning though. 👍

T::class.java.enumConstants?.get(it)
} ?: default
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class UiHelpers @Inject constructor() {

companion object {
fun adjustDialogSize(dialog: Dialog) {
val window = dialog.window
val window = requireNotNull(dialog.window)
val size = Point()

val display = window.windowManager.defaultDisplay
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class PluginBrowserViewModel @Inject constructor(
return
}
site = savedInstanceState.getSerializable(WordPress.SITE) as SiteModel
searchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY)
searchQuery = requireNotNull(savedInstanceState.getString(KEY_SEARCH_QUERY))
setTitle(savedInstanceState.getString(KEY_TITLE))
}

Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ buildScan {
}

ext {
compileSdkVersion = 28
buildToolVersion = '28.0.3'
compileSdkVersion = 29
buildToolVersion = '29.0.2'

minSdkVersion = 21
targetSdkVersion = 28
targetSdkVersion = 29

coroutinesVersion = '1.3.3'
androidxWorkVersion = "2.0.1"
Expand Down
4 changes: 2 additions & 2 deletions libs/analytics/WordPressAnalytics/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ dependencies {
}

android {
compileSdkVersion 28
compileSdkVersion 29

defaultConfig {
versionName "1.3.0"
minSdkVersion 16
targetSdkVersion 26
targetSdkVersion 29
}
}

Expand Down
4 changes: 2 additions & 2 deletions libs/editor/WordPressEditor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ apply plugin: 'kotlin-android-extensions'
apply from: 'https://gist.githubusercontent.com/hypest/e06f6097065728b6db7b7c462f8fef1a/raw/3b91756fca76e4c2a9b573313e186c47842e1f7d/submoduleGitHash.gradle'

android {
compileSdkVersion 28
compileSdkVersion 29

defaultConfig {
versionCode 13
versionName "1.3"
minSdkVersion 21
targetSdkVersion 28
targetSdkVersion 29
buildConfigField "boolean", "BUILD_GUTENBERG_FROM_SOURCE", (rootProject.ext.has("buildGutenbergFromSource") ? rootProject.ext.buildGutenbergFromSource : false).toString()
}
compileOptions {
Expand Down
4 changes: 2 additions & 2 deletions libs/editor/example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ repositories {
}

android {
compileSdkVersion 28
compileSdkVersion 29

defaultConfig {
applicationId "org.wordpress.editorexample"
minSdkVersion 21
targetSdkVersion 28
targetSdkVersion 29
versionCode 1
versionName "1.0"
}
Expand Down
4 changes: 2 additions & 2 deletions libs/mocks/WordPressMocks/build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 28
compileSdkVersion 29
defaultConfig {
minSdkVersion 16
targetSdkVersion 26
targetSdkVersion 29
versionCode 1
versionName "1.0"
}
Expand Down
4 changes: 2 additions & 2 deletions libs/networking/WordPressNetworking/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ apply plugin: 'com.android.library'
apply plugin: 'maven'

android {
compileSdkVersion 28
compileSdkVersion 29

defaultConfig {
minSdkVersion 14
targetSdkVersion 26
targetSdkVersion 29
versionName "1.0.0"
}
}
Expand Down
4 changes: 2 additions & 2 deletions libs/utils/WordPressUtils/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ dependencies {
android {
useLibrary 'org.apache.http.legacy'

compileSdkVersion 28
compileSdkVersion 29

defaultConfig {
versionName "1.30"
minSdkVersion 18
targetSdkVersion 26
targetSdkVersion 29

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down