How to set TestNG to run which test that available

Option1

Just delegate testNG xml generation to some pre-build CI step.

Create a class, which e.g. checks adb devices list and includes or excludes some xml parts.

Run the class and generate xml and use it in test run.

Option2

Use IAnnotationTransformListener to disable tests based on some logic.

You have to define somehow which test depends on which device. In your example, I see you can retrieve this from the class package name. Then you have to check if the device is connected and disable the test if needed.

https://techfortesting.wordpress.com/2019/12/27/iannotation-transformer/

Note: you have to apply this listener in xml, not in the code. This is because it should be applied in the early stage of TestNG execution.

Sorry, I've not provided the final code snippets, because it takes time to implement this.