[Android] Prevent NPE at device init
Geoffrey Métais
git at videolan.org
Thu Oct 5 16:50:33 CEST 2017
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Oct 5 16:10:35 2017 +0200| [44c6c93377e1e807784da17c3a5d64a2678888ee] | committer: Geoffrey Métais
Prevent NPE at device init
> https://code.videolan.org/videolan/vlc-android/commit/44c6c93377e1e807784da17c3a5d64a2678888ee
---
vlc-android/src/org/videolan/vlc/util/AndroidDevices.java | 4 +---
vlc-android/src/org/videolan/vlc/util/SubtitlesDownloader.java | 5 +++--
2 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/util/AndroidDevices.java b/vlc-android/src/org/videolan/vlc/util/AndroidDevices.java
index fcc0a984d..1926d846a 100644
--- a/vlc-android/src/org/videolan/vlc/util/AndroidDevices.java
+++ b/vlc-android/src/org/videolan/vlc/util/AndroidDevices.java
@@ -53,7 +53,6 @@ import java.util.StringTokenizer;
public class AndroidDevices {
public final static String TAG = "VLC/UiTools/AndroidDevices";
public final static String EXTERNAL_PUBLIC_DIRECTORY = Environment.getExternalStorageDirectory().getPath();
- public static final File SUBTITLES_DIRECTORY;
public final static boolean isPhone;
public final static boolean hasCombBar;
@@ -104,12 +103,11 @@ public class AndroidDevices {
isChromeBook = pm != null && pm.hasSystemFeature("org.chromium.arc.device_management");
hasPlayServices = pm == null || hasPlayServices(pm);
hasPiP = AndroidUtil.isOOrLater || AndroidUtil.isNougatOrLater && isAndroidTv;
- isPhone = ((TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE))
+ isPhone = ctx == null || ((TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE))
.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE;
// hasCombBar test if device has Combined Bar : only for tablet with Honeycomb or ICS
hasCombBar = !AndroidDevices.isPhone && AndroidUtil.isHoneycombOrLater
&& !AndroidUtil.isJellyBeanMR1OrLater;
- SUBTITLES_DIRECTORY = new File(ctx.getExternalFilesDir(null), "subs");
}
public static boolean hasExternalStorage() {
diff --git a/vlc-android/src/org/videolan/vlc/util/SubtitlesDownloader.java b/vlc-android/src/org/videolan/vlc/util/SubtitlesDownloader.java
index 499b00537..ef8b97cc2 100644
--- a/vlc-android/src/org/videolan/vlc/util/SubtitlesDownloader.java
+++ b/vlc-android/src/org/videolan/vlc/util/SubtitlesDownloader.java
@@ -80,6 +80,7 @@ public class SubtitlesDownloader {
private static final String OpenSubtitlesAPIUrl = "http://api.opensubtitles.org/xml-rpc";
private static final String HTTP_USER_AGENT = "VLSub";
private static final String USER_AGENT = "VLSub 0.9";
+ private static final File SUBTITLES_DIRECTORY = new File(VLCApplication.getAppContext().getExternalFilesDir(null), "subs");
private HashMap<String, Object> map = null;
private XMLRPCClient mClient;
@@ -116,7 +117,7 @@ public class SubtitlesDownloader {
VLCApplication.runBackground(new Runnable() {
@Override
public void run() {
- AndroidDevices.SUBTITLES_DIRECTORY.mkdirs();
+ SUBTITLES_DIRECTORY.mkdirs();
if (logIn())
getSubtitles(mediaList, finalLanguages);
mHandler.sendEmptyMessage(DIALOG_HIDE);
@@ -319,7 +320,7 @@ public class SubtitlesDownloader {
return;
final StringBuilder sb = new StringBuilder();
final String name = fileName.lastIndexOf('.') > 0 ? fileName.substring(0, fileName.lastIndexOf('.')) : fileName;
- sb.append(AndroidDevices.SUBTITLES_DIRECTORY.getPath()).append('/').append(name).append('.').append(language).append('.').append(subFormat);
+ sb.append(SUBTITLES_DIRECTORY.getPath()).append('/').append(name).append('.').append(language).append('.').append(subFormat);
final String srtUrl = sb.toString();
FileOutputStream f = null;
GZIPInputStream gzIS = null;
More information about the Android
mailing list