Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions docs/dictionary/command/androidRequestPermission.lcdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
Name: androidRequestPermission

Type: command

Syntax: androidRequestPermission <permissionName>

Summary:
Displays a dialog showing a permission request for <permissionName>. If a user has already granted permission for <permissionName>, this command does nothing.

Introduced: 9.0.1

OS: android

Platforms: mobile

Example:
local tCameraPermissionGranted
put androidHasPermission("android.permission.CAMERA") into tCameraPermissionGranted
if not tCameraPermissionGranted then
androidRequestPermission "android.permission.CAMERA"
end if
put androidHasPermission("android.permission.CAMERA") into tCameraPermissionGranted
if not tCameraPermissionGranted then
answer "This app is not permitted to access the device camera. You can change this" && \
"in the Settings app."
end if


Parameters:
permissionName (enum):
The name of the permission to request.

- "android.permission.READ_CALENDAR": permission to allow an application to read the device's calendar.
- "android.permission.WRITE_CALENDAR": permission to allow an application to write to the device's calendar.
- "android.permission.CAMERA": permission to allow an application to access the device's camera.
- "android.permission.ACCESS_COARSE_LOCATION": permission to allow an application to access the device's coarse location.
- "android.permission.ACCESS_FINE_LOCATION": permission to allow an application to access the device's fine location.
- "android.permission.READ_CONTACTS": permission to allow an application to read data from the device's contacts.
- "android.permission.WRITE_CONTACTS": permission to allow an application to write date to the device's contacts.
- "android.permission.GET_ACCOUNTS": permission to allow an application to access to the list of accounts in the Accounts Service.
- "android.permission.RECORD_AUDIO": permission to allow an application to allow an application to record audio.
- "android.permission.READ_EXTERNAL_STORAGE": permission to allow an application to read data from the device's external storage.
- "android.permission.WRITE_EXTERNAL_STORAGE": permission to allow an application to write data to the device's external storage.
- "android.permission.READ_PHONE_STATE": permission to allow an application to access phone state, including the phone number of the device, current cellular network information, the status of any ongoing calls, and a list of any PhoneAccounts registered on the device.
- "android.permission.READ_PHONE_NUMBERS": permission to allow an application to access the device's phone number(s).
- "android.permission.CALL_PHONE": permission to allow an application to initiate a phone call without going through the Dialer user interface for the user to confirm the call.
- "android.permission.ANSWER_PHONE_CALLS": permission to allow an application to answer an incoming phone call.
- "android.permission.READ_CALL_LOG": permission to allow an application to read the user's call log.
- "android.permission.WRITE_CALL_LOG": permission to allow an application to write to the user's call log.
- "android.permission.ADD_VOICEMAIL": permission to allow an application to add voicemails into the system.
- "android.permission.USE_SIP": permission to allow an application to use SIP service.
- "android.permission.PROCESS_OUTGOING_CALLS": permission to allow an application to see the number being dialed during an outgoing call with the option to redirect the call to a different number or abort the call altogether.
- "android.permission.SEND_SMS": permission to allow an application to send SMS messages.
- "android.permission.RECEIVE_SMS": permission to allow an application to receive SMS messages
- "android.permission.READ_SMS": permission to allow an application to read SMS messages.
- "android.permission.RECEIVE_WAP_PUSH": permission to allow an application to receive WAP push messages.
- "android.permission.RECEIVE_MMS": permission to allow an application to receive MMS messages.
- "android.permission.BODY_SENSORS": permission to allow an application to access data from sensors that the user uses to measure what is happening inside his/her body, such as heart rate.



Description:
Use the <androidRequestPermission> command to request permission for <permissionName> from the user.

>*Note:* Permission names are case sensitive.
66 changes: 66 additions & 0 deletions docs/dictionary/function/androidHasPermission.lcdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
Name: androidHasPermission

Type: function

Syntax: androidHasPermission(<permissionName>)

