public boolean updateAppKey(@NonNull final ApplicationKey applicationKey, @NonNull final String newAppKey) throws IllegalArgumentException {
        if (MeshParserUtils.validateKeyInput(newAppKey)) {
            final byte[] key = MeshParserUtils.toByteArray(newAppKey);
            if (isNetKeyExists(key)) {
                throw new IllegalArgumentException("Net key already in use");
            }

            final int keyIndex = applicationKey.getKeyIndex();
            final ApplicationKey appKey = getAppKey(keyIndex);
            if (!isKeyInUse(appKey)) {
                //We check if the contents of the key are the same
                //This will return true only if the key index and the key are the same
                if (appKey.equals(applicationKey)) {
                    appKey.setKey(key);
                    return updateMeshKey(appKey);
                } else {
                    return false;
                }
            } else {
                throw new IllegalArgumentException("Unable to update a application key that's already in use.");
            }
        }
        return false;
    }
Updates an app key with a given key in the mesh network.

<p>
Updates the Key if it is not use, if not Updating a Key's key value requires initiating a Key Refresh Procedure.
This requires the bound NetworkKey of the AppKey to be updated. A NetworkKey that's in use would require a
Key Refresh Procedure to update it's key contents. However a NetworkKey that's not in could be updated without this
procedure. If the key is in use, call {@link #distributeNetKey(NetworkKey, byte[])} to initiate the Key Refresh Procedure.
</p>

@param applicationKey {@link ApplicationKey}
@param newAppKey      Application key
@throws IllegalArgumentException if the key is in use.
mesh/src/main/java/no/nordicsemi/android/mesh/BaseMeshNetwork.java