1 /* 2 * Copyright 2018 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.SystemProperties; 21 import android.support.annotation.VisibleForTesting; 22 import android.support.v14.preference.SwitchPreference; 23 import android.support.v7.preference.Preference; 24 25 import com.android.settings.core.PreferenceControllerMixin; 26 import com.android.settingslib.development.DeveloperOptionsPreferenceController; 27 28 public class BluetoothA2dpHwOffloadPreferenceController extends DeveloperOptionsPreferenceController 29 implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin { 30 31 private static final String PREFERENCE_KEY = "bluetooth_disable_a2dp_hw_offload"; 32 private final DevelopmentSettingsDashboardFragment mFragment; 33 34 static final String A2DP_OFFLOAD_DISABLED_PROPERTY = "persist.bluetooth.a2dp_offload.disabled"; 35 static final String A2DP_OFFLOAD_SUPPORTED_PROPERTY = "ro.bluetooth.a2dp_offload.supported"; 36 37 public BluetoothA2dpHwOffloadPreferenceController(Context context, 38 DevelopmentSettingsDashboardFragment fragment) { 39 super(context); 40 mFragment = fragment; 41 } 42 43 @Override 44 public String getPreferenceKey() { 45 return PREFERENCE_KEY; 46 } 47 48 @Override 49 public boolean onPreferenceChange(Preference preference, Object newValue) { 50 BluetoothA2dpHwOffloadRebootDialog.show(mFragment, this); 51 return false; 52 } 53 54 @Override 55 public void updateState(Preference preference) { 56 super.updateState(preference); 57 final boolean offloadSupported = 58 SystemProperties.getBoolean(A2DP_OFFLOAD_SUPPORTED_PROPERTY, false); 59 if (offloadSupported) { 60 final boolean offloadDisabled = 61 SystemProperties.getBoolean(A2DP_OFFLOAD_DISABLED_PROPERTY, false); 62 ((SwitchPreference) mPreference).setChecked(offloadDisabled); 63 } else { 64 mPreference.setEnabled(false); 65 ((SwitchPreference) mPreference).setChecked(true); 66 } 67 } 68 69 @Override 70 protected void onDeveloperOptionsSwitchDisabled() { 71 super.onDeveloperOptionsSwitchDisabled(); 72 final boolean offloadSupported = 73 SystemProperties.getBoolean(A2DP_OFFLOAD_SUPPORTED_PROPERTY, false); 74 if (offloadSupported) { 75 ((SwitchPreference) mPreference).setChecked(false); 76 SystemProperties.set(A2DP_OFFLOAD_DISABLED_PROPERTY, "false"); 77 } else { 78 ((SwitchPreference) mPreference).setChecked(true); 79 SystemProperties.set(A2DP_OFFLOAD_DISABLED_PROPERTY, "true"); 80 } 81 } 82 83 public void onA2dpHwDialogConfirmed() { 84 final boolean offloadDisabled = 85 SystemProperties.getBoolean(A2DP_OFFLOAD_DISABLED_PROPERTY, false); 86 SystemProperties.set(A2DP_OFFLOAD_DISABLED_PROPERTY, Boolean.toString(!offloadDisabled)); 87 } 88 89 } 90