Skip to content

Commit

Permalink
Merge pull request #44 from VKCOM/public
Browse files Browse the repository at this point in the history
Release v2.2.2
  • Loading branch information
diklimchuk authored Dec 12, 2024
2 parents b5fae72 + 05f33b0 commit e98e88e
Show file tree
Hide file tree
Showing 17 changed files with 169 additions and 52 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ build-maven
!gradle

.kotlin

allure-results
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
> **Note**\
> Описание основных изменений в релизах VK ID SDK. Наш SDK следует [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## 2.2.2 (12.10.2024)

### Changed
Технический релиз — поработали над внутренними улучшениями SDK.

## Placeholders plugin 1.1.0 (08.11.2024)

### Fixed
- Исправлен способ подключения через явное указание всех свойств в property. Ранее они были помечены как internal, то есть внутренние.

## 2.2.1 (14.10.2024)

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ cd vkid-android-sdk
```bash
git checkout master
git pull
git checkout -b feature/some-feature/ISSUE-0000
git checkout -b feature/ISSUE-0000/some-feature
```

## 📝 Создание коммита
Expand Down
2 changes: 1 addition & 1 deletion build-logic/placeholders/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
POM_NAME=VK ID SDK Manifest Placeholder Plugin
POM_ARTIFACT_ID=placeholders-plugin
POM_PACKAGING=jar
VERSION_NAME=1.0.0
VERSION_NAME=1.1.0
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ package com.vk.id.manifest.placeholders
*/
public open class VKIDManifestPlaceholdersExtension {
/** Specifies redirect host manifest placeholder */
internal var vkidRedirectHost: String? = null
public var vkidRedirectHost: String? = null

/** Specifies redirect scheme manifest placeholder */
internal var vkidRedirectScheme: String? = null
public var vkidRedirectScheme: String? = null

/** Specifies client id manifest placeholder */
internal var vkidClientId: String? = null
public var vkidClientId: String? = null

/** Specifies client secret manifest placeholder */
internal var vkidClientSecret: String? = null
public var vkidClientSecret: String? = null

/**
* Generates placeholders based on the client id and client secret.
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ plugins {
alias(libs.plugins.compose.compiler) apply false
alias(libs.plugins.kover) apply true
alias(libs.plugins.screenshot) apply false
id("vkid.manifest.placeholders") version "1.0.0" apply true
id("vkid.manifest.placeholders") version "1.1.0" apply true
}

dependencies {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ POM_LICENCE_NAME=MIT
POM_LICENCE_URL=https://github.com/VKCOM/vkid-android-sdk/raw/master/LICENSE
POM_LICENCE_DISTRIBUTION=repo

VERSION_NAME=2.2.1
VERSION_NAME=2.2.2
GROUP=com.vk.id

SUBSTITUTE_SAMPLE_PROJECTS_WITH_MODULES=false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import com.vk.id.sample.app.screen.UseToken
import com.vk.id.sample.app.uikit.expandablecard.ExpandableCard
import com.vk.id.sample.app.uikit.selector.CheckboxSelector
import com.vk.id.sample.app.uikit.selector.DropdownSelector
import com.vk.id.sample.xml.flutter.IsFlutterHandler
import com.vk.id.sample.xml.sctrictmode.StrictModeHandler
import com.vk.id.sample.xml.uikit.common.copyToClipboard
import com.vk.id.sample.xml.uikit.common.onVKIDAuthSuccess
Expand Down Expand Up @@ -108,6 +109,8 @@ internal fun UtilsScreen(navController: NavController) {
Spacer(modifier = Modifier.height(8.dp))
StrictModeUtil()
Spacer(modifier = Modifier.height(8.dp))
IsFlutterUtil()
Spacer(modifier = Modifier.height(8.dp))
}
}

Expand Down Expand Up @@ -590,6 +593,36 @@ private fun RevokeUtil() {
}
}

@Composable
private fun IsFlutterUtil() {
val context = LocalContext.current
var isFlutter by remember { mutableStateOf<Boolean?>(null) }
LaunchedEffect(Unit) {
launch(Dispatchers.IO) {
isFlutter = IsFlutterHandler.isFlutter(context)
}
}
val coroutineScope = rememberCoroutineScope()
CheckboxSelector(
title = "Is Flutter",
isChecked = isFlutter ?: true,
onCheckedChange = {
isFlutter = it
coroutineScope.launch(Dispatchers.IO) {
IsFlutterHandler.setIsFlutter(context, it)
withContext(Dispatchers.Main) {
Toast.makeText(
context,
"Flutter flag ${if (it) "enabled" else "disabled"}. Killing app to apply changes.",
Toast.LENGTH_SHORT
).show()
}
context.toActivitySafe()?.finishAffinity()
}
}
)
}

@Composable
private fun StrictModeUtil() {
val context = LocalContext.current
Expand Down
6 changes: 5 additions & 1 deletion sample/xml/src/main/java/com/vk/id/sample/xml/App.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
@file:OptIn(InternalVKIDApi::class)

package com.vk.id.sample.xml

import android.app.Application
import com.vk.id.VKID
import com.vk.id.common.InternalVKIDApi
import com.vk.id.sample.xml.flutter.IsFlutterHandler
import com.vk.id.sample.xml.sctrictmode.StrictModeHandler

public class App : Application() {
Expand All @@ -13,6 +17,6 @@ public class App : Application() {
StrictModeHandler.enableStrictMode()
}
VKID.logsEnabled = true
VKID.init(this)
VKID.init(this, IsFlutterHandler.isFlutter(this))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.vk.id.sample.xml.flutter

import android.annotation.SuppressLint
import android.content.Context
import androidx.preference.PreferenceManager

public object IsFlutterHandler {

private const val KEY_IS_FLUTTER = "KEY_IS_FLUTTER"

public fun isFlutter(context: Context): Boolean {
return getPrefs(context).getBoolean(KEY_IS_FLUTTER, false)
}

@SuppressLint("ApplySharedPref")
public fun setIsFlutter(context: Context, isFlutter: Boolean) {
getPrefs(context).edit().putBoolean(KEY_IS_FLUTTER, isFlutter).commit()
}

private fun getPrefs(context: Context) = PreferenceManager.getDefaultSharedPreferences(context)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public class VKIDAnalytics private constructor() {

/** Parameter for event **/
@InternalVKIDApi
public class EventParam(
@Suppress("ForbiddenPublicDataClass")
public data class EventParam(
public val name: String,
public val strValue: String? = null,
public val intValue: Int? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal class StatEventJson(
val json: JSONObject

private companion object {
private val specialParams = listOf("screen_current", "screen_to", "error")
private val specialParams = listOf("screen_current", "screen_to", "error", "wrapper_sdk_type")
private val techEvents = setOf("vkid_sdk_init")
}

Expand All @@ -31,7 +31,7 @@ internal class StatEventJson(
}

in specialParams -> {
topLevelParams[p.name] = p.strValue ?: ""
topLevelParams[p.name] = p.strValue ?: p.intValue?.toString() ?: ""
}

else -> {
Expand All @@ -41,7 +41,7 @@ internal class StatEventJson(
}
val typeAction = actionForEvent(name)
val eventJson = if (name in techEvents) {
techEventJson(name)
techEventJson(name, topLevelParams)
} else {
eventJson(name, filteredParams, topLevelParams)
}
Expand Down Expand Up @@ -132,8 +132,11 @@ internal class StatEventJson(
}
}

private fun techEventJson(eventName: String) = JSONObject().apply {
private fun techEventJson(eventName: String, topLevelParams: Map<String, String>) = JSONObject().apply {
put("step", eventName)
for (p in topLevelParams) {
put(p.key, p.value)
}
}

private fun actionForEvent(name: String): String =
Expand Down
9 changes: 6 additions & 3 deletions sdk/core/vkid/src/main/java/com/vk/id/VKID.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ public class VKID {
*
* @param context The context of the application.
*/
public fun init(context: Context): Unit = init(VKID(VKIDDepsProd(context)))
public fun init(context: Context): Unit = init(context, isFlutter = false)

@InternalVKIDApi
public fun init(context: Context, isFlutter: Boolean): Unit = init(VKID(VKIDDepsProd(context, isFlutter)))

@Suppress("LongParameterList")
internal fun init(
Expand All @@ -94,7 +97,7 @@ public class VKID {
packageManager: InternalVKIDPackageManager?,
activityStarter: InternalVKIDActivityStarter?,
): Unit = init(
VKID(object : VKIDDepsProd(context) {
VKID(object : VKIDDepsProd(context, isFlutter = false) {
override val api = lazy { InternalVKIDImmediateApi(mockApi) }
override val vkSilentAuthInfoProvider = lazy { TestSilentAuthInfoProvider() }
override val deviceIdStorage = lazy { deviceIdStorage ?: super.deviceIdStorage.value }
Expand Down Expand Up @@ -177,7 +180,7 @@ public class VKID {
logger.info(
"VKID initialized\nVersion name: ${BuildConfig.VKID_VERSION_NAME}\nCI build: ${BuildConfig.CI_BUILD_NUMBER} ${BuildConfig.CI_BUILD_TYPE}"
)
VKIDAnalytics.trackEvent("vkid_sdk_init")
VKIDAnalytics.trackEvent("vkid_sdk_init", VKIDAnalytics.EventParam("wrapper_sdk_type", strValue = if (deps.isFlutter) "flutter" else "none"))
}

private val requestMutex = Mutex()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ internal interface VKIDDeps {
val statTracker: StatTracker
val vkidPackageManager: InternalVKIDPackageManager
val activityStarter: InternalVKIDActivityStarter
val isFlutter: Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ import com.vk.id.storage.InternalVKIDEncryptedSharedPreferencesStorage
import com.vk.id.storage.TokenStorage

internal open class VKIDDepsProd(
private val appContext: Context
private val appContext: Context,
override val isFlutter: Boolean,
) : VKIDDeps {

private val serviceCredentials: Lazy<ServiceCredentials> = lazy {
val componentName = ComponentName(appContext, AuthActivity::class.java)
val ai = getActivityInfo(componentName)
Expand Down
93 changes: 59 additions & 34 deletions sdk/core/vkid/src/test/java/com/vk/id/VKIDTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

package com.vk.id

import com.vk.id.analytics.VKIDAnalytics
import com.vk.id.analytics.stat.StatTracker
import com.vk.id.auth.VKIDAuthParams
import com.vk.id.common.InternalVKIDApi
Expand Down Expand Up @@ -45,48 +46,72 @@ internal class VKIDTest : BehaviorSpec({

coroutineTestScope = true

Given("Auth with VK is called") {
val authProvidersChooser = mockk<AuthProvidersChooser>()
val authProvider = mockk<VKIDAuthProvider>()
val authOptionsCreator = mockk<AuthOptionsCreator>()
val authCallbacksHolder = mockk<AuthCallbacksHolder>()
val authResultHandler = mockk<AuthResultHandler>()
val authProvidersChooser = mockk<AuthProvidersChooser>()
val authProvider = mockk<VKIDAuthProvider>()
val authOptionsCreator = mockk<AuthOptionsCreator>()
val authCallbacksHolder = mockk<AuthCallbacksHolder>()
val authResultHandler = mockk<AuthResultHandler>()
val userDataFetcher = mockk<UserDataFetcher>()
val dispatchers = mockk<VKIDCoroutinesDispatchers>()
val statTracker = mockk<StatTracker>(relaxed = true)
var isFlutter = false
val deps = object : VKIDDeps {
override val authProvidersChooser: Lazy<AuthProvidersChooser> = lazy { authProvidersChooser }
override val authOptionsCreator: AuthOptionsCreator = authOptionsCreator
override val authCallbacksHolder: AuthCallbacksHolder = authCallbacksHolder
override val authResultHandler: Lazy<AuthResultHandler> = lazy { authResultHandler }
override val dispatchers: VKIDCoroutinesDispatchers = dispatchers
override val statTracker: StatTracker = statTracker
override val vkSilentAuthInfoProvider: Lazy<VkSilentAuthInfoProvider> = mockk()
override val userDataFetcher: Lazy<UserDataFetcher> = lazy { userDataFetcher }
override val api: Lazy<InternalVKIDApiContract> = lazy { mockk() }
override val tokenRefresher: Lazy<VKIDTokenRefresher> = lazy { mockk() }
override val tokenExchanger: Lazy<VKIDTokenExchanger> = lazy { mockk() }
override val userRefresher: Lazy<VKIDUserRefresher> = lazy { mockk() }
override val loggerOut: Lazy<VKIDLoggerOut> = lazy { mockk() }
override val tokenStorage: TokenStorage = mockk()
override val deviceIdStorage: Lazy<InternalVKIDDeviceIdProvider.DeviceIdStorage> = lazy { mockk() }
override val prefsStore: Lazy<InternalVKIDPrefsStore> = lazy { mockk() }
override val encryptedSharedPreferencesStorage: Lazy<InternalVKIDEncryptedSharedPreferencesStorage> =
lazy { mockk() }
override val vkidPackageManager: InternalVKIDPackageManager = mockk()
override val activityStarter: InternalVKIDActivityStarter = mockk()
override val isFlutter: Boolean
get() = isFlutter
}

Given("VKID for flutter SDK") {
val scheduler = testCoroutineScheduler
val testDispatcher = StandardTestDispatcher(scheduler)
val userDataFetcher = mockk<UserDataFetcher>()
val dispatchers = mockk<VKIDCoroutinesDispatchers>()
val statTracker = mockk<StatTracker>(relaxed = true)
every { dispatchers.io } returns testDispatcher
val vkid = VKID(
object : VKIDDeps {
override val authProvidersChooser: Lazy<AuthProvidersChooser> = lazy { authProvidersChooser }
override val authOptionsCreator: AuthOptionsCreator = authOptionsCreator
override val authCallbacksHolder: AuthCallbacksHolder = authCallbacksHolder
override val authResultHandler: Lazy<AuthResultHandler> = lazy { authResultHandler }
override val dispatchers: VKIDCoroutinesDispatchers = dispatchers
override val statTracker: StatTracker = statTracker
override val vkSilentAuthInfoProvider: Lazy<VkSilentAuthInfoProvider> = mockk()
override val userDataFetcher: Lazy<UserDataFetcher> = lazy { userDataFetcher }
override val api: Lazy<InternalVKIDApiContract> = lazy { mockk() }
override val tokenRefresher: Lazy<VKIDTokenRefresher> = lazy { mockk() }
override val tokenExchanger: Lazy<VKIDTokenExchanger> = lazy { mockk() }
override val userRefresher: Lazy<VKIDUserRefresher> = lazy { mockk() }
override val loggerOut: Lazy<VKIDLoggerOut> = lazy { mockk() }
override val tokenStorage: TokenStorage = mockk()
override val deviceIdStorage: Lazy<InternalVKIDDeviceIdProvider.DeviceIdStorage> = lazy { mockk() }
override val prefsStore: Lazy<InternalVKIDPrefsStore> = lazy { mockk() }
override val encryptedSharedPreferencesStorage: Lazy<InternalVKIDEncryptedSharedPreferencesStorage> =
lazy { mockk() }
override val vkidPackageManager: InternalVKIDPackageManager = mockk()
override val activityStarter: InternalVKIDActivityStarter = mockk()
isFlutter = true
VKID(deps)

When("VKID initialized") {
Then("Analytics vkid_sdk_init event is send") {
verify {
statTracker.trackEvent(
"vkid_sdk_init",
VKIDAnalytics.EventParam("wrapper_sdk_type", strValue = "flutter")
)
}
}
)
}
}

Given("Auth with VK is called") {
val scheduler = testCoroutineScheduler
val testDispatcher = StandardTestDispatcher(scheduler)
every { dispatchers.io } returns testDispatcher
isFlutter = false
val vkid = VKID(deps)

When("VKID initialized") {
Then("Analytics vkid_init event is send") {
Then("Analytics vkid_sdk_init event is send") {
verify {
statTracker.trackEvent(
"vkid_sdk_init"
"vkid_sdk_init",
VKIDAnalytics.EventParam("wrapper_sdk_type", strValue = "none")
)
}
}
Expand Down
Loading

0 comments on commit e98e88e

Please sign in to comment.