Set incall button color to match sim color.

This change also add a handy adb command script run before UI integration test.

Bug: 67429956
Test: IncallActivityTest
PiperOrigin-RevId: 173565382
Change-Id: I9b8b957f00a0b7d11dbb7f40e8c9f1dbdb8c3928
diff --git a/common_fixture_script.sh b/common_fixture_script.sh
new file mode 100644
index 0000000..a7e527d
--- /dev/null
+++ b/common_fixture_script.sh
@@ -0,0 +1,4 @@
+# This file runs before emulator integration tests .
+# It utilizes adb shell commands to prepare test environment.
+
+setprop log.tag.Dialer VERBOSE
diff --git a/java/com/android/incallui/CallButtonPresenter.java b/java/com/android/incallui/CallButtonPresenter.java
index aa96c4f..cc95f7b 100644
--- a/java/com/android/incallui/CallButtonPresenter.java
+++ b/java/com/android/incallui/CallButtonPresenter.java
@@ -412,7 +412,8 @@
     }
 
     if (call != null) {
-      mInCallButtonUi.updateInCallButtonUiColors();
+      mInCallButtonUi.updateInCallButtonUiColors(
+          InCallPresenter.getInstance().getThemeColorManager().getSecondaryColor());
     }
 
     final boolean isEnabled =
@@ -559,5 +560,4 @@
     }
     return null;
   }
-
 }
diff --git a/java/com/android/incallui/InCallPresenter.java b/java/com/android/incallui/InCallPresenter.java
index 8535cbc..ed7b2c2 100644
--- a/java/com/android/incallui/InCallPresenter.java
+++ b/java/com/android/incallui/InCallPresenter.java
@@ -357,8 +357,10 @@
     mProximitySensor = proximitySensor;
     addListener(mProximitySensor);
 
-    mThemeColorManager =
-        new ThemeColorManager(new InCallUIMaterialColorMapUtils(mContext.getResources()));
+    if (mThemeColorManager == null) {
+      mThemeColorManager =
+          new ThemeColorManager(new InCallUIMaterialColorMapUtils(mContext.getResources()));
+    }
 
     mCallList = callList;
     mExternalCallList = externalCallList;
@@ -1651,6 +1653,11 @@
     return mThemeColorManager;
   }
 
