package com.xugame.gameconsole;

import androidx.appcompat.app.AppCompatActivity;

import android.Manifest;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.media.AudioManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.xugame.BuildConfig;
import com.xugame.gameconsole.dialog.LoadingDialog;
import com.xugame.gameconsole.emulator.RetroArchEmulatorActivity;
import com.xugame.gameconsole.preferences.UserPreferences;
import com.xugame.gameconsole.util.CheckFileCRC;
import com.xugame.gameconsole.util.CheckFileCRCListener;
import com.xugame.gameconsole.util.DebugUtil;
import com.xugame.gameconsole.util.Util;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

public class MainActivity extends PreferenceActivity implements View.OnClickListener,
        CheckFileCRCListener {
    private static final String TAG = "MainActivityTAG";
    private EditText mETRom, mETLib, mETConfig;
    private Button mBtnLocalGame, mBtnNetP1, mBtnNetP2;

    final private int REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS = 124;
    public static String PACKAGE_NAME;
    boolean checkPermissions = false;
    private LoadingDialog mLoadingDialog;
    private CheckFileCRC mCheckFileCRC;
    private int retryCOUNT = 0;

    public void showMessageOKCancel(String message, DialogInterface.OnClickListener onClickListener) {
        new AlertDialog.Builder(this).setMessage(message)
                .setPositiveButton("OK", onClickListener).setCancelable(false)
                .setNegativeButton("Cancel", null).create().show();
    }

    private boolean addPermission(List<String> permissionsList, String permission) {
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
            if (checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
                permissionsList.add(permission);

                // Check for Rationale Option
                if (!shouldShowRequestPermissionRationale(permission))
                    return false;
            }
        }
        return true;
    }

    public void checkRuntimePermissions() {
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
            // Android 6.0+ needs runtime permission checks
            List<String> permissionsNeeded = new ArrayList<String>();
            final List<String> permissionsList = new ArrayList<String>();

            if (!addPermission(permissionsList, Manifest.permission.READ_EXTERNAL_STORAGE))
                permissionsNeeded.add("Read External Storage");
            if (!addPermission(permissionsList, Manifest.permission.WRITE_EXTERNAL_STORAGE))
                permissionsNeeded.add("Write External Storage");

            if (permissionsList.size() > 0) {
                checkPermissions = true;

                if (permissionsNeeded.size() > 0) {
                    // Need Rationale
                    Log.i("MainMenuActivity", "Need to request external storage permissions.");

                    String message = "You need to grant access to " + permissionsNeeded.get(0);

                    for (int i = 1; i < permissionsNeeded.size(); i++)
                        message = message + ", " + permissionsNeeded.get(i);

                    showMessageOKCancel(message,
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    if (which == AlertDialog.BUTTON_POSITIVE) {
                                        requestPermissions(permissionsList.toArray(new String[permissionsList.size()]),
                                                REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS);

                                        Log.i("MainMenuActivity", "User accepted request for external storage permissions.");
                                    }
                                }
                            });
                } else {
                    requestPermissions(permissionsList.toArray(new String[permissionsList.size()]),
                            REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS);

                    Log.i("MainMenuActivity", "Requested external storage permissions.");
                }
            }
        }

        if (!checkPermissions) {
            finalStartup();
        }
    }

    public void finalStartup() {
        final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        Intent retro = new Intent(this, RetroArchEmulatorActivity.class);

//        retro.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//        retro.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        startRetroActivity(
                retro,
                romPath,
//                prefs.getString("libretro_path", getApplicationInfo().dataDir + "/cores/fbalpha2012_neogeo_libretro_android.so"),
                prefs.getString("libretro_path", corePath),
                UserPreferences.getDefaultConfigPath(this),
                Settings.Secure.getString(getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD),
                getApplicationInfo().dataDir,
                getApplicationInfo().sourceDir);
        startActivity(retro);
        finish();
    }

    public static void startRetroActivity(Intent retro, String contentPath, String corePath,
                                          String configFilePath, String imePath, String dataDirPath, String dataSourcePath) {
        if (contentPath != null) {
            retro.putExtra("ROM", contentPath);
        }
        retro.putExtra("LIBRETRO", corePath);
        retro.putExtra("CONFIGFILE", configFilePath);
        retro.putExtra("IME", imePath);
        retro.putExtra("DATADIR", dataDirPath);
        retro.putExtra("APK", dataSourcePath);
        retro.putExtra("SDCARD", Environment.getExternalStorageDirectory().getAbsolutePath());
        String external = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/" + PACKAGE_NAME + "/files";
        retro.putExtra("EXTERNAL", external);
        Log.i("TEST_STAT", "rompath=" + contentPath + "\ncorePath=" + corePath + "\n" + "configFilePath=" + configFilePath + "\nimePath=" + imePath
                + "\nDATADIR=" + dataDirPath + "\nAPK=" + dataSourcePath +
                "\nSDCARD=" + Environment.getExternalStorageDirectory().getAbsolutePath() + "\nEXTERNAL="
                + external);
        retro.putExtra("screenMode", screenMode);
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        switch (requestCode) {
            case REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS:
                for (int i = 0; i < permissions.length; i++) {
                    if (grantResults[i] == PackageManager.PERMISSION_GRANTED) {
                        Log.i("MainMenuActivity", "Permission: " + permissions[i] + " was granted.");
                    } else {
                        Log.i("MainMenuActivity", "Permission: " + permissions[i] + " was not granted.");
                    }
                }

                break;
            default:
                super.onRequestPermissionsResult(requestCode, permissions, grantResults);
                break;
        }

        finalStartup();
    }

    private String baseUsbPath, corePath, romPath, coreName;
    private static int screenMode = 0;
    private String romName;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_main);
