Skip to content

Commit 6c5428e

Browse files
Merge pull request #408 from appwrite/fix-android-12-cookies
Add fixed cookie dependency for Android 12+
2 parents ed26ca8 + 10c7049 commit 6c5428e

File tree

7 files changed

+491
-48
lines changed

7 files changed

+491
-48
lines changed

src/SDK/Language/Android.php

Lines changed: 20 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,16 @@ public function getFiles()
2424
'scope' => 'copy',
2525
'destination' => '.github/workflows/publish.yml',
2626
'template' => '/android/.github/workflows/publish.yml',
27-
'minify' => false,
2827
],
2928
[
3029
'scope' => 'method',
3130
'destination' => 'docs/examples/kotlin/{{service.name | caseLower}}/{{method.name | caseDash}}.md',
3231
'template' => '/android/docs/kotlin/example.md.twig',
33-
'minify' => false,
3432
],
3533
[
3634
'scope' => 'method',
3735
'destination' => 'docs/examples/java/{{service.name | caseLower}}/{{method.name | caseDash}}.md',
3836
'template' => '/android/docs/java/example.md.twig',
39-
'minify' => false,
4037
],
4138
[
4239
'scope' => 'copy',
@@ -47,207 +44,193 @@ public function getFiles()
4744
'scope' => 'copy',
4845
'destination' => 'gradle/wrapper/gradle-wrapper.properties',
4946
'template' => '/android/gradle/wrapper/gradle-wrapper.properties',
50-
'minify' => false,
5147
],
5248
[
5349
'scope' => 'copy',
5450
'destination' => 'scripts/publish-config.gradle',
5551
'template' => '/android/scripts/publish-config.gradle',
56-
'minify' => false,
5752
],
5853
[
5954
'scope' => 'copy',
6055
'destination' => 'scripts/publish-module.gradle',
6156
'template' => '/android/scripts/publish-module.gradle',
62-
'minify' => false,
6357
],
6458
[
6559
'scope' => 'copy',
6660
'destination' => '.gitignore',
6761
'template' => '/android/.gitignore',
68-
'minify' => false,
6962
],
7063
[
7164
'scope' => 'default',
7265
'destination' => 'build.gradle',
7366
'template' => '/android/build.gradle.twig',
74-
'minify' => false,
7567
],
7668
[
7769
'scope' => 'default',
7870
'destination' => 'CHANGELOG.md',
7971
'template' => '/android/CHANGELOG.md.twig',
80-
'minify' => false,
8172
],
8273
[
8374
'scope' => 'copy',
8475
'destination' => 'gradle.properties',
8576
'template' => '/android/gradle.properties',
86-
'minify' => false,
8777
],
8878
[
8979
'scope' => 'copy',
9080
'destination' => 'gradlew',
9181
'template' => '/android/gradlew',
92-
'minify' => false,
9382
],
9483
[
9584
'scope' => 'copy',
9685
'destination' => 'gradlew.bat',
9786
'template' => '/android/gradlew.bat',
98-
'minify' => false,
9987
],
10088
[
10189
'scope' => 'default',
10290
'destination' => 'LICENSE.md',
10391
'template' => '/android/LICENSE.md.twig',
104-
'minify' => false,
10592
],
10693
[
10794
'scope' => 'default',
10895
'destination' => 'README.md',
10996
'template' => '/android/README.md.twig',
110-
'minify' => false,
11197
],
11298
[
11399
'scope' => 'copy',
114100
'destination' => 'settings.gradle',
115101
'template' => '/android/settings.gradle',
116-
'minify' => false,
117102
],
118103
// Config for project :library
119104
[
120105
'scope' => 'default',
121106
'destination' => '/library/src/main/java/{{ sdk.namespace | caseSlash }}/Client.kt',
122107
'template' => '/android/library/src/main/java/io/appwrite/Client.kt.twig',
123-
'minify' => false,
124108
],
125109
[
126110
'scope' => 'default',
127111
'destination' => '/library/src/main/java/{{ sdk.namespace | caseSlash }}/Query.kt',
128112
'template' => '/android/library/src/main/java/io/appwrite/Query.kt.twig',
129-
'minify' => false,
130113
],
131114
[
132115
'scope' => 'default',
133116
'destination' => '/library/src/main/java/{{ sdk.namespace | caseSlash }}/exceptions/{{spec.title | caseUcfirst}}Exception.kt',
134117
'template' => '/android/library/src/main/java/io/appwrite/exceptions/Exception.kt.twig',
135-
'minify' => false,
136118
],
137119
[
138120
'scope' => 'default',
139121
'destination' => '/library/src/main/java/{{ sdk.namespace | caseSlash }}/extensions/JsonExtensions.kt',
140122
'template' => '/android/library/src/main/java/io/appwrite/extensions/JsonExtensions.kt.twig',
141-
'minify' => false,
142123
],
143124
[
144125
'scope' => 'default',
145126
'destination' => '/library/src/main/java/{{ sdk.namespace | caseSlash }}/extensions/CollectionExtensions.kt',
146127
'template' => '/android/library/src/main/java/io/appwrite/extensions/CollectionExtensions.kt.twig',
147-
'minify' => false,
148128
],
149129
[
150130
'scope' => 'default',
151131
'destination' => '/library/src/main/java/{{ sdk.namespace | caseSlash }}/json/PreciseNumberAdapter.kt',
152132
'template' => '/android/library/src/main/java/io/appwrite/json/PreciseNumberAdapter.kt.twig',
153-
'minify' => false,
154133
],
155134
[
156135
'scope' => 'default',
157136
'destination' => '/library/src/main/java/{{ sdk.namespace | caseSlash }}/models/RealtimeModels.kt',
158137
'template' => '/android/library/src/main/java/io/appwrite/models/RealtimeModels.kt.twig',
159-
'minify' => false,
160138
],
161139
[
162140
'scope' => 'default',
163141
'destination' => '/library/src/main/java/{{ sdk.namespace | caseSlash }}/models/UploadProgress.kt',
164142
'template' => '/android/library/src/main/java/io/appwrite/models/UploadProgress.kt.twig',
165-
'minify' => false,
166143
],
167144
[
168145
'scope' => 'default',
169146
'destination' => '/library/src/main/java/{{ sdk.namespace | caseSlash }}/WebAuthComponent.kt',
170147
'template' => '/android/library/src/main/java/io/appwrite/WebAuthComponent.kt.twig',
171-
'minify' => false,
172148
],
173149
[
174150
'scope' => 'default',
175151
'destination' => '/library/src/main/java/{{ sdk.namespace | caseSlash }}/KeepAliveService.kt',
176152
'template' => '/android/library/src/main/java/io/appwrite/KeepAliveService.kt.twig',
177-
'minify' => false,
178153
],
179154
[
180155
'scope' => 'default',
181156
'destination' => '/library/src/main/java/{{ sdk.namespace | caseSlash }}/views/CallbackActivity.kt',
182157
'template' => '/android/library/src/main/java/io/appwrite/views/CallbackActivity.kt.twig',
183-
'minify' => false,
184158
],
185159
[
186160
'scope' => 'default',
187161
'destination' => '/library/src/main/java/{{ sdk.namespace | caseSlash }}/services/Service.kt',
188162
'template' => '/android/library/src/main/java/io/appwrite/services/Service.kt.twig',
189-
'minify' => false,
190163
],
191164
[
192165
'scope' => 'default',
193166
'destination' => '/library/src/main/java/{{ sdk.namespace | caseSlash }}/services/Realtime.kt',
194167
'template' => '/android/library/src/main/java/io/appwrite/services/Realtime.kt.twig',
195-
'minify' => false,
168+
],
169+
[
170+
'scope' => 'default',
171+
'destination' => '/library/src/main/java/{{ sdk.namespace | caseSlash }}/cookies/Extensions.kt',
172+
'template' => '/android/library/src/main/java/io/appwrite/cookies/Extensions.kt.twig',
173+
],
174+
[
175+
'scope' => 'default',
176+
'destination' => '/library/src/main/java/{{ sdk.namespace | caseSlash }}/cookies/stores/InMemoryCookieStore.kt',
177+
'template' => '/android/library/src/main/java/io/appwrite/cookies/stores/InMemoryCookieStore.kt.twig',
178+
],
179+
[
180+
'scope' => 'default',
181+
'destination' => '/library/src/main/java/{{ sdk.namespace | caseSlash }}/cookies/stores/SharedPreferencesCookieStore.kt',
182+
'template' => '/android/library/src/main/java/io/appwrite/cookies/stores/SharedPreferencesCookieStore.kt.twig',
183+
],
184+
[
185+
'scope' => 'default',
186+
'destination' => '/library/src/main/java/{{ sdk.namespace | caseSlash }}/cookies/InternalCookie.kt',
187+
'template' => '/android/library/src/main/java/io/appwrite/cookies/InternalCookie.kt.twig',
196188
],
197189
[
198190
'scope' => 'service',
199191
'destination' => '/library/src/main/java/{{ sdk.namespace | caseSlash }}/services/{{service.name | caseUcfirst}}.kt',
200192
'template' => '/android/library/src/main/java/io/appwrite/services/ServiceTemplate.kt.twig',
201-
'minify' => false,
202193
],
203194
[
204195
'scope' => 'default',
205196
'destination' => '/library/src/main/AndroidManifest.xml',
206197
'template' => '/android/library/src/main/AndroidManifest.xml.twig',
207-
'minify' => false,
208198
],
209199
[
210200
'scope' => 'default',
211201
'destination' => '/library/build.gradle',
212202
'template' => '/android/library/build.gradle.twig',
213-
'minify' => false,
214203
],
215204
[
216205
'scope' => 'copy',
217206
'destination' => '/library/.gitignore',
218207
'template' => '/android/library/.gitignore',
219-
'minify' => false,
220208
],
221209
// Config for project :example
222210
[
223211
'scope' => 'default',
224212
'destination' => '/example/src/main/java/{{ sdk.namespace | caseSlash }}/android/MainActivity.kt',
225213
'template' => '/android/example/src/main/java/io/appwrite/android/MainActivity.kt.twig',
226-
'minify' => false,
227214
],
228215
[
229216
'scope' => 'default',
230217
'destination' => '/example/src/main/java/{{ sdk.namespace | caseSlash }}/android/ui/accounts/AccountsFragment.kt',
231218
'template' => '/android/example/src/main/java/io/appwrite/android/ui/accounts/AccountsFragment.kt.twig',
232-
'minify' => false,
233219
],
234220
[
235221
'scope' => 'default',
236222
'destination' => '/example/src/main/java/{{ sdk.namespace | caseSlash }}/android/ui/accounts/AccountsViewModel.kt',
237223
'template' => '/android/example/src/main/java/io/appwrite/android/ui/accounts/AccountsViewModel.kt.twig',
238-
'minify' => false,
239224
],
240225
[
241226
'scope' => 'default',
242227
'destination' => '/example/src/main/java/{{ sdk.namespace | caseSlash }}/android/utils/Client.kt',
243228
'template' => '/android/example/src/main/java/io/appwrite/android/utils/Client.kt.twig',
244-
'minify' => false,
245229
],
246230
[
247231
'scope' => 'default',
248232
'destination' => '/example/src/main/java/{{ sdk.namespace | caseSlash }}/android/utils/Event.kt',
249233
'template' => '/android/example/src/main/java/io/appwrite/android/utils/Event.kt.twig',
250-
'minify' => false,
251234
],
252235
[
253236
'scope' => 'copy',
@@ -298,26 +281,22 @@ public function getFiles()
298281
'scope' => 'copy',
299282
'destination' => '/example/src/main/AndroidManifest.xml',
300283
'template' => '/android/example/src/main/AndroidManifest.xml',
301-
'minify' => false,
302284
],
303285
[
304286
'scope' => 'default',
305287
'destination' => '/example/build.gradle',
306288
'template' => '/android/example/build.gradle.twig',
307-
'minify' => false,
308289
],
309290
[
310291
'scope' => 'copy',
311292
'destination' => '/example/.gitignore',
312293
'template' => '/android/example/.gitignore',
313-
'minify' => false,
314294
],
315295
// Config for project :example-java
316296
[
317297
'scope' => 'default',
318298
'destination' => '/example-java/src/main/java/{{ sdk.namespace | caseSlash }}/example_java/MainActivity.java',
319299
'template' => '/android/example-java/src/main/java/io/appwrite/example_java/MainActivity.java.twig',
320-
'minify' => false,
321300
],
322301
[
323302
'scope' => 'copy',
@@ -363,27 +342,22 @@ public function getFiles()
363342
'scope' => 'copy',
364343
'destination' => '/example-java/src/main/AndroidManifest.xml',
365344
'template' => '/android/example-java/src/main/AndroidManifest.xml',
366-
'minify' => false,
367345
],
368346
[
369347
'scope' => 'default',
370348
'destination' => '/example-java/build.gradle',
371349
'template' => '/android/example-java/build.gradle.twig',
372-
'minify' => false,
373350
],
374351
[
375352
'scope' => 'copy',
376353
'destination' => '/example-java/.gitignore',
377354
'template' => '/android/example-java/.gitignore',
378-
'minify' => false,
379355
],
380356
[
381357
'scope' => 'definition',
382358
'destination' => 'library/src/main/java/io/appwrite/models/{{ definition.name | caseUcfirst }}.kt',
383359
'template' => '/android/library/src/main/java/io/appwrite/models/Model.kt.twig',
384-
'minify' => false,
385360
],
386361
];
387362
}
388363
}
389-

