From ba849bce2c90287e820a3008e9dc9a1b14de19fc Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Tue, 3 Oct 2017 18:57:23 -0700 Subject: [PATCH] Add support for incognito keyboard preference Closes #6985 // FREEBIE --- res/values/strings.xml | 38 +++++++++++-------- res/xml/preferences_app_protection.xml | 8 +++- .../securesms/DatabaseUpgradeActivity.java | 7 ++++ .../securesms/components/ComposeText.java | 9 +++++ .../securesms/util/TextSecurePreferences.java | 11 +++++- 5 files changed, 56 insertions(+), 17 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index e7c6910ea2..16bc3a1056 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -70,6 +70,12 @@ Blocked contacts + + Today + Yesterday + This week + This month + Incoming call @@ -416,6 +422,10 @@ Error connecting to MMS provider Error reading wireless provider MMS settings + + Media + Documents + Signal call in progress Missed call from %s @@ -591,6 +601,15 @@ Registration error Signal registration has encountered a problem. + + Default ringtone + None + Ringtones + Default notification sound + Default alarm sound + Add ringtone + Unable to add custom ringtone + Image Audio @@ -1269,6 +1288,10 @@ Submit debug log \'WiFi Calling\' compatibility mode Enable if your device uses SMS/MMS delivery over WiFi (only enable when \'WiFi Calling\' is enabled on your device) + Incognito keyboard + Use keyboard without suggestions or auto-correct + Read receipts + If read receipts are disabled, you won\'t be able to see read receipts from others. Blocked contacts Safety numbers approval Require approval of new safety numbers when they change @@ -1459,22 +1482,7 @@ Transport icon Message read - Read receipts - If read receipts are disabled, you won\'t be able to see read receipts from others. - Default ringtone - None - Ringtones - Default notification sound - Default alarm sound - Add ringtone - Unable to add custom ringtone - Today - Yesterday - This week - This month - Media - Documents No documents found Read receipts are here Optionally see and share when messages have been read diff --git a/res/xml/preferences_app_protection.xml b/res/xml/preferences_app_protection.xml index a0fa003aed..46c99f7912 100644 --- a/res/xml/preferences_app_protection.xml +++ b/res/xml/preferences_app_protection.xml @@ -25,10 +25,16 @@ android:dependency="pref_timeout_passphrase"/> + + diff --git a/src/org/thoughtcrime/securesms/DatabaseUpgradeActivity.java b/src/org/thoughtcrime/securesms/DatabaseUpgradeActivity.java index 0edca80ecb..eea9536db8 100644 --- a/src/org/thoughtcrime/securesms/DatabaseUpgradeActivity.java +++ b/src/org/thoughtcrime/securesms/DatabaseUpgradeActivity.java @@ -44,6 +44,7 @@ import org.thoughtcrime.securesms.jobs.DirectoryRefreshJob; import org.thoughtcrime.securesms.jobs.PushDecryptJob; import org.thoughtcrime.securesms.jobs.RefreshAttributesJob; import org.thoughtcrime.securesms.notifications.MessageNotifier; +import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.thoughtcrime.securesms.util.Util; import org.thoughtcrime.securesms.util.VersionTracker; @@ -70,6 +71,7 @@ public class DatabaseUpgradeActivity extends BaseActivity { public static final int REDPHONE_SUPPORT_VERSION = 157; public static final int NO_MORE_CANONICAL_DB_VERSION = 276; public static final int PROFILES = 289; + public static final int SCREENSHOTS = 300; private static final SortedSet UPGRADE_VERSIONS = new TreeSet() {{ add(NO_MORE_KEY_EXCHANGE_PREFIX_VERSION); @@ -84,6 +86,7 @@ public class DatabaseUpgradeActivity extends BaseActivity { add(MEDIA_DOWNLOAD_CONTROLS_VERSION); add(REDPHONE_SUPPORT_VERSION); add(NO_MORE_CANONICAL_DB_VERSION); + add(SCREENSHOTS); }}; private MasterSecret masterSecret; @@ -240,6 +243,10 @@ public class DatabaseUpgradeActivity extends BaseActivity { .add(new DirectoryRefreshJob(getApplicationContext())); } + if (params[0] < SCREENSHOTS) { + TextSecurePreferences.setScreenSecurityEnabled(getApplicationContext(), true); + } + return null; } diff --git a/src/org/thoughtcrime/securesms/components/ComposeText.java b/src/org/thoughtcrime/securesms/components/ComposeText.java index 3b5ffb05d6..0b027f9128 100644 --- a/src/org/thoughtcrime/securesms/components/ComposeText.java +++ b/src/org/thoughtcrime/securesms/components/ComposeText.java @@ -37,14 +37,17 @@ public class ComposeText extends EmojiEditText { public ComposeText(Context context) { super(context); + initialize(); } public ComposeText(Context context, AttributeSet attrs) { super(context, attrs); + initialize(); } public ComposeText(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); + initialize(); } public String getTextTrimmed(){ @@ -107,6 +110,7 @@ public class ComposeText extends EmojiEditText { public void setTransport(TransportOption transport) { final boolean useSystemEmoji = TextSecurePreferences.isSystemEmojiPreferred(getContext()); + final boolean isIncognito = TextSecurePreferences.isIncognitoKeyboardEnabled(getContext()); int imeOptions = (getImeOptions() & ~EditorInfo.IME_MASK_ACTION) | EditorInfo.IME_ACTION_SEND; int inputType = getInputType(); @@ -146,6 +150,11 @@ public class ComposeText extends EmojiEditText { this.mediaListener = mediaListener; } + private void initialize() { + if (TextSecurePreferences.isIncognitoKeyboardEnabled(getContext())) { + setImeOptions(getImeOptions() | 16777216); + } + } @RequiresApi(api = Build.VERSION_CODES.HONEYCOMB_MR2) private static class CommitContentListener implements InputConnectionCompat.OnCommitContentListener { diff --git a/src/org/thoughtcrime/securesms/util/TextSecurePreferences.java b/src/org/thoughtcrime/securesms/util/TextSecurePreferences.java index 50cb5a6db7..1046616f79 100644 --- a/src/org/thoughtcrime/securesms/util/TextSecurePreferences.java +++ b/src/org/thoughtcrime/securesms/util/TextSecurePreferences.java @@ -113,6 +113,11 @@ public class TextSecurePreferences { private static final String PROFILE_KEY_PREF = "pref_profile_key"; private static final String PROFILE_NAME_PREF = "pref_profile_name"; public static final String READ_RECEIPTS_PREF = "pref_read_receipts"; + public static final String INCOGNITO_KEYBORAD_PREF = "pref_incognito_keyboard"; + + public static boolean isIncognitoKeyboardEnabled(Context context) { + return getBooleanPreference(context, INCOGNITO_KEYBORAD_PREF, false); + } public static boolean isReadReceiptsEnabled(Context context) { return getBooleanPreference(context, READ_RECEIPTS_PREF, false); @@ -471,8 +476,12 @@ public class TextSecurePreferences { setStringPreference(context, IDENTITY_PREF, identityUri); } + public static void setScreenSecurityEnabled(Context context, boolean value) { + setBooleanPreference(context, SCREEN_SECURITY_PREF, value); + } + public static boolean isScreenSecurityEnabled(Context context) { - return getBooleanPreference(context, SCREEN_SECURITY_PREF, true); + return getBooleanPreference(context, SCREEN_SECURITY_PREF, false); } public static boolean isLegacyUseLocalApnsEnabled(Context context) {