## 1 Introduction  
We have come a long way towards realizing [PERSON]'s 1991 vision of ubiquitous computing, where anytime, anywhere technologies will penetrate into our daily lives to such an extent that they become indistinguishable from the environments we live in. Cyber-physical systems (CPSs) such as smart cities and societies are examples of such environments [1; 2]. The vision is to make systems and applications coexist in these environments, interacting with each other, producing and consuming historical and real-time information emanating from humans, sensors, and machines, and improving quality of life in many areas, for example, transportation [3; 4; 5; 6], healthcare [7], and others [8]. The Internet of Things (IoT) is a vital technology to enable sensing, actions, and other interactions among various \"entities\" in these ubiquitous environments [9; 10; 11; 12]. The number of \"things\" connected to the IoT is expected to reach 50 billion by 2020 due to the massive influx of diverse \"things\" emerging rapidly [13]. This will enable us to monitor and control our environments at micro-levels, in time and space, advancing the path to providing interactive, personalized, and smarter services. However, it will also require solving challenges related to transport, management and analysis of data generatedfrom IoT, particularly the challenges related to the 4 Vs of big data analytics (Volume, Velocity, Variety, and Veracity) [9; 14]. Any movement of data requires energy and could increase latency. The data, analytics, and other computations would have to be optimally migrated and placed in these environments--on the device, or in the cloud, fog, or edge layers--such that various energy efficiency and QoS demands of these applications and the environments are best satisfied. The ubiquitous environments hence will need reliable, high speed, and low latency wireless networks. 5G networks with their significantly higher speeds (50 Mbps--Gbps), lower-latency, reliability, capacity, and other benefits offer a powerful communication platform for ubiquitous environments [15]. However, privacy and security of users and data will pose paramount challenges in the adoption of these ubiquitous environments by governments, industry, and common people. A particular challenge in this context would be to preserve privacy and security while delivering quality of service (QoS) and energy-efficiency. Several works have tried to address these challenges (QoS, energy efficiency, security, and privacy) in distributed environments [16; 17; 18; 19; 20; 21]. Despite these efforts, a number of gaps exist (see Section 2 for a detailed literature review). Firstly, the focus of the existing approaches is on improving or optimizing one or two of the design parameters--QoS, energy efficiency, security or privacy. Optimizing one or more parameters without measuring and counteracting their impact on other parameters is no more acceptable in the emerging ubiquitous environments. Secondly, existing approaches assume a fixed network configuration and attack models, and use fixed strategies in devising solutions. However, real environments are unpredictable and hence a priory identification of all design and operations parameters is not feasible. Solutions are needed that dynamically and adaptively devise strategies and make decisions in rapidly changing ubiquitous environments and holistically optimize performance subject to varying sets of policy constraints. This paper proposes UbiPriSEQ, a framework that adaptively, dynamically, and holistically optimizes QoS, energy-efficiency, security, and privacy of IoT devices and 5G heterogeneous networks (HetNet) based environments. The Framework is built on a three-layered model of ubiquitous environments (IoT Devices Layer, FRAN Layer, and Core Layer). It comprises two modules (Device Module and Network Module). Device Module executes within the IoT Devices Layer, and Network Module runs in both the FRAN Layer and Core Layer.