+  @VisibleForTesting
+  public void setThemeColorManager(ThemeColorManager themeColorManager) {
+    mThemeColorManager = themeColorManager;
+  }
+
   /** Called when the foreground call changes. */
   public void onForegroundCallChanged(DialerCall newForegroundCall) {
     mThemeColorManager.onForegroundCallChanged(mContext, newForegroundCall);
diff --git a/java/com/android/incallui/ThemeColorManager.java b/java/com/android/incallui/ThemeColorManager.java
index a88ae33..1d4c287 100644
--- a/java/com/android/incallui/ThemeColorManager.java
+++ b/java/com/android/incallui/ThemeColorManager.java
@@ -57,14 +57,16 @@
 
   public void onForegroundCallChanged(Context context, @Nullable DialerCall newForegroundCall) {
     if (newForegroundCall == null) {
-      updateThemeColors(context, pendingPhoneAccountHandle, false);
+      updateThemeColors(context, getHighlightColor(context, pendingPhoneAccountHandle), false);
     } else {
-      updateThemeColors(context, newForegroundCall.getAccountHandle(), newForegroundCall.isSpam());
+      updateThemeColors(
+          context,
+          getHighlightColor(context, newForegroundCall.getAccountHandle()),
+          newForegroundCall.isSpam());
     }
   }
 
-  private void updateThemeColors(
-      Context context, @Nullable PhoneAccountHandle handle, boolean isSpam) {
+  private void updateThemeColors(Context context, @ColorInt int highlightColor, boolean isSpam) {
     MaterialPalette palette;
     if (isSpam) {
       palette =
@@ -74,7 +76,6 @@
       backgroundColorBottom = context.getColor(R.color.incall_background_gradient_spam_bottom);
       backgroundColorSolid = context.getColor(R.color.incall_background_multiwindow_spam);
     } else {
-      @ColorInt int highlightColor = getHighlightColor(context, handle);
       palette = colorMap.calculatePrimaryAndSecondaryColor(highlightColor);
       backgroundColorTop = context.getColor(R.color.incall_background_gradient_top);
       backgroundColorMiddle = context.getColor(R.color.incall_background_gradient_middle);
@@ -95,7 +96,7 @@
   }
 
   @ColorInt
-  private static int getHighlightColor(Context context, @Nullable PhoneAccountHandle handle) {
+  private int getHighlightColor(Context context, @Nullable PhoneAccountHandle handle) {
     if (handle != null) {
       PhoneAccount account = context.getSystemService(TelecomManager.class).getPhoneAccount(handle);
       if (account != null) {
diff --git a/java/com/android/incallui/incall/impl/CheckableLabeledButton.java b/java/com/android/incallui/incall/impl/CheckableLabeledButton.java
index a681adc..325c3a9 100644
--- a/java/com/android/incallui/incall/impl/CheckableLabeledButton.java
+++ b/java/com/android/incallui/incall/impl/CheckableLabeledButton.java
@@ -18,11 +18,14 @@
 
 import android.animation.AnimatorInflater;
 import android.content.Context;
+import android.content.res.ColorStateList;
 import android.content.res.TypedArray;
+import android.graphics.Color;
 import android.graphics.PorterDuff.Mode;
 import android.graphics.drawable.Drawable;
 import android.os.Parcel;
 import android.os.Parcelable;
+import android.support.annotation.ColorInt;
 import android.support.annotation.DrawableRes;
 import android.support.annotation.StringRes;
 import android.text.TextUtils.TruncateAt;
@@ -88,6 +91,7 @@
     iconView.setImageDrawable(icon);
     iconView.setImageTintMode(Mode.SRC_IN);
     iconView.setImageTintList(getResources().getColorStateList(R.color.incall_button_icon, null));
+
     iconView.setBackground(getResources().getDrawable(R.drawable.incall_button_background, null));
     iconView.setDuplicateParentStateEnabled(true);
     iconView.setElevation(getResources().getDimension(R.dimen.incall_button_elevation));
@@ -124,6 +128,13 @@
     labelView.setAlpha(isEnabled() ? 1f : DISABLED_STATE_OPACITY);
   }
 
+  public void setCheckedColor(@ColorInt int color) {
+    iconView.setImageTintList(
+        new ColorStateList(
+            new int[][] {new int[] {android.R.attr.state_checked}, new int[] {}},
+            new int[] {color, Color.WHITE}));
+  }
+
   public void setIconDrawable(@DrawableRes int drawableRes) {
     iconView.setImageResource(drawableRes);
   }
diff --git a/java/com/android/incallui/incall/impl/InCallButtonGridFragment.java b/java/com/android/incallui/incall/impl/InCallButtonGridFragment.java
index db0b5b9..a0eead1 100644
--- a/java/com/android/incallui/incall/impl/InCallButtonGridFragment.java
+++ b/java/com/android/incallui/incall/impl/InCallButtonGridFragment.java
@@ -17,6 +17,7 @@
 package com.android.incallui.incall.impl;
 
 import android.os.Bundle;
+import android.support.annotation.ColorInt;
 import android.support.annotation.Nullable;
 import android.support.v4.app.Fragment;
 import android.util.ArraySet;
@@ -127,6 +128,12 @@
     return numVisibleButtons;
   }
 
+  public void updateButtonColor(@ColorInt int color) {
+    for (CheckableLabeledButton button : buttons) {
+      button.setCheckedColor(color);
+    }
+  }
+
   /** Interface to let the listener know the status of the button grid. */
   public interface OnButtonGridCreatedListener {
     void onButtonGridCreated(InCallButtonGridFragment inCallButtonGridFragment);
diff --git a/java/com/android/incallui/incall/impl/InCallFragment.java b/java/com/android/incallui/incall/impl/InCallFragment.java
index e96060c..ddad61d 100644
--- a/java/com/android/incallui/incall/impl/InCallFragment.java
+++ b/java/com/android/incallui/incall/impl/InCallFragment.java
@@ -23,6 +23,7 @@
 import android.os.Build.VERSION_CODES;
 import android.os.Bundle;
 import android.os.Handler;
+import android.support.annotation.ColorInt;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import android.support.v4.app.Fragment;
@@ -476,7 +477,9 @@
   }
 
   @Override
-  public void updateInCallButtonUiColors() {}
+  public void updateInCallButtonUiColors(@ColorInt int color) {
+    inCallButtonGridFragment.updateButtonColor(color);
+  }
 
   @Override
   public Fragment getInCallButtonUiFragment() {
diff --git a/java/com/android/incallui/incall/protocol/InCallButtonUi.java b/java/com/android/incallui/incall/protocol/InCallButtonUi.java
index 96d741a..28dd84c 100644
--- a/java/com/android/incallui/incall/protocol/InCallButtonUi.java
+++ b/java/com/android/incallui/incall/protocol/InCallButtonUi.java
@@ -16,6 +16,7 @@
 
 package com.android.incallui.incall.protocol;
 
+import android.support.annotation.ColorInt;
 import android.support.v4.app.Fragment;
 import android.telecom.CallAudioState;
 
@@ -42,7 +43,7 @@
    */
   void updateButtonStates();
 
-  void updateInCallButtonUiColors();
+  void updateInCallButtonUiColors(@ColorInt int color);
 
   Fragment getInCallButtonUiFragment();
 
diff --git a/java/com/android/incallui/video/impl/SurfaceViewVideoCallFragment.java b/java/com/android/incallui/video/impl/SurfaceViewVideoCallFragment.java
index 95bdd6b..631cc1d 100644
--- a/java/com/android/incallui/video/impl/SurfaceViewVideoCallFragment.java
+++ b/java/com/android/incallui/video/impl/SurfaceViewVideoCallFragment.java
@@ -22,6 +22,7 @@
 import android.graphics.Point;
 import android.graphics.drawable.Animatable;
 import android.os.Bundle;
+import android.support.annotation.ColorInt;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import android.support.annotation.VisibleForTesting;
@@ -804,7 +805,7 @@
   }
 
   @Override
-  public void updateInCallButtonUiColors() {}
+  public void updateInCallButtonUiColors(@ColorInt int color) {}
 
   @Override
   public Fragment getInCallButtonUiFragment() {
diff --git a/java/com/android/incallui/video/impl/VideoCallFragment.java b/java/com/android/incallui/video/impl/VideoCallFragment.java
index a3614c0..0793d18 100644
--- a/java/com/android/incallui/video/impl/VideoCallFragment.java
+++ b/java/com/android/incallui/video/impl/VideoCallFragment.java
@@ -30,6 +30,7 @@
 import android.renderscript.Element;
 import android.renderscript.RenderScript;
 import android.renderscript.ScriptIntrinsicBlur;
+import android.support.annotation.ColorInt;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import android.support.annotation.VisibleForTesting;
@@ -845,7 +846,7 @@
   }
 
   @Override
-  public void updateInCallButtonUiColors() {}
+  public void updateInCallButtonUiColors(@ColorInt int color) {}
 
   @Override
   public Fragment getInCallButtonUiFragment() {