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

Commit a1649aa2 authored by Khalid Zubair's avatar Khalid Zubair Committed by Scott Mertz
Browse files

Fix exponential content observer registration

On each call to ContentObserver.onChange(), updateUi() re-registers a
ContentObserver. On the first onChange, a second observer is
registered and for the next change, both observers call updateUi()
registering two more, and so on. After n onChanges there are 2^n
observers.

Remove the duplicate registrations and register a ContentObserver only
if the station changes.

FEIJ-1373

Change-Id: I07d0bd968165dfda5601f72fd20641bb9d62a5f1
parent 4da63b53
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -142,9 +142,16 @@ public class FmRecordActivity extends Activity implements
                mStationName.setText(stationName);
                mRadioText.setText(radioText);
                int id = cursor.getInt(cursor.getColumnIndex(Station._ID));

                if (mWatchedId != id) {
                    if (mWatchedId != -1) {
                        resolver.unregisterContentObserver(mContentObserver);
                    }
                    resolver.registerContentObserver(
                        ContentUris.withAppendedId(Station.CONTENT_URI, id), false,
                        mContentObserver);
                            ContentUris.withAppendedId(Station.CONTENT_URI, id),
                            false, mContentObserver);
                    mWatchedId = id;
                }
                // If no station name and no radio text, hide the view
                if ((!TextUtils.isEmpty(stationName))
                        || (!TextUtils.isEmpty(radioText))) {
@@ -282,7 +289,9 @@ public class FmRecordActivity extends Activity implements
            mService.unregisterFmRadioListener(mFmListener);
        }
        unbindService(mServiceConnection);
        if (mWatchedId != -1) {
            mContext.getContentResolver().unregisterContentObserver(mContentObserver);
        }
        super.onDestroy();
    }

@@ -471,6 +480,7 @@ public class FmRecordActivity extends Activity implements
        setResult(RESULT_OK, intent);
    }

    private int mWatchedId = -1;
    private final ContentObserver mContentObserver = new ContentObserver(new Handler()) {
        public void onChange(boolean selfChange) {
            updateUi();