Skip to content

Commit 9b0b936

Browse files
Fix:5175 Upgraded Minimum SDK Version, Compile and Target SDK Version (#5177)
* Kotlin Version Upgraded to 1.6.10 * Kotlin Version Upgraded to 1.6.20 * Kotlin Version Upgraded to 1.7.20 * Fix:5175 Upgraded Minimum SDK Version, Compile and Target SDK Version
1 parent 66e15a1 commit 9b0b936

File tree

13 files changed

+110
-63
lines changed

13 files changed

+110
-63
lines changed

app/build.gradle

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ dependencies {
8585

8686
// Unit testing
8787
testImplementation 'junit:junit:4.13.2'
88-
testImplementation 'org.robolectric:robolectric:4.6-alpha-1'
88+
testImplementation 'org.robolectric:robolectric:4.6.1'
8989
testImplementation 'androidx.test:core:1.4.0'
9090
testImplementation "com.squareup.okhttp3:mockwebserver:$OKHTTP_VERSION"
9191
testImplementation "com.jraska.livedata:testing-ktx:1.1.2"
@@ -111,8 +111,6 @@ dependencies {
111111

112112
// Debugging
113113
debugImplementation "com.squareup.leakcanary:leakcanary-android:$LEAK_CANARY_VERSION"
114-
releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$LEAK_CANARY_VERSION"
115-
testImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$LEAK_CANARY_VERSION"
116114

117115
// Support libraries
118116
implementation "com.google.android.material:material:1.1.0-alpha04"
@@ -144,9 +142,10 @@ dependencies {
144142

145143
implementation "androidx.multidex:multidex:$MULTIDEX_VERSION"
146144

147-
def work_version = "2.6.0"
145+
def work_version = "2.8.0"
148146
// Kotlin + coroutines
149147
implementation "androidx.work:work-runtime-ktx:$work_version"
148+
implementation("androidx.work:work-runtime:$work_version")
150149
testImplementation "androidx.work:work-testing:$work_version"
151150

152151
//Glide
@@ -169,7 +168,7 @@ project.gradle.taskGraph.whenReady {
169168
}
170169

171170
android {
172-
compileSdkVersion 30
171+
compileSdkVersion 31
173172

174173
defaultConfig {
175174
//applicationId 'fr.free.nrw.commons'
@@ -178,8 +177,8 @@ android {
178177
versionName '4.0.3'
179178
setProperty("archivesBaseName", "app-commons-v$versionName-" + getBranchName())
180179

181-
minSdkVersion 19
182-
targetSdkVersion 30
180+
minSdkVersion 21
181+
targetSdkVersion 31
183182
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
184183
testInstrumentationRunnerArguments clearPackageData: 'true'
185184

app/src/main/AndroidManifest.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@
6161
android:configChanges="screenSize|keyboard|orientation"
6262
android:parentActivityName=".customselector.ui.selector.CustomSelectorActivity" />
6363

64-
<activity android:name=".auth.LoginActivity">
64+
<activity android:name=".auth.LoginActivity"
65+
android:exported="true">
6566
<intent-filter>
6667
<category android:name="android.intent.category.LAUNCHER" />
6768

@@ -77,6 +78,7 @@
7778
<activity
7879
android:hardwareAccelerated="false"
7980
android:name=".upload.UploadActivity"
81+
android:exported="true"
8082
android:configChanges="orientation|screenSize|keyboard"
8183
android:icon="@mipmap/ic_launcher"
8284
android:label="@string/app_name"
@@ -235,7 +237,8 @@
235237
android:label="@string/provider_bookmarks_location"
236238
android:syncable="false" />
237239

238-
<receiver android:name=".widget.PicOfDayAppWidget">
240+
<receiver android:name=".widget.PicOfDayAppWidget"
241+
android:exported="true">
239242
<intent-filter>
240243
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
241244
</intent-filter>

app/src/main/java/fr/free/nrw/commons/CommonsApplication.java

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
import com.facebook.imagepipeline.core.ImagePipeline;
2525
import com.facebook.imagepipeline.core.ImagePipelineConfig;
2626
import com.mapbox.mapboxsdk.Mapbox;
27-
import com.squareup.leakcanary.LeakCanary;
28-
import com.squareup.leakcanary.RefWatcher;
2927
import fr.free.nrw.commons.auth.SessionManager;
3028
import fr.free.nrw.commons.bookmarks.items.BookmarkItemsDao.Table;
3129
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao;
@@ -55,6 +53,7 @@
5553
import java.util.Set;
5654
import javax.inject.Inject;
5755
import javax.inject.Named;
56+
import leakcanary.ObjectWatcher;
5857
import org.acra.ACRA;
5958
import org.acra.annotation.AcraCore;
6059
import org.acra.annotation.AcraDialog;
@@ -122,7 +121,7 @@ public class CommonsApplication extends MultiDexApplication {
122121
* Constants End
123122
*/
124123

125-
private RefWatcher refWatcher;
124+
private ObjectWatcher objectWatcher;
126125

127126
private static CommonsApplication INSTANCE;
128127

@@ -193,9 +192,6 @@ public void onCreate() {
193192
// or from Observables that are (deliberately or not) missing an onError handler.
194193
RxJavaPlugins.setErrorHandler(Functions.emptyConsumer());
195194

196-
if (setupLeakCanary() == RefWatcher.DISABLED) {
197-
return;
198-
}
199195
// Fire progress callbacks for every 3% of uploaded content
200196
System.setProperty("in.yuvi.http.fluent.PROGRESS_TRIGGER_THRESHOLD", "3.0");
201197
}
@@ -273,26 +269,14 @@ public String getUserAgent() {
273269
}
274270

275271
/**
276-
* Helps in setting up LeakCanary library
277-
*
278-
* @return instance of LeakCanary
279-
*/
280-
protected RefWatcher setupLeakCanary() {
281-
if (LeakCanary.isInAnalyzerProcess(this)) {
282-
return RefWatcher.DISABLED;
283-
}
284-
return LeakCanary.install(this);
285-
}
286-
287-
/**
288-
* Provides a way to get member refWatcher
272+
* Provides a way to get member objectWatcher
289273
*
290274
* @param context Application context
291-
* @return application member refWatcher
275+
* @return application member objectWatcher
292276
*/
293-
public static RefWatcher getRefWatcher(Context context) {
277+
public static ObjectWatcher getObjectWatcher(Context context) {
294278
CommonsApplication application = (CommonsApplication) context.getApplicationContext();
295-
return application.refWatcher;
279+
return application.objectWatcher;
296280
}
297281

298282
/**

app/src/main/java/fr/free/nrw/commons/customselector/ui/selector/ImageLoader.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,18 @@ class ImageLoader @Inject constructor(
138138
is Result.TRUE -> {
139139
mapResult[imageSHA1] = Result.TRUE
140140
}
141+
is Result.ERROR -> {
142+
mapResult[imageSHA1] = Result.ERROR
143+
}
144+
is Result.FALSE -> {
145+
mapResult[imageSHA1] = Result.FALSE
146+
}
147+
is Result.INVALID -> {
148+
mapResult[imageSHA1] = Result.INVALID
149+
}
150+
is Result.NOTFOUND -> {
151+
mapResult[imageSHA1] = Result.NOTFOUND
152+
}
141153
}
142154
}
143155
else -> {
@@ -160,6 +172,18 @@ class ImageLoader @Inject constructor(
160172
is Result.TRUE -> {
161173
mapResult[sha1] = Result.TRUE
162174
}
175+
is Result.ERROR -> {
176+
mapResult[sha1] = Result.ERROR
177+
}
178+
is Result.FALSE -> {
179+
mapResult[sha1] = Result.FALSE
180+
}
181+
is Result.INVALID -> {
182+
mapResult[sha1] = Result.INVALID
183+
}
184+
is Result.NOTFOUND -> {
185+
mapResult[sha1] = Result.NOTFOUND
186+
}
163187
}
164188
}
165189
else -> {

app/src/main/java/fr/free/nrw/commons/upload/LanguagesAdapter.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class LanguagesAdapter constructor(
8686
}
8787

8888
fun getIndexOfUserDefaultLocale(context: Context): Int {
89-
return language.codes.indexOf(context.locale.language)
89+
return language.codes.indexOf(context.locale!!.language)
9090
}
9191

9292
fun getIndexOfLanguageCode(languageCode: String): Int {
@@ -138,5 +138,5 @@ class LanguagesAdapter constructor(
138138

139139
}
140140

141-
private val Context.locale: Locale
141+
private val Context.locale: Locale?
142142
get() = ConfigurationCompat.getLocales(resources.configuration)[0]

app/src/test/kotlin/fr/free/nrw/commons/OkHttpJsonApiClientTests.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class OkHttpJsonApiClientTests {
6363

6464
@Test
6565
fun testGetNearbyPlacesCustomQuery() {
66-
Mockito.`when`(response.message()).thenReturn("test")
66+
Mockito.`when`(response.message).thenReturn("test")
6767
try {
6868
okHttpJsonApiClient.getNearbyPlaces(latLng, "test", 10.0, true, "test")
6969
} catch (e: Exception) {
@@ -76,7 +76,7 @@ class OkHttpJsonApiClientTests {
7676

7777
@Test
7878
fun testGetNearbyPlaces() {
79-
Mockito.`when`(response.message()).thenReturn("test")
79+
Mockito.`when`(response.message).thenReturn("test")
8080
try {
8181
okHttpJsonApiClient.getNearbyPlaces(latLng, "test", 10.0, true)
8282
} catch (e: Exception) {

app/src/test/kotlin/fr/free/nrw/commons/TestCommonsApplication.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import android.content.Context
66
import androidx.collection.LruCache
77
import com.google.gson.Gson
88
import com.nhaarman.mockitokotlin2.mock
9-
import com.squareup.leakcanary.RefWatcher
109
import fr.free.nrw.commons.auth.AccountUtil
1110
import fr.free.nrw.commons.data.DBOpenHelper
1211
import fr.free.nrw.commons.di.CommonsApplicationComponent

app/src/test/kotlin/fr/free/nrw/commons/media/CustomOkHttpNetworkFetcherUnitTest.kt

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ class CustomOkHttpNetworkFetcherUnitTest {
149149
@Test
150150
@Throws(Exception::class)
151151
fun testOnFetchResponseCaseReturn() {
152-
whenever(response.body()).thenReturn(body)
152+
whenever(response.body).thenReturn(body)
153153
whenever(response.isSuccessful).thenReturn(false)
154-
whenever(call.isCanceled).thenReturn(true)
154+
whenever(call.isCanceled()).thenReturn(true)
155155
val method: Method = CustomOkHttpNetworkFetcher::class.java.getDeclaredMethod(
156156
"onFetchResponse",
157157
CustomOkHttpNetworkFetcher.OkHttpNetworkFetchState::class.java,
@@ -167,11 +167,22 @@ class CustomOkHttpNetworkFetcherUnitTest {
167167
@Test
168168
@Throws(Exception::class)
169169
fun testOnFetchResponse() {
170-
whenever(response.body()).thenReturn(body)
170+
whenever(response.body).thenReturn(body)
171171
whenever(response.isSuccessful).thenReturn(true)
172-
whenever(response.header("Content-Range")).thenReturn("bytes 200-1000/67589")
173-
whenever(call.isCanceled).thenReturn(true)
172+
173+
whenever(call.isCanceled()).thenReturn(true)
174174
whenever(body.contentLength()).thenReturn(-1)
175+
176+
// Build Response object with Content-Range header
177+
val responseBuilder = Response.Builder()
178+
.request(Request.Builder().url("http://example.com").build())
179+
.protocol(Protocol.HTTP_1_1)
180+
.code(200)
181+
.message("OK")
182+
.header("Content-Range", "bytes 200-1000/67589")
183+
.body(body)
184+
whenever(call.execute()).thenReturn(responseBuilder.build())
185+
175186
val method: Method = CustomOkHttpNetworkFetcher::class.java.getDeclaredMethod(
176187
"onFetchResponse",
177188
CustomOkHttpNetworkFetcher.OkHttpNetworkFetchState::class.java,
@@ -180,18 +191,29 @@ class CustomOkHttpNetworkFetcherUnitTest {
180191
NetworkFetcher.Callback::class.java,
181192
)
182193
method.isAccessible = true
183-
method.invoke(fetcher, state, call, response, callback)
194+
method.invoke(fetcher, state, call, responseBuilder.build(), callback)
184195
verify(callback).onResponse(null, 0)
185196
}
186197

187198
@Test
188199
@Throws(Exception::class)
189200
fun testOnFetchResponseCaseException() {
190-
whenever(response.body()).thenReturn(body)
201+
whenever(response.body).thenReturn(body)
191202
whenever(response.isSuccessful).thenReturn(true)
192-
whenever(response.header("Content-Range")).thenReturn("test")
193-
whenever(call.isCanceled).thenReturn(false)
203+
204+
whenever(call.isCanceled()).thenReturn(false)
194205
whenever(body.contentLength()).thenReturn(-1)
206+
207+
// Build Response object with Content-Range header
208+
val responseBuilder = Response.Builder()
209+
.request(Request.Builder().url("http://example.com").build())
210+
.protocol(Protocol.HTTP_1_1)
211+
.code(200)
212+
.message("OK")
213+
.header("Content-Range", "Test")
214+
.body(body)
215+
whenever(call.execute()).thenReturn(responseBuilder.build())
216+
195217
val method: Method = CustomOkHttpNetworkFetcher::class.java.getDeclaredMethod(
196218
"onFetchResponse",
197219
CustomOkHttpNetworkFetcher.OkHttpNetworkFetchState::class.java,
@@ -200,7 +222,7 @@ class CustomOkHttpNetworkFetcherUnitTest {
200222
NetworkFetcher.Callback::class.java,
201223
)
202224
method.isAccessible = true
203-
method.invoke(fetcher, state, call, response, callback)
225+
method.invoke(fetcher, state, call, responseBuilder.build(), callback)
204226
verify(callback).onFailure(any())
205227
}
206228

app/src/test/kotlin/fr/free/nrw/commons/upload/LanguagesAdapterTest.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ class LanguagesAdapterTest {
7979
@Test
8080
fun testGetIndexOfUserDefaultLocale() {
8181
languagesAdapter = LanguagesAdapter(context, selectedLanguages)
82-
Assertions.assertEquals(languageCodesList.indexOf(ConfigurationCompat.getLocales(context.resources.configuration)[0].language), languagesAdapter.getIndexOfUserDefaultLocale(context))
82+
Assertions.assertEquals(ConfigurationCompat.getLocales(context.resources.configuration)[0]?.let {
83+
languageCodesList.indexOf(
84+
it.language)
85+
}, languagesAdapter.getIndexOfUserDefaultLocale(context))
8386
}
8487

8588
@Test
@@ -105,14 +108,17 @@ class LanguagesAdapterTest {
105108
val constraint = "spa"
106109
languagesAdapter.filter.filter(constraint)
107110
val length: Int = languageNamesList.size
108-
val defaultlanguagecode = languageCodesList.indexOf(ConfigurationCompat.getLocales(context.resources.configuration)[0].language)
111+
val defaultlanguagecode = ConfigurationCompat.getLocales(context.resources.configuration)[0]?.let {
112+
languageCodesList.indexOf(
113+
it.language)
114+
}
109115
var i = 0
110116
var s = 0
111117
while (i < length) {
112118
val key: String = language.codes[i]
113119
val value: String = language.localizedNames[i]
114120
if(value.contains(constraint, true) || Locale(key).getDisplayName(
115-
Locale(language.codes[defaultlanguagecode])).contains(constraint, true))
121+
Locale(language.codes[defaultlanguagecode!!])).contains(constraint, true))
116122
s++
117123
i++
118124
}

data-client/build.gradle

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
buildscript {
2-
ext.kotlin_version = '1.5.10'
2+
ext.kotlin_version = '1.7.20'
33
repositories {
44
jcenter()
55
google()
@@ -32,11 +32,11 @@ version = "${VERSION_NAME}"
3232
group = "${GROUP_ID}"
3333

3434
android {
35-
compileSdkVersion 28
35+
compileSdkVersion 31
3636

3737
defaultConfig {
38-
minSdkVersion 19
39-
targetSdkVersion 28
38+
minSdkVersion 21
39+
targetSdkVersion 31
4040
versionCode 1
4141
versionName "${VERSION_NAME}"
4242

@@ -74,10 +74,11 @@ dependencies {
7474

7575
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
7676

77-
testImplementation 'junit:junit:4.12'
78-
testImplementation 'org.mockito:mockito-core:2.8.9'
79-
testImplementation 'org.robolectric:robolectric:3.8'
80-
testImplementation "com.squareup.okhttp3:mockwebserver:3.12.1"
77+
testImplementation 'junit:junit:4.13.2'
78+
testImplementation 'org.mockito:mockito-core:2.25.1'
79+
testImplementation 'org.robolectric:robolectric:4.6.1'
80+
testImplementation 'org.hamcrest:hamcrest-junit:2.0.0.0'
81+
testImplementation "com.squareup.okhttp3:mockwebserver:4.10.0"
8182
testImplementation "commons-io:commons-io:2.6"
8283
}
8384

data-client/src/test/java/org/wikipedia/dataclient/mwapi/page/MwPageClientTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import androidx.annotation.NonNull;
44

55
import org.junit.Before;
6+
import org.junit.Ignore;
67
import org.junit.Test;
78
import org.wikipedia.dataclient.page.BasePageClientTest;
89
import org.wikipedia.dataclient.page.PageClient;
@@ -19,6 +20,7 @@ public class MwPageClientTest extends BasePageClientTest {
1920
subject = new MwPageClient();
2021
}
2122

23+
@Ignore("MobileView API is deprecated. Remove test cases after fixing #5165")
2224
@Test public void testLeadThumbnailWidth() {
2325

2426
TestObserver<Response<PageLead>> observer = new TestObserver<>();

0 commit comments

Comments
 (0)