Merge "Merge Coral/Flame into AOSP master"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 3e821dc..7dae45d 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1196,6 +1196,9 @@
          emergency calling is not currently available. -->
     <string name="dial_emergency_calling_not_available">Emergency calling not available</string>
 
+    <!-- Only handle pin entry when phone user is system-->
+    <string name="pin_puk_system_user_only">Only the owner of the device can enter PIN/PUK codes.</string>
+
     <!-- Text for description of police calling type -->
     <string name="police_type_description">Police</string>
     <!-- Text for description of ambulance calling type -->
diff --git a/src/com/android/phone/PhoneUtils.java b/src/com/android/phone/PhoneUtils.java
index e46cfc0..6c3f0bf 100644
--- a/src/com/android/phone/PhoneUtils.java
+++ b/src/com/android/phone/PhoneUtils.java
@@ -45,8 +45,8 @@
 import com.android.internal.telephony.Call;
 import com.android.internal.telephony.CallManager;
 import com.android.internal.telephony.CallStateException;
-import com.android.internal.telephony.CallerInfo;
-import com.android.internal.telephony.CallerInfoAsyncQuery;
+import android.telephony.CallerInfo;
+import android.telephony.CallerInfoAsyncQuery;
 import com.android.internal.telephony.Connection;
 import com.android.internal.telephony.IccCard;
 import com.android.internal.telephony.MmiCode;
@@ -835,7 +835,7 @@
             // Store CNAP information retrieved from the Connection (we want to do this
             // here regardless of whether the number is empty or not).
             cit.currentInfo.cnapName =  c.getCnapName();
-            cit.currentInfo.name = cit.currentInfo.cnapName; // This can still get overwritten
+            cit.currentInfo.setName(cit.currentInfo.cnapName); // This can still get overwritten
                                                              // by ContactInfo later
             cit.currentInfo.numberPresentation = c.getNumberPresentation();
             cit.currentInfo.namePresentation = c.getCnapNamePresentation();
@@ -854,7 +854,7 @@
                 number = modifyForSpecialCnapCases(context, cit.currentInfo, number,
                         cit.currentInfo.numberPresentation);
 
-                cit.currentInfo.phoneNumber = number;
+                cit.currentInfo.setPhoneNumber(number);
                 // For scenarios where we may receive a valid number from the network but a
                 // restricted/unavailable presentation, we do not want to perform a contact query
                 // (see note on isFinal above). So we set isFinal to true here as well.
@@ -913,14 +913,14 @@
                     // Store CNAP information retrieved from the Connection
                     cit.currentInfo.cnapName =  c.getCnapName();
                     // This can still get overwritten by ContactInfo
-                    cit.currentInfo.name = cit.currentInfo.cnapName;
+                    cit.currentInfo.setName(cit.currentInfo.cnapName);
                     cit.currentInfo.numberPresentation = c.getNumberPresentation();
                     cit.currentInfo.namePresentation = c.getCnapNamePresentation();
 
                     updatedNumber = modifyForSpecialCnapCases(context, cit.currentInfo,
                             updatedNumber, cit.currentInfo.numberPresentation);
 
