2929#define PERSISTENT_STORE_ANALYTICS_NAMESPACE " Analytics"
3030#define PERSISTENT_STORE_ACCOUNT_PROFILE_NAMESPACE " accountProfile"
3131#define JSONRPC_THUNDER_TIMEOUT 20000
32+ #define THUNDER_ACCESS_DEFAULT_VALUE " 127.0.0.1:9998"
33+ #define SIFT_PARTNER_ID_DFL " rdk"
3234
3335namespace WPEFramework
3436{
@@ -313,7 +315,8 @@ namespace WPEFramework
313315 mStoreConfig(),
314316 mUploaderConfig(),
315317 mShell(shell),
316- mSystemTime(systemTime)
318+ mSystemTime(systemTime),
319+ mAuthServiceLink(nullptr )
317320 {
318321 ASSERT (shell != nullptr );
319322 ParsePluginConfig ();
@@ -336,19 +339,28 @@ namespace WPEFramework
336339 uint32_t result = interface->Unregister (&mMonitorKeys );
337340 LOGINFO (" IStore status %d" , result);
338341 interface->Release ();
339- }
342+ }
343+ if (mAuthServiceLink != nullptr )
344+ {
345+ mAuthServiceLink ->Unsubscribe (JSONRPC_THUNDER_TIMEOUT, _T (" onActivationStatusChanged" ));
346+ }
340347 }
341348
342349 bool SiftConfig::GetAttributes (SiftConfig::Attributes &attributes)
343350 {
344- // Get latest values from AuthService
345- GetAuthServiceValues ();
346- bool timeZoneValid = GetTimeZone ();
351+ UpdateXboValues ();
352+ bool timeZoneValid = UpdateTimeZone ();
347353
348354 mMutex .lock ();
349-
350355 bool valid = false ;
351356
357+ // If not activated, make sure xbo values are empty and do not contain any old data
358+ if (!mAttributes .activated )
359+ {
360+ mAttributes .xboDeviceId .clear ();
361+ mAttributes .xboAccountId .clear ();
362+ }
363+
352364 if (mAttributes .schema2Enabled )
353365 {
354366 // Sift 2.0 requires attributes
@@ -376,41 +388,6 @@ namespace WPEFramework
376388 && !mAttributes .deviceMacAddress .empty ()
377389 && timeZoneValid);
378390
379- LOGINFO (" commonSchema: %s,"
380- " productName: %s,"
381- " productVersion: %s,"
382- " loggerName: %s,"
383- " loggerVersion: %s,"
384- " partnerId: %s,"
385- " activatedValid %d,"
386- " deviceModel: %s,"
387- " deviceType: %s,"
388- " deviceOsName: %s,"
389- " deviceOsVersion: %s,"
390- " platform: %s,"
391- " deviceManufacturer: %s,"
392- " proposition: %s,"
393- " deviceSerialNumber: %s,"
394- " deviceMacAddress: %s,"
395- " timeZoneValid: %d" ,
396- mAttributes .commonSchema .c_str (),
397- mAttributes .productName .c_str (),
398- mAttributes .productVersion .c_str (),
399- mAttributes .loggerName .c_str (),
400- mAttributes .loggerVersion .c_str (),
401- mAttributes .partnerId .c_str (),
402- activatedValid,
403- mAttributes .deviceModel .c_str (),
404- mAttributes .deviceType .c_str (),
405- mAttributes .deviceOsName .c_str (),
406- mAttributes .deviceOsVersion .c_str (),
407- mAttributes .platform .c_str (),
408- mAttributes .deviceManufacturer .c_str (),
409- mAttributes .proposition .c_str (),
410- mAttributes .deviceSerialNumber .c_str (),
411- mAttributes .deviceMacAddress .c_str (),
412- timeZoneValid);
413-
414391 if (valid)
415392 {
416393 if (mAttributes .deviceType == " TV" )
@@ -425,7 +402,6 @@ namespace WPEFramework
425402 }
426403 else // Sift 1.0 required attributes
427404 {
428-
429405 valid = (!mAttributes .productName .empty ()
430406 && !mAttributes .deviceAppName .empty ()
431407 && !mAttributes .deviceAppVersion .empty ()
@@ -434,16 +410,6 @@ namespace WPEFramework
434410 && !mAttributes .deviceOsVersion .empty ()
435411 && !mAttributes .deviceType .empty ()
436412 && timeZoneValid);
437-
438- LOGINFO (" %s, %s, %s, %s, %s, %s, %s, %d" ,
439- mAttributes .productName .c_str (),
440- mAttributes .deviceAppName .c_str (),
441- mAttributes .deviceAppVersion .c_str (),
442- mAttributes .deviceModel .c_str (),
443- mAttributes .platform .c_str (),
444- mAttributes .deviceOsVersion .c_str (),
445- mAttributes .deviceType .c_str (),
446- timeZoneValid);
447413 }
448414
449415 if (valid)
@@ -492,7 +458,7 @@ namespace WPEFramework
492458 mKeysMap [PERSISTENT_STORE_ANALYTICS_NAMESPACE][" manufacturer" ] = &mAttributes .deviceManufacturer ;
493459 mKeysMap [PERSISTENT_STORE_ANALYTICS_NAMESPACE][" serialNumber" ] = &mAttributes .deviceSerialNumber ;
494460 mKeysMap [PERSISTENT_STORE_ANALYTICS_NAMESPACE][" entertainmentOSVersion" ] = &mAttributes .productVersion ;
495- // For Sift 1.0 use default values form config
461+ // For Sift 1.0 use default values from config
496462 if (mAttributes .schema2Enabled )
497463 {
498464 mKeysMap [PERSISTENT_STORE_ACCOUNT_PROFILE_NAMESPACE][" proposition" ] = &mAttributes .proposition ;
@@ -605,6 +571,61 @@ namespace WPEFramework
605571 ActivatePlugin (mShell , AUTHSERVICE_CALLSIGN);
606572 }
607573
574+ // try to create AuthService jsonrpc link and register to onActivationStatusChanged event
575+ mAuthServiceLink = GetThunderControllerClient (AUTHSERVICE_CALLSIGN);
576+ if (mAuthServiceLink )
577+ {
578+ uint32_t result = mAuthServiceLink ->Subscribe <JsonObject>(JSONRPC_THUNDER_TIMEOUT, _T (" onActivationStatusChanged" ), &SiftConfig::OnActivationStatusChanged, this );
579+ if (result != Core::ERROR_NONE)
580+ {
581+ LOGERR (" Failed to subscribe to onActivationStatusChanged" );
582+ }
583+
584+ JsonObject params;
585+ JsonObject response;
586+
587+ // Get partnerId from AuthService.getDeviceId
588+ result = mAuthServiceLink ->Invoke <JsonObject, JsonObject>(JSONRPC_THUNDER_TIMEOUT, " getDeviceId" , params, response);
589+ if (result == Core::ERROR_NONE && response.HasLabel (" partnerId" ))
590+ {
591+ mMutex .lock ();
592+ mAttributes .partnerId = response[" partnerId" ].String ();
593+ LOGINFO (" Got partnerId %s" , mAttributes .partnerId .c_str ());
594+ mMutex .unlock ();
595+ }
596+ else
597+ {
598+ LOGERR (" Failed to get partnerId: %d" , result);
599+ }
600+
601+ // Get current activation status from AuthService.getActivationStatus
602+ result = mAuthServiceLink ->Invoke <JsonObject, JsonObject>(JSONRPC_THUNDER_TIMEOUT, " getActivationStatus" , params, response);
603+ if (result == Core::ERROR_NONE && response.HasLabel (" status" ))
604+ {
605+ bool activated = false ;
606+ if (response[" status" ].String () == " activated" )
607+ {
608+ activated = true ;
609+ }
610+
611+ mMutex .lock ();
612+ mAttributes .activated = activated;
613+ mMutex .unlock ();
614+ }
615+ else
616+ {
617+ LOGERR (" Failed to get activation status" );
618+ }
619+ }
620+ else
621+ {
622+ LOGERR (" Failed to get AuthService link" );
623+ mMutex .lock ();
624+ mAttributes .partnerId = SIFT_PARTNER_ID_DFL;
625+ mAttributes .activated = false ;
626+ mMutex .unlock ();
627+ }
628+
608629 // Activate System plugin if needed
609630 if (IsPluginActivated (mShell , SYSTEM_CALLSIGN) == false )
610631 {
@@ -745,65 +766,60 @@ namespace WPEFramework
745766 return result;
746767 }
747768
748- void SiftConfig::GetAuthServiceValues ()
769+ void SiftConfig::UpdateXboValues ()
749770 {
750- auto authServiceLink = std::unique_ptr<JSONRPCDirectLink>(new JSONRPCDirectLink (mShell , AUTHSERVICE_CALLSIGN));
751- if (authServiceLink == nullptr )
771+ if (mAuthServiceLink == nullptr )
752772 {
753- LOGERR (" Failed to create JSONRPCDirectLink" );
754773 return ;
755774 }
756775
757- JsonObject params;
758- JsonObject response;
759-
760- uint32_t result = authServiceLink->Invoke <JsonObject, JsonObject>(JSONRPC_THUNDER_TIMEOUT, " getDeviceId" , params, response);
761- if (result == Core::ERROR_NONE && response.HasLabel (" partnerId" ))
762- {
763- mMutex .lock ();
764- mAttributes .partnerId = response[" partnerId" ].String ();
765- LOGINFO (" Got partnerId %s" , mAttributes .partnerId .c_str ());
766- mMutex .unlock ();
767- }
776+ // get xboAccountId and xboDeviceId from AuthService if activated and empty
777+ mMutex .lock ();
778+ bool activated = mAttributes .activated ;
779+ string xboAccountId = mAttributes .xboAccountId ;
780+ string xboDeviceId = mAttributes .xboDeviceId ;
781+ mMutex .unlock ();
768782
769- // get activation status from AuthService.getActivationStatus
770- result = authServiceLink->Invoke <JsonObject, JsonObject>(JSONRPC_THUNDER_TIMEOUT, " getActivationStatus" , params, response);
771- if (result == Core::ERROR_NONE && response.HasLabel (" status" ) && response[" status" ].String () == " activated" )
783+ if (activated && xboAccountId.empty () )
772784 {
773- LOGINFO (" Device is activated" );
785+ JsonObject params;
786+ JsonObject response;
774787 // get xboAccountId from AuthService.getServiceAccountId
775- result = authServiceLink ->Invoke <JsonObject, JsonObject>(JSONRPC_THUNDER_TIMEOUT, " getServiceAccountId" , params, response);
788+ uint32_t result = mAuthServiceLink ->Invoke <JsonObject, JsonObject>(JSONRPC_THUNDER_TIMEOUT, " getServiceAccountId" , params, response);
776789 if (result == Core::ERROR_NONE && response.HasLabel (" serviceAccountId" ))
777790 {
778791 mMutex .lock ();
779792 mAttributes .xboAccountId = response[" serviceAccountId" ].String ();
780793 LOGINFO (" Got xboAccountId %s" , mAttributes .xboAccountId .c_str ());
781794 mMutex .unlock ();
782795 }
796+ else
797+ {
798+ LOGERR (" Failed to get xboAccountId" );
799+ }
800+ }
783801
802+ if (activated && xboDeviceId.empty ())
803+ {
804+ JsonObject params;
805+ JsonObject response;
784806 // get xboDeviceId from AuthService.getXDeviceId
785- result = authServiceLink ->Invoke <JsonObject, JsonObject>(JSONRPC_THUNDER_TIMEOUT, " getXDeviceId" , params, response);
807+ uint32_t result = mAuthServiceLink ->Invoke <JsonObject, JsonObject>(JSONRPC_THUNDER_TIMEOUT, " getXDeviceId" , params, response);
786808 if (result == Core::ERROR_NONE && response.HasLabel (" xDeviceId" ))
787809 {
788810 mMutex .lock ();
789811 mAttributes .xboDeviceId = response[" xDeviceId" ].String ();
790812 LOGINFO (" Got xboDeviceId %s" , mAttributes .xboDeviceId .c_str ());
791813 mMutex .unlock ();
792814 }
793-
794- mMutex .lock ();
795- mAttributes .activated = true ;
796- mMutex .unlock ();
797- }
798- else
799- {
800- mMutex .lock ();
801- mAttributes .activated = false ;
802- mMutex .unlock ();
815+ else
816+ {
817+ LOGERR (" Failed to get xboDeviceId" );
818+ }
803819 }
804820 }
805821
806- bool SiftConfig::GetTimeZone ()
822+ bool SiftConfig::UpdateTimeZone ()
807823 {
808824 int32_t timeZoneOffsetSec = 0 ;
809825 SystemTime::TimeZoneAccuracy accuracy = SystemTime::TimeZoneAccuracy::ACC_UNDEFINED;
@@ -813,7 +829,6 @@ namespace WPEFramework
813829 accuracy = mSystemTime ->GetTimeZoneOffset (timeZoneOffsetSec);
814830 mMutex .lock ();
815831 mAttributes .deviceTimeZone = timeZoneOffsetSec * 1000 ;
816- LOGINFO (" Got deviceTimeZone %d, accuracy %d" , mAttributes .deviceTimeZone , accuracy);
817832 mMutex .unlock ();
818833 }
819834
@@ -825,6 +840,24 @@ namespace WPEFramework
825840 return false ;
826841 }
827842
843+ void SiftConfig::OnActivationStatusChanged (const JsonObject& parameters)
844+ {
845+ std::string parametersString;
846+ parameters.ToString (parametersString);
847+ LOGINFO (" OnActivationStatusChanged: %s" , parametersString.c_str ());
848+ bool activated = false ;
849+ if (parameters.HasLabel (" newActivationStatus" ) && parameters[" newActivationStatus" ].String () == " activated" )
850+ {
851+ activated = true ;
852+ }
853+
854+ mMutex .lock ();
855+ mAttributes .activated = activated;
856+ mAttributes .xboAccountId .clear ();
857+ mAttributes .xboDeviceId .clear ();
858+ mMutex .unlock ();
859+ }
860+
828861 void SiftConfig::ActivatePlugin (PluginHost::IShell *shell, const char *callSign)
829862 {
830863 JsonObject joParams;
@@ -874,6 +907,20 @@ namespace WPEFramework
874907 return state == PluginHost::IShell::ACTIVATED;
875908 }
876909
910+ std::shared_ptr<WPEFramework::JSONRPC::LinkType<WPEFramework::Core::JSON::IElement>> SiftConfig::GetThunderControllerClient (std::string callsign)
911+ {
912+ std::string thunderAccessValue = THUNDER_ACCESS_DEFAULT_VALUE;
913+ char *thunderAccessValueEnv = getenv (" THUNDER_ACCESS_VALUE" );
914+ if (NULL != thunderAccessValueEnv)
915+ {
916+ thunderAccessValue = thunderAccessValueEnv;
917+ }
918+
919+ std::string query = " token=" + sThunderSecurityToken ;
920+ Core::SystemInfo::SetEnvironment (_T (" THUNDER_ACCESS" ), (_T (thunderAccessValue)));
921+ return std::make_shared<WPEFramework::JSONRPC::LinkType<WPEFramework::Core::JSON::IElement>>(callsign, " " , false , query);
922+ }
923+
877924 void SiftConfig::MonitorKeys::ValueChanged (const string& ns, const string& key, const string& value)
878925 {
879926 auto it = mCallbacks .find (ns);
0 commit comments