From 2daf227cf3c181c35ea70060c9baf5ef6c426c70 Mon Sep 17 00:00:00 2001 From: TARKZiM Date: Mon, 4 May 2020 16:01:47 +0800 Subject: [PATCH] Revert "kitakami-common: Add SonyDoze service" * No that useful for us. This reverts commit 3d54ab4354d2208914109fbad9ef12c4622454cf. --- device-common.mk | 4 - doze/Android.mk | 43 ----- doze/AndroidManifest.xml | 59 ------ doze/proguard.flags | 8 - doze/res/color/switch_bar_bg.xml | 20 --- .../res/color/switchbar_switch_thumb_tint.xml | 20 --- .../res/color/switchbar_switch_track_tint.xml | 21 --- doze/res/drawable/switchbar_background.xml | 20 --- doze/res/layout/doze.xml | 28 --- doze/res/layout/switch_bar.xml | 48 ----- doze/res/values/styles.xml | 62 ------- doze/res/xml/doze_settings.xml | 49 ----- .../settings/doze/BootCompletedReceiver.java | 38 ---- .../lineageos/settings/doze/DozeService.java | 98 ---------- .../settings/doze/DozeSettingsActivity.java | 34 ---- .../settings/doze/DozeSettingsFragment.java | 168 ------------------ .../settings/doze/ProximitySensor.java | 106 ----------- .../lineageos/settings/doze/TiltSensor.java | 94 ---------- .../org/lineageos/settings/doze/Utils.java | 116 ------------ 19 files changed, 1036 deletions(-) delete mode 100644 doze/Android.mk delete mode 100644 doze/AndroidManifest.xml delete mode 100644 doze/proguard.flags delete mode 100644 doze/res/color/switch_bar_bg.xml delete mode 100644 doze/res/color/switchbar_switch_thumb_tint.xml delete mode 100644 doze/res/color/switchbar_switch_track_tint.xml delete mode 100644 doze/res/drawable/switchbar_background.xml delete mode 100644 doze/res/layout/doze.xml delete mode 100644 doze/res/layout/switch_bar.xml delete mode 100644 doze/res/values/styles.xml delete mode 100644 doze/res/xml/doze_settings.xml delete mode 100644 doze/src/org/lineageos/settings/doze/BootCompletedReceiver.java delete mode 100644 doze/src/org/lineageos/settings/doze/DozeService.java delete mode 100644 doze/src/org/lineageos/settings/doze/DozeSettingsActivity.java delete mode 100644 doze/src/org/lineageos/settings/doze/DozeSettingsFragment.java delete mode 100644 doze/src/org/lineageos/settings/doze/ProximitySensor.java delete mode 100644 doze/src/org/lineageos/settings/doze/TiltSensor.java delete mode 100644 doze/src/org/lineageos/settings/doze/Utils.java diff --git a/device-common.mk b/device-common.mk index e6e514a..751c833 100644 --- a/device-common.mk +++ b/device-common.mk @@ -152,10 +152,6 @@ PRODUCT_PACKAGES += \ libtinyxml \ memtrack.msm8994 -# Doze mode -PRODUCT_PACKAGES += \ - SonyDoze - # Gatekeeper PRODUCT_PACKAGES += \ android.hardware.gatekeeper@1.0-impl diff --git a/doze/Android.mk b/doze/Android.mk deleted file mode 100644 index b28073b..0000000 --- a/doze/Android.mk +++ /dev/null @@ -1,43 +0,0 @@ -# -# Copyright (C) 2015-2016 The CyanogenMod Project -# (C) 2017-2018 The LineageOS Project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -LOCAL_PATH:= $(call my-dir) -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := optional - -LOCAL_SRC_FILES := $(call all-java-files-under, src) - -LOCAL_PACKAGE_NAME := SonyDoze -LOCAL_CERTIFICATE := platform -LOCAL_PRIVATE_PLATFORM_APIS := true -LOCAL_PRIVILEGED_MODULE := true - -LOCAL_USE_AAPT2 := true - -LOCAL_STATIC_ANDROID_LIBRARIES := \ - androidx.core_core \ - androidx.preference_preference - -LOCAL_RESOURCE_DIR := \ - $(LOCAL_PATH)/res \ - $(TOP)/packages/resources/devicesettings/res - -LOCAL_PROGUARD_FLAG_FILES := proguard.flags - -include $(BUILD_PACKAGE) - diff --git a/doze/AndroidManifest.xml b/doze/AndroidManifest.xml deleted file mode 100644 index ee69085..0000000 --- a/doze/AndroidManifest.xml +++ /dev/null @@ -1,59 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/doze/proguard.flags b/doze/proguard.flags deleted file mode 100644 index b1cabdb..0000000 --- a/doze/proguard.flags +++ /dev/null @@ -1,8 +0,0 @@ --keepclasseswithmembers class * { - public (android.content.Context, android.util.AttributeSet); -} - --keep class ** extends android.support.v14.preference.PreferenceFragment --keep class org.lineageos.settings.doze.* { - *; -} diff --git a/doze/res/color/switch_bar_bg.xml b/doze/res/color/switch_bar_bg.xml deleted file mode 100644 index ba2dae1..0000000 --- a/doze/res/color/switch_bar_bg.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - diff --git a/doze/res/color/switchbar_switch_thumb_tint.xml b/doze/res/color/switchbar_switch_thumb_tint.xml deleted file mode 100644 index d4bf9b3..0000000 --- a/doze/res/color/switchbar_switch_thumb_tint.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - diff --git a/doze/res/color/switchbar_switch_track_tint.xml b/doze/res/color/switchbar_switch_track_tint.xml deleted file mode 100644 index ae45c7a..0000000 --- a/doze/res/color/switchbar_switch_track_tint.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - diff --git a/doze/res/drawable/switchbar_background.xml b/doze/res/drawable/switchbar_background.xml deleted file mode 100644 index f210707..0000000 --- a/doze/res/drawable/switchbar_background.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - diff --git a/doze/res/layout/doze.xml b/doze/res/layout/doze.xml deleted file mode 100644 index 941cdf6..0000000 --- a/doze/res/layout/doze.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - diff --git a/doze/res/layout/switch_bar.xml b/doze/res/layout/switch_bar.xml deleted file mode 100644 index 9e11a0a..0000000 --- a/doze/res/layout/switch_bar.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - - - - - diff --git a/doze/res/values/styles.xml b/doze/res/values/styles.xml deleted file mode 100644 index 3443c0b..0000000 --- a/doze/res/values/styles.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/doze/res/xml/doze_settings.xml b/doze/res/xml/doze_settings.xml deleted file mode 100644 index 005c6ae..0000000 --- a/doze/res/xml/doze_settings.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/doze/src/org/lineageos/settings/doze/BootCompletedReceiver.java b/doze/src/org/lineageos/settings/doze/BootCompletedReceiver.java deleted file mode 100644 index b934501..0000000 --- a/doze/src/org/lineageos/settings/doze/BootCompletedReceiver.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2015 The CyanogenMod Project - * 2017 The LineageOS Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.lineageos.settings.doze; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.util.Log; - -public class BootCompletedReceiver extends BroadcastReceiver { - - private static final boolean DEBUG = false; - private static final String TAG = "SonyDoze"; - - @Override - public void onReceive(final Context context, Intent intent) { - if (Utils.isDozeEnabled(context) && Utils.sensorsEnabled(context)) { - if (DEBUG) Log.d(TAG, "Starting service"); - Utils.startService(context); - } - } - -} diff --git a/doze/src/org/lineageos/settings/doze/DozeService.java b/doze/src/org/lineageos/settings/doze/DozeService.java deleted file mode 100644 index 5b161e2..0000000 --- a/doze/src/org/lineageos/settings/doze/DozeService.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (C) 2015 The CyanogenMod Project - * 2017-2018 The LineageOS Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.lineageos.settings.doze; - -import android.app.Service; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.os.IBinder; -import android.util.Log; - -public class DozeService extends Service { - private static final String TAG = "DozeService"; - private static final boolean DEBUG = false; - - private ProximitySensor mProximitySensor; - private TiltSensor mTiltSensor; - - @Override - public void onCreate() { - if (DEBUG) Log.d(TAG, "Creating service"); - mProximitySensor = new ProximitySensor(this); - mTiltSensor = new TiltSensor(this); - - IntentFilter screenStateFilter = new IntentFilter(Intent.ACTION_SCREEN_ON); - screenStateFilter.addAction(Intent.ACTION_SCREEN_OFF); - registerReceiver(mScreenStateReceiver, screenStateFilter); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - if (DEBUG) Log.d(TAG, "Starting service"); - return START_STICKY; - } - - @Override - public void onDestroy() { - if (DEBUG) Log.d(TAG, "Destroying service"); - super.onDestroy(); - this.unregisterReceiver(mScreenStateReceiver); - mProximitySensor.disable(); - mTiltSensor.disable(); - } - - @Override - public IBinder onBind(Intent intent) { - return null; - } - - private void onDisplayOn() { - if (DEBUG) Log.d(TAG, "Display on"); - if (Utils.isPickUpEnabled(this)) { - mTiltSensor.disable(); - } - if (Utils.isHandwaveGestureEnabled(this) || - Utils.isPocketGestureEnabled(this)) { - mProximitySensor.disable(); - } - } - - private void onDisplayOff() { - if (DEBUG) Log.d(TAG, "Display off"); - if (Utils.isPickUpEnabled(this)) { - mTiltSensor.enable(); - } - if (Utils.isHandwaveGestureEnabled(this) || - Utils.isPocketGestureEnabled(this)) { - mProximitySensor.enable(); - } - } - - private BroadcastReceiver mScreenStateReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) { - onDisplayOn(); - } else if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) { - onDisplayOff(); - } - } - }; -} diff --git a/doze/src/org/lineageos/settings/doze/DozeSettingsActivity.java b/doze/src/org/lineageos/settings/doze/DozeSettingsActivity.java deleted file mode 100644 index 1591b2c..0000000 --- a/doze/src/org/lineageos/settings/doze/DozeSettingsActivity.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2015-2016 The CyanogenMod Project - * 2017 The LineageOS Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.lineageos.settings.doze; - -import android.os.Bundle; -import android.preference.PreferenceActivity; - -public class DozeSettingsActivity extends PreferenceActivity { - - private static final String TAG_DOZE = "doze"; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - getFragmentManager().beginTransaction().replace(android.R.id.content, - new DozeSettingsFragment(), TAG_DOZE).commit(); - } -} diff --git a/doze/src/org/lineageos/settings/doze/DozeSettingsFragment.java b/doze/src/org/lineageos/settings/doze/DozeSettingsFragment.java deleted file mode 100644 index 2e67d5d..0000000 --- a/doze/src/org/lineageos/settings/doze/DozeSettingsFragment.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (C) 2015 The CyanogenMod Project - * 2017-2018 The LineageOS Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.lineageos.settings.doze; - -import android.app.ActionBar; -import android.app.Activity; -import android.app.AlertDialog; -import android.app.Dialog; -import android.app.DialogFragment; -import android.content.Context; -import android.content.DialogInterface; -import android.content.SharedPreferences; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.MenuItem; -import android.view.View; -import android.view.ViewGroup; -import android.widget.CompoundButton; -import android.widget.Switch; -import android.widget.TextView; -import androidx.preference.Preference; -import androidx.preference.PreferenceCategory; -import androidx.preference.Preference.OnPreferenceChangeListener; -import androidx.preference.PreferenceFragment; -import androidx.preference.SwitchPreference; - -public class DozeSettingsFragment extends PreferenceFragment implements OnPreferenceChangeListener, - CompoundButton.OnCheckedChangeListener { - - private TextView mTextView; - private View mSwitchBar; - - private SwitchPreference mPickUpPreference; - private SwitchPreference mHandwavePreference; - private SwitchPreference mPocketPreference; - - @Override - public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { - addPreferencesFromResource(R.xml.doze_settings); - final ActionBar actionBar = getActivity().getActionBar(); - actionBar.setDisplayHomeAsUpEnabled(true); - - SharedPreferences prefs = getActivity().getSharedPreferences("doze_settings", - Activity.MODE_PRIVATE); - if (savedInstanceState == null && !prefs.getBoolean("first_help_shown", false)) { - showHelp(); - } - - boolean dozeEnabled = Utils.isDozeEnabled(getActivity()); - - PreferenceCategory proximitySensorCategory = - (PreferenceCategory) getPreferenceScreen().findPreference(Utils.CATEG_PROX_SENSOR); - - mPickUpPreference = (SwitchPreference) findPreference(Utils.GESTURE_PICK_UP_KEY); - mPickUpPreference.setEnabled(dozeEnabled); - mPickUpPreference.setOnPreferenceChangeListener(this); - - mHandwavePreference = (SwitchPreference) findPreference(Utils.GESTURE_HAND_WAVE_KEY); - mHandwavePreference.setEnabled(dozeEnabled); - mHandwavePreference.setOnPreferenceChangeListener(this); - - mPocketPreference = (SwitchPreference) findPreference(Utils.GESTURE_POCKET_KEY); - mPocketPreference.setEnabled(dozeEnabled); - mPocketPreference.setOnPreferenceChangeListener(this); - - // Hide proximity sensor related features if the device doesn't support them - if (!Utils.getProxCheckBeforePulse(getActivity())) { - getPreferenceScreen().removePreference(proximitySensorCategory); - } - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - final View view = LayoutInflater.from(getContext()).inflate(R.layout.doze, container, false); - ((ViewGroup) view).addView(super.onCreateView(inflater, container, savedInstanceState)); - return view; - } - - @Override - public void onViewCreated(View view, Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - - boolean dozeEnabled = Utils.isDozeEnabled(getActivity()); - - mTextView = view.findViewById(R.id.switch_text); - mTextView.setText(getString(dozeEnabled ? - R.string.switch_bar_on : R.string.switch_bar_off)); - - mSwitchBar = view.findViewById(R.id.switch_bar); - Switch switchWidget = mSwitchBar.findViewById(android.R.id.switch_widget); - switchWidget.setChecked(dozeEnabled); - switchWidget.setOnCheckedChangeListener(this); - mSwitchBar.setActivated(dozeEnabled); - mSwitchBar.setOnClickListener(v -> { - switchWidget.setChecked(!switchWidget.isChecked()); - mSwitchBar.setActivated(switchWidget.isChecked()); - }); - } - - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - Utils.enableGesture(getActivity(), preference.getKey(), (Boolean) newValue); - Utils.checkDozeService(getActivity()); - return true; - } - - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { - Utils.enableDoze(getActivity(), isChecked); - Utils.checkDozeService(getActivity()); - - mTextView.setText(getString(isChecked ? R.string.switch_bar_on : R.string.switch_bar_off)); - mSwitchBar.setActivated(isChecked); - - mPickUpPreference.setEnabled(isChecked); - mHandwavePreference.setEnabled(isChecked); - mPocketPreference.setEnabled(isChecked); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - if (item.getItemId() == android.R.id.home) { - getActivity().onBackPressed(); - return true; - } - return false; - } - - private static class HelpDialogFragment extends DialogFragment { - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - return new AlertDialog.Builder(getActivity()) - .setTitle(R.string.doze_settings_help_title) - .setMessage(R.string.doze_settings_help_text) - .setNegativeButton(R.string.dialog_ok, (dialog, which) -> dialog.cancel()) - .create(); - } - - @Override - public void onCancel(DialogInterface dialog) { - getActivity().getSharedPreferences("doze_settings", Activity.MODE_PRIVATE) - .edit() - .putBoolean("first_help_shown", true) - .commit(); - } - } - - private void showHelp() { - HelpDialogFragment fragment = new HelpDialogFragment(); - fragment.show(getFragmentManager(), "help_dialog"); - } -} diff --git a/doze/src/org/lineageos/settings/doze/ProximitySensor.java b/doze/src/org/lineageos/settings/doze/ProximitySensor.java deleted file mode 100644 index 71594ff..0000000 --- a/doze/src/org/lineageos/settings/doze/ProximitySensor.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2015 The CyanogenMod Project - * 2017-2018 The LineageOS Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.lineageos.settings.doze; - -import android.content.Context; -import android.hardware.Sensor; -import android.hardware.SensorEvent; -import android.hardware.SensorEventListener; -import android.hardware.SensorManager; -import android.util.Log; - -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; - -public class ProximitySensor implements SensorEventListener { - - private static final boolean DEBUG = false; - private static final String TAG = "ProximitySensor"; - - // Maximum time for the hand to cover the sensor: 1s - private static final int HANDWAVE_MAX_DELTA_NS = 1000 * 1000 * 1000; - - // Minimum time until the device is considered to have been in the pocket: 2s - private static final int POCKET_MIN_DELTA_NS = 2000 * 1000 * 1000; - - private SensorManager mSensorManager; - private Sensor mSensor; - private Context mContext; - private ExecutorService mExecutorService; - - private boolean mSawNear = false; - private long mInPocketTime = 0; - - public ProximitySensor(Context context) { - mContext = context; - mSensorManager = mContext.getSystemService(SensorManager.class); - mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY, false); - mExecutorService = Executors.newSingleThreadExecutor(); - } - - private Future submit(Runnable runnable) { - return mExecutorService.submit(runnable); - } - - @Override - public void onSensorChanged(SensorEvent event) { - boolean isNear = event.values[0] < mSensor.getMaximumRange(); - if (mSawNear && !isNear) { - if (shouldPulse(event.timestamp)) { - Utils.launchDozePulse(mContext); - } - } else { - mInPocketTime = event.timestamp; - } - mSawNear = isNear; - } - - private boolean shouldPulse(long timestamp) { - long delta = timestamp - mInPocketTime; - - if (Utils.isHandwaveGestureEnabled(mContext) && Utils.isPocketGestureEnabled(mContext)) { - return true; - } else if (Utils.isHandwaveGestureEnabled(mContext)) { - return delta < HANDWAVE_MAX_DELTA_NS; - } else if (Utils.isPocketGestureEnabled(mContext)) { - return delta >= POCKET_MIN_DELTA_NS; - } - return false; - } - - @Override - public void onAccuracyChanged(Sensor sensor, int accuracy) { - /* Empty */ - } - - protected void enable() { - if (DEBUG) Log.d(TAG, "Enabling"); - submit(() -> { - mSensorManager.registerListener(this, mSensor, - SensorManager.SENSOR_DELAY_NORMAL); - }); - } - - protected void disable() { - if (DEBUG) Log.d(TAG, "Disabling"); - submit(() -> { - mSensorManager.unregisterListener(this, mSensor); - }); - } -} diff --git a/doze/src/org/lineageos/settings/doze/TiltSensor.java b/doze/src/org/lineageos/settings/doze/TiltSensor.java deleted file mode 100644 index 6598127..0000000 --- a/doze/src/org/lineageos/settings/doze/TiltSensor.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2015 The CyanogenMod Project - * 2017-2018 The LineageOS Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.lineageos.settings.doze; - -import android.content.Context; -import android.hardware.Sensor; -import android.hardware.SensorEvent; -import android.hardware.SensorEventListener; -import android.hardware.SensorManager; -import android.os.SystemClock; -import android.util.Log; - -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; - -public class TiltSensor implements SensorEventListener { - - private static final boolean DEBUG = false; - private static final String TAG = "TiltSensor"; - - private static final int BATCH_LATENCY_IN_MS = 100; - private static final int MIN_PULSE_INTERVAL_MS = 2500; - - private SensorManager mSensorManager; - private Sensor mSensor; - private Context mContext; - private ExecutorService mExecutorService; - - private long mEntryTimestamp; - - public TiltSensor(Context context) { - mContext = context; - mSensorManager = mContext.getSystemService(SensorManager.class); - mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_TILT_DETECTOR); - mExecutorService = Executors.newSingleThreadExecutor(); - } - - private Future submit(Runnable runnable) { - return mExecutorService.submit(runnable); - } - - @Override - public void onSensorChanged(SensorEvent event) { - if (DEBUG) Log.d(TAG, "Got sensor event: " + event.values[0]); - - long delta = SystemClock.elapsedRealtime() - mEntryTimestamp; - if (delta < MIN_PULSE_INTERVAL_MS) { - return; - } else { - mEntryTimestamp = SystemClock.elapsedRealtime(); - } - - if (event.values[0] == 1) { - Utils.launchDozePulse(mContext); - } - } - - @Override - public void onAccuracyChanged(Sensor sensor, int accuracy) { - /* Empty */ - } - - protected void enable() { - if (DEBUG) Log.d(TAG, "Enabling"); - submit(() -> { - mSensorManager.registerListener(this, mSensor, - SensorManager.SENSOR_DELAY_NORMAL, BATCH_LATENCY_IN_MS * 1000); - mEntryTimestamp = SystemClock.elapsedRealtime(); - }); - } - - protected void disable() { - if (DEBUG) Log.d(TAG, "Disabling"); - submit(() -> { - mSensorManager.unregisterListener(this, mSensor); - }); - } -} diff --git a/doze/src/org/lineageos/settings/doze/Utils.java b/doze/src/org/lineageos/settings/doze/Utils.java deleted file mode 100644 index 7aa6884..0000000 --- a/doze/src/org/lineageos/settings/doze/Utils.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (C) 2015 The CyanogenMod Project - * 2017-2018 The LineageOS Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.lineageos.settings.doze; - -import android.content.Context; -import android.content.Intent; -import android.content.pm.PackageManager; -import android.os.UserHandle; -import android.provider.Settings; -import android.util.Log; -import androidx.preference.PreferenceManager; - -import static android.provider.Settings.Secure.DOZE_ENABLED; - -public final class Utils { - - private static final String TAG = "DozeUtils"; - private static final boolean DEBUG = false; - - private static final String DOZE_INTENT = "com.android.systemui.doze.pulse"; - - protected static final String CATEG_PROX_SENSOR = "proximity_sensor"; - - protected static final String GESTURE_PICK_UP_KEY = "gesture_pick_up"; - protected static final String GESTURE_HAND_WAVE_KEY = "gesture_hand_wave"; - protected static final String GESTURE_POCKET_KEY = "gesture_pocket"; - - protected static void startService(Context context) { - if (DEBUG) Log.d(TAG, "Starting service"); - context.startServiceAsUser(new Intent(context, DozeService.class), - UserHandle.CURRENT); - } - - protected static void stopService(Context context) { - if (DEBUG) Log.d(TAG, "Stopping service"); - context.stopServiceAsUser(new Intent(context, DozeService.class), - UserHandle.CURRENT); - } - - protected static void checkDozeService(Context context) { - if (isDozeEnabled(context) && sensorsEnabled(context)) { - startService(context); - } else { - stopService(context); - } - } - - protected static boolean getProxCheckBeforePulse(Context context) { - try { - Context con = context.createPackageContext("com.android.systemui", 0); - int id = con.getResources().getIdentifier("doze_proximity_check_before_pulse", - "bool", "com.android.systemui"); - return con.getResources().getBoolean(id); - } catch (PackageManager.NameNotFoundException e) { - return false; - } - } - - protected static boolean isDozeEnabled(Context context) { - return Settings.Secure.getInt(context.getContentResolver(), - DOZE_ENABLED, 1) != 0; - } - - protected static boolean enableDoze(Context context, boolean enable) { - return Settings.Secure.putInt(context.getContentResolver(), - DOZE_ENABLED, enable ? 1 : 0); - } - - protected static void launchDozePulse(Context context) { - if (DEBUG) Log.d(TAG, "Launch doze pulse"); - context.sendBroadcastAsUser(new Intent(DOZE_INTENT), - new UserHandle(UserHandle.USER_CURRENT)); - } - - protected static void enableGesture(Context context, String gesture, boolean enable) { - PreferenceManager.getDefaultSharedPreferences(context).edit() - .putBoolean(gesture, enable).apply(); - } - - protected static boolean isGestureEnabled(Context context, String gesture) { - return PreferenceManager.getDefaultSharedPreferences(context) - .getBoolean(gesture, false); - } - - protected static boolean isPickUpEnabled(Context context) { - return isGestureEnabled(context, GESTURE_PICK_UP_KEY); - } - - protected static boolean isHandwaveGestureEnabled(Context context) { - return isGestureEnabled(context, GESTURE_HAND_WAVE_KEY); - } - - protected static boolean isPocketGestureEnabled(Context context) { - return isGestureEnabled(context, GESTURE_POCKET_KEY); - } - - protected static boolean sensorsEnabled(Context context) { - return isPickUpEnabled(context) || isHandwaveGestureEnabled(context) - || isPocketGestureEnabled(context); - } -}