DcTesterFailBringUpAll.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.BroadcastReceiver; 20import android.content.Context; 21import android.content.Intent; 22import android.content.IntentFilter; 23import android.os.Handler; 24import android.os.SystemProperties; 25import android.telephony.Rlog; 26 27import com.android.internal.telephony.PhoneBase; 28 29/** 30 * A package level call that causes all DataConnection bringUp calls to fail a specific 31 * number of times. Here is an example that sets counter to 2 and cause to -3 for all instances: 32 * adb shell am broadcast -a com.android.internal.telephony.dataconnection.action_fail_bringup \ 33 * --ei counter 2 --ei fail_cause -3 34 * 35 * Also you can add a suggested retry time if desired: 36 * --ei suggested_retry_time 5000 37 * 38 * There is also a per DC command implemented in {@link DcRetryAlarmController#mFailBringUp} the intent is 39 * the same as above except the action has a "DC-x" before the action_fail_bringup so for 40 * DC-1 the action action is: 41 * adb shell am broadcast \ 42 * -a com.android.internal.telephony.dataconnection.DC-1.action_fail_bringup \ 43 * --ei counter 2 --ei fail_cause -3 44 * 45 * The fail_cause is one of {@link DcFailCause} 46 */ 47public class DcTesterFailBringUpAll { 48 private static final String LOG_TAG = "DcTesterFailBrinupAll"; 49 private static final boolean DBG = true; 50 private static final boolean DEBUGGABLE = SystemProperties.getInt("ro.debuggable", 0) == 1; 51 52 private PhoneBase mPhone; 53 54 private String mActionFailBringUp = DcFailBringUp.INTENT_BASE + "." 55 + DcFailBringUp.ACTION_FAIL_BRINGUP; 56 57 // The saved FailBringUp data from the intent 58 private DcFailBringUp mFailBringUp = new DcFailBringUp(); 59 60 // The static intent receiver one for all instances. 61 private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { 62 @Override 63 public void onReceive(Context context, Intent intent) { 64 String action = intent.getAction(); 65 if (DBG) log("sIntentReceiver.onReceive: action=" + action); 66 if (action.equals(mActionFailBringUp)) { 67 mFailBringUp.saveParameters(intent, "sFailBringUp"); 68 } else if (action.equals(mPhone.getActionDetached())) { 69 // Counter is MAX, bringUp/retry will always fail 70 log("simulate detaching"); 71 mFailBringUp.saveParameters(Integer.MAX_VALUE, 72 DcFailCause.LOST_CONNECTION.getErrorCode(), 73 DcFailBringUp.DEFAULT_SUGGESTED_RETRY_TIME); 74 } else if (action.equals(mPhone.getActionAttached())) { 75 // Counter is 0 next bringUp/retry will succeed 76 log("simulate attaching"); 77 mFailBringUp.saveParameters(0, DcFailCause.NONE.getErrorCode(), 78 DcFailBringUp.DEFAULT_SUGGESTED_RETRY_TIME); 79 } else { 80 if (DBG) log("onReceive: unknown action=" + action); 81 } 82 } 83 }; 84 85 DcTesterFailBringUpAll(PhoneBase phone, Handler handler) { 86 mPhone = phone; 87 if (DEBUGGABLE) { 88 IntentFilter filter = new IntentFilter(); 89 90 filter.addAction(mActionFailBringUp); 91 log("register for intent action=" + mActionFailBringUp); 92 93 filter.addAction(mPhone.getActionDetached()); 94 log("register for intent action=" + mPhone.getActionDetached()); 95 96 filter.addAction(mPhone.getActionAttached()); 97 log("register for intent action=" + mPhone.getActionAttached()); 98 99 phone.getContext().registerReceiver(mIntentReceiver, filter, null, handler); 100 } 101 } 102 103 void dispose() { 104 mPhone.getContext().unregisterReceiver(mIntentReceiver); 105 } 106 107 DcFailBringUp getDcFailBringUp() { 108 return mFailBringUp; 109 } 110 111 private void log(String s) { 112 Rlog.d(LOG_TAG, s); 113 } 114} 115