fix: 引入Settings的Module

This commit is contained in:
2024-12-10 14:57:24 +08:00
parent ad8fc8731d
commit df105485bd
6934 changed files with 896168 additions and 2 deletions

View File

@@ -0,0 +1,223 @@
/*
* 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.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.hardware.face.FaceManager;
import android.hardware.fingerprint.FingerprintManager;
import android.os.Bundle;
import android.os.Process;
import android.os.UserHandle;
import android.os.UserManager;
import android.safetycenter.SafetyEvent;
import android.safetycenter.SafetySourceData;
import android.safetycenter.SafetySourceStatus;
import com.android.settings.Utils;
import com.android.settings.biometrics.BiometricNavigationUtils;
import com.android.settings.biometrics.activeunlock.ActiveUnlockStatusUtils;
import com.android.settings.biometrics.combination.CombinedBiometricStatusUtils;
import com.android.settings.biometrics.face.FaceStatusUtils;
import com.android.settings.biometrics.fingerprint.FingerprintStatusUtils;
import com.android.settingslib.RestrictedLockUtils;
/** Combined Biometrics Safety Source for Safety Center. */
public final class BiometricsSafetySource {
public static final String SAFETY_SOURCE_ID = "AndroidBiometrics";
private static final int REQUEST_CODE_COMBINED_BIOMETRIC_SETTING = 10;
private static final int REQUEST_CODE_FACE_SETTING = 20;
private static final int REQUEST_CODE_FINGERPRINT_SETTING = 30;
private BiometricsSafetySource() {}
/** Sets biometric safety data for Safety Center. */
public static void setSafetySourceData(Context context, SafetyEvent safetyEvent) {
if (!SafetyCenterManagerWrapper.get().isEnabled(context)) {
return;
}
final UserHandle userHandle = Process.myUserHandle();
final int userId = userHandle.getIdentifier();
final UserManager userManager = UserManager.get(context);
UserHandle profileParentUserHandle = userManager.getProfileParent(userHandle);
if (profileParentUserHandle == null) {
profileParentUserHandle = userHandle;
}
final Context profileParentContext =
context.createContextAsUser(profileParentUserHandle, 0);
if (android.os.Flags.allowPrivateProfile() && userManager.isPrivateProfile()) {
// SC always expects a response from the source if the broadcast has been sent for this
// source, therefore, we need to send a null SafetySourceData.
SafetyCenterManagerWrapper.get().setSafetySourceData(
context,
SAFETY_SOURCE_ID,
/* safetySourceData= */ null,
safetyEvent);
return;
}
final BiometricNavigationUtils biometricNavigationUtils =
new BiometricNavigationUtils(userId);
final CombinedBiometricStatusUtils combinedBiometricStatusUtils =
new CombinedBiometricStatusUtils(context, userId);
final ActiveUnlockStatusUtils activeUnlockStatusUtils =
new ActiveUnlockStatusUtils(context);
if (!userManager.isProfile() && activeUnlockStatusUtils.isAvailable()) {
final RestrictedLockUtils.EnforcedAdmin disablingAdmin =
combinedBiometricStatusUtils.getDisablingAdmin();
setBiometricSafetySourceData(
context,
activeUnlockStatusUtils.getTitleForActiveUnlock(),
combinedBiometricStatusUtils.getSummary(),
createPendingIntent(
context,
biometricNavigationUtils.getBiometricSettingsIntent(
context,
combinedBiometricStatusUtils.getSettingsClassName(),
disablingAdmin,
Bundle.EMPTY),
REQUEST_CODE_COMBINED_BIOMETRIC_SETTING),
disablingAdmin == null /* enabled */,
combinedBiometricStatusUtils.hasEnrolled(),
safetyEvent);
return;
}
if (combinedBiometricStatusUtils.isAvailable()) {
final RestrictedLockUtils.EnforcedAdmin disablingAdmin =
combinedBiometricStatusUtils.getDisablingAdmin();
setBiometricSafetySourceData(
context,
combinedBiometricStatusUtils.getTitle(),
combinedBiometricStatusUtils.getSummary(),
createPendingIntent(
profileParentContext,
biometricNavigationUtils
.getBiometricSettingsIntent(
context,
combinedBiometricStatusUtils
.getSettingsClassNameBasedOnUser(),
disablingAdmin,
Bundle.EMPTY)
.setIdentifier(Integer.toString(userId)),
REQUEST_CODE_COMBINED_BIOMETRIC_SETTING),
disablingAdmin == null /* enabled */,
combinedBiometricStatusUtils.hasEnrolled(),
safetyEvent);
return;
}
final FaceManager faceManager = Utils.getFaceManagerOrNull(context);
final FaceStatusUtils faceStatusUtils = new FaceStatusUtils(context, faceManager, userId);
if (faceStatusUtils.isAvailable()) {
final RestrictedLockUtils.EnforcedAdmin disablingAdmin =
faceStatusUtils.getDisablingAdmin();
setBiometricSafetySourceData(
context,
faceStatusUtils.getTitle(),
faceStatusUtils.getSummary(),
createPendingIntent(
profileParentContext,
biometricNavigationUtils
.getBiometricSettingsIntent(
context,
faceStatusUtils.getSettingsClassName(),
disablingAdmin,
Bundle.EMPTY)
.setIdentifier(Integer.toString(userId)),
REQUEST_CODE_FACE_SETTING),
disablingAdmin == null /* enabled */,
faceStatusUtils.hasEnrolled(),
safetyEvent);
return;
}
final FingerprintManager fingerprintManager = Utils.getFingerprintManagerOrNull(context);
final FingerprintStatusUtils fingerprintStatusUtils =
new FingerprintStatusUtils(context, fingerprintManager, userId);
if (fingerprintStatusUtils.isAvailable()) {
final RestrictedLockUtils.EnforcedAdmin disablingAdmin =
fingerprintStatusUtils.getDisablingAdmin();
setBiometricSafetySourceData(
context,
fingerprintStatusUtils.getTitle(),
fingerprintStatusUtils.getSummary(),
createPendingIntent(
profileParentContext,
biometricNavigationUtils
.getBiometricSettingsIntent(
context,
fingerprintStatusUtils.getSettingsClassName(),
disablingAdmin,
Bundle.EMPTY)
.setIdentifier(Integer.toString(userId)),
REQUEST_CODE_FINGERPRINT_SETTING),
disablingAdmin == null /* enabled */,
fingerprintStatusUtils.hasEnrolled(),
safetyEvent);
return;
}
SafetyCenterManagerWrapper.get()
.setSafetySourceData(
context, SAFETY_SOURCE_ID, /* safetySourceData= */ null, safetyEvent);
}
/** Notifies Safety Center of a change in biometrics settings. */
public static void onBiometricsChanged(Context context) {
setSafetySourceData(
context,
new SafetyEvent.Builder(SafetyEvent.SAFETY_EVENT_TYPE_SOURCE_STATE_CHANGED)
.build());
}
private static void setBiometricSafetySourceData(
Context context,
String title,
String summary,
PendingIntent pendingIntent,
boolean enabled,
boolean hasEnrolled,
SafetyEvent safetyEvent) {
final int severityLevel =
enabled && hasEnrolled
? SafetySourceData.SEVERITY_LEVEL_INFORMATION
: SafetySourceData.SEVERITY_LEVEL_UNSPECIFIED;
final SafetySourceStatus status =
new SafetySourceStatus.Builder(title, summary, severityLevel)
.setPendingIntent(pendingIntent)
.setEnabled(enabled)
.build();
final SafetySourceData safetySourceData =
new SafetySourceData.Builder().setStatus(status).build();
SafetyCenterManagerWrapper.get()
.setSafetySourceData(context, SAFETY_SOURCE_ID, safetySourceData, safetyEvent);
}
private static PendingIntent createPendingIntent(
Context context, Intent intent, int requestCode) {
return PendingIntent.getActivity(
context, requestCode, intent, PendingIntent.FLAG_IMMUTABLE);
}
}