Summary:
Returns if permission <permissionName> has been granted by the user.

Introduced: 9.0.1

OS: android

Platforms: mobile

Example:
local tLocationPermissionGranted
put androidHasPermission("android.permission.ACCESS_FINE_LOCATION") into tLocationPermissionGranted
if not tLocationPermissionGranted then
androidRequestPermission "android.permission.ACCESS_FINE_LOCATION"
end if
if not tLocationPermissionGranted then
answer "This app is not permitted to access the device location. You can change this" && \
"in the Settings app."
end if


Parameters:
permissionName (enum):
The name of the permission to request.

- "android.permission.READ_CALENDAR": permission to allow an application to read the device's calendar.
- "android.permission.WRITE_CALENDAR": permission to allow an application to write to the device's calendar.
- "android.permission.CAMERA": permission to allow an application to access the device's camera.
- "android.permission.ACCESS_COARSE_LOCATION": permission to allow an application to access the device's coarse location.
- "android.permission.ACCESS_FINE_LOCATION": permission to allow an application to access the device's fine location.
- "android.permission.READ_CONTACTS": permission to allow an application to read data from the device's contacts.
- "android.permission.WRITE_CONTACTS": permission to allow an application to write date to the device's contacts.
- "android.permission.GET_ACCOUNTS": permission to allow an application to access to the list of accounts in the Accounts Service.
- "android.permission.RECORD_AUDIO": permission to allow an application to allow an application to record audio.
- "android.permission.READ_EXTERNAL_STORAGE": permission to allow an application to read data from the device's external storage.
- "android.permission.WRITE_EXTERNAL_STORAGE": permission to allow an application to write data to the device's external storage.
- "android.permission.READ_PHONE_STATE": permission to allow an application to access phone state, including the phone number of the device, current cellular network information, the status of any ongoing calls, and a list of any PhoneAccounts registered on the device.
- "android.permission.READ_PHONE_NUMBERS": permission to allow an application to access the device's phone number(s).
- "android.permission.CALL_PHONE": permission to allow an application to initiate a phone call without going through the Dialer user interface for the user to confirm the call.
- "android.permission.ANSWER_PHONE_CALLS": permission to allow an application to answer an incoming phone call.
- "android.permission.READ_CALL_LOG": permission to allow an application to read the user's call log.
- "android.permission.WRITE_CALL_LOG": permission to allow an application to write to the user's call log.
- "android.permission.ADD_VOICEMAIL": permission to allow an application to add voicemails into the system.
- "android.permission.USE_SIP": permission to allow an application to use SIP service.
- "android.permission.PROCESS_OUTGOING_CALLS": permission to allow an application to see the number being dialed during an outgoing call with the option to redirect the call to a different number or abort the call altogether.
- "android.permission.SEND_SMS": permission to allow an application to send SMS messages.
- "android.permission.RECEIVE_SMS": permission to allow an application to receive SMS messages
- "android.permission.READ_SMS": permission to allow an application to read SMS messages.
- "android.permission.RECEIVE_WAP_PUSH": permission to allow an application to receive WAP push messages.
- "android.permission.RECEIVE_MMS": permission to allow an application to receive MMS messages.
- "android.permission.BODY_SENSORS": permission to allow an application to access data from sensors that the user uses to measure what is happening inside his/her body, such as heart rate.

Returns(boolean):
True if permission has been granted, false otherwise.


Description:
Use the <androidRequestPermission> function to find out if permission <permissionName> has been granted by the user.

>*Note:* Permission names are case sensitive.
33 changes: 33 additions & 0 deletions docs/dictionary/function/androidPermissionExists.lcdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Name: androidPermissionExists

Type: function

Syntax: androidPermissionExists(<permissionName>)

Summary:
Returns true if <permissionName> is a valid Android permission name

Introduced: 9.0.1

OS: android

Platforms: mobile

Example:

if not androidPermissionExists(pPermission) then
answer pPermission && "is not a valid permission name"
end if


