Search in sources :

Example 21 with Sensor

use of android.hardware.Sensor in project android_frameworks_base by AOSPA.

the class SensorPowerCalculator method calculateApp.

@Override
public void calculateApp(BatterySipper app, BatteryStats.Uid u, long rawRealtimeUs, long rawUptimeUs, int statsType) {
    // Process Sensor usage
    final SparseArray<? extends BatteryStats.Uid.Sensor> sensorStats = u.getSensorStats();
    final int NSE = sensorStats.size();
    for (int ise = 0; ise < NSE; ise++) {
        final BatteryStats.Uid.Sensor sensor = sensorStats.valueAt(ise);
        final int sensorHandle = sensorStats.keyAt(ise);
        final BatteryStats.Timer timer = sensor.getSensorTime();
        final long sensorTime = timer.getTotalTimeLocked(rawRealtimeUs, statsType) / 1000;
        switch(sensorHandle) {
            case BatteryStats.Uid.Sensor.GPS:
                app.gpsTimeMs = sensorTime;
                app.gpsPowerMah = (app.gpsTimeMs * mGpsPowerOn) / (1000 * 60 * 60);
                break;
            default:
                final int sensorsCount = mSensors.size();
                for (int i = 0; i < sensorsCount; i++) {
                    final Sensor s = mSensors.get(i);
                    if (s.getHandle() == sensorHandle) {
                        app.sensorPowerMah += (sensorTime * s.getPower()) / (1000 * 60 * 60);
                        break;
                    }
                }
                break;
        }
    }
}
Also used : BatteryStats(android.os.BatteryStats) Sensor(android.hardware.Sensor)

Example 22 with Sensor

use of android.hardware.Sensor in project android_frameworks_base by crdroidandroid.

the class PowerManagerService method runPostProximityCheck.

private void runPostProximityCheck(final Runnable r) {
    if (mSensorManager == null) {
        r.run();
        return;
    }
    synchronized (mProximityWakeLock) {
        mProximityWakeLock.acquire();
        mProximityListener = new SensorEventListener() {

            @Override
            public void onSensorChanged(SensorEvent event) {
                cleanupProximityLocked();
                if (!mHandler.hasMessages(MSG_WAKE_UP)) {
                    Slog.w(TAG, "Proximity sensor took too long, wake event already triggered!");
                    return;
                }
                mHandler.removeMessages(MSG_WAKE_UP);
                final float distance = event.values[0];
                if (distance >= PROXIMITY_NEAR_THRESHOLD || distance >= mProximitySensor.getMaximumRange()) {
                    r.run();
                } else {
                    Slog.w(TAG, "Not waking up. Proximity sensor is blocked.");
                }
            }

            @Override
            public void onAccuracyChanged(Sensor sensor, int accuracy) {
            // Do nothing
            }
        };
        mSensorManager.registerListener(mProximityListener, mProximitySensor, SensorManager.SENSOR_DELAY_FASTEST);
    }
}
Also used : SensorEventListener(android.hardware.SensorEventListener) SensorEvent(android.hardware.SensorEvent) Sensor(android.hardware.Sensor)

Example 23 with Sensor

use of android.hardware.Sensor in project android_frameworks_base by DirtyUnicorns.

the class SensorPowerCalculator method calculateApp.

@Override
public void calculateApp(BatterySipper app, BatteryStats.Uid u, long rawRealtimeUs, long rawUptimeUs, int statsType) {
    // Process Sensor usage
    final SparseArray<? extends BatteryStats.Uid.Sensor> sensorStats = u.getSensorStats();
    final int NSE = sensorStats.size();
    for (int ise = 0; ise < NSE; ise++) {
        final BatteryStats.Uid.Sensor sensor = sensorStats.valueAt(ise);
        final int sensorHandle = sensorStats.keyAt(ise);
        final BatteryStats.Timer timer = sensor.getSensorTime();
        final long sensorTime = timer.getTotalTimeLocked(rawRealtimeUs, statsType) / 1000;
        switch(sensorHandle) {
            case BatteryStats.Uid.Sensor.GPS:
                app.gpsTimeMs = sensorTime;
                app.gpsPowerMah = (app.gpsTimeMs * mGpsPowerOn) / (1000 * 60 * 60);
                break;
            default:
                final int sensorsCount = mSensors.size();
                for (int i = 0; i < sensorsCount; i++) {
                    final Sensor s = mSensors.get(i);
                    if (s.getHandle() == sensorHandle) {
                        app.sensorPowerMah += (sensorTime * s.getPower()) / (1000 * 60 * 60);
                        break;
                    }
                }
                break;
        }
    }
}
Also used : BatteryStats(android.os.BatteryStats) Sensor(android.hardware.Sensor)

Example 24 with Sensor

use of android.hardware.Sensor in project aware-client by denzilferreira.

