1 /* 2 * Copyright 2014 The WebRTC Project Authors. All rights reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 package org.appspot.apprtc; 12 13 import android.app.Activity; 14 import android.content.SharedPreferences; 15 import android.content.SharedPreferences.OnSharedPreferenceChangeListener; 16 import android.os.Bundle; 17 import android.preference.ListPreference; 18 import android.preference.Preference; 19 import org.webrtc.Camera2Enumerator; 20 import org.webrtc.audio.JavaAudioDeviceModule; 21 22 /** 23 * Settings activity for AppRTC. 24 */ 25 public class SettingsActivity extends Activity implements OnSharedPreferenceChangeListener { 26 private SettingsFragment settingsFragment; 27 private String keyprefVideoCall; 28 private String keyprefScreencapture; 29 private String keyprefCamera2; 30 private String keyprefResolution; 31 private String keyprefFps; 32 private String keyprefCaptureQualitySlider; 33 private String keyprefMaxVideoBitrateType; 34 private String keyprefMaxVideoBitrateValue; 35 private String keyPrefVideoCodec; 36 private String keyprefHwCodec; 37 private String keyprefCaptureToTexture; 38 private String keyprefFlexfec; 39 40 private String keyprefStartAudioBitrateType; 41 private String keyprefStartAudioBitrateValue; 42 private String keyPrefAudioCodec; 43 private String keyprefNoAudioProcessing; 44 private String keyprefAecDump; 45 private String keyprefEnableSaveInputAudioToFile; 46 private String keyprefOpenSLES; 47 private String keyprefDisableBuiltInAEC; 48 private String keyprefDisableBuiltInAGC; 49 private String keyprefDisableBuiltInNS; 50 private String keyprefDisableWebRtcAGCAndHPF; 51 private String keyprefSpeakerphone; 52 53 private String keyPrefRoomServerUrl; 54 private String keyPrefDisplayHud; 55 private String keyPrefTracing; 56 private String keyprefEnabledRtcEventLog; 57 58 private String keyprefEnableDataChannel; 59 private String keyprefOrdered; 60 private String keyprefMaxRetransmitTimeMs; 61 private String keyprefMaxRetransmits; 62 private String keyprefDataProtocol; 63 private String keyprefNegotiated; 64 private String keyprefDataId; 65 66 @Override onCreate(Bundle savedInstanceState)67 protected void onCreate(Bundle savedInstanceState) { 68 super.onCreate(savedInstanceState); 69 keyprefVideoCall = getString(R.string.pref_videocall_key); 70 keyprefScreencapture = getString(R.string.pref_screencapture_key); 71 keyprefCamera2 = getString(R.string.pref_camera2_key); 72 keyprefResolution = getString(R.string.pref_resolution_key); 73 keyprefFps = getString(R.string.pref_fps_key); 74 keyprefCaptureQualitySlider = getString(R.string.pref_capturequalityslider_key); 75 keyprefMaxVideoBitrateType = getString(R.string.pref_maxvideobitrate_key); 76 keyprefMaxVideoBitrateValue = getString(R.string.pref_maxvideobitratevalue_key); 77 keyPrefVideoCodec = getString(R.string.pref_videocodec_key); 78 keyprefHwCodec = getString(R.string.pref_hwcodec_key); 79 keyprefCaptureToTexture = getString(R.string.pref_capturetotexture_key); 80 keyprefFlexfec = getString(R.string.pref_flexfec_key); 81 82 keyprefStartAudioBitrateType = getString(R.string.pref_startaudiobitrate_key); 83 keyprefStartAudioBitrateValue = getString(R.string.pref_startaudiobitratevalue_key); 84 keyPrefAudioCodec = getString(R.string.pref_audiocodec_key); 85 keyprefNoAudioProcessing = getString(R.string.pref_noaudioprocessing_key); 86 keyprefAecDump = getString(R.string.pref_aecdump_key); 87 keyprefEnableSaveInputAudioToFile = 88 getString(R.string.pref_enable_save_input_audio_to_file_key); 89 keyprefOpenSLES = getString(R.string.pref_opensles_key); 90 keyprefDisableBuiltInAEC = getString(R.string.pref_disable_built_in_aec_key); 91 keyprefDisableBuiltInAGC = getString(R.string.pref_disable_built_in_agc_key); 92 keyprefDisableBuiltInNS = getString(R.string.pref_disable_built_in_ns_key); 93 keyprefDisableWebRtcAGCAndHPF = getString(R.string.pref_disable_webrtc_agc_and_hpf_key); 94 keyprefSpeakerphone = getString(R.string.pref_speakerphone_key); 95 96 keyprefEnableDataChannel = getString(R.string.pref_enable_datachannel_key); 97 keyprefOrdered = getString(R.string.pref_ordered_key); 98 keyprefMaxRetransmitTimeMs = getString(R.string.pref_max_retransmit_time_ms_key); 99 keyprefMaxRetransmits = getString(R.string.pref_max_retransmits_key); 100 keyprefDataProtocol = getString(R.string.pref_data_protocol_key); 101 keyprefNegotiated = getString(R.string.pref_negotiated_key); 102 keyprefDataId = getString(R.string.pref_data_id_key); 103 104 keyPrefRoomServerUrl = getString(R.string.pref_room_server_url_key); 105 keyPrefDisplayHud = getString(R.string.pref_displayhud_key); 106 keyPrefTracing = getString(R.string.pref_tracing_key); 107 keyprefEnabledRtcEventLog = getString(R.string.pref_enable_rtceventlog_key); 108 109 // Display the fragment as the main content. 110 settingsFragment = new SettingsFragment(); 111 getFragmentManager() 112 .beginTransaction() 113 .replace(android.R.id.content, settingsFragment) 114 .commit(); 115 } 116 117 @Override onResume()118 protected void onResume() { 119 super.onResume(); 120 // Set summary to be the user-description for the selected value 121 SharedPreferences sharedPreferences = 122 settingsFragment.getPreferenceScreen().getSharedPreferences(); 123 sharedPreferences.registerOnSharedPreferenceChangeListener(this); 124 updateSummaryB(sharedPreferences, keyprefVideoCall); 125 updateSummaryB(sharedPreferences, keyprefScreencapture); 126 updateSummaryB(sharedPreferences, keyprefCamera2); 127 updateSummary(sharedPreferences, keyprefResolution); 128 updateSummary(sharedPreferences, keyprefFps); 129 updateSummaryB(sharedPreferences, keyprefCaptureQualitySlider); 130 updateSummary(sharedPreferences, keyprefMaxVideoBitrateType); 131 updateSummaryBitrate(sharedPreferences, keyprefMaxVideoBitrateValue); 132 setVideoBitrateEnable(sharedPreferences); 133 updateSummary(sharedPreferences, keyPrefVideoCodec); 134 updateSummaryB(sharedPreferences, keyprefHwCodec); 135 updateSummaryB(sharedPreferences, keyprefCaptureToTexture); 136 updateSummaryB(sharedPreferences, keyprefFlexfec); 137 138 updateSummary(sharedPreferences, keyprefStartAudioBitrateType); 139 updateSummaryBitrate(sharedPreferences, keyprefStartAudioBitrateValue); 140 setAudioBitrateEnable(sharedPreferences); 141 updateSummary(sharedPreferences, keyPrefAudioCodec); 142 updateSummaryB(sharedPreferences, keyprefNoAudioProcessing); 143 updateSummaryB(sharedPreferences, keyprefAecDump); 144 updateSummaryB(sharedPreferences, keyprefEnableSaveInputAudioToFile); 145 updateSummaryB(sharedPreferences, keyprefOpenSLES); 146 updateSummaryB(sharedPreferences, keyprefDisableBuiltInAEC); 147 updateSummaryB(sharedPreferences, keyprefDisableBuiltInAGC); 148 updateSummaryB(sharedPreferences, keyprefDisableBuiltInNS); 149 updateSummaryB(sharedPreferences, keyprefDisableWebRtcAGCAndHPF); 150 updateSummaryList(sharedPreferences, keyprefSpeakerphone); 151 152 updateSummaryB(sharedPreferences, keyprefEnableDataChannel); 153 updateSummaryB(sharedPreferences, keyprefOrdered); 154 updateSummary(sharedPreferences, keyprefMaxRetransmitTimeMs); 155 updateSummary(sharedPreferences, keyprefMaxRetransmits); 156 updateSummary(sharedPreferences, keyprefDataProtocol); 157 updateSummaryB(sharedPreferences, keyprefNegotiated); 158 updateSummary(sharedPreferences, keyprefDataId); 159 setDataChannelEnable(sharedPreferences); 160 161 updateSummary(sharedPreferences, keyPrefRoomServerUrl); 162 updateSummaryB(sharedPreferences, keyPrefDisplayHud); 163 updateSummaryB(sharedPreferences, keyPrefTracing); 164 updateSummaryB(sharedPreferences, keyprefEnabledRtcEventLog); 165 166 if (!Camera2Enumerator.isSupported(this)) { 167 Preference camera2Preference = settingsFragment.findPreference(keyprefCamera2); 168 169 camera2Preference.setSummary(getString(R.string.pref_camera2_not_supported)); 170 camera2Preference.setEnabled(false); 171 } 172 173 if (!JavaAudioDeviceModule.isBuiltInAcousticEchoCancelerSupported()) { 174 Preference disableBuiltInAECPreference = 175 settingsFragment.findPreference(keyprefDisableBuiltInAEC); 176 177 disableBuiltInAECPreference.setSummary(getString(R.string.pref_built_in_aec_not_available)); 178 disableBuiltInAECPreference.setEnabled(false); 179 } 180 181 Preference disableBuiltInAGCPreference = 182 settingsFragment.findPreference(keyprefDisableBuiltInAGC); 183 184 disableBuiltInAGCPreference.setSummary(getString(R.string.pref_built_in_agc_not_available)); 185 disableBuiltInAGCPreference.setEnabled(false); 186 187 if (!JavaAudioDeviceModule.isBuiltInNoiseSuppressorSupported()) { 188 Preference disableBuiltInNSPreference = 189 settingsFragment.findPreference(keyprefDisableBuiltInNS); 190 191 disableBuiltInNSPreference.setSummary(getString(R.string.pref_built_in_ns_not_available)); 192 disableBuiltInNSPreference.setEnabled(false); 193 } 194 } 195 196 @Override onPause()197 protected void onPause() { 198 super.onPause(); 199 SharedPreferences sharedPreferences = 200 settingsFragment.getPreferenceScreen().getSharedPreferences(); 201 sharedPreferences.unregisterOnSharedPreferenceChangeListener(this); 202 } 203 204 @Override onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key)205 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { 206 // clang-format off 207 if (key.equals(keyprefResolution) 208 || key.equals(keyprefFps) 209 || key.equals(keyprefMaxVideoBitrateType) 210 || key.equals(keyPrefVideoCodec) 211 || key.equals(keyprefStartAudioBitrateType) 212 || key.equals(keyPrefAudioCodec) 213 || key.equals(keyPrefRoomServerUrl) 214 || key.equals(keyprefMaxRetransmitTimeMs) 215 || key.equals(keyprefMaxRetransmits) 216 || key.equals(keyprefDataProtocol) 217 || key.equals(keyprefDataId)) { 218 updateSummary(sharedPreferences, key); 219 } else if (key.equals(keyprefMaxVideoBitrateValue) 220 || key.equals(keyprefStartAudioBitrateValue)) { 221 updateSummaryBitrate(sharedPreferences, key); 222 } else if (key.equals(keyprefVideoCall) 223 || key.equals(keyprefScreencapture) 224 || key.equals(keyprefCamera2) 225 || key.equals(keyPrefTracing) 226 || key.equals(keyprefCaptureQualitySlider) 227 || key.equals(keyprefHwCodec) 228 || key.equals(keyprefCaptureToTexture) 229 || key.equals(keyprefFlexfec) 230 || key.equals(keyprefNoAudioProcessing) 231 || key.equals(keyprefAecDump) 232 || key.equals(keyprefEnableSaveInputAudioToFile) 233 || key.equals(keyprefOpenSLES) 234 || key.equals(keyprefDisableBuiltInAEC) 235 || key.equals(keyprefDisableBuiltInAGC) 236 || key.equals(keyprefDisableBuiltInNS) 237 || key.equals(keyprefDisableWebRtcAGCAndHPF) 238 || key.equals(keyPrefDisplayHud) 239 || key.equals(keyprefEnableDataChannel) 240 || key.equals(keyprefOrdered) 241 || key.equals(keyprefNegotiated) 242 || key.equals(keyprefEnabledRtcEventLog)) { 243 updateSummaryB(sharedPreferences, key); 244 } else if (key.equals(keyprefSpeakerphone)) { 245 updateSummaryList(sharedPreferences, key); 246 } 247 // clang-format on 248 if (key.equals(keyprefMaxVideoBitrateType)) { 249 setVideoBitrateEnable(sharedPreferences); 250 } 251 if (key.equals(keyprefStartAudioBitrateType)) { 252 setAudioBitrateEnable(sharedPreferences); 253 } 254 if (key.equals(keyprefEnableDataChannel)) { 255 setDataChannelEnable(sharedPreferences); 256 } 257 } 258 updateSummary(SharedPreferences sharedPreferences, String key)259 private void updateSummary(SharedPreferences sharedPreferences, String key) { 260 Preference updatedPref = settingsFragment.findPreference(key); 261 // Set summary to be the user-description for the selected value 262 updatedPref.setSummary(sharedPreferences.getString(key, "")); 263 } 264 updateSummaryBitrate(SharedPreferences sharedPreferences, String key)265 private void updateSummaryBitrate(SharedPreferences sharedPreferences, String key) { 266 Preference updatedPref = settingsFragment.findPreference(key); 267 updatedPref.setSummary(sharedPreferences.getString(key, "") + " kbps"); 268 } 269 updateSummaryB(SharedPreferences sharedPreferences, String key)270 private void updateSummaryB(SharedPreferences sharedPreferences, String key) { 271 Preference updatedPref = settingsFragment.findPreference(key); 272 updatedPref.setSummary(sharedPreferences.getBoolean(key, true) 273 ? getString(R.string.pref_value_enabled) 274 : getString(R.string.pref_value_disabled)); 275 } 276 updateSummaryList(SharedPreferences sharedPreferences, String key)277 private void updateSummaryList(SharedPreferences sharedPreferences, String key) { 278 ListPreference updatedPref = (ListPreference) settingsFragment.findPreference(key); 279 updatedPref.setSummary(updatedPref.getEntry()); 280 } 281 setVideoBitrateEnable(SharedPreferences sharedPreferences)282 private void setVideoBitrateEnable(SharedPreferences sharedPreferences) { 283 Preference bitratePreferenceValue = 284 settingsFragment.findPreference(keyprefMaxVideoBitrateValue); 285 String bitrateTypeDefault = getString(R.string.pref_maxvideobitrate_default); 286 String bitrateType = 287 sharedPreferences.getString(keyprefMaxVideoBitrateType, bitrateTypeDefault); 288 if (bitrateType.equals(bitrateTypeDefault)) { 289 bitratePreferenceValue.setEnabled(false); 290 } else { 291 bitratePreferenceValue.setEnabled(true); 292 } 293 } 294 setAudioBitrateEnable(SharedPreferences sharedPreferences)295 private void setAudioBitrateEnable(SharedPreferences sharedPreferences) { 296 Preference bitratePreferenceValue = 297 settingsFragment.findPreference(keyprefStartAudioBitrateValue); 298 String bitrateTypeDefault = getString(R.string.pref_startaudiobitrate_default); 299 String bitrateType = 300 sharedPreferences.getString(keyprefStartAudioBitrateType, bitrateTypeDefault); 301 if (bitrateType.equals(bitrateTypeDefault)) { 302 bitratePreferenceValue.setEnabled(false); 303 } else { 304 bitratePreferenceValue.setEnabled(true); 305 } 306 } 307 setDataChannelEnable(SharedPreferences sharedPreferences)308 private void setDataChannelEnable(SharedPreferences sharedPreferences) { 309 boolean enabled = sharedPreferences.getBoolean(keyprefEnableDataChannel, true); 310 settingsFragment.findPreference(keyprefOrdered).setEnabled(enabled); 311 settingsFragment.findPreference(keyprefMaxRetransmitTimeMs).setEnabled(enabled); 312 settingsFragment.findPreference(keyprefMaxRetransmits).setEnabled(enabled); 313 settingsFragment.findPreference(keyprefDataProtocol).setEnabled(enabled); 314 settingsFragment.findPreference(keyprefNegotiated).setEnabled(enabled); 315 settingsFragment.findPreference(keyprefDataId).setEnabled(enabled); 316 } 317 } 318