mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-22 09:49:30 +01:00
Remove more SMS vestiges.
This commit is contained in:
@@ -1,87 +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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.thoughtcrime.securesms.util;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.telephony.SmsMessage;
|
||||
|
||||
import org.signal.core.util.logging.Log;
|
||||
|
||||
public class SmsCharacterCalculator extends CharacterCalculator {
|
||||
|
||||
private static final String TAG = Log.tag(SmsCharacterCalculator.class);
|
||||
|
||||
@Override
|
||||
public CharacterState calculateCharacters(String messageBody) {
|
||||
int[] length;
|
||||
int messagesSpent;
|
||||
int charactersSpent;
|
||||
int charactersRemaining;
|
||||
|
||||
try {
|
||||
length = SmsMessage.calculateLength(messageBody, false);
|
||||
messagesSpent = length[0];
|
||||
charactersSpent = length[1];
|
||||
charactersRemaining = length[2];
|
||||
} catch (NullPointerException e) {
|
||||
Log.w(TAG, e);
|
||||
messagesSpent = 1;
|
||||
charactersSpent = messageBody.length();
|
||||
charactersRemaining = 1000;
|
||||
} catch (RuntimeException e) {
|
||||
if (e instanceof SecurityException || e.getCause() instanceof SecurityException) {
|
||||
Log.e(TAG, "Security Exception", e);
|
||||
messagesSpent = 1;
|
||||
charactersSpent = messageBody.length();
|
||||
charactersRemaining = 1000;
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
int maxMessageSize;
|
||||
|
||||
if (messagesSpent > 0) {
|
||||
maxMessageSize = (charactersSpent + charactersRemaining) / messagesSpent;
|
||||
} else {
|
||||
maxMessageSize = (charactersSpent + charactersRemaining);
|
||||
}
|
||||
|
||||
return new CharacterState(messagesSpent, charactersRemaining, maxMessageSize, maxMessageSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
}
|
||||
|
||||
public static final Creator<SmsCharacterCalculator> CREATOR = new Creator<SmsCharacterCalculator>() {
|
||||
@Override
|
||||
public SmsCharacterCalculator createFromParcel(Parcel in) {
|
||||
return new SmsCharacterCalculator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SmsCharacterCalculator[] newArray(int size) {
|
||||
return new SmsCharacterCalculator[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package org.thoughtcrime.securesms.util;
|
||||
|
||||
import android.app.role.RoleManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.provider.Telephony;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
public final class SmsUtil {
|
||||
|
||||
private SmsUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Must be used with {@code startActivityForResult}
|
||||
*/
|
||||
public static @NonNull Intent getSmsRoleIntent(@NonNull Context context) {
|
||||
if (Build.VERSION.SDK_INT >= 29) {
|
||||
RoleManager roleManager = ContextCompat.getSystemService(context, RoleManager.class);
|
||||
return roleManager.createRequestRoleIntent(RoleManager.ROLE_SMS);
|
||||
} else {
|
||||
Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
|
||||
intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, context.getPackageName());
|
||||
return intent;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,9 +24,6 @@ import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Typeface;
|
||||
import android.net.Uri;
|
||||
import android.os.Build.VERSION;
|
||||
import android.os.Build.VERSION_CODES;
|
||||
import android.provider.Telephony;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
@@ -38,8 +35,6 @@ import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresPermission;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
import com.google.android.mms.pdu_alt.CharacterSets;
|
||||
import com.google.android.mms.pdu_alt.EncodedStringValue;
|
||||
import com.google.i18n.phonenumbers.NumberParseException;
|
||||
import com.google.i18n.phonenumbers.PhoneNumberUtil;
|
||||
import com.google.i18n.phonenumbers.Phonenumber;
|
||||
@@ -50,11 +45,10 @@ import org.thoughtcrime.securesms.BuildConfig;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.components.ComposeText;
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||
import org.thoughtcrime.securesms.mms.OutgoingLegacyMmsConnection;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -143,10 +137,6 @@ public class Util {
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
public static boolean isEmpty(EncodedStringValue[] value) {
|
||||
return value == null || value.length == 0;
|
||||
}
|
||||
|
||||
public static boolean isEmpty(ComposeText value) {
|
||||
return value == null || value.getText() == null || TextUtils.isEmpty(value.getTextTrimmed());
|
||||
}
|
||||
@@ -198,27 +188,15 @@ public class Util {
|
||||
}
|
||||
|
||||
public static @NonNull String toIsoString(byte[] bytes) {
|
||||
try {
|
||||
return new String(bytes, CharacterSets.MIMENAME_ISO_8859_1);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new AssertionError("ISO_8859_1 must be supported!");
|
||||
}
|
||||
return new String(bytes, StandardCharsets.ISO_8859_1);
|
||||
}
|
||||
|
||||
public static byte[] toIsoBytes(String isoString) {
|
||||
try {
|
||||
return isoString.getBytes(CharacterSets.MIMENAME_ISO_8859_1);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new AssertionError("ISO_8859_1 must be supported!");
|
||||
}
|
||||
return isoString.getBytes(StandardCharsets.ISO_8859_1);
|
||||
}
|
||||
|
||||
public static byte[] toUtf8Bytes(String utf8String) {
|
||||
try {
|
||||
return utf8String.getBytes(CharacterSets.MIMENAME_UTF_8);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new AssertionError("UTF_8 must be supported!");
|
||||
}
|
||||
return utf8String.getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public static void wait(Object lock, long timeout) {
|
||||
@@ -231,7 +209,6 @@ public class Util {
|
||||
|
||||
@RequiresPermission(anyOf = {
|
||||
android.Manifest.permission.READ_PHONE_STATE,
|
||||
android.Manifest.permission.READ_SMS,
|
||||
android.Manifest.permission.READ_PHONE_NUMBERS
|
||||
})
|
||||
@SuppressLint("MissingPermission")
|
||||
@@ -328,11 +305,6 @@ public class Util {
|
||||
return result;
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
public static boolean isDefaultSmsProvider(Context context){
|
||||
return context.getPackageName().equals(Telephony.Sms.getDefaultSmsPackage(context));
|
||||
}
|
||||
|
||||
/**
|
||||
* The app version.
|
||||
* <p>
|
||||
@@ -394,10 +366,6 @@ public class Util {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isMmsCapable(Context context) {
|
||||
return (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) || OutgoingLegacyMmsConnection.isConnectionPossible(context);
|
||||
}
|
||||
|
||||
public static <T> T getRandomElement(T[] elements) {
|
||||
return elements[new SecureRandom().nextInt(elements.length)];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user