From 5ce6dc954ab78b5658bc41f42dafe5e29e4bb999 Mon Sep 17 00:00:00 2001 From: Jake McGinty Date: Mon, 16 Jun 2014 20:32:54 -0700 Subject: [PATCH] move FLAG_SECURE to PassphraseRequiredMixin Fixes #1402 // FREEBIE --- .../securesms/ConversationActivity.java | 10 ---- .../securesms/ConversationListActivity.java | 11 ---- .../securesms/PassphraseRequiredMixin.java | 58 ++++++++++++------- .../PassphraseRequiredSherlockActivity.java | 8 +-- ...hraseRequiredSherlockFragmentActivity.java | 8 +-- ...assphraseRequiredSherlockListActivity.java | 8 +-- ...aseRequiredSherlockPreferenceActivity.java | 8 +-- .../thoughtcrime/securesms/ShareActivity.java | 11 ---- 8 files changed, 53 insertions(+), 69 deletions(-) diff --git a/src/org/thoughtcrime/securesms/ConversationActivity.java b/src/org/thoughtcrime/securesms/ConversationActivity.java index 683728647d..6224e994fe 100644 --- a/src/org/thoughtcrime/securesms/ConversationActivity.java +++ b/src/org/thoughtcrime/securesms/ConversationActivity.java @@ -203,7 +203,6 @@ public class ConversationActivity extends PassphraseRequiredSherlockFragmentActi dynamicLanguage.onResume(this); initializeSecurity(); - initializeScreenshotSecurity(); initializeTitleBar(); initializeEnabledCheck(); initializeMmsEnabledCheck(); @@ -731,15 +730,6 @@ public class ConversationActivity extends PassphraseRequiredSherlockFragmentActi calculateCharactersRemaining(); } - private void initializeScreenshotSecurity() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { - if (TextSecurePreferences.isScreenSecurityEnabled(this)) { - getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE); - } else { - getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE); - } - } - } private void initializeMmsEnabledCheck() { new AsyncTask() { diff --git a/src/org/thoughtcrime/securesms/ConversationListActivity.java b/src/org/thoughtcrime/securesms/ConversationListActivity.java index a446582863..fdb97d74e8 100644 --- a/src/org/thoughtcrime/securesms/ConversationListActivity.java +++ b/src/org/thoughtcrime/securesms/ConversationListActivity.java @@ -86,7 +86,6 @@ public class ConversationListActivity extends PassphraseRequiredSherlockFragment dynamicLanguage.onResume(this); initializeDefaultMessengerCheck(); - initializeSecurity(); } @Override @@ -299,16 +298,6 @@ public class ConversationListActivity extends PassphraseRequiredSherlockFragment } } - private void initializeSecurity() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { - if (TextSecurePreferences.isScreenSecurityEnabled(this)) { - getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE); - } else { - getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE); - } - } - } - class DrawerToggle extends ActionBarDrawerToggle { public DrawerToggle(Activity activity, DrawerLayout drawerLayout, diff --git a/src/org/thoughtcrime/securesms/PassphraseRequiredMixin.java b/src/org/thoughtcrime/securesms/PassphraseRequiredMixin.java index 682f71e00f..ec8f70603d 100644 --- a/src/org/thoughtcrime/securesms/PassphraseRequiredMixin.java +++ b/src/org/thoughtcrime/securesms/PassphraseRequiredMixin.java @@ -1,13 +1,17 @@ package org.thoughtcrime.securesms; +import android.app.Activity; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.ServiceConnection; +import android.os.Build; import android.os.IBinder; +import android.view.WindowManager; +import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.whispersystems.textsecure.crypto.MasterSecret; import org.thoughtcrime.securesms.service.KeyCachingService; @@ -18,27 +22,38 @@ public class PassphraseRequiredMixin { private BroadcastReceiver clearKeyReceiver; private BroadcastReceiver newKeyReceiver; - public void onCreate(Context context, PassphraseRequiredActivity activity) { - initializeClearKeyReceiver(context, activity); + public void onCreate(T activity) { + initializeClearKeyReceiver(activity); } - public void onResume(Context context, PassphraseRequiredActivity activity) { - initializeNewKeyReceiver(context, activity); - initializeServiceConnection(context, activity); - KeyCachingService.registerPassphraseActivityStarted(context); + public void onResume(T activity) { + initializeScreenshotSecurity(activity); + initializeNewKeyReceiver(activity); + initializeServiceConnection(activity); + KeyCachingService.registerPassphraseActivityStarted(activity); } - public void onPause(Context context, PassphraseRequiredActivity activity) { - removeNewKeyReceiver(context); - removeServiceConnection(context); - KeyCachingService.registerPassphraseActivityStopped(context); + public void onPause(T activity) { + removeNewKeyReceiver(activity); + removeServiceConnection(activity); + KeyCachingService.registerPassphraseActivityStopped(activity); } - public void onDestroy(Context context, PassphraseRequiredActivity activity) { - removeClearKeyReceiver(context); + public void onDestroy(T activity) { + removeClearKeyReceiver(activity); } - private void initializeClearKeyReceiver(Context context, final PassphraseRequiredActivity activity) { + private void initializeScreenshotSecurity(T activity) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { + if (TextSecurePreferences.isScreenSecurityEnabled(activity)) { + activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE); + } else { + activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE); + } + } + } + + private void initializeClearKeyReceiver(final T activity) { this.clearKeyReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { @@ -47,10 +62,11 @@ public class PassphraseRequiredMixin { }; IntentFilter filter = new IntentFilter(KeyCachingService.CLEAR_KEY_EVENT); - context.registerReceiver(clearKeyReceiver, filter, KeyCachingService.KEY_PERMISSION, null); + + activity.registerReceiver(clearKeyReceiver, filter, KeyCachingService.KEY_PERMISSION, null); } - private void initializeNewKeyReceiver(Context context, final PassphraseRequiredActivity activity) { + private void initializeNewKeyReceiver(final T activity) { this.newKeyReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { @@ -59,17 +75,17 @@ public class PassphraseRequiredMixin { }; IntentFilter filter = new IntentFilter(KeyCachingService.NEW_KEY_EVENT); - context.registerReceiver(newKeyReceiver, filter, KeyCachingService.KEY_PERMISSION, null); + activity.registerReceiver(newKeyReceiver, filter, KeyCachingService.KEY_PERMISSION, null); } - private void initializeServiceConnection(Context context, PassphraseRequiredActivity activity) { - Intent cachingIntent = new Intent(context, KeyCachingService.class); - context.startService(cachingIntent); + private void initializeServiceConnection(T activity) { + Intent cachingIntent = new Intent(activity, KeyCachingService.class); + activity.startService(cachingIntent); this.serviceConnection = new KeyCachingServiceConnection(activity); - Intent bindIntent = new Intent(context, KeyCachingService.class); - context.bindService(bindIntent, serviceConnection, Context.BIND_AUTO_CREATE); + Intent bindIntent = new Intent(activity, KeyCachingService.class); + activity.bindService(bindIntent, serviceConnection, Context.BIND_AUTO_CREATE); } private void removeClearKeyReceiver(Context context) { diff --git a/src/org/thoughtcrime/securesms/PassphraseRequiredSherlockActivity.java b/src/org/thoughtcrime/securesms/PassphraseRequiredSherlockActivity.java index 209b61f130..0566c6343a 100644 --- a/src/org/thoughtcrime/securesms/PassphraseRequiredSherlockActivity.java +++ b/src/org/thoughtcrime/securesms/PassphraseRequiredSherlockActivity.java @@ -13,25 +13,25 @@ public class PassphraseRequiredSherlockActivity extends SherlockActivity impleme @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - delegate.onCreate(this, this); + delegate.onCreate(this); } @Override protected void onResume() { super.onResume(); - delegate.onResume(this, this); + delegate.onResume(this); } @Override protected void onPause() { super.onPause(); - delegate.onPause(this, this); + delegate.onPause(this); } @Override protected void onDestroy() { super.onDestroy(); - delegate.onDestroy(this, this); + delegate.onDestroy(this); } @Override diff --git a/src/org/thoughtcrime/securesms/PassphraseRequiredSherlockFragmentActivity.java b/src/org/thoughtcrime/securesms/PassphraseRequiredSherlockFragmentActivity.java index 910eba01da..257ce5943c 100644 --- a/src/org/thoughtcrime/securesms/PassphraseRequiredSherlockFragmentActivity.java +++ b/src/org/thoughtcrime/securesms/PassphraseRequiredSherlockFragmentActivity.java @@ -13,25 +13,25 @@ public class PassphraseRequiredSherlockFragmentActivity extends SherlockFragment @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - delegate.onCreate(this, this); + delegate.onCreate(this); } @Override protected void onResume() { super.onResume(); - delegate.onResume(this, this); + delegate.onResume(this); } @Override protected void onPause() { super.onPause(); - delegate.onPause(this, this); + delegate.onPause(this); } @Override protected void onDestroy() { super.onDestroy(); - delegate.onDestroy(this, this); + delegate.onDestroy(this); } @Override diff --git a/src/org/thoughtcrime/securesms/PassphraseRequiredSherlockListActivity.java b/src/org/thoughtcrime/securesms/PassphraseRequiredSherlockListActivity.java index b4bc7fda5e..1f4834612a 100644 --- a/src/org/thoughtcrime/securesms/PassphraseRequiredSherlockListActivity.java +++ b/src/org/thoughtcrime/securesms/PassphraseRequiredSherlockListActivity.java @@ -13,25 +13,25 @@ public class PassphraseRequiredSherlockListActivity extends SherlockListActivity @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - delegate.onCreate(this, this); + delegate.onCreate(this); } @Override protected void onResume() { super.onResume(); - delegate.onResume(this, this); + delegate.onResume(this); } @Override protected void onPause() { super.onPause(); - delegate.onPause(this, this); + delegate.onPause(this); } @Override protected void onDestroy() { super.onDestroy(); - delegate.onDestroy(this, this); + delegate.onDestroy(this); } @Override diff --git a/src/org/thoughtcrime/securesms/PassphraseRequiredSherlockPreferenceActivity.java b/src/org/thoughtcrime/securesms/PassphraseRequiredSherlockPreferenceActivity.java index 02e2b2d60f..6f44c743cc 100644 --- a/src/org/thoughtcrime/securesms/PassphraseRequiredSherlockPreferenceActivity.java +++ b/src/org/thoughtcrime/securesms/PassphraseRequiredSherlockPreferenceActivity.java @@ -16,25 +16,25 @@ public abstract class PassphraseRequiredSherlockPreferenceActivity @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - delegate.onCreate(this, this); + delegate.onCreate(this); } @Override protected void onResume() { super.onResume(); - delegate.onResume(this, this); + delegate.onResume(this); } @Override protected void onPause() { super.onPause(); - delegate.onPause(this, this); + delegate.onPause(this); } @Override protected void onDestroy() { super.onDestroy(); - delegate.onDestroy(this, this); + delegate.onDestroy(this); } @Override diff --git a/src/org/thoughtcrime/securesms/ShareActivity.java b/src/org/thoughtcrime/securesms/ShareActivity.java index 875e934e6b..5a5e2abcf5 100644 --- a/src/org/thoughtcrime/securesms/ShareActivity.java +++ b/src/org/thoughtcrime/securesms/ShareActivity.java @@ -72,7 +72,6 @@ public class ShareActivity extends PassphraseRequiredSherlockFragmentActivity dynamicTheme.onResume(this); dynamicLanguage.onResume(this); getSupportActionBar().setTitle(R.string.ShareActivity_share_with); - initializeSecurity(); } @Override @@ -141,16 +140,6 @@ public class ShareActivity extends PassphraseRequiredSherlockFragmentActivity this.fragment.setMasterSecret(masterSecret); } - private void initializeSecurity() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { - if (TextSecurePreferences.isScreenSecurityEnabled(this)) { - getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE); - } else { - getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE); - } - } - } - private Intent getBaseShareIntent(final Class target) { final Intent intent = new Intent(this, target); final Intent originalIntent = getIntent();