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