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.

124 lines
5.1KB

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