Skip to content

Commit

Permalink
App screen lock #42
Browse files Browse the repository at this point in the history
  • Loading branch information
Boehrsi committed Oct 1, 2018
1 parent e16df36 commit 79b98a4
Show file tree
Hide file tree
Showing 8 changed files with 249 additions and 266 deletions.
7 changes: 4 additions & 3 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1063,15 +1063,15 @@
<string name="preferences__pressing_the_enter_key_will_send_text_messages">Pressing the Enter key will send text messages</string>
<string name="preferences__choose_identity">Choose identity</string>
<string name="preferences__choose_your_contact_entry_from_the_contacts_list">Choose your contact entry from the contacts list.</string>
<string name="preferences__change_passphrase">Change passphrase</string>
<string name="preferences__change_your_passphrase">Change your passphrase</string>
<string name="preferences__change_passphrase">Change secret</string>
<string name="preferences__change_your_passphrase">Change your pin / pattern / fingerprint via system settings</string>
<string name="preferences__enable_passphrase">Enable passphrase screen lock</string>
<string name="preferences__lock_signal_and_message_notifications_with_a_passphrase">Lock screen and notifications with a passphrase</string>
<string name="preferences__screen_security">Screen security</string>
<string name="preferences__screen_security_restart_warning">To apply the screen security setting please restart the app</string>
<string name="preferences__disable_screen_security_to_allow_screen_shots">Block screenshots in the recents list and inside the app</string>
<string name="preferences__auto_lock_signal_after_a_specified_time_interval_of_inactivity">Auto-lock Delta Chat after a specified time interval of inactivity</string>
<string name="preferences__inactivity_timeout_passphrase">Inactivity timeout passphrase</string>
<string name="preferences__inactivity_timeout_passphrase">Inactivity timeout lock</string>
<string name="preferences__inactivity_timeout_interval">Inactivity timeout interval</string>
<string name="preferences__notifications">Notifications</string>
<string name="preferences__led_color">LED color</string>
Expand Down Expand Up @@ -1473,5 +1473,6 @@
<string name="contact_selection_list__type_email_above">Type email address above</string>
<string name="text_secure_normal__menu_new_chat">New chat</string>
<string name="help_url">https://delta.chat/en/help</string>
<string name="security_authentication_failed">Authentication failed.</string>

</resources>
71 changes: 32 additions & 39 deletions res/xml/preferences_app_protection.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,55 @@
<PreferenceCategory android:title="@string/preferences_app_protection__app_access">

<org.thoughtcrime.securesms.components.SwitchPreferenceCompat
android:key="pref_android_screen_lock"
android:defaultValue="false"
android:title="@string/preferences_app_protection__screen_lock"
android:summary="@string/preferences_app_protection__lock_signal_access_with_android_screen_lock_or_fingerprint"/>

<Preference android:title="@string/preferences_app_protection__screen_lock_inactivity_timeout"
android:key="pref_android_screen_lock_timeout"
android:dependency="pref_android_screen_lock"/>

<org.thoughtcrime.securesms.components.SwitchPreferenceCompat
android:key="pref_enable_passphrase_temporary"
android:defaultValue="true"
android:title="@string/preferences__enable_passphrase"
android:summary="@string/preferences__lock_signal_and_message_notifications_with_a_passphrase"/>
android:defaultValue="false"
android:key="pref_android_screen_lock"
android:summary="@string/preferences_app_protection__lock_signal_access_with_android_screen_lock_or_fingerprint"
android:title="@string/preferences_app_protection__screen_lock" />

<Preference android:key="pref_change_passphrase"
android:title="@string/preferences__change_passphrase"
android:summary="@string/preferences__change_your_passphrase"
android:dependency="pref_enable_passphrase_temporary"/>
<Preference
android:key="pref_change_passphrase"
android:summary="@string/preferences__change_your_passphrase"
android:title="@string/preferences__change_passphrase" />

<org.thoughtcrime.securesms.components.SwitchPreferenceCompat
android:defaultValue="false"
android:key="pref_timeout_passphrase"
android:title="@string/preferences__inactivity_timeout_passphrase"
android:summary="@string/preferences__auto_lock_signal_after_a_specified_time_interval_of_inactivity"
android:dependency="pref_enable_passphrase_temporary"/>
android:defaultValue="false"
android:key="pref_timeout_passphrase"
android:summary="@string/preferences__auto_lock_signal_after_a_specified_time_interval_of_inactivity"
android:title="@string/preferences__inactivity_timeout_passphrase" />

<Preference android:title="@string/preferences__inactivity_timeout_interval"
android:key="pref_timeout_interval"
android:dependency="pref_timeout_passphrase"/>
<Preference
android:dependency="pref_timeout_passphrase"
android:key="pref_timeout_interval"
android:title="@string/preferences__inactivity_timeout_interval" />

<org.thoughtcrime.securesms.components.SwitchPreferenceCompat
android:defaultValue="false"
android:key="pref_screen_security"
android:title="@string/preferences__screen_security"
android:summary="@string/preferences__disable_screen_security_to_allow_screen_shots" />
android:defaultValue="false"
android:key="pref_screen_security"
android:summary="@string/preferences__disable_screen_security_to_allow_screen_shots"
android:title="@string/preferences__screen_security" />

