summaryrefslogtreecommitdiff
path: root/src/com/android/dialer
diff options
context:
space:
mode:
authorYorke Lee <yorkelee@google.com>2014-04-07 15:39:48 -0700
committerYorke Lee <yorkelee@google.com>2014-04-07 15:39:48 -0700
commit3921359f3f01938768f0b0e731941542f0385787 (patch)
treec8265ba2f31618b1ec5bb764ef374545c2b43347 /src/com/android/dialer
parentea8fa952d9024a136a401b5c1cf6a546c870d81f (diff)
Catch activity not found exceptions
Instead of crashing when an ActivityNotFoundException is thrown, display an error toast. Bug: 13882939 Change-Id: I5cda14ba8a404ff0f5196fdbc382201c47f4b4c8
Diffstat (limited to 'src/com/android/dialer')
-rw-r--r--src/com/android/dialer/CallDetailActivity.java25
-rw-r--r--src/com/android/dialer/util/DialerUtils.java57
2 files changed, 70 insertions, 12 deletions
diff --git a/src/com/android/dialer/CallDetailActivity.java b/src/com/android/dialer/CallDetailActivity.java
index e09e6f302..470c0b668 100644
--- a/src/com/android/dialer/CallDetailActivity.java
+++ b/src/com/android/dialer/CallDetailActivity.java
@@ -72,6 +72,7 @@ import com.android.dialer.calllog.PhoneNumberDisplayHelper;
import com.android.dialer.calllog.PhoneNumberUtilsWrapper;
import com.android.dialer.util.AsyncTaskExecutor;
import com.android.dialer.util.AsyncTaskExecutors;
+import com.android.dialer.util.DialerUtils;
import com.android.dialer.voicemail.VoicemailPlaybackFragment;
import com.android.dialer.voicemail.VoicemailStatusHelper;
import com.android.dialer.voicemail.VoicemailStatusHelper.StatusMessage;
@@ -237,7 +238,8 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware
if (finishPhoneNumerSelectedActionModeIfShown()) {
return;
}
- startActivity(((ViewEntry) view.getTag()).primaryIntent);
+ DialerUtils.startActivityWithErrorToast(CallDetailActivity.this,
+ ((ViewEntry) view.getTag()).primaryIntent);
}
};
@@ -247,7 +249,8 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware
if (finishPhoneNumerSelectedActionModeIfShown()) {
return;
}
- startActivity(((ViewEntry) view.getTag()).secondaryIntent);
+ DialerUtils.startActivityWithErrorToast(CallDetailActivity.this,
+ ((ViewEntry) view.getTag()).secondaryIntent);
}
};
@@ -416,8 +419,10 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware
TelephonyManager tm = (TelephonyManager)
getSystemService(Context.TELEPHONY_SERVICE);
if (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) {
- startActivity(CallUtil.getCallIntent(
- Uri.fromParts(CallUtil.SCHEME_TEL, mNumber, null)));
+ DialerUtils.startActivityWithErrorToast(this,
+ CallUtil.getCallIntent(Uri.fromParts(CallUtil.SCHEME_TEL, mNumber,
+ null)),
+ R.string.call_not_available);
return true;
}
}
@@ -659,13 +664,8 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware
mMainActionPushLayerView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- try {
- startActivity(actionIntent);
- } catch (ActivityNotFoundException e) {
- final Toast toast = Toast.makeText(CallDetailActivity.this,
- R.string.add_contact_not_available, Toast.LENGTH_SHORT);
- toast.show();
- }
+ DialerUtils.startActivityWithErrorToast(CallDetailActivity.this, actionIntent,
+ R.string.add_contact_not_available);
}
});
mMainActionPushLayerView.setContentDescription(actionDescription);
@@ -840,7 +840,8 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware
mStatusMessageAction.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- startActivity(new Intent(Intent.ACTION_VIEW, message.actionUri));
+ DialerUtils.startActivityWithErrorToast(CallDetailActivity.this,
+ new Intent(Intent.ACTION_VIEW, message.actionUri));
}
});
} else {
diff --git a/src/com/android/dialer/util/DialerUtils.java b/src/com/android/dialer/util/DialerUtils.java
new file mode 100644
index 000000000..8b0c4c6dd
--- /dev/null
+++ b/src/com/android/dialer/util/DialerUtils.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.dialer.util;
+
+import android.content.ActivityNotFoundException;
+import android.content.Context;
+import android.content.Intent;
+import android.widget.Toast;
+
+import com.android.dialer.R;
+
+/**
+ * General purpose utility methods for the Dialer.
+ */
+public class DialerUtils {
+
+ /**
+ * Attempts to start an activity and displays a toast with the default error message if the
+ * activity is not found, instead of throwing an exception.
+ *
+ * @param context to start the activity with.
+ * @param intent to start the activity with.
+ */
+ public static void startActivityWithErrorToast(Context context, Intent intent) {
+ startActivityWithErrorToast(context, intent, R.string.activity_not_available);
+ }
+
+ /**
+ * Attempts to start an activity and displays a toast with a provided error message if the
+ * activity is not found, instead of throwing an exception.
+ *
+ * @param context to start the activity with.
+ * @param intent to start the activity with.
+ * @param msgId Resource ID of the string to display in an error message if the activity is
+ * not found.
+ */
+ public static void startActivityWithErrorToast(Context context, Intent intent, int msgId) {
+ try {
+ context.startActivity(intent);
+ } catch (ActivityNotFoundException e) {
+ Toast.makeText(context, msgId, Toast.LENGTH_SHORT).show();
+ }
+ }
+}