Skip to content

Commit ec985e1

Browse files
author
Bitrise Buildbot
committed
Bitrise build 14308
1 parent ff4471e commit ec985e1

23 files changed

+1271
-97
lines changed

geotabdrivesdk/build.gradle.kts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import java.util.Properties
22

3-
val versionName = "6.8.0_75069"
3+
val versionName = "6.8.0_75308"
44

55
plugins {
66
id("com.android.library")
@@ -16,18 +16,18 @@ apply {
1616
from("./../kotlin-lint.gradle.kts")
1717
}
1818

19+
ksp {
20+
arg("room.schemaLocation", "$projectDir/schemas")
21+
}
1922
android {
2023
compileSdk = 34
2124
namespace = "com.geotab.mobile.sdk"
2225

2326
defaultConfig {
2427
minSdk = 24
25-
2628
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
2729

28-
ksp {
29-
arg("room.schemaLocation", "$projectDir/schemas")
30-
}
30+
3131

3232
buildConfigField("String", "KEYSTORE_ALIAS", "\"" + System.getenv("KEYSTORE_ALIAS") + "\"")
3333
buildConfigField("String", "VERSION_NAME", "\"${versionName}\"")
@@ -137,25 +137,28 @@ dependencies {
137137
implementation("androidx.core:core-ktx:1.12.0")
138138
// This implementation is needed for consumers of the SDK have the option to not include the
139139
// RedirectUriReceiverActivity in their app if they don't use SSO login.
140-
implementation("net.openid:appauth:0.11.1")
140+
api("net.openid:appauth:0.11.1")
141141
implementation("androidx.constraintlayout:constraintlayout:2.0.3")
142142
implementation("androidx.appcompat:appcompat:1.1.0")
143143
implementation("androidx.exifinterface:exifinterface:1.3.1")
144144
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2-native-mt")
145145
implementation("com.github.spullara.mustache.java:compiler:0.8.18")
146146
implementation("androidx.fragment:fragment-ktx:1.4.0-alpha07")
147+
implementation("androidx.work:work-runtime-ktx:2.9.0")
148+
testImplementation("androidx.work:work-testing:2.9.0")
147149
implementation("androidx.lifecycle:lifecycle-common:2.5.1")
148150
implementation("com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava")
149-
debugImplementation("androidx.fragment:fragment-testing:1.6.0-alpha04")
150151
implementation("com.google.code.gson:gson:2.11.0")
151-
implementation ("androidx.room:room-runtime:2.5.2")
152-
implementation("androidx.room:room-ktx:2.5.2")
153-
annotationProcessor("androidx.room:room-compiler:2.5.2")
152+
api ("androidx.room:room-runtime:2.6.1")
153+
api("androidx.room:room-ktx:2.6.1")
154+
annotationProcessor("androidx.room:room-compiler:2.6.1")
154155
ksp("androidx.room:room-compiler:2.6.1")
155156
testImplementation("junit:junit:4.13.2")
156157
testImplementation("org.jetbrains.kotlin:kotlin-test:2.0.20")
157158
testImplementation("io.mockk:mockk:1.12.3")
158159
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4")
160+
testImplementation("org.robolectric:robolectric:4.10.3")
161+
testImplementation ("org.json:json:20231013")
159162
androidTestImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.5.2-native-mt")
160163
implementation("org.jetbrains.kotlin:kotlin-reflect:1.5.31")
161164
androidTestImplementation("androidx.test:core:1.5.0")

geotabdrivesdk/native-sdk.d.ts

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -503,23 +503,43 @@ declare namespace geotabModules {
503503
}
504504

505505
namespace login {
506-
enum GeotabAppId {
507-
GEOTAB_DRIVE = 0,
508-
MYGEOTAB
509-
}
510-
511506
/*******
512507
* Start the login function integrated with Chrome Custom Tabs.
513-
* @param argument: { clientId: string, discoveryUri: string, geotabAppId: GeotabAppId, loginHint: string? }
508+
* @param argument: { clientId: string, discoveryUri: string, loginHint: string }
514509
* @param callback:
515510
* - result: string. A GeotabAuthState object.
516-
* The loginHint parameter is optional. It is used to pre-fill the username field in the login page.
511+
* The loginHint parameter is mandatory as we use it to store it as username in the SecureStorage.
512+
* It is also used to pre-fill the username field in the login page.
517513
* On a successful call a GeotabAuthState object turned into JSON will be given as result
518514
* If there's an error while logging in, err will be given.
519515
* GeotabAuthState object contains the following properties:
520-
* { accessToken: string, idToken: string, refreshToken: string }
516+
* { accessToken: string }
521517
*/
522-
function start(argument: { clientId: string, discoveryUri: string, geotabAppId: GeotabAppId, loginHint: string? }, callback: (err?: Error, result?: string) => void);
518+
function start(argument: { clientId: string, discoveryUri: string, loginHint: string }, callback: (err?: Error, result?: string) => void);
519+
520+
/*******
521+
* Start the getAuthToken function.
522+
* @param argument: { username: string }
523+
* @param callback:
524+
* - result: string. A GeotabAuthState object.
525+
* On a successful call a GeotabAuthState object turned into JSON will be given as result
526+
* If there's an error while retrieving the access token, err will be given.
527+
* GeotabAuthState object contains the following properties:
528+
* { accessToken: string }
529+
*/
530+
function getAuthToken(argument: { username: string }, callback: (err?: Error, result?: string) => void);
531+
}
532+
533+
namespace auth {
534+
/*******
535+
* Start the logout function integrated with Chrome Custom Tabs.
536+
* @param argument: { username: string }
537+
* @param callback:
538+
* - result: string.
539+
* On a successful call a string will be given as result with a success message.
540+
* If there's an error while retrieving the access token, err will be given.
541+
*/
542+
function logout(argument: { username: string }, callback: (err?: Error, result?: string) => void);
523543
}
524544

525545
namespace appearance {

geotabdrivesdk/src/main/AndroidManifest.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
<activity
5656
android:name="net.openid.appauth.RedirectUriReceiverActivity"
5757
android:exported="true"
58-
android:taskAffinity=""
5958
tools:node="replace">
6059
</activity>
6160
<service

geotabdrivesdk/src/main/java/com/geotab/mobile/sdk/DriveFragment.kt

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,12 @@ import com.geotab.mobile.sdk.module.NetworkErrorDelegate
3232
import com.geotab.mobile.sdk.module.Result
3333
import com.geotab.mobile.sdk.module.Success
3434
import com.geotab.mobile.sdk.logging.AppLogEventSource
35+
import com.geotab.mobile.sdk.models.database.AppDatabase
36+
import com.geotab.mobile.sdk.models.database.secureStorage.SecureStorageRepository
3537
import com.geotab.mobile.sdk.module.app.AppModule
3638
import com.geotab.mobile.sdk.module.app.LastServerUpdatedCallbackType
3739
import com.geotab.mobile.sdk.module.appearance.AppearanceModule
40+
import com.geotab.mobile.sdk.module.auth.AuthModule
3841
import com.geotab.mobile.sdk.module.battery.BatteryModule
3942
import com.geotab.mobile.sdk.module.browser.BrowserModule
4043
import com.geotab.mobile.sdk.module.camera.CameraDelegate
@@ -62,6 +65,8 @@ import com.geotab.mobile.sdk.module.state.StateModule
6265
import com.geotab.mobile.sdk.module.user.DriverActionNecessaryCallbackType
6366
import com.geotab.mobile.sdk.module.dutyStatusLog.GetDutyStatusLogFunction
6467
import com.geotab.mobile.sdk.module.dutyStatusLog.GetCurrentDrivingLogFunction
68+
import com.geotab.mobile.sdk.module.login.AuthUtil
69+
import com.geotab.mobile.sdk.module.login.LoginModule
6570
import com.geotab.mobile.sdk.module.user.GetAllUsersFunction
6671
import com.geotab.mobile.sdk.module.user.GetAvailabilityFunction
6772
import com.geotab.mobile.sdk.module.user.GetHosRuleSetFunction
@@ -240,10 +245,24 @@ class DriveFragment :
240245
appPreferences
241246
)
242247
}
248+
private val authUtil: AuthUtil by lazy {
249+
AuthUtil.init(secureStorageRepository)
250+
}
251+
252+
private var loginModule: LoginModule? = null
253+
private var authModule: AuthModule? = null
254+
255+
private val secureStorageRepository: SecureStorageRepository by lazy {
256+
SecureStorageRepository(
257+
requireContext().packageName,
258+
AppDatabase.getDatabase(requireContext()).secureStorageDao()
259+
)
260+
}
243261

244262
private val secureStorageModule: SecureStorageModule by lazy {
245-
SecureStorageModule(requireContext())
263+
SecureStorageModule(secureStorageRepository)
246264
}
265+
247266
private val modulesInternal: ArrayList<Module?> by lazy {
248267
arrayListOf(
249268
deviceModule,
@@ -346,6 +365,24 @@ class DriveFragment :
346365
startForegroundService()
347366
driveReadyCallback()
348367
}
368+
if (DriveSdkConfig.includeAppAuthModules) {
369+
loginModule?.let { module ->
370+
with(module) {
371+
initValues(requireActivity())
372+
lifecycleScope.launch {
373+
withContext(Dispatchers.IO) {
374+
startTokenRefresh()
375+
}
376+
}
377+
}
378+
}
379+
authModule?.let { module ->
380+
with(module) {
381+
initValues(requireActivity())
382+
}
383+
}
384+
}
385+
349386
ioxUsbModule.start()
350387
}
351388

@@ -375,6 +412,9 @@ class DriveFragment :
375412

376413
ioxUsbModule.stop()
377414

415+
loginModule?.dispose()
416+
authModule?.dispose()
417+
378418
appModule.stopForegroundService()
379419
}
380420

@@ -425,6 +465,12 @@ class DriveFragment :
425465
this.modules = ArrayList(modules)
426466
}
427467
this.modules.addAll(modulesInternal.filterNotNull())
468+
if (DriveSdkConfig.includeAppAuthModules) {
469+
loginModule = LoginModule(authUtil)
470+
authModule = AuthModule(authUtil)
471+
loginModule?.let { this.modules.add(it) }
472+
authModule?.let { this.modules.add(it) }
473+
}
428474
logger.info(TAG, "modules initialized")
429475
}
430476

