B2G/gecko/dom/system/gonk/net_worker.js
/**
 * Modify usb function's property to turn on USB RNDIS function
 */
Modify usb function's property to turn on USB RNDIS function
Modify usb function ' s property to turn on USB RNDIS function
function enableUsbRndis(params) {
  let report = params.report;
  let retry = 0;
   On the otoro/unagi, persist.sys.usb.config should be one of:
      diag,modem,nmea,mass_storage
      diag,modem,nmea,mass_storage,adb
   When rndis is enabled, sys.usb.config should be one of:
      rdnis
      rndis,adb
   and when rndis is disabled, it should revert to persist.sys.usb.config
  let currentConfig = libcutils.property_get(SYS_USB_CONFIG_PROPERTY);
  let configFuncs = currentConfig.split(",");
  let persistConfig = libcutils.property_get(PERSIST_SYS_USB_CONFIG_PROPERTY);
  let persistFuncs = persistConfig.split(",");
  if (params.enable) {
    configFuncs = [USB_FUNCTION_RNDIS];
    if (persistFuncs.indexOf(USB_FUNCTION_ADB) >= 0) {
      configFuncs.push(USB_FUNCTION_ADB);
    }
  } else {
     We're turning rndis off, revert back to the persist setting.
     adb will already be correct there, so we don't need to do any
     further adjustments.
    configFuncs = persistFuncs;
  }
  let newConfig = configFuncs.join(",");
  if (newConfig != currentConfig) {
    libcutils.property_set(SYS_USB_CONFIG_PROPERTY, newConfig);
  }
   Trigger the timer to check usb state and report the result to NetworkManager.
  if (report) {
    setTimeout(checkUsbRndisState, USB_FUNCTION_RETRY_INTERVAL, params);
  }
  function checkUsbRndisState(params) {
    let currentState = libcutils.property_get(SYS_USB_STATE_PROPERTY);
    let stateFuncs = currentState.split(",");
    let rndisPresent = (stateFuncs.indexOf(USB_FUNCTION_RNDIS) >= 0);
    if (params.enable == rndisPresent) {
      params.result = true;
      postMessage(params);
      retry = 0;
      return;
    }
    if (retry < USB_FUNCTION_RETRY_TIMES) {
      retry++;
      setTimeout(checkUsbRndisState, USB_FUNCTION_RETRY_INTERVAL, params);
      return;
    }
    params.result = false;
    postMessage(params);
  };
  return true;
}
function enableUsbRndis ( params ) { let report = params . report ; let retry = 0 ; let currentConfig = libcutils . property_get ( SYS_USB_CONFIG_PROPERTY ) ; let configFuncs = currentConfig . split ( "," ) ; let persistConfig = libcutils . property_get ( PERSIST_SYS_USB_CONFIG_PROPERTY ) ; let persistFuncs = persistConfig . split ( "," ) ; if ( params . enable ) { configFuncs = [ USB_FUNCTION_RNDIS ] ; if ( persistFuncs . indexOf ( USB_FUNCTION_ADB ) >= 0 ) { configFuncs . push ( USB_FUNCTION_ADB ) ; } } else { configFuncs = persistFuncs ; } let newConfig = configFuncs . join ( "," ) ; if ( newConfig != currentConfig ) { libcutils . property_set ( SYS_USB_CONFIG_PROPERTY , newConfig ) ; } if ( report ) { setTimeout ( checkUsbRndisState , USB_FUNCTION_RETRY_INTERVAL , params ) ; } function checkUsbRndisState ( params ) { let currentState = libcutils . property_get ( SYS_USB_STATE_PROPERTY ) ; let stateFuncs = currentState . split ( "," ) ; let rndisPresent = ( stateFuncs . indexOf ( USB_FUNCTION_RNDIS ) >= 0 ) ; if ( params . enable == rndisPresent ) { params . result = true ; postMessage ( params ) ; retry = 0 ; return ; } if ( retry < USB_FUNCTION_RETRY_TIMES ) { retry ++ ; setTimeout ( checkUsbRndisState , USB_FUNCTION_RETRY_INTERVAL , params ) ; return ; } params . result = false ; postMessage ( params ) ; } ; return true ; }
Modify usb function's property to turn on USB RNDIS function
Modify usb function ' s property to turn on USB RNDIS function
// For some reason, rndis doesn't play well with diag,modem,nmea. // So when turning rndis on, we set sys.usb.config to either "rndis" // or "rndis,adb". When turning rndis off, we go back to // persist.sys.usb.config. // // On the otoro/unagi, persist.sys.usb.config should be one of: // //    diag,modem,nmea,mass_storage //    diag,modem,nmea,mass_storage,adb // // When rndis is enabled, sys.usb.config should be one of: // //    rdnis //    rndis,adb // // and when rndis is disabled, it should revert to persist.sys.usb.config // We're turning rndis off, revert back to the persist setting. // adb will already be correct there, so we don't need to do any // further adjustments. // Trigger the timer to check usb state and report the result to NetworkManager.