It is possible to block specific feature plugins for a specific Kapsel app using the Settings plugin and configuring some settings in the SMP Administration and Monitoring tool (cockpit). The SMP help pages define feature plugins as “typically JavaScript APIs that provide access to the native APIs of the mobile device (implemented as Apache Cordova plugins, for example, camera, calendar, and push).


Today, it is possible to restrict feature plugins just for Android and iOS. Windows support is coming soon.


For native apps, in the future, it will be possible to get the feature policies information via APIs. Wait for news.



Changing the Feature Restriction Policies


  1. In the SMP Administration and Monitoring tool, go to Applications.
  2. Edit the configuration of the Kapsel app that you want to restrict or allow a feature plugin from.
  3. Go to the Client Policy tab.
  4. Under Feature Restriction Policies, you can see which feature plugins are allowed to work for that specific Kapsel app. If you never did any changes to your app’s feature restriction policies, all feature plugins will be enabled. The icon under the Allowed column will be a green checkmark when this feature plugin is allowed and a red exclamation mark when it is restricted (blocked).

/wp-content/uploads/2015/05/feature_policies_711529.jpg

If you want to restrict or allow a feature plugin, you should click on the name of the desired feature plugin. Then select the Allowed checkbox if you want to allow this feature plugin to work, or unselect this checkbox if you want to block it. Click on Save and then on Save again. It is ready!

/wp-content/uploads/2015/05/feature_policies_edit_711552.jpg

Warning: a simple settings exchange should be enough for having your Kapsel app client applying the changes in the feature restriction policies you have just set. However, if you block a feature policy and then allow it to work again, you will need to close and open your Kapsel app client.

When the Kapsel starts a settings exchange after you blocked a feature plugin, it does two things:

  • Invalidates the native side of the blocked feature plugin.
  • Set the feature plugins namespace to null.

If you allow this same feature plugin to work again and perform a settings exchange, it is not in the disabled list anymore. However this plugin namespace is still null. This null value will be reset only when the page refresh happens and cordova reloads the plugin namespace.

So you will have to close the app and start it again to give cordova a chance to refresh all the namespaces.

You also can add other Kapsel or Cordova plugins to the list to block them. For that, you just have to click on the Add button, fill out the fields with information of the feature plugin you want to add and click on Save > Save.

Settings Exchange


As explained above, a settings exchange needs to be performed in order to have the Kapsel app client synchronized with feature policies set in SMP Administration and Monitoring tool (cockpit).

You can do so using the start API of the Kapsel settings plugin. You first need to pass a connection data variable with the settings to be set to the SMP Server, then success and error callbacks.

Check the index.html file attached here for an example.

For more information, please check the SMP SDK Help Portal.

The work the developer needs to do


As written above, when a feature plugin is restricted (blocked) in SMP Administration and Monitoring tool (cockpit) and settings exchange is performed from the Kapsel app client, the feature plugin namespace is set to null, preventing it to work. So, if a client tries to use this plugin, an error will occur. In order to avoid this, settings plugin has an API to check if a feature plugin is enabled or not: isFeatureEnabled.


The first parameter to be passed is a string with the name of the feature to be checked. Then success and error callbacks should be passed.


In the success callback, one parameter is received with a boolean information representing if the feature is enabled (true) or not (false).

See below the example that Daniel van Leeuwen presented in his SCN Document.

function pickContact() {

    //first check if the feature is enabled

    sap.Settings.isFeatureEnabled(“navigator.contacts”, isPickContactEnabledCallback, errorCallback);

}

function isPickContactEnabledCallback(enabled) {

    if (enabled) {

        navigator.contacts.pickContact(contactPickedCallback, errorCallback);

    }

    else {

        alert(“The Contacts Plugin has been disabled by the feature restriction policy”);    

    }

}

function contactPickedCallback(contact)  {

    alert(“The following Conact was selected: ” + JSON.stringify(contact));

}

function errorCallback(error) {

    alert(JSON.stringify(error));

}


For more information, please check the SMP SDK Help Portal.



Creating a sample app


  • Create an app in the Administration and Monitoring tool using the com.sap.test.featurevector app ID name.
    • Set any URL as your OData endpoint, since we are not going to consume data at this sample app.
    • Use Basic SSO mechanism and the Default security provider.
    • If you need further details in how to do so, go through Dan’s instructions at Configuring a Kapsel App in the Management Cockpit


  • Create your Cordova project and add the Android platform to it.
    • Open a Terminal.
    • If you do not have one, create a Kapsel_projects folder inside your Development folder.
    • Run the following commands in your terminal shell:
      • cordova -d create <DEVELOPMENT_PATH>/Kapsel_Projects/FeatureVector com.sap.test.featurevector FeatureVector
      • cd <DEVELOPMENT_PATH>/Kapsel_Projects/FeatureVector
      • cordova -d platform add android
  • Add the push plugin to your Cordova project, running the following command in your terminal shell:
    • cordova -d plugin add com.sap.mp.cordova.plugins.logon –searchpath <SMP_SDK_PATH>/KapselSDK/plugins/
    • cordova -d plugin add nl.x-services.plugins.calendar –searchpath <SMP_SDK_PATH>/KapselSDK/plugins/
    • cordova -d plugin add com.sap.mp.cordova.plugins.barcodescanner –searchpath <SMP_SDK_PATH>/KapselSDK/plugins/
    • cordova -d plugin add com.sap.mp.cordova.plugins.encryptedstorage –searchpath <SMP_SDK_PATH>/KapselSDK/plugins/
    • cordova -d plugin add com.sap.mp.cordova.plugins.settings –searchpath <SMP_SDK_PATH>/KapselSDK/plugins/
    • cordova -d plugin add de.appplant.cordova.plugin.printer –searchpath <SMP_SDK_PATH>/KapselSDK/plugins/
  • In your Cordova project, replace the content of www/index.html by the content of the following compressed file: index_fv.html.zip
    • In line 16 of the copied index_fv.html file, set serverHost as your SMP Server’s hostname or IP address.
  • Copy your www files to the Android platform folder, running the following command in your terminal shell:
    • cordova -d prepare android


  • Run the following command to run the sample app in your Android emulator or phone:
    • cordova run android
  • Register against SMP Server. This is how this app looks like after registered:

