Since: 2.4
typedef DOMString RawData;
enum PermissionType{ "NONE", "READ", "REMOVE", "READ_REMOVE" };
[NoInterfaceObject] interface KeyManagerObject { readonly attribute KeyManager keymanager; };
Tizen implements KeyManagerObject;
The tizen.keymanager object allows access to the functionality of the KeyManager API.
[NoInterfaceObject] interface KeyManager { void saveData(DOMString name, RawData rawData, optional DOMString? password, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises (WebAPIException); void removeData(KeyManagerAlias dataAlias) raises (WebAPIException); RawData getData(KeyManagerAlias dataAlias, optional DOMString? password) raises (WebAPIException); KeyManagerAlias[] getDataAliasList() raises (WebAPIException); void setPermission(KeyManagerAlias dataAlias, PackageId packageId, PermissionType permissionType, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises (WebAPIException); };
saveData
void saveData(DOMString name, RawData rawData, optional DOMString? password, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
On success, this method will add a KeyManagerAlias into the KeyManager. The name attribute of that KeyManagerAlias will be set to be the value of the name parameter which is used in this method call. The packageId attribute of that KeyManagerAlias will automatically be set to be the package ID of the application which calls this method.
The ErrorCallback is launched with these error types:
Warning: http://tizen.org/privilege/keymanager (public level privilege) MUST NOT be declared to use this API since 3.0.
Parameters:
Exceptions:
with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter.
Code example:
var data_name = "data1", raw_data = "my data"; function onSave() { console.log("Successfully saved data"); } tizen.keymanager.saveData(data_name, raw_data, null, onSave);
removeData
void removeData(KeyManagerAlias dataAlias);
To remove data, an application must have permission to remove that data. By default, an application which saved data into the KeyManager has permission to remove the data. An application can also use the setPermission method to allow another application to remove its data.
If an application calls this method to remove data which it saved into the KeyManager, the dataAlias parameter does not require the packageId attribute.
with error type NotFoundError, if the dataAlias cannot be found.
with error type UnknownError, if the method cannot be completed because of an unknown error
var data_name = "data1", raw_data = "my data"; function onSave() { // do something // Dictionary does not require package ID because the // application which is calling removeData() saved "data1" tizen.keymanager.removeData({ "name": data_name }); } tizen.keymanager.saveData(data_name, raw_data, null, onSave);
var aliases = tizen.keymanager.getDataAliasList(); if (aliases.length != 0) { // Assuming the application calling removeData() has permission // to remove aliases[0] var app_data = tizen.keymanager.removeData(aliases[0]); }
getData
RawData getData(KeyManagerAlias dataAlias, optional DOMString? password);
To get raw data, an application must have permission to get that raw data. By default, an application which saved raw data into the KeyManager has permission to get that raw data. An application can also use the setPermission method to allow another application to get and read its raw data.
If an application calls this method to retrieve raw data which it saved into the KeyManager, the dataAlias parameter does not require the packageId attribute.
Return value:
with error type VerificationError, if the method cannot be completed because an incorrect password is used.
with error type UnknownError, if the method cannot be completed because of a database access failure or any other unknown error.
var data_name = "data1", raw_data = "my data"; function onSave() { // Dictionary does not require package ID because the // application which is calling getData() saved "data1" var app_data = tizen.keymanager.getData({ "name": data_name }); console.log("App data: " + app_data + " was retrieved"); } tizen.keymanager.saveData(data_name, raw_data, null, onSave);
var aliases = tizen.keymanager.getDataAliasList(); if (aliases.length != 0) { // Assuming the application calling getData() has permission to read // aliases[0] var app_data = tizen.keymanager.getData(aliases[0]); console.log("App data: " + app_data + " was retrieved"); }
getDataAliasList
KeyManagerAlias[] getDataAliasList();
with error type UnknownError, if the method cannot be completed because of an unknown error.
var aliases = tizen.keymanager.getDataAliasList(); console.log("aliases: "); for (var i = 0; i < aliases.length; i++) { console.log("Package ID: " + aliases[i].packageId + ", Name: " + aliases[i].name); }
setPermission
void setPermission(KeyManagerAlias dataAlias, PackageId packageId, PermissionType permissionType, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
An application can only set permissions for data which it saved into the KeyManager. Therefore, the dataAlias parameter does not require the packageId attribute.
var data_name = "data1", raw_data = "my data"; function onPermissionSet() { console.log("Successfully set permssion"); } function onSave() { // Dictionary does not require package ID because an // application can only set permission for data which it saved tizen.keymanager.setPermission({ "name": data_name }, "9PdoiICQ4c", "READ_REMOVE", onPermissionSet); } tizen.keymanager.saveData(data_name, raw_data, null, onSave);
var aliases = tizen.keymanager.getDataAliasList(); function onPermissionSet() { console.log("Successfully set permssion"); } if (aliases.length != 0) { // Check that the application calling setPermission() saved aliases[0] into // the KeyManager if (aliases[0].packageId === tizen.package.getPackageInfo().id) { tizen.keymanager.setPermission(aliases[0], "9PdoiICQ4c", "READ_REMOVE", onPermissionSet); } else { console.log("This application did not save aliases[0] into the KeyManager"); } }
dictionary KeyManagerAlias { PackageId packageId; DOMString name; };
If this attribute contains any spaces, the spaces will be removed. Characters which are separated by spaces will be concatenated.
module KeyManager { typedef DOMString RawData; enum PermissionType{ "NONE", "READ", "REMOVE", "READ_REMOVE" }; [NoInterfaceObject] interface KeyManagerObject { readonly attribute KeyManager keymanager; }; Tizen implements KeyManagerObject; [NoInterfaceObject] interface KeyManager { void saveData(DOMString name, RawData rawData, optional DOMString? password, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises (WebAPIException); void removeData(KeyManagerAlias dataAlias) raises (WebAPIException); RawData getData(KeyManagerAlias dataAlias, optional DOMString? password) raises (WebAPIException); KeyManagerAlias[] getDataAliasList() raises (WebAPIException); void setPermission(KeyManagerAlias dataAlias, PackageId packageId, PermissionType permissionType, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises (WebAPIException); }; dictionary KeyManagerAlias { PackageId packageId; DOMString name; }; };