diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index cdd0709c2..b0f477a94 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -205,11 +205,6 @@
android:windowSoftInputMode="stateVisible"
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -388,18 +369,6 @@
-
-
-
-
-
-
-
-
-
diff --git a/src/org/thoughtcrime/securesms/ApplicationContext.java b/src/org/thoughtcrime/securesms/ApplicationContext.java
index 00dcb0f12..edaba2519 100644
--- a/src/org/thoughtcrime/securesms/ApplicationContext.java
+++ b/src/org/thoughtcrime/securesms/ApplicationContext.java
@@ -37,7 +37,6 @@ import org.thoughtcrime.securesms.jobmanager.requirements.NetworkRequirementProv
import org.thoughtcrime.securesms.jobs.CreateSignedPreKeyJob;
import org.thoughtcrime.securesms.jobs.MultiDeviceContactUpdateJob;
import org.thoughtcrime.securesms.jobs.requirements.MasterSecretRequirementProvider;
-import org.thoughtcrime.securesms.jobs.requirements.ServiceRequirementProvider;
import org.thoughtcrime.securesms.jobs.requirements.SqlCipherMigrationRequirementProvider;
import org.thoughtcrime.securesms.push.SignalServiceNetworkAccess;
import org.thoughtcrime.securesms.service.ExpiringMessageManager;
@@ -144,7 +143,6 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
.withDependencyInjector(this)
.withJobSerializer(new JavaJobSerializer())
.withRequirementProviders(new MasterSecretRequirementProvider(this),
- new ServiceRequirementProvider(this),
new NetworkRequirementProvider(this),
new SqlCipherMigrationRequirementProvider())
.withConsumerThreads(5)
diff --git a/src/org/thoughtcrime/securesms/DatabaseMigrationActivity.java b/src/org/thoughtcrime/securesms/DatabaseMigrationActivity.java
deleted file mode 100644
index b9aef9aaa..000000000
--- a/src/org/thoughtcrime/securesms/DatabaseMigrationActivity.java
+++ /dev/null
@@ -1,194 +0,0 @@
-package org.thoughtcrime.securesms;
-
-import android.content.BroadcastReceiver;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.content.ServiceConnection;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.IBinder;
-import android.os.Message;
-import android.os.Parcelable;
-import android.view.View;
-import android.widget.Button;
-import android.widget.LinearLayout;
-import android.widget.ProgressBar;
-import android.widget.TextView;
-
-import org.thoughtcrime.securesms.database.SmsMigrator.ProgressDescription;
-import org.thoughtcrime.securesms.service.ApplicationMigrationService;
-import org.thoughtcrime.securesms.service.ApplicationMigrationService.ImportState;
-
-public class DatabaseMigrationActivity extends PassphraseRequiredActionBarActivity {
-
- private final ImportServiceConnection serviceConnection = new ImportServiceConnection();
- private final ImportStateHandler importStateHandler = new ImportStateHandler();
- private final BroadcastReceiver completedReceiver = new NullReceiver();
-
- private LinearLayout promptLayout;
- private LinearLayout progressLayout;
- private Button skipButton;
- private Button importButton;
- private ProgressBar progress;
- private TextView progressLabel;
-
- private ApplicationMigrationService importService;
- private boolean isVisible = false;
-
- @Override
- protected void onCreate(Bundle bundle, boolean ready) {
- setContentView(R.layout.database_migration_activity);
-
- initializeResources();
- initializeServiceBinding();
- }
-
- @Override
- public void onResume() {
- super.onResume();
- isVisible = true;
- registerForCompletedNotification();
- }
-
- @Override
- public void onPause() {
- super.onPause();
- isVisible = false;
- unregisterForCompletedNotification();
- }
-
- @Override
- public void onDestroy() {
- super.onDestroy();
- shutdownServiceBinding();
- }
-
- @Override
- public void onBackPressed() {
-
- }
-
- private void initializeServiceBinding() {
- Intent intent = new Intent(this, ApplicationMigrationService.class);
- bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
- }
-
- private void initializeResources() {
- this.promptLayout = (LinearLayout)findViewById(R.id.prompt_layout);
- this.progressLayout = (LinearLayout)findViewById(R.id.progress_layout);
- this.skipButton = (Button) findViewById(R.id.skip_button);
- this.importButton = (Button) findViewById(R.id.import_button);
- this.progress = (ProgressBar) findViewById(R.id.import_progress);
- this.progressLabel = (TextView) findViewById(R.id.import_status);
-
- this.progressLayout.setVisibility(View.GONE);
- this.promptLayout.setVisibility(View.GONE);
-
- this.importButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Intent intent = new Intent(DatabaseMigrationActivity.this, ApplicationMigrationService.class);
- intent.setAction(ApplicationMigrationService.MIGRATE_DATABASE);
- intent.putExtra("master_secret", (Parcelable)getIntent().getParcelableExtra("master_secret"));
- startService(intent);
-
- promptLayout.setVisibility(View.GONE);
- progressLayout.setVisibility(View.VISIBLE);
- }
- });
-
- this.skipButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- ApplicationMigrationService.setDatabaseImported(DatabaseMigrationActivity.this);
- handleImportComplete();
- }
- });
- }
-
- private void registerForCompletedNotification() {
- IntentFilter filter = new IntentFilter();
- filter.addAction(ApplicationMigrationService.COMPLETED_ACTION);
- filter.setPriority(1000);
-
- registerReceiver(completedReceiver, filter);
- }
-
- private void unregisterForCompletedNotification() {
- unregisterReceiver(completedReceiver);
- }
-
- private void shutdownServiceBinding() {
- unbindService(serviceConnection);
- }
-
- private void handleStateIdle() {
- this.promptLayout.setVisibility(View.VISIBLE);
- this.progressLayout.setVisibility(View.GONE);
- }
-
- private void handleStateProgress(ProgressDescription update) {
- this.promptLayout.setVisibility(View.GONE);
- this.progressLayout.setVisibility(View.VISIBLE);
- this.progressLabel.setText(update.primaryComplete + "/" + update.primaryTotal);
-
- double max = this.progress.getMax();
- double primaryTotal = update.primaryTotal;
- double primaryComplete = update.primaryComplete;
- double secondaryTotal = update.secondaryTotal;
- double secondaryComplete = update.secondaryComplete;
-
- this.progress.setProgress((int)Math.round((primaryComplete / primaryTotal) * max));
- this.progress.setSecondaryProgress((int)Math.round((secondaryComplete / secondaryTotal) * max));
- }
-
- private void handleImportComplete() {
- if (isVisible) {
- if (getIntent().hasExtra("next_intent")) {
- startActivity((Intent)getIntent().getParcelableExtra("next_intent"));
- } else {
- startActivity(new Intent(this, ConversationListActivity.class));
- }
- }
-
- finish();
- }
-
- private class ImportStateHandler extends Handler {
- @Override
- public void handleMessage(Message message) {
- switch (message.what) {
- case ImportState.STATE_IDLE: handleStateIdle(); break;
- case ImportState.STATE_MIGRATING_IN_PROGRESS: handleStateProgress((ProgressDescription)message.obj); break;
- case ImportState.STATE_MIGRATING_COMPLETE: handleImportComplete(); break;
- }
- }
- }
-
- private class ImportServiceConnection implements ServiceConnection {
- @Override
- public void onServiceConnected(ComponentName className, IBinder service) {
- importService = ((ApplicationMigrationService.ApplicationMigrationBinder)service).getService();
- importService.setImportStateHandler(importStateHandler);
-
- ImportState state = importService.getState();
- importStateHandler.obtainMessage(state.state, state.progress).sendToTarget();
- }
-
- @Override
- public void onServiceDisconnected(ComponentName name) {
- importService.setImportStateHandler(null);
- }
- }
-
- private static class NullReceiver extends BroadcastReceiver {
- @Override
- public void onReceive(Context context, Intent intent) {
- abortBroadcast();
- }
- }
-
-
-}
diff --git a/src/org/thoughtcrime/securesms/components/reminder/SystemSmsImportReminder.java b/src/org/thoughtcrime/securesms/components/reminder/SystemSmsImportReminder.java
deleted file mode 100644
index d4a7824aa..000000000
--- a/src/org/thoughtcrime/securesms/components/reminder/SystemSmsImportReminder.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package org.thoughtcrime.securesms.components.reminder;
-
-import android.content.Context;
-import android.content.Intent;
-import android.view.View;
-import android.view.View.OnClickListener;
-
-import org.thoughtcrime.securesms.ConversationListActivity;
-import org.thoughtcrime.securesms.DatabaseMigrationActivity;
-import org.thoughtcrime.securesms.R;
-import org.thoughtcrime.securesms.service.ApplicationMigrationService;
-
-public class SystemSmsImportReminder extends Reminder {
-
- public SystemSmsImportReminder(final Context context) {
- super(context.getString(R.string.reminder_header_sms_import_title),
- context.getString(R.string.reminder_header_sms_import_text));
-
- final OnClickListener okListener = v -> {
- Intent intent = new Intent(context, ApplicationMigrationService.class);
- intent.setAction(ApplicationMigrationService.MIGRATE_DATABASE);
- context.startService(intent);
-
- Intent nextIntent = new Intent(context, ConversationListActivity.class);
- Intent activityIntent = new Intent(context, DatabaseMigrationActivity.class);
- activityIntent.putExtra("next_intent", nextIntent);
- context.startActivity(activityIntent);
- };
- final OnClickListener cancelListener = new OnClickListener() {
- @Override
- public void onClick(View v) {
- ApplicationMigrationService.setDatabaseImported(context);
- }
- };
- setOkListener(okListener);
- setDismissListener(cancelListener);
- }
-
- public static boolean isEligible(Context context) {
- return !ApplicationMigrationService.isDatabaseImported(context);
- }
-}
diff --git a/src/org/thoughtcrime/securesms/database/SmsMigrator.java b/src/org/thoughtcrime/securesms/database/SmsMigrator.java
deleted file mode 100644
index 8222dd82d..000000000
--- a/src/org/thoughtcrime/securesms/database/SmsMigrator.java
+++ /dev/null
@@ -1,271 +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.database;
-
-import android.content.Context;
-import android.database.Cursor;
-import android.database.sqlite.SQLiteException;
-import android.net.Uri;
-import android.support.annotation.Nullable;
-import android.util.Log;
-
-import net.sqlcipher.database.SQLiteDatabase;
-import net.sqlcipher.database.SQLiteStatement;
-
-import org.thoughtcrime.securesms.recipients.Recipient;
-import org.thoughtcrime.securesms.util.TextSecurePreferences;
-
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-import java.util.StringTokenizer;
-
-public class SmsMigrator {
-
- private static final String TAG = SmsMigrator.class.getSimpleName();
-
- private static void addStringToStatement(SQLiteStatement statement, Cursor cursor,
- int index, String key)
- {
- int columnIndex = cursor.getColumnIndexOrThrow(key);
-
- if (cursor.isNull(columnIndex)) {
- statement.bindNull(index);
- } else {
- statement.bindString(index, cursor.getString(columnIndex));
- }
- }
-
- private static void addIntToStatement(SQLiteStatement statement, Cursor cursor,
- int index, String key)
- {
- int columnIndex = cursor.getColumnIndexOrThrow(key);
-
- if (cursor.isNull(columnIndex)) {
- statement.bindNull(index);
- } else {
- statement.bindLong(index, cursor.getLong(columnIndex));
- }
- }
-
- @SuppressWarnings("SameParameterValue")
- private static void addTranslatedTypeToStatement(SQLiteStatement statement, Cursor cursor, int index, String key)
- {
- int columnIndex = cursor.getColumnIndexOrThrow(key);
-
- if (cursor.isNull(columnIndex)) {
- statement.bindLong(index, SmsDatabase.Types.BASE_INBOX_TYPE);
- } else {
- long theirType = cursor.getLong(columnIndex);
- statement.bindLong(index, SmsDatabase.Types.translateFromSystemBaseType(theirType));
- }
- }
-
- private static boolean isAppropriateTypeForMigration(Cursor cursor, int columnIndex) {
- long systemType = cursor.getLong(columnIndex);
- long ourType = SmsDatabase.Types.translateFromSystemBaseType(systemType);
-
- return ourType == MmsSmsColumns.Types.BASE_INBOX_TYPE ||
- ourType == MmsSmsColumns.Types.BASE_SENT_TYPE ||
- ourType == MmsSmsColumns.Types.BASE_SENT_FAILED_TYPE;
- }
-
- private static void getContentValuesForRow(Context context, Cursor cursor,
- long threadId, SQLiteStatement statement)
- {
- String theirAddress = cursor.getString(cursor.getColumnIndexOrThrow(SmsDatabase.ADDRESS));
- statement.bindString(1, Address.fromExternal(context, theirAddress).serialize());
-
- addIntToStatement(statement, cursor, 2, SmsDatabase.PERSON);
- addIntToStatement(statement, cursor, 3, SmsDatabase.DATE_RECEIVED);
- addIntToStatement(statement, cursor, 4, SmsDatabase.DATE_RECEIVED);
- addIntToStatement(statement, cursor, 5, SmsDatabase.PROTOCOL);
- addIntToStatement(statement, cursor, 6, SmsDatabase.READ);
- addIntToStatement(statement, cursor, 7, SmsDatabase.STATUS);
- addTranslatedTypeToStatement(statement, cursor, 8, SmsDatabase.TYPE);
- addIntToStatement(statement, cursor, 9, SmsDatabase.REPLY_PATH_PRESENT);
- addStringToStatement(statement, cursor, 10, SmsDatabase.SUBJECT);
- addStringToStatement(statement, cursor, 11, SmsDatabase.BODY);
- addStringToStatement(statement, cursor, 12, SmsDatabase.SERVICE_CENTER);
-
- statement.bindLong(13, threadId);
- }
-
- private static String getTheirCanonicalAddress(Context context, String theirRecipientId) {
- Uri uri = Uri.parse("content://mms-sms/canonical-address/" + theirRecipientId);
- Cursor cursor = null;
-
- try {
- cursor = context.getContentResolver().query(uri, null, null, null, null);
-
- if (cursor != null && cursor.moveToFirst()) {
- return cursor.getString(0);
- } else {
- return null;
- }
- } catch (IllegalStateException iae) {
- Log.w("SmsMigrator", iae);
- return null;
- } finally {
- if (cursor != null)
- cursor.close();
- }
- }
-
- private static @Nullable Set getOurRecipients(Context context, String theirRecipients) {
- StringTokenizer tokenizer = new StringTokenizer(theirRecipients.trim(), " ");
- Set recipientList = new HashSet<>();
-
- while (tokenizer.hasMoreTokens()) {
- String theirRecipientId = tokenizer.nextToken();
- String address = getTheirCanonicalAddress(context, theirRecipientId);
-
- if (address != null) {
- recipientList.add(Recipient.from(context, Address.fromExternal(context, address), true));
- }
- }
-
- if (recipientList.isEmpty()) return null;
- else return recipientList;
- }
-
- private static void migrateConversation(Context context, SmsMigrationProgressListener listener,
- ProgressDescription progress,
- long theirThreadId, long ourThreadId)
- {
- SmsDatabase ourSmsDatabase = DatabaseFactory.getSmsDatabase(context);
- Cursor cursor = null;
-
- try {
- Uri uri = Uri.parse("content://sms/conversations/" + theirThreadId);
-
- try {
- cursor = context.getContentResolver().query(uri, null, null, null, null);
- } catch (SQLiteException e) {
- /// Work around for weird sony-specific (?) bug: #4309
- Log.w(TAG, e);
- return;
- }
-
- SQLiteDatabase transaction = ourSmsDatabase.beginTransaction();
- SQLiteStatement statement = ourSmsDatabase.createInsertStatement(transaction);
-
- while (cursor != null && cursor.moveToNext()) {
- int typeColumn = cursor.getColumnIndex(SmsDatabase.TYPE);
-
- if (cursor.isNull(typeColumn) || isAppropriateTypeForMigration(cursor, typeColumn)) {
- getContentValuesForRow(context, cursor, ourThreadId, statement);
- statement.execute();
- }
-
- listener.progressUpdate(new ProgressDescription(progress, cursor.getCount(), cursor.getPosition()));
- }
-
- ourSmsDatabase.endTransaction(transaction);
- DatabaseFactory.getThreadDatabase(context).update(ourThreadId, true);
- DatabaseFactory.getThreadDatabase(context).notifyConversationListeners(ourThreadId);
-
- } finally {
- if (cursor != null)
- cursor.close();
- }
- }
-
- public static void migrateDatabase(Context context, SmsMigrationProgressListener listener)
- {
-// if (context.getSharedPreferences("SecureSMS", Context.MODE_PRIVATE).getBoolean("migrated", false))
-// return;
-
- ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(context);
- Cursor cursor = null;
-
- try {
- Uri threadListUri = Uri.parse("content://mms-sms/conversations?simple=true");
- cursor = context.getContentResolver().query(threadListUri, null, null, null, "date ASC");
-
- while (cursor != null && cursor.moveToNext()) {
- long theirThreadId = cursor.getLong(cursor.getColumnIndexOrThrow("_id"));
- String theirRecipients = cursor.getString(cursor.getColumnIndexOrThrow("recipient_ids"));
- Set ourRecipients = getOurRecipients(context, theirRecipients);
- ProgressDescription progress = new ProgressDescription(cursor.getCount(), cursor.getPosition(), 100, 0);
-
- if (ourRecipients != null) {
- if (ourRecipients.size() == 1) {
- long ourThreadId = threadDatabase.getThreadIdFor(ourRecipients.iterator().next());
- migrateConversation(context, listener, progress, theirThreadId, ourThreadId);
- } else if (ourRecipients.size() > 1) {
- ourRecipients.add(Recipient.from(context, Address.fromSerialized(TextSecurePreferences.getLocalNumber(context)), true));
-
- List memberAddresses = new LinkedList<>();
-
- for (Recipient recipient : ourRecipients) {
- memberAddresses.add(recipient.getAddress());
- }
-
- String ourGroupId = DatabaseFactory.getGroupDatabase(context).getOrCreateGroupForMembers(memberAddresses, true);
- Recipient ourGroupRecipient = Recipient.from(context, Address.fromSerialized(ourGroupId), true);
- long ourThreadId = threadDatabase.getThreadIdFor(ourGroupRecipient, ThreadDatabase.DistributionTypes.CONVERSATION);
-
- migrateConversation(context, listener, progress, theirThreadId, ourThreadId);
- }
- }
-
- progress.incrementPrimaryComplete();
- listener.progressUpdate(progress);
- }
- } finally {
- if (cursor != null)
- cursor.close();
- }
-
- context.getSharedPreferences("SecureSMS", Context.MODE_PRIVATE).edit()
- .putBoolean("migrated", true).apply();
- }
-
- public interface SmsMigrationProgressListener {
- void progressUpdate(ProgressDescription description);
- }
-
- public static class ProgressDescription {
- public final int primaryTotal;
- public int primaryComplete;
- public final int secondaryTotal;
- public final int secondaryComplete;
-
- ProgressDescription(int primaryTotal, int primaryComplete,
- int secondaryTotal, int secondaryComplete)
- {
- this.primaryTotal = primaryTotal;
- this.primaryComplete = primaryComplete;
- this.secondaryTotal = secondaryTotal;
- this.secondaryComplete = secondaryComplete;
- }
-
- ProgressDescription(ProgressDescription that, int secondaryTotal, int secondaryComplete) {
- this.primaryComplete = that.primaryComplete;
- this.primaryTotal = that.primaryTotal;
- this.secondaryComplete = secondaryComplete;
- this.secondaryTotal = secondaryTotal;
- }
-
- void incrementPrimaryComplete() {
- primaryComplete += 1;
- }
- }
-
-}
diff --git a/src/org/thoughtcrime/securesms/database/XmlBackup.java b/src/org/thoughtcrime/securesms/database/XmlBackup.java
deleted file mode 100644
index a206825a0..000000000
--- a/src/org/thoughtcrime/securesms/database/XmlBackup.java
+++ /dev/null
@@ -1,245 +0,0 @@
-package org.thoughtcrime.securesms.database;
-
-import android.text.TextUtils;
-
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-import org.xmlpull.v1.XmlPullParserFactory;
-
-import java.io.BufferedWriter;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.text.SimpleDateFormat;
-import java.util.Locale;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-public class XmlBackup {
-
- private static final String PROTOCOL = "protocol";
- private static final String ADDRESS = "address";
- private static final String CONTACT_NAME = "contact_name";
- private static final String DATE = "date";
- private static final String READABLE_DATE = "readable_date";
- private static final String TYPE = "type";
- private static final String SUBJECT = "subject";
- private static final String BODY = "body";
- private static final String SERVICE_CENTER = "service_center";
- private static final String READ = "read";
- private static final String STATUS = "status";
- private static final String TOA = "toa";
- private static final String SC_TOA = "sc_toa";
- private static final String LOCKED = "locked";
-
- private static final SimpleDateFormat dateFormatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z");
-
- private final XmlPullParser parser;
-
- public XmlBackup(String path) throws XmlPullParserException, FileNotFoundException {
- this.parser = XmlPullParserFactory.newInstance().newPullParser();
- parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
- parser.setInput(new FileInputStream(path), null);
- }
-
- public XmlBackupItem getNext() throws IOException, XmlPullParserException {
- while (parser.next() != XmlPullParser.END_DOCUMENT) {
- if (parser.getEventType() != XmlPullParser.START_TAG) {
- continue;
- }
-
- String name = parser.getName();
-
- if (!name.equalsIgnoreCase("sms")) {
- continue;
- }
-
- int attributeCount = parser.getAttributeCount();
-
- if (attributeCount <= 0) {
- continue;
- }
-
- XmlBackupItem item = new XmlBackupItem();
-
- for (int i=0;i";
- private static final String CREATED_BY = "";
- private static final String OPEN_TAG_SMSES = "";
- private static final String CLOSE_TAG_SMSES = "";
- private static final String OPEN_TAG_SMS = " void appendAttribute(StringBuilder stringBuilder, String name, T value) {
- stringBuilder.append(name).append(OPEN_ATTRIBUTE).append(value).append(CLOSE_ATTRIBUTE);
- }
-
- public void close() throws IOException {
- bufferedWriter.newLine();
- bufferedWriter.write(CLOSE_TAG_SMSES);
- bufferedWriter.close();
- }
-
- private String escapeXML(String s) {
- if (TextUtils.isEmpty(s)) return s;
-
- Matcher matcher = PATTERN.matcher( s.replace("&", "&")
- .replace("<", "<")
- .replace(">", ">")
- .replace("\"", """)
- .replace("'", "'"));
- StringBuffer st = new StringBuffer();
-
- while (matcher.find()) {
- String escaped="";
- for (char ch: matcher.group(0).toCharArray()) {
- escaped += ("" + ((int) ch) + ";");
- }
- matcher.appendReplacement(st, escaped);
- }
- matcher.appendTail(st);
- return st.toString();
- }
-
- }
-}
diff --git a/src/org/thoughtcrime/securesms/jobs/requirements/NetworkOrServiceRequirement.java b/src/org/thoughtcrime/securesms/jobs/requirements/NetworkOrServiceRequirement.java
deleted file mode 100644
index 5dcf686b5..000000000
--- a/src/org/thoughtcrime/securesms/jobs/requirements/NetworkOrServiceRequirement.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package org.thoughtcrime.securesms.jobs.requirements;
-
-import android.content.Context;
-
-import org.thoughtcrime.securesms.jobmanager.dependencies.ContextDependent;
-import org.thoughtcrime.securesms.jobmanager.requirements.NetworkRequirement;
-import org.thoughtcrime.securesms.jobmanager.requirements.Requirement;
-import org.thoughtcrime.securesms.jobmanager.requirements.SimpleRequirement;
-
-public class NetworkOrServiceRequirement extends SimpleRequirement implements ContextDependent {
-
- private transient Context context;
-
- public NetworkOrServiceRequirement(Context context) {
- this.context = context;
- }
-
- @Override
- public void setContext(Context context) {
- this.context = context;
- }
-
- @Override
- public boolean isPresent() {
- NetworkRequirement networkRequirement = new NetworkRequirement(context);
- ServiceRequirement serviceRequirement = new ServiceRequirement(context);
-
- return networkRequirement.isPresent() || serviceRequirement.isPresent();
- }
-}
diff --git a/src/org/thoughtcrime/securesms/jobs/requirements/ServiceRequirement.java b/src/org/thoughtcrime/securesms/jobs/requirements/ServiceRequirement.java
deleted file mode 100644
index 49a0368c5..000000000
--- a/src/org/thoughtcrime/securesms/jobs/requirements/ServiceRequirement.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package org.thoughtcrime.securesms.jobs.requirements;
-
-import android.content.Context;
-
-import org.thoughtcrime.securesms.jobmanager.dependencies.ContextDependent;
-import org.thoughtcrime.securesms.jobmanager.requirements.Requirement;
-import org.thoughtcrime.securesms.jobmanager.requirements.SimpleRequirement;
-import org.thoughtcrime.securesms.sms.TelephonyServiceState;
-
-public class ServiceRequirement extends SimpleRequirement implements ContextDependent {
-
- private static final String TAG = ServiceRequirement.class.getSimpleName();
-
- private transient Context context;
-
- public ServiceRequirement(Context context) {
- this.context = context;
- }
-
- @Override
- public void setContext(Context context) {
- this.context = context;
- }
-
- @Override
- public boolean isPresent() {
- TelephonyServiceState telephonyServiceState = new TelephonyServiceState();
- return telephonyServiceState.isConnected(context);
- }
-}
diff --git a/src/org/thoughtcrime/securesms/jobs/requirements/ServiceRequirementProvider.java b/src/org/thoughtcrime/securesms/jobs/requirements/ServiceRequirementProvider.java
deleted file mode 100644
index 4b7ccd08a..000000000
--- a/src/org/thoughtcrime/securesms/jobs/requirements/ServiceRequirementProvider.java
+++ /dev/null
@@ -1,56 +0,0 @@
-package org.thoughtcrime.securesms.jobs.requirements;
-
-import android.content.Context;
-import android.telephony.PhoneStateListener;
-import android.telephony.ServiceState;
-import android.telephony.TelephonyManager;
-
-import org.thoughtcrime.securesms.jobmanager.requirements.RequirementListener;
-import org.thoughtcrime.securesms.jobmanager.requirements.RequirementProvider;
-
-import java.util.concurrent.atomic.AtomicBoolean;
-
-public class ServiceRequirementProvider implements RequirementProvider {
-
- private final TelephonyManager telephonyManager;
- private final ServiceStateListener serviceStateListener;
- private final AtomicBoolean listeningForServiceState;
-
- private RequirementListener requirementListener;
-
- public ServiceRequirementProvider(Context context) {
- this.telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
- this.serviceStateListener = new ServiceStateListener();
- this.listeningForServiceState = new AtomicBoolean(false);
- }
-
- @Override
- public void setListener(RequirementListener requirementListener) {
- this.requirementListener = requirementListener;
- }
-
- public void start() {
- if (listeningForServiceState.compareAndSet(false, true)) {
- this.telephonyManager.listen(serviceStateListener, PhoneStateListener.LISTEN_SERVICE_STATE);
- }
- }
-
- private void handleInService() {
- if (listeningForServiceState.compareAndSet(true, false)) {
- this.telephonyManager.listen(serviceStateListener, PhoneStateListener.LISTEN_NONE);
- }
-
- if (requirementListener != null) {
- requirementListener.onRequirementStatusChanged();
- }
- }
-
- private class ServiceStateListener extends PhoneStateListener {
- @Override
- public void onServiceStateChanged(ServiceState serviceState) {
- if (serviceState.getState() == ServiceState.STATE_IN_SERVICE) {
- handleInService();
- }
- }
- }
-}
diff --git a/src/org/thoughtcrime/securesms/service/ApplicationMigrationService.java b/src/org/thoughtcrime/securesms/service/ApplicationMigrationService.java
deleted file mode 100644
index 64f67bf53..000000000
--- a/src/org/thoughtcrime/securesms/service/ApplicationMigrationService.java
+++ /dev/null
@@ -1,219 +0,0 @@
-package org.thoughtcrime.securesms.service;
-
-import android.app.Notification;
-import android.app.NotificationManager;
-import android.app.PendingIntent;
-import android.app.Service;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.graphics.BitmapFactory;
-import android.os.Binder;
-import android.os.Handler;
-import android.os.IBinder;
-import android.os.PowerManager;
-import android.os.PowerManager.WakeLock;
-import android.support.v4.app.NotificationCompat;
-
-import org.thoughtcrime.securesms.ConversationListActivity;
-import org.thoughtcrime.securesms.R;
-import org.thoughtcrime.securesms.database.SmsMigrator;
-import org.thoughtcrime.securesms.database.SmsMigrator.ProgressDescription;
-
-import java.lang.ref.WeakReference;
-import java.util.concurrent.Executor;
-import java.util.concurrent.Executors;
-
-// FIXME: This class is nuts.
-public class ApplicationMigrationService extends Service
- implements SmsMigrator.SmsMigrationProgressListener
-{
- private static final String TAG = ApplicationMigrationService.class.getSimpleName();
- public static final String MIGRATE_DATABASE = "org.thoughtcrime.securesms.ApplicationMigration.MIGRATE_DATABSE";
- public static final String COMPLETED_ACTION = "org.thoughtcrime.securesms.ApplicationMigrationService.COMPLETED";
- private static final String PREFERENCES_NAME = "SecureSMS";
- private static final String DATABASE_MIGRATED = "migrated";
-
- private final BroadcastReceiver completedReceiver = new CompletedReceiver();
- private final Binder binder = new ApplicationMigrationBinder();
- private final Executor executor = Executors.newSingleThreadExecutor();
-
- private WeakReference handler = null;
- private NotificationCompat.Builder notification = null;
- private ImportState state = new ImportState(ImportState.STATE_IDLE, null);
-
- @Override
- public void onCreate() {
- registerCompletedReceiver();
- }
-
- @Override
- public int onStartCommand(Intent intent, int flags, int startId) {
- if (intent == null) return START_NOT_STICKY;
-
- if (intent.getAction() != null && intent.getAction().equals(MIGRATE_DATABASE)) {
- executor.execute(new ImportRunnable());
- }
-
- return START_NOT_STICKY;
- }
-
- @Override
- public void onDestroy() {
- unregisterCompletedReceiver();
- }
-
- @Override
- public IBinder onBind(Intent intent) {
- return binder;
- }
-
- public void setImportStateHandler(Handler handler) {
- this.handler = new WeakReference<>(handler);
- }
-
- private void registerCompletedReceiver() {
- IntentFilter filter = new IntentFilter();
- filter.addAction(COMPLETED_ACTION);
-
- registerReceiver(completedReceiver, filter);
- }
-
- private void unregisterCompletedReceiver() {
- unregisterReceiver(completedReceiver);
- }
-
- private void notifyImportComplete() {
- Intent intent = new Intent();
- intent.setAction(COMPLETED_ACTION);
-
- sendOrderedBroadcast(intent, null);
- }
-
- @Override
- public void progressUpdate(ProgressDescription progress) {
- setState(new ImportState(ImportState.STATE_MIGRATING_IN_PROGRESS, progress));
- }
-
- public ImportState getState() {
- return state;
- }
-
- private void setState(ImportState state) {
- this.state = state;
-
- if (this.handler != null) {
- Handler handler = this.handler.get();
-
- if (handler != null) {
- handler.obtainMessage(state.state, state.progress).sendToTarget();
- }
- }
-
- if (state.progress != null && state.progress.secondaryComplete == 0) {
- updateBackgroundNotification(state.progress.primaryTotal, state.progress.primaryComplete);
- }
- }
-
- private void updateBackgroundNotification(int total, int complete) {
- notification.setProgress(total, complete, false);
-
- ((NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE))
- .notify(4242, notification.build());
- }
-
- private NotificationCompat.Builder initializeBackgroundNotification() {
- NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
-
- builder.setSmallIcon(R.drawable.icon_notification);
- builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.icon_notification));
- builder.setContentTitle(getString(R.string.ApplicationMigrationService_importing_text_messages));
- builder.setContentText(getString(R.string.ApplicationMigrationService_import_in_progress));
- builder.setOngoing(true);
- builder.setProgress(100, 0, false);
- builder.setContentIntent(PendingIntent.getActivity(this, 0, new Intent(this, ConversationListActivity.class), 0));
-
- stopForeground(true);
- startForeground(4242, builder.build());
-
- return builder;
- }
-
- private class ImportRunnable implements Runnable {
-
- ImportRunnable() {}
-
- @Override
- public void run() {
- notification = initializeBackgroundNotification();
- PowerManager powerManager = (PowerManager)getSystemService(Context.POWER_SERVICE);
- WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Migration");
-
- try {
- wakeLock.acquire();
-
- setState(new ImportState(ImportState.STATE_MIGRATING_BEGIN, null));
-
- SmsMigrator.migrateDatabase(ApplicationMigrationService.this,
- ApplicationMigrationService.this);
-
- setState(new ImportState(ImportState.STATE_MIGRATING_COMPLETE, null));
-
- setDatabaseImported(ApplicationMigrationService.this);
- stopForeground(true);
- notifyImportComplete();
- stopSelf();
- } finally {
- wakeLock.release();
- }
- }
- }
-
- public class ApplicationMigrationBinder extends Binder {
- public ApplicationMigrationService getService() {
- return ApplicationMigrationService.this;
- }
- }
-
- private static class CompletedReceiver extends BroadcastReceiver {
- @Override
- public void onReceive(Context context, Intent intent) {
- NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
- builder.setSmallIcon(R.drawable.icon_notification);
- builder.setContentTitle(context.getString(R.string.ApplicationMigrationService_import_complete));
- builder.setContentText(context.getString(R.string.ApplicationMigrationService_system_database_import_is_complete));
- builder.setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, ConversationListActivity.class), 0));
- builder.setWhen(System.currentTimeMillis());
- builder.setDefaults(Notification.DEFAULT_VIBRATE);
- builder.setAutoCancel(true);
-
- Notification notification = builder.build();
- ((NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(31337, notification);
- }
- }
-
- public static class ImportState {
- public static final int STATE_IDLE = 0;
- public static final int STATE_MIGRATING_BEGIN = 1;
- public static final int STATE_MIGRATING_IN_PROGRESS = 2;
- public static final int STATE_MIGRATING_COMPLETE = 3;
-
- public int state;
- public ProgressDescription progress;
-
- public ImportState(int state, ProgressDescription progress) {
- this.state = state;
- this.progress = progress;
- }
- }
-
- public static boolean isDatabaseImported(Context context) {
- return context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_PRIVATE)
- .getBoolean(DATABASE_MIGRATED, false);
- }
-
- public static void setDatabaseImported(Context context) {
- context.getSharedPreferences(PREFERENCES_NAME, 0).edit().putBoolean(DATABASE_MIGRATED, true).apply();
- }
-}
diff --git a/src/org/thoughtcrime/securesms/service/SmsListener.java b/src/org/thoughtcrime/securesms/service/SmsListener.java
deleted file mode 100644
index b2535f282..000000000
--- a/src/org/thoughtcrime/securesms/service/SmsListener.java
+++ /dev/null
@@ -1,167 +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.service;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.os.Build;
-import android.os.Bundle;
-import android.provider.Telephony;
-import android.support.annotation.NonNull;
-import android.support.annotation.Nullable;
-import android.support.annotation.VisibleForTesting;
-import android.telephony.SmsMessage;
-import android.util.Log;
-
-import org.thoughtcrime.securesms.ApplicationContext;
-import org.thoughtcrime.securesms.RegistrationActivity;
-import org.thoughtcrime.securesms.jobs.SmsReceiveJob;
-import org.thoughtcrime.securesms.util.TextSecurePreferences;
-import org.thoughtcrime.securesms.util.Util;
-
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-public class SmsListener extends BroadcastReceiver {
-
- private static final String SMS_RECEIVED_ACTION = Telephony.Sms.Intents.SMS_RECEIVED_ACTION;
- private static final String SMS_DELIVERED_ACTION = Telephony.Sms.Intents.SMS_DELIVER_ACTION;
-
- private static final Pattern CHALLENGE_PATTERN = Pattern.compile(".*Your (Signal|TextSecure) verification code:? ([0-9]{3,4})-([0-9]{3,4}).*", Pattern.DOTALL);
-
- private boolean isExemption(SmsMessage message, String messageBody) {
-
- // ignore CLASS0 ("flash") messages
- if (message.getMessageClass() == SmsMessage.MessageClass.CLASS_0)
- return true;
-
- // ignore OTP messages from Sparebank1 (Norwegian bank)
- if (messageBody.startsWith("Sparebank1://otp?")) {
- return true;
- }
-
- return
- message.getOriginatingAddress().length() < 7 &&
- (messageBody.toUpperCase().startsWith("//ANDROID:") || // Sprint Visual Voicemail
- messageBody.startsWith("//BREW:")); //BREW stands for “Binary Runtime Environment for Wireless"
- }
-
- private SmsMessage getSmsMessageFromIntent(Intent intent) {
- Bundle bundle = intent.getExtras();
- Object[] pdus = (Object[])bundle.get("pdus");
-
- if (pdus == null || pdus.length == 0)
- return null;
-
- return SmsMessage.createFromPdu((byte[])pdus[0]);
- }
-
- private String getSmsMessageBodyFromIntent(Intent intent) {
- Bundle bundle = intent.getExtras();
- Object[] pdus = (Object[])bundle.get("pdus");
- StringBuilder bodyBuilder = new StringBuilder();
-
- if (pdus == null)
- return null;
-
- for (Object pdu : pdus)
- bodyBuilder.append(SmsMessage.createFromPdu((byte[])pdu).getDisplayMessageBody());
-
- return bodyBuilder.toString();
- }
-
- private boolean isRelevant(Context context, Intent intent) {
- SmsMessage message = getSmsMessageFromIntent(intent);
- String messageBody = getSmsMessageBodyFromIntent(intent);
-
- if (message == null && messageBody == null)
- return false;
-
- if (isExemption(message, messageBody))
- return false;
-
- if (!ApplicationMigrationService.isDatabaseImported(context))
- return false;
-
- if (isChallenge(context, messageBody))
- return false;
-
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT &&
- SMS_RECEIVED_ACTION.equals(intent.getAction()) &&
- Util.isDefaultSmsProvider(context))
- {
- return false;
- }
-
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT &&
- TextSecurePreferences.isInterceptAllSmsEnabled(context))
- {
- return true;
- }
-
- return false;
- }
-
- @VisibleForTesting boolean isChallenge(@NonNull Context context, @Nullable String messageBody) {
- if (messageBody == null)
- return false;
-
- if (CHALLENGE_PATTERN.matcher(messageBody).matches() &&
- TextSecurePreferences.isVerifying(context))
- {
- return true;
- }
-
- return false;
- }
-
- @VisibleForTesting String parseChallenge(String messageBody) {
- Matcher challengeMatcher = CHALLENGE_PATTERN.matcher(messageBody);
-
- if (!challengeMatcher.matches()) {
- throw new AssertionError("Expression should match.");
- }
-
- return challengeMatcher.group(2) + challengeMatcher.group(3);
- }
-
- @Override
- public void onReceive(Context context, Intent intent) {
- Log.w("SMSListener", "Got SMS broadcast...");
-
- String messageBody = getSmsMessageBodyFromIntent(intent);
- if (SMS_RECEIVED_ACTION.equals(intent.getAction()) && isChallenge(context, messageBody)) {
- Log.w("SmsListener", "Got challenge!");
- Intent challengeIntent = new Intent(RegistrationActivity.CHALLENGE_EVENT);
- challengeIntent.putExtra(RegistrationActivity.CHALLENGE_EXTRA, parseChallenge(messageBody));
- context.sendBroadcast(challengeIntent);
-
- abortBroadcast();
- } else if ((intent.getAction().equals(SMS_DELIVERED_ACTION)) ||
- (intent.getAction().equals(SMS_RECEIVED_ACTION)) && isRelevant(context, intent))
- {
- Log.w("SmsListener", "Constructing SmsReceiveJob...");
- Object[] pdus = (Object[]) intent.getExtras().get("pdus");
- int subscriptionId = intent.getExtras().getInt("subscription", -1);
-
- ApplicationContext.getInstance(context).getJobManager().add(new SmsReceiveJob(context, pdus, subscriptionId));
-
- abortBroadcast();
- }
- }
-}
diff --git a/src/org/thoughtcrime/securesms/sms/TelephonyServiceState.java b/src/org/thoughtcrime/securesms/sms/TelephonyServiceState.java
deleted file mode 100644
index b6cb7e5e2..000000000
--- a/src/org/thoughtcrime/securesms/sms/TelephonyServiceState.java
+++ /dev/null
@@ -1,92 +0,0 @@
-package org.thoughtcrime.securesms.sms;
-
-import android.content.Context;
-import android.os.Looper;
-import android.telephony.PhoneStateListener;
-import android.telephony.ServiceState;
-import android.telephony.TelephonyManager;
-
-public class TelephonyServiceState {
-
- public boolean isConnected(Context context) {
- ListenThread listenThread = new ListenThread(context);
- listenThread.start();
-
- return listenThread.get();
- }
-
- private static class ListenThread extends Thread {
-
- private final Context context;
-
- private boolean complete;
- private boolean result;
-
- public ListenThread(Context context) {
- this.context = context.getApplicationContext();
- }
-
- @Override
- public void run() {
- Looper looper = initializeLooper();
- ListenCallback callback = new ListenCallback(looper);
-
- TelephonyManager telephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
- telephonyManager.listen(callback, PhoneStateListener.LISTEN_SERVICE_STATE);
-
- Looper.loop();
-
- telephonyManager.listen(callback, PhoneStateListener.LISTEN_NONE);
-
- set(callback.isConnected());
- }
-
- private Looper initializeLooper() {
- Looper looper = Looper.myLooper();
-
- if (looper == null) {
- Looper.prepare();
- }
-
- return Looper.myLooper();
- }
-
- public synchronized boolean get() {
- while (!complete) {
- try {
- wait();
- } catch (InterruptedException e) {
- throw new AssertionError(e);
- }
- }
-
- return result;
- }
-
- private synchronized void set(boolean result) {
- this.result = result;
- this.complete = true;
- notifyAll();
- }
- }
-
- private static class ListenCallback extends PhoneStateListener {
-
- private final Looper looper;
- private volatile boolean connected;
-
- public ListenCallback(Looper looper) {
- this.looper = looper;
- }
-
- @Override
- public void onServiceStateChanged(ServiceState serviceState) {
- this.connected = (serviceState.getState() == ServiceState.STATE_IN_SERVICE);
- looper.quit();
- }
-
- public boolean isConnected() {
- return connected;
- }
- }
-}
diff --git a/src/org/thoughtcrime/securesms/util/ShortCodeUtil.java b/src/org/thoughtcrime/securesms/util/ShortCodeUtil.java
deleted file mode 100644
index 4a4aec614..000000000
--- a/src/org/thoughtcrime/securesms/util/ShortCodeUtil.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package org.thoughtcrime.securesms.util;
-
-import android.support.annotation.NonNull;
-import android.util.Log;
-
-import com.google.i18n.phonenumbers.NumberParseException;
-import com.google.i18n.phonenumbers.PhoneNumberUtil;
-import com.google.i18n.phonenumbers.Phonenumber;
-import com.google.i18n.phonenumbers.ShortNumberInfo;
-
-import java.util.HashSet;
-import java.util.Set;
-
-public class ShortCodeUtil {
-
- private static final String TAG = ShortCodeUtil.class.getSimpleName();
-
- private static final Set SHORT_COUNTRIES = new HashSet() {{
- add("NU");
- add("TK");
- add("NC");
- add("AC");
- }};
-
- public static boolean isShortCode(@NonNull String localNumber, @NonNull String number) {
- try {
- PhoneNumberUtil util = PhoneNumberUtil.getInstance();
- Phonenumber.PhoneNumber localNumberObject = util.parse(localNumber, null);
- String localCountryCode = util.getRegionCodeForNumber(localNumberObject);
- String bareNumber = number.replaceAll("[^0-9+]", "");
-
- // libphonenumber seems incorrect for Russia and a few other countries with 4 digit short codes.
- if (bareNumber.length() <= 4 && !SHORT_COUNTRIES.contains(localCountryCode)) {
- return true;
- }
-
- Phonenumber.PhoneNumber shortCode = util.parse(number, localCountryCode);
- return ShortNumberInfo.getInstance().isPossibleShortNumberForRegion(shortCode, localCountryCode);
- } catch (NumberParseException e) {
- Log.w(TAG, e);
- return false;
- }
- }
-
-}
diff --git a/src/org/thoughtcrime/securesms/util/TelephonyUtil.java b/src/org/thoughtcrime/securesms/util/TelephonyUtil.java
deleted file mode 100644
index 5d172ea08..000000000
--- a/src/org/thoughtcrime/securesms/util/TelephonyUtil.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package org.thoughtcrime.securesms.util;
-
-import android.content.Context;
-import android.content.res.Configuration;
-import android.net.ConnectivityManager;
-import android.telephony.TelephonyManager;
-import android.util.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.w(TAG, "Choosing MCC+MNC info from TelephonyManager.getSimOperator()");
- return tm.getSimOperator();
- } else if (tm.getPhoneType() != TelephonyManager.PHONE_TYPE_CDMA) {
- Log.w(TAG, "Choosing MCC+MNC info from TelephonyManager.getNetworkOperator()");
- return tm.getNetworkOperator();
- } else if (configMcc != 0 && configMnc != 0) {
- Log.w(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();
- }
-}