View File

@@ -0,0 +1,174 @@
/*
* 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 static android.safetycenter.SafetyEvent.SAFETY_EVENT_TYPE_SOURCE_STATE_CHANGED;
import android.app.PendingIntent;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.Intent;
import android.os.UserHandle;
import android.os.UserManager;
import android.safetycenter.SafetyEvent;
import android.safetycenter.SafetySourceData;
import android.safetycenter.SafetySourceIssue;
import android.safetycenter.SafetySourceStatus;
import android.safetycenter.SafetySourceStatus.IconAction;
import com.android.settings.R;
import com.android.settings.security.ScreenLockPreferenceDetailsUtils;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedLockUtilsInternal;
/** Lock Screen Safety Source for Safety Center. */
public final class LockScreenSafetySource {
public static final String SAFETY_SOURCE_ID = "AndroidLockScreen";
public static final String NO_SCREEN_LOCK_ISSUE_ID = "NoScreenLockIssue";
public static final String NO_SCREEN_LOCK_ISSUE_TYPE_ID = "NoScreenLockIssueType";
public static final String SET_SCREEN_LOCK_ACTION_ID = "SetScreenLockAction";
private static final int REQUEST_CODE_SCREEN_LOCK = 1;
private static final int REQUEST_CODE_SCREEN_LOCK_SETTINGS = 2;
private LockScreenSafetySource() {}
/** Sets lock screen safety data for Safety Center. */
public static void setSafetySourceData(
Context context,
ScreenLockPreferenceDetailsUtils screenLockPreferenceDetailsUtils,
SafetyEvent safetyEvent) {
if (!SafetyCenterManagerWrapper.get().isEnabled(context)) {
return;
}
UserManager userManager = context.getSystemService(UserManager.class);
if (userManager != null && userManager.isProfile()) {
return; // LockScreen source only supports primary profile.
}
if (!screenLockPreferenceDetailsUtils.isAvailable()) {
SafetyCenterManagerWrapper.get()
.setSafetySourceData(
context, SAFETY_SOURCE_ID, /* safetySourceData= */ null, safetyEvent);
return;
}
final int userId = UserHandle.myUserId();
final RestrictedLockUtils.EnforcedAdmin admin =
RestrictedLockUtilsInternal.checkIfPasswordQualityIsSet(context, userId);
final PendingIntent pendingIntent =
createPendingIntent(
context,
screenLockPreferenceDetailsUtils.getLaunchChooseLockGenericFragmentIntent(
SettingsEnums.SAFETY_CENTER),
REQUEST_CODE_SCREEN_LOCK);
final IconAction gearMenuIconAction =
createGearMenuIconAction(context, screenLockPreferenceDetailsUtils);
final boolean lockScreenAllowedByAdmin =
!screenLockPreferenceDetailsUtils.isPasswordQualityManaged(userId, admin);
final boolean isLockPatternSecure = screenLockPreferenceDetailsUtils.isLockPatternSecure();
final int severityLevel =
lockScreenAllowedByAdmin
? isLockPatternSecure
? SafetySourceData.SEVERITY_LEVEL_INFORMATION
: SafetySourceData.SEVERITY_LEVEL_RECOMMENDATION
: SafetySourceData.SEVERITY_LEVEL_UNSPECIFIED;
final SafetySourceStatus status =
new SafetySourceStatus.Builder(
context.getString(R.string.unlock_set_unlock_launch_picker_title),
lockScreenAllowedByAdmin
? screenLockPreferenceDetailsUtils.getSummary(
UserHandle.myUserId())
: context.getString(R.string.disabled_by_policy_title),
severityLevel)
.setPendingIntent(lockScreenAllowedByAdmin ? pendingIntent : null)
.setEnabled(lockScreenAllowedByAdmin)
.setIconAction(lockScreenAllowedByAdmin ? gearMenuIconAction : null)
.build();
final SafetySourceData.Builder safetySourceDataBuilder =
new SafetySourceData.Builder().setStatus(status);
if (lockScreenAllowedByAdmin && !isLockPatternSecure) {
safetySourceDataBuilder.addIssue(createNoScreenLockIssue(context, pendingIntent));
}
final SafetySourceData safetySourceData = safetySourceDataBuilder.build();
SafetyCenterManagerWrapper.get()
.setSafetySourceData(context, SAFETY_SOURCE_ID, safetySourceData, safetyEvent);
}
/** Notifies Safety Center of a change in lock screen settings. */
public static void onLockScreenChange(Context context) {
setSafetySourceData(
context,
new ScreenLockPreferenceDetailsUtils(context),
new SafetyEvent.Builder(SAFETY_EVENT_TYPE_SOURCE_STATE_CHANGED).build());
// Also send refreshed safety center data for biometrics, since changing lockscreen settings
// can unset biometrics.
BiometricsSafetySource.onBiometricsChanged(context);
}
private static IconAction createGearMenuIconAction(
Context context, ScreenLockPreferenceDetailsUtils screenLockPreferenceDetailsUtils) {
return screenLockPreferenceDetailsUtils.shouldShowGearMenu()
? new IconAction(
IconAction.ICON_TYPE_GEAR,
createPendingIntent(
context,
screenLockPreferenceDetailsUtils.getLaunchScreenLockSettingsIntent(
SettingsEnums.SAFETY_CENTER),
REQUEST_CODE_SCREEN_LOCK_SETTINGS))
: null;
}
private static PendingIntent createPendingIntent(
Context context, Intent intent, int requestCode) {
return PendingIntent.getActivity(
context, requestCode, intent, PendingIntent.FLAG_IMMUTABLE);
}
private static SafetySourceIssue createNoScreenLockIssue(
Context context, PendingIntent pendingIntent) {
final SafetySourceIssue.Action action =
new SafetySourceIssue.Action.Builder(
SET_SCREEN_LOCK_ACTION_ID,
context.getString(R.string.no_screen_lock_issue_action_label),
pendingIntent)
.build();
// Custom notification deliberately has zero actions
final SafetySourceIssue.Notification customNotification =
new SafetySourceIssue.Notification.Builder(
context.getString(R.string.no_screen_lock_issue_notification_title),
context.getString(R.string.no_screen_lock_issue_notification_text))
.build();
return new SafetySourceIssue.Builder(
NO_SCREEN_LOCK_ISSUE_ID,
context.getString(R.string.no_screen_lock_issue_title),
context.getString(R.string.no_screen_lock_issue_summary),
SafetySourceData.SEVERITY_LEVEL_RECOMMENDATION,
NO_SCREEN_LOCK_ISSUE_TYPE_ID)
.setIssueCategory(SafetySourceIssue.ISSUE_CATEGORY_DEVICE)
.addAction(action)
.setIssueActionability(SafetySourceIssue.ISSUE_ACTIONABILITY_MANUAL)
.setCustomNotification(customNotification)
.setNotificationBehavior(SafetySourceIssue.NOTIFICATION_BEHAVIOR_DELAYED)
.build();
}
}

