diff options
author | Adnan <adnan@cyngn.com> | 2014-11-06 16:41:33 -0800 |
---|---|---|
committer | Martin Brabham <mbrabham@cyngn.com> | 2014-11-10 18:53:18 +0000 |
commit | c309fdf772ede3cd71040ccb63a1f862712193a2 (patch) | |
tree | 01b188d603466c759b42b88dbbe9f5eb7e3148f6 | |
parent | 29b1dc3848144325ad5adb67c887080427d3767d (diff) | |
download | android_packages_services_Telephony-c309fdf772ede3cd71040ccb63a1f862712193a2.tar.gz android_packages_services_Telephony-c309fdf772ede3cd71040ccb63a1f862712193a2.tar.bz2 android_packages_services_Telephony-c309fdf772ede3cd71040ccb63a1f862712193a2.zip |
Telephony: Implement protected sms broadcast API.
- Normalize any addresses to be added or removed.
- Enforce MODIFY_PROTECTED_SMS_LIST permission.
Change-Id: Ieb0cb46be6ce107297988f6035a0a13d0db2c850
-rw-r--r-- | src/com/android/phone/PhoneInterfaceManager.java | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java index 58d06c4d3..16a9ac31c 100644 --- a/src/com/android/phone/PhoneInterfaceManager.java +++ b/src/com/android/phone/PhoneInterfaceManager.java @@ -19,6 +19,7 @@ package com.android.phone; +import android.Manifest; import android.app.ActivityManager; import android.app.AppOpsManager; import android.bluetooth.IBluetoothHeadsetPhone; @@ -63,6 +64,7 @@ import com.android.internal.util.HexDump; import com.android.internal.telephony.uicc.IccIoResult; import com.android.internal.telephony.uicc.IccUtils; import com.android.internal.telephony.CommandException; +import com.google.i18n.phonenumbers.PhoneNumberUtil; import java.util.ArrayList; import java.util.HashMap; @@ -1049,6 +1051,74 @@ public class PhoneInterfaceManager extends ITelephony.Stub implements CallModele mPhone.setCellInfoListRate(rateInMillis); } + + /** + * Allows an application to add a protected sms address if the application has + * been granted the permission MODIFY_PROTECTED_SMS_LIST. + * @param address + * @hide + */ + @Override + public void addProtectedSmsAddress(String address) { + // Enforce MODIFY_PROTECTED_SMS_LIST permission + // requires the application to be signature + enforceModifyProtectedSms(); + + if (TextUtils.isEmpty(address)) { + return; + } + + //Normalize the number + String normalized = PhoneNumberUtil.normalizeDigitsOnly(address); + + List<String> settings = + Settings.Secure.getDelimitedStringAsList(mApp.getContentResolver(), + Settings.Secure.PROTECTED_SMS_ADDRESSES, "\\|"); + if (!settings.contains(normalized)) { + // Add the address + settings.add(normalized); + } + + // Commit + Settings.Secure.putString(mApp.getContentResolver(), + Settings.Secure.PROTECTED_SMS_ADDRESSES, TextUtils.join("|", settings)); + } + + /** + * Allows an application to revoke/remove a protected sms address if the application has been + * granted the permission MODIFY_PROTECTED_SMS_LIST. + * @param address + * @return true if address is successfully removed + * @hide + */ + @Override + public boolean revokeProtectedSmsAddress(String address) { + // Enforce MODIFY_PROTECTED_SMS_LIST permission + // requires the application to be signature + enforceModifyProtectedSms(); + + if (TextUtils.isEmpty(address)) { + return false; + } + + //Normalize the number + String normalized = PhoneNumberUtil.normalizeDigitsOnly(address); + + List<String> settings = + Settings.Secure.getDelimitedStringAsList(mApp.getContentResolver(), + Settings.Secure.PROTECTED_SMS_ADDRESSES, "\\|"); + + if (settings.contains(normalized)) { + settings.remove(normalized); + // Commit + Settings.Secure.putString(mApp.getContentResolver(), + Settings.Secure.PROTECTED_SMS_ADDRESSES, TextUtils.join("\\|", settings)); + return true; + } else { + return false; + } + } + // // Internal helper methods. // @@ -1104,6 +1174,16 @@ public class PhoneInterfaceManager extends ITelephony.Stub implements CallModele } /** + * Make sure the caller has the MODIFY_PROTECTED_SMS_LIST permission + * + * @throws SecurityException if the caller does not have the required permission + */ + private void enforceModifyProtectedSms() { + mApp.enforceCallingOrSelfPermission( + android.Manifest.permission.MODIFY_PROTECTED_SMS_LIST, null); + } + + /** * Make sure the caller has the CALL_PHONE permission. * * @throws SecurityException if the caller does not have the required permission |