The Upgrade Policy API allows us to specify wether we can perform upgrades or downgrades. The upgrade policy object is created using the UpgradePolicyBuilder, by specifying setAllowUpgrade (to allow upgrades), setAllowDowngrade (to allow downgrades) and setAllowAllUpgrades (to allow all OTA upgrades and downgrades on all devices, as aligned with the ZigBee specification).
By enabling setAllowAllUpgrades, upgrades or downgrades could start automatically if initiated by the end device. If setAllowAllUpgrades is disabled, upgrades or downgrades can only start if initiated by coordinator (using startOtaUpgrade method). By default AllowUpgrade is true, AllowDowngrade is false, and AllowAllUpgrades is false.
Below shows how to apply the upgrade policy.
UpgradePolicyBuilder builder = new UpgradePolicyBuilder(); // allowUpgrade can be true or false builder.setAllowUpgrade(allowUpgrade); // allowUpgrade can be true or false builder.setAllowDowngrade(allowDowngrade); // allowAllUpgrades can be true or false builder.setAllowAllUpgrades(allowAllUpgrades); UpgradePolicy policy = builder.create(); gw.getInternalOtaHandler().setOtaUpgradePolicy(policy);