1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
| package android.hardware;
import android.app.ActivityThread; import android.app.IOplusCompactWindowAppManager; import android.common.OplusFeatureCache; import android.content.Context; import android.hardware.SystemSensorManager; import android.os.Handler; import android.os.SystemProperties; import android.util.Log; import com.aiunit.aon.AonSmartRotation; import com.oplus.android.internal.util.OplusFrameworkStatsLog; import java.util.HashMap;
public class SystemSensorManagerExtImpl implements ISystemSensorManagerExt { private static final boolean DEBUG_DYNAMIC_SENSOR = false; private static final float FLOAT_DIFF = 0.0f; private static final int MESSAGE_WHAT = 1001; private static final int POST_DELAYED_INTERVEL = 5000; private static final int SENSOR_VALUE_STEP = 100; private static final int STATSLOG_CONSTANT = 1; private static final String TAG = "SystemSensorManagerExtImpl"; public static final int TYPE_PEDOMETER_MINUTE = 33171034; public static boolean sInZoomWindow; private int mSensorEnableStatus; private float mSensorEventValueLight; private SensorEvent mSensorevent; private Handler mTimerHandler; public static float mLastStep = 0.0f; public static float mPedoLastStep = 0.0f; public static int MAX_STEP_INTERVAL = 100; public static AonSmartRotation mAonSmartRotation = null; public static boolean haveAonSmartRotation = false; public static float hardwareValue = 0.0f; public static int mLastSmartRotationStatus = 0; public static int mCurrentSmartRotationStatus = 0; private static float sSensorEventValueLight = 1.0f; private static long sTimestamp = 0; private static int sOldProxStatus = 1; private static int sProxStatus = 1; private static boolean sStepDectorFlag = false; private Runnable mTimerThread = new Runnable() { @Override public void run() { SystemSensorManagerExtImpl.sStepDectorFlag = false; long duration = SystemSensorManagerExtImpl.this.mSensorevent.timestamp - SystemSensorManagerExtImpl.sTimestamp; OplusFrameworkStatsLog.write(100098, SystemSensorManagerExtImpl.sTimestamp, SystemSensorManagerExtImpl.this.mSensorevent.timestamp, duration, SystemSensorManagerExtImpl.this.mSensorevent.sensor.getHandle()); } }; public IOplusCompactWindowAppManager mCompactWindowAppManager = OplusFeatureCache.getOrCreate(IOplusCompactWindowAppManager.DEFAULT, new Object[0]);
public SystemSensorManagerExtImpl(Object base) { }
public boolean registerListenerImplHook(Context context, SensorEventListener listener, Sensor sensor, int delayUs) { if (listener != null) { if (sensor == null) { Log.v(TAG, "RegisterListener by " + listener.toString() + " from " + context.getPackageName()); } else { Log.v(TAG, "RegisterListener " + sensor.getName() + " type:" + sensor.getType() + " delay:" + delayUs + "us by " + listener.toString() + " from " + context.getPackageName()); } if (listener.getClass().getName() != null && listener.getClass().getName().indexOf("com.tencent.beacon") != -1) { Log.w(TAG, "Block tencent beacon for using sensor."); return true; } } if (sensor != null) { try { if (sensor.getType() == 27 && mAonSmartRotation == null) { haveAonSmartRotation = SystemProperties.get("persist.sys.oplus.smartrotation", "false").equals("true"); if (haveAonSmartRotation) { mAonSmartRotation = new AonSmartRotation(context); if (listener != null) { Log.d(TAG, "SmartRotationDebug, Init AonSmartRotation by " + listener.toString()); return false; } return false; } return false; } return false; } catch (Exception e) { Log.e(TAG, "SmartRotation got exception, e = " + e.toString()); return false; } } return false; }
public boolean unregisterListenerImplHook(SensorEventListener listener, Sensor sensor) { if (listener != null) { if (sensor != null) { Log.v(TAG, "unRegisterListener by " + listener.toString() + " and its name is " + sensor.getName()); } else { Log.v(TAG, "unRegisterListener by " + listener.toString()); } } if (sensor != null) { try { if (sensor.getType() == 27 && mAonSmartRotation != null) { mAonSmartRotation = null; if (listener != null) { Log.d(TAG, "SmartRotationDebug, Destroy AonSmartRotation by " + listener.toString()); return false; } return false; } return false; } catch (Exception e) { Log.e(TAG, "SmartRotation got exception, e = " + e.toString()); return false; } } return false; }
private boolean blockDispatchEvent(SensorEventListener listener, Sensor sensor, SensorEvent events) { if (sensor == null || sensor.getType() != 27 || events.values[0] <= 4.0d) { return sensor != null && (sensor.getType() == 27 || sensor.getType() == 8 || sensor.getType() == 1) && sInZoomWindow; } return true; }
private boolean needToAdjustEvent(SensorEventListener listener, Sensor sensor, SensorEvent events) { if (sensor == null) { return false; } try { if (sensor.getType() == 19) { if (mLastStep == 0.0f || Math.abs(events.values[0] - mLastStep) >= MAX_STEP_INTERVAL) { Log.v(TAG, "step counter dispatchSensorEvent step " + events.values[0] + " to + " + listener); mLastStep = events.values[0]; } } else if (sensor.getType() == 33171034 && (mPedoLastStep == 0.0f || Math.abs(events.values[0] - mPedoLastStep) >= MAX_STEP_INTERVAL)) { Log.v(TAG, "Pedometer minute step counter dispatchSensorEvent step " + events.values[0] + " to + " + listener); mPedoLastStep = events.values[0]; } } catch (Exception e) { Log.e(TAG, "step counter error e = " + e.toString()); } return sensor.getType() == 27 && haveAonSmartRotation && mAonSmartRotation != null; }
public SensorEvent dispatchEventDataAdjust(SensorEventListener listener, Sensor sensor, SensorEvent events) { if (sensor != null) { try { if (sensor.getType() == 27 && haveAonSmartRotation && mAonSmartRotation != null) { mCurrentSmartRotationStatus = mAonSmartRotation.getStatus(); if (mCurrentSmartRotationStatus != mLastSmartRotationStatus) { if (mCurrentSmartRotationStatus == 1) { Log.d(TAG, "SmartRotationDebug, SmartRotation switch On."); mAonSmartRotation.createSmartRotationConnection(); } else if (mCurrentSmartRotationStatus == 0) { Log.d(TAG, "SmartRotationDebug, SmartRotation switch Off."); mAonSmartRotation.destroySmartRotationConnection(); } else { Log.w(TAG, "SmartRotationDebug, SmartRotation switch Invalid, reset Status value."); mCurrentSmartRotationStatus = 0; mLastSmartRotationStatus = 0; } } mLastSmartRotationStatus = mCurrentSmartRotationStatus; hardwareValue = events.values[0]; events.values[0] = mAonSmartRotation.makeDecisionBySmartRotation(events.values); if (hardwareValue != events.values[0]) { Log.d(TAG, "SmartRotationDebug, Device Orientation changed by SmartRotation, t.value[0] is " + events.values[0] + ", and Hardware Value is " + hardwareValue + "to: " + listener); } } } catch (Exception e) { Log.e(TAG, "SmartRotation got exception, e = " + e.toString()); } } return events; }
public SensorEvent dispatchSensorEventHook(SensorEventListener listener, Sensor sensor, SensorEvent events, boolean inMirage, int cmdArgs, Context context) { SensorEvent t = events; int type = sensor != null ? sensor.getType() : -1; if (needToAdjustEvent(listener, sensor, events)) { t = dispatchEventDataAdjust(listener, sensor, events); } if (blockDispatchEvent(listener, sensor, events)) { t = null; } if (inMirage) { t = null; } if (cmdArgs == 1) { Log.d(TAG, "dispatchSensorEventHook newEvent=" + t + ",oldEvent=" + events + ",type=" + type + ",sInZoomWindow=" + sInZoomWindow + ",inMirage=" + inMirage + ",listener=" + listener); } if (!ActivityThread.isSystem() && this.mCompactWindowAppManager != null && this.mCompactWindowAppManager.blockOrientationSensorEventInCompactWindowMode(context, sensor.getType(), ActivityThread.currentPackageName())) { return null; } return t; }
public void dispatchSensorEventEnd(int res, int handle, float[] values, int accuracy, int type, int cmdArgs, String client) { if (cmdArgs == 1) { Log.d(TAG, "dispatchSensorEvent_end reportedRes=" + res + ",type=" + type + ",handle=data[" + values[0] + "," + values[1] + "," + values[2] + "],accuracy=" + accuracy + handle + ",client=" + client); } }
public void printSensorListenersWhileExceededLocked(Context context, HashMap<SensorEventListener, SystemSensorManager.SensorEventQueue> sensorListeners) { if (sensorListeners != null) { HashMap<SensorEventListener, SystemSensorManager.SensorEventQueue> listeners = new HashMap<>(sensorListeners); Log.e(TAG, "sensorListeners exceeded, size = " + listeners.size() + " in " + context.getPackageName()); for (SensorEventListener l : listeners.keySet()) { Log.e(TAG, "listener : " + l.toString()); } } }
public void enableSensorStatsLog(int enbale, int handler, int sensorType, String opPackageName, String packageName) { switch (sensorType) { case 5: case 8: case 18: case 19: case 30: if (this.mSensorEnableStatus != enbale) { this.mSensorEnableStatus = enbale; OplusFrameworkStatsLog.write(100038, handler, opPackageName, sensorType, packageName, enbale, this.mSensorEventValueLight); return; } return; default: return; } }
public void sensorDispatchEventStasLog(SensorEvent event, float[] values) { float max = event.sensor.getMaximumRange(); switch (event.sensor.getType()) { case 5: this.mSensorEventValueLight = Math.round((values[0] * 100.0f) / max); if (Math.abs(sSensorEventValueLight - this.mSensorEventValueLight) > 1.0f) { sSensorEventValueLight = this.mSensorEventValueLight; OplusFrameworkStatsLog.write(100039, event.sensor.getName(), event.sensor.getType(), event.accuracy, this.mSensorEventValueLight); return; } return; case 8: float distance = values[0]; if (distance >= 0.0f && distance < max) { sProxStatus = 1; } else { sProxStatus = 0; } if (sOldProxStatus != sProxStatus) { sOldProxStatus = sProxStatus; OplusFrameworkStatsLog.write(100039, event.sensor.getName(), event.sensor.getType(), event.accuracy, values[0]); return; } return; case 18: case 19: this.mSensorevent = event; if (this.mTimerHandler == null) { this.mTimerHandler = new Handler(); } if (!sStepDectorFlag) { sTimestamp = event.timestamp; sStepDectorFlag = true; this.mTimerHandler.postDelayed(this.mTimerThread, 1001, 5000L); return; } else { this.mTimerHandler.removeMessages(1001); this.mTimerHandler.postDelayed(this.mTimerThread, 1001, 5000L); return; } default: return; } } }
|