notifyCarrierNetworkChange:TelephonyManager->CarrierService

Re-checkin of 7f8be9d89b7f294bf5e5d377908a5c74d2f4968f.

ORIGINAL CHANGES:

Per API review, move TelephonyManager.notifyCarrierNetworkChange() to
CarrierService.notifyCarrierNetworkChange(). Underlying telephony
implementation remains unchanged.

Also minor tweaks to CarrierService:
* Remove some unnecessary @hide
* Remove final qualifier from onBind() so that subclasses can handle
  new internal callers that want to bind to it.

ADDITIONAL CHANGES:

- Fixes stack so that a SecurityException is thrown when caller
  does not have MODIFY_PHONE_STATE or carrier privileges.

Bug: 21572049
Bug: 21630803
Bug: 21721768

Change-Id: Ie952651d2f15c370de713ed8abb6d9f6f07dd2b4
diff --git a/services/core/java/com/android/server/TelephonyRegistry.java b/services/core/java/com/android/server/TelephonyRegistry.java
index bc93268..01a4ec8 100644
--- a/services/core/java/com/android/server/TelephonyRegistry.java
+++ b/services/core/java/com/android/server/TelephonyRegistry.java
@@ -817,9 +817,8 @@
 
     @Override
     public void notifyCarrierNetworkChange(boolean active) {
-        if (!checkNotifyPermissionOrCarrierPrivilege("notifyCarrierNetworkChange()")) {
-            return;
-        }
+        enforceNotifyPermissionOrCarrierPrivilege("notifyCarrierNetworkChange()");
+
         if (VDBG) {
             log("notifyCarrierNetworkChange: active=" + active);
         }
@@ -1486,15 +1485,12 @@
                 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
     }
 
-    private boolean checkNotifyPermissionOrCarrierPrivilege(String method) {
-        if  (checkNotifyPermission() || checkCarrierPrivilege()) {
-            return true;
+    private void enforceNotifyPermissionOrCarrierPrivilege(String method) {
+        if  (checkNotifyPermission()) {
+            return;
         }
 
-        String msg = "Modify Phone State or Carrier Privilege Permission Denial: " + method
-                + " from pid=" + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
-        if (DBG) log(msg);
-        return false;
+        enforceCarrierPrivilege();
     }
 
     private boolean checkNotifyPermission(String method) {
@@ -1512,17 +1508,20 @@
                 == PackageManager.PERMISSION_GRANTED;
     }
 
-    private boolean checkCarrierPrivilege() {
+    private void enforceCarrierPrivilege() {
         TelephonyManager tm = TelephonyManager.getDefault();
         String[] pkgs = mContext.getPackageManager().getPackagesForUid(Binder.getCallingUid());
         for (String pkg : pkgs) {
             if (tm.checkCarrierPrivilegesForPackage(pkg) ==
                     TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
-                return true;
+                return;
             }
         }
 
-        return false;
+        String msg = "Carrier Privilege Permission Denial: from pid=" + Binder.getCallingPid()
+                + ", uid=" + Binder.getCallingUid();
+        if (DBG) log(msg);
+        throw new SecurityException(msg);
     }
 
     private void checkListenerPermission(int events) {