geotabdrivesdk/src/main/java/com/geotab/mobile/sdk/DriveSdkConfig.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ class DriveSdkConfig {
99
const val apiCallTimeoutMilli = 9 * 1000L
1010
var serverAddress = "my.geotab.com"
1111
var allowThirdPartyCookies = false
12+
var includeAppAuthModules = false
1213
}
1314
}

geotabdrivesdk/src/main/java/com/geotab/mobile/sdk/MyGeotabFragment.kt

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,25 @@ import android.webkit.WebView
1616
import androidx.activity.OnBackPressedCallback
1717
import androidx.annotation.Keep
1818
import androidx.fragment.app.Fragment
19+
import androidx.lifecycle.lifecycleScope
1920
import com.geotab.mobile.sdk.databinding.FragmentGeotabDriveSdkBinding
2021
import com.geotab.mobile.sdk.fileChooser.FileChooserHelper
2122
import com.geotab.mobile.sdk.logging.AppLogEventSource
2223
import com.geotab.mobile.sdk.logging.InternalAppLogging
2324
import com.geotab.mobile.sdk.models.ModuleEvent
25+
import com.geotab.mobile.sdk.models.database.AppDatabase
26+
import com.geotab.mobile.sdk.models.database.secureStorage.SecureStorageRepository
2427
import com.geotab.mobile.sdk.module.Failure
2528
import com.geotab.mobile.sdk.module.Module
2629
import com.geotab.mobile.sdk.module.ModuleFunction
2730
import com.geotab.mobile.sdk.module.NetworkErrorDelegate
2831
import com.geotab.mobile.sdk.module.Result
2932
import com.geotab.mobile.sdk.module.Success
33+
import com.geotab.mobile.sdk.module.auth.AuthModule
3034
import com.geotab.mobile.sdk.module.browser.BrowserModule
3135
import com.geotab.mobile.sdk.module.device.DeviceModule
36+
import com.geotab.mobile.sdk.module.login.AuthUtil
37+
import com.geotab.mobile.sdk.module.login.LoginModule
3238
import com.geotab.mobile.sdk.module.sso.SSOModule
3339
import com.geotab.mobile.sdk.module.webview.WebViewModule
3440
import com.geotab.mobile.sdk.permission.Permission
@@ -41,6 +47,9 @@ import com.geotab.mobile.sdk.util.PushScriptUtil
4147
import com.geotab.mobile.sdk.util.UserAgentUtil
4248
import com.geotab.mobile.sdk.util.serializable
4349
import com.github.mustachejava.DefaultMustacheFactory
50+
import kotlinx.coroutines.Dispatchers
51+
import kotlinx.coroutines.launch
52+
import kotlinx.coroutines.withContext
4453
import org.json.JSONObject
4554

