diff options
| author | android-build-team Robot <android-build-team-robot@google.com> | 2017-10-20 07:17:41 +0000 |
|---|---|---|
| committer | android-build-team Robot <android-build-team-robot@google.com> | 2017-10-20 07:17:41 +0000 |
| commit | cdf70685d7796990df03b765c012174a86814bf5 (patch) | |
| tree | 548edadc62c1bc979a51636cd368566141ad0695 | |
| parent | 10bc7aacdb56616bf34ec34f29683adf21d6c57a (diff) | |
| parent | e594363266714de153e5b07f050a05acb2ad6ff9 (diff) | |
| download | platform_packages_apps_Nfc-oreo-m4-s1-release.tar.gz platform_packages_apps_Nfc-oreo-m4-s1-release.tar.bz2 platform_packages_apps_Nfc-oreo-m4-s1-release.zip | |
Snap for 4407597 from e594363266714de153e5b07f050a05acb2ad6ff9 to oc-mr1-releaseandroid-wear-8.1.0_r1android-vts-8.1_r9android-vts-8.1_r8android-vts-8.1_r7android-vts-8.1_r6android-vts-8.1_r5android-vts-8.1_r4android-vts-8.1_r3android-vts-8.1_r14android-vts-8.1_r13android-vts-8.1_r12android-vts-8.1_r11android-vts-8.1_r10android-cts-8.1_r9android-cts-8.1_r8android-cts-8.1_r7android-cts-8.1_r6android-cts-8.1_r5android-cts-8.1_r4android-cts-8.1_r3android-cts-8.1_r24android-cts-8.1_r23android-cts-8.1_r22android-cts-8.1_r21android-cts-8.1_r20android-cts-8.1_r2android-cts-8.1_r19android-cts-8.1_r18android-cts-8.1_r17android-cts-8.1_r16android-cts-8.1_r15android-cts-8.1_r14android-cts-8.1_r13android-cts-8.1_r12android-cts-8.1_r11android-cts-8.1_r10android-cts-8.1_r1android-8.1.0_r6android-8.1.0_r5android-8.1.0_r4android-8.1.0_r3android-8.1.0_r23android-8.1.0_r19android-8.1.0_r16android-8.1.0_r15android-8.1.0_r12android-8.1.0_r11android-8.1.0_r10android-8.1.0_r1oreo-mr1-wear-releaseoreo-mr1-vts-releaseoreo-mr1-s1-releaseoreo-mr1-releaseoreo-mr1-cuttlefish-testingoreo-mr1-cts-releaseoreo-m4-s1-release
Change-Id: I3c2aca0557c6f2b4cc8388f78d12994dfb31d190
| -rw-r--r-- | res/drawable/ic_weblink_nfc.xml | 19 | ||||
| -rw-r--r-- | res/layout/url_open_confirmation.xml | 35 | ||||
| -rw-r--r-- | res/values/config.xml | 1 | ||||
| -rwxr-xr-x | res/values/strings.xml | 9 | ||||
| -rw-r--r-- | src/com/android/nfc/NfcDispatcher.java | 50 |
5 files changed, 114 insertions, 0 deletions
diff --git a/res/drawable/ic_weblink_nfc.xml b/res/drawable/ic_weblink_nfc.xml new file mode 100644 index 00000000..60f83c77 --- /dev/null +++ b/res/drawable/ic_weblink_nfc.xml @@ -0,0 +1,19 @@ +<vector android:height="180dp" android:viewportHeight="180.0" + android:viewportWidth="180.0" android:width="180dp" xmlns:android="http://schemas.android.com/apk/res/android"> + <path android:fillColor="#F1F3F4" android:pathData="M90,90m-90,0a90,90 0,1 1,180 0a90,90 0,1 1,-180 0"/> + <path android:fillColor="#E0E0E0" android:pathData="M64.2,107.5m-28,0a28,28 0,1 1,56 0a28,28 0,1 1,-56 0"/> + <path android:fillColor="#2196F3" android:pathData="M64.2,105.5m-28,0a28,28 0,1 1,56 0a28,28 0,1 1,-56 0"/> + <path android:fillColor="#FFFFFF" android:pathData="M74.3,92.4h-21.2c-1.5,0 -2.7,1.2 -2.7,2.6v21.2c0,1.5 1.2,2.7 2.6,2.7h21.2c1.5,0 2.7,-1.2 2.7,-2.6l0.1,-21.3C77,93.6 75.8,92.4 74.3,92.4zM74.3,116.2h-21.2L53.1,95h21.2L74.3,116.2zM71.7,97.7h-6.6c-1.5,0 -2.7,1.2 -2.7,2.6v3c-0.8,0.5 -1.3,1.3 -1.3,2.3c0,1.5 1.2,2.7 2.6,2.7s2.7,-1.2 2.7,-2.6c0,-1 -0.5,-1.8 -1.3,-2.3v-3h4L69.1,111h-10.6v-10.6h2.7v-2.7h-5.3v15.9h15.9L71.7,97.7z"/> + <path android:fillColor="#FAC88B" android:pathData="M166.7,137.1c-6.6,-5.9 -13.7,-12.7 -18.6,-18.5c-4.5,-5.4 -6.1,-30.2 -6.1,-30.2c0,-1.8 -0.9,-5.5 -1.4,-5.8c-1.6,-0.9 -3,-0.1 -3.1,1.7l-0.1,0.8c0,0 0.1,2.9 -4.9,0.9l0,0c-0.2,-0.1 -6.3,-3.7 -10.5,-7.7l0,0l-10.9,-10.3l-0.4,-0.4l-26.5,-24.1c-1.9,-1.6 -4,-3 -6,-3.3c-1,-0.1 -2,-0.2 -2.9,0.7l0,0c-0.7,0.7 -0.7,1.4 -0.8,2.1c-0.2,2.2 1.5,4.6 3.2,6.9l23.4,26.9l0.5,0.6l3.2,3.4c0.2,0.2 0.3,0.5 0.2,0.8l-15.4,27c-0.4,0.7 -0.6,1.1 -0.1,1.8c0.6,0.8 2.2,2.9 2.3,3c1.5,1.7 13.2,10.3 34.9,22.1c0.1,0.1 2.8,2.8 2.9,2.9c0,0 0.1,0.1 0.1,0.2c0,0 0,0 -0.1,-0.1c1.2,1.3 6,6.5 12.5,13.3c0.2,0.2 0.4,0.4 0.6,0.7c0.1,0.1 0.1,0.1 0.2,0.2c1.8,1.8 3.7,3.8 5.6,5.8C155.6,152.3 161.8,145.1 166.7,137.1z"/> + <path android:fillColor="#FF000000" android:pathData="M86.9,122.3c-2.3,0 -6.1,-0.7 -6.8,-4.9l0,0c0,-0.2 -0.1,-0.4 -0.1,-0.7l0,0c0,-0.4 0,-0.7 0,-1.1l0.6,-77.4c0,-2.1 0.6,-3.7 1.8,-4.9c1.2,-1.1 2.9,-1.7 5.1,-1.7l0,0h0.1l0,0l32.3,0.2c2.2,0 4,0.6 5.1,1.8c1.2,1.1 1.8,2.8 1.7,4.9l-0.6,77.4c0,0.3 0,0.7 0,1.1l0,0c0,0.2 0,0.5 -0.1,0.7l0,0l0,0c-0.7,4.2 -4.6,4.8 -6.9,4.8L86.9,122.3z"/> + <path android:fillColor="#FFFFFF" android:pathData="M123.6,114.2l-41.8,-0.6c-0.4,0 -0.8,-0.4 -0.8,-0.8l1,-70.5c0,-0.4 0.4,-0.8 0.8,-0.8l41.9,0.5c0.4,0 0.8,0.4 0.8,0.8l-1,70.5C124.4,113.9 124.1,114.2 123.6,114.2z"/> + <path android:fillColor="#939393" android:pathData="M87.6,31.9L87.6,31.9h0.8l0,0l30.7,0.2h0.7h0.1c2.1,0 3.8,0.6 4.9,1.7c1.1,1.1 1.7,2.7 1.7,4.7v0.1v0.6l-0.6,76.7c0,0.4 0,0.7 0,1.1l0,0l0,0c0,0.2 0,0.5 -0.1,0.7l0,0c-0.7,4 -4.4,4.6 -6.6,4.6h-0.1h-0.7l-30.7,-0.3h-0.7h-0.1c-2.2,0 -5.9,-0.6 -6.5,-4.7l0,0c0,-0.2 -0.1,-0.4 -0.1,-0.7l0,0l0,0c0,-0.4 0,-0.7 0,-1.1l0.6,-76.7v-0.6v-0.1c0,-2 0.6,-3.6 1.7,-4.7C83.7,32.4 85.4,31.9 87.6,31.9C87.5,31.9 87.5,31.9 87.6,31.9C87.5,31.9 87.6,31.9 87.6,31.9L87.6,31.9M87.7,31.4L87.7,31.4L87.7,31.4h-0.2l0,0c-2.3,0 -4,0.6 -5.3,1.8c-1.2,1.2 -1.9,2.9 -1.9,5.1v0.1v0.6l-0.6,76.7c0,0.4 0,0.7 0,1.1l0,0l0,0c0,0.2 0,0.5 0.1,0.7l0,0l0,0l0,0l0,0c0.3,1.9 1.3,3.4 3,4.2c1.4,0.7 3,0.9 4.1,0.9h0.1h0.7l30.7,0.2h0.7h0.1c1.1,0 2.7,-0.1 4.1,-0.8c1.7,-0.8 2.7,-2.2 3,-4.2l0,0l0,0l0,0l0,0c0,-0.2 0.1,-0.4 0.1,-0.7l0,0l0,0c0,-0.4 0,-0.7 0,-1.1l0.6,-76.7v-0.6v-0.1c0,-2.2 -0.6,-3.9 -1.8,-5.1c-1.2,-1.2 -3,-1.8 -5.3,-1.8h-0.1h-0.7l-30.7,-0.2l0,0L87.7,31.4L87.7,31.4L87.7,31.4z"/> + <path android:fillColor="#2196F3" android:pathData="M111.7,63.9l-16.9,-0.1c-1.2,0 -2.1,0.9 -2.1,2.1l-0.1,16.9c0,1.2 0.9,2.1 2.1,2.1l16.9,0.1c1.2,0 2.1,-0.9 2.1,-2.1l0.1,-16.9C113.8,64.9 112.9,63.9 111.7,63.9zM111.6,83l-16.9,-0.1l0.1,-16.9l16.9,0.1L111.6,83zM109.6,68.1h-5.3c-1.2,0 -2.1,0.9 -2.1,2.1v2.4c-0.6,0.4 -1.1,1 -1.1,1.8c0,1.2 0.9,2.1 2.1,2.1s2.1,-0.9 2.1,-2.1c0,-0.8 -0.4,-1.5 -1,-1.8v-2.4h3.2v8.5h-8.5v-8.5h2.1v-2.1h-4.2l-0.1,12.7l12.7,0.1L109.6,68.1z"/> + <path android:fillColor="#E0E0E0" android:pathData="M96.4,91.7c0.6,-0.1 2.3,-0.3 2.7,-3.1c0.4,-2.7 -3.1,-6.4 -4.4,-7.6l-10.9,-10.7c-2.3,-2.1 -7.1,5.9 -4.8,8l13.4,12C93.5,91.4 95,91.8 96.4,91.7z"/> + <path android:fillColor="#E0E0E0" android:pathData="M95.3,101.7c0.6,-0.1 2.3,-0.3 2.7,-3.1c0.4,-2.7 -3.1,-6.4 -4.4,-7.6l-10.9,-10.7c-2.3,-2.1 -6.7,5.5 -4.4,7.6l13,12.4C92.5,101.4 93.9,101.8 95.3,101.7z"/> + <path android:fillColor="#E0E0E0" android:pathData="M76.1,87.2c-0.4,0 2.1,8.2 3.5,12.7c0.4,1.3 1.1,4.4 1.1,4.4c2,2.5 6,5.4 8.3,3.2s1.2,-5.6 -0.8,-8l-7.5,-10.2C79.7,88 77.5,87.3 76.1,87.2z"/> + <path android:fillColor="#FAC88B" android:pathData="M136.6,114.6l4.4,-23.2c0,0 3,-6.7 -0.9,-10.3c-3.9,-3.6 -14.4,-18.2 -14.4,-18.2s-6.7,-9.6 -11.5,-4.1c-2.9,3.3 3.1,11.1 3.1,11.1l8.5,14.4c-6.1,14.2 -5.7,26 1.5,36.1C127.4,120.4 132.6,125.3 136.6,114.6z"/> + <path android:fillColor="#FFCC80" android:pathData="M96.5,91c0.6,-0.1 2.3,-0.3 2.7,-3.1c0.4,-2.7 -3.1,-6.4 -4.4,-7.6l-10.8,-10.7c-2.3,-2.1 -6.7,-4.3 -8.6,-1.8c-2,2.5 -0.4,5.7 1.9,7.8l15.3,14.1C93.7,90.7 95.1,91.2 96.5,91z"/> + <path android:fillColor="#FFCC80" android:pathData="M95.3,100.9c0.6,-0.1 2.3,-0.3 2.7,-3.1c0.4,-2.7 -3.1,-6.4 -4.4,-7.6l-10.8,-10.7c-2.3,-2.1 -6.7,-4.3 -8.6,-1.8c-2,2.5 -0.4,5.7 1.9,7.8l15.3,14.1C92.5,100.6 93.9,101 95.3,100.9z"/> + <path android:fillColor="#FFCC80" android:pathData="M76.1,86.4c-0.6,0 -2.3,0 -3.1,2.7c-0.8,2.6 2.1,6.8 3.3,8.3l4.4,6.2c2,2.5 6,5.4 8.3,3.2c2.3,-2.2 1.2,-5.6 -0.8,-8l-7.5,-10.2C79.8,87.3 77.5,86.5 76.1,86.4z"/> +</vector> diff --git a/res/layout/url_open_confirmation.xml b/res/layout/url_open_confirmation.xml new file mode 100644 index 00000000..98ff5d2c --- /dev/null +++ b/res/layout/url_open_confirmation.xml @@ -0,0 +1,35 @@ +<LinearLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:gravity="start" + android:layout_width="wrap_content" + android:layout_height="400dp" + android:orientation="vertical" + android:paddingTop="24dp" + android:paddingStart="24dp" + android:paddingEnd="24dp"> + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:textAlignment="viewStart" + android:paddingBottom="24dp" + android:text="@string/summary_confirm_url_open" + android:textColor="?android:attr/textColorPrimaryInverse"/> + <TextView + android:id="@+id/url_open_confirmation_link" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:textAlignment="viewStart" + android:textColor="?android:attr/colorAccent"/> + <FrameLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:paddingTop="24dp" + android:paddingBottom="24dp"> + <ImageView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:src="@drawable/ic_weblink_nfc"/> + </FrameLayout> + +</LinearLayout> diff --git a/res/values/config.xml b/res/values/config.xml index 7a4803e0..c6654dd2 100644 --- a/res/values/config.xml +++ b/res/values/config.xml @@ -1,4 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> <resources> <string name="bluetooth_package" translatable="false">com.android.bluetooth</string> + <bool name="enable_nfc_url_open_dialog">false</bool> </resources> diff --git a/res/values/strings.xml b/res/values/strings.xml index 34faf5bb..9d812d98 100755 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -84,4 +84,13 @@ <!-- Message shown in a toast when user wants to Beam a file, but application doesn't have required permission --> <string name="beam_requires_external_storage_permission">Application does not have External Storage Permission. This is required to Beam this file</string> + <!-- Strings for a dialog informing the user a URL was read from an NFC tag, and allowing confirmation that they want to open it --> + <!-- Title of the dialog --> + <string name="title_confirm_url_open">Open link?</string> + <!-- Summary text appearing before the URL --> + <string name="summary_confirm_url_open" product="tablet">Your tablet received a link through NFC:</string> + <string name="summary_confirm_url_open" product="default">Your phone received a link through NFC:</string> + <!-- Label for the button which causes the URL to be opened --> + <string name="action_confirm_url_open">Open link</string> + </resources> diff --git a/src/com/android/nfc/NfcDispatcher.java b/src/com/android/nfc/NfcDispatcher.java index 0f921f14..934baf79 100644 --- a/src/com/android/nfc/NfcDispatcher.java +++ b/src/com/android/nfc/NfcDispatcher.java @@ -16,6 +16,7 @@ package com.android.nfc; +import android.Manifest; import android.app.ActivityManager; import android.bluetooth.BluetoothAdapter; import android.os.UserManager; @@ -26,12 +27,14 @@ import com.android.nfc.handover.PeripheralHandoverService; import android.app.Activity; import android.app.ActivityManager; +import android.app.AlertDialog; import android.app.IActivityManager; import android.app.PendingIntent; import android.app.PendingIntent.CanceledException; import android.content.ComponentName; import android.content.ContentResolver; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; import android.content.pm.PackageManager; @@ -48,6 +51,10 @@ import android.nfc.tech.NfcBarcode; import android.os.RemoteException; import android.os.UserHandle; import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.WindowManager; +import android.widget.TextView; import java.io.FileDescriptor; import java.io.PrintWriter; @@ -56,6 +63,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedList; import java.util.List; +import java.util.Locale; /** * Dispatch of NFC events to start activities @@ -198,6 +206,14 @@ class NfcDispatcher { return intent; } + public boolean isWebIntent() { + return ndefUri != null && ndefUri.normalizeScheme().getScheme().startsWith("http"); + } + + public String getUri() { + return ndefUri.toString(); + } + /** * Launch the activity via a (single) NFC root task, so that it * creates a new task stack instead of interfering with any existing @@ -536,6 +552,13 @@ class NfcDispatcher { // regular launch dispatch.intent.setPackage(null); + + if (dispatch.isWebIntent()) { + if (DBG) Log.i(TAG, "matched Web link - prompting user"); + showWebLinkConfirmation(dispatch); + return true; + } + if (dispatch.tryStartActivity()) { if (DBG) Log.i(TAG, "matched NDEF"); return true; @@ -706,6 +729,33 @@ class NfcDispatcher { return enabled; } + void showWebLinkConfirmation(DispatchInfo dispatch) { + if (!mContext.getResources().getBoolean(R.bool.enable_nfc_url_open_dialog)) { + dispatch.tryStartActivity(); + return; + } + AlertDialog.Builder builder = new AlertDialog.Builder( + mContext.getApplicationContext(), + android.R.style.Theme_DeviceDefault_Light_Dialog_Alert); + builder.setTitle(R.string.title_confirm_url_open); + LayoutInflater inflater = LayoutInflater.from(mContext); + View view = inflater.inflate(R.layout.url_open_confirmation, null); + if (view != null) { + TextView url = view.findViewById(R.id.url_open_confirmation_link); + if (url != null) { + url.setText(dispatch.getUri()); + } + builder.setView(view); + } + builder.setNegativeButton(R.string.cancel, (dialog, which) -> {}); + builder.setPositiveButton(R.string.action_confirm_url_open, (dialog, which) -> { + dispatch.tryStartActivity(); + }); + AlertDialog dialog = builder.create(); + dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); + dialog.show(); + } + void dump(FileDescriptor fd, PrintWriter pw, String[] args) { synchronized (this) { pw.println("mOverrideIntent=" + mOverrideIntent); |
