Class WidgetService

  • All Implemented Interfaces:

    
    public final class WidgetService
    extends MobileService
                        

    Provides widget-scoped HTTP access to BTP mobile services using the host app's OAuth token and a session-first authentication strategy. Replaces AppExtensionService.

    Token confidentiality is layered:

    • The on-disk token blob is AES-256-GCM encrypted (RawEncryption).

    • The encryption key is derived per-call as keystoreKey XOR localNonce, where keystoreKey comes from EncryptionUtil (Android Keystore) and localNonce is a 32-byte per-install random persisted in WidgetNonceStore (EncryptedSharedPreferences).

    • All key copies are zeroed in finally immediately after the cryptographic operation.

    Usage:

    val services = mutableListOf<MobileService>()
    services.add(WidgetService())
    SDKInitializer.start(application = application, services = services.toTypedArray())
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      Unit init(Application application, String apiKey) Initializes the mobile service
      Unit onStateChange(ApplicationState state) Notified when application state changes.
      final OkHttpClient buildHttpClient(Function1<List<AbstractOAuthClient>, AbstractOAuthClient> clientFilter, Function1<OkHttpClient.Builder, Unit> configure) Builds an OkHttpClient configured for widget read-only access.
      Unit reset() Resets the mobile service to the state that just initialized.
      • Methods inherited from class com.sap.cloud.mobile.foundation.mobileservices.MobileService

        enableNetworkPolicy, getApiKey, getApplication, isApplicationInitialized, mayStartNewProcess, setApiKey, setApplication
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • WidgetService

        WidgetService(CoroutineDispatcher ioDispatcher)
      • WidgetService

        WidgetService()
    • Method Detail

      • buildHttpClient

         final OkHttpClient buildHttpClient(Function1<List<AbstractOAuthClient>, AbstractOAuthClient> clientFilter, Function1<OkHttpClient.Builder, Unit> configure)

        Builds an OkHttpClient configured for widget read-only access.

        The client uses a session-first authentication strategy: requests are first sent with session cookies; on 401, the client falls back to Bearer token authentication with automatic token refresh.

        Parameters:
        clientFilter - optional filter to select which OAuth client to use from the configured list.
        configure - optional block to further customize the OkHttpClient.Builder (e.g.
        Returns:

        a configured OkHttpClient, or null if the service is not ready (missing AppConfig, user, or OAuth configuration).

      • reset

         Unit reset()

        Resets the mobile service to the state that just initialized.