@@ -516,6 +516,74 @@ else if (approovResults.getStatus() != Approov.TokenFetchStatus.SUCCESS)
516516 return approovResults .getToken ();
517517 }
518518
519+ /**
520+ * Gets the last ARC (Attestation Response Code) code.
521+ *
522+ * Always resolves with a string (ARC or empty string).
523+ * NOTE: You MUST only call this method upon succesfull attestation completion. Any networking
524+ * errors returned from the service layer will not return a meaningful ARC code if the method is called!!!
525+ * @return String ARC from last attestation request or empty string if network unavailable
526+ */
527+ public static String getLastARC () {
528+ // Get the dynamic pins from Approov
529+ Map <String , List <String >> approovPins = Approov .getPins ("public-key-sha256" );
530+ if (approovPins == null || approovPins .isEmpty ()) {
531+ Log .e (TAG , "ApproovService: no host pinning information available" );
532+ return "" ;
533+ }
534+ // The approovPins contains a map of hostnames to pin strings. Skip '*' and use another hostname if available.
535+ String hostname = null ;
536+ for (String key : approovPins .keySet ()) {
537+ if (!"*" .equals (key )) {
538+ hostname = key ;
539+ break ;
540+ }
541+ }
542+ if (hostname != null ) {
543+ try {
544+ Approov .TokenFetchResult result = Approov .fetchApproovTokenAndWait (hostname );
545+ if (result .getToken () != null && !result .getToken ().isEmpty ()) {
546+ String arc = result .getARC ();
547+ if (arc != null ) {
548+ return arc ;
549+ }
550+ }
551+ Log .i (TAG , "ApproovService: ARC code unavailable" );
552+ return "" ;
553+ } catch (Exception e ) {
554+ Log .e (TAG , "ApproovService: error fetching ARC" , e );
555+ return "" ;
556+ }
557+ } else {
558+ Log .i (TAG , "ApproovService: ARC code unavailable" );
559+ return "" ;
560+ }
561+ }
562+
563+ /**
564+ * Sets an install attributes token to be sent to the server and associated with this particular
565+ * app installation for future Approov token fetches. The token must be signed, within its
566+ * expiry time and bound to the correct device ID for it to be accepted by the server.
567+ * Calling this method ensures that the next call to fetch an Approov
568+ * token will not use a cached version, so that this information can be transmitted to the server.
569+ *
570+ * @param attrs is the signed JWT holding the new install attributes
571+ * @return void
572+ * @throws ApproovException if the attrs parameter is invalid or the SDK is not initialized
573+ */
574+ public static void setInstallAttrsInToken (String attrs ) throws ApproovException {
575+ try {
576+ Approov .setInstallAttrsInToken (attrs );
577+ Log .d (TAG , "setInstallAttrsInToken" );
578+ } catch (IllegalArgumentException e ) {
579+ Log .e (TAG , "setInstallAttrsInToken failed with IllegalArgument: " + e .getMessage ());
580+ throw new ApproovException ("setInstallAttrsInToken: " + e .getMessage ());
581+ } catch (IllegalStateException e ) {
582+ Log .e (TAG , "setInstallAttrsInToken failed with IllegalState: " + e .getMessage ());
583+ throw new ApproovException ("setInstallAttrsInToken: " + e .getMessage ());
584+ }
585+ }
586+
519587 /**
520588 * Adds Approov to the given connection. The Approov token is added in a header and this
521589 * also overrides the HostnameVerifier with something that pins the connections. If a
0 commit comments