1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings.development; 18 19 import android.content.Context; 20 import android.os.Build; 21 import android.os.SystemProperties; 22 import android.support.annotation.VisibleForTesting; 23 import android.support.v7.preference.ListPreference; 24 import android.support.v7.preference.Preference; 25 import android.text.TextUtils; 26 27 import com.android.settings.R; 28 import com.android.settings.core.PreferenceControllerMixin; 29 import com.android.settingslib.development.DeveloperOptionsPreferenceController; 30 import com.android.settingslib.development.SystemPropPoker; 31 32 public class HdcpCheckingPreferenceController extends DeveloperOptionsPreferenceController 33 implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin { 34 35 private static final String HDCP_CHECKING_KEY = "hdcp_checking"; 36 37 @VisibleForTesting 38 static final String HDCP_CHECKING_PROPERTY = "persist.sys.hdcp_checking"; 39 @VisibleForTesting 40 static final String USER_BUILD_TYPE = "user"; 41 42 private final String[] mListValues; 43 private final String[] mListSummaries; 44 HdcpCheckingPreferenceController(Context context)45 public HdcpCheckingPreferenceController(Context context) { 46 super(context); 47 48 mListValues = mContext.getResources().getStringArray(R.array.hdcp_checking_values); 49 mListSummaries = mContext.getResources().getStringArray(R.array.hdcp_checking_summaries); 50 } 51 52 @Override isAvailable()53 public boolean isAvailable() { 54 return !TextUtils.equals(USER_BUILD_TYPE, getBuildType()); 55 } 56 57 @Override getPreferenceKey()58 public String getPreferenceKey() { 59 return HDCP_CHECKING_KEY; 60 } 61 62 @Override onPreferenceChange(Preference preference, Object newValue)63 public boolean onPreferenceChange(Preference preference, Object newValue) { 64 SystemProperties.set(HDCP_CHECKING_PROPERTY, newValue.toString()); 65 updateHdcpValues((ListPreference) mPreference); 66 SystemPropPoker.getInstance().poke(); 67 return true; 68 } 69 70 @Override updateState(Preference preference)71 public void updateState(Preference preference) { 72 updateHdcpValues((ListPreference) mPreference); 73 } 74 updateHdcpValues(ListPreference preference)75 private void updateHdcpValues(ListPreference preference) { 76 final String currentValue = SystemProperties.get(HDCP_CHECKING_PROPERTY); 77 int index = 1; // Defaults to drm-only. Needs to match with R.array.hdcp_checking_values 78 for (int i = 0; i < mListValues.length; i++) { 79 if (TextUtils.equals(currentValue, mListValues[i])) { 80 index = i; 81 break; 82 } 83 } 84 preference.setValue(mListValues[index]); 85 preference.setSummary(mListSummaries[index]); 86 } 87 88 @VisibleForTesting getBuildType()89 public String getBuildType() { 90 return Build.TYPE; 91 } 92 } 93