diff options
| author | 2019-12-19 12:40:51 +0000 | |
|---|---|---|
| committer | 2019-12-19 12:40:51 +0000 | |
| commit | c6b17a06cd8368264652e40d48d8a246522f72dd (patch) | |
| tree | cfc24302950ca1a0c30118aca42c59e8b224d946 | |
| parent | cbb570901cceb32fe359698f2b0bc54b28fd335a (diff) | |
| parent | 420f048022df77d312fb56883c6968ca6884d08f (diff) | |
Merge "Do not call to SecureElement Service if device does not support any OMAPI readers" am: 98a96a40c6 am: 4d7d5c2c24 am: 420f048022
Change-Id: I325f8910c33bc7994a12a7ac0851df2f7109ef38
| -rw-r--r-- | core/java/android/se/omapi/SEService.java | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/core/java/android/se/omapi/SEService.java b/core/java/android/se/omapi/SEService.java index 00060ab8ef4a..d646e23d230a 100644 --- a/core/java/android/se/omapi/SEService.java +++ b/core/java/android/se/omapi/SEService.java @@ -22,11 +22,14 @@ package android.se.omapi; +import android.app.ActivityThread; import android.annotation.NonNull; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; +import android.content.pm.IPackageManager; +import android.content.pm.PackageManager; import android.os.IBinder; import android.os.RemoteException; import android.util.Log; @@ -140,6 +143,10 @@ public final class SEService { throw new NullPointerException("Arguments must not be null"); } + if (!hasOMAPIReaders()) { + throw new UnsupportedOperationException("Device does not support any OMAPI reader"); + } + mContext = context; mSEListener.mListener = listener; mSEListener.mExecutor = executor; @@ -270,4 +277,23 @@ public final class SEService { throw new IllegalStateException(e.getMessage()); } } + + /** + * Helper to check if this device support any OMAPI readers + */ + private static boolean hasOMAPIReaders() { + IPackageManager pm = ActivityThread.getPackageManager(); + if (pm == null) { + Log.e(TAG, "Cannot get package manager, assuming OMAPI readers supported"); + return true; + } + try { + return pm.hasSystemFeature(PackageManager.FEATURE_SE_OMAPI_UICC, 0) + || pm.hasSystemFeature(PackageManager.FEATURE_SE_OMAPI_ESE, 0) + || pm.hasSystemFeature(PackageManager.FEATURE_SE_OMAPI_SD, 0); + } catch (RemoteException e) { + Log.e(TAG, "Package manager query failed, assuming OMAPI readers supported", e); + return true; + } + } } |