Commit 022e12e5 authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

Check CPU compatibility in background

parent a221338a
......@@ -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)
......
......@@ -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);
......
......@@ -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))
......
......@@ -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());
}
......
......@@ -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;
}
......
......@@ -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();
}
});
}
});
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment