Skip to content
This repository was archived by the owner on Dec 18, 2022. It is now read-only.

Commit c22be13

Browse files
authored
Merge pull request #116 from 05nelsonm/mn/fix/sdk-31-pending-intent
Fix sdk 31+ pending intent flags
2 parents 1ae0caa + 5ede28e commit c22be13

File tree

10 files changed

+372
-345
lines changed

10 files changed

+372
-345
lines changed

gradle/dependencies.gradle

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
ext.versions = [
2-
'buildTools': "29.0.3",
3-
'compileSdk': 30,
2+
'buildTools': "31.0.0",
3+
'compileSdk': 31,
44
'minSdk': 16,
55

6-
'coroutines': '1.4.3',
7-
'lifecycle': '2.3.1',
8-
'kotlin': '1.4.32',
6+
'coroutines': '1.5.2',
7+
'lifecycle': '2.4.0',
8+
'kotlin': '1.5.31',
99
'navigation': '2.3.5',
1010
]
1111

@@ -18,9 +18,9 @@ ext.versions = [
1818
* */
1919
ext.deps = [
2020
androidx: [
21-
appCompat: "androidx.appcompat:appcompat:1.2.0",
22-
constraintLayout: "androidx.constraintlayout:constraintlayout:2.0.4",
23-
core: "androidx.core:core-ktx:1.3.2",
21+
appCompat: "androidx.appcompat:appcompat:1.4.0",
22+
constraintLayout: "androidx.constraintlayout:constraintlayout:2.1.2",
23+
core: "androidx.core:core-ktx:1.7.0",
2424
lifecycle: [
2525
commonJava8: "androidx.lifecycle:lifecycle-common-java8:${versions.lifecycle}",
2626
liveData: "androidx.lifecycle:lifecycle-livedata-ktx:${versions.lifecycle}",
@@ -33,7 +33,7 @@ ext.deps = [
3333
fragment: "androidx.navigation:navigation-fragment-ktx:${versions.navigation}",
3434
ui: "androidx.navigation:navigation-ui-ktx:${versions.navigation}",
3535
],
36-
recyclerView: "androidx.recyclerview:recyclerview:1.2.0",
36+
recyclerView: "androidx.recyclerview:recyclerview:1.2.1",
3737
],
3838
jtorctl: "info.guardianproject:jtorctl:0.4.5.7",
3939
kotlin: [
@@ -44,7 +44,7 @@ ext.deps = [
4444
]
4545

4646
ext.plugin = [
47-
androidGradle: "com.android.tools.build:gradle:4.1.2",
47+
androidGradle: "com.android.tools.build:gradle:7.0.3",
4848
gradleVersions: "com.github.ben-manes:gradle-versions-plugin:0.36.0",
4949
kotlin: [
5050
dokka: "org.jetbrains.dokka:dokka-gradle-plugin:0.10.1",
@@ -63,15 +63,15 @@ ext.plugin = [
6363
* */
6464
ext.testDeps = [
6565
androidx: [
66-
core: "androidx.test:core:1.3.0",
67-
espresso: "androidx.test.espresso:espresso-core:3.3.0",
68-
junit: "androidx.test.ext:junit:1.1.2",
66+
core: "androidx.test:core:1.4.0",
67+
espresso: "androidx.test.espresso:espresso-core:3.4.0",
68+
junit: "androidx.test.ext:junit:1.1.3",
6969
liveDataCore: "androidx.arch.core:core-testing:2.1.0",
7070
],
7171
junit: "junit:junit:4.12",
7272
kotlin: [
7373
coroutines: "org.jetbrains.kotlinx:kotlinx-coroutines-test:${versions.coroutines}",
7474
],
75-
robolectric: "org.robolectric:robolectric:4.3.1",
75+
robolectric: "org.robolectric:robolectric:4.7.2",
7676
turbine: "app.cash.turbine:turbine:0.2.1",
7777
]
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
# https://gradle.org/release-checksums/
4-
distributionSha256Sum=9af5c8e7e2cd1a3b0f694a4ac262b9f38c75262e74a9e8b5101af302a6beadd7
5-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip
63
zipStoreBase=GRADLE_USER_HOME
74
zipStorePath=wrapper/dists
5+
6+
# https://gradle.org/release-checksums/
7+
distributionSha256Sum=00b273629df4ce46e68df232161d5a7c4e495b9a029ce6e0420f071e21316867
8+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-all.zip

sampleapp/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ dependencies {
101101
implementation deps.kotlin.stdlib
102102

103103
implementation 'io.matthewnelson.encrypted-storage:encrypted-storage:2.0.1'
104-
implementation 'io.matthewnelson.topl-android:tor-binary:0.4.6.2-alpha'
104+
implementation 'io.matthewnelson.topl-android:tor-binary:0.4.6.5'
105105

106106
testImplementation testDeps.junit
107107
}

sampleapp/src/main/AndroidManifest.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
android:roundIcon="@mipmap/ic_launcher_round"
1616
android:supportsRtl="true"
1717
android:theme="@style/AppTheme">
18-
<activity android:name=".ui.MainActivity"
18+
<activity
19+
android:name=".ui.MainActivity"
20+
android:exported="true"
1921
android:launchMode="singleInstance"
20-
android:screenOrientation="portrait" >
22+
android:screenOrientation="portrait">
2123
<intent-filter>
2224
<action android:name="android.intent.action.MAIN" />
2325

sampleapp/src/main/java/io/matthewnelson/sampleapp/App.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,12 @@ package io.matthewnelson.sampleapp
7373

7474
import android.app.Application
7575
import android.app.PendingIntent
76-
import android.content.Intent
76+
import android.os.Build
7777
import android.os.Process
7878
import io.matthewnelson.encrypted_storage.Prefs
7979
import io.matthewnelson.sampleapp.topl_android.MyEventBroadcaster
8080
import io.matthewnelson.sampleapp.topl_android.MyServiceExecutionHooks
8181
import io.matthewnelson.sampleapp.topl_android.MyTorSettings
82-
import io.matthewnelson.sampleapp.ui.MainActivity
8382
import io.matthewnelson.sampleapp.ui.fragments.dashboard.DashMessage
8483
import io.matthewnelson.sampleapp.ui.fragments.dashboard.DashboardFragment
8584
import io.matthewnelson.sampleapp.ui.fragments.settings.library.components.LibraryPrefs
@@ -195,8 +194,14 @@ class App: Application() {
195194
super.onCreate()
196195
val prefs = Prefs.createUnencrypted(PREFS_NAME, this)
197196

197+
val flags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
198+
PendingIntent.FLAG_IMMUTABLE
199+
} else {
200+
0
201+
}
202+
198203
packageManager?.getLaunchIntentForPackage(packageName)?.let { intent ->
199-
contentIntent = PendingIntent.getActivity(this.applicationContext, 0, intent, 0)
204+
contentIntent = PendingIntent.getActivity(this.applicationContext, 0, intent, flags)
200205
}
201206

202207
val serviceNotificationBuilder = generateTorServiceNotificationBuilder(

sampleapp/src/main/java/io/matthewnelson/sampleapp/topl_android/CodeSamples.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ import android.app.Application
7575
import android.app.PendingIntent
7676
import android.content.Context
7777
import android.content.Intent
78+
import android.os.Build
7879
import androidx.core.app.NotificationCompat
7980
import io.matthewnelson.sampleapp.App
8081
import io.matthewnelson.sampleapp.BuildConfig
@@ -125,12 +126,18 @@ class CodeSamples {
125126
//
126127
// https://medium.com/swlh/truly-understand-tasks-and-back-stack-intent-flags-of-activity-2a137c401eca
127128

129+
val flags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
130+
PendingIntent.FLAG_IMMUTABLE
131+
} else {
132+
0
133+
}
134+
128135
builder.setContentIntent(
129136
PendingIntent.getActivity(
130137
context.applicationContext,
131138
0, // Your desired request code
132139
intent,
133-
0 // flags
140+
flags
134141
// can also include a bundle if desired
135142
)
136143
)

sampleapp/src/main/java/io/matthewnelson/sampleapp/ui/fragments/dashboard/DashboardFragment.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,14 @@ class DashboardFragment : Fragment() {
262262
private fun killApplication(context: Context) {
263263
// Build notification to restart the Application
264264
val intent = Intent(context.applicationContext, MainActivity::class.java)
265+
val flags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
266+
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE
267+
} else {
268+
PendingIntent.FLAG_ONE_SHOT
269+
}
270+
265271
val pendingIntent =
266-
PendingIntent.getActivity(context.applicationContext, 0, intent, PendingIntent.FLAG_ONE_SHOT)
272+
PendingIntent.getActivity(context.applicationContext, 0, intent, flags)
267273

268274
val notificationManager =
269275
context.applicationContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager?

topl-service/src/main/java/io/matthewnelson/topl_service/notification/ServiceNotification.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,11 +646,17 @@ class ServiceNotification private constructor(
646646
intent.putExtra(TorServiceReceiver.getServiceIntentFilter(), action)
647647
intent.setPackage(torService.getContext().packageName)
648648

649+
val flags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
650+
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
651+
} else {
652+
PendingIntent.FLAG_UPDATE_CURRENT
653+
}
654+
649655
return PendingIntent.getBroadcast(
650656
torService.getContext(),
651657
requestCode,
652658
intent,
653-
PendingIntent.FLAG_UPDATE_CURRENT
659+
flags
654660
)
655661
}
656662

0 commit comments

Comments
 (0)