Mapping and GIS Solutions Community

 View Only
Expand all | Collapse all

TPSDK for Xamarin 2020.2 - Licensing Workflow Changes

  • 1.  TPSDK for Xamarin 2020.2 - Licensing Workflow Changes

    Posted 10-20-2020 14:48



    After updating to TPSDK for Xamarin v2020.2.14.20939 my application's logic for loading a user's Catalyst subscription seems to have broken. I launch the "com.trimble.tmm.LOGIN" intent which returns successfully and gives me the logged in user's TID. My existing functionality which worked before updating the TPSDK will then create a Trimble.Licensing.V2.ILicensing instance and call the Login method, passing the TID returned from TMM. This method is supposed to return a ITrimbleUser instance which can then be passed along to the DriverManager.SetTrimbleUser method. Something like the following:


    NativeDependencyLoader.Instance.LibDir = MainActivity.get().ApplicationInfo.NativeLibraryDir;
    ILicensing oLicensing = LicensingFactory.CreateV2Licensing(MainActivity.get());
    if (oLicensing != null && m_oDriverManager != null)
          m_oCurrentUser = oLicensing.Login(szUserTID);

           if (m_oCurrentUser != null)
             bReturn = true;
          { m_oDriverManager.SetTrimbleUser(null); }
       catch (Trimble.Licensing.V2.LicenseException e1)
       { ... }


    The problem is that the oLicensing.Login method now will always return null with any user TID that I pass and my logic breaks. I have downloaded the most up to date documentation for the v2020.2 release and according to the documentation my code should still work.




    The release notes for v2020.2.14.20939 make note to Android 10 comparability, unified GNSS receiver support, and Trimble R12i support. In the "breaking changes" section there is a note about using 2020.2 if an application targets Android 10 (ours does) and changes to file locations but there is no reference to changes in the licensing workflow.


    I did download the new CatalystFacade Xamarin source code and was able to find that the source code for the licensing workflow has changed to now use an ITMMLicensingServiceConnector instance to download a user's license and then the DriverManager.SetTrimbleUser method now takes a TID not a ITrimbleUser instance (I can confirm that I had to change this in my own app in order to get it to compile). This is a bit confusing as the v2020.2 documentation doesn't make any reference to the iTMMLicensingServiceConnector.


    I can modify my application's code to follow the pattern that is laid out in the Catalyst Facade project but there's a bit of a grey area about what the implications of implementing that pattern may mean (for example, what's the role of the ITrimbleUser object now, do I need to have any internet connectivity when I call serviceConnector.DownloadLicense, etc...). I am not sure if I am doing something wrong or looking in the wrong places for documentation but It seems that the documentation for v2020.2 doesn't reflect the new licensing workflow. If the licensing workflow has indeed changed it would also be nice if the Release Notes for v2020.2 made reference to the previous licensing workflow versions being different to the current workflow.


    As a final note the documentation for v2020.2 for Xamarin makes several references to iOS/Objective-C. For example "Note also that a valid TID account is required for any application using TPSDK on iOS. Its TMMs responsibility to login the user and fetch the users TID as well as the token for accessing web services. The actual license parsing is handled by the Licensing Software Interface (LSI) as well as the LicensingHelper availble for ObjectiveC." I am not sure if this is intentional but is a little confusing to see in the Xamarin docs which I understand to be only for Android at this point in time.


  • 2.  Re: TPSDK for Xamarin 2020.2 - Licensing Workflow Changes
    Best Answer

    Posted 10-21-2020 07:08

    Hi Charles,


    nice reading from you - although in a semi-negative context


    Lets see if I can explain this so it makes sense:

    The problem you face is because you don't use the facade as component but basically import the functions/ use the functions.

    Due to this we have a sort of broken backwards comparability.

    Generally speaking the whole 'licensing' process consists of two steps:

    1. Login via TMM which
      1. gives you the user (and some other optional things)
    2. Load the subscription from TMM which
      1. Downloads your app license to the device
      2. Loads the license from the device



    function takes care about part 2.

    Because of Android 10 and data sandboxing we can't access the SD card anymore - which was where the license file was stored before.

    Therefore we introduced the 

    ITMMLicenseServiceConnector serviceConnector = TMMLicenseServiceConnectorInstanceFactory.getInstance(context);

    object - which basically bridges to TMM again. So TMM will download the license file, store it in the TMM data sandbox; the ServiceConnector funnels the content of the license then through to your application.

    So instead of deserializing the license file directly from the SD card we read it now from the app data place (SDCard/android/com.trimble.trimblemobilemager/files/Trimble/EMS) and funnel it through.

    Afterwards everything is back to default - so no change after the ServiceConnector.


    The ITrimbleUser object is in this context not super relevant. An ITrimbleUser instance contains next to the TID also access- and refresh tokens for web service calls. So if you do more web service interactions with Trimble services (like TerraFlex and Penmap are doing) this object is more useful; in your specific case there is no major need other then the TID which gets also returned from the login intent (so the callback onActivityResult).


    As for the mix of iOS, Android and Xamarin language - we're trying to merge documentation as best as possible... So although we have platform or dev language specific parts more and more things go into 'shared'... Which can lead to bad and unclear documentation in certain areas. I'll try to clean things up here. 


    Hope this helps a little.

    I would propose to just use the loadSubscriptionFromTrimbleMobileManager implementation as found in the facade. This is the easiest/ simplest approach. 




  • 3.  Re: TPSDK for Xamarin 2020.2 - Licensing Workflow Changes

    Posted 10-21-2020 08:15

    @Nico Becke Thank you so much for your quick reply! 


    All of the clarifying points you made make a lot of sense. The main concern for me was just making sure that I understood the differences in the licensing workflow now so I didn't change so code and not realize I maybe had broken another part of the logic somewhere else.


    You also make a great point that our application doesn't utilize the facade and if it did there would have been no noticeable difference in implementation when we went to update the SDK.


    The one thing I can see us needing to change is that in the past our application would cache the user's TID and then when we would load the Catalyst subscription we would rely on the returned ITrimbleUser instance to be null if the TID we had cached no longer matched the user logged into TMM. We will have to switch this around a little but it shouldn't be too bad.


    I appreciate your quick response and just wanted to say that the TPSDK team has done a great job with this release. We are excited to get Spectra Precision and R12i support in our app!


    Hope all is well and I look forward to future releases of the TPSDK, cheers!