Merge changes I243417e1,I2a40fe87

* changes:
  Convert KeyChain robotests to Android.bp
  Use tip-of-tree robolectric
diff --git a/robotests/Android.bp b/robotests/Android.bp
new file mode 100644
index 0000000..b6a6f4e
--- /dev/null
+++ b/robotests/Android.bp
@@ -0,0 +1,13 @@
+//############################################################
+// KeyChain Robolectric test target.                         #
+//############################################################
+
+android_robolectric_test {
+    name: "KeyChainRoboTests",
+
+    srcs: ["src/**/*.java"],
+
+    java_resource_dirs: ["config"],
+
+    instrumentation_for: "KeyChain",
+}
diff --git a/robotests/Android.mk b/robotests/Android.mk
deleted file mode 100644
index dece0df..0000000
--- a/robotests/Android.mk
+++ /dev/null
@@ -1,45 +0,0 @@
-#############################################
-#     KeyChain Robolectric test target.     #
-#############################################
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := $(call all-java-files-under, src)
-
-# Include the testing libraries (JUnit4 + Robolectric libs).
-LOCAL_STATIC_JAVA_LIBRARIES := \
-    mockito-robolectric-prebuilt \
-    platform-robolectric-android-all-stubs \
-    truth-prebuilt
-
-LOCAL_JAVA_LIBRARIES := \
-    junit \
-    platform-robolectric-3.6.2-prebuilt \
-    telephony-common
-
-LOCAL_INSTRUMENTATION_FOR := KeyChain
-LOCAL_MODULE := KeyChainRoboTests
-
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_STATIC_JAVA_LIBRARY)
-
-#############################################################
-# Settings runner target to run the previous target. #
-#############################################################
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := RunKeyChainRoboTests
-
-LOCAL_SDK_VERSION := current
-
-LOCAL_STATIC_JAVA_LIBRARIES := \
-    KeyChainRoboTests
-
-LOCAL_TEST_PACKAGE := KeyChain
-
-LOCAL_INSTRUMENT_SOURCE_DIRS := $(dir $(LOCAL_PATH))../src
-
-LOCAL_ROBOTEST_TIMEOUT := 36000
-
-include prebuilts/misc/common/robolectric/3.6.2/run_robotests.mk
diff --git a/robotests/config/robolectric.properties b/robotests/config/robolectric.properties
new file mode 100644
index 0000000..41ee528
--- /dev/null
+++ b/robotests/config/robolectric.properties
@@ -0,0 +1,2 @@
+manifest=packages/apps/KeyChain/AndroidManifest.xml
+sdk=NEWEST_SDK
diff --git a/robotests/src/com/android/keychain/AliasLoaderTest.java b/robotests/src/com/android/keychain/AliasLoaderTest.java
index f2a05c8..13241fd 100644
--- a/robotests/src/com/android/keychain/AliasLoaderTest.java
+++ b/robotests/src/com/android/keychain/AliasLoaderTest.java
@@ -32,11 +32,9 @@
 import org.junit.runner.RunWith;
 import org.robolectric.RobolectricTestRunner;
 import org.robolectric.RuntimeEnvironment;
