Merge pull request #1614 from mcginty/contact-list-security

move FLAG_SECURE to PassphraseRequiredMixin
This commit is contained in:
Moxie Marlinspike 2014-06-17 21:47:00 -07:00
commit 81365eff36
8 changed files with 53 additions and 69 deletions

View File

@ -203,7 +203,6 @@ public class ConversationActivity extends PassphraseRequiredSherlockFragmentActi
dynamicLanguage.onResume(this); dynamicLanguage.onResume(this);
initializeSecurity(); initializeSecurity();
initializeScreenshotSecurity();
initializeTitleBar(); initializeTitleBar();
initializeEnabledCheck(); initializeEnabledCheck();
initializeMmsEnabledCheck(); initializeMmsEnabledCheck();
@ -731,15 +730,6 @@ public class ConversationActivity extends PassphraseRequiredSherlockFragmentActi
calculateCharactersRemaining(); 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() { private void initializeMmsEnabledCheck() {
new AsyncTask<Void, Void, Boolean>() { new AsyncTask<Void, Void, Boolean>() {

View File

@ -86,7 +86,6 @@ public class ConversationListActivity extends PassphraseRequiredSherlockFragment
dynamicLanguage.onResume(this); dynamicLanguage.onResume(this);
initializeDefaultMessengerCheck(); initializeDefaultMessengerCheck();
initializeSecurity();
} }
@Override @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 { class DrawerToggle extends ActionBarDrawerToggle {
public DrawerToggle(Activity activity, DrawerLayout drawerLayout, public DrawerToggle(Activity activity, DrawerLayout drawerLayout,

View File

@ -1,13 +1,17 @@
package org.thoughtcrime.securesms; package org.thoughtcrime.securesms;
import android.app.Activity;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.ServiceConnection; import android.content.ServiceConnection;
import android.os.Build;
import android.os.IBinder; import android.os.IBinder;
import android.view.WindowManager;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.whispersystems.textsecure.crypto.MasterSecret; import org.whispersystems.textsecure.crypto.MasterSecret;
import org.thoughtcrime.securesms.service.KeyCachingService; import org.thoughtcrime.securesms.service.KeyCachingService;
@ -18,27 +22,38 @@ public class PassphraseRequiredMixin {
private BroadcastReceiver clearKeyReceiver; private BroadcastReceiver clearKeyReceiver;
private BroadcastReceiver newKeyReceiver; private BroadcastReceiver newKeyReceiver;
public void onCreate(Context context, PassphraseRequiredActivity activity) { public <T extends Activity & PassphraseRequiredActivity> void onCreate(T activity) {
initializeClearKeyReceiver(context, activity); initializeClearKeyReceiver(activity);
} }
public void onResume(Context context, PassphraseRequiredActivity activity) { public <T extends Activity & PassphraseRequiredActivity> void onResume(T activity) {
initializeNewKeyReceiver(context, activity); initializeScreenshotSecurity(activity);
initializeServiceConnection(context, activity); initializeNewKeyReceiver(activity);
KeyCachingService.registerPassphraseActivityStarted(context); initializeServiceConnection(activity);
KeyCachingService.registerPassphraseActivityStarted(activity);
} }
public void onPause(Context context, PassphraseRequiredActivity activity) { public <T extends Activity & PassphraseRequiredActivity> void onPause(T activity) {
removeNewKeyReceiver(context); removeNewKeyReceiver(activity);
removeServiceConnection(context); removeServiceConnection(activity);
KeyCachingService.registerPassphraseActivityStopped(context); KeyCachingService.registerPassphraseActivityStopped(activity);
} }
public void onDestroy(Context context, PassphraseRequiredActivity activity) { public <T extends Activity & PassphraseRequiredActivity> void onDestroy(T activity) {
removeClearKeyReceiver(context); removeClearKeyReceiver(activity);
} }
private void initializeClearKeyReceiver(Context context, final PassphraseRequiredActivity activity) { private <T extends Activity & PassphraseRequiredActivity> 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 <T extends Activity & PassphraseRequiredActivity> void initializeClearKeyReceiver(final T activity) {
this.clearKeyReceiver = new BroadcastReceiver() { this.clearKeyReceiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
@ -47,10 +62,11 @@ public class PassphraseRequiredMixin {
}; };
IntentFilter filter = new IntentFilter(KeyCachingService.CLEAR_KEY_EVENT); 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 <T extends Activity & PassphraseRequiredActivity> void initializeNewKeyReceiver(final T activity) {
this.newKeyReceiver = new BroadcastReceiver() { this.newKeyReceiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
@ -59,17 +75,17 @@ public class PassphraseRequiredMixin {
}; };
IntentFilter filter = new IntentFilter(KeyCachingService.NEW_KEY_EVENT); 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) { private <T extends Activity & PassphraseRequiredActivity> void initializeServiceConnection(T activity) {
Intent cachingIntent = new Intent(context, KeyCachingService.class); Intent cachingIntent = new Intent(activity, KeyCachingService.class);
context.startService(cachingIntent); activity.startService(cachingIntent);
this.serviceConnection = new KeyCachingServiceConnection(activity); this.serviceConnection = new KeyCachingServiceConnection(activity);
Intent bindIntent = new Intent(context, KeyCachingService.class); Intent bindIntent = new Intent(activity, KeyCachingService.class);
context.bindService(bindIntent, serviceConnection, Context.BIND_AUTO_CREATE); activity.bindService(bindIntent, serviceConnection, Context.BIND_AUTO_CREATE);
} }
private void removeClearKeyReceiver(Context context) { private void removeClearKeyReceiver(Context context) {

View File

@ -13,25 +13,25 @@ public class PassphraseRequiredSherlockActivity extends SherlockActivity impleme
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
delegate.onCreate(this, this); delegate.onCreate(this);
} }
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
delegate.onResume(this, this); delegate.onResume(this);
} }
@Override @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
delegate.onPause(this, this); delegate.onPause(this);
} }
@Override @Override
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); super.onDestroy();
delegate.onDestroy(this, this); delegate.onDestroy(this);
} }
@Override @Override

View File

@ -13,25 +13,25 @@ public class PassphraseRequiredSherlockFragmentActivity extends SherlockFragment
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
delegate.onCreate(this, this); delegate.onCreate(this);
} }
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
delegate.onResume(this, this); delegate.onResume(this);
} }
@Override @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
delegate.onPause(this, this); delegate.onPause(this);
} }
@Override @Override
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); super.onDestroy();
delegate.onDestroy(this, this); delegate.onDestroy(this);
} }
@Override @Override

