Fixed NPE that crashes Settings.

It happens due to a race condition when the AutofillDeveloperSettingsObserver
is triggered by a settings change while the underlying preferences activity is
being finished.

Fixes: 113030661

Test: echo 'could not reproduce this issue'
Test: runtest --path \
      packages/apps/Settings/tests/unit/src/com/android/settings/core/\
      PreferenceControllerContractTest.java
Test: atest AutofillResetOptionsPreferenceControllerTest \
            AutofillLoggingLevelPreferenceControllerTest

Change-Id: I761195df13ac10705b9ce6b0c7546ec66a85d3ef
This commit is contained in:
Felipe Leme
2018-08-22 11:41:13 -07:00
parent 85a5f96051
commit 934278e050

View File

@@ -19,6 +19,7 @@ package com.android.settings.development.autofill;
import android.content.Context;
import android.content.res.Resources;
import android.provider.Settings;
import android.util.Log;
import android.view.autofill.AutofillManager;
import com.android.settings.R;
@@ -32,6 +33,7 @@ public final class AutofillLoggingLevelPreferenceController
extends DeveloperOptionsPreferenceController
implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
private static final String TAG = "AutofillLoggingLevelPreferenceController";
private static final String AUTOFILL_LOGGING_LEVEL_KEY = "autofill_logging_level";
private final String[] mListValues;
@@ -73,6 +75,12 @@ public final class AutofillLoggingLevelPreferenceController
}
private void updateOptions() {
if (mPreference == null) {
// TODO: there should be a hook on AbstractPreferenceController where we could
// unregister mObserver and avoid this check
Log.v(TAG, "ignoring Settings update because UI is gone");
return;
}
final int level = Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.AUTOFILL_LOGGING_LEVEL, AutofillManager.DEFAULT_LOGGING_LEVEL);