Add accessibility info for bubble.

Bug: 62886248
Test: Manual with talkback enabled
PiperOrigin-RevId: 160349111
Change-Id: I9eaaac90b93b7e6f3a002288d0d68fbbe3fae56c
diff --git a/java/com/android/dialershared/bubble/Bubble.java b/java/com/android/dialershared/bubble/Bubble.java
index f2ba117..81e1dcb 100644
--- a/java/com/android/dialershared/bubble/Bubble.java
+++ b/java/com/android/dialershared/bubble/Bubble.java
@@ -31,6 +31,7 @@
 import android.net.Uri;
 import android.os.Build.VERSION;
 import android.os.Build.VERSION_CODES;
+import android.os.Bundle;
 import android.os.Handler;
 import android.provider.Settings;
 import android.support.annotation.ColorInt;
@@ -49,12 +50,15 @@
 import android.view.LayoutInflater;
 import android.view.MotionEvent;
 import android.view.View;
+import android.view.View.AccessibilityDelegate;
 import android.view.ViewGroup;
 import android.view.ViewGroup.MarginLayoutParams;
 import android.view.ViewPropertyAnimator;
 import android.view.ViewTreeObserver.OnPreDrawListener;
 import android.view.WindowManager;
 import android.view.WindowManager.LayoutParams;
+import android.view.accessibility.AccessibilityNodeInfo;
+import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction;
 import android.view.animation.AnticipateInterpolator;
 import android.view.animation.OvershootInterpolator;
 import android.widget.FrameLayout;
@@ -107,6 +111,38 @@
   private Integer overrideGravity;
   private ViewPropertyAnimator exitAnimator;
 
+  private final AccessibilityDelegate accessibilityDelegate =
+      new AccessibilityDelegate() {
+        @Override
+        public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) {
+          super.onInitializeAccessibilityNodeInfo(host, info);
+          if (textShowing) {
+            info.setContentDescription(viewHolder.getPrimaryText().getText());
+            return;
+          }
+          if (expanded) {
+            info.setContentDescription(currentInfo.getPrimaryContentDescription());
+            info.addAction(AccessibilityAction.ACTION_CLICK);
+          } else {
+            info.setContentDescription(currentInfo.getBubbleContentDescription());
+            info.addAction(
+                new AccessibilityAction(
+                    AccessibilityNodeInfo.ACTION_CLICK,
+                    host.getContext().getString(R.string.content_description_action_bubble_click)));
+          }
+          info.addAction(AccessibilityAction.ACTION_MOVE_WINDOW);
+        }
+
+        @Override
+        public boolean performAccessibilityAction(View host, int action, Bundle args) {
+          if (action == AccessibilityNodeInfo.ACTION_CLICK) {
+            primaryButtonClick();
+            return true;
+          }
+          return super.performAccessibilityAction(host, action, args);
+        }
+      };
+
   @Retention(RetentionPolicy.SOURCE)
   @IntDef({CollapseEnd.NOTHING, CollapseEnd.HIDE})
   private @interface CollapseEnd {
@@ -713,6 +749,8 @@
       secondButton = contentView.findViewById(R.id.bubble_icon_second);
       thirdButton = contentView.findViewById(R.id.bubble_icon_third);
 
+      primaryButton.setAccessibilityDelegate(accessibilityDelegate);
+
       root.setOnBackPressedListener(
           () -> {
             if (visibility == Visibility.SHOWING && expanded) {
diff --git a/java/com/android/dialershared/bubble/BubbleInfo.java b/java/com/android/dialershared/bubble/BubbleInfo.java
index eb9abd0..99875fe 100644
--- a/java/com/android/dialershared/bubble/BubbleInfo.java
+++ b/java/com/android/dialershared/bubble/BubbleInfo.java
@@ -28,6 +28,9 @@
 /** Info for displaying a {@link Bubble} */
 @AutoValue
 public abstract class BubbleInfo {
+  @NonNull
+  public abstract CharSequence getBubbleContentDescription();
+
   @ColorInt
   public abstract int getPrimaryColor();
 
@@ -35,6 +38,9 @@
   public abstract Icon getPrimaryIcon();
 
   @NonNull
+  public abstract CharSequence getPrimaryContentDescription();
+
+  @NonNull
   public abstract PendingIntent getPrimaryIntent();
 
   @Px
@@ -60,12 +66,16 @@
   @AutoValue.Builder
   public abstract static class Builder {
 
+    public abstract Builder setBubbleContentDescription(@NonNull CharSequence description);
+
     public abstract Builder setPrimaryColor(@ColorInt int primaryColor);
 
     public abstract Builder setPrimaryIcon(@NonNull Icon primaryIcon);
 
     public abstract Builder setPrimaryIntent(@NonNull PendingIntent primaryIntent);
 
+    public abstract Builder setPrimaryContentDescription(@NonNull CharSequence description);
+
     public abstract Builder setStartingYPosition(@Px int startingYPosition);
 
     public abstract Builder setActions(List<Action> actions);
diff --git a/java/com/android/dialershared/bubble/res/values/strings.xml b/java/com/android/dialershared/bubble/res/values/strings.xml
new file mode 100644
index 0000000..c686198
--- /dev/null
+++ b/java/com/android/dialershared/bubble/res/values/strings.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2017 The Android Open Source Project
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License
+  -->
+
+<resources>
+  <string name="content_description_action_bubble_click">Expand drawer</string>
+</resources>
diff --git a/java/com/android/incallui/ReturnToCallController.java b/java/com/android/incallui/ReturnToCallController.java
index 33154c5..c105e68 100644
--- a/java/com/android/incallui/ReturnToCallController.java
+++ b/java/com/android/incallui/ReturnToCallController.java
@@ -169,6 +169,10 @@
         .setStartingYPosition(
             context.getResources().getDimensionPixelOffset(R.dimen.return_to_call_initial_offset_y))
         .setPrimaryIntent(PendingIntent.getActivity(context, 0, activityIntent, 0))
+        .setBubbleContentDescription(
+            context.getText(R.string.content_description_return_to_call_bubble))
+        .setPrimaryContentDescription(
+            context.getText(R.string.content_description_return_to_call_primary))
         .setActions(generateActions())
         .build();
   }
diff --git a/java/com/android/incallui/res/values/strings.xml b/java/com/android/incallui/res/values/strings.xml
index 4113313..c694874 100644
--- a/java/com/android/incallui/res/values/strings.xml
+++ b/java/com/android/incallui/res/values/strings.xml
@@ -357,5 +357,7 @@
     data charges may apply.
   </string>
   <string name="video_call_lte_to_wifi_failed_do_not_show">Do not show this again</string>
+  <string name="content_description_return_to_call_bubble">Ongoing call</string>
+  <string name="content_description_return_to_call_primary">Return to call</string>
 
 </resources>