OpenShot Library | OpenShotAudio  0.2.2
juce_RuntimePermissions.h
1 
2 /** @weakgroup juce_core-misc
3  * @{
4  */
5 /*
6  ==============================================================================
7 
8  This file is part of the JUCE library.
9  Copyright (c) 2017 - ROLI Ltd.
10 
11  JUCE is an open source library subject to commercial or open-source
12  licensing.
13 
14  The code included in this file is provided under the terms of the ISC license
15  http://www.isc.org/downloads/software-support-policy/isc-license. Permission
16  To use, copy, modify, and/or distribute this software for any purpose with or
17  without fee is hereby granted provided that the above copyright notice and
18  this permission notice appear in all copies.
19 
20  JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21  EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22  DISCLAIMED.
23 
24  ==============================================================================
25 */
26 
27 namespace juce
28 {
29 
30 //==============================================================================
31 /**
32  Class to handle app runtime permissions for certain functionality on some platforms.
33 
34  The use of this class is currently only required if the app should run on
35  Android API level 23 and higher.
36 
37  On lower API levels, the permissions are specified in the app manifest. On iOS,
38  runtime permission requests are handled automatically by the Apple APIs and not
39  manually in the app code. On Windows, OS X, and Linux, runtime permissions are not
40  used at all. In all these cases, request() will simply call through to the
41  callback with no overhead and pass true (making it safe to use on all platforms).
42 
43  For example, to enable audio recording on Android in your cross-platform app,
44  you could modify your code as follows:
45 
46  Old code:
47 
48  audioDeviceManager.initialise (2, 2, nullptr, true, String(), nullptr);
49 
50  New code:
51 
52  RuntimePermissions::request (
53  RuntimePermissions::audioRecording,
54  [this] (bool wasGranted)
55  {
56  if (! wasGranted)
57  {
58  // e.g. display an error or initialise with 0 input channels
59  return;
60  }
61 
62  audioDeviceManager.initialise (2, 2, nullptr, true, String(), nullptr);
63  }
64  );
65 
66  @tags{Core}
67 */
69 {
70 public:
71  //==============================================================================
73  {
74  /** Permission to access the microphone (required on Android).
75  You need to request this, for example, to initialise an AudioDeviceManager with
76  a non-zero number of input channels, and to open the default audio input device.
77  */
78  recordAudio = 1,
79 
80  /** Permission to scan for and pair to Bluetooth MIDI devices (required on Android).
81  You need to request this before calling BluetoothMidiDevicePairingDialogue::open(),
82  otherwise no devices will be found.
83  */
84  bluetoothMidi = 2,
85 
86  /** Permission to read from external storage such as SD cards */
87  readExternalStorage = 3,
88 
89  /** Permission to write to external storage such as SD cards */
90  writeExternalStorage = 4,
91 
92  /** Permission to use camera */
93  camera = 5
94  };
95 
96  //==============================================================================
97  /** Function type of runtime permission request callbacks. */
98  using Callback = std::function<void(bool)>;
99 
100  //==============================================================================
101  /** Call this method to request a runtime permission.
102 
103  @param permission The PermissionID of the permission you want to request.
104 
105  @param callback The callback to be called after the request has been granted
106  or denied; the argument passed will be true if the permission
107  has been granted and false otherwise.
108 
109  If no runtime request is required or possible to obtain the permission, the
110  callback will be called immediately. The argument passed in will be true
111  if the permission is granted or no permission is required on this platform,
112  and false otherwise.
113 
114  If a runtime request is required to obtain the permission, the callback
115  will be called asynchronously after the OS has granted or denied the requested
116  permission (typically by displaying a dialog box to the user and waiting until
117  the user has responded).
118  */
119  static void request (PermissionID permission, Callback callback);
120 
121  /** Returns whether a runtime request is required to obtain the permission
122  on the current platform.
123  */
124  static bool isRequired (PermissionID permission);
125 
126  /** Returns true if the app has been already granted this permission, either
127  via a previous runtime request or otherwise, or no permission is necessary.
128 
129  Note that this can be false even if isRequired returns false. In this case,
130  the permission can not be obtained at all at runtime.
131  */
132  static bool isGranted (PermissionID permission);
133 };
134 
135 } // namespace juce
136 
137 /** @}*/
#define JUCE_API
This macro is added to all JUCE public class declarations.
Class to handle app runtime permissions for certain functionality on some platforms.
std::function< void(bool)> Callback
Function type of runtime permission request callbacks.