Debug feature for HDCP compliance testing.

Bug: 4149811

Add a setting in Application->Development to change HDCP checking.

Change-Id: I5561b097b3fd7dbfc4eaf1977b80a37fc29572aa
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index 6194719..482830c 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -533,11 +533,32 @@
         <item>Long</item>
     </string-array>
 
-    <!-- Valeus for the list of long press timeout options. -->
+    <!-- Values for the list of long press timeout options. -->
     <string-array name="long_press_timeout_selector_values" translatable="false">
         <item>500</item>
         <item>1000</item>
         <item>1500</item>
     </string-array>
 
+    <!-- Titles for HDCP checking preference. [CHAR LIMIT=35] -->
+    <string-array name="hdcp_checking_titles">
+        <item>Never check</item>
+        <item>Check for DRM content only</item>
+        <item>Always check</item>
+    </string-array>
+
+    <!-- Values for HDCP checking preference. -->
+    <string-array name="hdcp_checking_values" translatable="false" >
+        <item>never</item>
+        <item>drm-only</item>
+        <item>always</item>
+    </string-array>
+
+    <!-- Summaries for HDCP checking preference. [CHAR LIMIT=100]-->
+    <string-array name="hdcp_checking_summaries" >
+        <item>Never use HDCP checking</item>
+        <item>Use HDCP checking for DRM content only</item>
+        <item>Always use HDCP checking</item>
+    </string-array>
 </resources>
+
diff --git a/res/values/strings.xml b/res/values/strings.xml
index b3e439f..80f3d57 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -3319,4 +3319,9 @@
     <string name="misc_files_selected_count_bytes"><xliff:g id="number" example="3.25MB">%1$s</xliff:g> out of <xliff:g id="total" example="15.25MB">%2$s</xliff:g></string>
     <!--  action to select all [CHAR LIMIT=30] -->
     <string name="select_all">Select All</string>
+
+    <!-- HDCP checking title, used for debug purposes only. [CHAR LIMIT=25] -->
+    <string name="hdcp_checking_title">HDCP checking</string>
+    <!-- HDCP checking dialog title, used for debug purposes only. [CHAR LIMIT=25] -->
+    <string name="hdcp_checking_dialog_title">Set HDCP checking behavior</string>
 </resources>
diff --git a/res/xml/development_prefs.xml b/res/xml/development_prefs.xml
index 77c100a..292206a 100644
--- a/res/xml/development_prefs.xml
+++ b/res/xml/development_prefs.xml
@@ -32,4 +32,10 @@
         android:title="@string/allow_mock_location" 
         android:summary="@string/allow_mock_location_summary"/>
 
+    <ListPreference
+        android:key="hdcp_checking"
+        android:title="@string/hdcp_checking_title"
+        android:dialogTitle="@string/hdcp_checking_dialog_title"
+        android:entries="@array/hdcp_checking_titles"
+        android:entryValues="@array/hdcp_checking_values" />
 </PreferenceScreen>
diff --git a/src/com/android/settings/DevelopmentSettings.java b/src/com/android/settings/DevelopmentSettings.java
index c9c9263..2508454 100644
--- a/src/com/android/settings/DevelopmentSettings.java
+++ b/src/com/android/settings/DevelopmentSettings.java
@@ -21,22 +21,29 @@
 import android.content.ContentResolver;
 import android.content.DialogInterface;
 import android.os.BatteryManager;
+import android.os.Build;
 import android.os.Bundle;
+import android.os.SystemProperties;
+import android.preference.CheckBoxPreference;
+import android.preference.ListPreference;
 import android.preference.Preference;
 import android.preference.PreferenceFragment;
 import android.preference.PreferenceScreen;
-import android.preference.CheckBoxPreference;
+import android.preference.Preference.OnPreferenceChangeListener;
 import android.provider.Settings;
 
 /*
  * Displays preferences for application developers.
  */
 public class DevelopmentSettings extends PreferenceFragment
-        implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener {
+        implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener,
+                OnPreferenceChangeListener {
 
     private static final String ENABLE_ADB = "enable_adb";
     private static final String KEEP_SCREEN_ON = "keep_screen_on";
     private static final String ALLOW_MOCK_LOCATION = "allow_mock_location";
+    private static final String HDCP_CHECKING_KEY = "hdcp_checking";
+    private static final String HDCP_CHECKING_PROPERTY = "persist.sys.hdcp_checking";
 
     private CheckBoxPreference mEnableAdb;
     private CheckBoxPreference mKeepScreenOn;
@@ -56,6 +63,18 @@
         mEnableAdb = (CheckBoxPreference) findPreference(ENABLE_ADB);
         mKeepScreenOn = (CheckBoxPreference) findPreference(KEEP_SCREEN_ON);
         mAllowMockLocation = (CheckBoxPreference) findPreference(ALLOW_MOCK_LOCATION);
+
+        removeHdcpOptionsForProduction();
+    }
+
+    private void removeHdcpOptionsForProduction() {
+        if ("user".equals(Build.TYPE)) {
+            Preference hdcpChecking = findPreference(HDCP_CHECKING_KEY);
+            if (hdcpChecking != null) {
+                // Remove the preference
+                getPreferenceScreen().removePreference(hdcpChecking);
+            }
+        }
     }
 
     @Override
@@ -69,6 +88,26 @@
                 Settings.System.STAY_ON_WHILE_PLUGGED_IN, 0) != 0);
         mAllowMockLocation.setChecked(Settings.Secure.getInt(cr,
                 Settings.Secure.ALLOW_MOCK_LOCATION, 0) != 0);
+        updateHdcpValues();
+    }
+
+    private void updateHdcpValues() {
+        int index = 1; // Defaults to drm-only. Needs to match with R.array.hdcp_checking_values
+        ListPreference hdcpChecking = (ListPreference) findPreference(HDCP_CHECKING_KEY);
+        if (hdcpChecking != null) {
+            String currentValue = SystemProperties.get(HDCP_CHECKING_PROPERTY);
+            String[] values = getResources().getStringArray(R.array.hdcp_checking_values);
+            String[] summaries = getResources().getStringArray(R.array.hdcp_checking_summaries);
+            for (int i = 0; i < values.length; i++) {
+                if (currentValue.equals(values[i])) {
+                    index = i;
+                    break;
+                }
+            }
+            hdcpChecking.setValue(values[index]);
+            hdcpChecking.setSummary(summaries[index]);
+            hdcpChecking.setOnPreferenceChangeListener(this);
+        }
     }
 
     @Override
@@ -137,4 +176,14 @@
         dismissDialog();
         super.onDestroy();
     }
+
+    @Override
+    public boolean onPreferenceChange(Preference preference, Object newValue) {
+        if (HDCP_CHECKING_KEY.equals(preference.getKey())) {
+            SystemProperties.set(HDCP_CHECKING_PROPERTY, newValue.toString());
+            updateHdcpValues();
+            return true;
+        }
+        return false;
+    }
 }