Allow updating enteprise strings in Dialer

Bug: 211422509
Bug: 188410712
Test: manual
Change-Id: I07d8b323d0e39a7f85ccb0a3ff39778c73defabf
diff --git a/java/com/android/dialer/app/calllog/MissedCallNotifier.java b/java/com/android/dialer/app/calllog/MissedCallNotifier.java
index 4b5bfba..ffa92d9 100644
--- a/java/com/android/dialer/app/calllog/MissedCallNotifier.java
+++ b/java/com/android/dialer/app/calllog/MissedCallNotifier.java
@@ -15,9 +15,12 @@
  */
 package com.android.dialer.app.calllog;
 
+import static android.app.admin.DevicePolicyResources.Strings.Dialer.NOTIFICATION_MISSED_WORK_CALL_TITLE;
+
 import android.app.Notification;
 import android.app.Notification.Builder;
 import android.app.PendingIntent;
+import android.app.admin.DevicePolicyManager;
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
@@ -107,7 +110,7 @@
   void updateMissedCallNotification(int count, @Nullable String number) {
     LogUtil.enterBlock("MissedCallNotifier.updateMissedCallNotification");
 
-    final int titleResId;
+    final String titleText;
     CharSequence expandedText; // The text in the notification's line 1 and 2.
 
     List<NewCall> newCalls = callLogNotificationsQueryHelper.getNewMissedCalls();
@@ -168,10 +171,13 @@
       ContactInfo contactInfo =
           callLogNotificationsQueryHelper.getContactInfo(
               call.number, call.numberPresentation, call.countryIso);
-      titleResId =
-          contactInfo.userType == ContactsUtils.USER_TYPE_WORK
-              ? R.string.notification_missedWorkCallTitle
-              : R.string.notification_missedCallTitle;
+      if (contactInfo.userType == ContactsUtils.USER_TYPE_WORK) {
+        titleText = context.getSystemService(DevicePolicyManager.class).getString(
+                NOTIFICATION_MISSED_WORK_CALL_TITLE,
+                () -> context.getString(R.string.notification_missedWorkCallTitle));
+      } else {
+        titleText = context.getString(R.string.notification_missedCallTitle);
+      }
 
       if (TextUtils.equals(contactInfo.name, contactInfo.formattedNumber)
           || TextUtils.equals(contactInfo.name, contactInfo.number)) {
@@ -189,7 +195,7 @@
         groupSummary.setLargeIcon(photoIcon);
       }
     } else {
-      titleResId = R.string.notification_missedCallsTitle;
+      titleText = context.getString(R.string.notification_missedCallsTitle);
       expandedText = context.getString(R.string.notification_missedCallsMsg, count);
     }
 
@@ -199,14 +205,14 @@
     // notification content is hidden.
     Notification.Builder publicSummaryBuilder = createNotificationBuilder();
     publicSummaryBuilder
-        .setContentTitle(context.getText(titleResId))
+        .setContentTitle(titleText)
         .setContentIntent(createCallLogPendingIntent())
         .setDeleteIntent(
             CallLogNotificationsService.createCancelAllMissedCallsPendingIntent(context));
 
     // Create the notification summary suitable for display when sensitive information is showing.
     groupSummary
-        .setContentTitle(context.getText(titleResId))
+        .setContentTitle(titleText)
         .setContentText(expandedText)
         .setContentIntent(createCallLogPendingIntent())
         .setDeleteIntent(
diff --git a/java/com/android/incallui/StatusBarNotifier.java b/java/com/android/incallui/StatusBarNotifier.java
index 99ff725..c689fdb 100644
--- a/java/com/android/incallui/StatusBarNotifier.java
+++ b/java/com/android/incallui/StatusBarNotifier.java
@@ -16,6 +16,9 @@
 
 package com.android.incallui;
 
+import static android.app.admin.DevicePolicyResources.Strings.Dialer.NOTIFICATION_INCOMING_WORK_CALL_TITLE;
+import static android.app.admin.DevicePolicyResources.Strings.Dialer.NOTIFICATION_ONGOING_WORK_CALL_TITLE;
+import static android.app.admin.DevicePolicyResources.Strings.Dialer.NOTIFICATION_WIFI_WORK_CALL_LABEL;
 import static android.telecom.Call.Details.PROPERTY_HIGH_DEF_AUDIO;
 import static com.android.contacts.common.compat.CallCompat.Details.PROPERTY_ENTERPRISE_CALL;
 import static com.android.incallui.NotificationBroadcastReceiver.ACTION_ACCEPT_VIDEO_UPGRADE_REQUEST;
@@ -31,6 +34,7 @@
 import android.Manifest;
 import android.app.Notification;
 import android.app.PendingIntent;
+import android.app.admin.DevicePolicyManager;
 import android.content.Context;
 import android.content.Intent;
 import android.content.res.Resources;
@@ -677,6 +681,10 @@
         call.getState() == DialerCallState.INCOMING
             || call.getState() == DialerCallState.CALL_WAITING;
 
+    // Is the call placed through work connection service.
+    boolean isWorkCall = call.hasProperty(PROPERTY_ENTERPRISE_CALL)
+            || userType == ContactsUtils.USER_TYPE_WORK;
+
     if (isIncomingOrWaiting
         && call.getNumberPresentation() == TelecomManager.PRESENTATION_ALLOWED) {
 
@@ -687,54 +695,73 @@
       }
     }
 
