Catch ActivityNotFoundExceptions

Fixes #3726
Closes #5617
// FREEBIE
This commit is contained in:
FeuRenard 2016-08-14 12:23:51 +02:00 committed by Moxie Marlinspike
parent db10e5fec6
commit 5bf1707d60
6 changed files with 47 additions and 7 deletions

View File

@ -147,6 +147,7 @@
<string name="ConversationActivity_quick_camera_unavailable">Camera unavailable</string> <string name="ConversationActivity_quick_camera_unavailable">Camera unavailable</string>
<string name="ConversationActivity_unable_to_record_audio">Unable to record audio!</string> <string name="ConversationActivity_unable_to_record_audio">Unable to record audio!</string>
<string name="ConversationActivity_error_sending_voice_message">Error sending voice message...</string> <string name="ConversationActivity_error_sending_voice_message">Error sending voice message...</string>
<string name="ConversationActivity_there_is_no_app_available_to_handle_this_link_on_your_device">There is no app available to handle this link on your device.</string>
<!-- ConversationFragment --> <!-- ConversationFragment -->
<string name="ConversationFragment_message_details">Message details</string> <string name="ConversationFragment_message_details">Message details</string>
@ -189,6 +190,7 @@
<!-- ConversationListActivity --> <!-- ConversationListActivity -->
<string name="ConversationListActivity_search">Search...</string> <string name="ConversationListActivity_search">Search...</string>
<string name="ConversationListActivity_there_is_no_browser_installed_on_your_device">There is no browser installed on your device.</string>
<!-- ConversationListFragment --> <!-- ConversationListFragment -->
<plurals name="ConversationListFragment_delete_selected_conversations"> <plurals name="ConversationListFragment_delete_selected_conversations">
@ -429,6 +431,7 @@
<string name="RatingManager_rate_now">Rate now!</string> <string name="RatingManager_rate_now">Rate now!</string>
<string name="RatingManager_no_thanks">No thanks</string> <string name="RatingManager_no_thanks">No thanks</string>
<string name="RatingManager_later">Later</string> <string name="RatingManager_later">Later</string>
<string name="RatingManager_whoops_the_play_store_app_does_not_appear_to_be_installed">Whoops, the Play Store app does not appear to be installed on your device.</string>
<!-- RecipientPreferencesActivity --> <!-- RecipientPreferencesActivity -->
<string name="RecipientPreferenceActivity_block_this_contact_question">Block this contact?</string> <string name="RecipientPreferenceActivity_block_this_contact_question">Block this contact?</string>
@ -766,6 +769,7 @@
<string name="log_submit_activity__thanks">Thanks for your help!</string> <string name="log_submit_activity__thanks">Thanks for your help!</string>
<string name="log_submit_activity__submitting">Submitting</string> <string name="log_submit_activity__submitting">Submitting</string>
<string name="log_submit_activity__posting_logs">Posting logs to gist&#8230;</string> <string name="log_submit_activity__posting_logs">Posting logs to gist&#8230;</string>
<string name="log_submit_activity__no_browser_installed">No browser installed</string>
<!-- database_migration_activity --> <!-- database_migration_activity -->
<string name="database_migration_activity__would_you_like_to_import_your_existing_text_messages">Would you like to import your existing text messages into Signal\'s encrypted database?</string> <string name="database_migration_activity__would_you_like_to_import_your_existing_text_messages">Would you like to import your existing text messages into Signal\'s encrypted database?</string>

View File

@ -36,7 +36,6 @@ import android.os.Vibrator;
import android.provider.Browser; import android.provider.Browser;
import android.provider.ContactsContract; import android.provider.ContactsContract;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v4.view.MenuItemCompat;
import android.support.v4.view.WindowCompat; import android.support.v4.view.WindowCompat;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.text.Editable; import android.text.Editable;
@ -128,7 +127,6 @@ import org.thoughtcrime.securesms.util.DirectoryHelper.UserCapabilities;
import org.thoughtcrime.securesms.util.DirectoryHelper.UserCapabilities.Capability; import org.thoughtcrime.securesms.util.DirectoryHelper.UserCapabilities.Capability;
import org.thoughtcrime.securesms.util.DynamicLanguage; import org.thoughtcrime.securesms.util.DynamicLanguage;
import org.thoughtcrime.securesms.util.DynamicTheme; import org.thoughtcrime.securesms.util.DynamicTheme;
import org.thoughtcrime.securesms.util.ExpirationUtil;
import org.thoughtcrime.securesms.util.GroupUtil; import org.thoughtcrime.securesms.util.GroupUtil;
import org.thoughtcrime.securesms.util.MediaUtil; import org.thoughtcrime.securesms.util.MediaUtil;
import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.thoughtcrime.securesms.util.TextSecurePreferences;
@ -375,7 +373,13 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
if (intent.getStringExtra(Browser.EXTRA_APPLICATION_ID) != null) { if (intent.getStringExtra(Browser.EXTRA_APPLICATION_ID) != null) {
intent.removeExtra(Browser.EXTRA_APPLICATION_ID); intent.removeExtra(Browser.EXTRA_APPLICATION_ID);
} }
super.startActivity(intent);
try {
super.startActivity(intent);
} catch (ActivityNotFoundException e) {
Log.w(TAG, e);
Toast.makeText(this, R.string.ConversationActivity_there_is_no_app_available_to_handle_this_link_on_your_device, Toast.LENGTH_LONG).show();
}
} }
@Override @Override

