Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
DanielSilva1
Advisor
Advisor
0 Kudos

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).

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!

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:

  • 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:


  • 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.

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

  • Have fun and make other tests.


6 Comments