1/*
2 * Copyright (C) 2008 Esmertec AG.
3 * Copyright (C) 2008 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18package com.android.mms.transaction;
19
20import com.android.mms.LogTag;
21
22import android.content.Context;
23import android.util.Config;
24import android.util.Log;
25
26/**
27 * Default retry scheme, based on specs.
28 */
29public class DefaultRetryScheme extends AbstractRetryScheme {
30    private static final String TAG = LogTag.TAG;
31    private static final boolean DEBUG = false;
32    private static final boolean LOCAL_LOGV = DEBUG ? Config.LOGD : Config.LOGV;
33
34    private static final int[] sDefaultRetryScheme = {
35        0, 1 * 60 * 1000, 5 * 60 * 1000, 10 * 60 * 1000, 30 * 60 * 1000};
36
37    public DefaultRetryScheme(Context context, int retriedTimes) {
38        super(retriedTimes);
39
40        mRetriedTimes = mRetriedTimes < 0 ? 0 : mRetriedTimes;
41        mRetriedTimes = mRetriedTimes >= sDefaultRetryScheme.length
42                ? sDefaultRetryScheme.length - 1 : mRetriedTimes;
43
44        // TODO Get retry scheme from preference.
45    }
46
47    @Override
48    public int getRetryLimit() {
49        return sDefaultRetryScheme.length;
50    }
51
52    @Override
53    public long getWaitingInterval() {
54        if (LOCAL_LOGV) {
55            Log.v(TAG, "Next int: " + sDefaultRetryScheme[mRetriedTimes]);
56        }
57        return sDefaultRetryScheme[mRetriedTimes];
58    }
59}
60