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, wherekeystoreKeycomes from EncryptionUtil (Android Keystore) andlocalNonceis a 32-byte per-install random persisted in WidgetNonceStore (EncryptedSharedPreferences).All key copies are zeroed in
finallyimmediately after the cryptographic operation.
Usage:
val services = mutableListOf<MobileService>() services.add(WidgetService()) SDKInitializer.start(application = application, services = services.toTypedArray())
-
-
Field Summary
Fields Modifier and Type Field Description private Applicationapplicationprivate StringapiKey
-
Constructor Summary
Constructors Constructor Description WidgetService(CoroutineDispatcher ioDispatcher)WidgetService()
-
Method Summary
Modifier and Type Method Description Unitinit(Application application, String apiKey)Initializes the mobile service UnitonStateChange(ApplicationState state)Notified when application state changes. final OkHttpClientbuildHttpClient(Function1<List<AbstractOAuthClient>, AbstractOAuthClient> clientFilter, Function1<OkHttpClient.Builder, Unit> configure)Builds an OkHttpClient configured for widget read-only access. Unitreset()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
-
-
Method Detail
-
init
Unit init(Application application, String apiKey)
Initializes the mobile service
-
onStateChange
Unit onStateChange(ApplicationState state)
Notified when application state changes. This function will be called on Main thread.
-
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
nullif the service is not ready (missing AppConfig, user, or OAuth configuration).
-
-
-
-