-                    cit.currentInfo.phoneNumber = updatedNumber;
+                    cit.currentInfo.setPhoneNumber(updatedNumber);
                     if (DBG) {
                         log("startGetCallerInfo: updatedNumber="
                                 + toLogSafePhoneNumber(updatedNumber));
@@ -951,7 +951,7 @@
                     // Store CNAP information retrieved from the Connection
                     cit.currentInfo.cnapName = c.getCnapName();  // This can still get
                                                                  // overwritten by ContactInfo
-                    cit.currentInfo.name = cit.currentInfo.cnapName;
+                    cit.currentInfo.setName(cit.currentInfo.cnapName);
                     cit.currentInfo.numberPresentation = c.getNumberPresentation();
                     cit.currentInfo.namePresentation = c.getCnapNamePresentation();
 
@@ -1032,7 +1032,7 @@
                     // ...but copy over the (few) things we care about
                     // from the original CallerInfo object:
                     if (newCi != null) {
-                        newCi.phoneNumber = ci.phoneNumber; // To get formatted phone number
+                        newCi.setPhoneNumber(ci.getPhoneNumber()); // To get formatted phone number
                         newCi.geoDescription = ci.geoDescription; // To get geo description string
                         ci = newCi;
                     }
@@ -1054,14 +1054,14 @@
 
         String compactName = null;
         if (ci != null) {
-            if (TextUtils.isEmpty(ci.name)) {
+            if (TextUtils.isEmpty(ci.getName())) {
                 // Perform any modifications for special CNAP cases to
                 // the phone number being displayed, if applicable.
-                compactName = modifyForSpecialCnapCases(context, ci, ci.phoneNumber,
+                compactName = modifyForSpecialCnapCases(context, ci, ci.getPhoneNumber(),
                                                         ci.numberPresentation);
             } else {
                 // Don't call modifyForSpecialCnapCases on regular name. See b/2160795.
-                compactName = ci.name;
+                compactName = ci.getName();
             }
         }
 
diff --git a/src/com/android/phone/SpecialCharSequenceMgr.java b/src/com/android/phone/SpecialCharSequenceMgr.java
index 514b2c9..674449e 100644
--- a/src/com/android/phone/SpecialCharSequenceMgr.java
+++ b/src/com/android/phone/SpecialCharSequenceMgr.java
@@ -21,6 +21,7 @@
 import android.content.ActivityNotFoundException;
 import android.content.Context;
 import android.content.Intent;
+import android.os.UserManager;
 import android.provider.Settings;
 import android.telephony.PhoneNumberUtils;
 import android.telephony.SubscriptionInfo;
@@ -233,32 +234,45 @@
         // if a dialstring is an MMI code.
         if ((input.startsWith("**04") || input.startsWith("**05"))
                 && input.endsWith("#")) {
-            PhoneGlobals app = PhoneGlobals.getInstance();
-            Phone phone;
-            int subId;
-            if (input.startsWith("**04")) {
-                subId = getNextSubIdForState(IccCardConstants.State.PIN_REQUIRED, context);
-            } else {
-                subId = getNextSubIdForState(IccCardConstants.State.PUK_REQUIRED, context);
-            }
-            if (SubscriptionManager.isValidSubscriptionId(subId)) {
-                log("get phone with subId: " + subId);
-                phone = PhoneGlobals.getPhone(subId);
-            } else {
-                log("get default phone");
-                phone = PhoneGlobals.getPhone();
-            }
-            boolean isMMIHandled = phone.handlePinMmi(input);
+            UserManager userManager = (UserManager) pukInputActivity
+                       .getSystemService(Context.USER_SERVICE);
+            if (userManager.isSystemUser()) {
+                PhoneGlobals app = PhoneGlobals.getInstance();
+                Phone phone;
+                int subId;
+                if (input.startsWith("**04")) {
+                    subId = getNextSubIdForState(IccCardConstants.State.PIN_REQUIRED, context);
+                } else {
+                    subId = getNextSubIdForState(IccCardConstants.State.PUK_REQUIRED, context);
+                }
+                if (SubscriptionManager.isValidSubscriptionId(subId)) {
+                    log("get phone with subId: " + subId);
+                    phone = PhoneGlobals.getPhone(subId);
+                } else {
+                    log("get default phone");
+                    phone = PhoneGlobals.getPhone();
+                }
+                boolean isMMIHandled = phone.handlePinMmi(input);
 
-            // if the PUK code is recognized then indicate to the
-            // phone app that an attempt to unPUK the device was
-            // made with this activity.  The PUK code may still
-            // fail though, but we won't know until the MMI code
-            // returns a result.
-            if (isMMIHandled && input.startsWith("**05")) {
-                app.setPukEntryActivity(pukInputActivity);
+                // if the PUK code is recognized then indicate to the
+                // phone app that an attempt to unPUK the device was
+                // made with this activity.  The PUK code may still
+                // fail though, but we won't know until the MMI code
+                // returns a result.
+                if (isMMIHandled && input.startsWith("**05")) {
+                    app.setPukEntryActivity(pukInputActivity);
+                }
+                return isMMIHandled;
+            } else {
+                AlertDialog dialog = new AlertDialog.Builder(context)
+                        .setMessage(R.string.pin_puk_system_user_only)
+                        .setPositiveButton(R.string.ok, null)
+                        .setCancelable(true).create();
+                dialog.show();
+                dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
+                dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
+                return true;
             }
-            return isMMIHandled;
         }
         return false;
     }
diff --git a/tests/src/com/android/phone/CnapTest.java b/tests/src/com/android/phone/CnapTest.java
index 7161ba8..534d02a 100644
--- a/tests/src/com/android/phone/CnapTest.java
+++ b/tests/src/com/android/phone/CnapTest.java
@@ -19,12 +19,9 @@
 import android.content.Context;
 import android.test.AndroidTestCase;
 import android.test.suitebuilder.annotation.SmallTest;
-import android.util.Log;
-import com.android.internal.telephony.CallerInfo;
-import com.android.phone.PhoneUtils;
+import android.telephony.CallerInfo;
+
 import static com.android.internal.telephony.PhoneConstants.PRESENTATION_ALLOWED;
-import static com.android.internal.telephony.PhoneConstants.PRESENTATION_PAYPHONE;
-import static com.android.internal.telephony.PhoneConstants.PRESENTATION_RESTRICTED;
 import static com.android.internal.telephony.PhoneConstants.PRESENTATION_UNKNOWN;
 
 // Test suite for the Caller Name Presentation (CNAP) handling.