<org.thoughtcrime.securesms.components.SwitchPreferenceCompat
android:defaultValue="false"
android:key="pref_incognito_keyboard"
android:title="@string/preferences__incognito_keyboard"
android:summary="@string/preferences__request_keyboard_to_disable_personalized_learning"/>
android:summary="@string/preferences__request_keyboard_to_disable_personalized_learning"
android:title="@string/preferences__incognito_keyboard" />

</PreferenceCategory>

<PreferenceCategory android:layout="@layout/preference_divider"/>
<PreferenceCategory android:layout="@layout/preference_divider" />

<PreferenceCategory android:title="@string/preferences_app_protection__communication">

<org.thoughtcrime.securesms.components.SwitchPreferenceCompat
android:defaultValue="false"
android:key="pref_read_receipts"
android:title="@string/preferences__read_receipts"
android:summary="@string/preferences__if_read_receipts_are_disabled_you_wont_be_able_to_see_read_receipts"/>
android:defaultValue="false"
android:key="pref_read_receipts"
android:summary="@string/preferences__if_read_receipts_are_disabled_you_wont_be_able_to_see_read_receipts"
android:title="@string/preferences__read_receipts" />

<Preference
android:key="preference_category_blocked"
android:title="@string/preferences_app_protection__blocked_contacts" />

<Preference android:key="preference_category_blocked"
android:title="@string/preferences_app_protection__blocked_contacts" />
</PreferenceCategory>

</PreferenceScreen>
8 changes: 2 additions & 6 deletions src/org/thoughtcrime/securesms/ApplicationContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,15 @@
*/
package org.thoughtcrime.securesms;

import android.annotation.SuppressLint;
import android.arch.lifecycle.DefaultLifecycleObserver;
import android.arch.lifecycle.LifecycleOwner;
import android.arch.lifecycle.ProcessLifecycleOwner;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.multidex.MultiDexApplication;
import android.util.Log;

import com.google.android.gms.security.ProviderInstaller;

import org.thoughtcrime.securesms.connect.ApplicationDcContext;
import org.thoughtcrime.securesms.crypto.PRNGFixes;
import org.thoughtcrime.securesms.dependencies.AxolotlStorageModule;
Expand All @@ -45,6 +41,7 @@
import org.thoughtcrime.securesms.jobs.requirements.SqlCipherMigrationRequirementProvider;
import org.thoughtcrime.securesms.push.SignalServiceNetworkAccess;
import org.thoughtcrime.securesms.service.ExpiringMessageManager;
import org.thoughtcrime.securesms.util.ScreenLockUtil;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.webrtc.PeerConnectionFactory;
import org.webrtc.PeerConnectionFactory.InitializationOptions;
Expand All @@ -55,7 +52,6 @@

import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import dagger.ObjectGraph;

Expand Down Expand Up @@ -105,14 +101,14 @@ public void onCreate() {
public void onStart(@NonNull LifecycleOwner owner) {
isAppVisible = true;
Log.i(TAG, "App is now visible.");

executePendingContactSync();
}

@Override
public void onStop(@NonNull LifecycleOwner owner) {
isAppVisible = false;
Log.i(TAG, "App is no longer visible.");
ScreenLockUtil.shouldLockApp = true;
}

@Override
Expand Down
54 changes: 52 additions & 2 deletions src/org/thoughtcrime/securesms/BaseActionBarActivity.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.thoughtcrime.securesms;

import android.annotation.TargetApi;
import android.app.ActivityOptions;
import android.content.Intent;
import android.os.Build;
import android.os.Build.VERSION_CODES;
Expand All @@ -15,16 +14,23 @@
import android.view.View;
import android.view.ViewConfiguration;
import android.view.WindowManager;
import android.view.animation.AnimationUtils;
import android.widget.Toast;

import org.thoughtcrime.securesms.util.ScreenLockUtil;
import org.thoughtcrime.securesms.util.TextSecurePreferences;

import java.lang.reflect.Field;
import java.util.Timer;

import static org.thoughtcrime.securesms.util.ScreenLockUtil.shouldLockApp;


public abstract class BaseActionBarActivity extends AppCompatActivity {

private static final String TAG = BaseActionBarActivity.class.getSimpleName();

private Timer timer;

@Override
protected void onCreate(Bundle savedInstanceState) {
if (BaseActivity.isMenuWorkaroundRequired()) {
Expand All @@ -33,10 +39,54 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}

@Override
protected void onStart() {
super.onStart();
if (ScreenLockUtil.isScreenLockEnabled(this) && shouldLockApp) {
ScreenLockUtil.applyScreenLock(this);
}
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == ScreenLockUtil.REQUEST_CODE_CONFIRM_CREDENTIALS) {
if (resultCode == RESULT_OK) {
shouldLockApp = false;
} else {
Toast.makeText(this, R.string.security_authentication_failed, Toast.LENGTH_SHORT).show();
}
}
}

@Override
protected void onResume() {
super.onResume();
initializeScreenshotSecurity();
initializeScreenLock();
}

private void initializeScreenLock() {
if (ScreenLockUtil.isScreenLockEnabled(this)) {
timer = ScreenLockUtil.scheduleScreenLockTimer(timer, this);
}
}

@Override
protected void onPause() {
super.onPause();
tearDownScreenLock();
}

private void tearDownScreenLock() {
if (ScreenLockUtil.isScreenLockEnabled(this)) {
ScreenLockUtil.cancelScreenLockTimer(timer);
}
}

@Override
public void onUserInteraction() {
super.onUserInteraction();
initializeScreenLock();
}

@Override
Expand Down
Loading

0 comments on commit 79b98a4

Please sign in to comment.