Introduce a NeededForTesting annotation.

This annotation can be used to mark those classes and methods that are
used by tests and that therefore should not be removed by ProGuard, even
if unused.

This is similar to VisibleForTesting annotation, but in this case, there
is increase of visibility, just happens that we do not currently use
those methods in the application code.

This fixes a number of failing tests in the continuous build. This
problem affects only userdebug builds, because eng builds do not run
ProGuard.

Bug: 5112827
Bug: 5131770
Change-Id: I13d06bc7bebb8f5d2d9ff515a5587b4f25bed5ac
diff --git a/proguard.flags b/proguard.flags
index 5a08b9f..f4ec4b2 100644
--- a/proguard.flags
+++ b/proguard.flags
@@ -24,3 +24,9 @@
 -keep class ** {
   *** *ForTest(...);
 }
+
+# Any class or method annotated with NeededForTesting.
+-keep @com.android.contacts.test.NeededForTesting class *
+-keepclassmembers class * {
+@com.android.contacts.test.NeededForTesting *;
+}
diff --git a/src/com/android/contacts/calllog/CallTypeIconsView.java b/src/com/android/contacts/calllog/CallTypeIconsView.java
index 4fbe7d7..e0242c8 100644
--- a/src/com/android/contacts/calllog/CallTypeIconsView.java
+++ b/src/com/android/contacts/calllog/CallTypeIconsView.java
@@ -17,6 +17,7 @@
 package com.android.contacts.calllog;
 
 import com.android.contacts.R;
+import com.android.contacts.test.NeededForTesting;
 import com.google.common.collect.Lists;
 
 import android.content.Context;
@@ -64,10 +65,12 @@
         invalidate();
     }
 
+    @NeededForTesting
     public int getCount() {
         return mCallTypes.size();
     }
 
+    @NeededForTesting
     public int getCallType(int index) {
         return mCallTypes.get(index);
     }
diff --git a/src/com/android/contacts/test/NeededForTesting.java b/src/com/android/contacts/test/NeededForTesting.java
new file mode 100644
index 0000000..f40fe2c
--- /dev/null
+++ b/src/com/android/contacts/test/NeededForTesting.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2011 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.
+ */
+
+package com.android.contacts.test;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Denotes that the class, constructor, method or field is used by tests and therefore cannot be
+ * removed by tools like ProGuard.
+ */
+@Retention(RetentionPolicy.CLASS)
+@Target({ElementType.TYPE, ElementType.CONSTRUCTOR, ElementType.METHOD, ElementType.FIELD})
+public @interface NeededForTesting {}
diff --git a/src/com/android/contacts/util/ExpirableCache.java b/src/com/android/contacts/util/ExpirableCache.java
index 0ee3bbe..196b03a 100644
--- a/src/com/android/contacts/util/ExpirableCache.java
+++ b/src/com/android/contacts/util/ExpirableCache.java
@@ -16,6 +16,8 @@
 
 package com.android.contacts.util;
 
+import com.android.contacts.test.NeededForTesting;
+
 import android.util.LruCache;
 
 import java.util.concurrent.atomic.AtomicInteger;
@@ -198,6 +200,7 @@
      *
      * @param key the key to look up
      */
+    @NeededForTesting
     public V get(K key) {
         CachedValue<V> cachedValue = getCachedValue(key);
         return cachedValue == null || cachedValue.isExpired() ? null : cachedValue.getValue();
diff --git a/src/com/android/contacts/util/StreamItemEntry.java b/src/com/android/contacts/util/StreamItemEntry.java
index dc54229..db15e3a 100644
--- a/src/com/android/contacts/util/StreamItemEntry.java
+++ b/src/com/android/contacts/util/StreamItemEntry.java
@@ -16,6 +16,8 @@
 
 package com.android.contacts.util;
 
+import com.android.contacts.test.NeededForTesting;
+
 import android.database.Cursor;
 import android.provider.ContactsContract.StreamItems;
 
@@ -46,6 +48,7 @@
     // Photos associated with this stream item.
     private List<StreamItemPhotoEntry> mPhotos;
 
+    @NeededForTesting
     public StreamItemEntry(long id, String text, String comments, long timestamp, String action,
             String actionUri, String resPackage, int iconRes, int labelRes) {
         mId = id;