Add SettingsContextualCardProvider

- provide contextual cards for SettingsIntelligence
- add contextualcards libs

Fixes: 116837093
Test: make RunSettingsRoboTests ROBOTEST_FILTER="com.android.settings.homepage.contextualcards"

Change-Id: I873e77fa43e9a8f6056be1f583b1910002efbd2e
diff --git a/Android.mk b/Android.mk
index 6b0d077..f10b3ec 100644
--- a/Android.mk
+++ b/Android.mk
@@ -41,6 +41,7 @@
     androidx.lifecycle_lifecycle-extensions \
     guava \
     jsr305 \
+    contextualcards \
     settings-logtags \
 
 LOCAL_PROGUARD_FLAG_FILES := proguard.flags
@@ -57,7 +58,14 @@
 
 include $(BUILD_PACKAGE)
 
+# ====  prebuilt library  ========================
+include $(CLEAR_VARS)
+
+LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := \
+    contextualcards:libs/contextualcards.aar
+include $(BUILD_MULTI_PREBUILT)
+
 # Use the following include to make our test apk.
 ifeq (,$(ONE_SHOT_MAKEFILE))
 include $(call all-makefiles-under,$(LOCAL_PATH))
-endif
+endif
\ No newline at end of file
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index aa53bdb..94be61c 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -3192,6 +3192,15 @@
             android:exported="true"
             android:permission="android.permission.WRITE_SETTINGS_HOMEPAGE_DATA" />
 
+        <provider
+            android:name=".homepage.contextualcards.SettingsContextualCardProvider"
+            android:authorities="com.android.settings.homepage.contextualcards"
+            android:permission="android.permission.WRITE_SETTINGS_HOMEPAGE_DATA"
+            android:exported="true">
+            <intent-filter>
+                <action android:name="android.content.action.SETTINGS_HOMEPAGE_DATA"/>
+            </intent-filter>
+        </provider>
         <!-- This is the longest AndroidManifest.xml ever. -->
     </application>
 </manifest>
diff --git a/libs/contextualcards.aar b/libs/contextualcards.aar
new file mode 100755
index 0000000..a44a26c
--- /dev/null
+++ b/libs/contextualcards.aar
Binary files differ
diff --git a/src/com/android/settings/homepage/contextualcards/SettingsContextualCardProvider.java b/src/com/android/settings/homepage/contextualcards/SettingsContextualCardProvider.java
new file mode 100644
index 0000000..44705c5
--- /dev/null
+++ b/src/com/android/settings/homepage/contextualcards/SettingsContextualCardProvider.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2018 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.settings.homepage.contextualcards;
+
+import static android.provider.SettingsSlicesContract.KEY_WIFI;
+
+import android.annotation.Nullable;
+
+import com.android.settings.homepage.deviceinfo.DataUsageSlice;
+import com.android.settings.wifi.WifiSlice;
+
+import com.google.android.settings.intelligence.libs.contextualcards.ContextualCard;
+import com.google.android.settings.intelligence.libs.contextualcards.ContextualCardProvider;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/** Provides dynamic card for SettingsIntelligence. */
+public class SettingsContextualCardProvider extends ContextualCardProvider {
+
+    public static final String CARD_AUTHORITY = "com.android.settings.homepage.contextualcards";
+
+    @Override
+    @Nullable
+    public List<ContextualCard> getContextualCards() {
+        final List<ContextualCard> cards = new ArrayList<>();
+        final ContextualCard wifiCard =
+                new ContextualCard.Builder()
+                        .setSliceUri(WifiSlice.WIFI_URI.toString())
+                        .setName(KEY_WIFI)
+                        .build();
+        final ContextualCard dataUsageCard =
+                new ContextualCard.Builder()
+                        .setSliceUri(DataUsageSlice.DATA_USAGE_CARD_URI.toString())
+                        .setName(DataUsageSlice.PATH_DATA_USAGE_CARD)
+                        .build();
+
+        cards.add(wifiCard);
+        cards.add(dataUsageCard);
+        return cards;
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/SettingsContextualCardProviderTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/SettingsContextualCardProviderTest.java
new file mode 100644
index 0000000..80d9497
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/SettingsContextualCardProviderTest.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2018 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.settings.homepage.contextualcards;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.net.Uri;
+import android.os.Bundle;
+
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import com.google.android.settings.intelligence.libs.contextualcards.ContextualCard;
+import com.google.android.settings.intelligence.libs.contextualcards.ContextualCardProvider;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RuntimeEnvironment;
+
+import java.util.ArrayList;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class SettingsContextualCardProviderTest {
+
+    private Context mContext;
+    private ContentResolver mResolver;
+    private Uri mUri;
+
+    @Before
+    public void setUp() {
+        mContext = RuntimeEnvironment.application;
+        mResolver = mContext.getContentResolver();
+        mUri = new Uri.Builder()
+                .scheme(ContentResolver.SCHEME_CONTENT)
+                .authority(SettingsContextualCardProvider.CARD_AUTHORITY)
+                .build();
+    }
+
+    @Test
+    public void contentProviderCall_returnCorrectSize() {
+        final Bundle returnValue =
+                mResolver.call(mUri, ContextualCardProvider.METHOD_GET_CARD_LIST, "", null);
+        final ArrayList<ContextualCard> cards =
+                returnValue.getParcelableArrayList(ContextualCardProvider.BUNDLE_CARD_LIST);
+        assertThat(cards.size()).isEqualTo(2);
+    }
+}
\ No newline at end of file