4655
// fragment initialization parameters
@@ -119,6 +128,19 @@ class MyGeotabFragment :
119128
activity?.let { WebViewModule(it, goBack) }
120129
}
121130

131+
private val authUtil: AuthUtil by lazy {
132+
AuthUtil.init(secureStorageRepository)
133+
}
134+
private var loginModule: LoginModule? = null
135+
private var authModule: AuthModule? = null
136+
137+
private val secureStorageRepository: SecureStorageRepository by lazy {
138+
SecureStorageRepository(
139+
requireContext().packageName,
140+
AppDatabase.getDatabase(requireContext()).secureStorageDao()
141+
)
142+
}
143+
122144
private val modulesInternal: ArrayList<Module?> by lazy {
123145
arrayListOf(
124146
deviceModule,
@@ -241,6 +263,23 @@ class MyGeotabFragment :
241263
webView.visibility = View.VISIBLE
242264
errorView.visibility = View.GONE
243265
}
266+
if (DriveSdkConfig.includeAppAuthModules) {
267+
loginModule?.let { module ->
268+
with(module) {
269+
initValues(requireActivity())
270+
lifecycleScope.launch {
271+
withContext(Dispatchers.IO) {
272+
startTokenRefresh()
273+
}
274+
}
275+
}
276+
}
277+
authModule?.let { module ->
278+
with(module) {
279+
initValues(requireActivity())
280+
}
281+
}
282+
}
244283

245284
configureWebView()
246285
configureWebViewScript(contentController)
@@ -337,6 +376,13 @@ class MyGeotabFragment :
337376
this.modules = ArrayList(modules)
338377
}
339378
this.modules.addAll(modulesInternal.filterNotNull())
379+
380+
if (DriveSdkConfig.includeAppAuthModules) {
381+
loginModule = LoginModule(authUtil)
382+
authModule = AuthModule(authUtil)
383+
loginModule?.let { this.modules.add(it) }
384+
authModule?.let { this.modules.add(it) }
385+
}
340386
}
341387

