Dialer: Add support to show device info via *#0000#

It will call into DeviceInfo.apk to display the device info.

Change-Id: I59f16aafd856bdb68caa96f5ba5d878d7be3ca46
CRs-Fixed: 695024
diff --git a/src/com/android/dialer/SpecialCharSequenceMgr.java b/src/com/android/dialer/SpecialCharSequenceMgr.java
index 4303f3e..63b5588 100644
--- a/src/com/android/dialer/SpecialCharSequenceMgr.java
+++ b/src/com/android/dialer/SpecialCharSequenceMgr.java
@@ -74,6 +74,8 @@
     private static final String MMI_IMEI_DISPLAY = "*#06#";
     private static final String MMI_REGULATORY_INFO_DISPLAY = "*#07#";
 
+    private static final String PRL_VERSION_DISPLAY = "*#0000#";
+
     /**
      * Remembers the previous {@link QueryHandler} and cancel the operation when needed, to
      * prevent possible crash.
@@ -137,6 +139,7 @@
         String dialString = PhoneNumberUtils.stripSeparators(input);
 
         if (handleDeviceIdDisplay(context, dialString)
+                || handlePRLVersion(context, dialString)
                 || handleRegulatoryInfoDisplay(context, dialString)
                 || handlePinEntry(context, dialString)
                 || handleAdnEntry(context, dialString, textField)
@@ -147,6 +150,20 @@
         return false;
     }
 
+    static private boolean handlePRLVersion(Context context, String input) {
+        if (input.equals(PRL_VERSION_DISPLAY)) {
+            try {
+                Intent intent = new Intent("android.intent.action.ENGINEER_MODE_DEVICEINFO");
+                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+                context.startActivity(intent);
+                return true;
+            } catch (ActivityNotFoundException e) {
+                Log.d(TAG, "no activity to handle showing device info");
+            }
+        }
+        return false;
+    }
+
     /**
      * Cleanup everything around this class. Must be run inside the main thread.
      *
diff --git a/tests/src/com/android/dialer/SpecialCharSequenceMgrTest.java b/tests/src/com/android/dialer/SpecialCharSequenceMgrTest.java
new file mode 100644
index 0000000..79179ae
--- /dev/null
+++ b/tests/src/com/android/dialer/SpecialCharSequenceMgrTest.java
@@ -0,0 +1,64 @@
+/* Copyright (c) 2016, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of The Linux Foundation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+package com.android.dialer;
+
+import android.content.Context;
+import android.test.suitebuilder.annotation.SmallTest;
+import android.test.AndroidTestCase;
+import java.lang.reflect.*;
+import junit.framework.Assert;
+import junit.framework.TestCase;
+import com.android.dialer.SpecialCharSequenceMgr;
+
+@SmallTest
+public class SpecialCharSequenceMgrTest extends AndroidTestCase {
+
+    Context context;
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        context = getContext();
+    }
+
+    public void testHandlePRLVersion(){
+        Class<SpecialCharSequenceMgr> scMgrClass = SpecialCharSequenceMgr.class;
+
+        try {
+            Method handlePRLVersion = scMgrClass.getDeclaredMethod("handlePRLVersion",
+                    Context.class, String.class);
+            handlePRLVersion.setAccessible(true);
+            boolean result1 = (boolean)handlePRLVersion.invoke(context, "*#0000#");
+            boolean result2 = (boolean)handlePRLVersion.invoke(context, "*#BAD#");
+            assertTrue(result1);
+            assertFalse(result2);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+}