Do not redact OTPs when device is fully managed

Test: atest SmsTest, SmsManagerTest
Bug: 351976749
Flag: com.android.internal.telephony.flags.redact_otp_sms
Change-Id: I24de78022b264c1580c82d0027f977607e9b9e70
diff --git a/src/com/android/providers/telephony/SmsProvider.java b/src/com/android/providers/telephony/SmsProvider.java
index efcfe48..e26f8ed 100644
--- a/src/com/android/providers/telephony/SmsProvider.java
+++ b/src/com/android/providers/telephony/SmsProvider.java
@@ -446,7 +446,8 @@
 
         try {
             Trace.beginSection("SmsProvider_query_otpSection");
-            if (Flags.redactOtpSms() && qb.getTables().startsWith(smsTable)
+            if (Telephony.Sms.isOtpRedactionEnabled(getContext())
+                    && qb.getTables().startsWith(smsTable)
                     && !canReadOtpSms(callingUid, callingPackage)) {
                 // If this app can't read OTP messages, only return messages without OTPs, or
                 // messages more than the threshold old, or messages still pending classification,
@@ -891,7 +892,7 @@
                 // Determine if incoming messages contain an OTP code
                 String message = values.getAsString(Sms.BODY);
                 int otpType;
-                if (Telephony.Sms.shouldCheckForOtp(message)) {
+                if (Telephony.Sms.shouldCheckForOtp(getContext(), message)) {
                     otpType = Telephony.Sms.OTP_TYPE_PENDING;
                     possibleOtpMessage = message;
                 } else {
diff --git a/tests/src/com/android/providers/telephony/SmsProviderTest.java b/tests/src/com/android/providers/telephony/SmsProviderTest.java
index f7b1039..d071466 100644
--- a/tests/src/com/android/providers/telephony/SmsProviderTest.java
+++ b/tests/src/com/android/providers/telephony/SmsProviderTest.java
@@ -24,6 +24,7 @@
 import static org.mockito.Mockito.when;
 
 import android.app.AppOpsManager;
+import android.app.admin.DevicePolicyManager;
 import android.content.ContentValues;
 import android.content.Context;
 import android.content.pm.PackageManager;
@@ -110,6 +111,8 @@
                 .thenReturn(mock(AppOpsManager.class));
         when(mContext.getSystemService(eq(Context.TELEPHONY_SERVICE)))
                 .thenReturn(mock(TelephonyManager.class));
+        when(mContext.getSystemService(eq(Context.DEVICE_POLICY_SERVICE)))
+                .thenReturn(mock(DevicePolicyManager.class));
 
         when(mContext.checkCallingOrSelfPermission(anyString()))
                 .thenReturn(PackageManager.PERMISSION_GRANTED);