Parameters:
permissionName (string):
The name of the permission to check.

Returns(boolean):
True if <permissionName> is a valid Android permission name, false otherwise.

Description:
Use the <androidPermissionExists> function to check if <permissionName> is a valid Android permission name.

>*Note:* Permission names are case sensitive.
26 changes: 26 additions & 0 deletions docs/notes/feature-android_runtime_permissions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Android 6.0 runtime permissions

Android 6.0 (API 23) Marshmallow introduced a new permissions model
that lets apps request permissions from the user at runtime, rather
than prior to installation. Apps built with LC 9.0.1 do support this
new permissions model, and request permissions automatically when the
app actually requires the services or data protected by the services.

For example, if the app calls `mobilePickPhoto "camera"`, a dialog will
be shown to the user asking for permission to access the device camera.

If the user does not grant permission, the call will fail. Moreover, the
app can use the function `androidRequestPermission(permissionName)` to
check if the permission for `permissionName` has been granted.

Notes:

- You have to make sure that you check the required permissions for your
app in the standalone settings.
- Apps that run on devices running Android 6+ will work with the new
permissions model.
- Apps that run on older devices (less than Android 6) will continue to
work with the old permissions model.
- If the user does not grant a permission when the dialog appears for the
first time, they can change this preference from the Settings app.

25 changes: 25 additions & 0 deletions engine/src/exec-misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,31 @@ void MCMiscGetDoNotBackupFile(MCExecContext& ctxt, MCStringRef p_path, bool& r_n
ctxt.Throw();
}

void MCMiscExecRequestPermission(MCExecContext& ctxt, MCStringRef p_permission, bool& r_granted)
{
if (MCSystemRequestPermission(p_permission, r_granted))
return;

ctxt.Throw();
}

void MCMiscExecPermissionExists(MCExecContext& ctxt, MCStringRef p_permission, bool& r_exists)
{
if (MCSystemPermissionExists(p_permission, r_exists))
return;

ctxt.Throw();
}

void MCMiscExecHasPermission(MCExecContext& ctxt, MCStringRef p_permission, bool& r_permission_granted)
{
if (MCSystemHasPermission(p_permission, r_permission_granted))
return;

ctxt.Throw();
}


void MCMiscSetDoNotBackupFile(MCExecContext& ctxt, MCStringRef p_path, bool p_no_backup)
{
if (MCSystemFileSetDoNotBackup(p_path, p_no_backup))
Expand Down
3 changes: 3 additions & 0 deletions engine/src/exec.h
Original file line number Diff line number Diff line change
Expand Up @@ -4043,6 +4043,9 @@ void MCMiscExecLibUrlDownloadToFile(MCExecContext& ctxt, MCStringRef p_url, MCSt
void MCMiscExecLibUrlSetSSLVerification(MCExecContext& ctxt, bool p_enabled);

void MCMiscGetBuildInfo(MCExecContext& ctxt, MCStringRef p_key, MCStringRef& r_value);
void MCMiscExecRequestPermission(MCExecContext& ctxt, MCStringRef p_permission, bool& r_granted);
void MCMiscExecPermissionExists(MCExecContext& ctxt, MCStringRef p_permission, bool& r_exists);
void MCMiscExecHasPermission(MCExecContext& ctxt, MCStringRef p_permission, bool& r_permission_granted);

void MCMiscExecEnableRemoteControl(MCExecContext& ctxt);
void MCMiscExecDisableRemoteControl(MCExecContext& ctxt);
Expand Down
3 changes: 3 additions & 0 deletions engine/src/executionerrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -2774,6 +2774,9 @@ enum Exec_errors
// {EE-0908} fontLanguage: bad font name
EE_FONTLANGUAGE_BADFONTNAME,

// {EE-0909} android permission: bad permission name
EE_BAD_PERMISSION_NAME,

};

extern const char *MCexecutionerrors;
Expand Down
Loading