View File

@ -16,6 +16,7 @@
*/ */
package org.thoughtcrime.securesms; package org.thoughtcrime.securesms;
import android.content.ActivityNotFoundException;
import android.content.Intent; import android.content.Intent;
import android.database.ContentObserver; import android.database.ContentObserver;
import android.net.Uri; import android.net.Uri;
@ -30,6 +31,7 @@ import android.support.v7.widget.SearchView;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.widget.Toast;
import org.thoughtcrime.securesms.components.RatingManager; import org.thoughtcrime.securesms.components.RatingManager;
import org.thoughtcrime.securesms.crypto.MasterSecret; import org.thoughtcrime.securesms.crypto.MasterSecret;
@ -212,7 +214,11 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
} }
private void handleHelp() { private void handleHelp() {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://support.whispersystems.org"))); try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://support.whispersystems.org")));
} catch (ActivityNotFoundException e) {
Toast.makeText(this, R.string.ConversationListActivity_there_is_no_browser_installed_on_your_device, Toast.LENGTH_LONG).show();
}
} }
private void initializeContactUpdatesReceiver() { private void initializeContactUpdatesReceiver() {

View File

@ -1,8 +1,11 @@
package org.thoughtcrime.securesms; package org.thoughtcrime.securesms;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.MenuItem; import android.view.MenuItem;
import android.widget.Toast; import android.widget.Toast;
@ -58,4 +61,14 @@ public class LogSubmitActivity extends BaseActionBarActivity implements SubmitLo
public void onCancel() { public void onCancel() {
finish(); finish();
} }
@Override
public void startActivity(Intent intent) {
try {
super.startActivity(intent);
} catch (ActivityNotFoundException e) {
Log.w(TAG, e);
Toast.makeText(this, R.string.log_submit_activity__no_browser_installed, Toast.LENGTH_LONG).show();
}
}
} }

View File

@ -1,5 +1,6 @@
package org.thoughtcrime.securesms; package org.thoughtcrime.securesms;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
@ -41,6 +42,7 @@ import org.whispersystems.signalservice.api.util.PhoneNumberFormatter;
public class RegistrationActivity extends BaseActionBarActivity { public class RegistrationActivity extends BaseActionBarActivity {
private static final int PICK_COUNTRY = 1; private static final int PICK_COUNTRY = 1;
private static final String TAG = RegistrationActivity.class.getSimpleName();
private AsYouTypeFormatter countryFormatter; private AsYouTypeFormatter countryFormatter;
private ArrayAdapter<String> countrySpinnerAdapter; private ArrayAdapter<String> countrySpinnerAdapter;
@ -99,7 +101,11 @@ public class RegistrationActivity extends BaseActionBarActivity {
intent.setAction(Intent.ACTION_VIEW); intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE); intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setData(Uri.parse("https://twilio.com")); intent.setData(Uri.parse("https://twilio.com"));
startActivity(intent); try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
Log.w(TAG,e);
}
} }
}); });
} }
@ -154,7 +160,7 @@ public class RegistrationActivity extends BaseActionBarActivity {
} }
} }
} catch (NumberParseException npe) { } catch (NumberParseException npe) {
Log.w("CreateAccountActivity", npe); Log.w(TAG, npe);
} }
} }

View File

@ -1,5 +1,6 @@
package org.thoughtcrime.securesms.components; package org.thoughtcrime.securesms.components;
import android.content.ActivityNotFoundException;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
@ -7,6 +8,7 @@ import android.content.pm.PackageManager;
import android.net.Uri; import android.net.Uri;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.util.Log; import android.util.Log;
import android.widget.Toast;
import org.thoughtcrime.securesms.R; import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.thoughtcrime.securesms.util.TextSecurePreferences;
@ -62,7 +64,12 @@ public class RatingManager {
private static void startPlayStore(Context context) { private static void startPlayStore(Context context) {
Uri uri = Uri.parse("market://details?id=" + context.getPackageName()); Uri uri = Uri.parse("market://details?id=" + context.getPackageName());
context.startActivity(new Intent(Intent.ACTION_VIEW, uri)); try {
context.startActivity(new Intent(Intent.ACTION_VIEW, uri));
} catch (ActivityNotFoundException e) {
Log.w(TAG, e);
Toast.makeText(context, R.string.RatingManager_whoops_the_play_store_app_does_not_appear_to_be_installed, Toast.LENGTH_LONG).show();
}
} }
private static long getDaysSinceInstalled(Context context) { private static long getDaysSinceInstalled(Context context) {