|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
/**
|
|
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2011 Whisper Systems
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
@ -16,6 +16,7 @@
|
|
|
|
|
*/
|
|
|
|
|
package org.thoughtcrime.securesms.service;
|
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
|
import android.annotation.TargetApi;
|
|
|
|
|
import android.app.AlarmManager;
|
|
|
|
|
import android.app.Notification;
|
|
|
|
@ -44,6 +45,7 @@ import org.thoughtcrime.securesms.crypto.MasterSecretUtil;
|
|
|
|
|
import org.thoughtcrime.securesms.jobs.MasterSecretDecryptJob;
|
|
|
|
|
import org.thoughtcrime.securesms.notifications.MessageNotifier;
|
|
|
|
|
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
|
|
|
|
import org.thoughtcrime.securesms.util.ServiceUtil;
|
|
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
|
|
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
@ -95,6 +97,7 @@ public class KeyCachingService extends Service {
|
|
|
|
|
return masterSecret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressLint("StaticFieldLeak")
|
|
|
|
|
public void setMasterSecret(final MasterSecret masterSecret) {
|
|
|
|
|
synchronized (KeyCachingService.class) {
|
|
|
|
|
KeyCachingService.masterSecret = masterSecret;
|
|
|
|
@ -176,7 +179,7 @@ public class KeyCachingService extends Service {
|
|
|
|
|
private void handleActivityStarted() {
|
|
|
|
|
Log.w("KeyCachingService", "Incrementing activity count...");
|
|
|
|
|
|
|
|
|
|
AlarmManager alarmManager = (AlarmManager)this.getSystemService(ALARM_SERVICE);
|
|
|
|
|
AlarmManager alarmManager = ServiceUtil.getAlarmManager(this);
|
|
|
|
|
alarmManager.cancel(pending);
|
|
|
|
|
activitiesRunning++;
|
|
|
|
|
}
|
|
|
|
@ -188,6 +191,7 @@ public class KeyCachingService extends Service {
|
|
|
|
|
startTimeoutIfAppropriate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressLint("StaticFieldLeak")
|
|
|
|
|
private void handleClearKey() {
|
|
|
|
|
Log.w("KeyCachingService", "handleClearKey()");
|
|
|
|
|
KeyCachingService.masterSecret = null;
|
|
|
|
@ -226,7 +230,7 @@ public class KeyCachingService extends Service {
|
|
|
|
|
|
|
|
|
|
Log.w("KeyCachingService", "Starting timeout: " + timeoutMillis);
|
|
|
|
|
|
|
|
|
|
AlarmManager alarmManager = (AlarmManager)this.getSystemService(ALARM_SERVICE);
|
|
|
|
|
AlarmManager alarmManager = ServiceUtil.getAlarmManager(this);
|
|
|
|
|
alarmManager.cancel(pending);
|
|
|
|
|
alarmManager.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + timeoutMillis, pending);
|
|
|
|
|
}
|
|
|
|
@ -304,15 +308,13 @@ public class KeyCachingService extends Service {
|
|
|
|
|
private PendingIntent buildLockIntent() {
|
|
|
|
|
Intent intent = new Intent(this, KeyCachingService.class);
|
|
|
|
|
intent.setAction(PASSPHRASE_EXPIRED_EVENT);
|
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(), 0, intent, 0);
|
|
|
|
|
return pendingIntent;
|
|
|
|
|
return PendingIntent.getService(getApplicationContext(), 0, intent, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private PendingIntent buildLaunchIntent() {
|
|
|
|
|
Intent intent = new Intent(this, ConversationListActivity.class);
|
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
|
|
|
PendingIntent launchIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);
|
|
|
|
|
return launchIntent;
|
|
|
|
|
return PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|