View File

@@ -0,0 +1,151 @@
/*
* Copyright (C) 2023 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.app.settings.SettingsEnums;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.SearchIndexableResource;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.security.LockUnificationPreferenceController;
import com.android.settings.security.trustagent.TrustAgentListPreferenceController;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.drawer.CategoryKey;
import com.android.settingslib.search.SearchIndexable;
import java.util.ArrayList;
import java.util.List;
/**
* An overflow menu for {@code SecuritySettings} containing advanced security and privacy settings.
*
* <p>This also includes all work-profile related settings.
*/
@SearchIndexable
public class MoreSecurityPrivacyFragment extends DashboardFragment {
private static final String TAG = "MoreSecurityPrivacyFragment";
private static final String KEY_NOTIFICATION_WORK_PROFILE_NOTIFICATIONS =
"privacy_lock_screen_work_profile_notifications";
@Override
public int getMetricsCategory() {
return SettingsEnums.MORE_SECURITY_PRIVACY_SETTINGS;
}
@Override
protected int getPreferenceScreenResId() {
return R.xml.more_security_privacy_settings;
}
@Override
public String getCategoryKey() {
return CategoryKey.CATEGORY_MORE_SECURITY_PRIVACY_SETTINGS;
}
@Override
protected String getLogTag() {
return TAG;
}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
SafetyCenterUtils.replaceEnterpriseStringsForPrivacyEntries(this);
SafetyCenterUtils.replaceEnterpriseStringsForSecurityEntries(this);
}
/** see confirmPatternThenDisableAndClear */
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (use(TrustAgentListPreferenceController.class)
.handleActivityResult(requestCode, resultCode)) {
return;
}
if (use(LockUnificationPreferenceController.class)
.handleActivityResult(requestCode, resultCode, data)) {
return;
}
super.onActivityResult(requestCode, resultCode, data);
}
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
return buildPreferenceControllers(context, getSettingsLifecycle(), this /* host*/);
}
private static List<AbstractPreferenceController> buildPreferenceControllers(
Context context, Lifecycle lifecycle, DashboardFragment host) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
controllers.addAll(SafetyCenterUtils.getControllersForAdvancedPrivacy(context, lifecycle));
controllers.addAll(
SafetyCenterUtils.getControllersForAdvancedSecurity(context, lifecycle, host));
return controllers;
}
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider(R.xml.more_security_privacy_settings) {
/**
* If SafetyCenter is disabled, all of these entries will be in the More Security
* Settings and the Privacy page, and we don't want to index these entries.
*/
@Override
public List<SearchIndexableResource> getXmlResourcesToIndex(
Context context, boolean enabled) {
// NOTE: This check likely should be moved to the super method. This is done
// here to avoid potentially undesired side effects for existing implementors.
if (!isPageSearchEnabled(context)) {
return null;
}
return super.getXmlResourcesToIndex(context, enabled);
}
@Override
public List<AbstractPreferenceController> createPreferenceControllers(
Context context) {
return buildPreferenceControllers(context, null, null);
}
@Override
public List<String> getNonIndexableKeys(Context context) {
final List<String> keys = super.getNonIndexableKeys(context);
final int profileUserId =
Utils.getManagedProfileId(
UserManager.get(context), UserHandle.myUserId());
// If work profile is supported, we should keep the search result.
if (profileUserId != UserHandle.USER_NULL) {
return keys;
}
// Otherwise, we should hide the search result.
keys.add(KEY_NOTIFICATION_WORK_PROFILE_NOTIFICATIONS);
return keys;
}
@Override
protected boolean isPageSearchEnabled(Context context) {
return SafetyCenterManagerWrapper.get().isEnabled(context);
}
};
}

