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
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index a12c982..5240035 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -2978,6 +2978,10 @@
<action android:name="android.settings.panel.action.VOLUME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
+ <intent-filter>
+ <action android:name="android.settings.panel.action.NFC" />
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
</activity>
<provider android:name=".slices.SettingsSliceProvider"
diff --git a/src/com/android/settings/panel/NfcPanel.java b/src/com/android/settings/panel/NfcPanel.java
new file mode 100644
index 0000000..70452a3
--- /dev/null
+++ b/src/com/android/settings/panel/NfcPanel.java
@@ -0,0 +1,53 @@
+package com.android.settings.panel;
+
+import android.app.settings.SettingsEnums;
+import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
+
+import com.android.settings.R;
+import com.android.settings.SubSettings;
+import com.android.settings.connecteddevice.AdvancedConnectedDeviceDashboardFragment;
+import com.android.settings.slices.CustomSliceRegistry;
+import com.android.settings.slices.SliceBuilderUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class NfcPanel implements PanelContent {
+
+ private final Context mContext;
+
+ public static NfcPanel create(Context context) {
+ return new NfcPanel(context);
+ }
+
+ private NfcPanel(Context context) {
+ mContext = context.getApplicationContext();
+ }
+
+ @Override
+ public CharSequence getTitle() {
+ return mContext.getText(R.string.nfc_quick_toggle_title);
+ }
+
+ @Override
+ public List<Uri> getSlices() {
+ final List<Uri> 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 ade2ffd..b4c37bf 100644
--- a/src/com/android/settings/panel/PanelFeatureProviderImpl.java
+++ b/src/com/android/settings/panel/PanelFeatureProviderImpl.java
@@ -28,6 +28,8 @@
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 e842cb9..3a213df 100644
--- a/src/com/android/settings/slices/CustomSliceRegistry.java
+++ b/src/com/android/settings/slices/CustomSliceRegistry.java
@@ -155,6 +155,15 @@
.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.
*/
public static final Uri NOTIFICATION_CHANNEL_SLICE_URI = new Uri.Builder()
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 0000000..bf6662d
--- /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<Uri> uris = mPanel.getSlices();
+
+ assertThat(uris).containsExactly(
+ CustomSliceRegistry.NFC_SLICE_URI);
+ }
+
+ @Test
+ public void getSeeMoreIntent_notNull() {
+ assertThat(mPanel.getSeeMoreIntent()).isNotNull();
+ }
+}