aboutsummaryrefslogtreecommitdiff
path: root/src/java/com/android/internal/telephony/dataconnection/DcFailBringUp.java
blob: 420340d50e16fb7061d049bfc2ddf982c5411829 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
 * Copyright (C) 2013 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.telephony.dataconnection;

import android.content.Intent;
import android.telephony.Annotation.DataFailureCause;
import android.telephony.DataFailCause;

import com.android.telephony.Rlog;

/**
 * A package visible class for supporting testing failing bringUp commands. This
 * saves the parameters from a action_fail_bringup intent. See
 * {@link DataConnection#doOnConnect} and {@see DcTesterFailBringUpAll} for more info.
 */
public class DcFailBringUp {
    private static final String LOG_TAG = "DcFailBringUp";
    private static final boolean DBG = true;

    static final String INTENT_BASE = DataConnection.class.getPackage().getName();

    static final String ACTION_FAIL_BRINGUP = "action_fail_bringup";

    // counter with its --ei option name and default value
    static final String COUNTER = "counter";
    static final int DEFAULT_COUNTER = 2;
    int mCounter;

    // failCause with its --ei option name and default value
    static final String FAIL_CAUSE = "fail_cause";
    static final int DEFAULT_FAIL_CAUSE = DataFailCause.ERROR_UNSPECIFIED;
    @DataFailureCause
    int mFailCause;

    // suggestedRetryTime with its --ei option name and default value
    static final String SUGGESTED_RETRY_TIME = "suggested_retry_time";
    static final int DEFAULT_SUGGESTED_RETRY_TIME = -1;
    int mSuggestedRetryTime;

    // Get the Extra Intent parameters
    void saveParameters(Intent intent, String s) {
        if (DBG) log(s + ".saveParameters: action=" + intent.getAction());
        mCounter = intent.getIntExtra(COUNTER, DEFAULT_COUNTER);
        mFailCause = DataFailCause.getFailCause(
                intent.getIntExtra(FAIL_CAUSE, DEFAULT_FAIL_CAUSE));
        mSuggestedRetryTime =
                intent.getIntExtra(SUGGESTED_RETRY_TIME, DEFAULT_SUGGESTED_RETRY_TIME);
        if (DBG) {
            log(s + ".saveParameters: " + this);
        }
    }

    public void saveParameters(int counter, @DataFailureCause int failCause,
                               int suggestedRetryTime) {
        mCounter = counter;
        mFailCause = DataFailCause.getFailCause(failCause);
        mSuggestedRetryTime = suggestedRetryTime;
    }

    @Override
    public String toString() {
        return "{mCounter=" + mCounter +
                " mFailCause=" + mFailCause +
                " mSuggestedRetryTime=" + mSuggestedRetryTime + "}";

    }

    private static void log(String s) {
        Rlog.d(LOG_TAG, s);
    }
}