//        this.findView();
        Util.init(this);
        PACKAGE_NAME = getPackageName();
        baseUsbPath = getIntent().getStringExtra("baseUsbPath");
        romPath = getIntent().getStringExtra("romPath");
        corePath = getIntent().getStringExtra("corePath");
        coreName = getIntent().getStringExtra("coreName");
        screenMode = getIntent().getIntExtra("screenMode", 0);
        BuildConfig.FIRST_DEVICE_ID = getIntent().getIntExtra("first_device_id", -1);
        DebugUtil.i(TAG,"DEFAULT_DEVICE"+BuildConfig.FIRST_DEVICE_ID);
        mLoadingDialog = new LoadingDialog(this);
        checkCores();
//        checkRobot();
    }

    private void checkRobot() {
        File file = new File(this.getFilesDir().getParent() + File.separator + "autoconfig/android/robot.cfg");
        if (!file.exists()) {
            DebugUtil.i("", "复制robot" + file.getAbsolutePath());
            try {
                InputStream in = getResources().openRawResource(R.raw.robot);
//            in = this.getResources().getAssets().open("xucores/"+fileName);
//                in = new FileInputStream(file);
                BufferedOutputStream outStream
                        = new BufferedOutputStream(new FileOutputStream(getFilesDir().getParent() + File.separator + "autoconfig/android/robot.cfg", false));
                byte[] buffer = new byte[1024];
                int size;
                while ((size = in.read(buffer)) > 0) {
                    outStream.write(buffer, 0, size);
                }
                in.close();
                outStream.flush();
                outStream.close();


            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    private void checkCores() {
        if (mLoadingDialog != null)
            mLoadingDialog.show();
        if (TextUtils.isEmpty(corePath)) {
            finish();
        }
        File file = new File(corePath);
        if (file.exists()) {
            DebugUtil.i(TAG, "core is exists,to check" + coreName);
            if (coreName.equals("fbalpha2012_libretro_android.so")) {
                //不校验
                DebugUtil.i(TAG, "不校验" + coreName);
                file.delete();
                startCopy(coreName, corePath);
            } else
                toCheckCrc(file.getAbsolutePath());
//            start();
        } else {
            DebugUtil.i(TAG, "core not exists,to copy");
            startCopy(coreName, corePath);
        }
    }

    private void toCheckCrc(String path) {
        mCheckFileCRC = new CheckFileCRC(this, this);
        mCheckFileCRC.check(path);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mLoadingDialog != null && mLoadingDialog.isShowing())
            mLoadingDialog.dismiss();
    }

    private void startCopy(final String fileName, final String toPath) {
        File file = new File(this.getFilesDir().getParent() + File.separator + "cores");
        DebugUtil.i(TAG, "core path=" + file.getAbsolutePath());
        if (!file.exists())
            file.mkdirs();
        new AsyncTask<String, Integer, String>() {
            @Override
            protected String doInBackground(String... strings) {
                copyFile(getFilesDir().getParent() + File.separator + "cores/" + fileName, fileName);
                return null;
            }

            @Override
            protected void onPostExecute(String s) {
//                start();
                if (coreName.equals("fbalpha2012_libretro_android.so")) {
                    //不校验
                    start();
                } else
                    toCheckCrc(corePath);

                super.onPostExecute(s);
            }
        }.execute("");
    }


    private boolean copyFile(String file_path, String fileName) {
//        File baseFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/arcade/cores/");
//        if (!baseFile.exists())//创建/arcade/cores文件夹
//            baseFile.mkdirs();
//        File file;
//        if (!TextUtils.isEmpty(baseUsbPath)) {
//            file = new File(baseUsbPath + "/cores/" + fileName);
//        } else
//            file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/arcade/cores/" + fileName);
//20231207修改cores默认路径为本机存储/cores


        File file;
            file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/cores/" + fileName);

        DebugUtil.i(TAG, "从" + file.getAbsolutePath() + "复制");
        if (!file.exists())//检测cores文件夹下是否存在.so
            return false;
        DebugUtil.i("COPY:", file.getAbsolutePath());

        try {
            InputStream in = null;
//            in = this.getResources().getAssets().open("xucores/"+fileName);
            in = new FileInputStream(file);
            BufferedOutputStream outStream
                    = new BufferedOutputStream(new FileOutputStream(file_path, false));
            byte[] buffer = new byte[1024];
            int size;
            while ((size = in.read(buffer)) > 0) {
                outStream.write(buffer, 0, size);
            }
            in.close();
            outStream.flush();
            outStream.close();

            return true;

        } catch (IOException e) {
            DebugUtil.i(TAG, "IOException");
            e.printStackTrace();
        }

        return false;
    }

    private void start() {
        // Bind audio stream to hardware controls.
        setVolumeControlStream(AudioManager.STREAM_MUSIC);

        UserPreferences.updateConfigFile(this, baseUsbPath + File.separator + "/system");

        checkRuntimePermissions();
        if (mLoadingDialog != null && mLoadingDialog.isShowing())
            mLoadingDialog.dismiss();
    }

    private void findView() {
        this.mBtnLocalGame = findViewById(R.id.btn_start_local_game);
        this.mBtnNetP1 = findViewById(R.id.btn_start_net_game_p1);
        this.mBtnNetP2 = findViewById(R.id.btn_start_net_game_p2);
        this.mETRom = findViewById(R.id.et_rom);
        this.mETLib = findViewById(R.id.et_libs);
        this.mETConfig = findViewById(R.id.et_config);
        this.mBtnLocalGame.setOnClickListener(this);
        this.mBtnNetP1.setOnClickListener(this);
        this.mBtnNetP1.setOnClickListener(this);
    }


    @Override
    public void onClick(View view) {

        if (view == mBtnLocalGame) {

            if (!checkPermissions) {
                finalStartup();
            }

//            String PACKAGE_NAME = this.getPackageName();
//            Intent retro = new Intent(this, RetroArchEmulatorActivity.class);
//            retro.putExtra("ROM", "/storage/emulated/0/arcade/rom/kofxi.zip");
//            retro.putExtra("LIBRETRO", "/data/data/com.xugame.gameconsole/cores/flycast_libretro_android.so");
////            retro.putExtra("ROM", "");
////            retro.putExtra("LIBRETRO", "");
//
//            retro.putExtra("CONFIGFILE", "/storage/emulated/0/Android/data/com.xugame.gameconsole/files/retroarch.cfg");
//            retro.putExtra("IME", "com.android.inputmethod.latin/.LatinIME");
//            retro.putExtra("DATADIR", "/data/user/0/com.xugame.gameconsole");
//            retro.putExtra("APK", "/data/app/com.xugame.gameconsole-1/base.apk");
//            retro.putExtra("SDCARD", Environment.getExternalStorageDirectory().getAbsolutePath());
//            String external = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/" + PACKAGE_NAME + "/files";
//            retro.putExtra("EXTERNAL", external);
//            startActivity(retro);
        }

    }

    @Override
    public void onCheckCoresCRCDone(String crc, String defaultCRC) {
        DebugUtil.i(TAG, "onCheckCoresCRCDone" + crc + "-" + defaultCRC);
        if (crc.equals(defaultCRC)) {
            start();
        } else {
            onCheckCoresCRCError(-3);
        }
    }

    @Override
    public void onCheckCoresCRCError(int error) {
        DebugUtil.i(TAG, "onCheckCoresCRCError" + error);
        if (retryCOUNT < 3) {
            retryCOUNT++;
            startCopy(coreName, corePath);
        } else {
            retryCOUNT = 0;
            Toast.makeText(this, "cores is error", Toast.LENGTH_SHORT).show();
            finish();
        }
    }

//    2023-11-01 11:07:45.634 7083-7083/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: passPermissons
//2023-11-01 11:07:45.636 7083-7083/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: aaaaaaaaaa
//2023-11-01 11:07:45.719 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: 2048_libretro_android.so==1042003817
//            2023-11-01 11:07:45.771 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: 3dengine_libretro_android.so==1535549497
//            2023-11-01 11:07:45.796 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: 81_libretro_android.so==3797825066
//            2023-11-01 11:07:45.808 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: a5200_libretro_android.so==3869894026
//            2023-11-01 11:07:45.841 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: arduous_libretro_android.so==780006344
//            2023-11-01 11:07:45.866 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: atari800_libretro_android.so==3982345270
//            2023-11-01 11:07:45.877 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: bk_libretro_android.so==3404889964
//            2023-11-01 11:07:45.931 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: bluemsx_libretro_android.so==2174918511
//            2023-11-01 11:07:45.981 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: bsnes2014_accuracy_libretro_android.so==4004440739
//            2023-11-01 11:07:46.026 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: bsnes2014_balanced_libretro_android.so==3040064712
//            2023-11-01 11:07:46.069 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: bsnes2014_performance_libretro_android.so==3696944667
//            2023-11-01 11:07:46.099 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: bsnes_cplusplus98_libretro_android.so==1869373139
//            2023-11-01 11:07:46.151 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: bsnes_hd_beta_libretro_android.so==382458000
//            2023-11-01 11:07:46.256 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: bsnes_libretro_android.so==3307173016
//            2023-11-01 11:07:46.318 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: bsnes_mercury_accuracy_libretro_android.so==3911464644
//            2023-11-01 11:07:46.367 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: bsnes_mercury_balanced_libretro_android.so==252543078
//            2023-11-01 11:07:46.490 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: bsnes_mercury_performance_libretro_android.so==1625131764
//            2023-11-01 11:07:46.528 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: cannonball_libretro_android.so==2880937827
//            2023-11-01 11:07:46.594 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: cap32_libretro_android.so==2493288555
//            2023-11-01 11:07:46.734 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: chailove_libretro_android.so==1375760160
//            2023-11-01 11:07:46.776 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: craft_libretro_android.so==1081743909
//            2023-11-01 11:07:46.799 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: crocods_libretro_android.so==1627025149
//            2023-11-01 11:07:46.880 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: daphne_libretro_android.so==1749009889
//            2023-11-01 11:07:46.956 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: desmume2015_libretro_android.so==3350467466
//            2023-11-01 11:07:47.054 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: desmume_libretro_android.so==2142315990
//            2023-11-01 11:07:47.089 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: dinothawr_libretro_android.so==205446461
//            2023-11-01 11:07:47.119 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: dirksimple_libretro_android.so==1067967961
//            2023-11-01 11:07:47.265 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: dosbox_core_libretro_android.so==1427022774
//            2023-11-01 11:07:47.403 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: dosbox_pure_libretro_android.so==572308854
//            2023-11-01 11:07:47.529 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: dosbox_svn_libretro_android.so==2385688716
//            2023-11-01 11:07:48.026 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: easyrpg_libretro_android.so==2585895017
//            2023-11-01 11:07:48.077 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: ecwolf_libretro_android.so==2475511887
//            2023-11-01 11:07:48.228 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: ep128emu_core_libretro_android.so==1052432164
//            2023-11-01 11:07:48.314 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: fbalpha2012_cps1_libretro_android.so==1386541134
//            2023-11-01 11:07:48.394 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: fbalpha2012_cps2_libretro_android.so==3732721916
//            2023-11-01 11:07:48.420 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: fbalpha2012_cps3_libretro_android.so==2416818326
//            2023-11-01 11:07:48.996 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: fbalpha2012_libretro_android.so==147964066
//            2023-11-01 11:07:49.059 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: fbalpha2012_neogeo_libretro_android.so==1517614885
//            2023-11-01 11:07:50.397 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: fbalpha_libretro_android.so==1536260623
//            2023-11-01 11:07:52.070 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: fbneo_libretro_android.so==1018321941
//            2023-11-01 11:07:52.158 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: fceumm_libretro_android.so==1950764938
//            2023-11-01 11:07:52.665 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: ffmpeg_libretro_android.so==587118488
//            2023-11-01 11:07:53.821 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: flycast_libretro_android.so==880260156
//            2023-11-01 11:07:53.831 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: fmsx_libretro_android.so==3889882656
//            2023-11-01 11:07:53.837 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: freechaf_libretro_android.so==2075251627
//            2023-11-01 11:07:53.844 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: freeintv_libretro_android.so==516128921
//            2023-11-01 11:07:53.873 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: frodo_libretro_android.so==2469160198
//            2023-11-01 11:07:53.933 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: fuse_libretro_android.so==3857999837
//            2023-11-01 11:07:53.946 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: galaksija_libretro_android.so==999199391
//            2023-11-01 11:07:54.031 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: gambatte_libretro_android.so==3111808968
//            2023-11-01 11:07:54.057 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: gearboy_libretro_android.so==4188330667
//            2023-11-01 11:07:54.087 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: gearcoleco_libretro_android.so==1921185480
//            2023-11-01 11:07:54.114 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: gearsystem_libretro_android.so==3669451411
//            2023-11-01 11:07:54.370 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: genesis_plus_gx_libretro_android.so==3411919808
//            2023-11-01 11:07:54.625 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: genesis_plus_gx_wide_libretro_android.so==3033288201
//            2023-11-01 11:07:54.642 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: gme_libretro_android.so==910154216
//            2023-11-01 11:07:54.644 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: gong_libretro_android.so==510552488
//            2023-11-01 11:07:54.682 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: gpsp_libretro_android.so==3115776383
//            2023-11-01 11:07:54.705 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: gw_libretro_android.so==78719041
//            2023-11-01 11:07:54.731 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: handy_libretro_android.so==1857042333
//            2023-11-01 11:07:54.800 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: hatari_libretro_android.so==4002646417
//            2023-11-01 11:07:54.804 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: jaxe_libretro_android.so==2538426728
//            2023-11-01 11:07:54.809 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: jumpnbump_libretro_android.so==2835147507
//            2023-11-01 11:07:54.816 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: lowresnx_libretro_android.so==2020869293
//            2023-11-01 11:07:54.897 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: lutro_libretro_android.so==1367222163
//            2023-11-01 11:07:55.241 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: mame2000_libretro_android.so==3850503187
//            2023-11-01 11:07:56.154 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: mame2003_libretro_android.so==1483054888
//            2023-11-01 11:07:56.239 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: mame2003_midway_libretro_android.so==2944755977
//            2023-11-01 11:07:57.193 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: mame2003_plus_libretro_android.so==2050019383
//            2023-11-01 11:07:58.691 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: mame2010_libretro_android.so==658690590
//            2023-11-01 11:08:05.747 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: mamearcade_libretro_android.so==3141440399
//            2023-11-01 11:08:05.772 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: mednafen_gba_libretro_android.so==3627362044
//            2023-11-01 11:08:05.789 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: mednafen_lynx_libretro_android.so==3022889740
//            2023-11-01 11:08:05.806 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: mednafen_ngp_libretro_android.so==997079995
//            2023-11-01 11:08:05.899 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: mednafen_pce_fast_libretro_android.so==301716041
//            2023-11-01 11:08:06.009 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: mednafen_pce_libretro_android.so==2459283410
//            2023-11-01 11:08:06.065 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: mednafen_pcfx_libretro_android.so==920163216
//            2023-11-01 11:08:06.342 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: mednafen_psx_hw_libretro_android.so==2978947402
//            2023-11-01 11:08:06.532 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: mednafen_psx_libretro_android.so==1510037674
//            2023-11-01 11:08:06.717 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: mednafen_saturn_libretro_android.so==356920118
//            2023-11-01 11:08:06.773 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: mednafen_snes_libretro_android.so==1257017063
//            2023-11-01 11:08:06.847 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: mednafen_supafaust_libretro_android.so==4081301686
//            2023-11-01 11:08:06.925 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: mednafen_supergrafx_libretro_android.so==2594090264
//            2023-11-01 11:08:06.965 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: mednafen_vb_libretro_android.so==3256836489
//            2023-11-01 11:08:07.001 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: mednafen_wswan_libretro_android.so==3497937091
//            2023-11-01 11:08:07.082 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: melonds_libretro_android.so==2918883364
//            2023-11-01 11:08:07.145 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: mesen-s_libretro_android.so==1260744833
//            2023-11-01 11:08:07.296 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: mesen_libretro_android.so==2700063797
//            2023-11-01 11:08:07.318 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: meteor_libretro_android.so==3258943291
//            2023-11-01 11:08:07.401 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: mgba_libretro_android.so==2923170793
//            2023-11-01 11:08:07.425 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: minivmac_libretro_android.so==4156638768
//            2023-11-01 11:08:07.463 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: mojozork_libretro_android.so==2562154472
//            2023-11-01 11:08:07.848 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: mrboom_libretro_android.so==3736040718
//            2023-11-01 11:08:08.130 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: mupen64plus_next_gles2_libretro_android.so==92497630
//            2023-11-01 11:08:08.450 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: mupen64plus_next_gles3_libretro_android.so==914889182
//            2023-11-01 11:08:08.473 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: mu_libretro_android.so==643777069
//            2023-11-01 11:08:08.515 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: nekop2_libretro_android.so==145865232
//            2023-11-01 11:08:08.601 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: neocd_libretro_android.so==2661926962
//            2023-11-01 11:08:08.751 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: nestopia_libretro_android.so==2387233794
//            2023-11-01 11:08:08.821 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: np2kai_libretro_android.so==2954182638
//            2023-11-01 11:08:08.881 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: numero_libretro_android.so==1595551155
//            2023-11-01 11:08:08.915 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: nxengine_libretro_android.so==3498192948
//            2023-11-01 11:08:08.933 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: o2em_libretro_android.so==2159610848
//            2023-11-01 11:08:08.968 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: oberon_libretro_android.so==2524142882
//            2023-11-01 11:08:09.038 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: openlara_libretro_android.so==842639624
//            2023-11-01 11:08:09.081 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: opera_libretro_android.so==3164829577
//            2023-11-01 11:08:09.423 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: parallel_n64_libretro_android.so==3098451268
//            2023-11-01 11:08:09.479 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: pcsx_rearmed_libretro_android.so==1576915211
//            2023-11-01 11:08:09.545 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: picodrive_libretro_android.so==3845465822
//            2023-11-01 11:08:11.023 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: play_libretro_android.so==1988422128
//            2023-11-01 11:08:11.031 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: pocketcdg_libretro_android.so==1618466829
//            2023-11-01 11:08:11.082 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: pokemini_libretro_android.so==1592896062
//            2023-11-01 11:08:11.130 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: potator_libretro_android.so==3022486751
//            2023-11-01 11:08:11.768 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: ppsspp_libretro_android.so==820240270
//            2023-11-01 11:08:11.814 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: prboom_libretro_android.so==2332874982
//            2023-11-01 11:08:11.824 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: prosystem_libretro_android.so==2684419963
//            2023-11-01 11:08:12.267 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: puae2021_libretro_android.so==807296260
//            2023-11-01 11:08:13.077 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: puae_libretro_android.so==2126600417
//            2023-11-01 11:08:13.109 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: px68k_libretro_android.so==3887247101
//            2023-11-01 11:08:13.164 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: quasi88_libretro_android.so==2354749396
//            2023-11-01 11:08:13.202 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: quicknes_libretro_android.so==1635437732
//            2023-11-01 11:08:13.242 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: race_libretro_android.so==1179511441
//            2023-11-01 11:08:13.259 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: reminiscence_libretro_android.so==812522150
//            2023-11-01 11:08:13.321 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: retro8_libretro_android.so==1733843823
//            2023-11-01 11:08:13.336 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: sameboy_libretro_android.so==450186404
//            2023-11-01 11:08:13.343 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: sameduck_libretro_android.so==3214298071
//            2023-11-01 11:08:16.254 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: same_cdi_libretro_android.so==992935775
//            2023-11-01 11:08:18.569 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: scummvm_libretro_android.so==4100300513
//            2023-11-01 11:08:18.578 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: smsplus_libretro_android.so==1061157626
//            2023-11-01 11:08:18.613 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: snes9x2002_libretro_android.so==1832895834
//            2023-11-01 11:08:18.662 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: snes9x2005_libretro_android.so==265847001
//            2023-11-01 11:08:18.713 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: snes9x2005_plus_libretro_android.so==406882931
//            2023-11-01 11:08:18.807 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: snes9x2010_libretro_android.so==1912744787
//            2023-11-01 11:08:18.874 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: snes9x_libretro_android.so==1396374684
//            2023-11-01 11:08:18.879 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: squirreljme_libretro_android.so==1686990514
//            2023-11-01 11:08:18.995 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: stella2014_libretro_android.so==2694497635
//            2023-11-01 11:08:19.150 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: stella_libretro_android.so==2878062309
//            2023-11-01 11:08:19.257 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: superbroswar_libretro_android.so==1177918814
//            2023-11-01 11:08:19.441 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: swanstation_libretro_android.so==2189927838
//            2023-11-01 11:08:19.471 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: test_libretro_android.so==4072819540
//            2023-11-01 11:08:19.519 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: tgbdual_libretro_android.so==4118501607
//            2023-11-01 11:08:19.652 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: theodore_libretro_android.so==1794530955
//            2023-11-01 11:08:19.836 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: thepowdertoy_libretro_android.so==1431444086
//            2023-11-01 11:08:19.941 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: tic80_libretro_android.so==3523696412
//            2023-11-01 11:08:19.972 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: tyrquake_libretro_android.so==4011954349
//            2023-11-01 11:08:19.984 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: uw8_libretro_android.so==707177494
//            2023-11-01 11:08:19.995 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: uzem_libretro_android.so==4025363444
//            2023-11-01 11:08:20.035 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: vaporspec_libretro_android.so==62375315
//            2023-11-01 11:08:20.117 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: vbam_libretro_android.so==2529213728
//            2023-11-01 11:08:20.144 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: vba_next_libretro_android.so==3272353476
//            2023-11-01 11:08:20.152 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: vecx_libretro_android.so==3708413075
//            2023-11-01 11:08:20.172 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: vemulator_libretro_android.so==1403685916
//            2023-11-01 11:08:20.314 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: vice_x128_libretro_android.so==77282354
//            2023-11-01 11:08:20.436 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: vice_x64sc_libretro_android.so==502339610
//            2023-11-01 11:08:20.553 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: vice_x64_libretro_android.so==3744918022
//            2023-11-01 11:08:20.653 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: vice_xcbm2_libretro_android.so==3472472312
//            2023-11-01 11:08:20.771 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: vice_xcbm5x0_libretro_android.so==41796132
//            2023-11-01 11:08:20.872 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: vice_xpet_libretro_android.so==3282819252
//            2023-11-01 11:08:21.012 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: vice_xplus4_libretro_android.so==262861266
//            2023-11-01 11:08:21.156 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: vice_xscpu64_libretro_android.so==3181671713
//            2023-11-01 11:08:21.257 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: vice_xvic_libretro_android.so==2385615623
//            2023-11-01 11:08:21.340 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: virtualjaguar_libretro_android.so==3681754840
//            2023-11-01 11:08:21.370 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: virtualxt_libretro_android.so==1112863931
//            2023-11-01 11:08:21.424 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: vitaquake2-rogue_libretro_android.so==3746780493
//            2023-11-01 11:08:21.474 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: vitaquake2-xatrix_libretro_android.so==1734504512
//            2023-11-01 11:08:21.526 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: vitaquake2-zaero_libretro_android.so==3920496352
//            2023-11-01 11:08:21.574 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: vitaquake2_libretro_android.so==1500644696
//            2023-11-01 11:08:21.583 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: wasm4_libretro_android.so==4263425003
//            2023-11-01 11:08:21.647 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: x1_libretro_android.so==265044321
//            2023-11-01 11:08:21.667 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: xrick_libretro_android.so==3169920846
//            2023-11-01 11:08:21.737 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: yabasanshiro_libretro_android.so==1494296251
//            2023-11-01 11:08:21.826 7083-7099/com.xugame.TestSomeThing1 I/TestCircleActivityTAG: yabause_libretro_android.so==1201015839

}