diff options
| author | android-build-team Robot <android-build-team-robot@google.com> | 2020-04-10 07:36:55 +0000 |
|---|---|---|
| committer | android-build-team Robot <android-build-team-robot@google.com> | 2020-04-10 07:36:55 +0000 |
| commit | de7af594cde0e3a7a0e6a598e898b092dff813cc (patch) | |
| tree | 7be07c811f97f963d54a26e70e22b91a298d9737 | |
| parent | 019009f994163c8a2f75889966a0aeefd933139d (diff) | |
| parent | a3bb2e5b767dd2073c00b9dadeb6b20ea64572fb (diff) | |
| download | platform_packages_apps_Nfc-android10-d4-release.tar.gz platform_packages_apps_Nfc-android10-d4-release.tar.bz2 platform_packages_apps_Nfc-android10-d4-release.zip | |
Merge cherrypicks of [11008966, 11008967, 11004166, 11010579, 11010580, 11010581, 11010582, 11010583, 11010592] into qt-d4-releaseandroid-10.0.0_r45android-10.0.0_r44android-10.0.0_r43android-10.0.0_r42android10-d4-s1-releaseandroid10-d4-release
Change-Id: I984456b18ba782ab8cbdf39bd4196e0a8813e3b1
| -rwxr-xr-x | AndroidManifest.xml | 8 | ||||
| -rw-r--r-- | res/values/config.xml | 5 | ||||
| -rwxr-xr-x | res/values/strings.xml | 4 | ||||
| -rw-r--r-- | src/com/android/nfc/NfcBlockedNotification.java | 66 | ||||
| -rw-r--r-- | src/com/android/nfc/NfcService.java | 54 |
5 files changed, 136 insertions, 1 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 2649328d..17f68f2c 100755 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -118,6 +118,14 @@ android:configChanges="orientation|keyboardHidden|screenSize" /> + <activity android:name=".NfcBlockedNotification" + android:finishOnCloseSystemDialogs="true" + android:excludeFromRecents="true" + android:theme="@android:style/Theme.Translucent.NoTitleBar" + android:noHistory="true" + android:configChanges="orientation|keyboardHidden|screenSize" + /> + <activity android:name=".BeamShareActivity" android:finishOnCloseSystemDialogs="true" android:theme="@android:style/Theme.Translucent" diff --git a/res/values/config.xml b/res/values/config.xml index c5354c25..50ad0389 100644 --- a/res/values/config.xml +++ b/res/values/config.xml @@ -4,7 +4,12 @@ <bool name="enable_nfc_url_open_dialog">false</bool> <bool name="enable_auto_play">true</bool> <bool name="enable_notify_dispatch_failed">false</bool> + <bool name="enable_antenna_blocked_alert">false</bool> + <integer name="max_antenna_blocked_failure_count">10</integer> + <integer name="unknown_tag_polling_delay">-1</integer> <!-- List of SKUs where Secure NFC functionality is supported --> <string-array name="config_skuSupportsSecureNfc" translatable="false" /> + <!-- NFC blocking alert notification link uri string --> + <string name="antenna_blocked_alert_link" translatable="false" /> </resources> diff --git a/res/values/strings.xml b/res/values/strings.xml index e46ba4cc..3636cbd0 100755 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -97,4 +97,8 @@ <string name="tag_read_error">NFC read error. Try again.</string> <!-- Toast string informing the user that no application can handle the NFC tag --> <string name="tag_dispatch_failed">No supported application for this NFC Tag</string> + <!-- Notification title string informing the user that NFC may be blocked --> + <string name="nfc_blocking_alert_title">NFC may be blocked</string> + <!-- Notification message string informing the user that NFC may be blocked --> + <string name="nfc_blocking_alert_message">Tap to learn how to fix.</string> </resources> diff --git a/src/com/android/nfc/NfcBlockedNotification.java b/src/com/android/nfc/NfcBlockedNotification.java new file mode 100644 index 00000000..5dd28ee6 --- /dev/null +++ b/src/com/android/nfc/NfcBlockedNotification.java @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2020 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.nfc; + +import android.app.Activity; +import android.app.Notification; +import android.app.NotificationChannel; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.IntentFilter; +import android.content.res.Resources; +import android.net.Uri; +import android.os.Bundle; +import android.text.TextUtils; +import com.android.nfc.R; + +public class NfcBlockedNotification extends Activity { + private static final String NFC_NOTIFICATION_CHANNEL = "nfc_notification_channel"; + private NotificationChannel mNotificationChannel; + public static final int NOTIFICATION_ID_NFC = -1000001; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + PendingIntent pIntent; + Intent infoIntent; + if (TextUtils.isEmpty(getString(R.string.antenna_blocked_alert_link))) { + // Do nothing after user click the notification if antenna_blocked_alert_link is empty + infoIntent = new Intent(); + } else { + // Open the link after user click the notification + infoIntent = new Intent(Intent.ACTION_VIEW); + infoIntent.setData(Uri.parse(getString(R.string.antenna_blocked_alert_link))); + } + Notification.Builder builder = new Notification.Builder(this, NFC_NOTIFICATION_CHANNEL); + builder.setContentTitle(getString(R.string.nfc_blocking_alert_title)) + .setContentText(getString(R.string.nfc_blocking_alert_message)) + .setSmallIcon(android.R.drawable.stat_sys_warning) + .setPriority(NotificationManager.IMPORTANCE_DEFAULT) + .setAutoCancel(true) + .setContentIntent(PendingIntent.getActivity(getApplicationContext(), 0, infoIntent, 0)); + mNotificationChannel = new NotificationChannel(NFC_NOTIFICATION_CHANNEL, + getString(R.string.nfcUserLabel), NotificationManager.IMPORTANCE_DEFAULT); + NotificationManager notificationManager = + getApplicationContext().getSystemService(NotificationManager.class); + notificationManager.createNotificationChannel(mNotificationChannel); + notificationManager.notify(NOTIFICATION_ID_NFC, builder.build()); + } +} + diff --git a/src/com/android/nfc/NfcService.java b/src/com/android/nfc/NfcService.java index 48c3594c..f1ba3be0 100644 --- a/src/com/android/nfc/NfcService.java +++ b/src/com/android/nfc/NfcService.java @@ -131,6 +131,9 @@ public class NfcService implements DeviceHostListener { static final String PREF_FIRST_BEAM = "first_beam"; static final String PREF_FIRST_BOOT = "first_boot"; + static final String PREF_ANTENNA_BLOCKED_MESSAGE_SHOWN = "antenna_blocked_message_shown"; + static final boolean ANTENNA_BLOCKED_MESSAGE_SHOWN_DEFAULT = false; + static final String TRON_NFC_CE = "nfc_ce"; static final String TRON_NFC_P2P = "nfc_p2p"; static final String TRON_NFC_TAG = "nfc_tag"; @@ -156,6 +159,9 @@ public class NfcService implements DeviceHostListener { static final int MSG_APPLY_SCREEN_STATE = 16; static final int MSG_TRANSACTION_EVENT = 17; + // Negative value for NO polling delay + static final int NO_POLL_DELAY = -1; + // Update stats every 4 hours static final long STATS_UPDATE_INTERVAL_MS = 4 * 60 * 60 * 1000; static final long MAX_POLLING_PAUSE_TIMEOUT = 40000; @@ -245,6 +251,11 @@ public class NfcService implements DeviceHostListener { private int mUserId; boolean mPollingPaused; + // True if nfc notification message already shown + boolean mAntennaBlockedMessageShown; + private static int mDispatchFailedCount; + private static int mDispatchFailedMax; + static final int INVALID_NATIVE_HANDLE = -1; byte mDebounceTagUid[]; int mDebounceTagDebounceMs; @@ -284,6 +295,9 @@ public class NfcService implements DeviceHostListener { boolean mIsBeamCapable; boolean mIsSecureNfcCapable; + int mPollDelay; + boolean mNotifyDispatchFailed; + private NfcDispatcher mNfcDispatcher; private PowerManager mPowerManager; private KeyguardManager mKeyguard; @@ -505,6 +519,22 @@ public class NfcService implements DeviceHostListener { mIsSecureNfcCapable; mDeviceHost.setNfcSecure(mIsSecureNfcEnabled); + + // Notification message variables + mDispatchFailedCount = 0; + if (mContext.getResources().getBoolean(R.bool.enable_antenna_blocked_alert) && + !mPrefs.getBoolean(PREF_ANTENNA_BLOCKED_MESSAGE_SHOWN, ANTENNA_BLOCKED_MESSAGE_SHOWN_DEFAULT)) { + mAntennaBlockedMessageShown = false; + mDispatchFailedMax = + mContext.getResources().getInteger(R.integer.max_antenna_blocked_failure_count); + } else { + mAntennaBlockedMessageShown = true; + } + + // Polling delay variables + mPollDelay = mContext.getResources().getInteger(R.integer.unknown_tag_polling_delay); + mNotifyDispatchFailed = mContext.getResources().getBoolean(R.bool.enable_notify_dispatch_failed); + // Make sure this is only called when object construction is complete. ServiceManager.addService(SERVICE_NAME, mNfcAdapter); @@ -645,6 +675,7 @@ public class NfcService implements DeviceHostListener { Log.d(TAG, "NFC is off. Checking firmware version"); initialized = mDeviceHost.checkFirmware(); } + if (initialized) { SystemProperties.set("nfc.initialized", "true"); } @@ -900,6 +931,7 @@ public class NfcService implements DeviceHostListener { mPollingPaused = false; new ApplyRoutingTask().execute(); } + if (DBG) Log.d(TAG, "Polling is resumed"); } @Override @@ -2561,7 +2593,14 @@ public class NfcService implements DeviceHostListener { } int dispatchResult = mNfcDispatcher.dispatchTag(tag); if (dispatchResult == NfcDispatcher.DISPATCH_FAIL && !mInProvisionMode) { + if (DBG) Log.d(TAG, "Tag dispatch failed"); unregisterObject(tagEndpoint.getHandle()); + if (mPollDelay > NO_POLL_DELAY) { + tagEndpoint.stopPresenceChecking(); + mNfcAdapter.pausePolling(mPollDelay); + } else { + Log.e(TAG, "Keep presence checking."); + } if (mScreenState == ScreenStateHelper.SCREEN_STATE_ON_UNLOCKED && mContext.getResources().getBoolean(R.bool.enable_notify_dispatch_failed)) { if (mToast != null) { @@ -2570,9 +2609,22 @@ public class NfcService implements DeviceHostListener { mToast = Toast.makeText(mContext, R.string.tag_dispatch_failed, Toast.LENGTH_SHORT); mToast.show(); + playSound(SOUND_ERROR); + } + if (!mAntennaBlockedMessageShown && mDispatchFailedCount++ > mDispatchFailedMax) { + Intent dialogIntent = new Intent(mContext, NfcBlockedNotification.class); + dialogIntent.setFlags( + Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); + mContext.startActivity(dialogIntent); + mPrefsEditor.putBoolean(PREF_ANTENNA_BLOCKED_MESSAGE_SHOWN, true); + mPrefsEditor.apply(); + mBackupManager.dataChanged(); + mAntennaBlockedMessageShown = true; + mDispatchFailedCount = 0; + if (DBG) Log.d(TAG, "Tag dispatch failed notification"); } - playSound(SOUND_ERROR); } else if (dispatchResult == NfcDispatcher.DISPATCH_SUCCESS) { + mDispatchFailedCount = 0; mVibrator.vibrate(mVibrationEffect); playSound(SOUND_END); } |
