Reputation: 114
Morning, folks!
I'm porting a desktop OpenGL c++ app to Android. This app is already fairly cross-platform. It requires reliable rendering on all platforms, so it accounts for differences in graphics driver implementations by enabling or disabling certain code paths based on the the host OS and the card's PCI information. Specifically, it switches over the device, vendor, and revision IDs.
I need to get these PCI IDs from within Android.
I'd prefer to do it programmatically from native code, but a JNI path or even parsing output of an external command are reasonable alternatives.
I've been looking around but I can't find anything reliable. Any google search I can come up with involving Android and PCI or ID, even with a ton of filtering, returns getting the Android device's ID, a database or list of all known PCI device IDs, or the PCI Security Standards Council. Nothing about actual PCI headers. Maybe I just need more google-fu?
There is no lspci on Android. Poking around in adb shell, I see that there is no accessible /sys filesystem and /proc/bus/pci/devices is empty. The closest I've seen is /proc/device-tree/nvidia-boardids on a Tegra, which prints out a fairly cryptic string that I'm pretty sure contains these IDs. This will probably work for devices which have it, but that's only the subset of devices running nVidia cards.
As a last resort, we can probably use the info that comes back from glGetString, but that varies far more than PCI IDs. I would strongly prefer avoiding this route.
This app is meant for Google Play distribution, so I absolutely cannot root these devices.
Any ideas?
Thanks!
Upvotes: 1
Views: 2706
Reputation: 103
Here is the java class
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.CellInfo;
import android.telephony.CellInfoLte;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.Window;
import android.widget.TextView;
import java.util.List;
public class MainActivity extends AppCompatActivity {
phoneStateListener listener;
TelephonyManager telephonyManager;
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
telephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
listener = new phoneStateListener();
telephonyManager.listen(listener,PhoneStateListener.LISTEN_CELL_INFO);
tv = (TextView) findViewById(R.id.tv);
}
@Override
protected void onResume() {
super.onResume();
}
public class phoneStateListener extends PhoneStateListener{
public phoneStateListener(){
}
@Override
public void onCellInfoChanged(List<CellInfo> cellInfo) {
super.onCellInfoChanged(cellInfo);
for(CellInfo m: cellInfo)
if (m instanceof CellInfoLte){
CellInfoLte cellInfoLte=(CellInfoLte) m;
int pciNum = cellInfoLte.getCellIdentity().getPci();
Log.d("onCellInfoChanged", "CellInfoLte--" + m);
tv.setText("PCINUMBER: "+pciNum);
}
}
}
@Override
protected void onStop() {
super.onStop();
telephonyManager = null;
}
}
Don't forget to use permission android.permission.READ_PHONE_STATE android.permission.ACCESS_COARSE_LOCATION
Upvotes: 1