TelephonyTester.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; 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 * Telephony tester receives the following intents where {name} is the phone name 31 * 32 * adb shell am broadcast -a com.android.internal.telephony.{name}.action_detached 33 * adb shell am broadcast -a com.android.internal.telephony.{name}.action_attached 34 */ 35public class TelephonyTester { 36 private static final String LOG_TAG = "TelephonyTester"; 37 private static final boolean DBG = true; 38 private static final boolean DEBUGGABLE = SystemProperties.getInt("ro.debuggable", 0) == 1; 39 40 private PhoneBase mPhone; 41 42 // The static intent receiver one for all instances and we assume this 43 // is running on the same thread as Dcc. 44 protected BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { 45 @Override 46 public void onReceive(Context context, Intent intent) { 47 String action = intent.getAction(); 48 if (DBG) log("sIntentReceiver.onReceive: action=" + action); 49 if (action.equals(mPhone.getActionDetached())) { 50 log("simulate detaching"); 51 mPhone.getServiceStateTracker().mDetachedRegistrants.notifyRegistrants(); 52 } else if (action.equals(mPhone.getActionAttached())) { 53 log("simulate attaching"); 54 mPhone.getServiceStateTracker().mAttachedRegistrants.notifyRegistrants(); 55 } else { 56 if (DBG) log("onReceive: unknown action=" + action); 57 } 58 } 59 }; 60 61 TelephonyTester(PhoneBase phone) { 62 mPhone = phone; 63 64 if (DEBUGGABLE) { 65 IntentFilter filter = new IntentFilter(); 66 67 filter.addAction(mPhone.getActionDetached()); 68 log("register for intent action=" + mPhone.getActionDetached()); 69 70 filter.addAction(mPhone.getActionAttached()); 71 log("register for intent action=" + mPhone.getActionAttached()); 72 73 phone.getContext().registerReceiver(mIntentReceiver, filter, null, mPhone.getHandler()); 74 } 75 } 76 77 void dispose() { 78 mPhone.getContext().unregisterReceiver(mIntentReceiver); 79 } 80 81 private static void log(String s) { 82 Rlog.d(LOG_TAG, s); 83 } 84} 85