From 3f743aecb43158e006a3bb2e70c3399562a3615c Mon Sep 17 00:00:00 2001 From: Matthew Fritze Date: Tue, 22 Jan 2019 15:53:37 -0800 Subject: [PATCH] Add NFC Panel NFC Panel only shows the NFC setting slice, for now. Title is "NFC", and See More takes you to the Advanced Device Connectivity page. Possibly use cases would be for apps that need to enable NFC for their peripheral, or accessory. Test: Manual App Test: robotest Change-Id: I8538fd0e4501fb83672418591616f28bf2436645 Fixes: 120142616 --- AndroidManifest.xml | 4 ++ src/com/android/settings/panel/NfcPanel.java | 53 +++++++++++++++++++ .../panel/PanelFeatureProviderImpl.java | 2 + .../settings/slices/CustomSliceRegistry.java | 9 ++++ .../android/settings/panel/NfcPanelTest.java | 40 ++++++++++++++ 5 files changed, 108 insertions(+) create mode 100644 src/com/android/settings/panel/NfcPanel.java create mode 100644 tests/robotests/src/com/android/settings/panel/NfcPanelTest.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index a12c9825111..524003583f5 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -2978,6 +2978,10 @@ + + + + getSlices() { + final List uris = new ArrayList<>(); + uris.add(CustomSliceRegistry.NFC_SLICE_URI); + return uris; + } + + @Override + public Intent getSeeMoreIntent() { + final String screenTitle = + mContext.getText(R.string.connected_device_connections_title).toString(); + Intent intent = SliceBuilderUtils.buildSearchResultPageIntent(mContext, + AdvancedConnectedDeviceDashboardFragment.class.getName(), + null /* key */, + screenTitle, + SettingsEnums.SETTINGS_CONNECTED_DEVICE_CATEGORY); + intent.setClassName(mContext.getPackageName(), SubSettings.class.getName()); + return intent; + } +} diff --git a/src/com/android/settings/panel/PanelFeatureProviderImpl.java b/src/com/android/settings/panel/PanelFeatureProviderImpl.java index ade2ffdc946..b4c37bf39a1 100644 --- a/src/com/android/settings/panel/PanelFeatureProviderImpl.java +++ b/src/com/android/settings/panel/PanelFeatureProviderImpl.java @@ -28,6 +28,8 @@ public class PanelFeatureProviderImpl implements PanelFeatureProvider { return InternetConnectivityPanel.create(context); case Settings.Panel.ACTION_VOLUME: return VolumePanel.create(context); + case Settings.Panel.ACTION_NFC: + return NfcPanel.create(context); } throw new IllegalStateException("No matching panel for: " + panelType); diff --git a/src/com/android/settings/slices/CustomSliceRegistry.java b/src/com/android/settings/slices/CustomSliceRegistry.java index e842cb97857..3a213df6742 100644 --- a/src/com/android/settings/slices/CustomSliceRegistry.java +++ b/src/com/android/settings/slices/CustomSliceRegistry.java @@ -154,6 +154,15 @@ public class CustomSliceRegistry { .appendEncodedPath(SettingsSlicesContract.PATH_SETTING_INTENT) .appendPath("low_storage") .build(); + /** + * Backing Uri for NFC Slice + */ + public static final Uri NFC_SLICE_URI = new Uri.Builder() + .scheme(ContentResolver.SCHEME_CONTENT) + .authority(SettingsSliceProvider.SLICE_AUTHORITY) + .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION) + .appendPath("toggle_nfc") + .build(); /** * Backing Uri for Notification channel Slice. */ diff --git a/tests/robotests/src/com/android/settings/panel/NfcPanelTest.java b/tests/robotests/src/com/android/settings/panel/NfcPanelTest.java new file mode 100644 index 00000000000..bf6662dc946 --- /dev/null +++ b/tests/robotests/src/com/android/settings/panel/NfcPanelTest.java @@ -0,0 +1,40 @@ +package com.android.settings.panel; + +import static com.google.common.truth.Truth.assertThat; + +import android.net.Uri; + +import com.android.settings.slices.CustomSliceRegistry; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.RuntimeEnvironment; + + +import java.util.List; + +@RunWith(RobolectricTestRunner.class) +public class NfcPanelTest { + + private NfcPanel mPanel; + + @Before + public void setUp() { + mPanel = NfcPanel.create(RuntimeEnvironment.application); + } + + @Test + public void getSlices_containsNecessarySlices() { + final List uris = mPanel.getSlices(); + + assertThat(uris).containsExactly( + CustomSliceRegistry.NFC_SLICE_URI); + } + + @Test + public void getSeeMoreIntent_notNull() { + assertThat(mPanel.getSeeMoreIntent()).isNotNull(); + } +}