29
29
#define PERSISTENT_STORE_ANALYTICS_NAMESPACE " Analytics"
30
30
#define PERSISTENT_STORE_ACCOUNT_PROFILE_NAMESPACE " accountProfile"
31
31
#define JSONRPC_THUNDER_TIMEOUT 20000
32
+ #define THUNDER_ACCESS_DEFAULT_VALUE " 127.0.0.1:9998"
33
+ #define SIFT_PARTNER_ID_DFL " rdk"
32
34
33
35
namespace WPEFramework
34
36
{
@@ -313,7 +315,8 @@ namespace WPEFramework
313
315
mStoreConfig(),
314
316
mUploaderConfig(),
315
317
mShell(shell),
316
- mSystemTime(systemTime)
318
+ mSystemTime(systemTime),
319
+ mAuthServiceLink(nullptr )
317
320
{
318
321
ASSERT (shell != nullptr );
319
322
ParsePluginConfig ();
@@ -336,19 +339,28 @@ namespace WPEFramework
336
339
uint32_t result = interface->Unregister (&mMonitorKeys );
337
340
LOGINFO (" IStore status %d" , result);
338
341
interface->Release ();
339
- }
342
+ }
343
+ if (mAuthServiceLink != nullptr )
344
+ {
345
+ mAuthServiceLink ->Unsubscribe (JSONRPC_THUNDER_TIMEOUT, _T (" onActivationStatusChanged" ));
346
+ }
340
347
}
341
348
342
349
bool SiftConfig::GetAttributes (SiftConfig::Attributes &attributes)
343
350
{
344
- // Get latest values from AuthService
345
- GetAuthServiceValues ();
346
- bool timeZoneValid = GetTimeZone ();
351
+ UpdateXboValues ();
352
+ bool timeZoneValid = UpdateTimeZone ();
347
353
348
354
mMutex .lock ();
349
-
350
355
bool valid = false ;
351
356
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
+
352
364
if (mAttributes .schema2Enabled )
353
365
{
354
366
// Sift 2.0 requires attributes
@@ -376,41 +388,6 @@ namespace WPEFramework
376
388
&& !mAttributes .deviceMacAddress .empty ()
377
389
&& timeZoneValid);
378
390
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
-
414
391
if (valid)
415
392
{
416
393
if (mAttributes .deviceType == " TV" )
@@ -425,7 +402,6 @@ namespace WPEFramework
425
402
}
426
403
else // Sift 1.0 required attributes
427
404
{
428
-
429
405
valid = (!mAttributes .productName .empty ()
430
406
&& !mAttributes .deviceAppName .empty ()
431
407
&& !mAttributes .deviceAppVersion .empty ()
@@ -434,16 +410,6 @@ namespace WPEFramework
434
410
&& !mAttributes .deviceOsVersion .empty ()
435
411
&& !mAttributes .deviceType .empty ()
436
412
&& 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);
447
413
}
448
414
449
415
if (valid)
@@ -492,7 +458,7 @@ namespace WPEFramework
492
458
mKeysMap [PERSISTENT_STORE_ANALYTICS_NAMESPACE][" manufacturer" ] = &mAttributes .deviceManufacturer ;
493
459
mKeysMap [PERSISTENT_STORE_ANALYTICS_NAMESPACE][" serialNumber" ] = &mAttributes .deviceSerialNumber ;
494
460
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
496
462
if (mAttributes .schema2Enabled )
497
463
{
498
464
mKeysMap [PERSISTENT_STORE_ACCOUNT_PROFILE_NAMESPACE][" proposition" ] = &mAttributes .proposition ;
@@ -605,6 +571,61 @@ namespace WPEFramework
605
571
ActivatePlugin (mShell , AUTHSERVICE_CALLSIGN);
606
572
}
607
573
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
+
608
629
// Activate System plugin if needed
609
630
if (IsPluginActivated (mShell , SYSTEM_CALLSIGN) == false )
610
631
{
@@ -745,65 +766,60 @@ namespace WPEFramework
745
766
return result;
746
767
}
747
768
748
- void SiftConfig::GetAuthServiceValues ()
769
+ void SiftConfig::UpdateXboValues ()
749
770
{
750
- auto authServiceLink = std::unique_ptr<JSONRPCDirectLink>(new JSONRPCDirectLink (mShell , AUTHSERVICE_CALLSIGN));
751
- if (authServiceLink == nullptr )
771
+ if (mAuthServiceLink == nullptr )
752
772
{
753
- LOGERR (" Failed to create JSONRPCDirectLink" );
754
773
return ;
755
774
}
756
775
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 ();
768
782
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 () )
772
784
{
773
- LOGINFO (" Device is activated" );
785
+ JsonObject params;
786
+ JsonObject response;
774
787
// 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);
776
789
if (result == Core::ERROR_NONE && response.HasLabel (" serviceAccountId" ))
777
790
{
778
791
mMutex .lock ();
779
792
mAttributes .xboAccountId = response[" serviceAccountId" ].String ();
780
793
LOGINFO (" Got xboAccountId %s" , mAttributes .xboAccountId .c_str ());
781
794
mMutex .unlock ();
782
795
}
796
+ else
797
+ {
798
+ LOGERR (" Failed to get xboAccountId" );
799
+ }
800
+ }
783
801
802
+ if (activated && xboDeviceId.empty ())
803
+ {
804
+ JsonObject params;
805
+ JsonObject response;
784
806
// 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);
786
808
if (result == Core::ERROR_NONE && response.HasLabel (" xDeviceId" ))
787
809
{
788
810
mMutex .lock ();
789
811
mAttributes .xboDeviceId = response[" xDeviceId" ].String ();
790
812
LOGINFO (" Got xboDeviceId %s" , mAttributes .xboDeviceId .c_str ());
791
813
mMutex .unlock ();
792
814
}
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
+ }
803
819
}
804
820
}
805
821
806
- bool SiftConfig::GetTimeZone ()
822
+ bool SiftConfig::UpdateTimeZone ()
807
823
{
808
824
int32_t timeZoneOffsetSec = 0 ;
809
825
SystemTime::TimeZoneAccuracy accuracy = SystemTime::TimeZoneAccuracy::ACC_UNDEFINED;
@@ -813,7 +829,6 @@ namespace WPEFramework
813
829
accuracy = mSystemTime ->GetTimeZoneOffset (timeZoneOffsetSec);
814
830
mMutex .lock ();
815
831
mAttributes .deviceTimeZone = timeZoneOffsetSec * 1000 ;
816
- LOGINFO (" Got deviceTimeZone %d, accuracy %d" , mAttributes .deviceTimeZone , accuracy);
817
832
mMutex .unlock ();
818
833
}
819
834
@@ -825,6 +840,24 @@ namespace WPEFramework
825
840
return false ;
826
841
}
827
842
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
+
828
861
void SiftConfig::ActivatePlugin (PluginHost::IShell *shell, const char *callSign)
829
862
{
830
863
JsonObject joParams;
@@ -874,6 +907,20 @@ namespace WPEFramework
874
907
return state == PluginHost::IShell::ACTIVATED;
875
908
}
876
909
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
+
877
924
void SiftConfig::MonitorKeys::ValueChanged (const string& ns, const string& key, const string& value)
878
925
{
879
926
auto it = mCallbacks .find (ns);
0 commit comments