Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 12592e84 authored by Flavio Lerda's avatar Flavio Lerda
Browse files

Fix StrictMode violation.

Currently we load the data about the phone calls on the UI thread.
Instead, start an async task that loads the data and then updates the UI
onPostExecute.

Bug: 4968959
Change-Id: I117c0794268592cc60767012175253fa43cda65a
parent 8ebfa3d1
Loading
Loading
Loading
Loading
+133 −114
Original line number Diff line number Diff line
@@ -272,24 +272,38 @@ public class CallDetailActivity extends ListActivity {
     * @param callUris URIs into {@link CallLog.Calls} of the calls to be displayed
     */
    private void updateData(final Uri... callUris) {
        // TODO: All phone calls correspond to the same person, so we can make a single lookup.
        mBackgroundTaskService.submit(new BackgroundTask() {
            private PhoneCallDetails[] details;

            @Override
            public void doInBackground() {
                // TODO: All phone calls correspond to the same person, so we can make a single
                // lookup.
                final int numCalls = callUris.length;
        final PhoneCallDetails[] details = new PhoneCallDetails[numCalls];
                details = new PhoneCallDetails[numCalls];
                try {
                    for (int index = 0; index < numCalls; ++index) {
                        details[index] = getPhoneCallDetailsForUri(callUris[index]);
                    }
                } catch (IllegalArgumentException e) {
            // Something went wrong reading in our primary data, so we're going to
            // bail out and show error to users.
                    // Something went wrong reading in our primary data.
                    Log.w(TAG, "invalid URI starting call details", e);
            Toast.makeText(this, R.string.toast_call_detail_error,
                    details = null;
                }
            }

            @Override
            public void onPostExecute() {
                if (details == null) {
                    // Somewhere went wrong: we're going to bail out and show error to users.
                    Toast.makeText(CallDetailActivity.this, R.string.toast_call_detail_error,
                            Toast.LENGTH_SHORT).show();
                    finish();
                    return;
                }

        // We know that all calls are from the same number and the same contact, so pick the first.
                // We know that all calls are from the same number and the same contact, so pick the
                // first.
                PhoneCallDetails firstDetails = details[0];
                mNumber = firstDetails.number.toString();
                final long personId = firstDetails.personId;
@@ -304,8 +318,8 @@ public class CallDetailActivity extends ListActivity {
                final boolean isVoicemailNumber = mPhoneNumberHelper.isVoicemailNumber(mNumber);
                final boolean isSipNumber = mPhoneNumberHelper.isSipNumber(mNumber);

        // Let user view contact details if they exist, otherwise add option to create new contact
        // from this number.
                // Let user view contact details if they exist, otherwise add option to create new
                // contact from this number.
                final Intent mainActionIntent;
                final int mainActionIcon;

@@ -375,10 +389,12 @@ public class CallDetailActivity extends ListActivity {
                                firstDetails.numberLabel);
                    }

            // The secondary action allows to send an SMS to the number that placed the call.
                    // The secondary action allows to send an SMS to the number that placed the
                    // call.
                    if (mPhoneNumberHelper.canSendSmsTo(mNumber)) {
                        entry.setSecondaryAction(R.drawable.ic_text_holo_dark,
                        new Intent(Intent.ACTION_SENDTO, Uri.fromParts("sms", mNumber, null)));
                                new Intent(Intent.ACTION_SENDTO,
                                           Uri.fromParts("sms", mNumber, null)));
                    }

                    actions.add(entry);
@@ -388,7 +404,7 @@ public class CallDetailActivity extends ListActivity {

                if (actions.size() != 0) {
                    // Set the actions for this phone number.
            setListAdapter(new ViewAdapter(this, actions));
                    setListAdapter(new ViewAdapter(CallDetailActivity.this, actions));
                    getListView().setVisibility(View.VISIBLE);
                    getListView().setItemsCanFocus(true);
                } else {
@@ -397,9 +413,12 @@ public class CallDetailActivity extends ListActivity {

                ListView historyList = (ListView) findViewById(R.id.history);
                historyList.setAdapter(
                new CallDetailHistoryAdapter(this, mInflater, mCallTypeHelper, details));
                        new CallDetailHistoryAdapter(CallDetailActivity.this, mInflater,
                                mCallTypeHelper, details));
                loadContactPhotos(photoUri);
            }
        });
    }

    /** Return the phone call details for a given call log URI. */
    private PhoneCallDetails getPhoneCallDetailsForUri(Uri callUri) {