/**
   * Re-enable mobile data connectivity after a {@link #teardown()}.
   *
   * @param radioNum 0:sim1, 1:sim2
   */
  public boolean reconnectGemini(int radioNum) {
    boolean retValue = false; // false: failed, true: network is connecting or connected

    // reset teardown flag
    setTeardownRequested(false);
    switch (setEnableApnGemini(mApnType, true, radioNum)) {
      case PhoneConstants.APN_ALREADY_ACTIVE:
        // need to set self to CONNECTING so the below message is handled.
        // TODO: need to notify the app
        retValue = true;
        break;
      case PhoneConstants.APN_REQUEST_STARTED:
        // set IDLE here , avoid the following second FAILED not sent out
        if (!mNetworkInfo.isConnectedOrConnecting()) {
          mNetworkInfo.setDetailedState(DetailedState.IDLE, null, null);
        }
        retValue = true;
        break;
      case PhoneConstants.APN_REQUEST_FAILED:
      case PhoneConstants.APN_TYPE_NOT_AVAILABLE:
        break;
      default:
        loge("Error in reconnect - unexpected response.");
        break;
    }
    return retValue;
  }
Пример #2
0
 /**
  * http://developer.android.com/training/monitoring-device-state/connectivity-monitoring.html
  * http://developer.android.com/training/basics/network-ops/managing.html
  *
  * @param context
  * @return
  */
 public static boolean isNetworkAvailable(final Context context, final boolean mobile) {
   boolean available = false;
   try {
     final ConnectivityManager connectivitymanager =
         (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
     final NetworkInfo networkinfo = connectivitymanager.getActiveNetworkInfo();
     if ((networkinfo != null) && networkinfo.isConnectedOrConnecting()) {
       switch (networkinfo.getType()) {
         case ConnectivityManager.TYPE_WIFI:
         case ConnectivityManager.TYPE_WIMAX:
         case ConnectivityManager.TYPE_ETHERNET:
           available = true;
           break;
         case ConnectivityManager.TYPE_MOBILE:
           if (mobile) {
             available = true;
           }
           break;
       }
     }
   } catch (Throwable x) {
     DBG.m(x);
   }
   return available;
 }