Media Permissions
Unless you are the owner, the db8 service, by default, denies application and service access to all stored media data objects (Media Indexer). Read-only access to db8 data is granted through the "com.palm.mediapermissions" service. Currently, this service provides the following API.
request
Your app can use this API to request access to one or more db8 kinds and their stored data objects. If the caller is new to the media permissions service, a dialog box is displayed to the user asking if access is ok for this app. Once the user responds, the caller is notified with the verdict - either the app has complete access or none at all. At the moment, it is not possible for the user to grant limited or partial access or deny. The response is then stored in the database for future reference. This cached response is used in case repeated requests for access are made so the user is not disturbed.
Note that granted permissions can become invalid after inactivity or application removal. There is no guaranteed permissions duration, though it is unlikely permissions would be revoked immediately after being granted. A typical solution is to attempt access during application start and, if denied, make a request call to prompt the user before continuing.
Syntax
{
"rights": {
"read": string array
}
}
Parameters
| Parameter | Required | Type | Description |
| rights | Yes | inline object | See element below |
| read | Yes | string array | db8 kinds you want read-only access for. |
Returns
{
"returnValue" : boolean,
"isAllowed" : boolean,
"reason" : string
}
| Element | Required | Type | Description |
| returnValue | Yes | boolean | Service call success (true) or failure (false) |
| isAllowed | Yes | boolean | If true, rights are granted. |
| reason | No | string | If "isAllowed" is false, reason for denial. |
Examples
Enyo
enyo.kind({
name : "enyo.mediaidxr",
kind : enyo.VFlexBox,
components : [
{ flex : 1,
kind : "Pane",
components : [{
flex : 1,
kind : "Scroller",
components : [
{
name : "getPerm",
kind : "PalmService",
service : "palm://com.palm.mediapermissions",
method : "request",
onSuccess : "getPermSuccess",
onFailure : "getPermFailure",
subscribe : true
},
{kind : "Button", name : "getPermButton", caption : "Get Permissions", onclick : "getPermClick"}
]
}]
}],
getPermClick: function() {
var album = "com.palm.media.audio.album:1";
var albumimage = "com.palm.media.image.album:1";
var artist = "com.palm.media.audio.artist:1";
var audio = "com.palm.media.audio.file:1";
var genre = "com.palm.media.audio.genre:1";
var image = "com.palm.media.image.file:1";
var playlist = "com.palm.media.audio.playlist.object:1";
var video = "com.palm.media.video.file:1";
var params = {"read":[album, albumimage, artist, audio, genre, image, playlist, video]};
this.$.getPerm.call({ "rights":params});
},
getPermSuccess: function(inSender, inResponse) {
this.log("Get Permissions success, results=" + enyo.json.stringify(inResponse));
},
// Log errors to the console for debugging
getPermFailure: function(inSender, inError, inRequest) {
this.log(enyo.json.stringify(inError));
}
});
Mojo
var self = this;
var imageKind = "com.palm.media.image.file:1";
var albumKind = "com.palm.media.image.album:1";
function requestPermission(done) {
self.controller.serviceRequest('palm://com.palm.mediapermissions', {
method: 'request',
parameters: {
rights: {
read: [imageKind, albumKind]
}
},
onComplete: function(response) {
if (response.returnValue && response.isAllowed) {
Mojo.Log.info('Got permissions okay!');
done();
} else {
Mojo.Log.error('Failed to get permissions!');
}
}
});
}
function checkPermissions(done) {
self.controller.serviceRequest('palm://com.palm.db', {
method: 'find',
parameters: {
query: {
from: imageKind,
limit: 1
}
},
onSuccess: function() {
Mojo.Log.info('We have permissions.');
done();
},
onFailure: function() {
Mojo.Log.info('We do not have permission, asking.');
requestPermission(done);
}
});
}
checkPermissions(function continueToRunApp() {
// we're running good now!
});
Checking Device Permissions
You can open a shell on the device using putty or novacom and run the following luna-send command that makes a db8 service call to check device permissions.
Note: The filenotifyd process is always running and dynamically informs other applications of file system changes.
luna-send -n 1 -f -a com.palm.filenotifyd.js palm://com.palm.db/find '{"query":{"from":"com.palm.media.permissions:1"}}'
{
"returnValue": true,
"results": [
{
"_id": "++HdXMLuDHSWAph2",
"_kind": "com.palm.media.permissions:1",
"_rev": 792,
"rights": {
"read": [
"com.palm.media.audio.album:1",
"com.palm.media.image.album:1",
"com.palm.media.audio.artist:1",
"com.palm.media.audio.file:1",
"com.palm.media.audio.genre:1",
"com.palm.media.image.file:1",
"com.palm.media.audio.playlist.object:1",
"com.palm.media.video.file:1"
]
},
"senderId": "com.palmdts.enyo.mediaidxr"
}
]
}
Deleting Device Permissions
You can open a shell on the device using putty or novacom and run the following luna-send command that makes a db8 service call to delete device permissions.
Note: The filenotifyd process is always running and dynamically informs other applications of file system changes.
luna-send -n 1 -a com.palm.filenotifyd.js palm://com.palm.db/del '{"query":{"from":"com.palm.media.permissions:1"}}'
{"returnValue":true,"count":1}