/* * Copyright (C) 2016 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef CAR_VEHICLE_MONITOR_SERVICE_H_ #define CAR_VEHICLE_MONITOR_SERVICE_H_ #include #include #include #include #include #include #include #include #include #include namespace android { // ---------------------------------------------------------------------------- class VehicleMonitorService; /** * MessageHandler to handle periodic data processing. * Init / release is handled in the handler thread to allow upper layer to * allocate resource for the thread. */ class VehicleMonitorMessageHandler : public MessageHandler { enum { COLLECT_DATA = 0, }; public: // not passing VMS as sp as this is held by VMS always. VehicleMonitorMessageHandler( const sp& mLooper, VehicleMonitorService& service); virtual ~VehicleMonitorMessageHandler(); void dump(String8& msg); private: void handleMessage(const Message& message); void doHandleCollectData(); private: mutable std::mutex mLock; const sp mLooper; ProcessMonitor mProcessMonitor; VehicleMonitorService& mService; int64_t mLastDispatchTime; }; // ---------------------------------------------------------------------------- class VehicleMonitorService : public BinderService, public BnVehicleMonitor, public IBinder::DeathRecipient { public: static const char* getServiceName() ANDROID_API { return IVehicleMonitor::SERVICE_NAME; }; VehicleMonitorService(); ~VehicleMonitorService(); virtual status_t dump(int fd, const Vector& args); void release(); virtual void binderDied(const wp& who); virtual status_t setAppPriority( uint32_t pid, uint32_t uid, vehicle_app_priority priority); virtual status_t setMonitorListener( const sp &listener); private: // RefBase virtual void onFirstRef(); private: static VehicleMonitorService* sInstance; sp mHandlerThread; sp mHandler; mutable std::mutex mLock; }; } #endif /* CAR_VEHICLE_MONITOR_SERVICE_H_ */