Question

I am new to android framework. I am working with USB Settings. I want to know where are USB settings stored in android. I am having following problem : when i connect my phone to Computer and select one of the option from mass storage, MTP,PTP and now if I switch off and then switch on the device my selection get cleared. I want the previous selection to be retained. What should I do..??

Thanks in advance...

Edit : I discovered today that usb_device_manager.xml file should be created in /data/system folder but in my case it is not getting generated. I am unable to find what is the reason behind this. The file that creates this file is located at frameworks/base/services/java/com/android/server/usb/

Waiting for positive reply...

Was it helpful?

Solution

According to http://developer.android.com/reference/android/hardware/usb/UsbManager.html You cannot find an open API for getting this information. However, from the source code we can see this two functions:

/**
 * Name of the MTP USB function.
 * Used in extras for the {@link #ACTION_USB_STATE} broadcast
 *
 * {@hide}
 */
public static final String USB_FUNCTION_MTP = "mtp";

/**
 * Name of the PTP USB function.
 * Used in extras for the {@link #ACTION_USB_STATE} broadcast
 *
 * {@hide}
 */
public static final String USB_FUNCTION_PTP = "ptp";


 /**
     * Returns the current default USB function.
     *
     * @return name of the default function.
     *
     * {@hide}
     */
    public String getDefaultFunction() {
        String functions = SystemProperties.get("persist.sys.usb.config", "");
        int commaIndex = functions.indexOf(',');
        if (commaIndex > 0) {
            return functions.substring(0, commaIndex);
        } else {
            return functions;
        }
    }

    /**
     * Sets the current USB function.
     * If function is null, then the current function is set to the default function.
     *
     * @param function name of the USB function, or null to restore the default function
     * @param makeDefault true if the function should be set as the new default function
     *
     * {@hide}
     */
    public void setCurrentFunction(String function, boolean makeDefault) {
        try {
            mService.setCurrentFunction(function, makeDefault);
        } catch (RemoteException e) {
            Log.e(TAG, "RemoteException in setCurrentFunction", e);
        }
    }

It is not recommended to use hidden APIs, but this might solve your problem. If you wants to know how to use the hidden APIs, refer to this link: http://devmaze.wordpress.com/2011/01/18/using-com-android-internal-part-1-introduction/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top