Calling isServiceEnabled with the context in credential manager settings

Test: Built and deployed locally

Change-Id: I22d3fe863fa31c2601cedbde10907c79469a75f4
This commit is contained in:
Reema Bajwa
2022-12-20 22:09:15 +00:00
parent 5ba7d67b42
commit dbd9904c0a
4 changed files with 19 additions and 15 deletions

View File

@@ -25,6 +25,7 @@ import android.content.pm.UserInfo;
import android.credentials.CredentialManager; import android.credentials.CredentialManager;
import android.os.UserHandle; import android.os.UserHandle;
import android.os.UserManager; import android.os.UserManager;
import android.provider.SearchIndexableResource;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.applications.autofill.PasswordsPreferenceController; import com.android.settings.applications.autofill.PasswordsPreferenceController;
@@ -46,7 +47,6 @@ import java.util.List;
@SearchIndexable @SearchIndexable
public class AccountDashboardFragment extends DashboardFragment { public class AccountDashboardFragment extends DashboardFragment {
private static final String TAG = "AccountDashboardFrag"; private static final String TAG = "AccountDashboardFrag";
@Override @Override
@@ -61,7 +61,7 @@ public class AccountDashboardFragment extends DashboardFragment {
@Override @Override
protected int getPreferenceScreenResId() { protected int getPreferenceScreenResId() {
return getPreferenceLayoutResId(); return getPreferenceLayoutResId(this.getContext());
} }
@Override @Override
@@ -72,7 +72,7 @@ public class AccountDashboardFragment extends DashboardFragment {
@Override @Override
public void onAttach(Context context) { public void onAttach(Context context) {
super.onAttach(context); super.onAttach(context);
if (CredentialManager.isServiceEnabled()) { if (CredentialManager.isServiceEnabled(context)) {
CredentialManagerPreferenceController cmpp = CredentialManagerPreferenceController cmpp =
use(CredentialManagerPreferenceController.class); use(CredentialManagerPreferenceController.class);
cmpp.setParentFragment(this); cmpp.setParentFragment(this);
@@ -118,14 +118,21 @@ public class AccountDashboardFragment extends DashboardFragment {
controllers.add(new AutoSyncWorkDataPreferenceController(context, parent)); controllers.add(new AutoSyncWorkDataPreferenceController(context, parent));
} }
public static int getPreferenceLayoutResId() { private static int getPreferenceLayoutResId(Context context) {
return CredentialManager.isServiceEnabled() return (context != null && CredentialManager.isServiceEnabled(context))
? R.xml.accounts_dashboard_settings_credman ? R.xml.accounts_dashboard_settings_credman
: R.xml.accounts_dashboard_settings; : R.xml.accounts_dashboard_settings;
} }
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider(getPreferenceLayoutResId()) { new BaseSearchIndexProvider() {
@Override
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
boolean enabled) {
final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId = getPreferenceLayoutResId(context);
return List.of(sir);
}
@Override @Override
public List<AbstractPreferenceController> createPreferenceControllers( public List<AbstractPreferenceController> createPreferenceControllers(

View File

@@ -38,7 +38,6 @@ import java.util.List;
/** Account Setting page for personal profile. */ /** Account Setting page for personal profile. */
public class AccountPersonalDashboardFragment extends DashboardFragment { public class AccountPersonalDashboardFragment extends DashboardFragment {
private static final String TAG = "AccountPersonalFrag"; private static final String TAG = "AccountPersonalFrag";
@Override @Override
@@ -53,7 +52,7 @@ public class AccountPersonalDashboardFragment extends DashboardFragment {
@Override @Override
protected int getPreferenceScreenResId() { protected int getPreferenceScreenResId() {
if (CredentialManager.isServiceEnabled()) { if (this.getContext() != null && CredentialManager.isServiceEnabled(this.getContext())) {
return R.xml.accounts_personal_dashboard_settings_credman; return R.xml.accounts_personal_dashboard_settings_credman;
} }
return R.xml.accounts_personal_dashboard_settings; return R.xml.accounts_personal_dashboard_settings;
@@ -67,8 +66,7 @@ public class AccountPersonalDashboardFragment extends DashboardFragment {
@Override @Override
public void onAttach(Context context) { public void onAttach(Context context) {
super.onAttach(context); super.onAttach(context);
if (CredentialManager.isServiceEnabled(context)) {
if (CredentialManager.isServiceEnabled()) {
CredentialManagerPreferenceController cmpp = CredentialManagerPreferenceController cmpp =
use(CredentialManagerPreferenceController.class); use(CredentialManagerPreferenceController.class);
cmpp.setParentFragment(this); cmpp.setParentFragment(this);

View File

@@ -38,7 +38,6 @@ import java.util.List;
/** Account Setting page for work profile. */ /** Account Setting page for work profile. */
public class AccountWorkProfileDashboardFragment extends DashboardFragment { public class AccountWorkProfileDashboardFragment extends DashboardFragment {
private static final String TAG = "AccountWorkProfileFrag"; private static final String TAG = "AccountWorkProfileFrag";
@Override @Override
@@ -53,7 +52,7 @@ public class AccountWorkProfileDashboardFragment extends DashboardFragment {
@Override @Override
protected int getPreferenceScreenResId() { protected int getPreferenceScreenResId() {
if (CredentialManager.isServiceEnabled()) { if (this.getContext() != null && CredentialManager.isServiceEnabled(this.getContext())) {
return R.xml.accounts_work_dashboard_settings_credman; return R.xml.accounts_work_dashboard_settings_credman;
} }
return R.xml.accounts_work_dashboard_settings; return R.xml.accounts_work_dashboard_settings;
@@ -67,8 +66,7 @@ public class AccountWorkProfileDashboardFragment extends DashboardFragment {
@Override @Override
public void onAttach(Context context) { public void onAttach(Context context) {
super.onAttach(context); super.onAttach(context);
if (CredentialManager.isServiceEnabled(context)) {
if (CredentialManager.isServiceEnabled()) {
CredentialManagerPreferenceController cmpp = CredentialManagerPreferenceController cmpp =
use(CredentialManagerPreferenceController.class); use(CredentialManagerPreferenceController.class);
cmpp.setParentFragment(this); cmpp.setParentFragment(this);

View File

@@ -96,7 +96,8 @@ public class CredentialManagerPreferenceController extends BasePreferenceControl
} }
Object service = context.getSystemService(Context.CREDENTIAL_SERVICE); Object service = context.getSystemService(Context.CREDENTIAL_SERVICE);
if (service != null && CredentialManager.isServiceEnabled()) {
if (service != null && CredentialManager.isServiceEnabled(context)) {
return (CredentialManager) service; return (CredentialManager) service;
} }