QA

class QA

This is the main element one needs to use to access all the functionality of the QA SDK. As a singleton it can be called easily from anywhere in the code and gives access to all the possible interactions with the QA backend, as well as some functions to retrieve user metrics. Since most of the calls are asynchronous server interactions, they return flows.

Author

Enea Ceolini

Types

Link copied to clipboard
object Companion

Used to retrieve the default singleton instance of QA.

Link copied to clipboard
enum Flag : Enum<QA.Flag>

This internal class holds the string that identify the flags for requesting the number of taps in a certain period with QA.getLastTaps

Link copied to clipboard

Enumeration class containing the available Genders for the registration of the device.

Properties

Link copied to clipboard

BasicInfo for the current user

Link copied to clipboard

ID of the device

Link copied to clipboard

Firebase token for communication

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
fun canActivity(context: Context): Boolean

Returns whether or not the activity recognition permission has been granted

Link copied to clipboard
fun canDraw(context: Context): Boolean

Returns whether or not the draw over other apps permission has been granted

Link copied to clipboard
fun canUsage(context: Context): Boolean

Returns whether or not the usage permission has been granted

Link copied to clipboard
suspend fun deleteJournalEntry(id: String)

Use this function to delete a journal entry. You need to provide the id of the entry you want to delete, checkout journalEntries and JournalEntry to see how to retrieve the id of the entry to delete.

Link copied to clipboard
suspend fun getCohortList(): List<Cohort>

Retrieves the list of studies the device is currently registered for.

Link copied to clipboard
Link copied to clipboard
fun getJournalEntry(journalEntryId: String): JournalEntry?

Use this function to retrieve a particular journal entry. You need to provide the id of the entry you want to retrieve, checkout journalEntries and JournalEntry to see how to retrieve the id of the entry.

Link copied to clipboard
suspend fun getJournalSample(context: Context, apiKey: String): List<JournalEntry>

This functions returns a fictitious journal and can be used for test/display purposes, Checkout JournalEntry for a complete description of how the journal entries are organized.

Link copied to clipboard

Retrieves taps in the last day, week or month depending on the provided flag. Please also QATaps shows the provided result structure. Alpha feature, try setting flag as the number of days you would like to gat back.

Link copied to clipboard
fun <P : TimestampedEntity, T> getMetric(score: Metric<P, T>, from: Long = Instant.now().minus(60, ChronoUnit.DAYS).toEpochMilli(), to: Long = Instant.now().toEpochMilli(), refresh: Boolean = false): Flow<TimeSeries<T>>

Get a QA metric or trend relative to the device in use. Check the the list of available metrics from Metric and Trend. The function returns an object of type TimeSeries which contains timestamps and values of the requested metric. The call is asynchronous ans returns a flow.

Link copied to clipboard
fun <P : TimestampedEntity, T> getMetricSample(context: Context, apiKey: String, score: Metric<P, T>, from: Long = Instant.now().minus(60, ChronoUnit.DAYS).toEpochMilli(), to: Long = Instant.now().toEpochMilli()): Flow<TimeSeries<T>>

Get a QA metric relative to a fictitious test device. Check the the list of available metrics from Metric. The function returns an object of type TimeSeries which contains timestamps and values of the requested metric. The call is asynchronous ans returns a flow. You can use this function to test your data workflow and visualization.

Link copied to clipboard

Get a list of all the questionnaires available to complete (across all the studies to which a device is subscribed to).

Link copied to clipboard
suspend fun init(context: Context, apiKey: String, basicInfo: BasicInfo, identityId: String? = null, password: String? = null): Boolean

The first time you use the QA SDK in the code you should initialize it, this allows the SDK to create a unique identifier and initiate server transactions and workflows. Most of the functionality will not work if you have never initialized the singleton before. The function is synchronous and return a flow with the status of the registration of the device to the server. NOTE: do not use this function without collecting the flow otherwise the function will not be called at all.

Link copied to clipboard

This function check that the data collection is currently running.

Link copied to clipboard

This function checks if the device is already registered to the QA backend.

Link copied to clipboard
fun journalEntries(): Flow<List<JournalEntry>>

This functions returns the full journal of the device, meaning all entries with the corresponding events. Checkout JournalEntry for a complete description of how the journal entries are organized.

Link copied to clipboard
suspend fun journalEventKinds(): List<JournalEventEntity>

Retrieves the Journal events, meaning the events that one can log together with a journal entry. The events come from a fixed set which may be updated in the future, this function return the latest update to the JournalEventEntity.

Link copied to clipboard
suspend fun leaveCohort(subscriptionId: String, cohortId: String)

Use this to withdraw the device from a particular cohort.

Link copied to clipboard

Pause the data collection.

Link copied to clipboard
suspend fun recordQuestionnaireResponse(name: String, code: String, date: Long, fullID: String, response: Map<String, Any>)

Saves a questionnaire response.

Link copied to clipboard

This function checks if the overlay permission has been granted, if not opens the corresponding settings activity to prompt the user to grant this permission.

Link copied to clipboard

This function checks if the usage permission has been granted, if not open the corresponding settings activity to prompt the user to grant this permission.

Link copied to clipboard
suspend fun reSubscribe(subscriptionId: String)

Use this to re-subscribe the user to a cohort from which they were withdrawn.

Link copied to clipboard

Restart the data collection after it has been purposely paused.

Some manufacturers kill apps that are running for too long, on those devices it is better to ask the user to prevent the OS from killing the app running this SDK. Call this function to retrieve the Intent that redirects the user to the correct setting for disabling battery optimization of the current manufacturer. The functions returns a list, choose the first intent, in an empty list is returned, the current manufacturer does not have specific battery optimization options, thus the request is not needed and the SDk should run safely.

Link copied to clipboard
suspend fun saveJournalEntry(journalEntry: JournalEntry): JournalEntry

Use this utility function to create or edit a journal entry. In case you want to edit a note you will need to pass the ID of the entity to edit. The function returns an asynchronous flow with the response of the action. The response is mostly to trigger UI/UX events, in case of failure the SDK will take care internally of retrying.

Link copied to clipboard
suspend fun sendNote(text: String)

Saves simple text note.

Link copied to clipboard
Link copied to clipboard
suspend fun subscribe(cohortId: String? = null, subscriptionId: String? = null): SubscriptionWithQuestionnaires

Use this function to subscribe the device to your(one of your) cohort(s).

Link copied to clipboard
suspend fun subscriptions(studyId: String? = null): List<Subscription>
Link copied to clipboard
suspend fun syncData(context: Context)

Utility function to sync all the local data with the server. Due to the complexity of the work, it spawns a Worker and return its UUID. The status of the worker can be observed to check its status of SUCCESS/FAILURE.

Link copied to clipboard
fun update(newYearOfBirth: Int = basicInfo.yearOfBirth, newGender: QA.Gender = basicInfo.gender, newSelfDeclaredHealthy: Boolean = basicInfo.selfDeclaredHealthy)

Use this function to update the basic info of a user. You can call the function with one or parameters, the missing ones will be considered unaltered.