mirror of
https://github.com/oxen-io/session-android.git
synced 2025-01-11 19:43:38 +00:00
clean up unused utils
This commit is contained in:
parent
6f002311b8
commit
704ab37cad
@ -29,7 +29,6 @@ import org.thoughtcrime.securesms.mms.MmsException;
|
||||
import org.thoughtcrime.securesms.mms.OutgoingMediaMessage;
|
||||
import org.session.libsession.messaging.threads.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.service.ExpiringMessageManager;
|
||||
import org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException;
|
||||
import org.thoughtcrime.securesms.transport.RetryLaterException;
|
||||
import org.thoughtcrime.securesms.transport.UndeliverableMessageException;
|
||||
import org.session.libsignal.libsignal.util.guava.Optional;
|
||||
|
@ -22,7 +22,6 @@ import org.thoughtcrime.securesms.dependencies.InjectableType;
|
||||
import org.thoughtcrime.securesms.jobmanager.Job;
|
||||
import org.thoughtcrime.securesms.loki.database.LokiMessageDatabase;
|
||||
import org.thoughtcrime.securesms.service.ExpiringMessageManager;
|
||||
import org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException;
|
||||
import org.thoughtcrime.securesms.transport.RetryLaterException;
|
||||
import org.session.libsignal.libsignal.util.guava.Optional;
|
||||
import org.session.libsignal.service.api.SignalServiceMessageSender;
|
||||
|
@ -1,11 +0,0 @@
|
||||
package org.thoughtcrime.securesms.transport;
|
||||
|
||||
public class InsecureFallbackApprovalException extends Exception {
|
||||
public InsecureFallbackApprovalException(String detailMessage) {
|
||||
super(detailMessage);
|
||||
}
|
||||
|
||||
public InsecureFallbackApprovalException(Throwable e) {
|
||||
super(e);
|
||||
}
|
||||
}
|
@ -1,7 +1,5 @@
|
||||
package org.thoughtcrime.securesms.transport;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class RetryLaterException extends Exception {
|
||||
public RetryLaterException() {}
|
||||
|
||||
|
@ -1,17 +1,11 @@
|
||||
package org.thoughtcrime.securesms.transport;
|
||||
|
||||
public class UndeliverableMessageException extends Exception {
|
||||
public UndeliverableMessageException() {
|
||||
}
|
||||
|
||||
public UndeliverableMessageException(String detailMessage) {
|
||||
super(detailMessage);
|
||||
}
|
||||
|
||||
public UndeliverableMessageException(String detailMessage, Throwable throwable) {
|
||||
super(detailMessage, throwable);
|
||||
}
|
||||
|
||||
public UndeliverableMessageException(Throwable throwable) {
|
||||
super(throwable);
|
||||
}
|
||||
|
@ -23,15 +23,6 @@ public abstract class CharacterCalculator {
|
||||
|
||||
public abstract CharacterState calculateCharacters(String messageBody);
|
||||
|
||||
public static CharacterCalculator readFromParcel(@NonNull Parcel in) {
|
||||
switch (in.readInt()) {
|
||||
case 1: return new SmsCharacterCalculator();
|
||||
case 2: return new MmsCharacterCalculator();
|
||||
case 3: return new PushCharacterCalculator();
|
||||
default: throw new IllegalArgumentException("Read an unsupported value for a calculator.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeToParcel(@NonNull Parcel dest, @NonNull CharacterCalculator calculator) {
|
||||
if (calculator instanceof SmsCharacterCalculator) {
|
||||
dest.writeInt(1);
|
||||
|
@ -20,10 +20,6 @@ import org.session.libsession.messaging.threads.recipients.Recipient;
|
||||
|
||||
public class CommunicationActions {
|
||||
|
||||
public static void startConversation(@NonNull Context context, @NonNull Recipient recipient, @Nullable String text) {
|
||||
startConversation(context, recipient, text, null);
|
||||
}
|
||||
|
||||
public static void startConversation(@NonNull Context context,
|
||||
@NonNull Recipient recipient,
|
||||
@Nullable String text,
|
||||
@ -56,14 +52,6 @@ public class CommunicationActions {
|
||||
}.execute();
|
||||
}
|
||||
|
||||
public static void composeSmsThroughDefaultApp(@NonNull Context context, @NonNull Address address, @Nullable String text) {
|
||||
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:" + address.serialize()));
|
||||
if (text != null) {
|
||||
intent.putExtra("sms_body", text);
|
||||
}
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
public static void openBrowserLink(@NonNull Context context, @NonNull String link) {
|
||||
try {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(link));
|
||||
|
@ -20,10 +20,6 @@ public class FileProviderUtil {
|
||||
return Uri.fromFile(file);
|
||||
}
|
||||
|
||||
public static boolean isAuthority(@NonNull Uri uri) {
|
||||
return AUTHORITY.equals(uri.getAuthority());
|
||||
}
|
||||
|
||||
public static boolean delete(@NonNull Context context, @NonNull Uri uri) {
|
||||
if (AUTHORITY.equals(uri.getAuthority())) {
|
||||
return context.getContentResolver().delete(uri, null, null) > 0;
|
||||
|
@ -188,10 +188,6 @@ public class MediaUtil {
|
||||
return isVideoType(attachment.getContentType());
|
||||
}
|
||||
|
||||
public static boolean isVideo(String contentType) {
|
||||
return !TextUtils.isEmpty(contentType) && contentType.trim().startsWith("video/");
|
||||
}
|
||||
|
||||
public static boolean isVcard(String contentType) {
|
||||
return !TextUtils.isEmpty(contentType) && contentType.trim().equals(MediaTypes.VCARD);
|
||||
}
|
||||
@ -208,10 +204,6 @@ public class MediaUtil {
|
||||
return !isGif(attachment) && !isImage(attachment) && !isAudio(attachment) && !isVideo(attachment);
|
||||
}
|
||||
|
||||
public static boolean isTextType(String contentType) {
|
||||
return (null != contentType) && contentType.startsWith("text/");
|
||||
}
|
||||
|
||||
public static boolean isImageType(String contentType) {
|
||||
return (null != contentType)
|
||||
&& contentType.startsWith("image/")
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.thoughtcrime.securesms.util;
|
||||
|
||||
|
||||
import android.os.Build;
|
||||
import android.os.MemoryFile;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
|
||||
|
@ -1,15 +0,0 @@
|
||||
package org.thoughtcrime.securesms.util;
|
||||
|
||||
import android.os.Build;
|
||||
import android.os.PowerManager;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
public class PowerManagerCompat {
|
||||
|
||||
public static boolean isDeviceIdleMode(@NonNull PowerManager powerManager) {
|
||||
if (Build.VERSION.SDK_INT >= 23) {
|
||||
return powerManager.isDeviceIdleMode();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,23 +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;
|
||||
|
||||
public interface RedPhoneCallTypes {
|
||||
public static final int INCOMING = 1023;
|
||||
public static final int OUTGOING = 1024;
|
||||
public static final int MISSED = 1025;
|
||||
}
|
@ -1,165 +0,0 @@
|
||||
package org.thoughtcrime.securesms.util;
|
||||
|
||||
import android.content.Context;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.TextView;
|
||||
|
||||
import network.loki.messenger.R;
|
||||
import org.session.libsession.messaging.threads.recipients.Recipient;
|
||||
import org.session.libsignal.libsignal.util.guava.Optional;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class SelectedRecipientsAdapter extends BaseAdapter {
|
||||
@NonNull private Context context;
|
||||
@Nullable private OnRecipientDeletedListener onRecipientDeletedListener;
|
||||
@NonNull private List<RecipientWrapper> recipients;
|
||||
|
||||
public SelectedRecipientsAdapter(@NonNull Context context) {
|
||||
this(context, Collections.<Recipient>emptyList());
|
||||
}
|
||||
|
||||
public SelectedRecipientsAdapter(@NonNull Context context,
|
||||
@NonNull Collection<Recipient> existingRecipients)
|
||||
{
|
||||
this.context = context;
|
||||
this.recipients = wrapExistingMembers(existingRecipients);
|
||||
}
|
||||
|
||||
public void add(@NonNull Recipient recipient, boolean isPush) {
|
||||
if (!find(recipient).isPresent()) {
|
||||
RecipientWrapper wrapper = new RecipientWrapper(recipient, true, isPush);
|
||||
this.recipients.add(0, wrapper);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public Optional<RecipientWrapper> find(@NonNull Recipient recipient) {
|
||||
RecipientWrapper found = null;
|
||||
for (RecipientWrapper wrapper : recipients) {
|
||||
if (wrapper.getRecipient().equals(recipient)) found = wrapper;
|
||||
}
|
||||
return Optional.fromNullable(found);
|
||||
}
|
||||
|
||||
public void remove(@NonNull Recipient recipient) {
|
||||
Optional<RecipientWrapper> match = find(recipient);
|
||||
if (match.isPresent()) {
|
||||
recipients.remove(match.get());
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public Set<Recipient> getRecipients() {
|
||||
final Set<Recipient> recipientSet = new HashSet<>(recipients.size());
|
||||
for (RecipientWrapper wrapper : recipients) {
|
||||
recipientSet.add(wrapper.getRecipient());
|
||||
}
|
||||
return recipientSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return recipients.size();
|
||||
}
|
||||
|
||||
public boolean hasNonPushMembers() {
|
||||
for (RecipientWrapper wrapper : recipients) {
|
||||
if (!wrapper.isPush()) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return recipients.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(final int position, View v, final ViewGroup parent) {
|
||||
if (v == null) {
|
||||
v = LayoutInflater.from(context).inflate(R.layout.selected_recipient_list_item, parent, false);
|
||||
}
|
||||
|
||||
final RecipientWrapper rw = (RecipientWrapper)getItem(position);
|
||||
final Recipient p = rw.getRecipient();
|
||||
final boolean modifiable = rw.isModifiable();
|
||||
|
||||
TextView name = (TextView) v.findViewById(R.id.name);
|
||||
TextView phone = (TextView) v.findViewById(R.id.phone);
|
||||
ImageButton delete = (ImageButton) v.findViewById(R.id.delete);
|
||||
|
||||
name.setText(p.getName());
|
||||
phone.setText(p.getAddress().serialize());
|
||||
delete.setVisibility(modifiable ? View.VISIBLE : View.GONE);
|
||||
delete.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (onRecipientDeletedListener != null) {
|
||||
onRecipientDeletedListener.onRecipientDeleted(recipients.get(position).getRecipient());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
private static List<RecipientWrapper> wrapExistingMembers(Collection<Recipient> recipients) {
|
||||
final LinkedList<RecipientWrapper> wrapperList = new LinkedList<>();
|
||||
for (Recipient recipient : recipients) {
|
||||
wrapperList.add(new RecipientWrapper(recipient, false, true));
|
||||
}
|
||||
return wrapperList;
|
||||
}
|
||||
|
||||
public void setOnRecipientDeletedListener(@Nullable OnRecipientDeletedListener listener) {
|
||||
onRecipientDeletedListener = listener;
|
||||
}
|
||||
|
||||
public interface OnRecipientDeletedListener {
|
||||
void onRecipientDeleted(Recipient recipient);
|
||||
}
|
||||
|
||||
public static class RecipientWrapper {
|
||||
private final Recipient recipient;
|
||||
private final boolean modifiable;
|
||||
private final boolean push;
|
||||
|
||||
public RecipientWrapper(final @NonNull Recipient recipient,
|
||||
final boolean modifiable,
|
||||
final boolean push)
|
||||
{
|
||||
this.recipient = recipient;
|
||||
this.modifiable = modifiable;
|
||||
this.push = push;
|
||||
}
|
||||
|
||||
public @NonNull Recipient getRecipient() {
|
||||
return recipient;
|
||||
}
|
||||
|
||||
public boolean isModifiable() {
|
||||
return modifiable;
|
||||
}
|
||||
|
||||
public boolean isPush() {
|
||||
return push;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2014 Open 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 java.util.concurrent.Callable;
|
||||
import java.util.concurrent.FutureTask;
|
||||
|
||||
/**
|
||||
* FutureTask with a reference identifier tag.
|
||||
*
|
||||
* @author Jake McGinty
|
||||
*/
|
||||
public class TaggedFutureTask<V> extends FutureTask<V> {
|
||||
private final Object tag;
|
||||
public TaggedFutureTask(Runnable runnable, V result, Object tag) {
|
||||
super(runnable, result);
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public TaggedFutureTask(Callable<V> callable, Object tag) {
|
||||
super(callable);
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public Object getTag() {
|
||||
return tag;
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
package org.thoughtcrime.securesms.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.net.ConnectivityManager;
|
||||
import androidx.annotation.NonNull;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import org.session.libsignal.utilities.logging.Log;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class TelephonyUtil {
|
||||
private static final String TAG = TelephonyUtil.class.getSimpleName();
|
||||
|
||||
public static TelephonyManager getManager(final Context context) {
|
||||
return (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
}
|
||||
|
||||
public static String getMccMnc(final Context context) {
|
||||
final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
final int configMcc = context.getResources().getConfiguration().mcc;
|
||||
final int configMnc = context.getResources().getConfiguration().mnc;
|
||||
if (tm.getSimState() == TelephonyManager.SIM_STATE_READY) {
|
||||
Log.i(TAG, "Choosing MCC+MNC info from TelephonyManager.getSimOperator()");
|
||||
return tm.getSimOperator();
|
||||
} else if (tm.getPhoneType() != TelephonyManager.PHONE_TYPE_CDMA) {
|
||||
Log.i(TAG, "Choosing MCC+MNC info from TelephonyManager.getNetworkOperator()");
|
||||
return tm.getNetworkOperator();
|
||||
} else if (configMcc != 0 && configMnc != 0) {
|
||||
Log.i(TAG, "Choosing MCC+MNC info from current context's Configuration");
|
||||
return String.format(Locale.ROOT, "%03d%d",
|
||||
configMcc,
|
||||
configMnc == Configuration.MNC_ZERO ? 0 : configMnc);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getApn(final Context context) {
|
||||
final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
return cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE_MMS).getExtraInfo();
|
||||
}
|
||||
|
||||
public static boolean isAnyPstnLineBusy(@NonNull Context context) {
|
||||
return getManager(context).getCallState() != TelephonyManager.CALL_STATE_IDLE;
|
||||
}
|
||||
}
|
@ -42,28 +42,8 @@ public class Util {
|
||||
return value == null || value.getText() == null || TextUtils.isEmpty(value.getTextTrimmed());
|
||||
}
|
||||
|
||||
/**
|
||||
* The app version.
|
||||
* <p>
|
||||
* This code should be used in all places that compare app versions rather than
|
||||
* {@link #getManifestApkVersion(Context)} or {@link BuildConfig#VERSION_CODE}.
|
||||
*/
|
||||
public static int getCanonicalVersionCode() {
|
||||
return BuildConfig.CANONICAL_VERSION_CODE;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link BuildConfig#VERSION_CODE} may not be the actual version due to ABI split code adding a
|
||||
* postfix after BuildConfig is generated.
|
||||
* <p>
|
||||
* However, in most cases you want to use {@link BuildConfig#CANONICAL_VERSION_CODE} via
|
||||
* {@link #getCanonicalVersionCode()}
|
||||
*/
|
||||
public static int getManifestApkVersion(Context context) {
|
||||
try {
|
||||
return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode;
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,23 +12,6 @@ public class WakeLockUtil {
|
||||
|
||||
private static final String TAG = WakeLockUtil.class.getSimpleName();
|
||||
|
||||
/**
|
||||
* Run a runnable with a wake lock. Ensures that the lock is safely acquired and released.
|
||||
*
|
||||
* @param tag will be prefixed with "signal:" if it does not already start with it.
|
||||
*/
|
||||
public static void runWithLock(@NonNull Context context, int lockType, long timeout, @NonNull String tag, @NonNull Runnable task) {
|
||||
WakeLock wakeLock = null;
|
||||
try {
|
||||
wakeLock = acquire(context, lockType, timeout, tag);
|
||||
task.run();
|
||||
} finally {
|
||||
if (wakeLock != null) {
|
||||
release(wakeLock, tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tag will be prefixed with "signal:" if it does not already start with it.
|
||||
*/
|
||||
|
@ -1,35 +0,0 @@
|
||||
package org.thoughtcrime.securesms.util.dualsim;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
public class SubscriptionInfoCompat {
|
||||
|
||||
private final int subscriptionId;
|
||||
private final int mcc;
|
||||
private final int mnc;
|
||||
private final @Nullable CharSequence displayName;
|
||||
|
||||
public SubscriptionInfoCompat(int subscriptionId, @Nullable CharSequence displayName, int mcc, int mnc) {
|
||||
this.subscriptionId = subscriptionId;
|
||||
this.displayName = displayName;
|
||||
this.mcc = mcc;
|
||||
this.mnc = mnc;
|
||||
}
|
||||
|
||||
public @NonNull CharSequence getDisplayName() {
|
||||
return displayName != null ? displayName : "";
|
||||
}
|
||||
|
||||
public int getSubscriptionId() {
|
||||
return subscriptionId;
|
||||
}
|
||||
|
||||
public int getMnc() {
|
||||
return mnc;
|
||||
}
|
||||
|
||||
public int getMcc() {
|
||||
return mcc;
|
||||
}
|
||||
}
|
@ -1,152 +0,0 @@
|
||||
package org.thoughtcrime.securesms.util.dualsim;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import network.loki.messenger.R;
|
||||
import org.session.libsession.utilities.ServiceUtil;
|
||||
|
||||
import org.session.libsignal.utilities.logging.Log;
|
||||
import org.session.libsignal.libsignal.util.guava.Function;
|
||||
import org.session.libsignal.libsignal.util.guava.Optional;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public final class SubscriptionManagerCompat {
|
||||
|
||||
private static final String TAG = SubscriptionManagerCompat.class.getSimpleName();
|
||||
|
||||
private final Context context;
|
||||
|
||||
public SubscriptionManagerCompat(Context context) {
|
||||
this.context = context.getApplicationContext();
|
||||
}
|
||||
|
||||
public Optional<Integer> getPreferredSubscriptionId() {
|
||||
if (Build.VERSION.SDK_INT < 24) {
|
||||
return Optional.absent();
|
||||
}
|
||||
|
||||
return Optional.of(SubscriptionManager.getDefaultSmsSubscriptionId());
|
||||
}
|
||||
|
||||
public Optional<SubscriptionInfoCompat> getActiveSubscriptionInfo(int subscriptionId) {
|
||||
if (Build.VERSION.SDK_INT < 22) {
|
||||
return Optional.absent();
|
||||
}
|
||||
|
||||
return Optional.fromNullable(getActiveSubscriptionInfoMap(false).get(subscriptionId));
|
||||
}
|
||||
|
||||
public @NonNull Collection<SubscriptionInfoCompat> getActiveAndReadySubscriptionInfos() {
|
||||
if (Build.VERSION.SDK_INT < 22) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return getActiveSubscriptionInfoMap(true).values();
|
||||
}
|
||||
|
||||
@RequiresApi(api = 22)
|
||||
private @NonNull Map<Integer, SubscriptionInfoCompat> getActiveSubscriptionInfoMap(boolean excludeUnreadySubscriptions) {
|
||||
List<SubscriptionInfo> subscriptionInfos = getActiveSubscriptionInfoList();
|
||||
|
||||
if (subscriptionInfos.isEmpty()) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
Map<SubscriptionInfo, CharSequence> descriptions = getDescriptionsFor(subscriptionInfos);
|
||||
Map<Integer, SubscriptionInfoCompat> map = new LinkedHashMap<>();
|
||||
|
||||
for (SubscriptionInfo subscriptionInfo : subscriptionInfos) {
|
||||
if (!excludeUnreadySubscriptions || isReady(subscriptionInfo)) {
|
||||
map.put(subscriptionInfo.getSubscriptionId(),
|
||||
new SubscriptionInfoCompat(subscriptionInfo.getSubscriptionId(),
|
||||
descriptions.get(subscriptionInfo),
|
||||
subscriptionInfo.getMcc(),
|
||||
subscriptionInfo.getMnc()));
|
||||
}
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
public boolean isMultiSim() {
|
||||
if (Build.VERSION.SDK_INT < 22) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return getActiveSubscriptionInfoList().size() >= 2;
|
||||
}
|
||||
|
||||
@RequiresApi(api = 22)
|
||||
private @NonNull List<SubscriptionInfo> getActiveSubscriptionInfoList() {
|
||||
SubscriptionManager subscriptionManager = ServiceUtil.getSubscriptionManager(context);
|
||||
|
||||
if (subscriptionManager == null) {
|
||||
Log.w(TAG, "Missing SubscriptionManager.");
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
List<SubscriptionInfo> list = subscriptionManager.getActiveSubscriptionInfoList();
|
||||
|
||||
return list != null? list : Collections.emptyList();
|
||||
}
|
||||
|
||||
@RequiresApi(api = 22)
|
||||
private Map<SubscriptionInfo, CharSequence> getDescriptionsFor(@NonNull Collection<SubscriptionInfo> subscriptions) {
|
||||
Map<SubscriptionInfo, CharSequence> descriptions;
|
||||
|
||||
descriptions = createDescriptionMap(subscriptions, SubscriptionInfo::getDisplayName);
|
||||
if (hasNoDuplicates(descriptions.values())) return descriptions;
|
||||
|
||||
return createDescriptionMap(subscriptions, this::describeSimIndex);
|
||||
}
|
||||
|
||||
@RequiresApi(api = 22)
|
||||
private String describeSimIndex(SubscriptionInfo info) {
|
||||
return context.getString(R.string.conversation_activity__sim_n, info.getSimSlotIndex() + 1);
|
||||
}
|
||||
|
||||
private static Map<SubscriptionInfo, CharSequence> createDescriptionMap(@NonNull Collection<SubscriptionInfo> subscriptions,
|
||||
@NonNull Function<SubscriptionInfo, CharSequence> createDescription)
|
||||
{
|
||||
Map<SubscriptionInfo, CharSequence> descriptions = new HashMap<>();
|
||||
for (SubscriptionInfo subscriptionInfo: subscriptions) {
|
||||
descriptions.put(subscriptionInfo, createDescription.apply(subscriptionInfo));
|
||||
}
|
||||
return descriptions;
|
||||
}
|
||||
|
||||
private static <T> boolean hasNoDuplicates(Collection<T> collection) {
|
||||
final Set<T> set = new HashSet<>();
|
||||
|
||||
for (T t : collection) {
|
||||
if (!set.add(t)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isReady(@NonNull SubscriptionInfo subscriptionInfo) {
|
||||
if (Build.VERSION.SDK_INT < 24) return true;
|
||||
|
||||
TelephonyManager telephonyManager = ServiceUtil.getTelephonyManager(context);
|
||||
|
||||
TelephonyManager specificTelephonyManager = telephonyManager.createForSubscriptionId(subscriptionInfo.getSubscriptionId());
|
||||
|
||||
return specificTelephonyManager.getSimState() == TelephonyManager.SIM_STATE_READY;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user