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

Commit 2828c48c authored by Makoto Onuki's avatar Makoto Onuki
Browse files

Prevent passing null context to AggregationSuggestionEngine

The monkey crash suggests we're creating this object when getActivity()
returns null, meaning after the fragment is destroyed.

I couldn't really find any path that could cause it, but let's make
sure we'll never pass null.

Bug 6340106

Change-Id: I38091b46a99821065e248c811ed2f974f2f47152
parent 9ec8a75d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -119,7 +119,7 @@ public class AggregationSuggestionEngine extends HandlerThread {

    public AggregationSuggestionEngine(Context context) {
        super("AggregationSuggestions", Process.THREAD_PRIORITY_BACKGROUND);
        mContext = context;
        mContext = context.getApplicationContext();
        mMainHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
+9 −4
Original line number Diff line number Diff line
@@ -724,13 +724,17 @@ public class ContactEditorFragment extends Fragment implements
            if (bitmap != null) editor.setPhotoBitmap(bitmap);

            if (editor instanceof RawContactEditorView) {
                final Activity activity = getActivity();
                final RawContactEditorView rawContactEditor = (RawContactEditorView) editor;
                EditorListener listener = new EditorListener() {

                    @Override
                    public void onRequest(int request) {
                        if (activity.isFinishing()) { // Make sure activity is still running.
                            return;
                        }
                        if (request == EditorListener.FIELD_CHANGED && !isEditingUserProfile()) {
                            acquireAggregationSuggestions(rawContactEditor);
                            acquireAggregationSuggestions(activity, rawContactEditor);
                        }
                    }

@@ -752,7 +756,7 @@ public class ContactEditorFragment extends Fragment implements
                rawContactEditor.setAutoAddToDefaultGroup(mAutoAddToDefaultGroup);

                if (rawContactId == mAggregationSuggestionsRawContactId) {
                    acquireAggregationSuggestions(rawContactEditor);
                    acquireAggregationSuggestions(activity, rawContactEditor);
                }
            }
        }
@@ -1351,7 +1355,8 @@ public class ContactEditorFragment extends Fragment implements
    /**
     * Triggers an asynchronous search for aggregation suggestions.
     */
    public void acquireAggregationSuggestions(RawContactEditorView rawContactEditor) {
    private void acquireAggregationSuggestions(Context context,
            RawContactEditorView rawContactEditor) {
        long rawContactId = rawContactEditor.getRawContactId();
        if (mAggregationSuggestionsRawContactId != rawContactId
                && mAggregationSuggestionView != null) {
@@ -1363,7 +1368,7 @@ public class ContactEditorFragment extends Fragment implements
        mAggregationSuggestionsRawContactId = rawContactId;

        if (mAggregationSuggestionEngine == null) {
            mAggregationSuggestionEngine = new AggregationSuggestionEngine(getActivity());
            mAggregationSuggestionEngine = new AggregationSuggestionEngine(context);
            mAggregationSuggestionEngine.setListener(this);
            mAggregationSuggestionEngine.start();
        }