1*79330504STreehugger Robot /* 2*79330504STreehugger Robot * Copyright 2019 The Android Open Source Project 3*79330504STreehugger Robot * 4*79330504STreehugger Robot * Licensed under the Apache License, Version 2.0 (the "License"); 5*79330504STreehugger Robot * you may not use this file except in compliance with the License. 6*79330504STreehugger Robot * You may obtain a copy of the License at 7*79330504STreehugger Robot * 8*79330504STreehugger Robot * http://www.apache.org/licenses/LICENSE-2.0 9*79330504STreehugger Robot * 10*79330504STreehugger Robot * Unless required by applicable law or agreed to in writing, software 11*79330504STreehugger Robot * distributed under the License is distributed on an "AS IS" BASIS, 12*79330504STreehugger Robot * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*79330504STreehugger Robot * See the License for the specific language governing permissions and 14*79330504STreehugger Robot * limitations under the License. 15*79330504STreehugger Robot */ 16*79330504STreehugger Robot 17*79330504STreehugger Robot #include <unistd.h> 18*79330504STreehugger Robot 19*79330504STreehugger Robot #include <iostream> 20*79330504STreehugger Robot 21*79330504STreehugger Robot #include <wakelock/wakelock.h> 22*79330504STreehugger Robot 23*79330504STreehugger Robot static constexpr const char *gWakeLockName = "block_suspend"; 24*79330504STreehugger Robot usage()25*79330504STreehugger Robotstatic void usage() { 26*79330504STreehugger Robot std::cout << "Usage: block_suspend\n" 27*79330504STreehugger Robot << "Prevent device from suspending indefinitely. " 28*79330504STreehugger Robot << "Process must be killed to unblock suspend.\n"; 29*79330504STreehugger Robot } 30*79330504STreehugger Robot main(int argc,char **)31*79330504STreehugger Robotint main(int argc, char ** /* argv */) { 32*79330504STreehugger Robot if (argc > 1) { 33*79330504STreehugger Robot usage(); 34*79330504STreehugger Robot return 0; 35*79330504STreehugger Robot } 36*79330504STreehugger Robot 37*79330504STreehugger Robot auto wl = android::wakelock::WakeLock::tryGet(gWakeLockName); // RAII object 38*79330504STreehugger Robot if (!wl.has_value()) { 39*79330504STreehugger Robot return EXIT_FAILURE; 40*79330504STreehugger Robot } 41*79330504STreehugger Robot 42*79330504STreehugger Robot while (true) { sleep(1000000); }; 43*79330504STreehugger Robot std::abort(); // should never reach here 44*79330504STreehugger Robot return 0; 45*79330504STreehugger Robot } 46