[Android] Check CPU compatibility in background
Geoffrey Métais
git at videolan.org
Wed May 2 11:53:08 CEST 2018
vlc-android | branch: 3.0.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed May 2 11:51:38 2018 +0200| [be689ac2693625f81be7644782c39864fc8ffe6b] | committer: Geoffrey Métais
Check CPU compatibility in background
> https://code.videolan.org/videolan/vlc-android/commit/be689ac2693625f81be7644782c39864fc8ffe6b
---
vlc-android/src/org/videolan/vlc/PlaybackService.java | 8 ++------
.../src/org/videolan/vlc/gui/MainActivity.java | 6 ++----
.../src/org/videolan/vlc/gui/tv/MainTvActivity.java | 7 ++-----
.../videolan/vlc/gui/video/VideoPlayerActivity.java | 7 ++-----
vlc-android/src/org/videolan/vlc/util/Util.java | 19 +++++++++++++++++++
5 files changed, 27 insertions(+), 20 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.java b/vlc-android/src/org/videolan/vlc/PlaybackService.java
index ea5893e44..864afb210 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -36,9 +36,9 @@ import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
-import android.media.audiofx.AudioEffect;
import android.media.AudioManager;
import android.media.AudioManager.OnAudioFocusChangeListener;
+import android.media.audiofx.AudioEffect;
import android.net.Uri;
import android.os.Binder;
import android.os.Build;
@@ -90,7 +90,6 @@ import org.videolan.vlc.util.AndroidDevices;
import org.videolan.vlc.util.Constants;
import org.videolan.vlc.util.Permissions;
import org.videolan.vlc.util.Util;
-import org.videolan.vlc.util.VLCInstance;
import org.videolan.vlc.util.VLCOptions;
import org.videolan.vlc.util.VoiceSearchParams;
import org.videolan.vlc.util.WeakHandler;
@@ -177,10 +176,7 @@ public class PlaybackService extends MediaBrowserServiceCompat{
super.onCreate();
mSettings = PreferenceManager.getDefaultSharedPreferences(this);
playlistManager = new PlaylistManager(this);
- if (!VLCInstance.testCompatibleCPU(this)) {
- stopSelf();
- return;
- }
+ Util.checkCpuCompatibility(this);
mMedialibrary = VLCApplication.getMLInstance();
if (!mMedialibrary.isInitiated()) registerMedialibrary(null);
diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index c84d5518a..1dd72b460 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -76,6 +76,7 @@ import org.videolan.vlc.interfaces.IRefreshable;
import org.videolan.vlc.media.MediaUtils;
import org.videolan.vlc.util.Constants;
import org.videolan.vlc.util.Permissions;
+import org.videolan.vlc.util.Util;
import org.videolan.vlc.util.VLCInstance;
import java.lang.ref.WeakReference;
@@ -109,10 +110,7 @@ public class MainActivity extends ContentActivity implements FilterQueryProvider
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- if (!VLCInstance.testCompatibleCPU(this)) {
- finish();
- return;
- }
+ Util.checkCpuCompatibility(this);
Permissions.checkReadStoragePermission(this, false);
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java b/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java
index ca0140faf..c7f9c9a49 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java
@@ -82,7 +82,7 @@ import org.videolan.vlc.media.MediaUtils;
import org.videolan.vlc.util.AndroidDevices;
import org.videolan.vlc.util.Constants;
import org.videolan.vlc.util.Permissions;
-import org.videolan.vlc.util.VLCInstance;
+import org.videolan.vlc.util.Util;
import java.util.List;
@@ -125,10 +125,7 @@ public class MainTvActivity extends BaseTvActivity implements OnItemViewSelected
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- if (!VLCInstance.testCompatibleCPU(this)) {
- finish();
- return;
- }
+ Util.checkCpuCompatibility(this);
// Delay access permission dialog prompt to avoid background corruption
if (!Permissions.canReadStorage(this))
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
index 680846048..2c6b03225 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -351,10 +351,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- if (!VLCInstance.testCompatibleCPU(this)) {
- exit(RESULT_CANCELED);
- return;
- }
+ Util.checkCpuCompatibility(this);
mSettings = PreferenceManager.getDefaultSharedPreferences(this);
@@ -1001,7 +998,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
}
};
- protected void exit(int resultCode){
+ public void exit(int resultCode){
if (isFinishing())
return;
Intent resultIntent = new Intent(ACTION_RESULT);
diff --git a/vlc-android/src/org/videolan/vlc/util/Util.java b/vlc-android/src/org/videolan/vlc/util/Util.java
index 12dfb3900..4ede60ff5 100644
--- a/vlc-android/src/org/videolan/vlc/util/Util.java
+++ b/vlc-android/src/org/videolan/vlc/util/Util.java
@@ -20,6 +20,8 @@
package org.videolan.vlc.util;
+import android.app.Activity;
+import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
@@ -35,6 +37,7 @@ import org.videolan.medialibrary.Tools;
import org.videolan.medialibrary.media.MediaLibraryItem;
import org.videolan.vlc.R;
import org.videolan.vlc.VLCApplication;
+import org.videolan.vlc.gui.video.VideoPlayerActivity;
import java.io.BufferedReader;
import java.io.Closeable;
@@ -203,4 +206,20 @@ public class Util {
}
return false;
}
+
+ public static void checkCpuCompatibility(final Context ctx) {
+ VLCApplication.runBackground(new Runnable() {
+ @Override
+ public void run() {
+ if (!VLCInstance.testCompatibleCPU(ctx)) VLCApplication.runOnMainThread(new Runnable() {
+ @Override
+ public void run() {
+ if (ctx instanceof Service) ((Service) ctx).stopSelf();
+ else if (ctx instanceof VideoPlayerActivity) ((VideoPlayerActivity) ctx).exit(Activity.RESULT_CANCELED);
+ else if (ctx instanceof Activity) ((Activity) ctx).finish();
+ }
+ });
+ }
+ });
+ }
}
More information about the Android
mailing list