Websites Navigation: Airbit | Shop | m-shell.net
Languages: EN | DE

User Permissions

Since m allows many harmful or costly operations to happen automatically, the user can grant or deny permission for certain operations, for instance to write some files or to dial the phone.

Of course, from within a native module, you have almost complete control over the device, as you can ignore the permissions denied by the user if you want[4]. However, it is a good idea to conform to m standards, particularly if you think of writing your module for a broader audience.

Permissions are checked anywhere within ExecuteL() by two functions from class Runtime:

  • void CheckPermissionsL(TInt access);
    Checks whether the user granted all permissions in the bit mask access and leaves with ExcNotPermitted if any of the permissions has been denied. The permission bits are defined in UserPermissions.h, which is always included if you include NativeModule.h.
  • const TDesC &RealPathL(const TDesC &path, TInt accessMode);
    Gets the real absolute path of a relative path or file, and checks for user permissions to access it, leaving if the necessary permissions have been denied. This handles ".", "..", the current directory and missing drives. The path returned need not be valid. The bit mask accessMode determines the permissions checked: it can be ReadAccess, WriteAccess or both.

Alarm Server Example, Continued

In our alarm module, all functions read application data, so we check for ReadApp right at the beginning:

Runtime::Value ExecuteL(TInt index, Runtime::Value *params,
                        TInt paramCount, TRequestStatus &status)
{
  // all functions in this module require permission to read
  // application data, we should check for it
  runtime->CheckPermissionL(ReadAppPermission);
  // if the session is not connected, connect it
  ...

Furthermore, alarm.add, alarm.delete and alarm.on may write application data, so these functions should check for WriteApp:

switch (index) {
case AddFunction:
  runtime->CheckPermissionL(WriteAppPermission);
  ...
case DeleteFunction:
  runtime->CheckPermissionL(WriteAppPermission);
  ...
case OnFunction:
  runtime->CheckPermissionL(WriteAppPermission);


© 2004-2011 airbit AG, CH-8008 Zürich
Document AB-M-NMI-887
mShell Home  > Documentation  > Manuals