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

Commit 4986044f authored by Amith Yamasani's avatar Amith Yamasani
Browse files

Fix window leak and receiver leak. Bug: 2520143 and Bug: 2517390

In Activity.onDestroy close any open SearchDialog to avoid a window leak.

Register/unregister broadcast receiver in onStart/onStop of the dialog.
parent e4eb5bf2
Loading
Loading
Loading
Loading
+5 −0
Original line number Original line Diff line number Diff line
@@ -1320,6 +1320,11 @@ public class Activity extends ContextThemeWrapper
            }
            }
            mManagedCursors.clear();
            mManagedCursors.clear();
        }
        }

        // Close any open search dialog
        if (mSearchManager != null) {
            mSearchManager.stopSearch();
        }
    }
    }


    /**
    /**
+22 −11
Original line number Original line Diff line number Diff line
@@ -132,6 +132,15 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
    // Last known IME options value for the search edit text.
    // Last known IME options value for the search edit text.
    private int mSearchAutoCompleteImeOptions;
    private int mSearchAutoCompleteImeOptions;


    private BroadcastReceiver mConfChangeListener = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(Intent.ACTION_CONFIGURATION_CHANGED)) {
                onConfigurationChanged();
            }
        }
    };

    /**
    /**
     * Constructor - fires it up and makes it look like the search UI.
     * Constructor - fires it up and makes it look like the search UI.
     * 
     * 
@@ -149,16 +158,6 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
        mVoiceAppSearchIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        mVoiceAppSearchIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        mVoiceAppSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mVoiceAppSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mSearchManager = searchManager;
        mSearchManager = searchManager;
        IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
        context.registerReceiver(new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                if (intent.getAction().equals(Intent.ACTION_CONFIGURATION_CHANGED)) {
                    onConfigurationChanged();
                }
            }
        }, filter);
    }
    }


    /**
    /**
@@ -301,6 +300,16 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
        return true;
        return true;
    }
    }


    @Override
    public void onStart() {
        super.onStart();

        // Register a listener for configuration change events.
        IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
        getContext().registerReceiver(mConfChangeListener, filter);
    }

    /**
    /**
     * The search dialog is being dismissed, so handle all of the local shutdown operations.
     * The search dialog is being dismissed, so handle all of the local shutdown operations.
     * 
     * 
@@ -311,6 +320,8 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
    public void onStop() {
    public void onStop() {
        super.onStop();
        super.onStop();


        getContext().unregisterReceiver(mConfChangeListener);

        closeSuggestionsAdapter();
        closeSuggestionsAdapter();
        
        
        // dump extra memory we're hanging on to
        // dump extra memory we're hanging on to