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

Commit 8d3e159b authored by Hiroaki Kuriyama's avatar Hiroaki Kuriyama Committed by Zoran Jovanovic
Browse files

onAccountsUpdated shouldn't be called back after listener unregistered

There is a problem of AccountManager that onAccountsUpdated() is
called back even after the OnAccountsUpdatedListener is unregistered.
It may cause application crash.

For example, when rotating a tablet 180 degree with Settings apk
running, com.android.settings.Settings is re-launched 2 times
successively. (Destroy->Create->Destroy->Create)
It repeats adding&removing OnAccountUpdatedListener.

When dialog was being opened in the following cases,
NullPointerException at BackStackRecord.getBreadCrumbTitle()
was happened on 10 inch tablet which has 2 panes on Settings.
* Settings > Language&input > Language
* Settings > Language & input > Text-to-speech output > Speech rate
* Settings > Wi-Fi > Menu > Advanced > Keep Wi-Fi on during sleep
* Settings > Wi-Fi > Menu > Wi-Fi Direct > Rename device

This fix prevents the undesirable callback.

Change-Id: I081f69c90539cca821cf686b4587495135f375e4
parent 738a557d
Loading
Loading
Loading
Loading
+10 −6
Original line number Diff line number Diff line
@@ -1857,14 +1857,18 @@ public class AccountManager {
        handler = (handler == null) ? mMainHandler : handler;
        handler.post(new Runnable() {
            public void run() {
                synchronized (mAccountsUpdatedListeners) {
                    try {
                        if (mAccountsUpdatedListeners.containsKey(listener)) {
                            listener.onAccountsUpdated(accountsCopy);
                        }
                    } catch (SQLException e) {
                        // Better luck next time.  If the problem was disk-full,
                        // the STORAGE_OK intent will re-trigger the update.
                        Log.e(TAG, "Can't update accounts", e);
                    }
                }
            }
        });
    }