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 "hubconnection.h" 26 27 #define DEBUG_ACTIVITY_RECOGNITION 0 28 29 struct ActivityContext { 30 activity_recognition_device_t device; 31 32 explicit ActivityContext(const struct hw_module_t *module); 33 34 void onActivityEvent( 35 uint64_t when_us, bool is_flush, float x, float y, float z); 36 37 bool getHubAlive(); 38 39 private: 40 android::Mutex mLock; 41 42 android::sp<android::HubConnection> mHubConnection; 43 44 bool mHubAlive; 45 46 const activity_recognition_callback_procs_t *mCallback; 47 48 android::KeyedVector<uint64_t, int64_t> mMaxBatchReportLatencyNs; 49 50 int mPrevActivity; 51 52 bool mInitExitDone; 53 54 ~ActivityContext(); 55 56 int close(); 57 58 void registerActivityCallback( 59 const activity_recognition_callback_procs_t *callback); 60 61 bool isEnabled(uint32_t activity_handle, uint32_t event_type) const; 62 63 int enableActivityEvent( 64 uint32_t activity_handle, 65 uint32_t event_type, 66 int64_t max_batch_report_latency_ns); 67 68 int disableActivityEvent(uint32_t activity_handle, uint32_t event_type); 69 70 int flush(); 71 72 int64_t calculateReportLatencyNs(); 73 74 static int CloseWrapper(struct hw_device_t *dev); 75 76 static void RegisterActivityCallbackWrapper( 77 const struct activity_recognition_device *dev, 78 const activity_recognition_callback_procs_t *callback); 79 80 static int EnableActivityEventWrapper( 81 const struct activity_recognition_device *dev, 82 uint32_t activity_handle, 83 uint32_t event_type, 84 int64_t max_batch_report_latency_ns); 85 86 static int DisableActivityEventWrapper( 87 const struct activity_recognition_device *dev, 88 uint32_t activity_handle, 89 uint32_t event_type); 90 91 static int FlushWrapper(const struct activity_recognition_device *dev); 92 93 static void HubCallbackWrapper( 94 void *me, uint64_t time_ms, bool is_flush, float x, float y, float z); 95 96 DISALLOW_EVIL_CONSTRUCTORS(ActivityContext); 97 }; 98 99 #endif // ACTIVITY_H_ 100 101