View File

@@ -0,0 +1,95 @@
/*
* 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.safetycenter.SafetyEvent;
import android.safetycenter.SafetySourceData;
import android.util.Log;
import androidx.annotation.Nullable;
import com.android.internal.annotations.VisibleForTesting;
/** A wrapper for the SafetyCenterManager system service. */
public class SafetyCenterManagerWrapper {
/**
* Tag for logging.
*
* <p>The tag is restricted to 23 characters (the maximum allowed for Android logging).
*/
private static final String TAG = "SafetyCenterManagerWrap";
@VisibleForTesting
public static SafetyCenterManagerWrapper sInstance;
private SafetyCenterManagerWrapper() {}
/** Returns an instance of {@link SafetyCenterManagerWrapper}. */
public static SafetyCenterManagerWrapper get() {
if (sInstance == null) {
sInstance = new SafetyCenterManagerWrapper();
}
return sInstance;
}
/** Sets the latest safety source data for Safety Center. */
public void setSafetySourceData(Context context, String safetySourceId,
@Nullable SafetySourceData safetySourceData,
SafetyEvent safetyEvent) {
SafetyCenterManager safetyCenterManager =
context.getSystemService(SafetyCenterManager.class);
if (safetyCenterManager == null) {
Log.e(TAG, "System service SAFETY_CENTER_SERVICE (SafetyCenterManager) is null");
return;
}
try {
safetyCenterManager.setSafetySourceData(
safetySourceId,
safetySourceData,
safetyEvent
);
} catch (Exception e) {
Log.e(TAG, "Failed to send SafetySourceData", e);
return;
}
}
/** Returns true is SafetyCenter page is enabled, false otherwise. */
public boolean isEnabled(Context context) {
if (context == null) {
Log.e(TAG, "Context is null at SafetyCenterManagerWrapper#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;
}
}
}

View File

@@ -0,0 +1,158 @@
/*
* Copyright (C) 2023 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 static android.app.admin.DevicePolicyResources.Strings.Settings.CONNECTED_WORK_AND_PERSONAL_APPS_TITLE;
import static android.app.admin.DevicePolicyResources.Strings.Settings.FINGERPRINT_FOR_WORK;
import static android.app.admin.DevicePolicyResources.Strings.Settings.MANAGED_DEVICE_INFO;
import static android.app.admin.DevicePolicyResources.Strings.Settings.MANAGE_DEVICE_ADMIN_APPS;
import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_PROFILE_LOCKED_NOTIFICATION_TITLE;
import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_PROFILE_NOTIFICATIONS_SECTION_HEADER;
import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_PROFILE_PRIVACY_POLICY_INFO;
import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_PROFILE_PRIVACY_POLICY_INFO_SUMMARY;
import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_PROFILE_SECURITY_TITLE;
import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_PROFILE_SET_UNLOCK_LAUNCH_PICKER_TITLE;
import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_PROFILE_UNIFY_LOCKS_SUMMARY;
import android.content.Context;
import com.android.settings.R;
import com.android.settings.biometrics.combination.CombinedBiometricProfileStatusPreferenceController;
import com.android.settings.biometrics.face.FaceProfileStatusPreferenceController;
import com.android.settings.biometrics.fingerprint.FingerprintProfileStatusPreferenceController;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.notification.LockScreenNotificationPreferenceController;
import com.android.settings.privacy.PrivacyDashboardFragment;
import com.android.settings.security.ChangeProfileScreenLockPreferenceController;
import com.android.settings.security.LockUnificationPreferenceController;
import com.android.settings.security.trustagent.TrustAgentListPreferenceController;
import com.android.settings.widget.PreferenceCategoryController;
import com.android.settingslib.core.AbstractPreferenceController;
import java.util.ArrayList;
import java.util.List;
/** A class with helper method used in logic involving safety center. */
public final class SafetyCenterUtils {
private static final String WORK_PROFILE_SECURITY_CATEGORY = "work_profile_category";
private static final String KEY_LOCK_SCREEN_NOTIFICATIONS = "privacy_lock_screen_notifications";
private static final String KEY_WORK_PROFILE_CATEGORY =
"privacy_work_profile_notifications_category";
private static final String KEY_NOTIFICATION_WORK_PROFILE_NOTIFICATIONS =
"privacy_lock_screen_work_profile_notifications";
/**
* Returns preference controllers related to advanced security entries. This is used in {@link
* MoreSecurityPrivacyFragment} and {@link
* com.android.settings.security.SecurityAdvancedSettings}.
*/
public static List<AbstractPreferenceController> getControllersForAdvancedSecurity(
Context context,
com.android.settingslib.core.lifecycle.Lifecycle lifecycle,
DashboardFragment host) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
controllers.add(new TrustAgentListPreferenceController(context, host, lifecycle));
final List<AbstractPreferenceController> profileSecurityControllers = new ArrayList<>();
profileSecurityControllers.add(
new ChangeProfileScreenLockPreferenceController(context, host));
profileSecurityControllers.add(new LockUnificationPreferenceController(context, host));
profileSecurityControllers.add(new FaceProfileStatusPreferenceController(
context, lifecycle));
profileSecurityControllers.add(new FingerprintProfileStatusPreferenceController(
context, lifecycle));
profileSecurityControllers
.add(new CombinedBiometricProfileStatusPreferenceController(context, lifecycle));
controllers.add(new PreferenceCategoryController(context, WORK_PROFILE_SECURITY_CATEGORY)
.setChildren(profileSecurityControllers));
controllers.addAll(profileSecurityControllers);
return controllers;
}
/**
* Returns preference controllers for advanced privacy entries. This is used in {@link
* MoreSecurityPrivacyFragment} and {@link PrivacyDashboardFragment}.
*/
public static List<AbstractPreferenceController> getControllersForAdvancedPrivacy(
Context context, com.android.settingslib.core.lifecycle.Lifecycle lifecycle) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
final LockScreenNotificationPreferenceController notificationController =
new LockScreenNotificationPreferenceController(
context,
KEY_LOCK_SCREEN_NOTIFICATIONS,
KEY_WORK_PROFILE_CATEGORY,
KEY_NOTIFICATION_WORK_PROFILE_NOTIFICATIONS);
if (lifecycle != null) {
lifecycle.addObserver(notificationController);
}
controllers.add(notificationController);
return controllers;
}
/** Replaces relevant strings with their enterprise variants for the privacy entries. */
public static void replaceEnterpriseStringsForPrivacyEntries(
DashboardFragment dashboardFragment) {
dashboardFragment.replaceEnterpriseStringTitle(
"privacy_lock_screen_work_profile_notifications",
WORK_PROFILE_LOCKED_NOTIFICATION_TITLE,
R.string.locked_work_profile_notification_title);
dashboardFragment.replaceEnterpriseStringTitle(
"interact_across_profiles_privacy",
CONNECTED_WORK_AND_PERSONAL_APPS_TITLE,
R.string.interact_across_profiles_title);
dashboardFragment.replaceEnterpriseStringTitle(
"privacy_work_profile_notifications_category",
WORK_PROFILE_NOTIFICATIONS_SECTION_HEADER,
R.string.profile_section_header);
dashboardFragment.replaceEnterpriseStringTitle(
"work_policy_info",
WORK_PROFILE_PRIVACY_POLICY_INFO,
R.string.work_policy_privacy_settings);
dashboardFragment.replaceEnterpriseStringSummary(
"work_policy_info",
WORK_PROFILE_PRIVACY_POLICY_INFO_SUMMARY,
R.string.work_policy_privacy_settings_summary);
}
/** Replaces relevant strings with their enterprise variants for the security entries. */
public static void replaceEnterpriseStringsForSecurityEntries(
DashboardFragment dashboardFragment) {
dashboardFragment.replaceEnterpriseStringTitle(
"unlock_set_or_change_profile",
WORK_PROFILE_SET_UNLOCK_LAUNCH_PICKER_TITLE,
R.string.unlock_set_unlock_launch_picker_title_profile);
dashboardFragment.replaceEnterpriseStringSummary(
"unification",
WORK_PROFILE_UNIFY_LOCKS_SUMMARY,
R.string.lock_settings_profile_unification_summary);
dashboardFragment.replaceEnterpriseStringTitle(
"fingerprint_settings_profile",
FINGERPRINT_FOR_WORK,
R.string.security_settings_work_fingerprint_preference_title);
dashboardFragment.replaceEnterpriseStringTitle(
"manage_device_admin", MANAGE_DEVICE_ADMIN_APPS, R.string.manage_device_admin);
dashboardFragment.replaceEnterpriseStringTitle(
"security_category_profile",
WORK_PROFILE_SECURITY_TITLE,
R.string.lock_settings_profile_title);
dashboardFragment.replaceEnterpriseStringTitle(
"enterprise_privacy", MANAGED_DEVICE_INFO, R.string.enterprise_privacy_settings);
}
private SafetyCenterUtils() {}
}

