1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Platform: Remove compatibility checks for Android 20 and earlier

This commit is contained in:
reuk 2024-07-01 18:49:16 +01:00
parent 483429f432
commit 8ba2dc2ae2
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C
12 changed files with 167 additions and 321 deletions

View file

@ -84,10 +84,8 @@ namespace juce::AndroidHighPerformanceAudioHelpers
if (canUseHighPerformanceAudioPath (nativeBufferSize, nativeBufferSize, (int) requestedSampleRate)) if (canUseHighPerformanceAudioPath (nativeBufferSize, nativeBufferSize, (int) requestedSampleRate))
{ {
// see https://developer.android.com/ndk/guides/audio/opensl/opensl-prog-notes.html#sandp // see https://developer.android.com/ndk/guides/audio/opensl/opensl-prog-notes.html#sandp
// "For Android 4.2 (API level 17) and earlier, a buffer count of two or more is required // > Beginning with Android 4.3 (API level 18), a buffer count of one is sufficient for lower latency.
// for lower latency. Beginning with Android 4.3 (API level 18), a buffer count of one return 1;
// is sufficient for lower latency."
return (getAndroidSDKVersion() >= 18 ? 1 : 2);
} }
// not using low-latency path so we can use the absolute minimum number of buffers to queue // not using low-latency path so we can use the absolute minimum number of buffers to queue

View file

