Loading src/java/android/provider/Telephony.java +70 −0 Original line number Diff line number Diff line Loading @@ -38,7 +38,10 @@ import com.android.internal.telephony.MSimConstants; import com.android.internal.telephony.SmsApplication; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; Loading Loading @@ -834,6 +837,30 @@ public final class Telephony { */ public static final int RESULT_SMS_BLACKLISTED_REGEX = 8; /** * Used internally: * Broadcast Action: A new protected text-based SMS message has been received * by the device. This intent will be delivered to all registered * receivers who possess {@link android.Manifest.permission#RECEIVE_PROTECTED_SMS}. * These apps SHOULD NOT write the message or notify the user. * The intent will have the following extra values: * </p> * * <ul> * <li><em>"pdus"</em> - An Object[] of byte[]s containing the PDUs * that make up the message.</li> * </ul> * * <p>The extra values can be extracted using * {@link #getMessagesFromIntent(Intent)}.</p> * * <p>If a BroadcastReceiver encounters an error while processing * this intent it should set the result code appropriately.</p> * @hide */ public static final String PROTECTED_SMS_RECEIVED_ACTION = "android.provider.Telephony.ACTION_PROTECTED_SMS_RECEIVED"; /** * Activity action: Ask the user to change the default * SMS application. This will show a dialog that asks the Loading Loading @@ -1120,6 +1147,49 @@ public final class Telephony { } return msgs; } /** * Read the normalized addresses out of PDUs * @param pdus bytes for PDUs * @param format the format of the message * @return a list of Addresses for the PDUs * @hide */ public static List<String> getNormalizedAddressesFromPdus(byte[][] pdus, String format) { int pduCount = pdus.length; SmsMessage[] msgs = new SmsMessage[pduCount]; List<String> addresses = new ArrayList<String>(); for (int i = 0; i < pduCount; i++) { byte[] pdu = (byte[]) pdus[i]; msgs[i] = SmsMessage.createFromPdu(pdu, format); String originatingAddress = msgs[i].getOriginatingAddress(); if (!TextUtils.isEmpty(originatingAddress)) { String normalized = normalizeDigitsOnly(originatingAddress); addresses.add(normalized); } } return addresses; } private static String normalizeDigitsOnly(String number) { return normalizeDigits(number, false /* strip non-digits */).toString(); } private static StringBuilder normalizeDigits(String number, boolean keepNonDigits) { StringBuilder normalizedDigits = new StringBuilder(number.length()); for (char c : number.toCharArray()) { int digit = Character.digit(c, 10); if (digit != -1) { normalizedDigits.append(digit); } else if (keepNonDigits) { normalizedDigits.append(c); } } return normalizedDigits; } } } Loading src/java/com/android/internal/telephony/CallManager.java +14 −1 Original line number Diff line number Diff line Loading @@ -117,6 +117,8 @@ public class CallManager { protected boolean mSpeedUpAudioForMtCall = false; protected Boolean mAlwaysRequestVolumeFocus; protected CmHandler mHandler; // state registrants Loading Loading @@ -474,7 +476,8 @@ public class CallManager { int curAudioMode = audioManager.getMode(); if (curAudioMode != AudioManager.MODE_RINGTONE) { // only request audio focus if the ringtone is going to be heard if (audioManager.getStreamVolume(AudioManager.STREAM_RING) > 0) { if (audioManager.getStreamVolume(AudioManager.STREAM_RING) > 0 || shouldAlwaysRequestAudioFocusForCall()) { if (VDBG) Rlog.d(LOG_TAG, "requestAudioFocus on STREAM_RING"); audioManager.requestAudioFocusForCall(AudioManager.STREAM_RING, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT); Loading Loading @@ -527,6 +530,16 @@ public class CallManager { Rlog.d(LOG_TAG, "setAudioMode state = " + getState()); } protected boolean shouldAlwaysRequestAudioFocusForCall() { if (mAlwaysRequestVolumeFocus == null) { Context context = getContext(); if (context == null) return false; mAlwaysRequestVolumeFocus = context.getResources().getBoolean( com.android.internal.R.bool.config_alwaysRequestAudioFocusForCalls); } return mAlwaysRequestVolumeFocus; } protected Context getContext() { Phone defaultPhone = getDefaultPhone(); return ((defaultPhone == null) ? null : defaultPhone.getContext()); Loading src/java/com/android/internal/telephony/ExtCallManager.java +2 −1 Original line number Diff line number Diff line Loading @@ -336,7 +336,8 @@ public class ExtCallManager extends CallManager { int curAudioMode = mAudioManager.getMode(); if (curAudioMode != AudioManager.MODE_RINGTONE) { // only request audio focus if the ringtone is going to be heard if (mAudioManager.getStreamVolume(AudioManager.STREAM_RING) > 0) { if (mAudioManager.getStreamVolume(AudioManager.STREAM_RING) > 0 || shouldAlwaysRequestAudioFocusForCall()) { Rlog.d(LOG_TAG, "requestAudioFocus on STREAM_RING"); mAudioManager.requestAudioFocusForCall(AudioManager.STREAM_RING, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT); Loading src/java/com/android/internal/telephony/InboundSmsHandler.java +20 −1 Original line number Diff line number Diff line Loading @@ -37,12 +37,14 @@ import android.os.Message; import android.os.PowerManager; import android.os.SystemProperties; import android.preference.PreferenceManager; import android.provider.Settings; import android.provider.Telephony; import android.provider.Telephony.Sms.Intents; import android.telephony.Rlog; import android.telephony.SmsMessage; import android.telephony.TelephonyManager; import android.text.TextUtils; import com.android.internal.telephony.util.BlacklistUtils; import com.android.internal.telephony.PhoneBase; import com.android.internal.util.HexDump; Loading @@ -50,7 +52,11 @@ import com.android.internal.util.State; import com.android.internal.util.StateMachine; import java.io.ByteArrayOutputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; import static android.telephony.TelephonyManager.PHONE_TYPE_CDMA; Loading Loading @@ -730,7 +736,20 @@ public abstract class InboundSmsHandler extends StateMachine { } Intent intent; if (destPort == -1) { List<String> regAddresses = Settings.Secure.getDelimitedStringAsList(mContext.getContentResolver(), Settings.Secure.PROTECTED_SMS_ADDRESSES , "\\|"); List<String> allAddresses = Intents .getNormalizedAddressesFromPdus(pdus, tracker.getFormat()); if (!Collections.disjoint(regAddresses, allAddresses)) { intent = new Intent(Intents.PROTECTED_SMS_RECEIVED_ACTION); intent.putExtra("pdus", pdus); intent.putExtra("format", tracker.getFormat()); dispatchIntent(intent, android.Manifest.permission.RECEIVE_PROTECTED_SMS, AppOpsManager.OP_RECEIVE_SMS, resultReceiver); return true; } else if (destPort == -1) { intent = new Intent(Intents.SMS_DELIVER_ACTION); // Direct the intent to only the default SMS app. If we can't find a default SMS app Loading src/java/com/android/internal/telephony/SmsApplication.java +10 −0 Original line number Diff line number Diff line Loading @@ -34,8 +34,11 @@ import android.provider.Settings; import android.provider.Telephony.Sms.Intents; import android.telephony.Rlog; import android.telephony.TelephonyManager; import com.android.internal.R; import com.android.internal.content.PackageMonitor; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.List; Loading Loading @@ -600,6 +603,13 @@ public final class SmsApplication { defaultSmsPackage = component.getPackageName(); } List<String> ignorePackages = Arrays.asList( context.getResources().getStringArray(R.array.config_ignored_sms_packages)); if (ignorePackages.contains(packageName)) { return false; } if ((defaultSmsPackage == null || !defaultSmsPackage.equals(packageName)) && !packageName.equals(BLUETOOTH_PACKAGE_NAME)) { // To write the message for someone other than the default SMS and BT app Loading Loading
src/java/android/provider/Telephony.java +70 −0 Original line number Diff line number Diff line Loading @@ -38,7 +38,10 @@ import com.android.internal.telephony.MSimConstants; import com.android.internal.telephony.SmsApplication; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; Loading Loading @@ -834,6 +837,30 @@ public final class Telephony { */ public static final int RESULT_SMS_BLACKLISTED_REGEX = 8; /** * Used internally: * Broadcast Action: A new protected text-based SMS message has been received * by the device. This intent will be delivered to all registered * receivers who possess {@link android.Manifest.permission#RECEIVE_PROTECTED_SMS}. * These apps SHOULD NOT write the message or notify the user. * The intent will have the following extra values: * </p> * * <ul> * <li><em>"pdus"</em> - An Object[] of byte[]s containing the PDUs * that make up the message.</li> * </ul> * * <p>The extra values can be extracted using * {@link #getMessagesFromIntent(Intent)}.</p> * * <p>If a BroadcastReceiver encounters an error while processing * this intent it should set the result code appropriately.</p> * @hide */ public static final String PROTECTED_SMS_RECEIVED_ACTION = "android.provider.Telephony.ACTION_PROTECTED_SMS_RECEIVED"; /** * Activity action: Ask the user to change the default * SMS application. This will show a dialog that asks the Loading Loading @@ -1120,6 +1147,49 @@ public final class Telephony { } return msgs; } /** * Read the normalized addresses out of PDUs * @param pdus bytes for PDUs * @param format the format of the message * @return a list of Addresses for the PDUs * @hide */ public static List<String> getNormalizedAddressesFromPdus(byte[][] pdus, String format) { int pduCount = pdus.length; SmsMessage[] msgs = new SmsMessage[pduCount]; List<String> addresses = new ArrayList<String>(); for (int i = 0; i < pduCount; i++) { byte[] pdu = (byte[]) pdus[i]; msgs[i] = SmsMessage.createFromPdu(pdu, format); String originatingAddress = msgs[i].getOriginatingAddress(); if (!TextUtils.isEmpty(originatingAddress)) { String normalized = normalizeDigitsOnly(originatingAddress); addresses.add(normalized); } } return addresses; } private static String normalizeDigitsOnly(String number) { return normalizeDigits(number, false /* strip non-digits */).toString(); } private static StringBuilder normalizeDigits(String number, boolean keepNonDigits) { StringBuilder normalizedDigits = new StringBuilder(number.length()); for (char c : number.toCharArray()) { int digit = Character.digit(c, 10); if (digit != -1) { normalizedDigits.append(digit); } else if (keepNonDigits) { normalizedDigits.append(c); } } return normalizedDigits; } } } Loading
src/java/com/android/internal/telephony/CallManager.java +14 −1 Original line number Diff line number Diff line Loading @@ -117,6 +117,8 @@ public class CallManager { protected boolean mSpeedUpAudioForMtCall = false; protected Boolean mAlwaysRequestVolumeFocus; protected CmHandler mHandler; // state registrants Loading Loading @@ -474,7 +476,8 @@ public class CallManager { int curAudioMode = audioManager.getMode(); if (curAudioMode != AudioManager.MODE_RINGTONE) { // only request audio focus if the ringtone is going to be heard if (audioManager.getStreamVolume(AudioManager.STREAM_RING) > 0) { if (audioManager.getStreamVolume(AudioManager.STREAM_RING) > 0 || shouldAlwaysRequestAudioFocusForCall()) { if (VDBG) Rlog.d(LOG_TAG, "requestAudioFocus on STREAM_RING"); audioManager.requestAudioFocusForCall(AudioManager.STREAM_RING, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT); Loading Loading @@ -527,6 +530,16 @@ public class CallManager { Rlog.d(LOG_TAG, "setAudioMode state = " + getState()); } protected boolean shouldAlwaysRequestAudioFocusForCall() { if (mAlwaysRequestVolumeFocus == null) { Context context = getContext(); if (context == null) return false; mAlwaysRequestVolumeFocus = context.getResources().getBoolean( com.android.internal.R.bool.config_alwaysRequestAudioFocusForCalls); } return mAlwaysRequestVolumeFocus; } protected Context getContext() { Phone defaultPhone = getDefaultPhone(); return ((defaultPhone == null) ? null : defaultPhone.getContext()); Loading
src/java/com/android/internal/telephony/ExtCallManager.java +2 −1 Original line number Diff line number Diff line Loading @@ -336,7 +336,8 @@ public class ExtCallManager extends CallManager { int curAudioMode = mAudioManager.getMode(); if (curAudioMode != AudioManager.MODE_RINGTONE) { // only request audio focus if the ringtone is going to be heard if (mAudioManager.getStreamVolume(AudioManager.STREAM_RING) > 0) { if (mAudioManager.getStreamVolume(AudioManager.STREAM_RING) > 0 || shouldAlwaysRequestAudioFocusForCall()) { Rlog.d(LOG_TAG, "requestAudioFocus on STREAM_RING"); mAudioManager.requestAudioFocusForCall(AudioManager.STREAM_RING, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT); Loading
src/java/com/android/internal/telephony/InboundSmsHandler.java +20 −1 Original line number Diff line number Diff line Loading @@ -37,12 +37,14 @@ import android.os.Message; import android.os.PowerManager; import android.os.SystemProperties; import android.preference.PreferenceManager; import android.provider.Settings; import android.provider.Telephony; import android.provider.Telephony.Sms.Intents; import android.telephony.Rlog; import android.telephony.SmsMessage; import android.telephony.TelephonyManager; import android.text.TextUtils; import com.android.internal.telephony.util.BlacklistUtils; import com.android.internal.telephony.PhoneBase; import com.android.internal.util.HexDump; Loading @@ -50,7 +52,11 @@ import com.android.internal.util.State; import com.android.internal.util.StateMachine; import java.io.ByteArrayOutputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; import static android.telephony.TelephonyManager.PHONE_TYPE_CDMA; Loading Loading @@ -730,7 +736,20 @@ public abstract class InboundSmsHandler extends StateMachine { } Intent intent; if (destPort == -1) { List<String> regAddresses = Settings.Secure.getDelimitedStringAsList(mContext.getContentResolver(), Settings.Secure.PROTECTED_SMS_ADDRESSES , "\\|"); List<String> allAddresses = Intents .getNormalizedAddressesFromPdus(pdus, tracker.getFormat()); if (!Collections.disjoint(regAddresses, allAddresses)) { intent = new Intent(Intents.PROTECTED_SMS_RECEIVED_ACTION); intent.putExtra("pdus", pdus); intent.putExtra("format", tracker.getFormat()); dispatchIntent(intent, android.Manifest.permission.RECEIVE_PROTECTED_SMS, AppOpsManager.OP_RECEIVE_SMS, resultReceiver); return true; } else if (destPort == -1) { intent = new Intent(Intents.SMS_DELIVER_ACTION); // Direct the intent to only the default SMS app. If we can't find a default SMS app Loading
src/java/com/android/internal/telephony/SmsApplication.java +10 −0 Original line number Diff line number Diff line Loading @@ -34,8 +34,11 @@ import android.provider.Settings; import android.provider.Telephony.Sms.Intents; import android.telephony.Rlog; import android.telephony.TelephonyManager; import com.android.internal.R; import com.android.internal.content.PackageMonitor; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.List; Loading Loading @@ -600,6 +603,13 @@ public final class SmsApplication { defaultSmsPackage = component.getPackageName(); } List<String> ignorePackages = Arrays.asList( context.getResources().getStringArray(R.array.config_ignored_sms_packages)); if (ignorePackages.contains(packageName)) { return false; } if ((defaultSmsPackage == null || !defaultSmsPackage.equals(packageName)) && !packageName.equals(BLUETOOTH_PACKAGE_NAME)) { // To write the message for someone other than the default SMS and BT app Loading