[Android] Check CPU compatibility in background
Geoffrey Métais
git at videolan.org
Thu May 3 14:17:12 CEST 2018
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu May 3 12:11:52 2018 +0200| [022e12e5509f2d4944de978dc6a50e1df8e54ed7] | committer: Geoffrey Métais
Check CPU compatibility in background
> https://code.videolan.org/videolan/vlc-android/commit/022e12e5509f2d4944de978dc6a50e1df8e54ed7
---
vlc-android/src/org/videolan/vlc/PlaybackService.kt | 5 +----
.../src/org/videolan/vlc/gui/MainActivity.java | 7 ++-----
.../src/org/videolan/vlc/gui/tv/MainTvActivity.java | 7 ++-----
.../videolan/vlc/gui/video/VideoPlayerActivity.java | 19 ++++++-------------
.../vlc/gui/video/benchmark/BenchActivity.java | 2 +-
vlc-android/src/org/videolan/vlc/util/Util.java | 19 +++++++++++++++++++
6 files changed, 31 insertions(+), 28 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.kt b/vlc-android/src/org/videolan/vlc/PlaybackService.kt
index edf78943e..3d0a2ab1e 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.kt
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.kt
@@ -453,10 +453,7 @@ class PlaybackService : MediaBrowserServiceCompat() {
super.onCreate()
settings = PreferenceManager.getDefaultSharedPreferences(this)
playlistManager = PlaylistManager(this)
- if (!VLCInstance.testCompatibleCPU(this)) {
- stopSelf()
- return
- }
+ Util.checkCpuCompatibility(this)
medialibrary = VLCApplication.getMLInstance()
if (!medialibrary.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 541e090e2..9b6b7fcaf 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -66,7 +66,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.VLCInstance;
+import org.videolan.vlc.util.Util;
import java.util.List;
@@ -89,10 +89,7 @@ public class MainActivity extends ContentActivity implements FilterQueryProvider
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- if (!VLCInstance.testCompatibleCPU(this)) {
- finish();
- return;
- }
+ Util.checkCpuCompatibility(this);
Permissions.checkReadStoragePermission(this, false);
/*** Start initializing the UI ***/
setContentView(R.layout.main);
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 bd88e0885..0e33ecdea 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java
@@ -37,7 +37,7 @@ import org.videolan.vlc.gui.preferences.PreferencesActivity;
import org.videolan.vlc.gui.tv.browser.BaseTvActivity;
import org.videolan.vlc.util.Constants;
import org.videolan.vlc.util.Permissions;
-import org.videolan.vlc.util.VLCInstance;
+import org.videolan.vlc.util.Util;
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public class MainTvActivity extends BaseTvActivity {
@@ -55,10 +55,7 @@ public class MainTvActivity extends BaseTvActivity {
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 498a644b8..c593c8dcb 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -134,7 +134,6 @@ import org.videolan.vlc.util.Permissions;
import org.videolan.vlc.util.Strings;
import org.videolan.vlc.util.SubtitlesDownloader;
import org.videolan.vlc.util.Util;
-import org.videolan.vlc.util.VLCInstance;
import org.videolan.vlc.util.WorkersKt;
import java.io.ByteArrayInputStream;
@@ -317,10 +316,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);
@@ -945,15 +941,12 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
}
};
- protected void exit(int resultCode){
- if (isFinishing())
- return;
- Intent resultIntent = new Intent(ACTION_RESULT);
+ public void exit(int resultCode){
+ if (isFinishing()) return;
+ final Intent resultIntent = new Intent(ACTION_RESULT);
if (mUri != null && mService != null) {
- if (AndroidUtil.isNougatOrLater)
- resultIntent.putExtra(EXTRA_URI, mUri.toString());
- else
- resultIntent.setData(mUri);
+ if (AndroidUtil.isNougatOrLater) resultIntent.putExtra(EXTRA_URI, mUri.toString());
+ else resultIntent.setData(mUri);
resultIntent.putExtra(EXTRA_POSITION, mService.getTime());
resultIntent.putExtra(EXTRA_DURATION, mService.getLength());
}
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/benchmark/BenchActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/benchmark/BenchActivity.java
index cd52512bc..f5e8b6727 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/benchmark/BenchActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/benchmark/BenchActivity.java
@@ -304,7 +304,7 @@ public class BenchActivity extends ShallowVideoPlayer {
* @param resultCode VideoPlayerActivity's resultCode
*/
@Override
- protected void exit (int resultCode) {
+ public void exit (int resultCode) {
if (resultCode != RESULT_OK) {
mVLCFailed = true;
}
diff --git a/vlc-android/src/org/videolan/vlc/util/Util.java b/vlc-android/src/org/videolan/vlc/util/Util.java
index 12dfb3900..79706cd53 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) {
+ WorkersKt.runBackground(new Runnable() {
+ @Override
+ public void run() {
+ if (!VLCInstance.testCompatibleCPU(ctx)) WorkersKt.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