Merge "Fix issue 2472495: Phone cannot be set to silent mode via volume keys while Driveabout is taking."
diff --git a/core/java/android/os/PowerManager.java b/core/java/android/os/PowerManager.java
index e4eaf45b..f4ca8bc 100644
--- a/core/java/android/os/PowerManager.java
+++ b/core/java/android/os/PowerManager.java
@@ -361,6 +361,9 @@
      */
     public WakeLock newWakeLock(int flags, String tag)
     {
+        if (tag == null) {
+            throw new NullPointerException("tag is null in PowerManager.newWakeLock");
+        }
         return new WakeLock(flags, tag);
     }
 
diff --git a/services/java/com/android/server/PowerManagerService.java b/services/java/com/android/server/PowerManagerService.java
index d72416d..848997b 100644
--- a/services/java/com/android/server/PowerManagerService.java
+++ b/services/java/com/android/server/PowerManagerService.java
@@ -571,6 +571,7 @@
             binder = b;
             tag = t;
             uid = u == MY_UID ? Process.SYSTEM_UID : u;
+            pid = Binder.getCallingPid();
             if (u != MY_UID || (
                     !"KEEP_SCREEN_ON_FLAG".equals(tag)
                     && !"KeyInputQueue".equals(tag))) {
@@ -595,6 +596,7 @@
         final IBinder binder;
         final String tag;
         final int uid;
+        final int pid;
         final int monitorType;
         boolean activated = true;
         int minState;
@@ -998,7 +1000,8 @@
                    activated = " activated";
                 }
                 pw.println("  " + type + " '" + wl.tag + "'" + acquireCausesWakeup
-                        + activated + " (minState=" + wl.minState + ")");
+                        + activated + " (minState=" + wl.minState + ", uid=" + wl.uid
+                        + ", pid=" + wl.pid + ")");
             }
 
             pw.println();
diff --git a/telephony/java/android/telephony/SmsMessage.java b/telephony/java/android/telephony/SmsMessage.java
index b8ea4c0..a284ea5 100644
--- a/telephony/java/android/telephony/SmsMessage.java
+++ b/telephony/java/android/telephony/SmsMessage.java
@@ -237,8 +237,8 @@
 
     /*
      * TODO(cleanup): It would make some sense if the result of
-     * preprocessing a message to determine the proper encoding (ie
-     * the resulting datastructure from calculateLength) could be
+     * preprocessing a message to determine the proper encoding (i.e.
+     * the resulting data structure from calculateLength) could be
      * passed as an argument to the actual final encoding function.
      * This would better ensure that the logic behind size calculation
      * actually matched the encoding.
@@ -427,7 +427,7 @@
      * @param destinationAddress the address of the destination for the message
      * @param destinationPort the port to deliver the message to at the
      *        destination
-     * @param data the dat for the message
+     * @param data the data for the message
      * @return a <code>SubmitPdu</code> containing the encoded SC
      *         address, if applicable, and the encoded message.
      *         Returns null on encode error.
diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java
index ae5b1de..f018d107 100644
--- a/telephony/java/android/telephony/TelephonyManager.java
+++ b/telephony/java/android/telephony/TelephonyManager.java
@@ -46,7 +46,7 @@
  * {@link android.content.Context#getSystemService
  * Context.getSystemService(Context.TELEPHONY_SERVICE)}.
  * <p>
- * Note that acess to some telephony information is
+ * Note that access to some telephony information is
  * permission-protected. Your application cannot access the protected
  * information unless it has the appropriate permissions declared in
  * its manifest file. Where permissions apply, they are noted in the
@@ -356,7 +356,7 @@
     }
 
     /**
-     * Returns the ISO country code equivilent of the current registered
+     * Returns the ISO country code equivalent of the current registered
      * operator's MCC (Mobile Country Code).
      * <p>
      * Availability: Only when user is registered to a network. Result may be
diff --git a/telephony/java/com/android/internal/telephony/PhoneBase.java b/telephony/java/com/android/internal/telephony/PhoneBase.java
index 358af95..a8f4143 100644
--- a/telephony/java/com/android/internal/telephony/PhoneBase.java
+++ b/telephony/java/com/android/internal/telephony/PhoneBase.java
@@ -585,7 +585,7 @@
 
     /**
      * Utility code to set the system locale if it's not set already
-     * @param langauge Two character language code desired
+     * @param language Two character language code desired
      * @param country Two character country code desired
      *
      *  {@hide}
@@ -694,22 +694,22 @@
 
     public void setTTYMode(int ttyMode, Message onComplete) {
         // This function should be overridden by the class CDMAPhone. Not implemented in GSMPhone.
-        Log.e(LOG_TAG, "Error! This function should never be executed, inactive CDMAPhone.");
+        logUnexpectedCdmaMethodCall("setTTYMode");
     }
 
     public void queryTTYMode(Message onComplete) {
         // This function should be overridden by the class CDMAPhone. Not implemented in GSMPhone.
-        Log.e(LOG_TAG, "Error! This function should never be executed, inactive CDMAPhone.");
+        logUnexpectedCdmaMethodCall("queryTTYMode");
     }
 
     public void enableEnhancedVoicePrivacy(boolean enable, Message onComplete) {
         // This function should be overridden by the class CDMAPhone. Not implemented in GSMPhone.
-        Log.e(LOG_TAG, "Error! This function should never be executed, inactive CDMAPhone.");
+        logUnexpectedCdmaMethodCall("enableEnhancedVoicePrivacy");
     }
 
     public void getEnhancedVoicePrivacy(Message onComplete) {
         // This function should be overridden by the class CDMAPhone. Not implemented in GSMPhone.
-        Log.e(LOG_TAG, "Error! This function should never be executed, inactive CDMAPhone.");
+        logUnexpectedCdmaMethodCall("getEnhancedVoicePrivacy");
     }
 
     public void setBandMode(int bandMode, Message response) {
@@ -754,7 +754,7 @@
      * Returns the CDMA ERI icon index to display
      */
     public int getCdmaEriIconIndex() {
-        Log.e(LOG_TAG, "Error! getCdmaEriIconIndex should never be executed in GSM mode");
+        logUnexpectedCdmaMethodCall("getCdmaEriIconIndex");
         return -1;
     }
 
