Skip to content

Commit

Permalink
"Silence Recording Alerts" switch now compares file contents
Browse files Browse the repository at this point in the history
  • Loading branch information
jacopotediosi committed Jan 9, 2023
1 parent 74b649c commit 71d88b7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Expand Up @@ -69,6 +69,7 @@ dependencies {
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.android.volley:volley:1.2.1'
implementation 'com.google.protobuf:protobuf-javalite:3.8.0'
implementation 'commons-io:commons-io:2.11.0'
implementation "com.github.topjohnwu.libsu:core:${libsuVersion}"
implementation "com.github.topjohnwu.libsu:service:${libsuVersion}"
implementation "com.github.topjohnwu.libsu:nio:${libsuVersion}"
Expand Down
Expand Up @@ -27,7 +27,10 @@
import com.topjohnwu.superuser.nio.ExtendedFile;
import com.topjohnwu.superuser.nio.FileSystemManager;

import org.apache.commons.io.IOUtils;

import java.io.IOException;
import java.io.InputStream;

public class SuggestedModsFragment extends Fragment {
private View mView;
Expand Down Expand Up @@ -163,19 +166,31 @@ public void refreshSwitchesStatus() {
mForceEnableCallRecordingSwitch.setOnCheckedChangeListener(mForceEnableCallRecordingSwitchOnCheckedChangeListener);

// mSilenceCallRecordingAlertsSwitch
long startingVoiceSize = -1;
long endingVoiceSize = -1;
if (fileSystemManager!=null) {
startingVoiceSize = fileSystemManager.getFile(DIALER_CALLRECORDINGPROMPT, CALLRECORDINGPROMPT_STARTING_VOICE_US).length();
endingVoiceSize = fileSystemManager.getFile(DIALER_CALLRECORDINGPROMPT, CALLRECORDINGPROMPT_ENDING_VOICE_US).length();
if (fileSystemManager != null) {
try {
InputStream silentVoiceInputStream;

InputStream startingVoiceInputStream = fileSystemManager.getFile(DIALER_CALLRECORDINGPROMPT, CALLRECORDINGPROMPT_STARTING_VOICE_US).newInputStream();
silentVoiceInputStream = getResources().openRawResource(R.raw.silent_wav);
boolean isStartingVoiceSilenced = IOUtils.contentEquals(silentVoiceInputStream, startingVoiceInputStream);
startingVoiceInputStream.close();
silentVoiceInputStream.close();

InputStream endingVoiceInputStream = fileSystemManager.getFile(DIALER_CALLRECORDINGPROMPT, CALLRECORDINGPROMPT_ENDING_VOICE_US).newInputStream();
silentVoiceInputStream = getResources().openRawResource(R.raw.silent_wav);
boolean isEndingVoiceSilenced = IOUtils.contentEquals(silentVoiceInputStream, endingVoiceInputStream);
endingVoiceInputStream.close();
silentVoiceInputStream.close();

mSilenceCallRecordingAlertsSwitch.setOnCheckedChangeListener(null);
mSilenceCallRecordingAlertsSwitch.setChecked(
mDBFlagsSingleton.areAllStringFlagsEmpty(SILENCE_CALL_RECORDING_ALERTS_FLAGS) && isStartingVoiceSilenced && isEndingVoiceSilenced
);
mSilenceCallRecordingAlertsSwitch.setOnCheckedChangeListener(mSilenceCallRecordingAlertsSwitchOnCheckedChangeListener);
} catch (IOException e) {
e.printStackTrace();
}
}
mSilenceCallRecordingAlertsSwitch.setOnCheckedChangeListener(null);
mSilenceCallRecordingAlertsSwitch.setChecked(
mDBFlagsSingleton.areAllStringFlagsEmpty(SILENCE_CALL_RECORDING_ALERTS_FLAGS) &&
startingVoiceSize > 0 && startingVoiceSize <= 100 &&
endingVoiceSize > 0 && endingVoiceSize <= 100
);
mSilenceCallRecordingAlertsSwitch.setOnCheckedChangeListener(mSilenceCallRecordingAlertsSwitchOnCheckedChangeListener);

// mForceEnableCallScreenSwitch
mForceEnableCallScreenSwitch.setOnCheckedChangeListener(null);
Expand Down

0 comments on commit 71d88b7

Please sign in to comment.