blob: bba83727d9b09371545d59c2620a9312155b9240 [file] [log] [blame]
Peng Xueb4d6282015-12-10 18:02:41 -08001/*
2 * Copyright (C) 2010 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 ANDROID_SENSOR_REGISTRATION_INFO_H
18#define ANDROID_SENSOR_REGISTRATION_INFO_H
19
Peng Xu51224682017-03-10 16:57:27 -080020#include "SensorServiceUtils.h"
21#include <utils/Thread.h>
22#include <iomanip>
23#include <sstream>
24
Peng Xueb4d6282015-12-10 18:02:41 -080025namespace android {
26
27class SensorService;
28
Peng Xu51224682017-03-10 16:57:27 -080029class SensorService::SensorRegistrationInfo : public SensorServiceUtil::Dumpable {
30public:
Peng Xueb4d6282015-12-10 18:02:41 -080031 SensorRegistrationInfo() : mPackageName() {
32 mSensorHandle = mSamplingRateUs = mMaxReportLatencyUs = INT32_MIN;
Peng Xu51224682017-03-10 16:57:27 -080033 mHour = mMin = mSec = INT8_MIN;
Peng Xueb4d6282015-12-10 18:02:41 -080034 mActivated = false;
35 }
36
Peng Xu51224682017-03-10 16:57:27 -080037 SensorRegistrationInfo(int32_t handle, const String8 &packageName,
Julius D'souzac35b8202017-12-11 17:33:04 -080038 int64_t samplingRateNs, int64_t maxReportLatencyNs, bool activate) {
Peng Xu51224682017-03-10 16:57:27 -080039 mSensorHandle = handle;
40 mPackageName = packageName;
41
Julius D'souzac35b8202017-12-11 17:33:04 -080042 mSamplingRateUs = static_cast<int64_t>(samplingRateNs/1000);
43 mMaxReportLatencyUs = static_cast<int64_t>(maxReportLatencyNs/1000);
Peng Xu51224682017-03-10 16:57:27 -080044 mActivated = activate;
45
46 IPCThreadState *thread = IPCThreadState::self();
47 mPid = (thread != nullptr) ? thread->getCallingPid() : -1;
48 mUid = (thread != nullptr) ? thread->getCallingUid() : -1;
49
50 time_t rawtime = time(NULL);
51 struct tm * timeinfo = localtime(&rawtime);
52 mHour = static_cast<int8_t>(timeinfo->tm_hour);
53 mMin = static_cast<int8_t>(timeinfo->tm_min);
54 mSec = static_cast<int8_t>(timeinfo->tm_sec);
Peng Xueb4d6282015-12-10 18:02:41 -080055 }
Peng Xu51224682017-03-10 16:57:27 -080056
57 static bool isSentinel(const SensorRegistrationInfo& info) {
58 return (info.mHour == INT8_MIN &&
59 info.mMin == INT8_MIN &&
60 info.mSec == INT8_MIN);
61 }
62
63 // Dumpable interface
64 virtual std::string dump() const override {
65 std::ostringstream ss;
66 ss << std::setfill('0') << std::setw(2) << static_cast<int>(mHour) << ":"
67 << std::setw(2) << static_cast<int>(mMin) << ":"
68 << std::setw(2) << static_cast<int>(mSec)
69 << (mActivated ? " +" : " -")
70 << " 0x" << std::hex << std::setw(8) << mSensorHandle << std::dec
71 << std::setfill(' ') << " pid=" << std::setw(5) << mPid
72 << " uid=" << std::setw(5) << mUid << " package=" << mPackageName;
73 if (mActivated) {
74 ss << " samplingPeriod=" << mSamplingRateUs << "us"
75 << " batchingPeriod=" << mMaxReportLatencyUs << "us";
76 };
77 return ss.str();
78 }
79
80private:
81 int32_t mSensorHandle;
82 String8 mPackageName;
83 pid_t mPid;
84 uid_t mUid;
Julius D'souzac35b8202017-12-11 17:33:04 -080085 int64_t mSamplingRateUs;
86 int64_t mMaxReportLatencyUs;
Peng Xu51224682017-03-10 16:57:27 -080087 bool mActivated;
88 int8_t mHour, mMin, mSec;
89
Peng Xueb4d6282015-12-10 18:02:41 -080090};
91
92} // namespace android;
93
94#endif // ANDROID_SENSOR_REGISTRATION_INFO_H
95
96