342388
@SuppressLint("SetJavaScriptEnabled")
@@ -419,6 +465,8 @@ class MyGeotabFragment :
419465
override fun onDestroyView() {
420466
super.onDestroyView()
421467
_binding = null
468+
loginModule?.dispose()
469+
authModule?.dispose()
422470
}
423471

424472
private fun moveAppToBackground() {

geotabdrivesdk/src/main/java/com/geotab/mobile/sdk/models/database/secureStorage/SecureStorageDao.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ import androidx.room.Query
88
@Dao
99
interface SecureStorageDao {
1010
@Query("SELECT COUNT(localKey) FROM secureStorage")
11-
fun length(): Int
11+
suspend fun length(): Int
1212

1313
@Query("SELECT localKey FROM secureStorage")
14-
fun getKeys(): List<String>
14+
suspend fun getKeys(): List<String>
1515

1616
@Query("SELECT localValue as value FROM secureStorage Where localKey = :key")
17-
fun getValue(key: String): ByteArray?
17+
suspend fun getValue(key: String): ByteArray?
1818

1919
@Insert(onConflict = OnConflictStrategy.REPLACE)
20-
fun insertOrUpdate(secureStorage: SecureStorage)
20+
suspend fun insertOrUpdate(secureStorage: SecureStorage)
2121

2222
@Query("DELETE FROM secureStorage Where localKey = :key")
23-
fun deleteKey(key: String): Int
23+
suspend fun deleteKey(key: String): Int
2424

2525
@Query("DELETE FROM secureStorage")
26-
fun deleteAll(): Int
26+
suspend fun deleteAll(): Int
2727
}

0 commit comments

Comments
 (0)