1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.safetycenter; 18 19 import static android.os.Build.VERSION_CODES.TIRAMISU; 20 21 import android.annotation.UserIdInt; 22 23 import androidx.annotation.RequiresApi; 24 25 import com.android.safetycenter.notifications.SafetyCenterNotificationSender; 26 27 import java.util.List; 28 29 import javax.annotation.concurrent.NotThreadSafe; 30 31 /** 32 * Knows how to update classes that need to know about any change in SafetyCenter data, which in 33 * this context entails any state change that happened in the data subpackage. 34 * 35 * @hide 36 */ 37 @RequiresApi(TIRAMISU) 38 @NotThreadSafe 39 public final class SafetyCenterDataChangeNotifier { 40 41 private final SafetyCenterNotificationSender mSafetyCenterNotificationSender; 42 private final SafetyCenterListeners mSafetyCenterListeners; 43 44 /** Initializes a new instance of {@link SafetyCenterDataChangeNotifier}. */ SafetyCenterDataChangeNotifier( SafetyCenterNotificationSender safetyCenterNotificationSender, SafetyCenterListeners safetyCenterListeners)45 SafetyCenterDataChangeNotifier( 46 SafetyCenterNotificationSender safetyCenterNotificationSender, 47 SafetyCenterListeners safetyCenterListeners) { 48 mSafetyCenterNotificationSender = safetyCenterNotificationSender; 49 mSafetyCenterListeners = safetyCenterListeners; 50 } 51 52 /** Updates classes that depend on data changes (changes of state in the data subpackage). */ updateDataConsumers(UserProfileGroup userProfileGroup, @UserIdInt int userId)53 public void updateDataConsumers(UserProfileGroup userProfileGroup, @UserIdInt int userId) { 54 mSafetyCenterNotificationSender.updateNotifications(userId); 55 mSafetyCenterListeners.deliverDataForUserProfileGroup(userProfileGroup); 56 } 57 58 /** Updates classes that depend on data changes (changes of state in the data subpackage). */ updateDataConsumers(UserProfileGroup userProfileGroup)59 void updateDataConsumers(UserProfileGroup userProfileGroup) { 60 mSafetyCenterNotificationSender.updateNotifications(userProfileGroup); 61 mSafetyCenterListeners.deliverDataForUserProfileGroup(userProfileGroup); 62 } 63 64 /** Updates classes that depend on data changes (changes of state in the data subpackage). */ updateDataConsumers(List<UserProfileGroup> userProfileGroups)65 void updateDataConsumers(List<UserProfileGroup> userProfileGroups) { 66 for (int i = 0; i < userProfileGroups.size(); i++) { 67 updateDataConsumers(userProfileGroups.get(i)); 68 } 69 } 70 } 71