-import org.robolectric.annotation.Config;
 import org.robolectric.shadows.ShadowApplication;
 
 @RunWith(RobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
 public final class AliasLoaderTest {
     private KeyInfoProvider mDummyInfoProvider;
 
diff --git a/robotests/src/com/android/keychain/KeyChainServiceRoboTest.java b/robotests/src/com/android/keychain/KeyChainServiceRoboTest.java
index 147f1ca..984fc9f 100644
--- a/robotests/src/com/android/keychain/KeyChainServiceRoboTest.java
+++ b/robotests/src/com/android/keychain/KeyChainServiceRoboTest.java
@@ -56,11 +56,7 @@
 import javax.security.auth.x500.X500Principal;
 
 @RunWith(RobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
-        shadows = {
-                ShadowTrustedCertificateStore.class,
-                ShadowPackageManager.class,
-        })
+@Config(shadows = ShadowTrustedCertificateStore.class)
 public final class KeyChainServiceRoboTest {
     private IKeyChainService.Stub mKeyChain;
 
@@ -138,8 +134,8 @@
         try {
             mKeyChain.installCaCertificate(TEST_CA.getBytes());
             fail("didn't propagate the exception");
-        } catch (IllegalStateException ignored) {
-            assertTrue(ignored.getCause() instanceof IOException);
+        } catch (IllegalStateException expected) {
+            assertTrue(expected.getCause() instanceof IOException);
         }
 
         verify(mockInjector, times(1)).writeSecurityEvent(
@@ -186,8 +182,8 @@
         try {
             mKeyChain.installCaCertificate(TEST_CA.getBytes());
             fail("didn't propagate the exception");
-        } catch (IllegalStateException ignored) {
-            assertTrue(ignored.getCause() instanceof IOException);
+        } catch (IllegalStateException expected) {
+            assertTrue(expected.getCause() instanceof IOException);
         }
         mKeyChain.deleteCaCertificate("alias");
 
diff --git a/robotests/src/com/android/keychain/ShadowTrustedCertificateStore.java b/robotests/src/com/android/keychain/ShadowTrustedCertificateStore.java
index c78f2b4..ffee470 100644
--- a/robotests/src/com/android/keychain/ShadowTrustedCertificateStore.java
+++ b/robotests/src/com/android/keychain/ShadowTrustedCertificateStore.java
@@ -31,6 +31,7 @@
  */
 @Implements(TrustedCertificateStore.class)
 public class ShadowTrustedCertificateStore {
+
     public static TrustedCertificateStore sDelegate;
 
     @Implementation
@@ -49,9 +50,7 @@
     }
 
     @Implementation
-    public void deleteCertificateEntry(String alias)
-            throws IOException, CertificateException {
+    public void deleteCertificateEntry(String alias) throws IOException, CertificateException {
         sDelegate.deleteCertificateEntry(alias);
     }
 }
-
diff --git a/robotests/src/com/android/keychain/TestConfig.java b/robotests/src/com/android/keychain/TestConfig.java
deleted file mode 100644
index d31d2e5..0000000
--- a/robotests/src/com/android/keychain/TestConfig.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * 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.
- */
-
-package com.android.keychain;
-
-public class TestConfig {
-    public static final int SDK_VERSION = 26;
-    public static final String MANIFEST_PATH = "packages/apps/KeyChain/AndroidManifest.xml";
-}
diff --git a/robotests/src/com/android/keychain/internal/GrantsDatabaseTest.java b/robotests/src/com/android/keychain/internal/GrantsDatabaseTest.java
index 821cfe1..e5212da 100644
--- a/robotests/src/com/android/keychain/internal/GrantsDatabaseTest.java
+++ b/robotests/src/com/android/keychain/internal/GrantsDatabaseTest.java
@@ -24,14 +24,12 @@
 import android.content.pm.PackageManager;
 import android.database.sqlite.SQLiteDatabase;
 import android.database.sqlite.SQLiteOpenHelper;
-import com.android.keychain.TestConfig;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.robolectric.RobolectricTestRunner;
 import org.robolectric.RuntimeEnvironment;
-import org.robolectric.annotation.Config;
 
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -39,7 +37,6 @@
 
 /** Unit tests for {@link com.android.keychain.internal.GrantsDatabase}. */
 @RunWith(RobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
 public final class GrantsDatabaseTest {
     private static final String DUMMY_ALIAS = "dummy_alias";
     private static final String DUMMY_ALIAS2 = "another_dummy_alias";
@@ -48,12 +45,12 @@
     private static final int DUMMY_UID2 = 1001;
     // Constants duplicated from GrantsDatabase to make sure the upgrade tests catch if the
     // name of one of the fields in the DB changes.
-    static final String DATABASE_NAME = "grants.db";
-    static final String TABLE_GRANTS = "grants";
-    static final String GRANTS_ALIAS = "alias";
-    static final String GRANTS_GRANTEE_UID = "uid";
-    static final String TABLE_SELECTABLE = "userselectable";
-    static final String SELECTABLE_IS_SELECTABLE = "is_selectable";
+    private static final String DATABASE_NAME = "grants.db";
+    private static final String TABLE_GRANTS = "grants";
+    private static final String GRANTS_ALIAS = "alias";
+    private static final String GRANTS_GRANTEE_UID = "uid";
+    private static final String TABLE_SELECTABLE = "userselectable";
+    private static final String SELECTABLE_IS_SELECTABLE = "is_selectable";
 
     private GrantsDatabase mGrantsDB;
     private ExistingKeysProvider mKeysProvider;