Merge commit 'ebca826a' into manualmerge
Wink Saville [Thu, 5 Sep 2013 03:21:09 +0000 (20:21 -0700)]
* commit 'ebca826a':
  Add provisioning apn timeout.

Conflicts:
src/java/com/android/internal/telephony/dataconnection/DcTrackerBase.java

Change-Id: Ic89a22167b91e05068160a6ef0a194215913bfe7

1  2 
src/java/com/android/internal/telephony/dataconnection/DcTrackerBase.java

@@@ -1596,66 -1637,53 +1642,113 @@@ public abstract class DcTrackerBase ext
          startDataStallAlarm(DATA_STALL_NOT_SUSPECTED);
      }
  
 +    protected void setInitialAttachApn() {
 +        ApnSetting iaApnSetting = null;
 +        ApnSetting defaultApnSetting = null;
 +        ApnSetting firstApnSetting = null;
 +
 +        log("setInitialApn: E mPreferredApn=" + mPreferredApn);
 +
 +        if (mAllApnSettings != null && !mAllApnSettings.isEmpty()) {
 +            firstApnSetting = mAllApnSettings.get(0);
 +            log("setInitialApn: firstApnSetting=" + firstApnSetting);
 +
 +            // Search for Initial APN setting and the first apn that can handle default
 +            for (ApnSetting apn : mAllApnSettings) {
 +                // Can't use apn.canHandleType(), as that returns true for APNs that have no type.
 +                if (ArrayUtils.contains(apn.types, PhoneConstants.APN_TYPE_IA)) {
 +                    // The Initial Attach APN is highest priority so use it if there is one
 +                    log("setInitialApn: iaApnSetting=" + apn);
 +                    iaApnSetting = apn;
 +                    break;
 +                } else if ((defaultApnSetting == null)
 +                        && (apn.canHandleType(PhoneConstants.APN_TYPE_DEFAULT))) {
 +                    // Use the first default apn if no better choice
 +                    log("setInitialApn: defaultApnSetting=" + apn);
 +                    defaultApnSetting = apn;
 +                }
 +            }
 +        }
 +
 +        // The priority of apn candidates from highest to lowest is:
 +        //   1) APN_TYPE_IA (Inital Attach)
 +        //   2) mPreferredApn, i.e. the current preferred apn
 +        //   3) The first apn that than handle APN_TYPE_DEFAULT
 +        //   4) The first APN we can find.
 +
 +        ApnSetting initialAttachApnSetting = null;
 +        if (iaApnSetting != null) {
 +            if (DBG) log("setInitialAttachApn: using iaApnSetting");
 +            initialAttachApnSetting = iaApnSetting;
 +        } else if (mPreferredApn != null) {
 +            if (DBG) log("setInitialAttachApn: using mPreferredApn");
 +            initialAttachApnSetting = mPreferredApn;
 +        } else if (defaultApnSetting != null) {
 +            if (DBG) log("setInitialAttachApn: using defaultApnSetting");
 +            initialAttachApnSetting = defaultApnSetting;
 +        } else if (firstApnSetting != null) {
 +            if (DBG) log("setInitialAttachApn: using firstApnSetting");
 +            initialAttachApnSetting = firstApnSetting;
 +        }
 +
 +        if (initialAttachApnSetting == null) {
 +            if (DBG) log("setInitialAttachApn: X There in no available apn");
 +        } else {
 +            if (DBG) log("setInitialAttachApn: X selected Apn=" + initialAttachApnSetting);
 +
 +            mPhone.mCi.setInitialAttachApn(initialAttachApnSetting.apn,
 +                    initialAttachApnSetting.protocol, initialAttachApnSetting.authType,
 +                    initialAttachApnSetting.user, initialAttachApnSetting.password, null);
 +        }
 +    }
 +
+     protected void onActionIntentProvisioningApnAlarm(Intent intent) {
+         if (DBG) log("onActionIntentProvisioningApnAlarm: action=" + intent.getAction());
+         Message msg = obtainMessage(DctConstants.EVENT_PROVISIONING_APN_ALARM,
+                 intent.getAction());
+         msg.arg1 = intent.getIntExtra(PROVISIONING_APN_ALARM_TAG_EXTRA, 0);
+         sendMessage(msg);
+     }
+     protected void startProvisioningApnAlarm() {
+         int delayInMs = Settings.Global.getInt(mResolver,
+                                 Settings.Global.PROVISIONING_APN_ALARM_DELAY_IN_MS,
+                                 PROVISIONING_APN_ALARM_DELAY_IN_MS_DEFAULT);
+         if (Build.IS_DEBUGGABLE) {
+             // Allow debug code to use a system property to provide another value
+             String delayInMsStrg = Integer.toString(delayInMs);
+             delayInMsStrg = System.getProperty(DEBUG_PROV_APN_ALARM, delayInMsStrg);
+             try {
+                 delayInMs = Integer.parseInt(delayInMsStrg);
+             } catch (NumberFormatException e) {
+                 loge("startProvisioningApnAlarm: e=" + e);
+             }
+         }
+         mProvisioningApnAlarmTag += 1;
+         if (DBG) {
+             log("startProvisioningApnAlarm: tag=" + mProvisioningApnAlarmTag +
+                     " delay=" + (delayInMs / 1000) + "s");
+         }
+         Intent intent = new Intent(INTENT_PROVISIONING_APN_ALARM);
+         intent.putExtra(PROVISIONING_APN_ALARM_TAG_EXTRA, mProvisioningApnAlarmTag);
+         mProvisioningApnAlarmIntent = PendingIntent.getBroadcast(mPhone.getContext(), 0, intent,
+                 PendingIntent.FLAG_UPDATE_CURRENT);
+         mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
+                 SystemClock.elapsedRealtime() + delayInMs, mProvisioningApnAlarmIntent);
+     }
+     protected void stopProvisioningApnAlarm() {
+         if (DBG) {
+             log("stopProvisioningApnAlarm: current tag=" + mProvisioningApnAlarmTag +
+                     " mProvsioningApnAlarmIntent=" + mProvisioningApnAlarmIntent);
+         }
+         mProvisioningApnAlarmTag += 1;
+         if (mProvisioningApnAlarmIntent != null) {
+             mAlarmManager.cancel(mProvisioningApnAlarmIntent);
+             mProvisioningApnAlarmIntent = null;
+         }
+     }
      void sendCleanUpConnection(boolean tearDown, ApnContext apnContext) {
          if (DBG)log("sendCleanUpConnection: tearDown=" + tearDown + " apnContext=" + apnContext);
          Message msg = obtainMessage(DctConstants.EVENT_CLEAN_UP_CONNECTION);