Skip to content

Commit abd5a8b

Browse files
authored
make changes for android 12 (#129)
* make changes for android 12 * Fix target sdk version for sample app * Update some dependencies to fix unit tests and warning * bump sdk version * Bump version
1 parent 6799889 commit abd5a8b

File tree

12 files changed

+69
-56
lines changed

12 files changed

+69
-56
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased]
88

9+
## [1.8.0] - 2021-11-11
10+
11+
### Fixed
12+
- Fix issue #126 and #127
13+
914
## [1.7.0] - 2021-06-07
1015

1116
### Fixed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ dependencies {
3434
// Add these lines
3535
implementation 'com.google.firebase:firebase-core:16.0.9'
3636
implementation 'com.google.firebase:firebase-messaging:18.0.0'
37-
implementation 'com.pusher:push-notifications-android:1.7.0'
37+
implementation 'com.pusher:push-notifications-android:1.8.0'
3838
}
3939
4040
// Add this line to the end of the file
@@ -49,7 +49,7 @@ dependencies {
4949
// Add these lines
5050
implementation 'com.google.firebase:firebase-messaging:22.0.0'
5151
implementation "com.google.firebase:firebase-iid:21.1.0"
52-
implementation 'com.pusher:push-notifications-android:1.7.0'
52+
implementation 'com.pusher:push-notifications-android:1.8.0'
5353
}
5454
5555
// Add this line to the end of the file

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ buildscript {
1515
}
1616

1717
dependencies {
18-
classpath 'com.android.tools.build:gradle:3.5.2'
18+
classpath 'com.android.tools.build:gradle:4.2.2'
1919
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}"
2020

2121
// NOTE: Do not place your application dependencies here; they belong

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip

pushnotifications-integration-tests/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ apply plugin: 'kotlin-android'
33
apply plugin: 'kotlin-android-extensions'
44

