diff options
author | Martijn Coenen <maco@google.com> | 2012-02-13 14:18:57 -0800 |
---|---|---|
committer | Martijn Coenen <maco@google.com> | 2012-02-13 15:14:52 -0800 |
commit | e288a8c852ad826efcb2ef5a318394974918209d (patch) | |
tree | 6f9ea0331171a7f8afc043c4f223754dc3836fbb /src/com/android/nfc | |
parent | 3c71cf4faad74e8aedd15d242ff2718fa1f36272 (diff) | |
download | packages_apps_nfc-e288a8c852ad826efcb2ef5a318394974918209d.zip packages_apps_nfc-e288a8c852ad826efcb2ef5a318394974918209d.tar.gz packages_apps_nfc-e288a8c852ad826efcb2ef5a318394974918209d.tar.bz2 |
Cache installed packages for sending SE broadcasts.
Getting the list of installed packages takes some time
on a phone with lots of packages (seen >500ms). Since
we did this for every SE broadcast (including field on / field off),
I've seen the NFC service event queue fill up, which has
a bad effect on latency-critical events such as the events
for llcp link establishment.
This caches the list of installed packages.
Bug: 5963061
Change-Id: Ia9f02c9ce58dae5c81949f7317425e5ee415ee92
Diffstat (limited to 'src/com/android/nfc')
-rwxr-xr-x | src/com/android/nfc/NfcService.java | 62 |
1 files changed, 41 insertions, 21 deletions
diff --git a/src/com/android/nfc/NfcService.java b/src/com/android/nfc/NfcService.java index 90d0036..cebce23 100755 --- a/src/com/android/nfc/NfcService.java +++ b/src/com/android/nfc/NfcService.java @@ -188,6 +188,7 @@ public class NfcService extends Application implements DeviceHostListener { boolean mIsNdefPushEnabled; boolean mNfceeRouteEnabled; // current Device Host state of NFC-EE routing boolean mNfcPollingEnabled; // current Device Host state of NFC-C polling + List<PackageInfo> mInstalledPackages; // cached version of installed packages // mState is protected by this, however it is only modified in onCreate() // and the default AsyncTask thread so it is read unprotected from that @@ -341,15 +342,20 @@ public class NfcService extends Application implements DeviceHostListener { filter.addAction(Intent.ACTION_SCREEN_ON); filter.addAction(ACTION_MASTER_CLEAR_NOTIFICATION); filter.addAction(Intent.ACTION_USER_PRESENT); + filter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE); + filter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE); registerForAirplaneMode(filter); registerReceiver(mReceiver, filter); filter = new IntentFilter(); + filter.addAction(Intent.ACTION_PACKAGE_ADDED); filter.addAction(Intent.ACTION_PACKAGE_REMOVED); filter.addDataScheme("package"); registerReceiver(mReceiver, filter); + updatePackageCache(); + new EnableDisableTask().execute(TASK_BOOT); // do blocking boot tasks } @@ -390,6 +396,14 @@ public class NfcService extends Application implements DeviceHostListener { } } + void updatePackageCache() { + PackageManager pm = getPackageManager(); + List<PackageInfo> packages = pm.getInstalledPackages(0); + synchronized (this) { + mInstalledPackages = packages; + } + } + int checkScreenState() { if (!mPowerManager.isScreenOn()) { return SCREEN_STATE_OFF; @@ -1675,18 +1689,17 @@ public class NfcService extends Application implements DeviceHostListener { } private void sendSeBroadcast(Intent intent) { - PackageManager pm = getPackageManager(); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - // Resume app switches so the receivers can start activites without delay mNfcDispatcher.resumeAppSwitches(); - List<PackageInfo> packages = pm.getInstalledPackages(0); - for (PackageInfo pkg : packages) { - if (pkg != null && pkg.applicationInfo != null) { - if (mNfceeAccessControl.check(pkg.applicationInfo)) { - intent.setPackage(pkg.packageName); - mContext.sendBroadcast(intent); + synchronized(this) { + for (PackageInfo pkg : mInstalledPackages) { + if (pkg != null && pkg.applicationInfo != null) { + if (mNfceeAccessControl.check(pkg.applicationInfo)) { + intent.setPackage(pkg.packageName); + mContext.sendBroadcast(intent); + } } } } @@ -1818,20 +1831,27 @@ public class NfcService extends Application implements DeviceHostListener { } catch (InterruptedException e) { Log.w(TAG, "failed to wipe NFC-EE"); } - } else if (action.equals(Intent.ACTION_PACKAGE_REMOVED)) { - // Clear the NFCEE access cache in case a UID gets recycled - mNfceeAccessControl.invalidateCache(); - - boolean dataRemoved = intent.getBooleanExtra(Intent.EXTRA_DATA_REMOVED, false); - if (dataRemoved) { - Uri data = intent.getData(); - if (data == null) return; - String packageName = data.getSchemeSpecificPart(); + } else if (action.equals(Intent.ACTION_PACKAGE_REMOVED) || + action.equals(Intent.ACTION_PACKAGE_ADDED) || + action.equals(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE) || + action.equals(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE)) { + updatePackageCache(); + + if (action.equals(Intent.ACTION_PACKAGE_REMOVED)) { + // Clear the NFCEE access cache in case a UID gets recycled + mNfceeAccessControl.invalidateCache(); + + boolean dataRemoved = intent.getBooleanExtra(Intent.EXTRA_DATA_REMOVED, false); + if (dataRemoved) { + Uri data = intent.getData(); + if (data == null) return; + String packageName = data.getSchemeSpecificPart(); - synchronized (NfcService.this) { - if (mSePackages.contains(packageName)) { - new EnableDisableTask().execute(TASK_EE_WIPE); - mSePackages.remove(packageName); + synchronized (NfcService.this) { + if (mSePackages.contains(packageName)) { + new EnableDisableTask().execute(TASK_EE_WIPE); + mSePackages.remove(packageName); + } } } } |