DcTesterDeactivateAll.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 * 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 */ 34public class DcTesterDeactivateAll { 35 private static final String LOG_TAG = "DcTesterDeacativeAll"; 36 private static final boolean DBG = true; 37 private static final boolean DEBUGGABLE = SystemProperties.getInt("ro.debuggable", 0) == 1; 38 39 private PhoneBase mPhone; 40 private DcController mDcc; 41 42 public static String sActionDcTesterDeactivateAll = 43 "com.android.internal.telephony.dataconnection.action_deactivate_all"; 44 45 46 // The static intent receiver one for all instances and we assume this 47 // is running on the same thread as Dcc. 48 protected BroadcastReceiver sIntentReceiver = new BroadcastReceiver() { 49 @Override 50 public void onReceive(Context context, Intent intent) { 51 String action = intent.getAction(); 52 if (DBG) log("sIntentReceiver.onReceive: action=" + action); 53 if (action.equals(sActionDcTesterDeactivateAll) 54 || action.equals(mPhone.getActionDetached())) { 55 log("Send DEACTIVATE to all Dcc's"); 56 if (mDcc != null) { 57 for (DataConnection dc : mDcc.mDcListAll) { 58 dc.tearDownNow(); 59 } 60 } else { 61 if (DBG) log("onReceive: mDcc is null, ignoring"); 62 } 63 } else { 64 if (DBG) log("onReceive: unknown action=" + action); 65 } 66 } 67 }; 68 69 DcTesterDeactivateAll(PhoneBase phone, DcController dcc, Handler handler) { 70 mPhone = phone; 71 mDcc = dcc; 72 73 if (DEBUGGABLE) { 74 IntentFilter filter = new IntentFilter(); 75 76 filter.addAction(sActionDcTesterDeactivateAll); 77 log("register for intent action=" + sActionDcTesterDeactivateAll); 78 79 filter.addAction(mPhone.getActionDetached()); 80 log("register for intent action=" + mPhone.getActionDetached()); 81 82 phone.getContext().registerReceiver(sIntentReceiver, filter, null, handler); 83 } 84 } 85 86 void dispose() { 87 mPhone.getContext().unregisterReceiver(sIntentReceiver); 88 } 89 90 private static void log(String s) { 91 Rlog.d(LOG_TAG, s); 92 } 93} 94