DcFailBringUp.java revision ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6a
1/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.internal.telephony.dataconnection;
18
19import android.content.Intent;
20import android.telephony.Rlog;
21
22/**
23 * A package visible class for supporting testing failing bringUp commands. This
24 * saves the parameters from a action_fail_bringup intent. See
25 * {@link DataConnection#doOnConnect} and {@see DcTesterFailBringUpAll} for more info.
26 */
27class DcFailBringUp {
28    private static final String LOG_TAG = "DcFailBringUp";
29    private static final boolean DBG = true;
30
31    static final String INTENT_BASE = DataConnection.class.getPackage().getName();
32
33    static final String ACTION_FAIL_BRINGUP = "action_fail_bringup";
34
35    // counter with its --ei option name and default value
36    static final String COUNTER = "counter";
37    static final int DEFAULT_COUNTER = 1;
38    int mCounter;
39
40    // failCause with its --ei option name and default value
41    static final String FAIL_CAUSE = "fail_cause";
42    static final DcFailCause DEFAULT_FAIL_CAUSE = DcFailCause.ERROR_UNSPECIFIED;
43    DcFailCause mFailCause;
44
45    // suggestedRetryTime with its --ei option name and default value
46    static final String SUGGESTED_RETRY_TIME = "suggested_retry_time";
47    static final int DEFAULT_SUGGESTED_RETRY_TIME = -1;
48    int mSuggestedRetryTime;
49
50    // Get the Extra Intent parameters
51    void saveParameters(Intent intent, String s) {
52        if (DBG) log(s + ".saveParameters: action=" + intent.getAction());
53        mCounter = intent.getIntExtra(COUNTER, DEFAULT_COUNTER);
54        mFailCause = DcFailCause.fromInt(
55                intent.getIntExtra(FAIL_CAUSE, DEFAULT_FAIL_CAUSE.getErrorCode()));
56        mSuggestedRetryTime =
57                intent.getIntExtra(SUGGESTED_RETRY_TIME, DEFAULT_SUGGESTED_RETRY_TIME);
58        if (DBG) {
59            log(s + ".saveParameters: " + this);
60        }
61    }
62
63    void saveParameters(int counter, int failCause, int suggestedRetryTime) {
64        mCounter = counter;
65        mFailCause = DcFailCause.fromInt(failCause);
66        mSuggestedRetryTime = suggestedRetryTime;
67    }
68
69    @Override
70    public String toString() {
71        return "{mCounter=" + mCounter +
72                " mFailCause=" + mFailCause +
73                " mSuggestedRetryTime=" + mSuggestedRetryTime + "}";
74
75    }
76
77    private static void log(String s) {
78        Rlog.d(LOG_TAG, s);
79    }
80}
81