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 android.annotation.UserIdInt; 20 21 import com.android.safetycenter.notifications.SafetyCenterNotificationSender; 22 23 import java.util.List; 24 25 import javax.annotation.concurrent.NotThreadSafe; 26 27 /** 28 * Knows how to update classes that need to know about any change in SafetyCenter data, which in 29 * this context entails any state change that happened in the data subpackage. 30 * 31 * @hide 32 */ 33 @NotThreadSafe 34 public final class SafetyCenterDataChangeNotifier { 35 36 private final SafetyCenterNotificationSender mSafetyCenterNotificationSender; 37 private final SafetyCenterListeners mSafetyCenterListeners; 38 39 /** Initializes a new instance of {@link SafetyCenterDataChangeNotifier}. */ SafetyCenterDataChangeNotifier( SafetyCenterNotificationSender safetyCenterNotificationSender, SafetyCenterListeners safetyCenterListeners)40 SafetyCenterDataChangeNotifier( 41 SafetyCenterNotificationSender safetyCenterNotificationSender, 42 SafetyCenterListeners safetyCenterListeners) { 43 mSafetyCenterNotificationSender = safetyCenterNotificationSender; 44 mSafetyCenterListeners = safetyCenterListeners; 45 } 46 47 /** Updates classes that depend on data changes (changes of state in the data subpackage). */ updateDataConsumers(UserProfileGroup userProfileGroup, @UserIdInt int userId)48 public void updateDataConsumers(UserProfileGroup userProfileGroup, @UserIdInt int userId) { 49 mSafetyCenterNotificationSender.updateNotifications(userId); 50 mSafetyCenterListeners.deliverDataForUserProfileGroup(userProfileGroup); 51 } 52 53 /** Updates classes that depend on data changes (changes of state in the data subpackage). */ updateDataConsumers(UserProfileGroup userProfileGroup)54 void updateDataConsumers(UserProfileGroup userProfileGroup) { 55 mSafetyCenterNotificationSender.updateNotifications(userProfileGroup); 56 mSafetyCenterListeners.deliverDataForUserProfileGroup(userProfileGroup); 57 } 58 59 /** Updates classes that depend on data changes (changes of state in the data subpackage). */ updateDataConsumers(List<UserProfileGroup> userProfileGroups)60 void updateDataConsumers(List<UserProfileGroup> userProfileGroups) { 61 for (int i = 0; i < userProfileGroups.size(); i++) { 62 updateDataConsumers(userProfileGroups.get(i)); 63 } 64 } 65 } 66