From baec8d229d5a4749ee21b5922464422ac37dfbed Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Thu, 15 Nov 2018 01:32:57 +0100 Subject: [PATCH] remove dead close: telephony --- .../contacts/ContactIdentityManager.java | 28 -- .../ContactIdentityManagerGingerbread.java | 134 ------ .../contacts/ContactIdentityManagerICS.java | 79 ---- .../securesms/contacts/NameAndNumber.java | 35 -- .../securesms/contacts/RecipientsEditor.java | 416 ------------------ .../securesms/database/Address.java | 2 +- .../securesms/events/PartProgressEvent.java | 19 - .../securesms/events/RedPhoneEvent.java | 51 --- .../service/QuickResponseService.java | 61 --- .../securesms/util/ServiceUtil.java | 5 - src/org/thoughtcrime/securesms/util/Util.java | 6 - 11 files changed, 1 insertion(+), 835 deletions(-) delete mode 100644 src/org/thoughtcrime/securesms/contacts/ContactIdentityManager.java delete mode 100644 src/org/thoughtcrime/securesms/contacts/ContactIdentityManagerGingerbread.java delete mode 100644 src/org/thoughtcrime/securesms/contacts/ContactIdentityManagerICS.java delete mode 100644 src/org/thoughtcrime/securesms/contacts/NameAndNumber.java delete mode 100644 src/org/thoughtcrime/securesms/contacts/RecipientsEditor.java delete mode 100644 src/org/thoughtcrime/securesms/events/PartProgressEvent.java delete mode 100644 src/org/thoughtcrime/securesms/events/RedPhoneEvent.java delete mode 100644 src/org/thoughtcrime/securesms/service/QuickResponseService.java diff --git a/src/org/thoughtcrime/securesms/contacts/ContactIdentityManager.java b/src/org/thoughtcrime/securesms/contacts/ContactIdentityManager.java deleted file mode 100644 index d829d3be6..000000000 --- a/src/org/thoughtcrime/securesms/contacts/ContactIdentityManager.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.thoughtcrime.securesms.contacts; - -import android.content.Context; -import android.net.Uri; -import android.os.Build; - -import java.util.List; - -public abstract class ContactIdentityManager { - - public static ContactIdentityManager getInstance(Context context) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) - return new ContactIdentityManagerICS(context); - else - return new ContactIdentityManagerGingerbread(context); - } - - protected final Context context; - - public ContactIdentityManager(Context context) { - this.context = context.getApplicationContext(); - } - - public abstract Uri getSelfIdentityUri(); - public abstract boolean isSelfIdentityAutoDetected(); - public abstract List getSelfIdentityRawContactIds(); - -} diff --git a/src/org/thoughtcrime/securesms/contacts/ContactIdentityManagerGingerbread.java b/src/org/thoughtcrime/securesms/contacts/ContactIdentityManagerGingerbread.java deleted file mode 100644 index fb97ea23b..000000000 --- a/src/org/thoughtcrime/securesms/contacts/ContactIdentityManagerGingerbread.java +++ /dev/null @@ -1,134 +0,0 @@ -package org.thoughtcrime.securesms.contacts; - -import android.content.Context; -import android.content.SharedPreferences; -import android.database.Cursor; -import android.net.Uri; -import android.preference.PreferenceManager; -import android.provider.ContactsContract; -import android.provider.ContactsContract.Contacts; -import android.provider.ContactsContract.PhoneLookup; -import android.provider.ContactsContract.RawContacts; -import android.telephony.TelephonyManager; - -import org.thoughtcrime.securesms.ApplicationPreferencesActivity; -import org.thoughtcrime.securesms.util.TextSecurePreferences; - -import java.util.ArrayList; -import java.util.List; - -class ContactIdentityManagerGingerbread extends ContactIdentityManager { - - public ContactIdentityManagerGingerbread(Context context) { - super(context); - } - - @Override - public Uri getSelfIdentityUri() { - String contactUriString = TextSecurePreferences.getIdentityContactUri(context); - - if (hasLocalNumber()) return getContactUriForNumber(getLocalNumber()); - else if (contactUriString != null) return Uri.parse(contactUriString); - - return null; - } - - @Override - public boolean isSelfIdentityAutoDetected() { - return hasLocalNumber() && getContactUriForNumber(getLocalNumber()) != null; - } - - @Override - public List getSelfIdentityRawContactIds() { - long selfIdentityContactId = getSelfIdentityContactId(); - - if (selfIdentityContactId == -1) - return null; - - Cursor cursor = null; - ArrayList rawContactIds = new ArrayList(); - - try { - cursor = context.getContentResolver().query(RawContacts.CONTENT_URI, - new String[] {RawContacts._ID}, - RawContacts.CONTACT_ID + " = ?", - new String[] {selfIdentityContactId+""}, - null); - - if (cursor == null || cursor.getCount() == 0) - return null; - - while (cursor.moveToNext()) { - rawContactIds.add(Long.valueOf(cursor.getLong(0))); - } - - return rawContactIds; - - } finally { - if (cursor != null) - cursor.close(); - } - } - - private Uri getContactUriForNumber(String number) { - String[] PROJECTION = new String[] { - PhoneLookup.DISPLAY_NAME, - PhoneLookup.LOOKUP_KEY, - PhoneLookup._ID, - }; - - Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number)); - Cursor cursor = null; - - try { - cursor = context.getContentResolver().query(uri, PROJECTION, null, null, null); - - if (cursor != null && cursor.moveToFirst()) { - return Contacts.getLookupUri(cursor.getLong(2), cursor.getString(1)); - } - } finally { - if (cursor != null) - cursor.close(); - } - - return null; - } - - private long getSelfIdentityContactId() { - Uri contactUri = getSelfIdentityUri(); - - if (contactUri == null) - return -1; - - Cursor cursor = null; - - try { - cursor = context.getContentResolver().query(contactUri, - new String[] {ContactsContract.Contacts._ID}, - null, null, null); - - if (cursor != null && cursor.moveToFirst()) { - return cursor.getLong(0); - } else { - return -1; - } - - } finally { - if (cursor != null) - cursor.close(); - } - } - - private String getLocalNumber() { - return ((TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE)) - .getLine1Number(); - } - - private boolean hasLocalNumber() { - String number = getLocalNumber(); - return (number != null) && (number.trim().length() > 0); - } - - - -} diff --git a/src/org/thoughtcrime/securesms/contacts/ContactIdentityManagerICS.java b/src/org/thoughtcrime/securesms/contacts/ContactIdentityManagerICS.java deleted file mode 100644 index c06fc4798..000000000 --- a/src/org/thoughtcrime/securesms/contacts/ContactIdentityManagerICS.java +++ /dev/null @@ -1,79 +0,0 @@ -package org.thoughtcrime.securesms.contacts; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.database.Cursor; -import android.net.Uri; -import android.provider.ContactsContract; -import android.provider.ContactsContract.Contacts; -import android.provider.ContactsContract.PhoneLookup; - -import java.util.LinkedList; -import java.util.List; - -class ContactIdentityManagerICS extends ContactIdentityManager { - - public ContactIdentityManagerICS(Context context) { - super(context); - } - - @SuppressLint("NewApi") - @Override - public Uri getSelfIdentityUri() { - String[] PROJECTION = new String[] { - PhoneLookup.DISPLAY_NAME, - PhoneLookup.LOOKUP_KEY, - PhoneLookup._ID, - }; - - Cursor cursor = null; - - try { - cursor = context.getContentResolver().query(ContactsContract.Profile.CONTENT_URI, - PROJECTION, null, null, null); - - if (cursor != null && cursor.moveToFirst()) { - return Contacts.getLookupUri(cursor.getLong(2), cursor.getString(1)); - } - } finally { - if (cursor != null) - cursor.close(); - } - - return null; - } - - @Override - public boolean isSelfIdentityAutoDetected() { - return true; - } - - @SuppressLint("NewApi") - @Override - public List getSelfIdentityRawContactIds() { - List results = new LinkedList(); - - String[] PROJECTION = new String[] { - ContactsContract.Profile._ID - }; - - Cursor cursor = null; - - try { - cursor = context.getContentResolver().query(ContactsContract.Profile.CONTENT_RAW_CONTACTS_URI, - PROJECTION, null, null, null); - - if (cursor == null || cursor.getCount() == 0) - return null; - - while (cursor.moveToNext()) { - results.add(cursor.getLong(0)); - } - - return results; - } finally { - if (cursor != null) - cursor.close(); - } - } -} diff --git a/src/org/thoughtcrime/securesms/contacts/NameAndNumber.java b/src/org/thoughtcrime/securesms/contacts/NameAndNumber.java deleted file mode 100644 index b9e0e1fb0..000000000 --- a/src/org/thoughtcrime/securesms/contacts/NameAndNumber.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Copyright (C) 2011 Whisper Systems - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.thoughtcrime.securesms.contacts; - -/** - * Name and number tuple. - * - * @author Moxie Marlinspike - * - */ -public class NameAndNumber { - public String name; - public String number; - - public NameAndNumber(String name, String number) { - this.name = name; - this.number = number; - } - - public NameAndNumber() {} -} diff --git a/src/org/thoughtcrime/securesms/contacts/RecipientsEditor.java b/src/org/thoughtcrime/securesms/contacts/RecipientsEditor.java deleted file mode 100644 index 7c77dd894..000000000 --- a/src/org/thoughtcrime/securesms/contacts/RecipientsEditor.java +++ /dev/null @@ -1,416 +0,0 @@ -/* - * Copyright (C) 2008 Esmertec AG. - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.thoughtcrime.securesms.contacts; - -import android.content.Context; -import android.support.v7.widget.AppCompatMultiAutoCompleteTextView; -import android.telephony.PhoneNumberUtils; -import android.text.Annotation; -import android.text.Editable; -import android.text.Layout; -import android.text.Spannable; -import android.text.SpannableString; -import android.text.SpannableStringBuilder; -import android.text.Spanned; -import android.text.TextUtils; -import android.text.TextWatcher; -import android.util.AttributeSet; -import android.view.ContextMenu.ContextMenuInfo; -import android.view.MotionEvent; -import android.view.inputmethod.EditorInfo; -import android.widget.MultiAutoCompleteTextView; - -import org.thoughtcrime.securesms.recipients.Recipient; -import org.thoughtcrime.securesms.recipients.RecipientsFormatter; - -import java.util.ArrayList; -import java.util.List; - -/** - * Provide UI for editing the recipients of multi-media messages. - */ -public class RecipientsEditor extends AppCompatMultiAutoCompleteTextView { - private int mLongPressedPosition = -1; - private final RecipientsEditorTokenizer mTokenizer; - private char mLastSeparator = ','; - private Context mContext; - - public RecipientsEditor(Context context, AttributeSet attrs) { - super(context, attrs); - mContext = context; - mTokenizer = new RecipientsEditorTokenizer(context, this); - setTokenizer(mTokenizer); - // For the focus to move to the message body when soft Next is pressed - setImeOptions(EditorInfo.IME_ACTION_NEXT); - - /* - * The point of this TextWatcher is that when the user chooses - * an address completion from the AutoCompleteTextView menu, it - * is marked up with Annotation objects to tie it back to the - * address book entry that it came from. If the user then goes - * back and edits that part of the text, it no longer corresponds - * to that address book entry and needs to have the Annotations - * claiming that it does removed. - */ - addTextChangedListener(new TextWatcher() { - private Annotation[] mAffected; - - public void beforeTextChanged(CharSequence s, int start, - int count, int after) { - mAffected = ((Spanned) s).getSpans(start, start + count, - Annotation.class); - } - - public void onTextChanged(CharSequence s, int start, - int before, int after) { - if (before == 0 && after == 1) { // inserting a character - char c = s.charAt(start); - if (c == ',' || c == ';') { - // Remember the delimiter the user typed to end this recipient. We'll - // need it shortly in terminateToken(). - mLastSeparator = c; - } - } - } - - public void afterTextChanged(Editable s) { - if (mAffected != null) { - for (Annotation a : mAffected) { - s.removeSpan(a); - } - } - - mAffected = null; - } - }); - } - - @Override - public boolean enoughToFilter() { - if (!super.enoughToFilter()) { - return false; - } - // If the user is in the middle of editing an existing recipient, don't offer the - // auto-complete menu. Without this, when the user selects an auto-complete menu item, - // it will get added to the list of recipients so we end up with the old before-editing - // recipient and the new post-editing recipient. As a precedent, gmail does not show - // the auto-complete menu when editing an existing recipient. - int end = getSelectionEnd(); - int len = getText().length(); - - return end == len; - } - - public int getRecipientCount() { - return mTokenizer.getNumbers().size(); - } - - public List getNumbers() { - return mTokenizer.getNumbers(); - } - -// public Recipients constructContactsFromInput() { -// return RecipientFactory.getRecipientsFromString(mContext, mTokenizer.getRawString(), false); -// } - - private boolean isValidAddress(String number, boolean isMms) { - /*if (isMms) { - return MessageUtils.isValidMmsAddress(number); - } else {*/ - // TODO: PhoneNumberUtils.isWellFormedSmsAddress() only check if the number is a valid - // GSM SMS address. If the address contains a dialable char, it considers it a well - // formed SMS addr. CDMA doesn't work that way and has a different parser for SMS - // address (see CdmaSmsAddress.parse(String address)). We should definitely fix this!!! - return PhoneNumberUtils.isWellFormedSmsAddress(number); - } - - public boolean hasValidRecipient(boolean isMms) { - for (String number : mTokenizer.getNumbers()) { - if (isValidAddress(number, isMms)) - return true; - } - return false; - } - - /*public boolean hasInvalidRecipient(boolean isMms) { - for (String number : mTokenizer.getNumbers()) { - if (!isValidAddress(number, isMms)) { - /* TODO if (MmsConfig.getEmailGateway() == null) { - return true; - } else if (!MessageUtils.isAlias(number)) { - return true; - } - } - } - return false; - }*/ - - public String formatInvalidNumbers(boolean isMms) { - StringBuilder sb = new StringBuilder(); - for (String number : mTokenizer.getNumbers()) { - if (!isValidAddress(number, isMms)) { - if (sb.length() != 0) { - sb.append(", "); - } - sb.append(number); - } - } - return sb.toString(); - } - - /*public boolean containsEmail() { - if (TextUtils.indexOf(getText(), '@') == -1) - return false; - - List numbers = mTokenizer.getNumbers(); - for (String number : numbers) { - if (Mms.isEmailAddress(number)) - return true; - } - return false; - }*/ - - public static CharSequence contactToToken(Recipient c) { - String name = c.getName(); - String number = c.getAddress().serialize(); - SpannableString s = new SpannableString(RecipientsFormatter.formatNameAndNumber(name, number)); - int len = s.length(); - - if (len == 0) { - return s; - } - - s.setSpan(new Annotation("number", c.getAddress().serialize()), 0, len, - Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - - return s; - } - - public void populate(List list) { - SpannableStringBuilder sb = new SpannableStringBuilder(); - - for (Recipient c : list) { - if (sb.length() != 0) { - sb.append(", "); - } - - sb.append(contactToToken(c)); - } - - setText(sb); - } - - private int pointToPosition(int x, int y) { - x -= getCompoundPaddingLeft(); - y -= getExtendedPaddingTop(); - - x += getScrollX(); - y += getScrollY(); - - Layout layout = getLayout(); - if (layout == null) { - return -1; - } - - int line = layout.getLineForVertical(y); - int off = layout.getOffsetForHorizontal(line, x); - - return off; - } - - @Override - public boolean onTouchEvent(MotionEvent ev) { - final int action = ev.getAction(); - final int x = (int) ev.getX(); - final int y = (int) ev.getY(); - - if (action == MotionEvent.ACTION_DOWN) { - mLongPressedPosition = pointToPosition(x, y); - } - - return super.onTouchEvent(ev); - } - - private static String getNumberAt(Spanned sp, int start, int end, Context context) { - return getFieldAt("number", sp, start, end, context); - } - - private static int getSpanLength(Spanned sp, int start, int end, Context context) { - // TODO: there's a situation where the span can lose its annotations: - // - add an auto-complete contact - // - add another auto-complete contact - // - delete that second contact and keep deleting into the first - // - we lose the annotation and can no longer get the span. - // Need to fix this case because it breaks auto-complete contacts with commas in the name. - Annotation[] a = sp.getSpans(start, end, Annotation.class); - if (a.length > 0) { - return sp.getSpanEnd(a[0]); - } - return 0; - } - - private static String getFieldAt(String field, Spanned sp, int start, int end, - Context context) { - Annotation[] a = sp.getSpans(start, end, Annotation.class); - String fieldValue = getAnnotation(a, field); - if (TextUtils.isEmpty(fieldValue)) { - fieldValue = TextUtils.substring(sp, start, end); - } - return fieldValue; - - } - - private static String getAnnotation(Annotation[] a, String key) { - for (int i = 0; i < a.length; i++) { - if (a[i].getKey().equals(key)) { - return a[i].getValue(); - } - } - - return ""; - } - - private class RecipientsEditorTokenizer - implements MultiAutoCompleteTextView.Tokenizer { - private final MultiAutoCompleteTextView mList; - private final Context mContext; - - RecipientsEditorTokenizer(Context context, MultiAutoCompleteTextView list) { - mList = list; - mContext = context; - } - - /** - * Returns the start of the token that ends at offset - * cursor within text. - * It is a method from the MultiAutoCompleteTextView.Tokenizer interface. - */ - public int findTokenStart(CharSequence text, int cursor) { - int i = cursor; - char c; - - while (i > 0 && (c = text.charAt(i - 1)) != ',' && c != ';') { - i--; - } - while (i < cursor && text.charAt(i) == ' ') { - i++; - } - - return i; - } - - /** - * Returns the end of the token (minus trailing punctuation) - * that begins at offset cursor within text. - * It is a method from the MultiAutoCompleteTextView.Tokenizer interface. - */ - public int findTokenEnd(CharSequence text, int cursor) { - int i = cursor; - int len = text.length(); - char c; - - while (i < len) { - if ((c = text.charAt(i)) == ',' || c == ';') { - return i; - } else { - i++; - } - } - - return len; - } - - /** - * Returns text, modified, if necessary, to ensure that - * it ends with a token terminator (for example a space or comma). - * It is a method from the MultiAutoCompleteTextView.Tokenizer interface. - */ - public CharSequence terminateToken(CharSequence text) { - int i = text.length(); - - while (i > 0 && text.charAt(i - 1) == ' ') { - i--; - } - - char c; - if (i > 0 && ((c = text.charAt(i - 1)) == ',' || c == ';')) { - return text; - } else { - // Use the same delimiter the user just typed. - // This lets them have a mixture of commas and semicolons in their list. - String separator = mLastSeparator + " "; - if (text instanceof Spanned) { - SpannableString sp = new SpannableString(text + separator); - TextUtils.copySpansFrom((Spanned) text, 0, text.length(), - Object.class, sp, 0); - return sp; - } else { - return text + separator; - } - } - } - public String getRawString() { - return mList.getText().toString(); - } - public List getNumbers() { - Spanned sp = mList.getText(); - int len = sp.length(); - List list = new ArrayList(); - - int start = 0; - int i = 0; - while (i < len + 1) { - char c; - if ((i == len) || ((c = sp.charAt(i)) == ',') || (c == ';')) { - if (i > start) { - list.add(getNumberAt(sp, start, i, mContext)); - - // calculate the recipients total length. This is so if the name contains - // commas or semis, we'll skip over the whole name to the next - // recipient, rather than parsing this single name into multiple - // recipients. - int spanLen = getSpanLength(sp, start, i, mContext); - if (spanLen > i) { - i = spanLen; - } - } - - i++; - - while ((i < len) && (sp.charAt(i) == ' ')) { - i++; - } - - start = i; - } else { - i++; - } - } - - return list; - } - } - - static class RecipientContextMenuInfo implements ContextMenuInfo { - final Recipient recipient; - - RecipientContextMenuInfo(Recipient r) { - recipient = r; - } - } -} diff --git a/src/org/thoughtcrime/securesms/database/Address.java b/src/org/thoughtcrime/securesms/database/Address.java index 7bb1c213f..8357af4fb 100644 --- a/src/org/thoughtcrime/securesms/database/Address.java +++ b/src/org/thoughtcrime/securesms/database/Address.java @@ -117,7 +117,7 @@ public class Address implements Parcelable, Comparable
{ return formatter; } else { - return new ExternalAddressFormatter(Util.getSimCountryIso(context).or("US"), true); + return new ExternalAddressFormatter("US", true); } } diff --git a/src/org/thoughtcrime/securesms/events/PartProgressEvent.java b/src/org/thoughtcrime/securesms/events/PartProgressEvent.java deleted file mode 100644 index 30817fd7d..000000000 --- a/src/org/thoughtcrime/securesms/events/PartProgressEvent.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.thoughtcrime.securesms.events; - - -import android.support.annotation.NonNull; - -import org.thoughtcrime.securesms.attachments.Attachment; - -public class PartProgressEvent { - - public final Attachment attachment; - public final long total; - public final long progress; - - public PartProgressEvent(@NonNull Attachment attachment, long total, long progress) { - this.attachment = attachment; - this.total = total; - this.progress = progress; - } -} diff --git a/src/org/thoughtcrime/securesms/events/RedPhoneEvent.java b/src/org/thoughtcrime/securesms/events/RedPhoneEvent.java deleted file mode 100644 index 0fcd3f97f..000000000 --- a/src/org/thoughtcrime/securesms/events/RedPhoneEvent.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.thoughtcrime.securesms.events; - -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; - -import org.thoughtcrime.securesms.recipients.Recipient; - -public class RedPhoneEvent { - - public enum Type { - CALL_CONNECTED, - WAITING_FOR_RESPONDER, - SERVER_FAILURE, - PERFORMING_HANDSHAKE, - HANDSHAKE_FAILED, - CONNECTING_TO_INITIATOR, - CALL_DISCONNECTED, - CALL_RINGING, - SERVER_MESSAGE, - RECIPIENT_UNAVAILABLE, - INCOMING_CALL, - OUTGOING_CALL, - CALL_BUSY, - LOGIN_FAILED, - CLIENT_FAILURE, - DEBUG_INFO, - NO_SUCH_USER - } - - private final @NonNull Type type; - private final @NonNull Recipient recipient; - private final @Nullable String extra; - - public RedPhoneEvent(@NonNull Type type, @NonNull Recipient recipient, @Nullable String extra) { - this.type = type; - this.recipient = recipient; - this.extra = extra; - } - - public @NonNull Type getType() { - return type; - } - - public @NonNull Recipient getRecipient() { - return recipient; - } - - public @Nullable String getExtra() { - return extra; - } -} diff --git a/src/org/thoughtcrime/securesms/service/QuickResponseService.java b/src/org/thoughtcrime/securesms/service/QuickResponseService.java deleted file mode 100644 index 965efc5d7..000000000 --- a/src/org/thoughtcrime/securesms/service/QuickResponseService.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.thoughtcrime.securesms.service; - -import android.app.IntentService; -import android.content.Intent; -import android.telephony.TelephonyManager; -import android.text.TextUtils; -import android.util.Log; -import android.widget.Toast; - -import org.thoughtcrime.securesms.R; -import org.thoughtcrime.securesms.connect.ApplicationDcContext; -import org.thoughtcrime.securesms.connect.DcHelper; -import org.thoughtcrime.securesms.database.Address; -import org.thoughtcrime.securesms.util.Rfc5724Uri; - -import java.net.URISyntaxException; -import java.net.URLDecoder; - -public class QuickResponseService extends IntentService { - - private static final String TAG = QuickResponseService.class.getSimpleName(); - - public QuickResponseService() { - super("QuickResponseService"); - } - - @Override - protected void onHandleIntent(Intent intent) { - if (!TelephonyManager.ACTION_RESPOND_VIA_MESSAGE.equals(intent.getAction())) { - Log.w(TAG, "Received unknown intent: " + intent.getAction()); - return; - } - - if (KeyCachingService.isLocked(this)) { - Log.w(TAG, "Got quick response request when locked..."); - Toast.makeText(this, R.string.QuickResponseService_quick_response_unavailable_when_Signal_is_locked, Toast.LENGTH_LONG).show(); - return; - } - - try { - Rfc5724Uri uri = new Rfc5724Uri(intent.getDataString()); - String content = intent.getStringExtra(Intent.EXTRA_TEXT); - String number = uri.getPath(); - - if (number.contains("%")){ - number = URLDecoder.decode(number); - } - - Address address = Address.fromExternal(this, number); - - if (!TextUtils.isEmpty(content)) { - ApplicationDcContext dcContext = DcHelper.getContext(this); - dcContext.sendTextMsg(address.getDcChatId(), content); - } - - } catch (URISyntaxException e) { - Toast.makeText(this, R.string.QuickResponseService_problem_sending_message, Toast.LENGTH_LONG).show(); - Log.w(TAG, e); - } - } -} diff --git a/src/org/thoughtcrime/securesms/util/ServiceUtil.java b/src/org/thoughtcrime/securesms/util/ServiceUtil.java index 7633d1b80..d57a86c77 100644 --- a/src/org/thoughtcrime/securesms/util/ServiceUtil.java +++ b/src/org/thoughtcrime/securesms/util/ServiceUtil.java @@ -8,7 +8,6 @@ import android.media.AudioManager; import android.net.ConnectivityManager; import android.os.PowerManager; import android.os.Vibrator; -import android.telephony.TelephonyManager; import android.view.WindowManager; import android.view.inputmethod.InputMethodManager; @@ -29,10 +28,6 @@ public class ServiceUtil { return (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); } - public static TelephonyManager getTelephonyManager(Context context) { - return (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); - } - public static AudioManager getAudioManager(Context context) { return (AudioManager)context.getSystemService(Context.AUDIO_SERVICE); } diff --git a/src/org/thoughtcrime/securesms/util/Util.java b/src/org/thoughtcrime/securesms/util/Util.java index a5c45c0d4..f20aa7c2e 100644 --- a/src/org/thoughtcrime/securesms/util/Util.java +++ b/src/org/thoughtcrime/securesms/util/Util.java @@ -33,7 +33,6 @@ import android.os.Looper; import android.provider.Telephony; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import android.telephony.TelephonyManager; import android.text.Spannable; import android.text.SpannableString; import android.text.TextUtils; @@ -251,11 +250,6 @@ public class Util { return total; } - public static Optional getSimCountryIso(Context context) { - String simCountryIso = ((TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE)).getSimCountryIso(); - return Optional.fromNullable(simCountryIso != null ? simCountryIso.toUpperCase() : null); - } - public static List> partition(List list, int partitionSize) { List> results = new LinkedList<>();