Loading nfc/java/android/nfc/NfcAdapter.java +84 −390 Original line number Diff line number Diff line Loading @@ -963,22 +963,9 @@ public final class NfcAdapter { throw new UnsupportedOperationException("You need a context on NfcAdapter to use the " + " NFC extras APIs"); } try { return sService.getNfcDtaInterface(mContext.getPackageName()); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return null; } try { return sService.getNfcDtaInterface(mContext.getPackageName()); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return null; } return callServiceReturn(() -> sService.getNfcDtaInterface(mContext.getPackageName()), null); } /** Loading Loading @@ -1095,22 +1082,8 @@ public final class NfcAdapter { @SystemApi @FlaggedApi(Flags.FLAG_ENABLE_NFC_MAINLINE) public @AdapterState int getAdapterState() { try { return sService.getState(); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return NfcAdapter.STATE_OFF; } try { return sService.getState(); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return NfcAdapter.STATE_OFF; } return callServiceReturn(() -> sService.getState(), NfcAdapter.STATE_OFF); } /** Loading @@ -1134,22 +1107,8 @@ public final class NfcAdapter { @FlaggedApi(Flags.FLAG_NFC_STATE_CHANGE) @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public boolean enable() { try { return sService.enable(mContext.getPackageName()); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return false; } try { return sService.enable(mContext.getPackageName()); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return false; } return callServiceReturn(() -> sService.enable(mContext.getPackageName()), false); } /** Loading @@ -1175,22 +1134,9 @@ public final class NfcAdapter { @FlaggedApi(Flags.FLAG_NFC_STATE_CHANGE) @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public boolean disable() { try { return sService.disable(true, mContext.getPackageName()); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return false; } try { return sService.disable(true, mContext.getPackageName()); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return false; } return callServiceReturn(() -> sService.disable(true, mContext.getPackageName()), false); } /** Loading @@ -1200,22 +1146,9 @@ public final class NfcAdapter { @SystemApi @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public boolean disable(boolean persist) { try { return sService.disable(persist, mContext.getPackageName()); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return false; } try { return sService.disable(persist, mContext.getPackageName()); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return false; } return callServiceReturn(() -> sService.disable(persist, mContext.getPackageName()), false); } /** Loading @@ -1241,12 +1174,7 @@ public final class NfcAdapter { */ @FlaggedApi(Flags.FLAG_NFC_OBSERVE_MODE) public boolean isObserveModeSupported() { try { return sService.isObserveModeSupported(); } catch (RemoteException e) { attemptDeadServiceRecovery(e); return false; } return callServiceReturn(() -> sService.isObserveModeSupported(), false); } /** Loading @@ -1257,12 +1185,7 @@ public final class NfcAdapter { @FlaggedApi(Flags.FLAG_NFC_OBSERVE_MODE) public boolean isObserveModeEnabled() { try { return sService.isObserveModeEnabled(); } catch (RemoteException e) { attemptDeadServiceRecovery(e); return false; } return callServiceReturn(() -> sService.isObserveModeEnabled(), false); } /** Loading @@ -1286,12 +1209,8 @@ public final class NfcAdapter { throw new UnsupportedOperationException("You need a context on NfcAdapter to use the " + " observe mode APIs"); } try { return sService.setObserveMode(enabled, mContext.getPackageName()); } catch (RemoteException e) { attemptDeadServiceRecovery(e); return false; } return callServiceReturn(() -> sService.setObserveMode(enabled, mContext.getPackageName()), false); } /** Loading Loading @@ -2057,22 +1976,8 @@ public final class NfcAdapter { if (!sHasNfcFeature && !sHasCeFeature) { throw new UnsupportedOperationException(); } try { return sService.setNfcSecure(enable); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return false; } try { return sService.setNfcSecure(enable); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return false; } return callServiceReturn(() -> sService.setNfcSecure(enable), false); } /** Loading @@ -2088,22 +1993,8 @@ public final class NfcAdapter { if (!sHasNfcFeature && !sHasCeFeature) { throw new UnsupportedOperationException(); } try { return sService.deviceSupportsNfcSecure(); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return false; } try { return sService.deviceSupportsNfcSecure(); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return false; } return callServiceReturn(() -> sService.deviceSupportsNfcSecure(), false); } /** Loading @@ -2121,22 +2012,8 @@ public final class NfcAdapter { if (!sHasNfcFeature && !sHasCeFeature) { throw new UnsupportedOperationException(); } try { return sService.getNfcAntennaInfo(); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return null; } try { return sService.getNfcAntennaInfo(); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return null; } return callServiceReturn(() -> sService.getNfcAntennaInfo(), null); } /** Loading @@ -2154,22 +2031,8 @@ public final class NfcAdapter { if (!sHasNfcFeature && !sHasCeFeature) { throw new UnsupportedOperationException(); } try { return sService.isNfcSecureEnabled(); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return false; } try { return sService.isNfcSecureEnabled(); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return false; } return callServiceReturn(() -> sService.isNfcSecureEnabled(), false); } /** Loading @@ -2185,22 +2048,8 @@ public final class NfcAdapter { if (!sHasNfcFeature) { throw new UnsupportedOperationException(); } try { return sService.enableReaderOption(enable); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return false; } try { return sService.enableReaderOption(enable); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return false; } return callServiceReturn(() -> sService.enableReaderOption(enable), false); } /** Loading @@ -2214,22 +2063,8 @@ public final class NfcAdapter { if (!sHasNfcFeature) { throw new UnsupportedOperationException(); } try { return sService.isReaderOptionSupported(); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return false; } try { return sService.isReaderOptionSupported(); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return false; } return callServiceReturn(() -> sService.isReaderOptionSupported(), false); } /** Loading @@ -2245,22 +2080,8 @@ public final class NfcAdapter { if (!sHasNfcFeature) { throw new UnsupportedOperationException(); } try { return sService.isReaderOptionEnabled(); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return false; } try { return sService.isReaderOptionEnabled(); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return false; } return callServiceReturn(() -> sService.isReaderOptionEnabled(), false); } /** Loading Loading @@ -2388,11 +2209,9 @@ public final class NfcAdapter { synchronized (mLock) { mTagRemovedListener = iListener; } try { return sService.ignore(tag.getServiceHandle(), debounceMs, iListener); } catch (RemoteException e) { return false; } final ITagRemovedCallback.Stub passedListener = iListener; return callServiceReturn(() -> sService.ignore(tag.getServiceHandle(), debounceMs, passedListener), false); } /** Loading Loading @@ -2509,22 +2328,9 @@ public final class NfcAdapter { throw new UnsupportedOperationException("You need a context on NfcAdapter to use the " + " NFC extras APIs"); } try { return sService.getNfcAdapterExtrasInterface(mContext.getPackageName()); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return null; } try { return sService.getNfcAdapterExtrasInterface(mContext.getPackageName()); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return null; } return callServiceReturn(() -> sService.getNfcAdapterExtrasInterface(mContext.getPackageName()), null); } void enforceResumed(Activity activity) { Loading Loading @@ -2569,22 +2375,8 @@ public final class NfcAdapter { if (!sHasNfcFeature && !sHasCeFeature) { throw new UnsupportedOperationException(); } try { return sService.setControllerAlwaysOn(value); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return false; } try { return sService.setControllerAlwaysOn(value); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return false; } return callServiceReturn(() -> sService.setControllerAlwaysOn(value), false); } /** Loading @@ -2600,22 +2392,8 @@ public final class NfcAdapter { @SystemApi @RequiresPermission(android.Manifest.permission.NFC_SET_CONTROLLER_ALWAYS_ON) public boolean isControllerAlwaysOn() { try { return sService.isControllerAlwaysOn(); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return false; } try { return sService.isControllerAlwaysOn(); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return false; } return callServiceReturn(() -> sService.isControllerAlwaysOn(), false); } /** Loading @@ -2634,22 +2412,8 @@ public final class NfcAdapter { if (!sHasNfcFeature && !sHasCeFeature) { throw new UnsupportedOperationException(); } try { return sService.isControllerAlwaysOnSupported(); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return false; } try { return sService.isControllerAlwaysOnSupported(); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return false; } return callServiceReturn(() -> sService.isControllerAlwaysOnSupported(), false); } /** Loading Loading @@ -2719,21 +2483,9 @@ public final class NfcAdapter { Log.e(TAG, "TagIntentAppPreference is not supported"); throw new UnsupportedOperationException(); } try { return sService.setTagIntentAppPreferenceForUser(userId, pkg, allow); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); } try { return sService.setTagIntentAppPreferenceForUser(userId, pkg, allow); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return TAG_INTENT_APP_PREF_RESULT_UNAVAILABLE; } return callServiceReturn(() -> sService.setTagIntentAppPreferenceForUser(userId, pkg, allow), TAG_INTENT_APP_PREF_RESULT_UNAVAILABLE); } Loading Loading @@ -2808,22 +2560,8 @@ public final class NfcAdapter { if (!sHasNfcFeature) { throw new UnsupportedOperationException(); } try { return sService.isTagIntentAppPreferenceSupported(); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return false; } try { return sService.isTagIntentAppPreferenceSupported(); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return false; } return callServiceReturn(() -> sService.isTagIntentAppPreferenceSupported(), false); } /** Loading @@ -2836,11 +2574,30 @@ public final class NfcAdapter { @TestApi @FlaggedApi(Flags.FLAG_NFC_READ_POLLING_LOOP) public void notifyPollingLoop(@NonNull PollingFrame pollingFrame) { callService(() -> sService.notifyPollingLoop(pollingFrame)); } /** * Notifies the system of new HCE data for tests. * * @hide */ @FlaggedApi(Flags.FLAG_NFC_READ_POLLING_LOOP) public void notifyTestHceData(int technology, byte[] data) { callService(() -> sService.notifyTestHceData(technology, data)); } interface ServiceCall { void call() throws RemoteException; } void callService(ServiceCall call) { try { if (sService == null) { attemptDeadServiceRecovery(null); } sService.notifyPollingLoop(pollingFrame); call.call(); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time Loading @@ -2849,38 +2606,35 @@ public final class NfcAdapter { return; } try { sService.notifyPollingLoop(pollingFrame); call.call(); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } } } /** * Notifies the system of new HCE data for tests. * * @hide */ @FlaggedApi(Flags.FLAG_NFC_READ_POLLING_LOOP) public void notifyTestHceData(int technology, byte[] data) { interface ServiceCallReturn<T> { T call() throws RemoteException; } <T> T callServiceReturn(ServiceCallReturn<T> call, T defaultReturn) { try { if (sService == null) { attemptDeadServiceRecovery(null); } sService.notifyTestHceData(technology, data); return call.call(); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return; return defaultReturn; } try { sService.notifyTestHceData(technology, data); } catch (RemoteException e2) { return call.call(); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } } return defaultReturn; } /** Loading @@ -2891,24 +2645,7 @@ public final class NfcAdapter { @TestApi @FlaggedApi(Flags.FLAG_NFC_READ_POLLING_LOOP) public void notifyHceDeactivated() { try { if (sService == null) { attemptDeadServiceRecovery(null); } sService.notifyHceDeactivated(); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return; } try { sService.notifyHceDeactivated(); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } } callService(() -> sService.notifyHceDeactivated()); } /** Loading @@ -2924,22 +2661,7 @@ public final class NfcAdapter { if (!sHasNfcWlcFeature) { throw new UnsupportedOperationException(); } try { return sService.setWlcEnabled(enable); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return false; } try { return sService.setWlcEnabled(enable); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return false; } return callServiceReturn(() -> sService.setWlcEnabled(enable), false); } /** Loading @@ -2954,22 +2676,8 @@ public final class NfcAdapter { if (!sHasNfcWlcFeature) { throw new UnsupportedOperationException(); } try { return sService.isWlcEnabled(); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return false; } try { return sService.isWlcEnabled(); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return false; } return callServiceReturn(() -> sService.isWlcEnabled(), false); } /** Loading Loading @@ -3048,22 +2756,8 @@ public final class NfcAdapter { if (!sHasNfcWlcFeature) { throw new UnsupportedOperationException(); } try { return sService.getWlcListenerDeviceInfo(); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return null; } try { return sService.getWlcListenerDeviceInfo(); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return null; } return callServiceReturn(() -> sService.getWlcListenerDeviceInfo(), null); } /** Loading Loading
nfc/java/android/nfc/NfcAdapter.java +84 −390 Original line number Diff line number Diff line Loading @@ -963,22 +963,9 @@ public final class NfcAdapter { throw new UnsupportedOperationException("You need a context on NfcAdapter to use the " + " NFC extras APIs"); } try { return sService.getNfcDtaInterface(mContext.getPackageName()); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return null; } try { return sService.getNfcDtaInterface(mContext.getPackageName()); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return null; } return callServiceReturn(() -> sService.getNfcDtaInterface(mContext.getPackageName()), null); } /** Loading Loading @@ -1095,22 +1082,8 @@ public final class NfcAdapter { @SystemApi @FlaggedApi(Flags.FLAG_ENABLE_NFC_MAINLINE) public @AdapterState int getAdapterState() { try { return sService.getState(); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return NfcAdapter.STATE_OFF; } try { return sService.getState(); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return NfcAdapter.STATE_OFF; } return callServiceReturn(() -> sService.getState(), NfcAdapter.STATE_OFF); } /** Loading @@ -1134,22 +1107,8 @@ public final class NfcAdapter { @FlaggedApi(Flags.FLAG_NFC_STATE_CHANGE) @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public boolean enable() { try { return sService.enable(mContext.getPackageName()); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return false; } try { return sService.enable(mContext.getPackageName()); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return false; } return callServiceReturn(() -> sService.enable(mContext.getPackageName()), false); } /** Loading @@ -1175,22 +1134,9 @@ public final class NfcAdapter { @FlaggedApi(Flags.FLAG_NFC_STATE_CHANGE) @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public boolean disable() { try { return sService.disable(true, mContext.getPackageName()); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return false; } try { return sService.disable(true, mContext.getPackageName()); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return false; } return callServiceReturn(() -> sService.disable(true, mContext.getPackageName()), false); } /** Loading @@ -1200,22 +1146,9 @@ public final class NfcAdapter { @SystemApi @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public boolean disable(boolean persist) { try { return sService.disable(persist, mContext.getPackageName()); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return false; } try { return sService.disable(persist, mContext.getPackageName()); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return false; } return callServiceReturn(() -> sService.disable(persist, mContext.getPackageName()), false); } /** Loading @@ -1241,12 +1174,7 @@ public final class NfcAdapter { */ @FlaggedApi(Flags.FLAG_NFC_OBSERVE_MODE) public boolean isObserveModeSupported() { try { return sService.isObserveModeSupported(); } catch (RemoteException e) { attemptDeadServiceRecovery(e); return false; } return callServiceReturn(() -> sService.isObserveModeSupported(), false); } /** Loading @@ -1257,12 +1185,7 @@ public final class NfcAdapter { @FlaggedApi(Flags.FLAG_NFC_OBSERVE_MODE) public boolean isObserveModeEnabled() { try { return sService.isObserveModeEnabled(); } catch (RemoteException e) { attemptDeadServiceRecovery(e); return false; } return callServiceReturn(() -> sService.isObserveModeEnabled(), false); } /** Loading @@ -1286,12 +1209,8 @@ public final class NfcAdapter { throw new UnsupportedOperationException("You need a context on NfcAdapter to use the " + " observe mode APIs"); } try { return sService.setObserveMode(enabled, mContext.getPackageName()); } catch (RemoteException e) { attemptDeadServiceRecovery(e); return false; } return callServiceReturn(() -> sService.setObserveMode(enabled, mContext.getPackageName()), false); } /** Loading Loading @@ -2057,22 +1976,8 @@ public final class NfcAdapter { if (!sHasNfcFeature && !sHasCeFeature) { throw new UnsupportedOperationException(); } try { return sService.setNfcSecure(enable); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return false; } try { return sService.setNfcSecure(enable); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return false; } return callServiceReturn(() -> sService.setNfcSecure(enable), false); } /** Loading @@ -2088,22 +1993,8 @@ public final class NfcAdapter { if (!sHasNfcFeature && !sHasCeFeature) { throw new UnsupportedOperationException(); } try { return sService.deviceSupportsNfcSecure(); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return false; } try { return sService.deviceSupportsNfcSecure(); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return false; } return callServiceReturn(() -> sService.deviceSupportsNfcSecure(), false); } /** Loading @@ -2121,22 +2012,8 @@ public final class NfcAdapter { if (!sHasNfcFeature && !sHasCeFeature) { throw new UnsupportedOperationException(); } try { return sService.getNfcAntennaInfo(); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return null; } try { return sService.getNfcAntennaInfo(); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return null; } return callServiceReturn(() -> sService.getNfcAntennaInfo(), null); } /** Loading @@ -2154,22 +2031,8 @@ public final class NfcAdapter { if (!sHasNfcFeature && !sHasCeFeature) { throw new UnsupportedOperationException(); } try { return sService.isNfcSecureEnabled(); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return false; } try { return sService.isNfcSecureEnabled(); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return false; } return callServiceReturn(() -> sService.isNfcSecureEnabled(), false); } /** Loading @@ -2185,22 +2048,8 @@ public final class NfcAdapter { if (!sHasNfcFeature) { throw new UnsupportedOperationException(); } try { return sService.enableReaderOption(enable); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return false; } try { return sService.enableReaderOption(enable); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return false; } return callServiceReturn(() -> sService.enableReaderOption(enable), false); } /** Loading @@ -2214,22 +2063,8 @@ public final class NfcAdapter { if (!sHasNfcFeature) { throw new UnsupportedOperationException(); } try { return sService.isReaderOptionSupported(); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return false; } try { return sService.isReaderOptionSupported(); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return false; } return callServiceReturn(() -> sService.isReaderOptionSupported(), false); } /** Loading @@ -2245,22 +2080,8 @@ public final class NfcAdapter { if (!sHasNfcFeature) { throw new UnsupportedOperationException(); } try { return sService.isReaderOptionEnabled(); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return false; } try { return sService.isReaderOptionEnabled(); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return false; } return callServiceReturn(() -> sService.isReaderOptionEnabled(), false); } /** Loading Loading @@ -2388,11 +2209,9 @@ public final class NfcAdapter { synchronized (mLock) { mTagRemovedListener = iListener; } try { return sService.ignore(tag.getServiceHandle(), debounceMs, iListener); } catch (RemoteException e) { return false; } final ITagRemovedCallback.Stub passedListener = iListener; return callServiceReturn(() -> sService.ignore(tag.getServiceHandle(), debounceMs, passedListener), false); } /** Loading Loading @@ -2509,22 +2328,9 @@ public final class NfcAdapter { throw new UnsupportedOperationException("You need a context on NfcAdapter to use the " + " NFC extras APIs"); } try { return sService.getNfcAdapterExtrasInterface(mContext.getPackageName()); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return null; } try { return sService.getNfcAdapterExtrasInterface(mContext.getPackageName()); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return null; } return callServiceReturn(() -> sService.getNfcAdapterExtrasInterface(mContext.getPackageName()), null); } void enforceResumed(Activity activity) { Loading Loading @@ -2569,22 +2375,8 @@ public final class NfcAdapter { if (!sHasNfcFeature && !sHasCeFeature) { throw new UnsupportedOperationException(); } try { return sService.setControllerAlwaysOn(value); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return false; } try { return sService.setControllerAlwaysOn(value); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return false; } return callServiceReturn(() -> sService.setControllerAlwaysOn(value), false); } /** Loading @@ -2600,22 +2392,8 @@ public final class NfcAdapter { @SystemApi @RequiresPermission(android.Manifest.permission.NFC_SET_CONTROLLER_ALWAYS_ON) public boolean isControllerAlwaysOn() { try { return sService.isControllerAlwaysOn(); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return false; } try { return sService.isControllerAlwaysOn(); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return false; } return callServiceReturn(() -> sService.isControllerAlwaysOn(), false); } /** Loading @@ -2634,22 +2412,8 @@ public final class NfcAdapter { if (!sHasNfcFeature && !sHasCeFeature) { throw new UnsupportedOperationException(); } try { return sService.isControllerAlwaysOnSupported(); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return false; } try { return sService.isControllerAlwaysOnSupported(); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return false; } return callServiceReturn(() -> sService.isControllerAlwaysOnSupported(), false); } /** Loading Loading @@ -2719,21 +2483,9 @@ public final class NfcAdapter { Log.e(TAG, "TagIntentAppPreference is not supported"); throw new UnsupportedOperationException(); } try { return sService.setTagIntentAppPreferenceForUser(userId, pkg, allow); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); } try { return sService.setTagIntentAppPreferenceForUser(userId, pkg, allow); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return TAG_INTENT_APP_PREF_RESULT_UNAVAILABLE; } return callServiceReturn(() -> sService.setTagIntentAppPreferenceForUser(userId, pkg, allow), TAG_INTENT_APP_PREF_RESULT_UNAVAILABLE); } Loading Loading @@ -2808,22 +2560,8 @@ public final class NfcAdapter { if (!sHasNfcFeature) { throw new UnsupportedOperationException(); } try { return sService.isTagIntentAppPreferenceSupported(); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return false; } try { return sService.isTagIntentAppPreferenceSupported(); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return false; } return callServiceReturn(() -> sService.isTagIntentAppPreferenceSupported(), false); } /** Loading @@ -2836,11 +2574,30 @@ public final class NfcAdapter { @TestApi @FlaggedApi(Flags.FLAG_NFC_READ_POLLING_LOOP) public void notifyPollingLoop(@NonNull PollingFrame pollingFrame) { callService(() -> sService.notifyPollingLoop(pollingFrame)); } /** * Notifies the system of new HCE data for tests. * * @hide */ @FlaggedApi(Flags.FLAG_NFC_READ_POLLING_LOOP) public void notifyTestHceData(int technology, byte[] data) { callService(() -> sService.notifyTestHceData(technology, data)); } interface ServiceCall { void call() throws RemoteException; } void callService(ServiceCall call) { try { if (sService == null) { attemptDeadServiceRecovery(null); } sService.notifyPollingLoop(pollingFrame); call.call(); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time Loading @@ -2849,38 +2606,35 @@ public final class NfcAdapter { return; } try { sService.notifyPollingLoop(pollingFrame); call.call(); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } } } /** * Notifies the system of new HCE data for tests. * * @hide */ @FlaggedApi(Flags.FLAG_NFC_READ_POLLING_LOOP) public void notifyTestHceData(int technology, byte[] data) { interface ServiceCallReturn<T> { T call() throws RemoteException; } <T> T callServiceReturn(ServiceCallReturn<T> call, T defaultReturn) { try { if (sService == null) { attemptDeadServiceRecovery(null); } sService.notifyTestHceData(technology, data); return call.call(); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return; return defaultReturn; } try { sService.notifyTestHceData(technology, data); } catch (RemoteException e2) { return call.call(); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } } return defaultReturn; } /** Loading @@ -2891,24 +2645,7 @@ public final class NfcAdapter { @TestApi @FlaggedApi(Flags.FLAG_NFC_READ_POLLING_LOOP) public void notifyHceDeactivated() { try { if (sService == null) { attemptDeadServiceRecovery(null); } sService.notifyHceDeactivated(); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return; } try { sService.notifyHceDeactivated(); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } } callService(() -> sService.notifyHceDeactivated()); } /** Loading @@ -2924,22 +2661,7 @@ public final class NfcAdapter { if (!sHasNfcWlcFeature) { throw new UnsupportedOperationException(); } try { return sService.setWlcEnabled(enable); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return false; } try { return sService.setWlcEnabled(enable); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return false; } return callServiceReturn(() -> sService.setWlcEnabled(enable), false); } /** Loading @@ -2954,22 +2676,8 @@ public final class NfcAdapter { if (!sHasNfcWlcFeature) { throw new UnsupportedOperationException(); } try { return sService.isWlcEnabled(); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return false; } try { return sService.isWlcEnabled(); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return false; } return callServiceReturn(() -> sService.isWlcEnabled(), false); } /** Loading Loading @@ -3048,22 +2756,8 @@ public final class NfcAdapter { if (!sHasNfcWlcFeature) { throw new UnsupportedOperationException(); } try { return sService.getWlcListenerDeviceInfo(); } catch (RemoteException e) { attemptDeadServiceRecovery(e); // Try one more time if (sService == null) { Log.e(TAG, "Failed to recover NFC Service."); return null; } try { return sService.getWlcListenerDeviceInfo(); } catch (RemoteException ee) { Log.e(TAG, "Failed to recover NFC Service."); } return null; } return callServiceReturn(() -> sService.getWlcListenerDeviceInfo(), null); } /** Loading