Android Open Source - androiddevice.info Usb Property






From Project

Back to project page androiddevice.info.

License

The source code is released under:

GNU General Public License

If you think the Android project androiddevice.info listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package info.androiddevice.deviceinventory.info;
//from   w ww. j  a v a 2  s.  c  o m
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import static info.androiddevice.deviceinventory.info.Utils.readFile;

public class UsbProperty implements Property {
    private final List<String> keys = new ArrayList<String>() {{
        add("iManufacturer");
        add("iProduct");
        add("idProduct");
        add("idVendor");
    }};
    @Override
    public Object getProperty() {
        JSONObject jsonObject = new JSONObject();
        for(String key:keys) {
            try {
                String deviceFolder = "/sys/devices/virtual/android_usb/android0/";
                String value = readFile(new File(deviceFolder, key));
                jsonObject.put(key, value.trim());
            } catch (Exception e) {
                try {
                    jsonObject.put(key, JSONObject.NULL);
                } catch (JSONException e1) {}
            }
        }
        return jsonObject;
    }

    @Override
    public String getName() {
        return "usb";
    }
}




Java Source Code List

android.system.ErrnoException.java
android.system.Os.java
android.system.StructStat.java
info.androiddevice.deviceinventory.Application.java
info.androiddevice.deviceinventory.DeviceInformation.java
info.androiddevice.deviceinventory.Error.java
info.androiddevice.deviceinventory.info.CpuinfoProperty.java
info.androiddevice.deviceinventory.info.DirProperty.java
info.androiddevice.deviceinventory.info.DisplayProperty.java
info.androiddevice.deviceinventory.info.EnvironmentProperty.java
info.androiddevice.deviceinventory.info.FeaturesProperty.java
info.androiddevice.deviceinventory.info.FileProperty.java
info.androiddevice.deviceinventory.info.GetPropProperty.java
info.androiddevice.deviceinventory.info.JavaSystemProperty.java
info.androiddevice.deviceinventory.info.MeminfoProperty.java
info.androiddevice.deviceinventory.info.MountsProperty.java
info.androiddevice.deviceinventory.info.NameProperty.java
info.androiddevice.deviceinventory.info.OtacertsProperty.java
info.androiddevice.deviceinventory.info.PackageSigProperty.java
info.androiddevice.deviceinventory.info.Property.java
info.androiddevice.deviceinventory.info.SharedLibraryNamesProperty.java
info.androiddevice.deviceinventory.info.UsbProperty.java
info.androiddevice.deviceinventory.info.Utils.java
info.androiddevice.deviceinventory.info.VersionProperty.java
info.androiddevice.deviceinventory.submission.DeviceInformationListAdapter.java
info.androiddevice.deviceinventory.submission.MainActivity.java
libcore.io.ErrnoException.java
libcore.io.Libcore.java
libcore.io.Os.java
libcore.io.StructStat.java
name.unused.android.utils.systemproperties.SystemProperty.java
name.unused.android.utils.systemproperties.exception.NoSuchPropertyException.java