-    int resId = R.string.notification_ongoing_call;
-    String wifiBrand = context.getString(R.string.notification_call_wifi_brand);
+
+    String message = getOngoingCallNotificationMessage(isWorkCall);
+    String wifiBrand = getWifiBrand(isWorkCall);
+
+    // TODO(a bug): Potentially apply this template logic everywhere.
     if (call.hasProperty(Details.PROPERTY_WIFI)) {
-      resId = R.string.notification_ongoing_call_wifi_template;
+      message = context.getString(R.string.notification_ongoing_call_wifi_template, wifiBrand);
     }
 
     if (isIncomingOrWaiting) {
       if (call.isSpam()) {
-        resId = R.string.notification_incoming_spam_call;
+        message = context.getString(R.string.notification_incoming_spam_call);
       } else if (shouldShowEnrichedCallNotification(call.getEnrichedCallSession())) {
-        resId = getECIncomingCallText(call.getEnrichedCallSession());
+        message = context.getString(getECIncomingCallText(call.getEnrichedCallSession()));
       } else if (call.hasProperty(Details.PROPERTY_WIFI)) {
-        resId = R.string.notification_incoming_call_wifi_template;
+        message = context.getString(R.string.notification_incoming_call_wifi_template, wifiBrand);
       } else if (call.getAccountHandle() != null && hasMultiplePhoneAccounts(call)) {
         return getMultiSimIncomingText(call);
       } else if (call.isVideoCall()) {
-        resId = R.string.notification_incoming_video_call;
+        message = context.getString(R.string.notification_incoming_video_call);
       } else {
-        resId = R.string.notification_incoming_call;
+        message = getIncomingCallNotificationMessage(isWorkCall);
       }
     } else if (call.getState() == DialerCallState.ONHOLD) {
-      resId = R.string.notification_on_hold;
+      message = context.getString(R.string.notification_on_hold);
     } else if (DialerCallState.isDialing(call.getState())) {
-      resId = R.string.notification_dialing;
+      message = context.getString(R.string.notification_dialing);
     } else if (call.isVideoCall()) {
-      resId =
-          call.getVideoTech().isPaused()
+      message = context.getString(call.getVideoTech().isPaused()
               ? R.string.notification_ongoing_paused_video_call
-              : R.string.notification_ongoing_video_call;
+              : R.string.notification_ongoing_video_call);
     } else if (call.getVideoTech().getSessionModificationState()
         == SessionModificationState.RECEIVED_UPGRADE_TO_VIDEO_REQUEST) {
-      resId = R.string.notification_requesting_video_call;
+      message = context.getString(R.string.notification_requesting_video_call);
     }
 
-    // Is the call placed through work connection service.
-    boolean isWorkCall = call.hasProperty(PROPERTY_ENTERPRISE_CALL);
-    if (userType == ContactsUtils.USER_TYPE_WORK || isWorkCall) {
-      resId = getWorkStringFromPersonalString(resId);
-      wifiBrand = context.getString(R.string.notification_call_wifi_work_brand);
-    }
+    return message;
+  }
 
-    if (resId == R.string.notification_incoming_call_wifi_template
-        || resId == R.string.notification_ongoing_call_wifi_template) {
-      // TODO(a bug): Potentially apply this template logic everywhere.
-      return context.getString(resId, wifiBrand);
+  private String getOngoingCallNotificationMessage(boolean isWorkCall) {
+    if (isWorkCall) {
+      DevicePolicyManager dpm = context.getSystemService(DevicePolicyManager.class);
+      return dpm.getString(NOTIFICATION_ONGOING_WORK_CALL_TITLE, () ->
+              context.getString(R.string.notification_ongoing_work_call));
+    } else {
+      return context.getString(R.string.notification_ongoing_call);
     }
+  }
 
-    return context.getString(resId);
+  private String getIncomingCallNotificationMessage(boolean isWorkCall) {
+    if (isWorkCall) {
+      DevicePolicyManager dpm = context.getSystemService(DevicePolicyManager.class);
+      return dpm.getString(NOTIFICATION_INCOMING_WORK_CALL_TITLE, () ->
+              context.getString(R.string.notification_incoming_work_call));
+    } else {
+      return context.getString(R.string.notification_incoming_call);
+    }
+  }
+
+  private String getWifiBrand(boolean isWorkCall) {
+    if (isWorkCall) {
+      DevicePolicyManager dpm = context.getSystemService(DevicePolicyManager.class);
+      return dpm.getString(NOTIFICATION_WIFI_WORK_CALL_LABEL, () ->
+              context.getString(R.string.notification_call_wifi_work_brand));
+    } else {
+      return context.getString(R.string.notification_call_wifi_brand);
+    }
   }
 
   private boolean shouldShowEnrichedCallNotification(Session session) {