View File

@@ -0,0 +1,95 @@
/*
* 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 static android.content.Intent.ACTION_BOOT_COMPLETED;
import static android.safetycenter.SafetyCenterManager.ACTION_REFRESH_SAFETY_SOURCES;
import static android.safetycenter.SafetyCenterManager.EXTRA_REFRESH_SAFETY_SOURCE_IDS;
import static android.safetycenter.SafetyEvent.SAFETY_EVENT_TYPE_DEVICE_REBOOTED;
import static android.safetycenter.SafetyEvent.SAFETY_EVENT_TYPE_REFRESH_REQUESTED;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.safetycenter.SafetyCenterManager;
import android.safetycenter.SafetyEvent;
import com.android.settings.privatespace.PrivateSpaceSafetySource;
import com.android.settings.security.ScreenLockPreferenceDetailsUtils;
import com.google.common.collect.ImmutableList;
import java.util.List;
/** Broadcast receiver for handling requests from Safety Center for fresh data. */
public class SafetySourceBroadcastReceiver extends BroadcastReceiver {
private static final SafetyEvent EVENT_DEVICE_REBOOTED =
new SafetyEvent.Builder(SAFETY_EVENT_TYPE_DEVICE_REBOOTED).build();
@Override
public void onReceive(Context context, Intent intent) {
if (!SafetyCenterManagerWrapper.get().isEnabled(context)) {
return;
}
if (ACTION_REFRESH_SAFETY_SOURCES.equals(intent.getAction())) {
String[] sourceIdsExtra =
intent.getStringArrayExtra(EXTRA_REFRESH_SAFETY_SOURCE_IDS);
final String refreshBroadcastId = intent.getStringExtra(
SafetyCenterManager.EXTRA_REFRESH_SAFETY_SOURCES_BROADCAST_ID);
if (sourceIdsExtra != null && sourceIdsExtra.length > 0 && refreshBroadcastId != null) {
final SafetyEvent safetyEvent = new SafetyEvent.Builder(
SAFETY_EVENT_TYPE_REFRESH_REQUESTED)
.setRefreshBroadcastId(refreshBroadcastId).build();
refreshSafetySources(
context,
ImmutableList.copyOf(sourceIdsExtra),
safetyEvent);
}
return;
}
if (ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
refreshAllSafetySources(context, EVENT_DEVICE_REBOOTED);
}
}
private static void refreshSafetySources(Context context, List<String> sourceIds,
SafetyEvent safetyEvent) {
if (sourceIds.contains(LockScreenSafetySource.SAFETY_SOURCE_ID)) {
LockScreenSafetySource.setSafetySourceData(context,
new ScreenLockPreferenceDetailsUtils(context), safetyEvent);
}
if (sourceIds.contains(BiometricsSafetySource.SAFETY_SOURCE_ID)) {
BiometricsSafetySource.setSafetySourceData(context, safetyEvent);
}
if (sourceIds.contains(PrivateSpaceSafetySource.SAFETY_SOURCE_ID)) {
PrivateSpaceSafetySource.setSafetySourceData(context, safetyEvent);
}
}
private static void refreshAllSafetySources(Context context, SafetyEvent safetyEvent) {
LockScreenSafetySource.setSafetySourceData(context,
new ScreenLockPreferenceDetailsUtils(context), safetyEvent);
BiometricsSafetySource.setSafetySourceData(context, safetyEvent);
PrivateSpaceSafetySource.setSafetySourceData(context, safetyEvent);
}
}

View File

@@ -0,0 +1,60 @@
/*
* 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.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.util.Log;
import androidx.preference.Preference;
import com.android.settings.core.BasePreferenceController;
/** Controller for the SafetyCenter entry in top level Settings. */
public class TopLevelSafetyCenterEntryPreferenceController extends BasePreferenceController {
private static final String TAG = "TopLevelSafetyCenterEntryPreferenceController";
public TopLevelSafetyCenterEntryPreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey);
}
@Override
public int getAvailabilityStatus() {
if (SafetyCenterManagerWrapper.get().isEnabled(mContext)) {
return AVAILABLE;
}
return CONDITIONALLY_UNAVAILABLE;
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) {
return super.handlePreferenceTreeClick(preference);
}
try {
mContext.startActivity(new Intent(Intent.ACTION_SAFETY_CENTER));
} catch (ActivityNotFoundException e) {
Log.e(TAG, "Unable to open safety center", e);
return false;
}
return true;
}
}