Screenshot_2015-06-12-13-52-37.png

  • If you click on the Printer button, for example, the cordova.plugins.printer.isAvailable API will be called to check if there is an available printer. See below:

Screenshot_2015-06-12-14-01-24.png


  • However, if you go to cockpit and block the Print plugin as show in the image below, you will not be able to use it in your app.

/wp-content/uploads/2015/05/cockpit_724295.jpg

  • Click on Exchange and then on Printer. This is the message will you have:

Screenshot_2015-06-12-14-03-27.png

  • Have fun and make other tests.


To report this post you need to login first.

6 Comments

You must be Logged on to comment or reply to a post.

  1. Premnarayan Patidar

    Hi Daniel,

    Setting API always returns error “MAFLogonCoreCDVPluginJS functionality is not yet implemented” for me, i have logon and setting plugin added already to the app and my device able to registered with SMP using logon manager, but sap.setting.start always throws me this error, my exchange setting function is as below, did i miss anything here,

    exchSettings: function() {

      var connectionData = {

      “keyMAFLogonOperationContextConnectionData”: {

      “keyMAFLogonConnectionDataApplicationSettings”: {

      “DeviceType”: “android”,

      “DeviceModel”: “”,

      “ApplicationConnectionId”: “myhat”,

      “ApnsBadges”: “true”,

      “ApnsSounds”: “true”,

      “ApnsAlerts”: “true”

      },

      “keyMAFLogonConnectionDataBaseURL”: “hcpms smp server path”

      },

      “keyMAFLogonOperationContextApplicationId”: “com.sap.myid”,

      “keyMAFLogonOperationContextBackendUserName”: “”,

      “keyMAFLogonOperationContextBackendPassword”: “”,

      “keyMAFLogonOperationContextSecurityConfig”: “”,

      “keySSLEnabled”: “false”

      };

      sap.Settings.start(connectionData, function(mesg) {

      sap.Logger.debug(“Setting Exchange is successful ” + mesg, “SMP_SETTINGS_JS”, function(m) {}, function(m) {});

      },

      function(mesg) {

      sap.Logger.debug(“Setting Exchange failed” + mesg, “SMP_SETTINGS_JS”, function(m) {}, function(m) {});

      });

      },

    thanks prem

    (0) 
    1. Daniel Silva Post author

      Hi, Prem!

      I’m sorry for this late response, but I’ve been very busy helping a customer with a critical project.

      What is the version of SDK you are using?

      I saw also that you left keyMAFLogonOperationContextSecurityConfig with no value. Try to pass the security config. To get this value, in the logonSuccessCallback(result), do the following:

      if (result) {

                         

                         applicationContext = result;

                          var securityConfig = applicationContext.securityConfig;

      }

      Then, the following:

                          connectionData = {

                              “keyMAFLogonOperationContextConnectionData”: {

                                  “keyMAFLogonConnectionDataApplicationSettings”:

                                  {

                                      “DeviceType”:device.platform,

                                      “DeviceModel”:device.model,

                                      “ApnsDeviceToken”:””,

                                      “ApnsBadges”:”true”,

                                      “ApnsSounds”:”true”,

                                      “ApnsAlerts”:”true”,

                                      “ApplicationConnectionId”:applicationContext.applicationConnectionId

                                  },

                                  “keyMAFLogonConnectionDataBaseURL”:burl

                              },

                              “keyMAFLogonOperationContextApplicationId”:appId,

                              “keyMAFLogonOperationContextBackendUserName”:applicationContext.registrationContext.user,

                              “keyMAFLogonOperationContextBackendPassword”:applicationContext.registrationContext.password,

                              “keyMAFLogonOperationContextSecurityConfig”:securityConfig,

                              “keySSLEnabled”:keySSLEnabled

                          };

      I hope it helps you!

      Regards,

      Daniel

      (0) 
      1. Premnarayan Patidar

        Hi Daniel,

        thanks for reply, actually i ma trying this in SAP WebIDE with HCPms server i have added logon plugin, while launching the application call logon and get resisted with server i am not calling the plugin explicitly, however i have tried calling the logon plugin explicitly to get the context of the app and security config to try out the code you sent above, but i get the same error (MAFLogonCoreCDVPluginJS functionality is not yet implemented) on logon plugin as well, i think this is happening with web IDE, did you try this in SAP web IDE.

        thanks, Prem

        (0) 
          1. Premnarayan Patidar

            Hi Daniel,

            Thanks for following back, i was having issue with setting plugin it was not working in webide for me, i have contacted product team for the same and got another API so my code now is as below and working fine for me now

            for setting exchange./wp-content/uploads/2015/12/exchange_855224.png

            And for Plugin enable/disable check.

            /wp-content/uploads/2015/12/enable_855225.png

            (0) 

Leave a Reply