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 android.content.Context;
21import android.util.Config;
22import android.util.Log;
23
24/**
25 * Default retry scheme, based on specs.
26 */
27public class DefaultRetryScheme extends AbstractRetryScheme {
28    private static final String TAG = "DefaultRetryScheme";
29    private static final boolean DEBUG = false;
30    private static final boolean LOCAL_LOGV = DEBUG ? Config.LOGD : Config.LOGV;
31
32    private static final int[] sDefaultRetryScheme = {
33        0, 1 * 60 * 1000, 5 * 60 * 1000, 10 * 60 * 1000, 30 * 60 * 1000};
34
35    public DefaultRetryScheme(Context context, int retriedTimes) {
36        super(retriedTimes);
37
38        mRetriedTimes = mRetriedTimes < 0 ? 0 : mRetriedTimes;
39        mRetriedTimes = mRetriedTimes >= sDefaultRetryScheme.length
40                ? sDefaultRetryScheme.length - 1 : mRetriedTimes;
41
42        // TODO Get retry scheme from preference.
43    }
44
45    @Override
46    public int getRetryLimit() {
47        return sDefaultRetryScheme.length;
48    }
49
50    @Override
51    public long getWaitingInterval() {
52        if (LOCAL_LOGV) {
53            Log.v(TAG, "Next int: " + sDefaultRetryScheme[mRetriedTimes]);
54        }
55        return sDefaultRetryScheme[mRetriedTimes];
56    }
57}
58