The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 lines
5.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2016 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of the ISC license
  6. http://www.isc.org/downloads/software-support-policy/isc-license/
  7. Permission to use, copy, modify, and/or distribute this software for any
  8. purpose with or without fee is hereby granted, provided that the above
  9. copyright notice and this permission notice appear in all copies.
  10. THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
  11. TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  12. FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
  13. OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  14. USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  16. OF THIS SOFTWARE.
  17. -----------------------------------------------------------------------------
  18. To release a closed-source product which uses other parts of JUCE not
  19. licensed under the ISC terms, commercial licenses are available: visit
  20. www.juce.com for more information.
  21. ==============================================================================
  22. */
  23. #ifndef JUCE_RUNTIMEPERMISSIONS_H_INCLUDED
  24. #define JUCE_RUNTIMEPERMISSIONS_H_INCLUDED
  25. //==============================================================================
  26. /**
  27. Class to handle app runtime permissions for certain functionality on some platforms.
  28. The use of this class is currently only required if the app should run on
  29. Android API level 23 and higher.
  30. On lower API levels, the permissions are specified in the app manifest. On iOS,
  31. runtime permission requests are handled automatically by the Apple APIs and not
  32. manually in the app code. On Windows, OS X, and Linux, runtime permissions are not
  33. used at all. In all these cases, request() will simply call through to the
  34. callback with no overhead and pass true (making it safe to use on all platforms).
  35. For example, to enable audio recording on Android in your cross-platform app,
  36. you could modify your code as follows:
  37. Old code:
  38. audioDeviceManager.initialise (2, 2, nullptr, true, String(), nullptr);
  39. New code:
  40. RuntimePermissions::request (
  41. RuntimePermissions::audioRecording,
  42. [this] (bool wasGranted)
  43. {
  44. if (! wasGranted)
  45. {
  46. // e.g. display an error or initialise with 0 input channels
  47. return;
  48. }
  49. audioDeviceManager.initialise (2, 2, nullptr, true, String(), nullptr);
  50. }
  51. );
  52. */
  53. class JUCE_API RuntimePermissions
  54. {
  55. public:
  56. //==============================================================================
  57. enum PermissionID
  58. {
  59. /** Permission to access the microphone (required on Android).
  60. You need to request this, for example, to initialise an AudioDeviceManager with
  61. a non-zero number of input channels, and to open the default audio input device.
  62. */
  63. recordAudio = 1,
  64. /** Permission to scan for and pair to Bluetooth MIDI devices (required on Android).
  65. You need to request this before calling BluetoothMidiDevicePairingDialogue::open(),
  66. otherwise no devices will be found.
  67. */
  68. bluetoothMidi = 2,
  69. };
  70. //==============================================================================
  71. /** Function type of runtime permission request callbacks. */
  72. #if JUCE_COMPILER_SUPPORTS_LAMBDAS
  73. typedef std::function<void (bool)> Callback;
  74. #else
  75. typedef void (*Callback) (bool);
  76. #endif
  77. //==============================================================================
  78. /** Call this method to request a runtime permission.
  79. @param permission The PermissionID of the permission you want to request.
  80. @param callback The callback to be called after the request has been granted
  81. or denied; the argument passed will be true if the permission
  82. has been granted and false otherwise.
  83. If no runtime request is required or possible to obtain the permission, the
  84. callback will be called immediately. The argument passed in will be true
  85. if the permission is granted or no permission is required on this platform,
  86. and false otherwise.
  87. If a runtime request is required to obtain the permission, the callback
  88. will be called asynchronously after the OS has granted or denied the requested
  89. permission (typically by displaying a dialog box to the user and waiting until
  90. the user has responded).
  91. */
  92. static void request (PermissionID permission, Callback callback);
  93. /** Returns whether a runtime request is required to obtain the permission
  94. on the current platform.
  95. */
  96. static bool isRequired (PermissionID permission);
  97. /** Returns true if the app has been already granted this permission, either
  98. via a previous runtime request or otherwise, or no permission is necessary.
  99. Note that this can be false even if isRequired returns false. In this case,
  100. the permission can not be obtained at all at runtime.
  101. */
  102. static bool isGranted (PermissionID permission);
  103. };
  104. #endif // JUCE_RUNTIMEPERMISSIONS_H_INCLUDED