From f4acaad40771df06411353a2dfa377b4762395ac Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Tue, 21 Mar 2017 10:23:16 -0700 Subject: [PATCH] Add Pixel, S5, Redmi Note 3, and Xiaomi Mi4 to AEC blacklist Make these application-level changes Helps #6241 // FREEBIE --- .../securesms/ApplicationContext.java | 46 ++++++++++++++++--- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/src/org/thoughtcrime/securesms/ApplicationContext.java b/src/org/thoughtcrime/securesms/ApplicationContext.java index aab1bc052a..dc55e0bdea 100644 --- a/src/org/thoughtcrime/securesms/ApplicationContext.java +++ b/src/org/thoughtcrime/securesms/ApplicationContext.java @@ -42,12 +42,16 @@ import org.thoughtcrime.securesms.service.RotateSignedPreKeyListener; import org.thoughtcrime.securesms.service.UpdateApkRefreshListener; import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.webrtc.PeerConnectionFactory; +import org.webrtc.voiceengine.WebRtcAudioManager; +import org.webrtc.voiceengine.WebRtcAudioUtils; import org.whispersystems.jobqueue.JobManager; import org.whispersystems.jobqueue.dependencies.DependencyInjector; import org.whispersystems.jobqueue.requirements.NetworkRequirementProvider; import org.whispersystems.libsignal.logging.SignalProtocolLoggerProvider; import org.whispersystems.libsignal.util.AndroidSignalProtocolLogger; +import java.util.HashSet; +import java.util.Set; import java.util.concurrent.TimeUnit; import dagger.ObjectGraph; @@ -87,10 +91,7 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc initializePeriodicTasks(); initializeCircumvention(); initializeSetVideoCapable(); - - if (Build.VERSION.SDK_INT >= 11) { - PeerConnectionFactory.initializeAndroidGlobals(this, true, true, true); - } + initializeWebRtc(); } @Override @@ -176,8 +177,38 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc } } + private void initializeWebRtc() { + Set HARDWARE_AEC_BLACKLIST = new HashSet() {{ + add("D6503"); // Sony Xperia Z2 D6503 + add("ONE A2005"); // OnePlus 2 + add("MotoG3"); // Moto G (3rd Generation) + add("Nexus 6P"); // Nexus 6p + add("Pixel"); // Pixel #6241 + add("Pixel XL"); // Pixel XL #6241 + add("MI 4LTE"); // Xiami Mi4 #6241 + add("Redmi Note 3"); // Redmi Note 3 #6241 + add("SM-G900F"); // Samsung Galaxy S5 #6241 + }}; + + Set OPEN_SL_ES_BLACKLIST = new HashSet() {{ + add("MI 4LTE"); // Xiami Mi4 #6241 + }}; + + if (Build.VERSION.SDK_INT >= 11) { + if (HARDWARE_AEC_BLACKLIST.contains(Build.MODEL)) { + WebRtcAudioUtils.setWebRtcBasedAcousticEchoCanceler(true); + } + + if (OPEN_SL_ES_BLACKLIST.contains(Build.MODEL)) { + WebRtcAudioManager.setBlacklistDeviceForOpenSLESUsage(true); + } + + PeerConnectionFactory.initializeAndroidGlobals(this, true, true, true); + } + } + private void initializeCircumvention() { - new AsyncTask() { + AsyncTask task = new AsyncTask() { @Override protected Void doInBackground(Void... params) { if (new SignalServiceNetworkAccess(ApplicationContext.this).isCensored(ApplicationContext.this)) { @@ -189,7 +220,10 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc } return null; } - }.execute(); + }; + + if (Build.VERSION.SDK_INT >= 11) task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + else task.execute(); } }