Skip to content

Android Configuration Guide

Overview

This guide covers all configuration options available in the Squad SDK for Android, including initialization, security, networking, and feature-specific settings.

Basic Configuration

SDK Configuration

data class SquadConfig(
    val organizationId: String,
    val apiKey: String,
    val environment: Environment,
    val logLevel: LogLevel
)

// Using Builder pattern
SquadSDK.Builder(context)
    .setOrganizationId("YOUR_ORG_ID")
    .setApiKey("YOUR_API_KEY")
    .setEnvironment(Environment.PRODUCTION)
    .setLogLevel(LogLevel.INFO)
    .build()
    .initialize()

Environment Configuration

enum class Environment {
    PRODUCTION,
    STAGING,
    DEVELOPMENT;

    data class Custom(val baseUrl: String)
}

// Custom environment setup
SquadSDK.Builder(context)
    .setEnvironment(Environment.Custom("https://dev-api.yourdomain.com"))
    .build()

Security Configuration

Certificate Pinning

val certificateConfig = CertificatePinningConfig.Builder()
    .addCertificate("api.squadforsports.com", "sha256/XXXX")
    .addBackupCertificate("api.squadforsports.com", "sha256/YYYY")
    .setIncludeDefaultCertificates(true)
    .build()

squadSDK.setCertificatePinning(certificateConfig)

User Data Protection

val securityConfig = SecurityConfig.Builder()
    .setEncryption(EncryptionConfig.AES256)
    .setBiometricAuth(BiometricConfig.OPTIONAL)
    .setSecureStorage(StorageConfig.ENCRYPTED_SHARED_PREFS)
    .build()

squadSDK.setSecurityConfig(securityConfig)

Network Configuration

Timeouts and Retries

val networkConfig = NetworkConfig.Builder()
    .setConnectionTimeout(30_000) // 30 seconds
    .setReadTimeout(30_000)
    .setWriteTimeout(30_000)
    .setRetryPolicy(
        RetryPolicy(
            maxRetries = 3,
            backoffMultiplier = 1.5f,
            initialRetryDelayMs = 1000
        )
    )
    .build()

squadSDK.setNetworkConfig(networkConfig)

Caching Strategy

val cacheConfig = CacheConfig.Builder()
    .setDiskCacheSize(50 * 1024 * 1024L) // 50 MB
    .setMemoryCacheSize(10 * 1024 * 1024L) // 10 MB
    .setTimeToLive(3600) // 1 hour
    .setDiskCacheDirectory(context.cacheDir)
    .build()

squadSDK.setCacheConfig(cacheConfig)

WebView Configuration

Basic Setup

val webViewConfig = WebViewConfig.Builder()
    .setMediaPlaybackRequiresUserGesture(false)
    .setDomStorageEnabled(true)
    .setJavaScriptEnabled(true)
    .setGeolocationEnabled(false)
    .build()

squadSDK.setWebViewConfig(webViewConfig)

Content Configuration

val contentConfig = ContentConfig.Builder()
    .setAllowedContentTypes(setOf(ContentType.ALL))
    .setUserScalable(false)
    .setLoadWithOverviewMode(true)
    .setUseWideViewPort(true)
    .build()

webViewConfig.setContentConfig(contentConfig)

Voice Call Configuration

Audio Settings

val audioConfig = AudioConfig.Builder()
    .setAudioMode(AudioMode.VOICE_CHAT)
    .setEchoCancellation(true)
    .setNoiseSuppression(true)
    .setAutomaticGainControl(true)
    .build()

squadSDK.setAudioConfig(audioConfig)

Call Quality

val qualityConfig = CallQualityConfig.Builder()
    .setBitrateMode(BitrateMode.ADAPTIVE)
    .setMinBitrate(8000)
    .setMaxBitrate(32000)
    .setOpusMode(OpusMode.VOIP)
    .build()

squadSDK.setCallQualityConfig(qualityConfig)

Analytics Configuration

val analyticsConfig = AnalyticsConfig.Builder()
    .setEnabled(true)
    .setTrackingEvents(
        setOf(
            TrackingEvent.CALLS,
            TrackingEvent.ERRORS,
            TrackingEvent.PERFORMANCE
        )
    )
    .addCustomDimension("app_version", BuildConfig.VERSION_NAME)
    .addCustomDimension("environment", "production")
    .build()

squadSDK.setAnalyticsConfig(analyticsConfig)

Error Handling Configuration

val errorConfig = ErrorConfig.Builder()
    .setRetryableErrors(setOf(ErrorType.NETWORK, ErrorType.TIMEOUT))
    .setMaxRetries(3)
    .setErrorCallback { error ->
        // Handle errors
        Log.e("SquadSDK", "Error occurred: $error")
    }
    .build()

squadSDK.setErrorConfig(errorConfig)

Resource Management

Memory Management

val memoryConfig = MemoryConfig.Builder()
    .setLowMemoryThreshold(50 * 1024 * 1024L) // 50 MB
    .setCriticalMemoryThreshold(25 * 1024 * 1024L) // 25 MB
    .setCleanupCallback {
        // Perform cleanup
    }
    .build()

squadSDK.setMemoryConfig(memoryConfig)

Background Tasks

val backgroundConfig = BackgroundConfig.Builder()
    .setAllowedTasks(setOf(BackgroundTask.VOICE_CALLS, BackgroundTask.MESSAGE_DELIVERY))
    .setTimeout(30_000)
    .setCompletionCallback { result ->
        // Handle background task completion
    }
    .build()

squadSDK.setBackgroundConfig(backgroundConfig)

Advanced Configuration

Custom Event Handling

val eventConfig = EventConfig.Builder()
    .setEventHandler { event ->
        when (event) {
            is SquadEvent.CallStarted -> {
                // Handle call start
            }
            is SquadEvent.CallEnded -> {
                // Handle call end
            }
            is SquadEvent.Error -> {
                // Handle error
            }
        }
    }
    .build()

squadSDK.setEventConfig(eventConfig)

Debug Configuration

if (BuildConfig.DEBUG) {
    val debugConfig = DebugConfig.Builder()
        .setLogLevel(LogLevel.DEBUG)
        .setNetworkLogging(true)
        .setPerformanceMetricsEnabled(true)
        .setScreenshotEnabled(true)
        .build()

    squadSDK.setDebugConfig(debugConfig)
}

ProGuard Configuration

Add these rules to your proguard-rules.pro:

# Squad SDK
-keep class com.withsquad.sdk.** { *; }
-keepclassmembers class com.withsquad.sdk.** { *; }

# WebView JavaScript Interface
-keepclassmembers class * {
    @android.webkit.JavascriptInterface <methods>;
}

Best Practices

  1. Security

  2. Enable certificate pinning in production

  3. Use encrypted shared preferences for sensitive data
  4. Configure appropriate timeouts
  5. Implement proper ProGuard rules

  6. Performance

  7. Configure appropriate cache sizes

  8. Implement memory management
  9. Handle lifecycle events properly
  10. Use appropriate background task handling

  11. Error Handling

  12. Configure comprehensive error handling

  13. Implement appropriate retry strategies
  14. Use proper logging levels
  15. Handle configuration changes

  16. Testing

  17. Use staging environment for testing
  18. Enable debug logging in development
  19. Test with various network conditions
  20. Verify ProGuard configurations