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 17 package com.android.internal.telephony.dataconnection; 18 19 import android.content.BroadcastReceiver; 20 import android.content.Context; 21 import android.content.Intent; 22 import android.content.IntentFilter; 23 import android.os.Handler; 24 25 import com.android.internal.telephony.Phone; 26 import com.android.internal.telephony.util.TelephonyUtils; 27 import com.android.telephony.Rlog; 28 29 /** 30 * To bring down all DC's send the following intent: 31 * 32 * adb shell am broadcast -a com.android.internal.telephony.dataconnection.action_deactivate_all 33 */ 34 public class DcTesterDeactivateAll { 35 private static final String LOG_TAG = "DcTesterDeacativateAll"; 36 private static final boolean DBG = true; 37 38 private Phone mPhone; 39 private DcController mDcc; 40 41 public static String sActionDcTesterDeactivateAll = 42 "com.android.internal.telephony.dataconnection.action_deactivate_all"; 43 44 45 // The static intent receiver one for all instances and we assume this 46 // is running on the same thread as Dcc. 47 protected BroadcastReceiver sIntentReceiver = new BroadcastReceiver() { 48 @Override 49 public void onReceive(Context context, Intent intent) { 50 String action = intent.getAction(); 51 if (DBG) log("sIntentReceiver.onReceive: action=" + action); 52 if (action.equals(sActionDcTesterDeactivateAll) 53 || action.equals(mPhone.getActionDetached())) { 54 log("Send DEACTIVATE to all Dcc's"); 55 if (mDcc != null) { 56 for (DataConnection dc : mDcc.mDcListAll) { 57 dc.tearDownNow(); 58 } 59 } else { 60 if (DBG) log("onReceive: mDcc is null, ignoring"); 61 } 62 } else { 63 if (DBG) log("onReceive: unknown action=" + action); 64 } 65 } 66 }; 67 DcTesterDeactivateAll(Phone phone, DcController dcc, Handler handler)68 DcTesterDeactivateAll(Phone phone, DcController dcc, Handler handler) { 69 mPhone = phone; 70 mDcc = dcc; 71 72 if (TelephonyUtils.IS_DEBUGGABLE) { 73 IntentFilter filter = new IntentFilter(); 74 75 filter.addAction(sActionDcTesterDeactivateAll); 76 log("register for intent action=" + sActionDcTesterDeactivateAll); 77 78 filter.addAction(mPhone.getActionDetached()); 79 log("register for intent action=" + mPhone.getActionDetached()); 80 81 phone.getContext().registerReceiver(sIntentReceiver, filter, null, handler); 82 } 83 } 84 dispose()85 void dispose() { 86 if (TelephonyUtils.IS_DEBUGGABLE) { 87 mPhone.getContext().unregisterReceiver(sIntentReceiver); 88 } 89 } 90 log(String s)91 private static void log(String s) { 92 Rlog.d(LOG_TAG, s); 93 } 94 } 95