55
android {
6-
compileSdkVersion 28
6+
compileSdkVersion 31
77

88
defaultConfig {
99
applicationId "com.example.pushnotificationsintegrationtests"
1010
minSdkVersion 26
11-
targetSdkVersion 28
11+
targetSdkVersion 29
1212
versionCode 1
1313
versionName "1.0"
1414

pushnotifications/build.gradle

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,25 @@ apply plugin: 'kotlin-android'
33
apply from: 'maven-push.gradle'
44

55
android {
6-
compileSdkVersion 28
6+
compileSdkVersion 31
77

88
defaultConfig {
99
minSdkVersion 16
10-
targetSdkVersion 28
10+
targetSdkVersion 29
1111
versionCode 1
12-
versionName "1.7.0"
12+
versionName "1.8.0"
1313

1414
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
1515
}
1616

1717
buildTypes {
18+
debug{
19+
buildConfigField "String", "VERSION_NAME", "\"${defaultConfig.versionName}\""
20+
}
1821
release {
1922
minifyEnabled false
2023
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
24+
buildConfigField "String", "VERSION_NAME", "\"${defaultConfig.versionName}\""
2125
}
2226
}
2327

@@ -43,29 +47,33 @@ dependencies {
4347
implementation "dev.zacsweers.moshisealed:moshi-sealed-annotations:0.1.0"
4448

4549
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${versions.kotlin}"
50+
implementation "org.jetbrains.kotlin:kotlin-reflect:1.5.0"
4651

4752
compileOnly "com.google.firebase:firebase-messaging:22.0.0"
4853
compileOnly "com.google.firebase:firebase-iid:21.1.0"
4954

5055
implementation("androidx.work:work-runtime-ktx:2.7.0")
5156
implementation 'androidx.concurrent:concurrent-futures:1.1.0'
52-
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1'
57+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0'
5358

5459
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
55-
implementation 'androidx.annotation:annotation:1.2.0'
60+
implementation 'androidx.annotation:annotation:1.3.0'
5661

5762
lintChecks project(':pushnotifications-lint')
5863

5964
testImplementation 'junit:junit:4.12'
60-
testImplementation 'androidx.test:core:1.3.0'
61-
testImplementation 'androidx.test.ext:junit:1.1.2'
62-
testImplementation 'androidx.test.ext:truth:1.3.0'
65+
testImplementation 'androidx.test:core:1.4.0'
66+
testImplementation 'androidx.test.ext:junit:1.1.3'
67+
testImplementation 'androidx.test.ext:truth:1.4.0'
6368
testImplementation "org.mockito:mockito-core:2.13.0"
6469

65-
androidTestImplementation 'androidx.test:core:1.3.0'
66-
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
70+
androidTestImplementation 'androidx.test:core:1.4.0'
71+
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
6772
androidTestImplementation 'com.squareup.okhttp3:mockwebserver:3.12.0'
68-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
73+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
74+
75+
testImplementation "net.bytebuddy:byte-buddy:1.8.22"
76+
testImplementation "net.bytebuddy:byte-buddy-agent:1.8.22"
6977
}
7078

7179
repositories {

pushnotifications/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION_NAME=1.7.0
1+
VERSION_NAME=1.8.0
22
VERSION_CODE=1
33
GROUP=com.pusher
44

pushnotifications/src/main/java/com/pusher/pushnotifications/api/PushNotificationsAPI.kt

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,17 @@ class PushNotificationsAPI(private val instanceId: String, overrideHostURL: Stri
141141
// not throwing a `PushNotificationsAPIBadRequest` here so that it still retries this request.
142142
// it would make the code that calls this more complex to handle it.
143143
// this really shouldn't happen anyway
144-
log.e("Critical error when registering a new device (error body: ${response?.errorBody()})")
144+
log.e("Critical error when registering a new device (error body: ${response.errorBody()})")
145145
}
146146

147-
val responseBody = response?.body()
147+
val responseBody = response.body()
148148
if (responseBody != null && response.code() in 200..299) {
149149
return RegisterDeviceResult(
150150
deviceId = responseBody.id,
151151
initialInterests = responseBody.initialInterestSet)
152152
}
153153

154-
val responseErrorBody = response?.errorBody()
154+
val responseErrorBody = response.errorBody()
155155
if (responseErrorBody != null) {
156156
val error = safeExtractJsonError(responseErrorBody.string())
157157
log.w("Failed to register device: $error")
@@ -173,12 +173,12 @@ class PushNotificationsAPI(private val instanceId: String, overrideHostURL: Stri
173173
throw PushNotificationsAPIDeviceNotFound()
174174
}
175175
if (response.code() == 400) {
176-
val reason = response?.errorBody()?.let { safeExtractJsonError(it.string()).description }
176+
val reason = response.errorBody()?.let { safeExtractJsonError(it.string()).description }
177177
throw PushNotificationsAPIBadRequest(reason ?: "Unknown reason")
178178
}
179179

180180
if (response.code() !in 200..299) {
181-
val responseErrorBody = response?.errorBody()
181+
val responseErrorBody = response.errorBody()
182182
if (responseErrorBody != null) {
183183
val error = safeExtractJsonError(responseErrorBody.string())
184184
log.w("Failed to subscribe to interest: $error")
@@ -201,12 +201,12 @@ class PushNotificationsAPI(private val instanceId: String, overrideHostURL: Stri
201201
throw PushNotificationsAPIDeviceNotFound()
202202
}
203203
if (response.code() == 400) {
204-
val reason = response?.errorBody()?.let { safeExtractJsonError(it.string()).description }
204+
val reason = response.errorBody()?.let { safeExtractJsonError(it.string()).description }
205205
throw PushNotificationsAPIBadRequest(reason ?: "Unknown reason")
206206
}
207207

208208
if (response.code() !in 200..299) {
209-
val responseErrorBody = response?.errorBody()
209+
val responseErrorBody = response.errorBody()
210210
if (responseErrorBody != null) {
211211
val error = safeExtractJsonError(responseErrorBody.string())
212212
log.w("Failed to unsubscribe from interest: $error")
@@ -229,12 +229,12 @@ class PushNotificationsAPI(private val instanceId: String, overrideHostURL: Stri
229229
throw PushNotificationsAPIDeviceNotFound()
230230
}
231231
if (response.code() == 400) {
232-
val reason = response?.errorBody()?.let { safeExtractJsonError(it.string()).description }
232+
val reason = response.errorBody()?.let { safeExtractJsonError(it.string()).description }
233233
throw PushNotificationsAPIBadRequest(reason ?: "Unknown reason")
234234
}
235235

236236
if (response.code() !in 200..299) {
237-
val responseErrorBody = response?.errorBody()
237+
val responseErrorBody = response.errorBody()
238238
if (responseErrorBody != null) {
239239
val error = safeExtractJsonError(responseErrorBody.string())
240240
log.w("Failed to set subscriptions: $error")
@@ -257,12 +257,12 @@ class PushNotificationsAPI(private val instanceId: String, overrideHostURL: Stri
257257
throw PushNotificationsAPIDeviceNotFound()
258258
}
259259
if (response.code() == 400) {
260-
val reason = response?.errorBody()?.let { safeExtractJsonError(it.string()).description }
260+
val reason = response.errorBody()?.let { safeExtractJsonError(it.string()).description }
261261
throw PushNotificationsAPIBadRequest(reason ?: "Unknown reason")
262262
}
263263

264264
if (response.code() !in 200..299) {
265-
val responseErrorBody = response?.errorBody()
265+
val responseErrorBody = response.errorBody()
266266
if (responseErrorBody != null) {
267267
val error = safeExtractJsonError(responseErrorBody.string())
268268
log.w("Failed to refresh FCM token: $error")
@@ -289,12 +289,12 @@ class PushNotificationsAPI(private val instanceId: String, overrideHostURL: Stri
289289
throw PushNotificationsAPIDeviceNotFound()
290290
}
291291
if (response.code() == 400) {
292-
val reason = response?.errorBody()?.let { safeExtractJsonError(it.string()).description }
292+
val reason = response.errorBody()?.let { safeExtractJsonError(it.string()).description }
293293
throw PushNotificationsAPIBadRequest(reason ?: "Unknown reason")
294294
}
295295

296296
if (response.code() !in 200..299) {
297-
val responseErrorBody = response?.errorBody()
297+
val responseErrorBody = response.errorBody()
298298
if (responseErrorBody != null) {
299299
val error = safeExtractJsonError(responseErrorBody.string())
300300
log.w("Failed to set device metadata: $error")
@@ -318,30 +318,30 @@ class PushNotificationsAPI(private val instanceId: String, overrideHostURL: Stri
318318
throw PushNotificationsAPIDeviceNotFound()
319319
}
320320
if (response.code() == 400) {
321-
val reason = response?.errorBody()?.let { safeExtractJsonError(it.string()).description }
321+
val reason = response.errorBody()?.let { safeExtractJsonError(it.string()).description }
322322
throw PushNotificationsAPIBadRequest(reason ?: "Unknown reason")
323323
}
324324
if (response.code() == 401 || response.code() == 403) {
325-
val responseErrorBody = response?.errorBody()
325+
val responseErrorBody = response.errorBody()
326326
if (responseErrorBody != null) {
327327
val error = safeExtractJsonError(responseErrorBody.string())
328-
throw PushNotificationsAPIBadJWT("${error?.error}: ${error?.description}")
328+
throw PushNotificationsAPIBadJWT("${error.error}: ${error.description}")
329329
}
330330

331331
throw PushNotificationsAPIBadJWT("Unknown reason")
332332
}
333333
if (response.code() == 422) {
334-
val responseErrorBody = response?.errorBody()
334+
val responseErrorBody = response.errorBody()
335335
if (responseErrorBody != null) {
336336
val error = safeExtractJsonError(responseErrorBody.string())
337-
throw PushNotificationsAPIUnprocessableEntity("${error?.error}: ${error?.description}")
337+
throw PushNotificationsAPIUnprocessableEntity("${error.error}: ${error.description}")
338338
}
339339

340340
throw PushNotificationsAPIUnprocessableEntity("Unknown reason")
341341
}
342342

343343
if (response.code() !in 200..299) {
344-
val responseErrorBody = response?.errorBody()
344+
val responseErrorBody = response.errorBody()
345345
if (responseErrorBody != null) {
346346
val error = safeExtractJsonError(responseErrorBody.string())
347347
log.w("Failed to set user id: $error")
@@ -369,11 +369,11 @@ class PushNotificationsAPI(private val instanceId: String, overrideHostURL: Stri
369369
// not throwing a `PushNotificationsAPIBadRequest` here so that it still retries this request.
370370
// it would make the code that calls this more complex to handle it.
371371
// this really shouldn't happen anyway
372-
log.e("Critical error when deleting a device (error body: ${response?.errorBody()})")
372+
log.e("Critical error when deleting a device (error body: ${response.errorBody()})")
373373
}
374374

375375
if (response.code() !in 200..299) {
376-
val responseErrorBody = response?.errorBody()
376+
val responseErrorBody = response.errorBody()
377377
if (responseErrorBody != null) {
378378
val error = safeExtractJsonError(responseErrorBody.string())
379379
log.w("Failed to delete device: $error")

pushnotifications/src/main/java/com/pusher/pushnotifications/internal/ApplicationLifecycle.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,22 @@ class AppActivityLifecycleCallbacks: Application.ActivityLifecycleCallbacks {
5353
}
5454
}
5555

56-
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle?) {
56+
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {
5757
}
5858
}
5959

6060
class PushNotificationsInitProvider: ContentProvider() {
6161
private val log = Logger.get(this::class)
6262

6363
override fun onCreate(): Boolean {
64-
val deviceStateStore = DeviceStateStore(context)
64+
val deviceStateStore = context?.let { DeviceStateStore(it) }
6565

66-
deviceStateStore.instanceIds.forEach { instanceId ->
67-
val pni = PushNotificationsInstance(context, instanceId)
68-
pni.onApplicationStarted()
66+
deviceStateStore?.instanceIds?.forEach { instanceId ->
67+
val pni = context?.let { PushNotificationsInstance(it, instanceId) }
68+
pni?.onApplicationStarted()
6969
}
7070

71-
(context.applicationContext as? Application).apply {
71+
(context?.applicationContext as? Application).apply {
7272
when(this) {
7373
is Application -> registerActivityLifecycleCallbacks(AppActivityLifecycleCallbacks())
7474
else -> log.w("Failed to register activity lifecycle callbacks. Notification delivery events might be incorrect.")
@@ -78,9 +78,9 @@ class PushNotificationsInitProvider: ContentProvider() {
7878
return false
7979
}
8080

81-
override fun query(uri: Uri?, projection: Array<out String>?, selection: String?, selectionArgs: Array<out String>?, sortOrder: String?): Cursor? = null
82-
override fun insert(uri: Uri?, values: ContentValues?): Uri? = null
83-
override fun update(uri: Uri?, values: ContentValues?, selection: String?, selectionArgs: Array<out String>?): Int = 0
84-
override fun delete(uri: Uri?, selection: String?, selectionArgs: Array<out String>?): Int = 0
85-
override fun getType(uri: Uri?): String? = null
81+
override fun query(uri: Uri, projection: Array<out String>?, selection: String?, selectionArgs: Array<out String>?, sortOrder: String?): Cursor? = null
82+
override fun insert(uri: Uri, values: ContentValues?): Uri? = null
83+
override fun update(uri: Uri, values: ContentValues?, selection: String?, selectionArgs: Array<out String>?): Int = 0
84+
override fun delete(uri: Uri, selection: String?, selectionArgs: Array<out String>?): Int = 0
85+
override fun getType(uri: Uri): String? = null
8686
}

pushnotifications/src/main/java/com/pusher/pushnotifications/internal/DeviceStateStore.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class DeviceStateStore(context: Context) {
3737
var instanceIds: MutableSet<String>
3838
// We need to clone the set we get from shared preferences because mutating it is not permitted
3939
// by the Android SDK
40-
get() = preferences.getStringSet(preferencesInstanceIdsKey, mutableSetOf<String>()).toMutableSet()
40+
get() = preferences.getStringSet(preferencesInstanceIdsKey, mutableSetOf<String>())!!.toMutableSet()
4141
set(value) = preferences.edit().putStringSet(preferencesInstanceIdsKey, value).apply()
4242

4343
fun clear() = preferences.edit().clear().commit()
@@ -100,7 +100,7 @@ class InstanceDeviceStateStore(context: Context, val instanceId: String?) {
100100
var interests: MutableSet<String>
101101
// We need to clone the set we get from shared preferences because mutating it is not permitted
102102
// by the Android SDK
103-
get() = preferences.getStringSet(preferencesInterestsKey, mutableSetOf<String>()).toMutableSet()
103+
get() = preferences.getStringSet(preferencesInterestsKey, mutableSetOf<String>())!!.toMutableSet()
104104
set(value) = preferences.edit().putStringSet(preferencesInterestsKey, value).apply()
105105

106106
var serverConfirmedInterestsHash: String?

pushnotifications/src/main/java/com/pusher/pushnotifications/reporting/OpenNotificationActivity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ import com.pusher.pushnotifications.reporting.api.OpenEvent
1919
class OpenNotificationActivity: Activity() {
2020
private val log = Logger.get(this::class)
2121

22-
private fun startIntent(bundle: Bundle, clickAction: String? = null) {
22+
private fun startIntent(bundle: Bundle?, clickAction: String? = null) {
2323
val i: Intent
2424
if (clickAction != null) {
2525
i = Intent()
2626
i.action = clickAction
2727
} else {
28-
i = packageManager.getLaunchIntentForPackage(packageName)
28+
i = packageManager.getLaunchIntentForPackage(packageName)!!
2929
}
3030

3131
i.replaceExtras(bundle)

sample_kotlin/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ apply plugin: 'kotlin-android'
55
apply plugin: 'kotlin-android-extensions'
66

77
android {
8-
compileSdkVersion 28
8+
compileSdkVersion 31
99
defaultConfig {
1010
applicationId "com.pusher.pushnotifications.sample"
1111
minSdkVersion 26
12-
targetSdkVersion 28
12+
targetSdkVersion 29
1313
versionCode 1
1414
versionName "1.0"
1515
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'

0 commit comments

Comments
 (0)