diff --git a/Android.mk b/Android.mk index 6b0d077a214..f10b3ec2d08 100644 --- a/Android.mk +++ b/Android.mk @@ -41,6 +41,7 @@ LOCAL_STATIC_JAVA_LIBRARIES := \ androidx.lifecycle_lifecycle-extensions \ guava \ jsr305 \ + contextualcards \ settings-logtags \ LOCAL_PROGUARD_FLAG_FILES := proguard.flags @@ -57,7 +58,14 @@ include frameworks/base/packages/SettingsLib/search/common.mk 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 aa53bdbdab0..94be61c9312 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -3192,6 +3192,15 @@ android:exported="true" android:permission="android.permission.WRITE_SETTINGS_HOMEPAGE_DATA" /> + + + + + diff --git a/libs/contextualcards.aar b/libs/contextualcards.aar new file mode 100755 index 00000000000..a44a26c38b1 Binary files /dev/null and b/libs/contextualcards.aar 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 00000000000..44705c59522 --- /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 getContextualCards() { + final List 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 00000000000..80d94977607 --- /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 cards = + returnValue.getParcelableArrayList(ContextualCardProvider.BUNDLE_CARD_LIST); + assertThat(cards.size()).isEqualTo(2); + } +} \ No newline at end of file