Fix "Automatically sync app data" button state not changed

This issue is caused by mPreference is null.
(Not recovered when the fragment is recreated after configuration change.)

Mimic the PreferenceDialogFragmentCompat.getPreference() in AndroidX to
solve this issue.
https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:preference/preference/src/main/java/androidx/preference/PreferenceDialogFragmentCompat.java;l=176;drc=ca9feb3b73769089afbfd36b4d4a3d91239f9cd5

Ideally in the long term, we could use PreferenceDialogFragmentCompat
instead.

Fix: 218754949
Test: robotest & manual
Change-Id: I7fc8dd3b771aa45c91f915e25c8cc6c6afdd8d63
This commit is contained in:
Chaohui Wang
2022-03-25 22:37:32 +08:00
parent 09b761700d
commit 9d8603568d
7 changed files with 95 additions and 67 deletions

View File

@@ -19,6 +19,7 @@ package com.android.settings.testutils.shadow;
import static android.provider.SearchIndexablesContract.INDEXABLES_RAW_COLUMNS;
import android.accounts.Account;
import android.annotation.UserIdInt;
import android.content.ContentResolver;
import android.content.SyncAdapterType;
import android.database.Cursor;
@@ -76,8 +77,12 @@ public class ShadowContentResolver {
@Implementation
protected static boolean getMasterSyncAutomaticallyAsUser(int userId) {
return sMasterSyncAutomatically.containsKey(userId)
? sMasterSyncAutomatically.get(userId) : true;
return sMasterSyncAutomatically.getOrDefault(userId, true);
}
@Implementation
protected static void setMasterSyncAutomaticallyAsUser(boolean sync, @UserIdInt int userId) {
sMasterSyncAutomatically.put(userId, sync);
}
public static void setSyncAdapterTypes(SyncAdapterType[] syncAdapterTypes) {