1 /* 2 * Copyright (C) 2008 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.phone; 18 19 import android.app.SearchManager; 20 import android.content.BroadcastReceiver; 21 import android.content.Context; 22 import android.content.Intent; 23 import android.net.Uri; 24 import android.util.Log; 25 26 /** 27 * ProcessOutgoingCallTest tests {@link OutgoingCallBroadcaster} by performing 28 * a couple of simple modifications to outgoing calls, and by printing log 29 * messages for each call. 30 */ 31 public class ProcessOutgoingCallTest extends BroadcastReceiver { 32 private static final String TAG = "ProcessOutgoingCallTest"; 33 private static final String AREACODE = "617"; 34 35 private static final boolean LOGV = false; 36 37 private static final boolean REDIRECT_411_TO_GOOG411 = true; 38 private static final boolean SEVEN_DIGIT_DIALING = true; 39 private static final boolean POUND_POUND_SEARCH = true; 40 private static final boolean BLOCK_555 = true; 41 onReceive(Context context, Intent intent)42 public void onReceive(Context context, Intent intent) { 43 if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) { 44 String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER); 45 if (LOGV) Log.v(TAG, "Received intent " + intent + " (number = " + number + "."); 46 /* Example of how to redirect calls from one number to another. */ 47 if (REDIRECT_411_TO_GOOG411 && number.equals("411")) { 48 setResultData("18004664411"); 49 } 50 51 /* Example of how to modify the phone number in flight. */ 52 if (SEVEN_DIGIT_DIALING && number.length() == 7) { 53 setResultData(AREACODE + number); 54 } 55 56 /* Example of how to route a call to another Application. */ 57 if (POUND_POUND_SEARCH && number.startsWith("##")) { 58 Intent newIntent = new Intent(Intent.ACTION_SEARCH); 59 newIntent.putExtra(SearchManager.QUERY, number.substring(2)); 60 newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 61 context.startActivity(newIntent); 62 setResultData(null); 63 } 64 65 /* Example of how to deny calls to a particular number. 66 * Note that no UI is displayed to the user -- the call simply 67 * does not happen. It is the application's responaibility to 68 * explain this to the user. */ 69 int length = number.length(); 70 if (BLOCK_555 && length >= 7) { 71 String exchange = number.substring(length - 7, length - 4); 72 Log.v(TAG, "exchange = " + exchange); 73 if (exchange.equals("555")) { 74 setResultData(null); 75 } 76 } 77 } 78 } 79 } 80