Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3936e9f3 authored by Raff Tsai's avatar Raff Tsai
Browse files

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
parent 81e2d88c
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ LOCAL_STATIC_JAVA_LIBRARIES := \
    androidx.lifecycle_lifecycle-extensions \
    guava \
    jsr305 \
    contextualcards \
    settings-logtags \

LOCAL_PROGUARD_FLAG_FILES := proguard.flags
@@ -57,6 +58,13 @@ 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))
+9 −0
Original line number Diff line number Diff line
@@ -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>
+5.15 KiB

File added.

No diff preview for this file type.

+56 −0
Original line number Diff line number Diff line
/*
 * 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;
    }
}
+64 −0
Original line number Diff line number Diff line
/*
 * 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