Thu, 15 Jan 2015 15:59:08 +0100
Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright (c) 2013, Linux Foundation. All rights reserved |
michael@0 | 3 | * |
michael@0 | 4 | * Copyright (C) 2008 The Android Open Source Project |
michael@0 | 5 | * |
michael@0 | 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
michael@0 | 7 | * you may not use this file except in compliance with the License. |
michael@0 | 8 | * You may obtain a copy of the License at |
michael@0 | 9 | * |
michael@0 | 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
michael@0 | 11 | * |
michael@0 | 12 | * Unless required by applicable law or agreed to in writing, software |
michael@0 | 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
michael@0 | 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
michael@0 | 15 | * See the License for the specific language governing permissions and |
michael@0 | 16 | * limitations under the License. |
michael@0 | 17 | */ |
michael@0 | 18 | |
michael@0 | 19 | #ifndef ProcessOrientation_h |
michael@0 | 20 | #define ProcessOrientation_h |
michael@0 | 21 | |
michael@0 | 22 | #include "mozilla/Hal.h" |
michael@0 | 23 | |
michael@0 | 24 | namespace mozilla { |
michael@0 | 25 | |
michael@0 | 26 | // History of observed tilt angles. |
michael@0 | 27 | #define TILT_HISTORY_SIZE 40 |
michael@0 | 28 | |
michael@0 | 29 | class ProcessOrientation { |
michael@0 | 30 | public: |
michael@0 | 31 | ProcessOrientation() {}; |
michael@0 | 32 | ~ProcessOrientation() {}; |
michael@0 | 33 | |
michael@0 | 34 | int OnSensorChanged(const mozilla::hal::SensorData& event, int deviceCurrentRotation); |
michael@0 | 35 | int Reset(); |
michael@0 | 36 | |
michael@0 | 37 | private: |
michael@0 | 38 | int GetProposedRotation(); |
michael@0 | 39 | |
michael@0 | 40 | // Returns true if the tilt angle is acceptable for a given predicted |
michael@0 | 41 | // rotation. |
michael@0 | 42 | bool IsTiltAngleAcceptable(int rotation, int tiltAngle); |
michael@0 | 43 | |
michael@0 | 44 | // Returns true if the orientation angle is acceptable for a given predicted |
michael@0 | 45 | // rotation. This function takes into account the gap between adjacent |
michael@0 | 46 | // orientations for hysteresis. |
michael@0 | 47 | bool IsOrientationAngleAcceptable(int rotation, int orientationAngle, |
michael@0 | 48 | int currentRotation); |
michael@0 | 49 | |
michael@0 | 50 | // Returns true if the predicted rotation is ready to be advertised as a |
michael@0 | 51 | // proposed rotation. |
michael@0 | 52 | bool IsPredictedRotationAcceptable(long now); |
michael@0 | 53 | |
michael@0 | 54 | void ClearPredictedRotation(); |
michael@0 | 55 | void UpdatePredictedRotation(long now, int rotation); |
michael@0 | 56 | bool IsAccelerating(float magnitude); |
michael@0 | 57 | void ClearTiltHistory(); |
michael@0 | 58 | void AddTiltHistoryEntry(long now, float tilt); |
michael@0 | 59 | bool IsFlat(long now); |
michael@0 | 60 | bool IsSwinging(long now, float tilt); |
michael@0 | 61 | int NextTiltHistoryIndex(int index); |
michael@0 | 62 | float RemainingMS(long now, long until); |
michael@0 | 63 | |
michael@0 | 64 | // The tilt angle range in degrees for each orientation. Beyond these tilt |
michael@0 | 65 | // angles, we don't even consider transitioning into the specified orientation. |
michael@0 | 66 | // We place more stringent requirements on unnatural orientations than natural |
michael@0 | 67 | // ones to make it less likely to accidentally transition into those states. |
michael@0 | 68 | // The first value of each pair is negative so it applies a limit when the |
michael@0 | 69 | // device is facing down (overhead reading in bed). The second value of each |
michael@0 | 70 | // pair is positive so it applies a limit when the device is facing up |
michael@0 | 71 | // (resting on a table). The ideal tilt angle is 0 (when the device is vertical) |
michael@0 | 72 | // so the limits establish how close to vertical the device must be in order |
michael@0 | 73 | // to change orientation. |
michael@0 | 74 | static const int tiltTolerance[][4]; |
michael@0 | 75 | |
michael@0 | 76 | // Timestamp and value of the last accelerometer sample. |
michael@0 | 77 | long mLastFilteredTimestampNanos; |
michael@0 | 78 | float mLastFilteredX, mLastFilteredY, mLastFilteredZ; |
michael@0 | 79 | |
michael@0 | 80 | // The last proposed rotation, -1 if unknown. |
michael@0 | 81 | int mProposedRotation; |
michael@0 | 82 | |
michael@0 | 83 | // Value of the current predicted rotation, -1 if unknown. |
michael@0 | 84 | int mPredictedRotation; |
michael@0 | 85 | |
michael@0 | 86 | // Timestamp of when the predicted rotation most recently changed. |
michael@0 | 87 | long mPredictedRotationTimestampNanos; |
michael@0 | 88 | |
michael@0 | 89 | // Timestamp when the device last appeared to be flat for sure (the flat delay |
michael@0 | 90 | // elapsed). |
michael@0 | 91 | long mFlatTimestampNanos; |
michael@0 | 92 | |
michael@0 | 93 | // Timestamp when the device last appeared to be swinging. |
michael@0 | 94 | long mSwingTimestampNanos; |
michael@0 | 95 | |
michael@0 | 96 | // Timestamp when the device last appeared to be undergoing external |
michael@0 | 97 | // acceleration. |
michael@0 | 98 | long mAccelerationTimestampNanos; |
michael@0 | 99 | |
michael@0 | 100 | struct { |
michael@0 | 101 | struct { |
michael@0 | 102 | float tiltAngle; |
michael@0 | 103 | long timestampNanos; |
michael@0 | 104 | } history[TILT_HISTORY_SIZE]; |
michael@0 | 105 | int index; |
michael@0 | 106 | } mTiltHistory; |
michael@0 | 107 | }; |
michael@0 | 108 | |
michael@0 | 109 | } // namespace mozilla |
michael@0 | 110 | #endif |