@ -398,7 +398,7 @@ private:
oboe::Direction::Output, oboe::Direction::Output,
oboe::SharingMode::Exclusive, oboe::SharingMode::Exclusive,
2, 2,
getAndroidSDKVersion() >= 21 ? oboe::AudioFormat::Float : oboe::AudioFormat::I16, oboe::AudioFormat::Float,
(int) AndroidHighPerformanceAudioHelpers::getNativeSampleRate(), (int) AndroidHighPerformanceAudioHelpers::getNativeSampleRate(),
bufferSizeHint, bufferSizeHint,
&callback); &callback);
@ -1023,19 +1023,18 @@ OboeAudioIODevice::OboeSessionBase* OboeAudioIODevice::OboeSessionBase::create (
int bufferSize) int bufferSize)
{ {
std::unique_ptr<OboeSessionBase> session;
auto sdkVersion = getAndroidSDKVersion();
// SDK versions 21 and higher should natively support floating point... // SDK versions 21 and higher should natively support floating point...
if (sdkVersion >= 21) std::unique_ptr<OboeSessionBase> session = std::make_unique<OboeSessionImpl<float>> (owner,
{ inputDeviceId,
session.reset (new OboeSessionImpl<float> (owner, inputDeviceId, outputDeviceId, outputDeviceId,
numInputChannels, numOutputChannels, sampleRate, bufferSize)); numInputChannels,
numOutputChannels,
sampleRate,
bufferSize);
// ...however, some devices lie so re-try without floating point // ...however, some devices lie so re-try without floating point
if (session != nullptr && (! session->openedOk())) if (session != nullptr && (! session->openedOk()))
session.reset(); session.reset();
}
if (session == nullptr) if (session == nullptr)
{ {

View file

@ -218,9 +218,6 @@ struct AndroidDocumentDetail
static void setPermissions (const URL& url, jmethodID func) static void setPermissions (const URL& url, jmethodID func)
{ {
if (getAndroidSDKVersion() < 19)
return;
const auto javaUri = urlToUri (url); const auto javaUri = urlToUri (url);
if (const auto resolver = AndroidContentUriResolver::getContentResolver()) if (const auto resolver = AndroidContentUriResolver::getContentResolver())
@ -402,19 +399,18 @@ struct AndroidDocument::Utils
AndroidMimeTypeMap.getSingleton) } }; AndroidMimeTypeMap.getSingleton) } };
}; };
class AndroidDocumentPimplApi19 : public Pimpl //==============================================================================
class AndroidDocumentPimplApi21 : public Pimpl
{ {
public: public:
AndroidDocumentPimplApi19() = default; AndroidDocumentPimplApi21() = default;
explicit AndroidDocumentPimplApi19 (const URL& uriIn) explicit AndroidDocumentPimplApi21 (const URL& uriIn)
: AndroidDocumentPimplApi19 (urlToUri (uriIn)) {} : AndroidDocumentPimplApi21 (urlToUri (uriIn)) {}
explicit AndroidDocumentPimplApi19 (const LocalRef<jobject>& uriIn) explicit AndroidDocumentPimplApi21 (const LocalRef<jobject>& uriIn)
: uri (uriIn) {} : uri (uriIn) {}
std::unique_ptr<Pimpl> clone() const override { return std::make_unique<AndroidDocumentPimplApi19> (*this); }
bool deleteDocument() const override bool deleteDocument() const override
{ {
if (const auto resolver = AndroidContentUriResolver::getContentResolver()) if (const auto resolver = AndroidContentUriResolver::getContentResolver())
@ -523,16 +519,6 @@ struct AndroidDocument::Utils
NativeInfo getNativeInfo() const override { return { uri }; } NativeInfo getNativeInfo() const override { return { uri }; }
private:
GlobalRef uri;
};
//==============================================================================
class AndroidDocumentPimplApi21 : public AndroidDocumentPimplApi19
{
public:
using AndroidDocumentPimplApi19::AndroidDocumentPimplApi19;
std::unique_ptr<Pimpl> clone() const override { return std::make_unique<AndroidDocumentPimplApi21> (*this); } std::unique_ptr<Pimpl> clone() const override { return std::make_unique<AndroidDocumentPimplApi21> (*this); }
std::unique_ptr<Pimpl> createChildDocumentWithTypeAndName (const String& type, const String& name) const override std::unique_ptr<Pimpl> createChildDocumentWithTypeAndName (const String& type, const String& name) const override
@ -558,6 +544,9 @@ struct AndroidDocument::Utils
return nullptr; return nullptr;
} }
private:
GlobalRef uri;
}; };
//============================================================================== //==============================================================================
@ -607,8 +596,7 @@ struct AndroidDocument::Utils
return createPimplForSdkImpl (uri, return createPimplForSdkImpl (uri,
VersionTag<AndroidDocumentPimplApi24> { 24 }, VersionTag<AndroidDocumentPimplApi24> { 24 },
VersionTag<AndroidDocumentPimplApi21> { 21 }, VersionTag<AndroidDocumentPimplApi21> { 21 });
VersionTag<AndroidDocumentPimplApi19> { 19 });
} }
static std::unique_ptr<Pimpl> createPimplForSdkImpl (const LocalRef<jobject>&) static std::unique_ptr<Pimpl> createPimplForSdkImpl (const LocalRef<jobject>&)
@ -777,9 +765,6 @@ std::vector<AndroidDocumentPermission> AndroidDocumentPermission::getPersistedPe
#if ! JUCE_ANDROID #if ! JUCE_ANDROID
return {}; return {};
#else #else
if (getAndroidSDKVersion() < 19)
return {};
auto* env = getEnv(); auto* env = getEnv();
const LocalRef<jobject> permissions { env->CallObjectMethod (AndroidContentUriResolver::getContentResolver().get(), const LocalRef<jobject> permissions { env->CallObjectMethod (AndroidContentUriResolver::getContentResolver().get(),
ContentResolver19.getPersistedUriPermissions) }; ContentResolver19.getPersistedUriPermissions) };
@ -829,13 +814,6 @@ AndroidDocument AndroidDocument::fromFile (const File& filePath)
AndroidDocument AndroidDocument::fromDocument ([[maybe_unused]] const URL& documentUrl) AndroidDocument AndroidDocument::fromDocument ([[maybe_unused]] const URL& documentUrl)
{ {
#if JUCE_ANDROID #if JUCE_ANDROID
if (getAndroidSDKVersion() < 19)
{
// This function is unsupported on this platform.
jassertfalse;
return AndroidDocument{};
}
const auto javaUri = urlToUri (documentUrl); const auto javaUri = urlToUri (documentUrl);
if (! getEnv()->CallStaticBooleanMethod (DocumentsContract19, if (! getEnv()->CallStaticBooleanMethod (DocumentsContract19,
@ -855,13 +833,6 @@ AndroidDocument AndroidDocument::fromDocument ([[maybe_unused]] const URL& docum
AndroidDocument AndroidDocument::fromTree ([[maybe_unused]] const URL& treeUrl) AndroidDocument AndroidDocument::fromTree ([[maybe_unused]] const URL& treeUrl)
{ {
#if JUCE_ANDROID #if JUCE_ANDROID
if (getAndroidSDKVersion() < 21)
{
// This function is unsupported on this platform.
jassertfalse;
return AndroidDocument{};
}
const auto javaUri = urlToUri (treeUrl); const auto javaUri = urlToUri (treeUrl);
LocalRef<jobject> treeDocumentId { getEnv()->CallStaticObjectMethod (DocumentsContract21, LocalRef<jobject> treeDocumentId { getEnv()->CallStaticObjectMethod (DocumentsContract21,
DocumentsContract21.getTreeDocumentId, DocumentsContract21.getTreeDocumentId,
@ -1042,7 +1013,7 @@ AndroidDocumentIterator AndroidDocumentIterator::makeNonRecursive (const Android
using Detail = AndroidDocumentDetail; using Detail = AndroidDocumentDetail;
#if JUCE_ANDROID #if JUCE_ANDROID
if (21 <= getAndroidSDKVersion()) if (getAndroidSDKVersion() == 21)
{ {
if (auto uri = dir.getNativeInfo().uri) if (auto uri = dir.getNativeInfo().uri)
return Utils::makeWithEngine (Detail::makeDocumentsContractIteratorEngine (uri)); return Utils::makeWithEngine (Detail::makeDocumentsContractIteratorEngine (uri));
@ -1060,7 +1031,7 @@ AndroidDocumentIterator AndroidDocumentIterator::makeRecursive (const AndroidDoc
using Detail = AndroidDocumentDetail; using Detail = AndroidDocumentDetail;
#if JUCE_ANDROID #if JUCE_ANDROID
if (21 <= getAndroidSDKVersion()) if (getAndroidSDKVersion() == 21)
{ {
if (auto uri = dir.getNativeInfo().uri) if (auto uri = dir.getNativeInfo().uri)
return Utils::makeWithEngine (Detail::RecursiveEngine { uri }); return Utils::makeWithEngine (Detail::RecursiveEngine { uri });

View file

@ -359,45 +359,18 @@ private:
static Array<File> getSecondaryStorageDirectories() static Array<File> getSecondaryStorageDirectories()
{ {
auto* env = getEnv();
static jmethodID m = (env->GetMethodID (AndroidContext, "getExternalFilesDirs",
"(Ljava/lang/String;)[Ljava/io/File;"));
if (m == nullptr)
return {};
auto paths = convertFileArray (LocalRef<jobject> (env->CallObjectMethod (getAppContext().get(), m, nullptr)));
Array<File> results; Array<File> results;
if (getAndroidSDKVersion() >= 19) for (auto path : paths)
{ results.add (getMountPointForFile (path));
auto* env = getEnv();
static jmethodID m = (env->GetMethodID (AndroidContext, "getExternalFilesDirs",
"(Ljava/lang/String;)[Ljava/io/File;"));
if (m == nullptr)
return {};
auto paths = convertFileArray (LocalRef<jobject> (env->CallObjectMethod (getAppContext().get(), m, nullptr)));
for (auto path : paths)
results.add (getMountPointForFile (path));
}
else
{
// on older SDKs other external storages are located "next" to the primary
// storage mount point
auto mountFolder = getMountPointForFile (getPrimaryStorageDirectory())
.getParentDirectory();
// don't include every folder. Only folders which are actually mountpoints
juce_statStruct info;
if (! juce_stat (mountFolder.getFullPathName(), info))
return {};
auto rootFsDevice = info.st_dev;
for (const auto& iter : RangedDirectoryIterator (mountFolder, false, "*", File::findDirectories))
{
auto candidate = iter.getFile();
if (juce_stat (candidate.getFullPathName(), info)
&& info.st_dev != rootFsDevice)
results.add (candidate);
}
}
return results; return results;
} }
@ -827,12 +800,7 @@ String File::getVersion() const
static File getDocumentsDirectory() static File getDocumentsDirectory()
{ {
auto* env = getEnv(); return getWellKnownFolder ("DIRECTORY_DOCUMENTS");
if (getAndroidSDKVersion() >= 19)
return getWellKnownFolder ("DIRECTORY_DOCUMENTS");
return juceFile (LocalRef<jobject> (env->CallStaticObjectMethod (AndroidEnvironment, AndroidEnvironment.getDataDirectory)));
} }
static File getAppDataDir (bool dataDir) static File getAppDataDir (bool dataDir)

View file

@ -680,23 +680,20 @@ bool androidHasSystemFeature (const String& property)
String audioManagerGetProperty (const String& property) String audioManagerGetProperty (const String& property)
{ {
if (getAndroidSDKVersion() >= 17) auto* env = getEnv();
LocalRef<jobject> audioManager (env->CallObjectMethod (getAppContext().get(), AndroidContext.getSystemService,
javaString ("audio").get()));
if (audioManager != nullptr)
{ {
auto* env = getEnv(); LocalRef<jstring> jProperty (javaString (property));
LocalRef<jobject> audioManager (env->CallObjectMethod (getAppContext().get(), AndroidContext.getSystemService,
javaString ("audio").get()));
if (audioManager != nullptr) auto methodID = env->GetMethodID (AndroidAudioManager, "getProperty", "(Ljava/lang/String;)Ljava/lang/String;");
{
LocalRef<jstring> jProperty (javaString (property));
auto methodID = env->GetMethodID (AndroidAudioManager, "getProperty", "(Ljava/lang/String;)Ljava/lang/String;"); if (methodID != nullptr)
return juceString (LocalRef<jstring> ((jstring) env->CallObjectMethod (audioManager.get(),
if (methodID != nullptr) methodID,
return juceString (LocalRef<jstring> ((jstring) env->CallObjectMethod (audioManager.get(), javaString (property).get())));
methodID,
javaString (property).get())));
}
} }
return {}; return {};

View file

@ -160,19 +160,12 @@ static void loadSDKDependentMethods()
hasChecked = true; hasChecked = true;
auto* env = getEnv(); auto* env = getEnv();
const auto sdkVersion = getAndroidSDKVersion();
if (sdkVersion >= 18) nodeInfoSetEditable = env->GetMethodID (AndroidAccessibilityNodeInfo, "setEditable", "(Z)V");
{ nodeInfoSetTextSelection = env->GetMethodID (AndroidAccessibilityNodeInfo, "setTextSelection", "(II)V");
nodeInfoSetEditable = env->GetMethodID (AndroidAccessibilityNodeInfo, "setEditable", "(Z)V");
nodeInfoSetTextSelection = env->GetMethodID (AndroidAccessibilityNodeInfo, "setTextSelection", "(II)V");
}
if (sdkVersion >= 19) nodeInfoSetLiveRegion = env->GetMethodID (AndroidAccessibilityNodeInfo, "setLiveRegion", "(I)V");
{ accessibilityEventSetContentChangeTypes = env->GetMethodID (AndroidAccessibilityEvent, "setContentChangeTypes", "(I)V");
nodeInfoSetLiveRegion = env->GetMethodID (AndroidAccessibilityNodeInfo, "setLiveRegion", "(I)V");
accessibilityEventSetContentChangeTypes = env->GetMethodID (AndroidAccessibilityEvent, "setContentChangeTypes", "(I)V");
}
} }
} }
@ -498,58 +491,55 @@ public:
} }
} }
if (getAndroidSDKVersion() >= 19) if (auto* tableInterface = accessibilityHandler.getTableInterface())
{ {
if (auto* tableInterface = accessibilityHandler.getTableInterface()) const auto rows = tableInterface->getNumRows();
const auto columns = tableInterface->getNumColumns();
const LocalRef<jobject> collectionInfo { env->CallStaticObjectMethod (AndroidAccessibilityNodeInfoCollectionInfo,
AndroidAccessibilityNodeInfoCollectionInfo.obtain,
(jint) rows,
(jint) columns,
(jboolean) false) };
env->CallVoidMethod (info, AndroidAccessibilityNodeInfo19.setCollectionInfo, collectionInfo.get());
}
if (auto* enclosingTableHandler = detail::AccessibilityHelpers::getEnclosingHandlerWithInterface (&accessibilityHandler, &AccessibilityHandler::getTableInterface))
{
auto* interface = enclosingTableHandler->getTableInterface();
jassert (interface != nullptr);
const auto rowSpan = interface->getRowSpan (accessibilityHandler);
const auto columnSpan = interface->getColumnSpan (accessibilityHandler);
enum class IsHeader { no, yes };
const auto addCellInfo = [env, &info] (AccessibilityTableInterface::Span rows, AccessibilityTableInterface::Span columns, IsHeader header)
{ {
const auto rows = tableInterface->getNumRows(); const LocalRef<jobject> collectionItemInfo { env->CallStaticObjectMethod (AndroidAccessibilityNodeInfoCollectionItemInfo,
const auto columns = tableInterface->getNumColumns(); AndroidAccessibilityNodeInfoCollectionItemInfo.obtain,
const LocalRef<jobject> collectionInfo { env->CallStaticObjectMethod (AndroidAccessibilityNodeInfoCollectionInfo, (jint) rows.begin,
AndroidAccessibilityNodeInfoCollectionInfo.obtain, (jint) rows.num,
(jint) rows, (jint) columns.begin,
(jint) columns, (jint) columns.num,
(jboolean) false) }; (jboolean) (header == IsHeader::yes)) };
env->CallVoidMethod (info, AndroidAccessibilityNodeInfo19.setCollectionInfo, collectionInfo.get()); env->CallVoidMethod (info, AndroidAccessibilityNodeInfo19.setCollectionItemInfo, collectionItemInfo.get());
};
if (rowSpan.hasValue() && columnSpan.hasValue())
{
addCellInfo (*rowSpan, *columnSpan, IsHeader::no);
} }
else
if (auto* enclosingTableHandler = detail::AccessibilityHelpers::getEnclosingHandlerWithInterface (&accessibilityHandler, &AccessibilityHandler::getTableInterface))
{ {
auto* interface = enclosingTableHandler->getTableInterface(); if (auto* tableHeader = interface->getHeaderHandler())
jassert (interface != nullptr);
const auto rowSpan = interface->getRowSpan (accessibilityHandler);
const auto columnSpan = interface->getColumnSpan (accessibilityHandler);
enum class IsHeader { no, yes };
const auto addCellInfo = [env, &info] (AccessibilityTableInterface::Span rows, AccessibilityTableInterface::Span columns, IsHeader header)
{ {
const LocalRef<jobject> collectionItemInfo { env->CallStaticObjectMethod (AndroidAccessibilityNodeInfoCollectionItemInfo, if (accessibilityHandler.getParent() == tableHeader)
AndroidAccessibilityNodeInfoCollectionItemInfo.obtain,
(jint) rows.begin,
(jint) rows.num,
(jint) columns.begin,
(jint) columns.num,
(jboolean) (header == IsHeader::yes)) };
env->CallVoidMethod (info, AndroidAccessibilityNodeInfo19.setCollectionItemInfo, collectionItemInfo.get());
};
if (rowSpan.hasValue() && columnSpan.hasValue())
{
addCellInfo (*rowSpan, *columnSpan, IsHeader::no);
}
else
{
if (auto* tableHeader = interface->getHeaderHandler())
{ {
if (accessibilityHandler.getParent() == tableHeader) const auto children = tableHeader->getChildren();
{ const auto column = std::distance (children.cbegin(), std::find (children.cbegin(), children.cend(), &accessibilityHandler));
const auto children = tableHeader->getChildren();
const auto column = std::distance (children.cbegin(), std::find (children.cbegin(), children.cend(), &accessibilityHandler));
// Talkback will only treat a row as a column header if its row index is zero // Talkback will only treat a row as a column header if its row index is zero
// https://github.com/google/talkback/blob/acd0bc7631a3dfbcf183789c7557596a45319e1f/utils/src/main/java/CollectionState.java#L853 // https://github.com/google/talkback/blob/acd0bc7631a3dfbcf183789c7557596a45319e1f/utils/src/main/java/CollectionState.java#L853
addCellInfo ({ 0, 1 }, { (int) column, 1 }, IsHeader::yes); addCellInfo ({ 0, 1 }, { (int) column, 1 }, IsHeader::yes);
}
} }
} }
} }

View file

@ -288,9 +288,6 @@ public:
constexpr int grantReadUriPermission = 1; constexpr int grantReadUriPermission = 1;
constexpr int grantPrefixUriPermission = 128; constexpr int grantPrefixUriPermission = 128;
if (getAndroidSDKVersion() < 21)
return grantReadUriPermission;
return grantReadUriPermission | grantPrefixUriPermission; return grantReadUriPermission | grantPrefixUriPermission;
}; };

View file

@ -59,7 +59,6 @@ public:
currentFileChooser = this; currentFileChooser = this;
auto* env = getEnv(); auto* env = getEnv();
auto sdkVersion = getAndroidSDKVersion();
auto saveMode = ((flags & FileBrowserComponent::saveMode) != 0); auto saveMode = ((flags & FileBrowserComponent::saveMode) != 0);
auto selectsDirectories = ((flags & FileBrowserComponent::canSelectDirectories) != 0); auto selectsDirectories = ((flags & FileBrowserComponent::canSelectDirectories) != 0);
auto canSelectMultiple = ((flags & FileBrowserComponent::canSelectMultipleItems) != 0); auto canSelectMultiple = ((flags & FileBrowserComponent::canSelectMultipleItems) != 0);
@ -67,24 +66,9 @@ public:
// You cannot save a directory // You cannot save a directory
jassert (! (saveMode && selectsDirectories)); jassert (! (saveMode && selectsDirectories));
if (sdkVersion < 19)
{
// native save dialogs are only supported in Android versions >= 19
jassert (! saveMode);
saveMode = false;
}
if (sdkVersion < 21)
{
// native directory chooser dialogs are only supported in Android versions >= 21
jassert (! selectsDirectories);
selectsDirectories = false;
}
const char* action = (selectsDirectories ? "android.intent.action.OPEN_DOCUMENT_TREE" const char* action = (selectsDirectories ? "android.intent.action.OPEN_DOCUMENT_TREE"
: (saveMode ? "android.intent.action.CREATE_DOCUMENT" : (saveMode ? "android.intent.action.CREATE_DOCUMENT"
: (sdkVersion >= 19 ? "android.intent.action.OPEN_DOCUMENT" : "android.intent.action.OPEN_DOCUMENT"));
: "android.intent.action.GET_CONTENT")));
intent = GlobalRef (LocalRef<jobject> (env->NewObject (AndroidIntent, AndroidIntent.constructWithString, intent = GlobalRef (LocalRef<jobject> (env->NewObject (AndroidIntent, AndroidIntent.constructWithString,
@ -108,13 +92,10 @@ public:
uri.get()); uri.get());
} }
if (canSelectMultiple && sdkVersion >= 18) env->CallObjectMethod (intent.get(),
{ AndroidIntent.putExtraBool,
env->CallObjectMethod (intent.get(), javaString ("android.intent.extra.ALLOW_MULTIPLE").get(),
AndroidIntent.putExtraBool, canSelectMultiple);
javaString ("android.intent.extra.ALLOW_MULTIPLE").get(),
true);
}
if (! selectsDirectories) if (! selectsDirectories)
{ {

View file

@ -383,7 +383,7 @@ struct PushNotifications::Pimpl
owner.listeners.call ([&] (Listener& l) { l.handleNotificationAction (true, notification, actionTitle, {}); }); owner.listeners.call ([&] (Listener& l) { l.handleNotificationAction (true, notification, actionTitle, {}); });
} }
else if (getAndroidSDKVersion() >= 20 && actionString.contains (notificationTextInputActionString)) else if (actionString.contains (notificationTextInputActionString))
{ {
auto prefix = notificationTextInputActionString + notification.identifier + "."; auto prefix = notificationTextInputActionString + notification.identifier + ".";
@ -613,10 +613,7 @@ struct PushNotifications::Pimpl
if (n.actions.size() > 0) if (n.actions.size() > 0)
setupActions (n, notificationBuilder); setupActions (n, notificationBuilder);
if (getAndroidSDKVersion() >= 16) return LocalRef<jobject> (env->CallObjectMethod (notificationBuilder, NotificationBuilderApi16.build));
return LocalRef<jobject> (env->CallObjectMethod (notificationBuilder, NotificationBuilderApi16.build));
return LocalRef<jobject> (env->CallObjectMethod (notificationBuilder, NotificationBuilderBase.getNotification));
} }
static LocalRef<jobject> createNotificationBuilder (const PushNotifications::Notification& n) static LocalRef<jobject> createNotificationBuilder (const PushNotifications::Notification& n)
@ -684,7 +681,7 @@ struct PushNotifications::Pimpl
env->CallObjectMethod (notificationBuilder, NotificationBuilderBase.setSmallIcon, iconId); env->CallObjectMethod (notificationBuilder, NotificationBuilderBase.setSmallIcon, iconId);
if (getAndroidSDKVersion() >= 21 && n.publicVersion != nullptr) if (n.publicVersion != nullptr)
{ {
// Public version of a notification is not expected to have another public one! // Public version of a notification is not expected to have another public one!
jassert (n.publicVersion->publicVersion == nullptr); jassert (n.publicVersion->publicVersion == nullptr);
@ -814,61 +811,49 @@ struct PushNotifications::Pimpl
env->CallObjectMethod (notificationBuilder, NotificationBuilderBase.setOngoing, n.ongoing); env->CallObjectMethod (notificationBuilder, NotificationBuilderBase.setOngoing, n.ongoing);
env->CallObjectMethod (notificationBuilder, NotificationBuilderBase.setOnlyAlertOnce, n.alertOnlyOnce); env->CallObjectMethod (notificationBuilder, NotificationBuilderBase.setOnlyAlertOnce, n.alertOnlyOnce);
if (getAndroidSDKVersion() >= 16) if (n.subtitle.isNotEmpty())
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi16.setSubText, javaString (n.subtitle).get());
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi16.setPriority, n.priority);
if (getAndroidSDKVersion() < 24)
{ {
if (n.subtitle.isNotEmpty()) const bool useChronometer = n.timestampVisibility == PushNotifications::Notification::chronometer;
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi16.setSubText, javaString (n.subtitle).get()); env->CallObjectMethod (notificationBuilder, NotificationBuilderApi16.setUsesChronometer, useChronometer);
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi16.setPriority, n.priority);
if (getAndroidSDKVersion() < 24)
{
const bool useChronometer = n.timestampVisibility == PushNotifications::Notification::chronometer;
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi16.setUsesChronometer, useChronometer);
}
} }
if (getAndroidSDKVersion() >= 17) const bool showTimeStamp = n.timestampVisibility != PushNotifications::Notification::off;
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi17.setShowWhen, showTimeStamp);
if (n.groupId.isNotEmpty())
{ {
const bool showTimeStamp = n.timestampVisibility != PushNotifications::Notification::off; env->CallObjectMethod (notificationBuilder, NotificationBuilderApi20.setGroup, javaString (n.groupId).get());
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi17.setShowWhen, showTimeStamp); env->CallObjectMethod (notificationBuilder, NotificationBuilderApi20.setGroupSummary, n.groupSummary);
} }
if (getAndroidSDKVersion() >= 20) if (n.groupSortKey.isNotEmpty())
{ env->CallObjectMethod (notificationBuilder, NotificationBuilderApi20.setSortKey, javaString (n.groupSortKey).get());
if (n.groupId.isNotEmpty())
{
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi20.setGroup, javaString (n.groupId).get());
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi20.setGroupSummary, n.groupSummary);
}
if (n.groupSortKey.isNotEmpty()) env->CallObjectMethod (notificationBuilder, NotificationBuilderApi20.setLocalOnly, n.localOnly);
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi20.setSortKey, javaString (n.groupSortKey).get());
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi20.setLocalOnly, n.localOnly); auto extras = LocalRef<jobject> (env->NewObject (AndroidBundle, AndroidBundle.constructor));
auto extras = LocalRef<jobject> (env->NewObject (AndroidBundle, AndroidBundle.constructor)); env->CallVoidMethod (extras, AndroidBundle.putBundle, javaString ("notificationData").get(),
juceNotificationToBundle (n).get());
env->CallVoidMethod (extras, AndroidBundle.putBundle, javaString ("notificationData").get(), env->CallObjectMethod (notificationBuilder, NotificationBuilderApi20.addExtras, extras.get());
juceNotificationToBundle (n).get());
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi20.addExtras, extras.get()); if (n.person.isNotEmpty())
} env->CallObjectMethod (notificationBuilder, NotificationBuilderApi21.addPerson, javaString (n.person).get());
if (getAndroidSDKVersion() >= 21) auto categoryString = typeToCategory (n.type);
{ if (categoryString.isNotEmpty())
if (n.person.isNotEmpty()) env->CallObjectMethod (notificationBuilder, NotificationBuilderApi21.setCategory, javaString (categoryString).get());
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi21.addPerson, javaString (n.person).get());
auto categoryString = typeToCategory (n.type); if (n.accentColour != Colour())
if (categoryString.isNotEmpty()) env->CallObjectMethod (notificationBuilder, NotificationBuilderApi21.setColor, n.accentColour.getARGB());
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi21.setCategory, javaString (categoryString).get());
if (n.accentColour != Colour()) env->CallObjectMethod (notificationBuilder, NotificationBuilderApi21.setVisibility, n.lockScreenAppearance);
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi21.setColor, n.accentColour.getARGB());
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi21.setVisibility, n.lockScreenAppearance);
}
if (getAndroidSDKVersion() >= 24) if (getAndroidSDKVersion() >= 24)
{ {
@ -917,9 +902,6 @@ struct PushNotifications::Pimpl
static void setupActions (const PushNotifications::Notification& n, LocalRef<jobject>& notificationBuilder) static void setupActions (const PushNotifications::Notification& n, LocalRef<jobject>& notificationBuilder)
{ {
if (getAndroidSDKVersion() < 16)
return;
auto* env = getEnv(); auto* env = getEnv();
LocalRef<jobject> context (getMainActivity()); LocalRef<jobject> context (getMainActivity());
@ -956,59 +938,51 @@ struct PushNotifications::Pimpl
iconId = env->CallIntMethod (resources, AndroidResources.getIdentifier, javaString (n.icon).get(), iconId = env->CallIntMethod (resources, AndroidResources.getIdentifier, javaString (n.icon).get(),
javaString ("raw").get(), packageNameString.get()); javaString ("raw").get(), packageNameString.get());
if (getAndroidSDKVersion() >= 20) auto actionBuilder = LocalRef<jobject> (env->NewObject (NotificationActionBuilder,
NotificationActionBuilder.constructor,
iconId,
javaString (action.title).get(),
notifyPendingIntent.get()));
env->CallObjectMethod (actionBuilder, NotificationActionBuilder.addExtras,
varToBundleWithPropertiesString (action.parameters).get());
if (isTextStyle)
{ {
auto actionBuilder = LocalRef<jobject> (env->NewObject (NotificationActionBuilder, auto resultKey = javaString (action.title + String (actionIndex));
NotificationActionBuilder.constructor, auto remoteInputBuilder = LocalRef<jobject> (env->NewObject (RemoteInputBuilder,
iconId, RemoteInputBuilder.constructor,
javaString (action.title).get(), resultKey.get()));
notifyPendingIntent.get()));
env->CallObjectMethod (actionBuilder, NotificationActionBuilder.addExtras, if (! action.textInputPlaceholder.isEmpty())
varToBundleWithPropertiesString (action.parameters).get()); env->CallObjectMethod (remoteInputBuilder, RemoteInputBuilder.setLabel, javaString (action.textInputPlaceholder).get());
if (isTextStyle) if (! action.allowedResponses.isEmpty())
{ {
auto resultKey = javaString (action.title + String (actionIndex)); env->CallObjectMethod (remoteInputBuilder, RemoteInputBuilder.setAllowFreeFormInput, false);
auto remoteInputBuilder = LocalRef<jobject> (env->NewObject (RemoteInputBuilder,
RemoteInputBuilder.constructor,
resultKey.get()));
if (! action.textInputPlaceholder.isEmpty()) const int size = action.allowedResponses.size();
env->CallObjectMethod (remoteInputBuilder, RemoteInputBuilder.setLabel, javaString (action.textInputPlaceholder).get());
if (! action.allowedResponses.isEmpty()) auto array = LocalRef<jobjectArray> (env->NewObjectArray (size, env->FindClass ("java/lang/String"), nullptr));
for (int i = 0; i < size; ++i)
{ {
env->CallObjectMethod (remoteInputBuilder, RemoteInputBuilder.setAllowFreeFormInput, false); const auto& response = action.allowedResponses[i];
auto responseString = javaString (response);
const int size = action.allowedResponses.size(); env->SetObjectArrayElement (array, i, responseString.get());
auto array = LocalRef<jobjectArray> (env->NewObjectArray (size, env->FindClass ("java/lang/String"), nullptr));
for (int i = 0; i < size; ++i)
{
const auto& response = action.allowedResponses[i];
auto responseString = javaString (response);
env->SetObjectArrayElement (array, i, responseString.get());
}
env->CallObjectMethod (remoteInputBuilder, RemoteInputBuilder.setChoices, array.get());
} }
env->CallObjectMethod (actionBuilder, NotificationActionBuilder.addRemoteInput, env->CallObjectMethod (remoteInputBuilder, RemoteInputBuilder.setChoices, array.get());
env->CallObjectMethod (remoteInputBuilder, RemoteInputBuilder.build));
} }
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi20.addAction, env->CallObjectMethod (actionBuilder, NotificationActionBuilder.addRemoteInput,
env->CallObjectMethod (actionBuilder, NotificationActionBuilder.build)); env->CallObjectMethod (remoteInputBuilder, RemoteInputBuilder.build));
}
else
{
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi16.addAction,
iconId, javaString (action.title).get(), notifyPendingIntent.get());
} }
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi20.addAction,
env->CallObjectMethod (actionBuilder, NotificationActionBuilder.build));
++actionIndex; ++actionIndex;
} }
} }
@ -1244,9 +1218,6 @@ struct PushNotifications::Pimpl
static PushNotifications::Notification javaNotificationToJuceNotification (const LocalRef<jobject>& notification) static PushNotifications::Notification javaNotificationToJuceNotification (const LocalRef<jobject>& notification)
{ {
if (getAndroidSDKVersion() < 20)
return {};
auto* env = getEnv(); auto* env = getEnv();
auto extras = LocalRef<jobject> (env->GetObjectField (notification, AndroidNotification.extras)); auto extras = LocalRef<jobject> (env->GetObjectField (notification, AndroidNotification.extras));

View file

@ -941,18 +941,8 @@ void WebBrowserComponent::clearCookies()
auto cookieManager = LocalRef<jobject> (env->CallStaticObjectMethod (AndroidCookieManager, auto cookieManager = LocalRef<jobject> (env->CallStaticObjectMethod (AndroidCookieManager,
AndroidCookieManager.getInstance)); AndroidCookieManager.getInstance));
jmethodID clearCookiesMethod = nullptr; jmethodID clearCookiesMethod = env->GetMethodID (AndroidCookieManager, "removeAllCookies", "(Landroid/webkit/ValueCallback;)V");
env->CallVoidMethod (cookieManager, clearCookiesMethod, 0);
if (getAndroidSDKVersion() >= 21)
{
clearCookiesMethod = env->GetMethodID (AndroidCookieManager, "removeAllCookies", "(Landroid/webkit/ValueCallback;)V");
env->CallVoidMethod (cookieManager, clearCookiesMethod, 0);
}
else
{
clearCookiesMethod = env->GetMethodID (AndroidCookieManager, "removeAllCookie", "()V");
env->CallVoidMethod (cookieManager, clearCookiesMethod);
}
} }
bool WebBrowserComponent::areOptionsSupported (const Options& options) bool WebBrowserComponent::areOptionsSupported (const Options& options)

