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.

130 lines
5.5KB

  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. #pragma once
  24. //==============================================================================
  25. /**
  26. Class to handle app runtime permissions for certain functionality on some platforms.
  27. The use of this class is currently only required if the app should run on
  28. Android API level 23 and higher.
  29. On lower API levels, the permissions are specified in the app manifest. On iOS,
  30. runtime permission requests are handled automatically by the Apple APIs and not
  31. manually in the app code. On Windows, OS X, and Linux, runtime permissions are not
  32. used at all. In all these cases, request() will simply call through to the
  33. callback with no overhead and pass true (making it safe to use on all platforms).
  34. For example, to enable audio recording on Android in your cross-platform app,
  35. you could modify your code as follows:
  36. Old code:
  37. audioDeviceManager.initialise (2, 2, nullptr, true, String(), nullptr);
  38. New code:
  39. RuntimePermissions::request (
  40. RuntimePermissions::audioRecording,
  41. [this] (bool wasGranted)
  42. {
  43. if (! wasGranted)
  44. {
  45. // e.g. display an error or initialise with 0 input channels
  46. return;
  47. }
  48. audioDeviceManager.initialise (2, 2, nullptr, true, String(), nullptr);
  49. }
  50. );
  51. */
  52. class JUCE_API RuntimePermissions
  53. {
  54. public:
  55. //==============================================================================
  56. enum PermissionID
  57. {
  58. /** Permission to access the microphone (required on Android).
  59. You need to request this, for example, to initialise an AudioDeviceManager with
  60. a non-zero number of input channels, and to open the default audio input device.
  61. */
  62. recordAudio = 1,
  63. /** Permission to scan for and pair to Bluetooth MIDI devices (required on Android).
  64. You need to request this before calling BluetoothMidiDevicePairingDialogue::open(),
  65. otherwise no devices will be found.
  66. */
  67. bluetoothMidi = 2,
  68. };
  69. //==============================================================================
  70. /** Function type of runtime permission request callbacks. */
  71. #if JUCE_COMPILER_SUPPORTS_LAMBDAS
  72. typedef std::function<void (bool)> Callback;
  73. #else
  74. typedef void (*Callback) (bool);
  75. #endif
  76. //==============================================================================
  77. /** Call this method to request a runtime permission.
  78. @param permission The PermissionID of the permission you want to request.
  79. @param callback The callback to be called after the request has been granted
  80. or denied; the argument passed will be true if the permission
  81. has been granted and false otherwise.
  82. If no runtime request is required or possible to obtain the permission, the
  83. callback will be called immediately. The argument passed in will be true
  84. if the permission is granted or no permission is required on this platform,
  85. and false otherwise.
  86. If a runtime request is required to obtain the permission, the callback
  87. will be called asynchronously after the OS has granted or denied the requested
  88. permission (typically by displaying a dialog box to the user and waiting until
  89. the user has responded).
  90. */
  91. static void request (PermissionID permission, Callback callback);
  92. /** Returns whether a runtime request is required to obtain the permission
  93. on the current platform.
  94. */
  95. static bool isRequired (PermissionID permission);
  96. /** Returns true if the app has been already granted this permission, either
  97. via a previous runtime request or otherwise, or no permission is necessary.
  98. Note that this can be false even if isRequired returns false. In this case,
  99. the permission can not be obtained at all at runtime.
  100. */
  101. static bool isGranted (PermissionID permission);
  102. };