PhoneNumberUtilsWrapper.java revision fb0a934ad90f1855787563eb80f2c8fff7f640ac
1fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng/* 2fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng * Copyright (C) 2013 The Android Open Source Project 3fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng * 4fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng * Licensed under the Apache License, Version 2.0 (the "License"); 5fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng * you may not use this file except in compliance with the License. 6fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng * You may obtain a copy of the License at 7fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng * 8fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng * http://www.apache.org/licenses/LICENSE-2.0 9fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng * 10fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng * Unless required by applicable law or agreed to in writing, software 11fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng * distributed under the License is distributed on an "AS IS" BASIS, 12fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng * See the License for the specific language governing permissions and 14fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng * limitations under the License 15fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng */ 16fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng 17fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Chengpackage com.android.dialer.calllog; 18fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng 19fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Chengimport android.provider.CallLog; 20fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Chengimport android.telephony.PhoneNumberUtils; 21fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Chengimport android.text.TextUtils; 22fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng 23fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng/** 24fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng * 25fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng */ 26fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Chengpublic class PhoneNumberUtilsWrapper { 27fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng 28fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng /** Returns true if it is possible to place a call to the given number. */ 29fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng public static boolean canPlaceCallsTo(CharSequence number, int presentation) { 30fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng return presentation == CallLog.Calls.PRESENTATION_ALLOWED 31fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng && !TextUtils.isEmpty(number); 32fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng } 33fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng 34fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng /** 35fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng * Returns true if it is possible to send an SMS to the given number. 36fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng */ 37fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng public boolean canSendSmsTo(CharSequence number, int presentation) { 38fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng return canPlaceCallsTo(number, presentation) && !isVoicemailNumber(number) && !isSipNumber( 39fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng number); 40fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng } 41fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng 42fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng /** 43fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng * Returns true if the given number is the number of the configured voicemail. To be able to 44fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng * mock-out this, it is not a static method. 45fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng */ 46fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng public boolean isVoicemailNumber(CharSequence number) { 47fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng return PhoneNumberUtils.isVoiceMailNumber(number.toString()); 48fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng } 49fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng 50fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng /** 51fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng * Returns true if the given number is a SIP address. To be able to mock-out this, it is not a 52fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng * static method. 53fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng */ 54fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng public boolean isSipNumber(CharSequence number) { 55fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng return PhoneNumberUtils.isUriNumber(number.toString()); 56fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng } 57fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng 58fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng public static boolean isUnknownNumberThatCanBeLookedUp(CharSequence number, int presentation) { 59fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng if (presentation == CallLog.Calls.PRESENTATION_UNKNOWN) { 60fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng return false; 61fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng } 62fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng if (presentation == CallLog.Calls.PRESENTATION_RESTRICTED) { 63fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng return false; 64fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng } 65fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng if (presentation == CallLog.Calls.PRESENTATION_PAYPHONE) { 66fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng return false; 67fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng } 68fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng if (TextUtils.isEmpty(number)) { 69fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng return false; 70fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng } 71fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng if (new PhoneNumberUtilsWrapper().isVoicemailNumber(number)) { 72fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng return false; 73fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng } 74fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng return true; 75fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng } 76fb0a934ad90f1855787563eb80f2c8fff7f640acChiao Cheng} 77