summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2024-04-09 14:13:47 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2024-04-09 14:13:47 +0000
commitc24c225a9adb42797503a98437297846717afebd (patch)
tree5af35d5b07d93298bba994724c76d82858a66351
parenta2e4189bf58ed864597c99f9ad0b419e5fcd359d (diff)
parentdce7e562a38bdf83ba060e3dce9f2506f248c158 (diff)
downloadNfc-c24c225a9adb42797503a98437297846717afebd.tar.gz
Merge "Optimization during routing table update" into main
-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;