Managing Platform Services 2.0 permissions prompts
This article explains how to manage permission prompts, when using Platform Services 2.0 APIs
Article Metadata
Tested with
Compatibility
Article
Summary
Security prompts are necessary to keep end user on control of what the Widget can do or not. However, if widget uses many Platform Services (PS) APIs, user experience degrades, as user has to grant permission for each API separately. Platform Services 1.0 offers an API to group these requests into one prompt: device.getServicePermissions(serviceSignatureObject);
When using Platform Services 2.0, it is not always clear what APIs you need to request access to, in order to make your widget to work without additional permission queries. One PS 2.0 API can use multiple PS1.0 APIs under the hood, to provide more complete interface to developer.
One undocumented service provider, that PS 2.0 uses internally, is ServiceRegistry. You don’t have to worry about details of this API, other than its signature. Signature consists of service provide name and interface name.
"Service.ServiceRegistry":"IService"
This signature needs always to be included in service signature object, which is passed to getServicePermissions() method. Rest of the service signatures depends on what PS 2.0 APIs are used. Those can be found, by looking at platformservices.js file . For example PS 2.0 Camera API uses System information API, for getting camera properties and MediaManagement API to fetch captured image. Then we need access to following providers:
//check that device & getServicePermissions exist for backward comptibility
if(device && typeof device.getServicePermissions == "function"){
try {
device.getServicePermissions({
"Service.ServiceRegistry":"IService",
"Service.SysInfo":"ISysInfo",
"Service.MediaManagement": "IDataSource"
});
}
catch (e) {
//notify the user that access to services has been declined
alert("declined");
return;
}
}
//continue by using old per service permission model
Following list has the signatures needed in addition to "Service.ServiceRegistry":"IService" to make PS 2.0 API to work, without additional prompts.
- Camera API:
- "Service.SysInfo":"ISysInfo"
- "Service.MediaManagement": "IDataSource"
- Calendar API :
- "Service.Calendar”: "IDataSource"
- Communications Log API:
- 'Service.Logging',:'IDataSource'
- Contacts API:
- "Service.Contact": "IDataSource"
- Landmarks API:
- "Service.Landmarks": "IDataSource"
- Location API:
- "Service.Location": "ILocation"
- Media Management API:
- "Service.MediaManagement": "IDataSource"
- Messaging API:
- "Service.Messaging": "IMessaging"
- Sensors API:
- 'Service.Sensor': 'ISensor'
- System Information API
- 'Service.SysInfo': 'ISysInfo'


(no comments yet)