templates/android/library/build.gradle.twig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ dependencies {
6363
implementation("com.squareup.okhttp3:logging-interceptor")
6464
implementation("com.google.code.gson:gson:2.8.7")
6565

66-
implementation("net.gotev:cookie-store:1.3.5")
6766
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.3.1")
6867
implementation("androidx.lifecycle:lifecycle-common-java8:2.3.1")
6968
implementation("androidx.appcompat:appcompat:1.3.1")

templates/android/library/src/main/java/io/appwrite/Client.kt.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import android.content.pm.PackageManager
55
import com.google.gson.GsonBuilder
66
import com.google.gson.reflect.TypeToken
77
import {{ sdk.namespace | caseDot }}.{{ spec.title | caseLower }}.BuildConfig
8+
import {{ sdk.namespace | caseDot }}.cookies.stores.SharedPreferencesCookieStore
89
import {{ sdk.namespace | caseDot }}.exceptions.{{ spec.title | caseUcfirst }}Exception
910
import {{ sdk.namespace | caseDot }}.extensions.fromJson
1011
import {{ sdk.namespace | caseDot }}.json.PreciseNumberAdapter
@@ -13,7 +14,6 @@ import kotlinx.coroutines.CoroutineScope
1314
import kotlinx.coroutines.Dispatchers
1415
import kotlinx.coroutines.Job
1516
import kotlinx.coroutines.suspendCancellableCoroutine
16-
import net.gotev.cookiestore.SharedPreferencesCookieStore
1717
import okhttp3.*
1818
import okhttp3.Headers.Companion.toHeaders
1919
import okhttp3.HttpUrl.Companion.toHttpUrl
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package {{ sdk.namespace | caseDot }}.cookies
2+
3+
import android.os.Build
4+
import java.net.CookieStore
5+
import java.net.HttpCookie
6+
import java.text.SimpleDateFormat
7+
import java.util.Calendar
8+
import java.util.Locale
9+
import java.util.TimeZone
10+
11+
fun HttpCookie.toSetCookieString(): String {
12+
val expires = if (maxAge != -1L) {
13+
val dateFormat = SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.UK).apply {
14+
timeZone = TimeZone.getTimeZone("GMT")
15+
}
16+
17+
val calendar = Calendar.getInstance(Locale.UK).apply { set(Calendar.SECOND, maxAge.toInt()) }
18+
19+
"; expires=${dateFormat.format(calendar.time)}"
20+
} else {
21+
""
22+
}
23+
24+
val path = if (path != null) "; path=$path" else ""
25+
val domain = if (domain != null) "; domain=$domain" else ""
26+
val secure = if (secure) "; secure" else ""
27+
val httpOnly = if (Build.VERSION.SDK_INT >= 24) {
28+
if (isHttpOnly) "; httponly" else ""
29+
} else {
30+
""
31+
}
32+
33+
return "$name=$value$expires$path$domain$secure$httpOnly"
34+
}
35+
36+
@Synchronized
37+
fun CookieStore.syncToWebKitCookieManager() {
38+
val webKitCookieManager = android.webkit.CookieManager.getInstance()
39+
40+
cookies.forEach {
41+
val hostUrl = "${if (it.secure) "https" else "http"}://${it.domain}"
42+
webKitCookieManager.setCookie(hostUrl, it.toSetCookieString())
43+
}
44+
45+
webKitCookieManager.flush()
46+
}
47+
48+
@Synchronized
49+
@Suppress("DEPRECATION")
50+
fun android.webkit.CookieManager.removeAll() {
51+
removeAllCookies(null)
52+
flush()
53+
}

0 commit comments

Comments
 (0)