Merge "Call system service API instead of checking the phenotype flag directly."
This commit is contained in:
committed by
Android (Google) Code Review
commit
1e81c40558
@@ -33,7 +33,7 @@ import com.android.settings.enterprise.EnterprisePrivacySettings;
|
||||
import com.android.settings.network.SubscriptionUtil;
|
||||
import com.android.settings.network.telephony.MobileNetworkUtils;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.safetycenter.SafetyCenterStatus;
|
||||
import com.android.settings.safetycenter.SafetyCenterStatusHolder;
|
||||
import com.android.settings.security.SecuritySettingsFeatureProvider;
|
||||
|
||||
import com.google.android.setupdesign.util.ThemeHelper;
|
||||
@@ -152,7 +152,7 @@ public class Settings extends SettingsActivity {
|
||||
/** Redirects to SafetyCenter if enabled. */
|
||||
@VisibleForTesting
|
||||
public void handleSafetyCenterRedirection() {
|
||||
if (SafetyCenterStatus.isEnabled()) {
|
||||
if (SafetyCenterStatusHolder.get().isEnabled(this)) {
|
||||
try {
|
||||
startActivity(new Intent(Intent.ACTION_SAFETY_CENTER));
|
||||
finish();
|
||||
@@ -213,7 +213,7 @@ public class Settings extends SettingsActivity {
|
||||
/** Redirects to SafetyCenter if enabled. */
|
||||
@VisibleForTesting
|
||||
public void handleSafetyCenterRedirection() {
|
||||
if (SafetyCenterStatus.isEnabled()) {
|
||||
if (SafetyCenterStatusHolder.get().isEnabled(this)) {
|
||||
try {
|
||||
startActivity(new Intent(Intent.ACTION_SAFETY_CENTER));
|
||||
finish();
|
||||
|
@@ -22,7 +22,7 @@ import android.content.Context;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.notification.LockScreenNotificationPreferenceController;
|
||||
import com.android.settings.safetycenter.SafetyCenterStatus;
|
||||
import com.android.settings.safetycenter.SafetyCenterStatusHolder;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
@@ -93,7 +93,7 @@ public class PrivacyDashboardFragment extends DashboardFragment {
|
||||
|
||||
@Override
|
||||
protected boolean isPageSearchEnabled(Context context) {
|
||||
return !SafetyCenterStatus.isEnabled();
|
||||
return !SafetyCenterStatusHolder.get().isEnabled(context);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@@ -20,7 +20,7 @@ import android.annotation.NonNull;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.safetycenter.SafetyCenterStatus;
|
||||
import com.android.settings.safetycenter.SafetyCenterStatusHolder;
|
||||
|
||||
/** The preference controller for the top level privacy tile. */
|
||||
public class TopLevelPrivacyEntryPreferenceController extends BasePreferenceController {
|
||||
@@ -31,7 +31,7 @@ public class TopLevelPrivacyEntryPreferenceController extends BasePreferenceCon
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
if (!SafetyCenterStatus.isEnabled()) {
|
||||
if (!SafetyCenterStatusHolder.get().isEnabled(mContext)) {
|
||||
return AVAILABLE;
|
||||
}
|
||||
return CONDITIONALLY_UNAVAILABLE;
|
||||
|
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.safetycenter;
|
||||
|
||||
import android.provider.DeviceConfig;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
|
||||
/** Knows whether safety center is enabled or disabled. */
|
||||
public class SafetyCenterStatus {
|
||||
|
||||
/** Whether SafetyCenter page is enabled. */
|
||||
@VisibleForTesting
|
||||
public static final String SAFETY_CENTER_IS_ENABLED = "safety_center_is_enabled";
|
||||
|
||||
/** Returns true is SafetyCenter page is enabled, false otherwise. */
|
||||
public static boolean isEnabled() {
|
||||
// TODO(b/208625216): use SafetyManager API instead
|
||||
return DeviceConfig.getBoolean(
|
||||
DeviceConfig.NAMESPACE_PRIVACY, SAFETY_CENTER_IS_ENABLED, false);
|
||||
}
|
||||
}
|
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.safetycenter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.safetycenter.SafetyCenterManager;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
|
||||
/** Knows whether safety center is enabled or disabled. */
|
||||
public class SafetyCenterStatusHolder {
|
||||
|
||||
private static final String TAG = "SafetyCenterStatusHolder";
|
||||
|
||||
@VisibleForTesting
|
||||
public static SafetyCenterStatusHolder sInstance;
|
||||
|
||||
private SafetyCenterStatusHolder() {}
|
||||
|
||||
/** Returns an instance of {@link SafetyCenterStatusHolder}. */
|
||||
public static SafetyCenterStatusHolder get() {
|
||||
if (sInstance == null) {
|
||||
sInstance = new SafetyCenterStatusHolder();
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
/** Returns true is SafetyCenter page is enabled, false otherwise. */
|
||||
public boolean isEnabled(Context context) {
|
||||
if (context == null) {
|
||||
Log.e(TAG, "Context is null at SafetyCenterStatusHolder#isEnabled");
|
||||
return false;
|
||||
}
|
||||
SafetyCenterManager safetyCenterManager =
|
||||
context.getSystemService(SafetyCenterManager.class);
|
||||
if (safetyCenterManager == null) {
|
||||
Log.w(TAG, "System service SAFETY_CENTER_SERVICE (SafetyCenterManager) is null");
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
return safetyCenterManager.isSafetyCenterEnabled();
|
||||
} catch (RuntimeException e) {
|
||||
Log.e(TAG, "Calling isSafetyCenterEnabled failed.", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@@ -37,7 +37,7 @@ public class TopLevelSafetyCenterEntryPreferenceController extends BasePreferenc
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
if (SafetyCenterStatus.isEnabled()) {
|
||||
if (SafetyCenterStatusHolder.get().isEnabled(mContext)) {
|
||||
return AVAILABLE;
|
||||
}
|
||||
return CONDITIONALLY_UNAVAILABLE;
|
||||
|
@@ -26,7 +26,7 @@ import com.android.settings.biometrics.face.FaceProfileStatusPreferenceControlle
|
||||
import com.android.settings.biometrics.fingerprint.FingerprintProfileStatusPreferenceController;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.safetycenter.SafetyCenterStatus;
|
||||
import com.android.settings.safetycenter.SafetyCenterStatusHolder;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.security.trustagent.TrustAgentListPreferenceController;
|
||||
import com.android.settings.widget.PreferenceCategoryController;
|
||||
@@ -60,11 +60,14 @@ public class SecurityAdvancedSettings extends DashboardFragment {
|
||||
|
||||
@Override
|
||||
public String getCategoryKey() {
|
||||
if (SafetyCenterStatus.isEnabled()) {
|
||||
final Context context = getContext();
|
||||
if (context == null) {
|
||||
return CATEGORY_SECURITY_LEGACY_ADVANCED_SETTINGS;
|
||||
} else if (SafetyCenterStatusHolder.get().isEnabled(context)) {
|
||||
return CategoryKey.CATEGORY_SECURITY_ADVANCED_SETTINGS;
|
||||
} else {
|
||||
final SecuritySettingsFeatureProvider securitySettingsFeatureProvider =
|
||||
FeatureFactory.getFactory(getContext())
|
||||
FeatureFactory.getFactory(context)
|
||||
.getSecuritySettingsFeatureProvider();
|
||||
|
||||
if (securitySettingsFeatureProvider.hasAlternativeSecuritySettingsFragment()) {
|
||||
|
@@ -25,7 +25,7 @@ import com.android.settings.biometrics.face.FaceStatusPreferenceController;
|
||||
import com.android.settings.biometrics.fingerprint.FingerprintStatusPreferenceController;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.safetycenter.SafetyCenterStatus;
|
||||
import com.android.settings.safetycenter.SafetyCenterStatusHolder;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.security.trustagent.TrustAgentListPreferenceController;
|
||||
import com.android.settings.widget.PreferenceCategoryController;
|
||||
@@ -129,7 +129,7 @@ public class SecuritySettings extends DashboardFragment {
|
||||
protected boolean isPageSearchEnabled(Context context) {
|
||||
return !FeatureFactory.getFactory(context).getSecuritySettingsFeatureProvider()
|
||||
.hasAlternativeSecuritySettingsFragment()
|
||||
&& !SafetyCenterStatus.isEnabled();
|
||||
&& !SafetyCenterStatusHolder.get().isEnabled(context);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@@ -24,7 +24,7 @@ import androidx.preference.Preference;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.safetycenter.SafetyCenterStatus;
|
||||
import com.android.settings.safetycenter.SafetyCenterStatusHolder;
|
||||
|
||||
public class TopLevelSecurityEntryPreferenceController extends BasePreferenceController {
|
||||
|
||||
@@ -38,7 +38,7 @@ public class TopLevelSecurityEntryPreferenceController extends BasePreferenceCon
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
if (!SafetyCenterStatus.isEnabled()) {
|
||||
if (!SafetyCenterStatusHolder.get().isEnabled(mContext)) {
|
||||
return AVAILABLE;
|
||||
}
|
||||
return CONDITIONALLY_UNAVAILABLE;
|
||||
|
Reference in New Issue
Block a user