private String getDefaultFunctions() { String func = SystemProperties.get(USB_PERSISTENT_CONFIG_PROPERTY, UsbManager.USB_FUNCTION_NONE); if (UsbManager.USB_FUNCTION_NONE.equals(func)) { func = UsbManager.USB_FUNCTION_MTP; } return func; }
public UsbHandler(Looper looper) { super(looper); try { // Restore default functions. mCurrentFunctions = SystemProperties.get(USB_CONFIG_PROPERTY, UsbManager.USB_FUNCTION_NONE); if (UsbManager.USB_FUNCTION_NONE.equals(mCurrentFunctions)) { mCurrentFunctions = UsbManager.USB_FUNCTION_MTP; } mCurrentFunctionsApplied = mCurrentFunctions.equals(SystemProperties.get(USB_STATE_PROPERTY)); mAdbEnabled = UsbManager.containsFunction(getDefaultFunctions(), UsbManager.USB_FUNCTION_ADB); setEnabledFunctions(null, false); String state = FileUtils.readTextFile(new File(STATE_PATH), 0, null).trim(); updateState(state); // register observer to listen for settings changes mContentResolver.registerContentObserver( Settings.Global.getUriFor(Settings.Global.ADB_ENABLED), false, new AdbSettingsObserver()); mContentResolver.registerContentObserver( Settings.Secure.getUriFor(Settings.Secure.ADB_NOTIFY), false, new ContentObserver(null) { public void onChange(boolean selfChange) { updateAdbNotification(); } }); // Watch for USB configuration changes mUEventObserver.startObserving(USB_STATE_MATCH); mUEventObserver.startObserving(ACCESSORY_START_MATCH); } catch (Exception e) { Slog.e(TAG, "Error initializing UsbHandler", e); } }