View File

@ -13,25 +13,25 @@ public class PassphraseRequiredSherlockListActivity extends SherlockListActivity
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
delegate.onCreate(this, this); delegate.onCreate(this);
} }
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
delegate.onResume(this, this); delegate.onResume(this);
} }
@Override @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
delegate.onPause(this, this); delegate.onPause(this);
} }
@Override @Override
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); super.onDestroy();
delegate.onDestroy(this, this); delegate.onDestroy(this);
} }
@Override @Override

View File

@ -16,25 +16,25 @@ public abstract class PassphraseRequiredSherlockPreferenceActivity
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
delegate.onCreate(this, this); delegate.onCreate(this);
} }
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
delegate.onResume(this, this); delegate.onResume(this);
} }
@Override @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
delegate.onPause(this, this); delegate.onPause(this);
} }
@Override @Override
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); super.onDestroy();
delegate.onDestroy(this, this); delegate.onDestroy(this);
} }
@Override @Override

View File

@ -72,7 +72,6 @@ public class ShareActivity extends PassphraseRequiredSherlockFragmentActivity
dynamicTheme.onResume(this); dynamicTheme.onResume(this);
dynamicLanguage.onResume(this); dynamicLanguage.onResume(this);
getSupportActionBar().setTitle(R.string.ShareActivity_share_with); getSupportActionBar().setTitle(R.string.ShareActivity_share_with);
initializeSecurity();
} }
@Override @Override
@ -141,16 +140,6 @@ public class ShareActivity extends PassphraseRequiredSherlockFragmentActivity
this.fragment.setMasterSecret(masterSecret); 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) { private Intent getBaseShareIntent(final Class<?> target) {
final Intent intent = new Intent(this, target); final Intent intent = new Intent(this, target);
final Intent originalIntent = getIntent(); final Intent originalIntent = getIntent();