Detecting SHIELD Portable at Runtime

Landscape-Only Device Detection

SHIELD portable is by nature a landscape-centric device. This can be detected using standard Android APIs, independent of any SHIELD-specific queries. It can be a very useful way to detect TV-centric devices and other landscape-only systems. It also cleanly splits the detection of orientation support from detecting SHIELD portable specifically. However, keep in mind that detecting landscape-only support is not in and of itself proof that the device is SHIELD.

Detecting landscape-only support is extremely simple within a Java Activity. However, note that it requires one additional check than might be expected. Specifically, devices that support both orientations need not expose either orientation feature flag. So in order to detect landscape-only, we must detect "landscape AND NOT portrait," as follows:

boolean portrait = getPackageManager().hasSystemFeature(
     PackageManager.FEATURE_SCREEN_PORTRAIT);
boolean landscape = getPackageManager().hasSystemFeature(
     PackageManager.FEATURE_SCREEN_LANDSCAPE);

if (landscape && !portrait) {
     // Device is a landscape-only device (e.g. SHIELD)
} else if (!landscape && portrait) {
     // Device is a portrait-only device
} else {
     // Device supports both orientations
}

There are only three cases in this conditional, since both "landscape AND portrait" and no indication of either feature imply that both orientations are supported. This is to preserve compatibility with older Android platforms.

SHIELD Controller Detection

Existence of the SHIELD controller at runtime can be detected by its standardized naming. In Android Java code, you would use something like:

boolean hasNVController = false;
final int[] devids = InputDevice.getDeviceIds();
for (int id : devids)
{
     InputDevice dev = InputDevice.getDevice(id);
     hasNVController = dev.getName().contains("NVIDIA Controller");
     if (hasNVController) break;
}
Note that certain earlier SHIELD development kit firmware has the controller (getName) name string of nvidia_joypad. When testing on a SHIELD devkit, this alternative name should trigger SHIELD control configuration as well.

Detecting the availability of a SHIELD controller on the current platform is most useful for pre-mapping controls to reasonable defaults; however,if you map to the NVIDIA amalgamated controls, you will pick up all existing gamepads that have proper layout.

Note that the entire SHIELD controller name string in Java is something of the form:

NVIDIA Corporation NVIDIA Controller v01.01

You should not try to match on the entire string, to avoid your application failing proper detection on a future device or even just a future revision of the firmware. Rather, we recommend looking for just the NVIDIA Controller substring. The version number is there simply to allow future NVIDIA expansion/enhancement.

General SHIELD Portable Detection

Performance profiles can be preset on SHIELD based on simple detection via the Android build strings, using Java code like:

boolean modelIsShield = android.os.Build.MODEL.startsWith("SHIELD");

We strongly recommend you use startsWith for comparison, in order to ensure broadest compatibility with any future hardware revisions.

 

 


NVIDIA® GameWorks™ Documentation Rev. 1.0.200608 ©2014-2020. NVIDIA Corporation. All Rights Reserved.