1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ACTIVITY_H_ 18 19 #define ACTIVITY_H_ 20 21 #include <hardware/activity_recognition.h> 22 #include <media/stagefright/foundation/ABase.h> 23 #include <utils/KeyedVector.h> 24 25 #include "activityeventhandler.h" 26 #include "hubconnection.h" 27 28 namespace android { 29 30 class ActivityContext : public ActivityEventHandler { 31 public: 32 activity_recognition_device_t device; 33 34 explicit ActivityContext(const struct hw_module_t *module); 35 ~ActivityContext(); 36 37 bool getHubAlive(); 38 39 void registerActivityCallback( 40 const activity_recognition_callback_procs_t *callback); 41 42 bool isEnabled(uint32_t activity_handle, uint32_t event_type) const; 43 44 int enableActivityEvent(uint32_t activity_handle, 45 uint32_t event_type, int64_t max_batch_report_latency_ns); 46 47 int disableActivityEvent(uint32_t activity_handle, uint32_t event_type); 48 49 int flush(); 50 51 // ActivityEventHandler interface. 52 virtual void OnActivityEvent(int activityRaw, uint64_t whenNs) override; 53 virtual void OnFlush() override; 54 private: 55 android::sp<android::HubConnection> mHubConnection; 56 57 android::Mutex mCallbackLock; 58 const activity_recognition_callback_procs_t *mCallback; 59 60 android::KeyedVector<uint64_t, int64_t> mMaxBatchReportLatencyNs; 61 62 int mPrevActivity; 63 64 bool mInitExitDone; 65 66 int64_t calculateReportLatencyNs(); 67 68 DISALLOW_EVIL_CONSTRUCTORS(ActivityContext); 69 }; 70 71 } // namespace android 72 73 #endif // ACTIVITY_H_ 74 75