Skip to content

Commit 6557de6

Browse files
Added trigger parameter to analytics event for integrity reporting.
Reporting heartbeat-triggered integrity reports as "Heartbeat". Reporting failed integrity checks during start of PersonalID configuration as "PersonalID Configuration"
1 parent 9fd08f7 commit 6557de6

File tree

6 files changed

+27
-14
lines changed

6 files changed

+27
-14
lines changed

app/src/org/commcare/android/integrity/IntegrityReporterWorker.kt

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ import androidx.work.NetworkType
1010
import androidx.work.OneTimeWorkRequest
1111
import androidx.work.WorkManager
1212
import androidx.work.WorkerParameters
13-
import com.google.android.play.core.integrity.StandardIntegrityException
1413
import com.google.common.base.Strings
15-
import org.commcare.android.database.connect.models.PersonalIdSessionData
1614
import org.commcare.android.integrity.IntegrityTokenApiRequestHelper.Companion.fetchIntegrityToken
1715
import org.commcare.android.logging.ReportingUtils
1816
import org.commcare.connect.network.connectId.PersonalIdApiHandler
@@ -63,13 +61,8 @@ class IntegrityReporterWorker(appContext: Context, workerParams: WorkerParameter
6361
val requestHash = org.commcare.utils.HashUtils.computeHash(jsonBody, org.commcare.utils.HashUtils.HashAlgorithm.SHA256)
6462
val tokenResult = fetchIntegrityToken(requestHash)
6563
val (integrityToken, hash) = tokenResult.getOrElse {
66-
val errorCode: String = if(it is StandardIntegrityException) {
67-
it.errorCode.toString();
68-
} else {
69-
it.message ?: "Unknown error"
70-
}
71-
72-
FirebaseAnalyticsUtil.reportPersonalIdIntegritySubmission(requestId, errorCode)
64+
val errorCode = IntegrityTokenApiRequestHelper.getCodeForException(it)
65+
FirebaseAnalyticsUtil.reportPersonalIdHeartbeatIntegritySubmission(requestId, errorCode)
7366

7467
body["device_error"] = errorCode
7568
makeReportIntegrityCall(context, null, null, body, requestId)
@@ -100,7 +93,7 @@ class IntegrityReporterWorker(appContext: Context, workerParams: WorkerParameter
10093
cont.resume(success)
10194
}
10295
override fun onFailure(errorCode: PersonalIdOrConnectApiErrorCodes, t: Throwable?) {
103-
FirebaseAnalyticsUtil.reportPersonalIdIntegritySubmission(requestId, "SendError")
96+
FirebaseAnalyticsUtil.reportPersonalIdHeartbeatIntegritySubmission(requestId, "SendError")
10497
cont.resume(false)
10598
}
10699
}

app/src/org/commcare/android/integrity/IntegrityTokenApiRequestHelper.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,5 +152,13 @@ class IntegrityTokenApiRequestHelper(
152152
Result.failure(e)
153153
}
154154
}
155+
156+
fun getCodeForException(exception: Throwable): String {
157+
return if (exception is StandardIntegrityException) {
158+
exception.errorCode.toString()
159+
} else {
160+
exception.message ?: "UnknownError"
161+
}
162+
}
155163
}
156164
}

app/src/org/commcare/connect/network/connectId/parser/ReportIntegrityResponseParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class ReportIntegrityResponseParser<T> implements BaseApiResponseParser<T
2020
@Override
2121
public T parse(int responseCode, @NonNull InputStream responseData, @Nullable Object anyInputObject) throws IOException,JSONException {
2222
JSONObject json = new JSONObject(new String(StreamsUtil.inputStreamToByteArray(responseData)));
23-
FirebaseAnalyticsUtil.reportPersonalIdIntegritySubmission(((String)anyInputObject),
23+
FirebaseAnalyticsUtil.reportPersonalIdHeartbeatIntegritySubmission(((String)anyInputObject),
2424
json.optString("result_code", "NoCodeFromServer"));
2525
return (T)Boolean.TRUE;
2626
}

app/src/org/commcare/fragments/personalId/PersonalIdPhoneFragment.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,9 @@ public void onTokenReceived(@NotNull String requestHash,
267267

268268
@Override
269269
public void onTokenFailure(@NotNull Exception exception) {
270-
FirebaseAnalyticsUtil.reportPersonalIdConfigurationFailure(
271-
AnalyticsParamValue.START_CONFIGURATION_INTEGRITY_DEVICE_FAILURE);
270+
String errorCode = IntegrityTokenApiRequestHelper.Companion.getCodeForException(exception);
271+
FirebaseAnalyticsUtil.reportPersonalIdConfigurationIntegritySubmission(errorCode);
272+
272273
makeStartConfigurationCall(null, body, null);
273274
}
274275
});

app/src/org/commcare/google/services/analytics/CCAnalyticsParam.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class CCAnalyticsParam {
2828
static final String FORM_ID = "form_id";
2929
static final String REQUEST_ID = "request_id";
3030
static final String RESULT_CODE = "result_code";
31+
static final String TRIGGER = "trigger";
3132

3233
static final String USER_RETURNED = "user_returned";
3334
static final String NOTIFICATION_TYPE = "notification_type";

app/src/org/commcare/google/services/analytics/FirebaseAnalyticsUtil.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,19 @@ public static void reportFormUploadAttempt(FormUploadResult first, Integer secon
409409
new String[]{String.valueOf(first), String.valueOf(second)});
410410
}
411411

412-
public static void reportPersonalIdIntegritySubmission(String requestId, String responseCode) {
412+
public static void reportPersonalIdConfigurationIntegritySubmission(String responseCode) {
413+
String label = "PersonalID Configuration";
414+
reportPersonalIdIntegritySubmission(label, label, responseCode);
415+
}
416+
417+
public static void reportPersonalIdHeartbeatIntegritySubmission(String requestId, String responseCode) {
418+
reportPersonalIdIntegritySubmission("Heartbeat", requestId, responseCode);
419+
}
420+
421+
public static void reportPersonalIdIntegritySubmission(String trigger, String requestId, String responseCode) {
413422
Bundle b = new Bundle();
414423
b.putString(CCAnalyticsParam.REQUEST_ID, requestId);
424+
b.putString(CCAnalyticsParam.TRIGGER, trigger);
415425
b.putString(CCAnalyticsParam.RESULT_CODE, responseCode);
416426
reportEvent(CCAnalyticsEvent.PERSONAL_ID_INTEGRITY_REPORTED, b);
417427
}

0 commit comments

Comments
 (0)