summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHimanshu Singh Kushwah <himanshusingh.kushwah@nxp.com>2024-02-16 15:40:07 +0530
committerHimanshu Singh Kushwah <himanshusingh.kushwah@nxp.com>2024-02-16 15:44:44 +0530
commitdce7e562a38bdf83ba060e3dce9f2506f248c158 (patch)
tree2f3661b45e00e50ffa45d296f49f776559340516
parent71e5c4551666094a453da081a44d104619fc233b (diff)
downloadNfc-dce7e562a38bdf83ba060e3dce9f2506f248c158.tar.gz
Optimization during routing table update
If route location is same as Default AID Route, then no routing update is needed. Track power state change and trigger routing update whenever there is change in power state. Bug: 316062619 Test: Manual Change-Id: Ife4be222400e727c7bf418511fdf066376942a3b
-rw-r--r--src/com/android/nfc/cardemulation/AidRoutingManager.java73
1 files changed, 67 insertions, 6 deletions
diff --git a/src/com/android/nfc/cardemulation/AidRoutingManager.java b/src/com/android/nfc/cardemulation/AidRoutingManager.java
index 3e602202..fe29fea6 100644
--- a/src/com/android/nfc/cardemulation/AidRoutingManager.java
+++ b/src/com/android/nfc/cardemulation/AidRoutingManager.java
@@ -52,6 +52,7 @@ public class AidRoutingManager {
int mDefaultIsoDepRoute;
//Let mDefaultRoute as default aid route
int mDefaultRoute;
+ int mPower_empty_AID = 0x00;
int mMaxAidRoutingTableSize;
@@ -197,6 +198,50 @@ public class AidRoutingManager {
return 0;
}
+ //Checking in case of power/route update of any AID after conflict
+ //resolution, is routing required or not?
+ private boolean isAidEntryUpdated(HashMap<String, Integer> currRouteForAid,
+ Map.Entry<String, Integer> aidEntry,
+ HashMap<String, Integer> prevPowerForAid){
+ if((currRouteForAid.get(aidEntry.getKey()) != aidEntry.getValue())||
+ (mPowerForAid.get(aidEntry.getKey()) != prevPowerForAid.get(aidEntry.getKey()))){
+ return true;
+ }
+ return false;
+ }
+
+ //Check if Any AID entry needs to be removed from previously registered
+ //entries in the Routing table. Current AID entries & power state are part of
+ //mRouteForAid & mPowerForAid respectively. previously registered AID entries &
+ //power states are part of input argument prevRouteForAid & prevPowerForAid respectively.
+ private boolean checkUnrouteAid(HashMap<String, Integer> prevRouteForAid,
+ HashMap<String, Integer> prevPowerForAid) {
+ for (Map.Entry<String, Integer> aidEntry : prevRouteForAid.entrySet()) {
+ if((aidEntry.getValue() != mDefaultRoute) &&
+ (!mRouteForAid.containsKey(aidEntry.getKey()) ||
+ isAidEntryUpdated(mRouteForAid, aidEntry, prevPowerForAid))){
+ return true;
+ }
+ }
+ return false;
+ }
+
+ //Check if Any AID entry needs to be added to previously registered
+ //entries in the Routing table. Current AID entries & power state are part of
+ //mRouteForAid & mPowerForAid respectively. previously registered AID entries &
+ //power states are part of input argument prevRouteForAid & prevPowerForAid respectively.
+ private boolean checkRouteAid(HashMap<String, Integer> prevRouteForAid,
+ HashMap<String, Integer> prevPowerForAid){
+ for (Map.Entry<String, Integer> aidEntry : mRouteForAid.entrySet()) {
+ if((aidEntry.getValue() != mDefaultRoute) &&
+ (!prevRouteForAid.containsKey(aidEntry.getKey())||
+ isAidEntryUpdated(prevRouteForAid, aidEntry, prevPowerForAid))){
+ return true;
+ }
+ }
+ return false;
+ }
+
public boolean configureRouting(HashMap<String, AidEntry> aidMap, boolean force) {
boolean aidRouteResolved = false;
HashMap<String, AidEntry> aidRoutingTableCache = new HashMap<String, AidEntry>(aidMap.size());
@@ -206,7 +251,7 @@ public class AidRoutingManager {
} else {
mDefaultRoute = mRoutingOptionManager.getDefaultRoute();
}
-
+ boolean isPowerStateUpdated = false;
seList.add(mDefaultRoute);
if (mDefaultRoute != ROUTE_HOST) {
seList.add(ROUTE_HOST);
@@ -216,6 +261,8 @@ public class AidRoutingManager {
HashMap<String, Integer> routeForAid = new HashMap<String, Integer>(aidMap.size());
HashMap<String, Integer> powerForAid = new HashMap<String, Integer>(aidMap.size());
HashMap<String, Integer> infoForAid = new HashMap<String, Integer>(aidMap.size());
+ HashMap<String, Integer> prevRouteForAid = new HashMap<String, Integer>();
+ HashMap<String, Integer> prevPowerForAid = new HashMap<String, Integer>();
// Then, populate internal data structures first
for (Map.Entry<String, AidEntry> aidEntry : aidMap.entrySet()) {
int route = ROUTE_HOST;
@@ -254,7 +301,9 @@ public class AidRoutingManager {
// Otherwise, update internal structures and commit new routing
clearNfcRoutingTableLocked();
+ prevRouteForAid = mRouteForAid;
mRouteForAid = routeForAid;
+ prevPowerForAid = mPowerForAid;
mPowerForAid = powerForAid;
mAidRoutingTable = aidRoutingTable;
@@ -373,6 +422,9 @@ public class AidRoutingManager {
entry.isOnHost = false;
default_route_power_state = RegisteredAidCache.POWER_STATE_ALL;
}
+ if(mPower_empty_AID != default_route_power_state)
+ isPowerStateUpdated = true;
+ mPower_empty_AID = default_route_power_state;
entry.aidInfo = RegisteredAidCache.AID_ROUTE_QUAL_PREFIX;
entry.power = default_route_power_state;
@@ -396,6 +448,7 @@ public class AidRoutingManager {
for (String aid : aidsForDefaultRoute) {
if (aidMap.get(aid).power != default_route_power_state) {
aidRoutingTableCache.put(aid, aidMap.get(aid));
+ isPowerStateUpdated = true;
}
}
}
@@ -408,12 +461,20 @@ public class AidRoutingManager {
}
}
- if(aidRouteResolved == true) {
- commit(aidRoutingTableCache);
+ boolean mIsUnrouteRequired = checkUnrouteAid(prevRouteForAid, prevPowerForAid);
+ boolean isRouteTableUpdated = checkRouteAid(prevRouteForAid, prevPowerForAid);
+
+ if (isPowerStateUpdated || isRouteTableUpdated || mIsUnrouteRequired || force) {
+ if (aidRouteResolved == true) {
+ commit(aidRoutingTableCache);
+ } else {
+ NfcStatsLog.write(NfcStatsLog.NFC_ERROR_OCCURRED,
+ NfcStatsLog.NFC_ERROR_OCCURRED__TYPE__AID_OVERFLOW, 0, 0);
+ Log.e(TAG, "RoutingTable unchanged because it's full, not updating");
+ }
} else {
- NfcStatsLog.write(NfcStatsLog.NFC_ERROR_OCCURRED,
- NfcStatsLog.NFC_ERROR_OCCURRED__TYPE__AID_OVERFLOW, 0, 0);
- Log.e(TAG, "RoutingTable unchanged because it's full, not updating");
+ Log.e(TAG, "All AIDs routing to mDefaultRoute, RoutingTable"
+ + " update is not required");
}
}
return true;