@@ -764,7 +764,7 @@
      * 1 - FLASHING
      */
     public int getCdmaEriIconMode() {
-        Log.e(LOG_TAG, "Error! getCdmaEriIconMode should never be executed in GSM mode");
+        logUnexpectedCdmaMethodCall("getCdmaEriIconMode");
         return -1;
     }
 
@@ -772,82 +772,82 @@
      * Returns the CDMA ERI text,
      */
     public String getCdmaEriText() {
-        Log.e(LOG_TAG, "Error! getCdmaEriText should never be executed in GSM mode");
+        logUnexpectedCdmaMethodCall("getCdmaEriText");
         return "GSM nw, no ERI";
     }
 
     public String getCdmaMin() {
         // This function should be overridden by the class CDMAPhone. Not implemented in GSMPhone.
-        Log.e(LOG_TAG, "Error! This function should never be executed, inactive CDMAPhone.");
+        logUnexpectedCdmaMethodCall("getCdmaMin");
         return null;
     }
 
     public boolean isMinInfoReady() {
         // This function should be overridden by the class CDMAPhone. Not implemented in GSMPhone.
-        Log.e(LOG_TAG, "Error! This function should never be executed, inactive CDMAPhone.");
+        logUnexpectedCdmaMethodCall("isMinInfoReady");
         return false;
     }
 
     public String getCdmaPrlVersion(){
         //  This function should be overridden by the class CDMAPhone. Not implemented in GSMPhone.
-        Log.e(LOG_TAG, "Error! This function should never be executed, inactive CDMAPhone.");
+        logUnexpectedCdmaMethodCall("getCdmaPrlVersion");
         return null;
     }
 
     public void sendBurstDtmf(String dtmfString, int on, int off, Message onComplete) {
         // This function should be overridden by the class CDMAPhone. Not implemented in GSMPhone.
-        Log.e(LOG_TAG, "Error! This function should never be executed, inactive CDMAPhone.");
+        logUnexpectedCdmaMethodCall("sendBurstDtmf");
     }
 
     public void exitEmergencyCallbackMode() {
         // This function should be overridden by the class CDMAPhone. Not implemented in GSMPhone.
-        Log.e(LOG_TAG, "Error! This function should never be executed, inactive CDMAPhone.");
+        logUnexpectedCdmaMethodCall("exitEmergencyCallbackMode");
     }
 
     public void registerForCdmaOtaStatusChange(Handler h, int what, Object obj) {
         // This function should be overridden by the class CDMAPhone. Not implemented in GSMPhone.
-        Log.e(LOG_TAG, "Error! This function should never be executed, inactive CDMAPhone.");
+        logUnexpectedCdmaMethodCall("registerForCdmaOtaStatusChange");
     }
 
     public void unregisterForCdmaOtaStatusChange(Handler h) {
         // This function should be overridden by the class CDMAPhone. Not implemented in GSMPhone.
-        Log.e(LOG_TAG, "Error! This function should never be executed, inactive CDMAPhone.");
+        logUnexpectedCdmaMethodCall("unregisterForCdmaOtaStatusChange");
     }
 
     public void registerForSubscriptionInfoReady(Handler h, int what, Object obj) {
         // This function should be overridden by the class CDMAPhone. Not implemented in GSMPhone.
-        Log.e(LOG_TAG, "Error! This function should never be executed, inactive CDMAPhone.");
+        logUnexpectedCdmaMethodCall("registerForSubscriptionInfoReady");
     }
 
     public void unregisterForSubscriptionInfoReady(Handler h) {
         // This function should be overridden by the class CDMAPhone. Not implemented in GSMPhone.
-        Log.e(LOG_TAG, "Error! This function should never be executed, inactive CDMAPhone.");
+        logUnexpectedCdmaMethodCall("unregisterForSubscriptionInfoReady");
     }
 
     public  boolean isOtaSpNumber(String dialStr) {
         // This function should be overridden by the class CDMAPhone. Not implemented in GSMPhone.
-        Log.e(LOG_TAG, "Error! This function should never be executed, inactive CDMAPhone.");
+        logUnexpectedCdmaMethodCall("isOtaSpNumber");
         return false;
     }
 
     public void registerForCallWaiting(Handler h, int what, Object obj){
         // This function should be overridden by the class CDMAPhone. Not implemented in GSMPhone.
-        Log.e(LOG_TAG, "Error! This function should never be executed, inactive CDMAPhone.");
+        logUnexpectedCdmaMethodCall("registerForCallWaiting");
     }
 
     public void unregisterForCallWaiting(Handler h){
         // This function should be overridden by the class CDMAPhone. Not implemented in GSMPhone.
-        Log.e(LOG_TAG, "Error! This function should never be executed, inactive CDMAPhone.");
+        logUnexpectedCdmaMethodCall("unregisterForCallWaiting");
     }
 
     public void registerForEcmTimerReset(Handler h, int what, Object obj) {
         // This function should be overridden by the class CDMAPhone. Not implemented in GSMPhone.
-        Log.e(LOG_TAG, "Error! This function should never be executed, inactive CDMAPhone.");
+        logUnexpectedCdmaMethodCall("registerForEcmTimerReset");
     }
 
     public void unregisterForEcmTimerReset(Handler h) {
         // This function should be overridden by the class CDMAPhone. Not implemented in GSMPhone.
-        Log.e(LOG_TAG, "Error! This function should never be executed, inactive CDMAPhone.");
+        logUnexpectedCdmaMethodCall("unregisterForEcmTimerReset");
     }
 
     public void registerForSignalInfo(Handler h, int what, Object obj) {
@@ -908,12 +908,12 @@
 
      public void setOnEcbModeExitResponse(Handler h, int what, Object obj){
          // This function should be overridden by the class CDMAPhone. Not implemented in GSMPhone.
-         Log.e(LOG_TAG, "Error! This function should never be executed, inactive CDMAPhone.");
+         logUnexpectedCdmaMethodCall("setOnEcbModeExitResponse");
      }
 
      public void unsetOnEcbModeExitResponse(Handler h){
         // This function should be overridden by the class CDMAPhone. Not implemented in GSMPhone.
-         Log.e(LOG_TAG, "Error! This function should never be executed, inactive CDMAPhone.");
+         logUnexpectedCdmaMethodCall("unsetOnEcbModeExitResponse");
      }
 
     public String getInterfaceName(String apnType) {
@@ -984,7 +984,7 @@
     }
 
     /**
-     * Notifiy registrants of a new ringing Connection.
+     * Notify registrants of a new ringing Connection.
      * Subclasses of Phone probably want to replace this with a
      * version scoped to their packages
      */
@@ -1017,4 +1017,13 @@
                     + " mCallRingContinueToken=" + mCallRingContinueToken);
         }
     }
+
+    /**
+     * Common error logger method for unexpected calls to CDMA-only methods.
+     */
+    private void logUnexpectedCdmaMethodCall(String name)
+    {
+        Log.e(LOG_TAG, "Error! " + name + "() in PhoneBase should not be " +
+                "called, CDMAPhone inactive.");
+    }
 }