Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit ee9fda0

Browse files
[[ AndroidPermissionsLCB ]] Added permission checking handlers to android-utils.
The android-utils lcb module has been updated to expose LiveCode's android permission API. Three new handlers have been added to the module that just wrap their equivalent engine functions.
1 parent 8375638 commit ee9fda0

File tree

4 files changed

+172
-7
lines changed

4 files changed

+172
-7
lines changed

engine/src/mblandroiddc.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2859,6 +2859,8 @@ void MCAndroidDisableOpenGLMode(void)
28592859

28602860
static bool s_in_permission_dialog = false;
28612861
static bool s_permission_granted = false;
2862+
2863+
MC_DLLEXPORT_DEF
28622864
bool MCAndroidCheckRuntimePermission(MCStringRef p_permission)
28632865
{
28642866
bool t_result;
@@ -2867,10 +2869,11 @@ bool MCAndroidCheckRuntimePermission(MCStringRef p_permission)
28672869

28682870
while (s_in_permission_dialog)
28692871
MCscreen -> wait(60.0, False, True);
2870-
2872+
28712873
return s_permission_granted;
28722874
}
28732875

2876+
MC_DLLEXPORT_DEF
28742877
bool MCAndroidCheckPermissionExists(MCStringRef p_permission)
28752878
{
28762879
bool t_result;
@@ -2879,6 +2882,7 @@ bool MCAndroidCheckPermissionExists(MCStringRef p_permission)
28792882
return t_result;
28802883
}
28812884

