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.data; 18 19 import android.annotation.UserIdInt; 20 import android.content.Context; 21 import android.safetycenter.SafetySourceData; 22 23 import androidx.annotation.Nullable; 24 25 import com.android.safetycenter.PendingIntentFactory; 26 import com.android.safetycenter.SafetyCenterConfigReader; 27 28 /** 29 * Applies various workarounds and fixes to {@link SafetySourceData} as it's received. 30 * 31 * @hide 32 */ 33 public final class SafetySourceDataFix { 34 35 private final DefaultActionOverrideFix mDefaultActionOverrideFix; 36 private Context mContext; 37 SafetySourceDataFix( Context context, PendingIntentFactory pendingIntentFactory, SafetyCenterConfigReader safetyCenterConfigReader)38 public SafetySourceDataFix( 39 Context context, 40 PendingIntentFactory pendingIntentFactory, 41 SafetyCenterConfigReader safetyCenterConfigReader) { 42 mContext = context; 43 mDefaultActionOverrideFix = 44 new DefaultActionOverrideFix( 45 context, pendingIntentFactory, safetyCenterConfigReader); 46 } 47 48 /** 49 * Potentially overrides the {@link SafetySourceData}. 50 * 51 * <p>Should be called when the data is received from a source and before it's stored by Safety 52 * Center. 53 */ 54 @Nullable maybeOverrideSafetySourceData( String sourceId, @Nullable SafetySourceData safetySourceData, String packageName, @UserIdInt int userId)55 public SafetySourceData maybeOverrideSafetySourceData( 56 String sourceId, 57 @Nullable SafetySourceData safetySourceData, 58 String packageName, 59 @UserIdInt int userId) { 60 if (safetySourceData == null) { 61 return null; 62 } 63 64 if (AndroidLockScreenFix.shouldApplyFix(sourceId)) { 65 safetySourceData = AndroidLockScreenFix.applyFix(mContext, safetySourceData); 66 } 67 68 if (DefaultActionOverrideFix.shouldApplyFix(sourceId)) { 69 safetySourceData = 70 mDefaultActionOverrideFix.applyFix( 71 sourceId, safetySourceData, packageName, userId); 72 } 73 74 return safetySourceData; 75 } 76 } 77