This article addresses the problem of secure communication in an unmanned aerial vehicle (UAV)-aided wireless communication system in which a source sends confidential messages to a destination via an untrusted UAV mounted with a miniaturized energy-harvesting transceiver.The UAV can overhear the source's confidential messages. To create a positive secrecy rate, the destination sends jamming signals during the communication. We aim to maximize the achievable secrecy rate for two scenarios: security-on-demand UAV (SoD-UAV), where the UAV can modify its trajectory and power-splitting (PS) ratio to serve the secure communication, and non-security-on-demand UAV (nSoD-UAV), where the UAV only forwards the source's messages. For the nSoD-UAV, we optimize the transmit powers at the source and the destination for a given UAV's trajectory and given PS ratios. For the SoD-UAV, the UAV's trajectory, the PS ratios and the transmit powers are jointly optimized. Due to the non-convex optimization problems, we use successive convex optimization and block coordinate descent methods to find efficient approximate solutions. Numerical results verify that the achievable secrecy rate is significantly improved using the proposed algorithms.