2885+
MC_DLLEXPORT_DEF
28822886
bool MCAndroidHasPermission(MCStringRef p_permission)
28832887
{
28842888
bool t_result;

engine/src/mblandroidutil.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,11 @@ void MCAndroidObjectCall(jobject p_object, const char *p_method, const char *p_s
6363
void MCAndroidObjectRemoteCall(jobject p_object, const char *p_method, const char *p_signature, void *p_return_value, ...);
6464

6565
bool MCAndroidGetBuildInfo(MCStringRef t_key, MCStringRef &r_value);
66+
extern "C" MC_DLLEXPORT
6667
bool MCAndroidCheckRuntimePermission(MCStringRef p_permission);
68+
extern "C" MC_DLLEXPORT
6769
bool MCAndroidCheckPermissionExists(MCStringRef p_permission);
70+
extern "C" MC_DLLEXPORT
6871
bool MCAndroidHasPermission(MCStringRef p_permission);
6972

7073
typedef struct _android_device_configuration

extensions/modules/android-utils/android-utils.lcb

Lines changed: 149 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ metadata os is "android"
3333

3434
private handler ColorComponentToInt(in pComponent as Real) returns Integer
3535
multiply pComponent by 255
36-
round pComponent
36+
round pComponent
3737
return pComponent
3838
end handler
3939

@@ -47,13 +47,13 @@ Parameters:
4747
pString: The color string
4848

4949
Description:
50-
Use the <StringToAndroidColor> handler to convert a string representing
50+
Use the <StringToAndroidColor> handler to convert a string representing
5151
a color to an integer that can be used with Android color APIs.
52-
*/
52+
*/
5353
public handler StringToAndroidColor(in pString as String) returns Integer
5454
variable tColor as Color
5555
put stringToColor(pString) into tColor
56-
56+
5757
variable tA as Integer
5858
variable tR as Integer
5959
variable tG as Integer
@@ -62,7 +62,7 @@ public handler StringToAndroidColor(in pString as String) returns Integer
6262
put ColorComponentToInt(the red of tColor) into tR
6363
put ColorComponentToInt(the green of tColor) into tG
6464
put ColorComponentToInt(the blue of tColor) into tB
65-
65+
6666
return _JNI_GetColorFromARGB(tA,tR,tG,tB)
6767
end handler
6868

@@ -84,9 +84,152 @@ Example:
8484

8585
Description:
8686
Use the <ApplicationContext> handler to fetch the current application's
87-
Context object.
87+
Context object.
8888
*/
8989
public handler ApplicationContext() returns JObject
9090
return _JNI_GetEngineContext(_JNI_GetAndroidEngine())
9191
end handler
92+
93+
private foreign handler MCAndroidCheckRuntimePermission(in pPermission as String) \
94+
returns CBool binds to "<builtin>"
95+
96+
/**
97+
Summary:
98+
Displays a dialog showing a permission request for <pPermission>. If a user
99+
has already granted permission for <pPermission>, this function does nothing.
100+
101+
Returns true if permission <pPermission> has been granted by the user.
102+
103+
Parameters:
104+
pPermission (enum):
105+
The name of the permission to request.
106+
107+
- "android.permission.READ_CALENDAR": permission to allow an application to read the device's calendar.
108+
- "android.permission.WRITE_CALENDAR": permission to allow an application to write to the device's calendar.
109+
- "android.permission.CAMERA": permission to allow an application to access the device's camera.
110+
- "android.permission.ACCESS_COARSE_LOCATION": permission to allow an application to access the device's coarse location.
111+
- "android.permission.ACCESS_FINE_LOCATION": permission to allow an application to access the device's fine location.
112+
- "android.permission.READ_CONTACTS": permission to allow an application to read data from the device's contacts.
113+
- "android.permission.WRITE_CONTACTS": permission to allow an application to write date to the device's contacts.
114+
- "android.permission.GET_ACCOUNTS": permission to allow an application to access to the list of accounts in the Accounts Service.
115+
- "android.permission.RECORD_AUDIO": permission to allow an application to allow an application to record audio.
116+
- "android.permission.READ_EXTERNAL_STORAGE": permission to allow an application to read data from the device's external storage.
117+
- "android.permission.WRITE_EXTERNAL_STORAGE": permission to allow an application to write data to the device's external storage.
118+
- "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.
119+
- "android.permission.READ_PHONE_NUMBERS": permission to allow an application to access the device's phone number(s).
120+
- "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.
121+
- "android.permission.ANSWER_PHONE_CALLS": permission to allow an application to answer an incoming phone call.
122+
- "android.permission.READ_CALL_LOG": permission to allow an application to read the user's call log.
123+
- "android.permission.WRITE_CALL_LOG": permission to allow an application to write to the user's call log.
124+
- "android.permission.ADD_VOICEMAIL": permission to allow an application to add voicemails into the system.
125+
- "android.permission.USE_SIP": permission to allow an application to use SIP service.
126+
- "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.
127+
- "android.permission.SEND_SMS": permission to allow an application to send SMS messages.
128+
- "android.permission.RECEIVE_SMS": permission to allow an application to receive SMS messages
129+
- "android.permission.READ_SMS": permission to allow an application to read SMS messages.
130+
- "android.permission.RECEIVE_WAP_PUSH": permission to allow an application to receive WAP push messages.
131+
- "android.permission.RECEIVE_MMS": permission to allow an application to receive MMS messages.
132+
- "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.
133+
134+
Returns(boolean):
135+
True if permission has been granted, false otherwise.
136+
137+
Description:
138+
Use the <AndroidRequestPermission> command to request permission for
139+
<pPermission> from the user.
140+
141+
>*Note:* Permission names are case sensitive.
142+
*/
143+
public handler AndroidRequestPermission(in pPermission as String) returns Boolean
144+
variable tHasPermission as Boolean
145+
unsafe
146+
MCAndroidCheckRuntimePermission(pPermission)
147+
put MCAndroidHasPermission(pPermission) into tHasPermission
148+
end unsafe
149+
return tHasPermission
150+
end handler
151+
152+
private foreign handler MCAndroidCheckPermissionExists(in pPermission as String) \
153+
returns CBool binds to "<builtin>"
154+
155+
/**
156+
Summary:
157+
Returns true if <pPermission> is a valid Android permission name
158+
159+
Parameters:
160+
pPermission (string):
161+
The name of the permission to check.
162+
163+
Returns(boolean):
164+
True if <pPermission> is a valid Android permission name, false otherwise.
165+
166+
Description:
167+
Use the <AndroidPermissionExists> function to check if <pPermission> is a valid
168+
Android permission name.
169+
170+
>*Note:* Permission names are case sensitive.
171+
*/
172+
public handler AndroidPermissionExists(in pPermission as String) returns Boolean
173+
variable tPermissionExists as Boolean
174+
unsafe
175+
put MCAndroidCheckPermissionExists(pPermission) into tPermissionExists
176+
end unsafe
177+
return tPermissionExists
178+
end handler
179+
180+
private foreign handler MCAndroidHasPermission(in pPermission as String) \
181+
returns CBool binds to "<builtin>"
182+
183+
/**
184+
Summary:
185+
Returns true if permission <pPermission> has been granted by the user.
186+
187+
Parameters:
188+
pPermission (enum):
189+
The name of the permission to request.
190+
191+
- "android.permission.READ_CALENDAR": permission to allow an application to read the device's calendar.
192+
- "android.permission.WRITE_CALENDAR": permission to allow an application to write to the device's calendar.
193+
- "android.permission.CAMERA": permission to allow an application to access the device's camera.
194+
- "android.permission.ACCESS_COARSE_LOCATION": permission to allow an application to access the device's coarse location.
195+
- "android.permission.ACCESS_FINE_LOCATION": permission to allow an application to access the device's fine location.
196+
- "android.permission.READ_CONTACTS": permission to allow an application to read data from the device's contacts.
197+
- "android.permission.WRITE_CONTACTS": permission to allow an application to write date to the device's contacts.
198+
- "android.permission.GET_ACCOUNTS": permission to allow an application to access to the list of accounts in the Accounts Service.
199+
- "android.permission.RECORD_AUDIO": permission to allow an application to allow an application to record audio.
200+
- "android.permission.READ_EXTERNAL_STORAGE": permission to allow an application to read data from the device's external storage.
201+
- "android.permission.WRITE_EXTERNAL_STORAGE": permission to allow an application to write data to the device's external storage.
202+
- "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.
203+
- "android.permission.READ_PHONE_NUMBERS": permission to allow an application to access the device's phone number(s).
204+
- "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.
205+
- "android.permission.ANSWER_PHONE_CALLS": permission to allow an application to answer an incoming phone call.
206+
- "android.permission.READ_CALL_LOG": permission to allow an application to read the user's call log.
207+
- "android.permission.WRITE_CALL_LOG": permission to allow an application to write to the user's call log.
208+
- "android.permission.ADD_VOICEMAIL": permission to allow an application to add voicemails into the system.
209+
- "android.permission.USE_SIP": permission to allow an application to use SIP service.
210+
- "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.
211+
- "android.permission.SEND_SMS": permission to allow an application to send SMS messages.
212+
- "android.permission.RECEIVE_SMS": permission to allow an application to receive SMS messages
213+
- "android.permission.READ_SMS": permission to allow an application to read SMS messages.
214+
- "android.permission.RECEIVE_WAP_PUSH": permission to allow an application to receive WAP push messages.
215+
- "android.permission.RECEIVE_MMS": permission to allow an application to receive MMS messages.
216+
- "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.
217+
218+
Returns(boolean):
219+
True if permission has been granted, false otherwise.
220+
221+
Description:
222+
Use the <AndroidHasPermission> function to find out if permission
223+
<pPermission> has been granted by the user.
224+
225+
>*Note:* Permission names are case sensitive.
226+
*/
227+
public handler AndroidHasPermission(in pPermission as String) returns Boolean
228+
variable tHasPermission as Boolean
229+
unsafe
230+
put MCAndroidHasPermission(pPermission) into tHasPermission
231+
end unsafe
232+
return tHasPermission
233+
end handler
234+
92235
end module
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Android Permission Checking
2+
3+
The ability to check Android permissions in LCB has been added to the android
4+
utility module.
5+
6+
Use these handlers to check and request permissions before accessing resources
7+
(e.g. camera access).
8+
9+
The following handler have been added:
10+
11+
* `AndroidRequestPermission` - Display a dialog requesting a given permission.
12+
* `AndroidPermissionExists` - Check to see if a given permission name is valid.
13+
* `AndroidHasPermission` - Check to see if a given permission has been granted.
14+
15+
See the dictionary for full details.

0 commit comments

Comments
 (0)