Refactor MasterSecret initialization, access, and timeout paths.

1) Consolidate all of the KeyCachingService interaction into a single
   mixin. Activities extend delegates which call through to the mixin.

2) Switch Activity increment/decrement triggers from onStop to onPause
   in order to account for some screen locks that don't stop activities.
This commit is contained in:
Moxie Marlinspike
2013-02-10 17:30:51 -08:00
parent 90280a62ae
commit c2dcf7ae74
15 changed files with 412 additions and 250 deletions

View File

@@ -20,6 +20,7 @@ import android.app.AlarmManager;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Binder;
@@ -44,8 +45,7 @@ import org.thoughtcrime.securesms.notifications.MessageNotifier;
public class KeyCachingService extends Service {
public static final int NOTIFICATION_ID = 1337;
public static final int SERVICE_RUNNING_ID = 4141;
public static final int SERVICE_RUNNING_ID = 4141;
public static final String KEY_PERMISSION = "org.thoughtcrime.securesms.ACCESS_SECRETS";
public static final String NEW_KEY_EVENT = "org.thoughtcrime.securesms.service.action.NEW_KEY_EVENT";
@@ -215,4 +215,16 @@ public class KeyCachingService extends Service {
return KeyCachingService.this;
}
}
public static void registerPassphraseActivityStarted(Context activity) {
Intent intent = new Intent(activity, KeyCachingService.class);
intent.setAction(KeyCachingService.ACTIVITY_START_EVENT);
activity.startService(intent);
}
public static void registerPassphraseActivityStopped(Context activity) {
Intent intent = new Intent(activity, KeyCachingService.class);
intent.setAction(KeyCachingService.ACTIVITY_STOP_EVENT);
activity.startService(intent);
}
}