the class Aware_Client method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Android 8 specific: create a notification channel for AWARE
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationManager not_manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        NotificationChannel aware_channel = new NotificationChannel(Aware.AWARE_NOTIFICATION_ID, getResources().getString(com.aware.R.string.app_name), NotificationManager.IMPORTANCE_DEFAULT);
        aware_channel.setDescription(getResources().getString(com.aware.R.string.aware_description));
        aware_channel.enableLights(true);
        aware_channel.setLightColor(Color.BLUE);
        aware_channel.enableVibration(true);
        not_manager.createNotificationChannel(aware_channel);
    }
    prefs = getSharedPreferences("com.aware.phone", Context.MODE_PRIVATE);
    optionalSensors.put(Aware_Preferences.STATUS_ACCELEROMETER, Sensor.TYPE_ACCELEROMETER);
    optionalSensors.put(Aware_Preferences.STATUS_SIGNIFICANT_MOTION, Sensor.TYPE_ACCELEROMETER);
    optionalSensors.put(Aware_Preferences.STATUS_BAROMETER, Sensor.TYPE_PRESSURE);
    optionalSensors.put(Aware_Preferences.STATUS_GRAVITY, Sensor.TYPE_GRAVITY);
    optionalSensors.put(Aware_Preferences.STATUS_GYROSCOPE, Sensor.TYPE_GYROSCOPE);
    optionalSensors.put(Aware_Preferences.STATUS_LIGHT, Sensor.TYPE_LIGHT);
    optionalSensors.put(Aware_Preferences.STATUS_LINEAR_ACCELEROMETER, Sensor.TYPE_LINEAR_ACCELERATION);
    optionalSensors.put(Aware_Preferences.STATUS_MAGNETOMETER, Sensor.TYPE_MAGNETIC_FIELD);
    optionalSensors.put(Aware_Preferences.STATUS_PROXIMITY, Sensor.TYPE_PROXIMITY);
    optionalSensors.put(Aware_Preferences.STATUS_ROTATION, Sensor.TYPE_ROTATION_VECTOR);
    optionalSensors.put(Aware_Preferences.STATUS_TEMPERATURE, Sensor.TYPE_AMBIENT_TEMPERATURE);
    SensorManager manager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    List<Sensor> sensors = manager.getSensorList(Sensor.TYPE_ALL);
    listSensorType = new Hashtable<>();
    for (int i = 0; i < sensors.size(); i++) {
        listSensorType.put(sensors.get(i).getType(), true);
    }
    addPreferencesFromResource(R.xml.aware_preferences);
    setContentView(R.layout.aware_ui);
    REQUIRED_PERMISSIONS.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
    REQUIRED_PERMISSIONS.add(Manifest.permission.ACCESS_WIFI_STATE);
    REQUIRED_PERMISSIONS.add(Manifest.permission.CAMERA);
    REQUIRED_PERMISSIONS.add(Manifest.permission.BLUETOOTH);
    REQUIRED_PERMISSIONS.add(Manifest.permission.BLUETOOTH_ADMIN);
    REQUIRED_PERMISSIONS.add(Manifest.permission.ACCESS_COARSE_LOCATION);
    REQUIRED_PERMISSIONS.add(Manifest.permission.ACCESS_FINE_LOCATION);
    REQUIRED_PERMISSIONS.add(Manifest.permission.READ_PHONE_STATE);
    REQUIRED_PERMISSIONS.add(Manifest.permission.GET_ACCOUNTS);
    REQUIRED_PERMISSIONS.add(Manifest.permission.WRITE_SYNC_SETTINGS);
    REQUIRED_PERMISSIONS.add(Manifest.permission.READ_SYNC_SETTINGS);
    REQUIRED_PERMISSIONS.add(Manifest.permission.READ_SYNC_STATS);
    boolean PERMISSIONS_OK = true;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        for (String p : REQUIRED_PERMISSIONS) {
            if (PermissionChecker.checkSelfPermission(this, p) != PermissionChecker.PERMISSION_GRANTED) {
                PERMISSIONS_OK = false;
                break;
            }
        }
    }
    if (PERMISSIONS_OK) {
        Intent aware = new Intent(this, Aware.class);
        startService(aware);
    }
// IntentFilter awarePackages = new IntentFilter();
// awarePackages.addAction(Intent.ACTION_PACKAGE_ADDED);
// awarePackages.addAction(Intent.ACTION_PACKAGE_REMOVED);
// 
// packageMonitor = new Aware.AndroidPackageMonitor();
// 
// registerReceiver(packageMonitor, awarePackages);
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationManager(android.app.NotificationManager) SensorManager(android.hardware.SensorManager) Intent(android.content.Intent) Sensor(android.hardware.Sensor)

Example 25 with Sensor

use of android.hardware.Sensor in project AndroidSDK-RecipeBook by gabu.

the class Recipe072 method onResume.

@Override
protected void onResume() {
    super.onResume();
    // 明るさセンサーを取得
    List<Sensor> list = mSensorManager.getSensorList(Sensor.TYPE_LIGHT);
    // 取得できなければ何もしない
    if (list.size() < 1)
        return;
    // 明るさセンサーを取得
    Sensor sensor = list.get(0);
    // 明るさセンサーにリスナーを登録
    // 第3引数で感度を指定できます。
    mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL);
}
Also used : Sensor(android.hardware.Sensor)

Aggregations

Sensor (android.hardware.Sensor)36 SensorManager (android.hardware.SensorManager)7 SensorEventListener (android.hardware.SensorEventListener)5 BatteryStats (android.os.BatteryStats)5 SensorEvent (android.hardware.SensorEvent)4 Intent (android.content.Intent)2 Handler (android.os.Handler)2 ArrayList (java.util.ArrayList)2 NotificationChannel (android.app.NotificationChannel)1 NotificationManager (android.app.NotificationManager)1 SharedPreferences (android.content.SharedPreferences)1 Resources (android.content.res.Resources)1 ViewPager (android.support.v4.view.ViewPager)1 View (android.view.View)1 ViewTreeObserver (android.view.ViewTreeObserver)1 Window (android.view.Window)1 AdapterView (android.widget.AdapterView)1 TextView (android.widget.TextView)1 InjectView (butterknife.InjectView)1 BmobUser (cn.bmob.v3.BmobUser)1