[Android] Ml: Subscriptions: add null checks
Duncan McNamara
git at videolan.org
Fri Nov 18 12:29:46 UTC 2022
vlc-android | branch: master | Duncan McNamara <dcn.mcnamara at gmail.com> | Wed Nov 16 18:05:06 2022 +0100| [aa37d153468bf4a6db38f49f44a4614e1884c403] | committer: Nicolas Pomepuy
Ml: Subscriptions: add null checks
> https://code.videolan.org/videolan/vlc-android/commit/aa37d153468bf4a6db38f49f44a4614e1884c403
---
.../videolan/medialibrary/media/MlServiceImpl.java | 24 ++++++++++-----------
.../medialibrary/media/SubscriptionImpl.java | 25 ++++++++++++----------
2 files changed, 26 insertions(+), 23 deletions(-)
diff --git a/medialibrary/src/org/videolan/medialibrary/media/MlServiceImpl.java b/medialibrary/src/org/videolan/medialibrary/media/MlServiceImpl.java
index c4e37d4c0f..e80a44373c 100644
--- a/medialibrary/src/org/videolan/medialibrary/media/MlServiceImpl.java
+++ b/medialibrary/src/org/videolan/medialibrary/media/MlServiceImpl.java
@@ -11,73 +11,73 @@ public class MlServiceImpl extends MlService {
public boolean addSubscription(String mrl) {
final Medialibrary ml = Medialibrary.getInstance();
- return nativeAddSubscription(ml, this.type.value, mrl);
+ return ml.isInitiated() && nativeAddSubscription(ml, this.type.value, mrl);
}
@Override
public boolean isAutoDownloadEnabled() {
final Medialibrary ml = Medialibrary.getInstance();
- return nativeIsAutoDownloadEnabled(ml, this.type.value);
+ return ml.isInitiated() && nativeIsAutoDownloadEnabled(ml, this.type.value);
}
@Override
public boolean setAutoDownloadEnabled(boolean enabled) {
final Medialibrary ml = Medialibrary.getInstance();
- return nativeSetAutoDownloadEnabled(ml, this.type.value, enabled);
+ return ml.isInitiated() && nativeSetAutoDownloadEnabled(ml, this.type.value, enabled);
}
@Override
public boolean isNewMediaNotificationEnabled() {
final Medialibrary ml = Medialibrary.getInstance();
- return nativeIsNewMediaNotificationEnabled(ml, this.type.value);
+ return ml.isInitiated() && nativeIsNewMediaNotificationEnabled(ml, this.type.value);
}
@Override
public boolean setNewMediaNotificationEnabled(boolean enabled) {
final Medialibrary ml = Medialibrary.getInstance();
- return nativeSetNewMediaNotificationEnabled(ml, this.type.value, enabled);
+ return ml.isInitiated() && nativeSetNewMediaNotificationEnabled(ml, this.type.value, enabled);
}
@Override
public long getMaxCachedSize() {
final Medialibrary ml = Medialibrary.getInstance();
- return nativeGetMaxCachedSize(ml, this.type.value);
+ return ml.isInitiated() ? nativeGetMaxCachedSize(ml, this.type.value) : -2L;
}
@Override
public boolean setMaxCachedSize(long size) {
final Medialibrary ml = Medialibrary.getInstance();
- return nativeSetMaxCachedSize(ml, this.type.value, size);
+ return ml.isInitiated() && nativeSetMaxCachedSize(ml, this.type.value, size);
}
@Override
public int getNbSubscriptions() {
final Medialibrary ml = Medialibrary.getInstance();
- return nativeGetNbSubscriptions(ml, this.type.value);
+ return ml.isInitiated() ? nativeGetNbSubscriptions(ml, this.type.value) : -1;
}
@Override
public int getNbUnplayedMedia() {
final Medialibrary ml = Medialibrary.getInstance();
- return nativeGetNbUnplayedMedia(ml, this.type.value);
+ return ml.isInitiated() ? nativeGetNbUnplayedMedia(ml, this.type.value) : -1;
}
@Override
public Subscription[] getSubscriptions(int sort, boolean desc, boolean includeMissing) {
final Medialibrary ml = Medialibrary.getInstance();
- return nativeGetSubscriptions(ml, this.type.value, sort, desc, includeMissing);
+ return ml.isInitiated() ? nativeGetSubscriptions(ml, this.type.value, sort, desc, includeMissing) : new Subscription[0];
}
@Override
public int getNbMedia() {
final Medialibrary ml = Medialibrary.getInstance();
- return nativeGetNbMedia(ml, this.type.value);
+ return ml.isInitiated() ? nativeGetNbMedia(ml, this.type.value) : -1;
}
@Override
public MediaWrapper[] getMedia(int sortingCriteria, boolean desc, boolean includeMissing) {
final Medialibrary ml = Medialibrary.getInstance();
- return nativeGetServiceMedia(ml, this.type.value, sortingCriteria, desc, includeMissing);
+ return ml.isInitiated() ? nativeGetServiceMedia(ml, this.type.value, sortingCriteria, desc, includeMissing) : Medialibrary.EMPTY_COLLECTION;
}
private native boolean nativeAddSubscription(Medialibrary ml, int type, String mrl);
diff --git a/medialibrary/src/org/videolan/medialibrary/media/SubscriptionImpl.java b/medialibrary/src/org/videolan/medialibrary/media/SubscriptionImpl.java
index 6f0b10f16e..d5630e4c4b 100644
--- a/medialibrary/src/org/videolan/medialibrary/media/SubscriptionImpl.java
+++ b/medialibrary/src/org/videolan/medialibrary/media/SubscriptionImpl.java
@@ -1,5 +1,7 @@
package org.videolan.medialibrary.media;
+import androidx.annotation.Nullable;
+
import org.videolan.medialibrary.interfaces.Medialibrary;
import org.videolan.medialibrary.interfaces.media.MediaWrapper;
import org.videolan.medialibrary.interfaces.media.MlService;
@@ -18,67 +20,68 @@ public class SubscriptionImpl extends Subscription {
@Override
public int getNewMediaNotification() {
final Medialibrary ml = Medialibrary.getInstance();
- return nativeSubscriptionNewMediaNotification(ml, this.id);
+ return ml.isInitiated() ? nativeSubscriptionNewMediaNotification(ml, this.id) : -1;
}
@Override
public boolean setNewMediaNotification(int value) {
final Medialibrary ml = Medialibrary.getInstance();
- return nativeSetSubscriptionNewMediaNotification(ml, this.id, value);
+ return ml.isInitiated() && nativeSetSubscriptionNewMediaNotification(ml, this.id, value);
}
@Override
public long getCachedSize() {
final Medialibrary ml = Medialibrary.getInstance();
- return nativeGetSubscriptionCachedSize(ml, this.id);
+ return ml.isInitiated() ? nativeGetSubscriptionCachedSize(ml, this.id) : -2;
}
@Override
public long getMaxCachedSize() {
final Medialibrary ml = Medialibrary.getInstance();
- return nativeGetSubscriptionMaxCachedSize(ml, this.id);
+ return ml.isInitiated() ? nativeGetSubscriptionMaxCachedSize(ml, this.id) : -2;
}
@Override
public boolean setMaxCachedSize(long size) {
final Medialibrary ml = Medialibrary.getInstance();
- return nativeSetSubscriptionMaxCachedSize(ml, this.id, size);
+ return ml.isInitiated() && nativeSetSubscriptionMaxCachedSize(ml, this.id, size);
}
@Override
public int getNbUnplayedMedia() {
final Medialibrary ml = Medialibrary.getInstance();
- return nativeGetSubscriptionNbUnplayedMedia(ml, this.id);
+ return ml.isInitiated() ? nativeGetSubscriptionNbUnplayedMedia(ml, this.id) : -1;
}
@Override
public Subscription[] getChildSubscriptions(int sortingCriteria, boolean desc, boolean includeMissing) {
final Medialibrary ml = Medialibrary.getInstance();
- return nativeGetChildSubscriptions(ml, id, sortingCriteria, desc, includeMissing);
+ return ml.isInitiated() ? nativeGetChildSubscriptions(ml, id, sortingCriteria, desc, includeMissing) : new Subscription[0];
}
@Override
+ @Nullable
public Subscription getParent() {
final Medialibrary ml = Medialibrary.getInstance();
- return nativeGetParent(ml, id);
+ return ml.isInitiated() ? nativeGetParent(ml, id) : null;
}
@Override
public boolean refresh() {
final Medialibrary ml = Medialibrary.getInstance();
- return nativeSubscriptionRefresh(ml, id);
+ return ml.isInitiated() && nativeSubscriptionRefresh(ml, id);
}
@Override
public MediaWrapper[] getMedia(int sortingCriteria, boolean desc, boolean includeMissing) {
final Medialibrary ml = Medialibrary.getInstance();
- return nativeGetSubscriptionMedia(ml, id, sortingCriteria, desc, includeMissing);
+ return ml.isInitiated() ? nativeGetSubscriptionMedia(ml, id, sortingCriteria, desc, includeMissing) : Medialibrary.EMPTY_COLLECTION;
}
@Override
public int getNbMedia() {
final Medialibrary ml = Medialibrary.getInstance();
- return nativeGetSubscriptionNbMedia(ml, id);
+ return ml.isInitiated() ? nativeGetSubscriptionNbMedia(ml, id) : -1;
}
private native int nativeSubscriptionNewMediaNotification(Medialibrary ml, long id);
More information about the Android
mailing list