Test: atest SettingsUnitTests Bug: 222679576 Change-Id: I52ba3aff3045a8211fc936240f1310da6fad9fb0
93 lines
3.8 KiB
Java
93 lines
3.8 KiB
Java
/*
|
|
* 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.app.settings.SettingsEnums;
|
|
import android.content.BroadcastReceiver;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.safetycenter.SafetyCenterManager;
|
|
import android.safetycenter.SafetyEvent;
|
|
|
|
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);
|
|
if (sourceIdsExtra != null && sourceIdsExtra.length > 0) {
|
|
final String refreshBroadcastId = intent.getStringExtra(
|
|
SafetyCenterManager.EXTRA_REFRESH_SAFETY_SOURCES_BROADCAST_ID);
|
|
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, SettingsEnums.SAFETY_CENTER),
|
|
safetyEvent);
|
|
}
|
|
|
|
if (sourceIds.contains(BiometricsSafetySource.SAFETY_SOURCE_ID)) {
|
|
BiometricsSafetySource.setSafetySourceData(context, safetyEvent);
|
|
}
|
|
}
|
|
|
|
private static void refreshAllSafetySources(Context context, SafetyEvent safetyEvent) {
|
|
LockScreenSafetySource.setSafetySourceData(context,
|
|
new ScreenLockPreferenceDetailsUtils(context, SettingsEnums.SAFETY_CENTER),
|
|
safetyEvent);
|
|
BiometricsSafetySource.setSafetySourceData(context, safetyEvent);
|
|
}
|
|
}
|