Fix passwords settings crash due to null lifecycle owner.

A change related to lifecycles was reverted some time ago
(I7e6d2e9e6fd363a3afdd3dbab24e7c3b36e9ed29), which caused this to break.

The crash is only seen if an autofill service sets the new Passwords
Activity attr; currently no services do.

Fix: 184077486
Test: manual - check settings page and see no crash
Test: manual - same with work profile added
Test: make RunSettingsRoboTests
Change-Id: Ie439f37c9e884f9de2b112b348e1bef03adcd077
This commit is contained in:
Ahaan Ugale
2021-03-24 17:13:07 -07:00
parent 448dac80de
commit 318f7cc512
3 changed files with 21 additions and 0 deletions

View File

@@ -27,6 +27,7 @@ import android.os.UserManager;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.applications.autofill.PasswordsPreferenceController;
import com.android.settings.applications.defaultapps.DefaultAutofillPreferenceController;
import com.android.settings.applications.defaultapps.DefaultWorkAutofillPreferenceController;
import com.android.settings.dashboard.DashboardFragment;
@@ -68,6 +69,12 @@ public class AccountDashboardFragment extends DashboardFragment {
return R.string.help_url_user_and_account_dashboard;
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
getSettingsLifecycle().addObserver(use(PasswordsPreferenceController.class));
}
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();

View File

@@ -25,6 +25,7 @@ import android.content.Context;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.applications.autofill.PasswordsPreferenceController;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
import com.android.settings.users.AutoSyncDataPreferenceController;
@@ -61,6 +62,12 @@ public class AccountPersonalDashboardFragment extends DashboardFragment {
return R.string.help_url_user_and_account_dashboard;
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
getSettingsLifecycle().addObserver(use(PasswordsPreferenceController.class));
}
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();

View File

@@ -25,6 +25,7 @@ import android.content.Context;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.applications.autofill.PasswordsPreferenceController;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
import com.android.settings.users.AutoSyncDataPreferenceController;
@@ -61,6 +62,12 @@ public class AccountWorkProfileDashboardFragment extends DashboardFragment {
return R.string.help_url_user_and_account_dashboard;
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
getSettingsLifecycle().addObserver(use(PasswordsPreferenceController.class));
}
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();