-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support "quick response" when SMSSecure is unlocked.
Fixes signalapp/Signal-Android#299 Closes signalapp/Signal-Android#3456 // FREEBIE
- Loading branch information
1 parent
fe11c43
commit 0ead7b1
Showing
3 changed files
with
69 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/org/smssecure/smssecure/service/MasterSecretIntentService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.smssecure.smssecure.service; | ||
|
||
import android.app.IntentService; | ||
import android.content.Intent; | ||
import android.support.annotation.Nullable; | ||
|
||
import org.smssecure.smssecure.crypto.MasterSecret; | ||
|
||
public abstract class MasterSecretIntentService extends IntentService { | ||
|
||
public MasterSecretIntentService(String name) { | ||
super(name); | ||
} | ||
|
||
@Override | ||
protected final void onHandleIntent(Intent intent) { | ||
onHandleIntent(intent, KeyCachingService.getMasterSecret(this)); | ||
} | ||
|
||
protected abstract void onHandleIntent(Intent intent, @Nullable MasterSecret masterSecret); | ||
} |
59 changes: 45 additions & 14 deletions
59
src/org/smssecure/smssecure/service/QuickResponseService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,62 @@ | ||
package org.smssecure.smssecure.service; | ||
|
||
import android.app.Service; | ||
import android.content.Intent; | ||
import android.os.IBinder; | ||
import android.support.annotation.Nullable; | ||
import android.telephony.TelephonyManager; | ||
import android.text.TextUtils; | ||
import android.util.Log; | ||
import android.widget.Toast; | ||
|
||
import org.smssecure.smssecure.R; | ||
import org.smssecure.smssecure.crypto.MasterSecret; | ||
import org.smssecure.smssecure.database.ThreadDatabase; | ||
import org.smssecure.smssecure.mms.OutgoingMediaMessage; | ||
import org.smssecure.smssecure.mms.SlideDeck; | ||
import org.smssecure.smssecure.recipients.RecipientFactory; | ||
import org.smssecure.smssecure.recipients.Recipients; | ||
import org.smssecure.smssecure.sms.MessageSender; | ||
import org.smssecure.smssecure.sms.OutgoingTextMessage; | ||
import org.smssecure.smssecure.util.Rfc5724Uri; | ||
|
||
public class QuickResponseService extends Service { | ||
import java.net.URISyntaxException; | ||
|
||
public int onStartCommand(Intent intent, int flags, int startId) { | ||
if (!TelephonyManager.ACTION_RESPOND_VIA_MESSAGE.equals(intent.getAction())) { | ||
Log.w("QuickResponseService", "Received unknown intent: " + intent.getAction()); | ||
return START_NOT_STICKY; | ||
} | ||
public class QuickResponseService extends MasterSecretIntentService { | ||
|
||
Toast.makeText(this, | ||
getString(R.string.QuickResponseService_sorry_quick_response_is_not_yet_supported_by_textsecure), | ||
Toast.LENGTH_LONG).show(); | ||
private static final String TAG = QuickResponseService.class.getSimpleName(); | ||
|
||
return START_NOT_STICKY; | ||
public QuickResponseService() { | ||
super("QuickResponseService"); | ||
} | ||
|
||
@Override | ||
public IBinder onBind(Intent intent) { | ||
return null; | ||
protected void onHandleIntent(Intent intent, @Nullable MasterSecret masterSecret) { | ||
if (!TelephonyManager.ACTION_RESPOND_VIA_MESSAGE.equals(intent.getAction())) { | ||
Log.w(TAG, "Received unknown intent: " + intent.getAction()); | ||
return; | ||
} | ||
|
||
if (masterSecret == null) { | ||
Log.w(TAG, "Got quick response request when locked..."); | ||
Toast.makeText(this, R.string.QuickResponseService_quick_response_unavailable_when_SMSSecure_is_locked, Toast.LENGTH_LONG).show(); | ||
return; | ||
} | ||
|
||
try { | ||
Rfc5724Uri uri = new Rfc5724Uri(intent.getDataString()); | ||
String content = intent.getStringExtra(Intent.EXTRA_TEXT); | ||
Recipients recipients = RecipientFactory.getRecipientsFromString(this, uri.getPath(), false); | ||
|
||
if (!TextUtils.isEmpty(content)) { | ||
if (recipients.isSingleRecipient()) { | ||
MessageSender.send(this, masterSecret, new OutgoingTextMessage(recipients, content), -1, false); | ||
} else { | ||
MessageSender.send(this, masterSecret, new OutgoingMediaMessage(this, recipients, new SlideDeck(), content, | ||
ThreadDatabase.DistributionTypes.DEFAULT), -1, false); | ||
} | ||
} | ||
} catch (URISyntaxException e) { | ||
Toast.makeText(this, R.string.QuickResponseService_problem_sending_message, Toast.LENGTH_LONG).show(); | ||
Log.w(TAG, e); | ||
} | ||
} | ||
} |