View file

@ -549,21 +549,14 @@ struct CameraDevice::Pimpl
void continueOpenRequest (bool granted) void continueOpenRequest (bool granted)
{ {
if (getAndroidSDKVersion() >= 21) if (granted)
{ {
if (granted) getEnv()->CallVoidMethod (getAppContext().get(), AndroidApplication.registerActivityLifecycleCallbacks, activityLifeListener.get());
{ scopedCameraDevice.reset (new ScopedCameraDevice (*this, cameraId, cameraManager, handler, getAutoFocusModeToUse()));
getEnv()->CallVoidMethod (getAppContext().get(), AndroidApplication.registerActivityLifecycleCallbacks, activityLifeListener.get());
scopedCameraDevice.reset (new ScopedCameraDevice (*this, cameraId, cameraManager, handler, getAutoFocusModeToUse()));
}
else
{
invokeCameraOpenCallback ("Camera permission not granted");
}
} }
else else
{ {
invokeCameraOpenCallback ("Camera requires android sdk version 21 or greater"); invokeCameraOpenCallback ("Camera permission not granted");
} }
} }
@ -636,9 +629,6 @@ struct CameraDevice::Pimpl
static StringArray getAvailableDevices() static StringArray getAvailableDevices()
{ {
if (getAndroidSDKVersion() < 21)
return StringArray(); // Camera requires SDK version 21 or later
StringArray results; StringArray results;
auto* env = getEnv(); auto* env = getEnv();

View file

@ -354,9 +354,6 @@ struct VideoComponent::Pimpl
, systemVolumeListener (*this) , systemVolumeListener (*this)
#endif #endif
{ {
// Video requires SDK version 21 or higher
jassert (getAndroidSDKVersion() >= 21);
setVisible (true); setVisible (true);
auto* env = getEnv(); auto* env = getEnv();
@ -1617,9 +1614,6 @@ private:
//============================================================================== //==============================================================================
static LocalRef<jobject> getAudioAttributes() static LocalRef<jobject> getAudioAttributes()
{ {
// Video requires SDK version 21 or higher
jassert (getAndroidSDKVersion() >= 21);
auto* env = getEnv(); auto* env = getEnv();
auto audioAttribsBuilder = LocalRef<jobject> (env->NewObject (AndroidAudioAttributesBuilder, auto audioAttribsBuilder = LocalRef<jobject> (env->NewObject (AndroidAudioAttributesBuilder,