Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d3924fe9 authored by Wink Saville's avatar Wink Saville Committed by Android (Google) Code Review
Browse files

Merge "Data Connection: Use Alarm for all delayed data retries." into honeycomb-LTE

parents de60ce66 a88d76b7
Loading
Loading
Loading
Loading
+18 −14
Original line number Diff line number Diff line
@@ -521,8 +521,22 @@ public final class CdmaDataConnectionTracker extends DataConnectionTracker {
             * TODO: Make this configurable?
             */
            int nextReconnectDelay = mDataConnections.get(0).getRetryTimer();
            startAlarmForReconnect(nextReconnectDelay, reason);
            mDataConnections.get(0).increaseRetryCount();

            if (!shouldPostNotification(lastFailCauseCode)) {
                log("NOT Posting Data Connection Unavailable notification "
                                + "-- likely transient error");
            } else {
                notifyNoData(lastFailCauseCode);
            }
        }
    }

    private void startAlarmForReconnect(int delay, String reason) {

        log("Data Connection activate failed. Scheduling next attempt for "
                    + (nextReconnectDelay / 1000) + "s");
                + (delay / 1000) + "s");

        AlarmManager am =
            (AlarmManager) mPhone.getContext().getSystemService(Context.ALARM_SERVICE);
@@ -531,18 +545,8 @@ public final class CdmaDataConnectionTracker extends DataConnectionTracker {
        mReconnectIntent = PendingIntent.getBroadcast(
                mPhone.getContext(), 0, intent, 0);
        am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
                    SystemClock.elapsedRealtime() + nextReconnectDelay,
                    mReconnectIntent);

            mDataConnections.get(0).increaseRetryCount();
                SystemClock.elapsedRealtime() + delay, mReconnectIntent);

            if (!shouldPostNotification(lastFailCauseCode)) {
                log("NOT Posting Data Connection Unavailable notification "
                                + "-- likely transient error");
            } else {
                notifyNoData(lastFailCauseCode);
            }
        }
    }

    private void notifyNoData(FailCause lastFailCauseCode) {
@@ -702,7 +706,7 @@ public final class CdmaDataConnectionTracker extends DataConnectionTracker {
        mActiveApn = null;
        if (retryAfterDisconnected(reason)) {
          // Wait a bit before trying, so we're not tying up RIL command channel.
          sendMessageDelayed(obtainMessage(EVENT_TRY_SETUP_DATA, reason), APN_DELAY_MILLIS);
          startAlarmForReconnect(APN_DELAY_MILLIS, reason);
      }
    }

+22 −20
Original line number Diff line number Diff line
@@ -1406,34 +1406,37 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
            }

            int nextReconnectDelay = apnContext.getDataConnection().getRetryTimer();
            startAlarmForReconnect(nextReconnectDelay, apnContext);
            apnContext.getDataConnection().increaseRetryCount();

            if (!shouldPostNotification(lastFailCauseCode)) {
                if (DBG) {
                log("reconnectAfterFail: activate failed. Scheduling next attempt for "
                    + (nextReconnectDelay / 1000) + "s");
                    log("reconnectAfterFail: NOT Posting GPRS Unavailable notification "
                                + "-- likely transient error");
                }
            } else {
                notifyNoData(lastFailCauseCode, apnContext);
            }
        }
    }

    private void startAlarmForReconnect(int delay, ApnContext apnContext) {

        if (DBG) {
            log("Schedule alarm for reconnect: activate failed. Scheduling next attempt for "
                + (delay / 1000) + "s");
        }

        AlarmManager am =
            (AlarmManager) mPhone.getContext().getSystemService(Context.ALARM_SERVICE);
        Intent intent = new Intent(INTENT_RECONNECT_ALARM);
        intent.putExtra(INTENT_RECONNECT_ALARM_EXTRA_REASON, apnContext.getReason());
            // Should put an extra of apn type?
        intent.putExtra(INTENT_RECONNECT_ALARM_EXTRA_TYPE, apnContext.getApnType());
        apnContext.setReconnectIntent(PendingIntent.getBroadcast (
                mPhone.getContext(), 0, intent, 0));
        am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
                    SystemClock.elapsedRealtime() + nextReconnectDelay,
                    apnContext.getReconnectIntent());

            apnContext.getDataConnection().increaseRetryCount();
                SystemClock.elapsedRealtime() + delay, apnContext.getReconnectIntent());

            if (!shouldPostNotification(lastFailCauseCode)) {
                if (DBG) {
                    log("reconnectAfterFail: NOT Posting GPRS Unavailable notification "
                                + "-- likely transient error");
                }
            } else {
                notifyNoData(lastFailCauseCode, apnContext);
            }
        }
    }

    private void notifyNoData(GsmDataConnection.FailCause lastFailCauseCode,
@@ -1723,8 +1726,7 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
                apnContext.setState(State.SCANNING);
                // Wait a bit before trying the next APN, so that
                // we're not tying up the RIL command channel
                sendMessageDelayed(obtainMessage(EVENT_TRY_SETUP_DATA, apnContext),
                        APN_DELAY_MILLIS);
                startAlarmForReconnect(APN_DELAY_MILLIS, apnContext);
            }
        }
    }
@@ -1764,7 +1766,7 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
            // Wait a bit before trying the next APN, so that
            // we're not tying up the RIL command channel.
            // This also helps in any external dependency to turn off the context.
            sendMessageDelayed(obtainMessage(EVENT_TRY_SETUP_DATA, apnContext),APN_DELAY_MILLIS);
            startAlarmForReconnect(APN_DELAY_MILLIS, apnContext);
        }
    }