sdm710-common: Import XiaomiParts from sdm845-common

* As of LineageOS/android_device_xiaomi_sdm845-common/commit/0125b10db7d4
* Only Doze-related stuff, other stuff will be added maybe later

Change-Id: Icdd4191f4a9cd584062f806f275a5debad118bc1
This commit is contained in:
Ivan Vecera
2022-09-13 17:08:13 +02:00
parent 40b953d2dc
commit a630a95195
15 changed files with 868 additions and 0 deletions

24
parts/Android.bp Normal file
View File

@@ -0,0 +1,24 @@
//
// Copyright (C) 2017-2022 The LineageOS Project
//
// SPDX-License-Identifier: Apache-2.0
//
android_app {
name: "XiaomiParts",
srcs: ["src/**/*.java"],
resource_dirs: ["res"],
certificate: "platform",
platform_apis: true,
privileged: true,
system_ext_specific: true,
static_libs: [
"org.lineageos.settings.resources",
],
optimize: {
proguard_flags_files: ["proguard.flags"],
},
}

61
parts/AndroidManifest.xml Normal file
View File

@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015-2016 The CyanogenMod Project
2017-2021 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.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.lineageos.settings"
android:versionCode="1"
android:versionName="1.0"
android:sharedUserId="android.uid.system">
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<protected-broadcast android:name="com.android.systemui.doze.pulse" />
<uses-sdk
android:minSdkVersion="24"
android:targetSdkVersion="24"/>
<application
android:icon="@mipmap/ic_launcher"
android:label="@string/device_settings_app_name"
android:persistent="true"
android:theme="@style/Theme.SubSettingsBase">
<receiver android:name=".BootCompletedReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<service android:name=".doze.DozeService"
android:permission="XiaomiDozeService">
</service>
<activity
android:name=".doze.DozeSettingsActivity"
android:label="@string/ambient_display_title">
<intent-filter>
<action android:name="org.lineageos.settings.device.DOZE_SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>

3
parts/proguard.flags Normal file
View File

@@ -0,0 +1,3 @@
-keep class org.lineageos.settings.doze.* {
*;
}

View File

@@ -0,0 +1,9 @@
<!-- drawable/hand.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?android:attr/colorControlNormal" >
<path android:fillColor="#000" android:pathData="M6.58,19H14.58V22H6.58V19M19.74,11.6C19.55,11.4 19.29,11.28 19,11.28L18.78,11.31L15.58,13V11.83L16.09,2.9C16.12,2.35 15.7,1.87 15.15,1.84C14.6,1.81 14.12,2.23 14.09,2.78L13.82,7.47H13.58L12.54,7.58V2A1,1 0 0,0 11.54,1C11,1 10.54,1.45 10.54,2V8.41L9.72,8.78L9.03,3.32C8.96,2.77 8.46,2.38 7.91,2.45C7.36,2.5 6.97,3 7.04,3.57L7.81,9.63L7.43,9.8C7.3,9.85 7.18,9.93 7.07,10L5.97,6.11C5.81,5.54 5.25,5.2 4.71,5.34C4.18,5.5 3.88,6.08 4.04,6.65L6.61,15.77C6.61,15.8 6.63,15.84 6.64,15.87L6.67,16H6.68C6.9,16.57 7.47,17 8.08,17H14.58C14.97,17 15.32,16.84 15.58,16.57L20.5,12.37L19.74,11.6Z" />
</vector>

View File

@@ -0,0 +1,9 @@
<!-- drawable/arrow_decision_outline.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?android:attr/colorControlNormal" >
<path android:fillColor="#000" android:pathData="M9.64,13.4C8.63,12.5 7.34,12.03 6,12V15L2,11L6,7V10C7.67,10 9.3,10.57 10.63,11.59C10.22,12.15 9.89,12.76 9.64,13.4M18,15V12C17.5,12 13.5,12.16 13.05,16.2C14.61,16.75 15.43,18.47 14.88,20.03C14.33,21.59 12.61,22.41 11.05,21.86C9.5,21.3 8.67,19.59 9.22,18.03C9.5,17.17 10.2,16.5 11.05,16.2C11.34,12.61 14.4,9.88 18,10V7L22,11L18,15M13,19A1,1 0 0,0 12,18A1,1 0 0,0 11,19A1,1 0 0,0 12,20A1,1 0 0,0 13,19M11,11.12C11.58,10.46 12.25,9.89 13,9.43V5H16L12,1L8,5H11V11.12Z" />
</vector>

View File

@@ -0,0 +1,9 @@
<!-- drawable/pocket.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?android:attr/colorControlNormal" >
<path android:fillColor="#000" android:pathData="M21.9,4.26C21.64,3.55 20.96,3.07 20.2,3.07H20.19L18.46,3.07H3.81C3.07,3.07 2.39,3.54 2.12,4.24C2.04,4.45 2,4.66 2,4.88V10.92L2.07,12.12C2.36,14.85 3.78,17.23 5.97,18.9C6,18.93 6.05,18.96 6.09,19H6.11C7.29,19.86 8.6,20.44 10,20.73C10.68,20.86 11.35,20.93 12,20.93C12.63,20.93 13.25,20.87 13.85,20.76C13.93,20.75 14,20.73 14.07,20.72C14.09,20.71 14.11,20.7 14.14,20.69C15.5,20.4 16.76,19.83 17.89,19H17.91C17.95,18.96 18,18.93 18.03,18.9C20.22,17.23 21.64,14.85 21.93,12.12L22,10.92V4.88C22,4.68 21.97,4.47 21.9,4.26M17.67,10.55L12.96,15.06C12.7,15.32 12.35,15.44 12,15.44C11.67,15.44 11.33,15.32 11.06,15.06L6.36,10.55C5.81,10.03 5.79,9.16 6.32,8.61C6.84,8.06 7.71,8.05 8.26,8.57L12,12.17L15.77,8.57C16.31,8.05 17.18,8.07 17.71,8.61C18.23,9.16 18.21,10.03 17.67,10.55Z" />
</vector>

View File

@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 The CyanogenMod Project
2018-2019,2021 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.
-->
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/ambient_display_title">
<com.android.settingslib.widget.TopIntroPreference
android:key="doze_top_intro"
android:title="@string/ambient_display_enable_summary"/>
<com.android.settingslib.widget.MainSwitchPreference
android:defaultValue="false"
android:key="doze_enable"
android:title="@string/ambient_display_enable_title" />
<SwitchPreference
android:key="always_on_display"
android:disableDependentsState="true"
android:title="@string/ambient_display_always_on_title"
android:summary="@string/ambient_display_always_on_summary"
android:persistent="false" />
<PreferenceCategory
android:key="pickup_sensor"
android:title="@string/pickup_sensor_title">
<SwitchPreference
android:key="gesture_pick_up"
android:defaultValue="false"
android:icon="@drawable/ic_pickup"
android:title="@string/pick_up_gesture_title"
android:summary="@string/pick_up_gesture_summary" />
</PreferenceCategory>
<PreferenceCategory
android:key="proximity_sensor"
android:title="@string/proximity_sensor_title">
<SwitchPreference
android:key="gesture_hand_wave"
android:defaultValue="false"
android:icon="@drawable/ic_hand"
android:title="@string/hand_wave_gesture_title"
android:summary="@string/hand_wave_gesture_summary" />
<SwitchPreference
android:key="gesture_pocket"
android:defaultValue="false"
android:icon="@drawable/ic_pocket"
android:title="@string/pocket_gesture_title"
android:summary="@string/pocket_gesture_summary" />
</PreferenceCategory>
</PreferenceScreen>

View File

@@ -0,0 +1,37 @@
/*
* Copyright (C) 2015 The CyanogenMod Project
* 2017-2020 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;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import org.lineageos.settings.doze.DozeUtils;
public class BootCompletedReceiver extends BroadcastReceiver {
private static final boolean DEBUG = false;
private static final String TAG = "XiaomiParts";
@Override
public void onReceive(final Context context, Intent intent) {
if (DEBUG) Log.d(TAG, "Received boot completed intent");
DozeUtils.checkDozeService(context);
}
}

View File

@@ -0,0 +1,99 @@
/*
* 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 PickupSensor mPickupSensor;
@Override
public void onCreate() {
if (DEBUG) Log.d(TAG, "Creating service");
mProximitySensor = new ProximitySensor(this);
mPickupSensor = new PickupSensor(this);
IntentFilter screenStateFilter = new IntentFilter();
screenStateFilter.addAction(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();
mPickupSensor.disable();
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
private void onDisplayOn() {
if (DEBUG) Log.d(TAG, "Display on");
if (DozeUtils.isPickUpEnabled(this)) {
mPickupSensor.disable();
}
if (DozeUtils.isHandwaveGestureEnabled(this) ||
DozeUtils.isPocketGestureEnabled(this)) {
mProximitySensor.disable();
}
}
private void onDisplayOff() {
if (DEBUG) Log.d(TAG, "Display off");
if (DozeUtils.isPickUpEnabled(this)) {
mPickupSensor.enable();
}
if (DozeUtils.isHandwaveGestureEnabled(this) ||
DozeUtils.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();
}
}
};
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright (C) 2015-2016 The CyanogenMod Project
* 2017,2021 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 com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseActivity;
import com.android.settingslib.collapsingtoolbar.R;
public class DozeSettingsActivity extends CollapsingToolbarBaseActivity {
private static final String TAG_DOZE = "doze";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getFragmentManager().beginTransaction().replace(R.id.content_frame,
new DozeSettingsFragment(), TAG_DOZE).commit();
}
}

View File

@@ -0,0 +1,158 @@
/*
* Copyright (C) 2015 The CyanogenMod Project
* 2017-2019,2021 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.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.os.Handler;
import android.widget.Switch;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceFragment;
import androidx.preference.SwitchPreference;
import com.android.settingslib.widget.MainSwitchPreference;
import com.android.settingslib.widget.OnMainSwitchChangeListener;
import org.lineageos.settings.R;
public class DozeSettingsFragment extends PreferenceFragment implements
Preference.OnPreferenceChangeListener, OnMainSwitchChangeListener {
private MainSwitchPreference mSwitchBar;
private SwitchPreference mAlwaysOnDisplayPreference;
private SwitchPreference mPickUpPreference;
private SwitchPreference mHandwavePreference;
private SwitchPreference mPocketPreference;
private Handler mHandler = new Handler();
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
addPreferencesFromResource(R.xml.doze_settings);
SharedPreferences prefs = getActivity().getSharedPreferences("doze_settings",
Activity.MODE_PRIVATE);
if (savedInstanceState == null && !prefs.getBoolean("first_help_shown", false)) {
showHelp();
}
boolean dozeEnabled = DozeUtils.isDozeEnabled(getActivity());
mSwitchBar = (MainSwitchPreference) findPreference(DozeUtils.DOZE_ENABLE);
mSwitchBar.addOnSwitchChangeListener(this);
mSwitchBar.setChecked(dozeEnabled);
mAlwaysOnDisplayPreference = (SwitchPreference) findPreference(DozeUtils.ALWAYS_ON_DISPLAY);
mAlwaysOnDisplayPreference.setEnabled(dozeEnabled);
mAlwaysOnDisplayPreference.setChecked(DozeUtils.isAlwaysOnEnabled(getActivity()));
mAlwaysOnDisplayPreference.setOnPreferenceChangeListener(this);
PreferenceCategory pickupSensorCategory = (PreferenceCategory) getPreferenceScreen().
findPreference(DozeUtils.CATEG_PICKUP_SENSOR);
PreferenceCategory proximitySensorCategory = (PreferenceCategory) getPreferenceScreen().
findPreference(DozeUtils.CATEG_PROX_SENSOR);
mPickUpPreference = (SwitchPreference) findPreference(DozeUtils.GESTURE_PICK_UP_KEY);
mPickUpPreference.setEnabled(dozeEnabled);
mPickUpPreference.setOnPreferenceChangeListener(this);
mHandwavePreference = (SwitchPreference) findPreference(DozeUtils.GESTURE_HAND_WAVE_KEY);
mHandwavePreference.setEnabled(dozeEnabled);
mHandwavePreference.setOnPreferenceChangeListener(this);
mPocketPreference = (SwitchPreference) findPreference(DozeUtils.GESTURE_POCKET_KEY);
mPocketPreference.setEnabled(dozeEnabled);
mPocketPreference.setOnPreferenceChangeListener(this);
// Hide proximity sensor related features if the device doesn't support them
if (!DozeUtils.getProxCheckBeforePulse(getActivity())) {
getPreferenceScreen().removePreference(proximitySensorCategory);
}
// Hide AOD if not supported and set all its dependents otherwise
if (!DozeUtils.alwaysOnDisplayAvailable(getActivity())) {
getPreferenceScreen().removePreference(mAlwaysOnDisplayPreference);
} else {
pickupSensorCategory.setDependency(DozeUtils.ALWAYS_ON_DISPLAY);
proximitySensorCategory.setDependency(DozeUtils.ALWAYS_ON_DISPLAY);
}
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (DozeUtils.ALWAYS_ON_DISPLAY.equals(preference.getKey())) {
DozeUtils.enableAlwaysOn(getActivity(), (Boolean) newValue);
}
mHandler.post(() -> DozeUtils.checkDozeService(getActivity()));
return true;
}
@Override
public void onSwitchChanged(Switch switchView, boolean isChecked) {
DozeUtils.enableDoze(getActivity(), isChecked);
DozeUtils.checkDozeService(getActivity());
mSwitchBar.setChecked(isChecked);
if (!isChecked) {
DozeUtils.enableAlwaysOn(getActivity(), false);
mAlwaysOnDisplayPreference.setChecked(false);
}
mAlwaysOnDisplayPreference.setEnabled(isChecked);
mPickUpPreference.setEnabled(isChecked);
mHandwavePreference.setEnabled(isChecked);
mPocketPreference.setEnabled(isChecked);
}
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");
}
}

View File

@@ -0,0 +1,148 @@
/*
* Copyright (C) 2015 The CyanogenMod Project
* 2017-2019,2021 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.hardware.display.AmbientDisplayConfiguration;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.UserHandle;
import android.provider.Settings;
import android.util.Log;
import androidx.preference.PreferenceManager;
import static android.provider.Settings.Secure.DOZE_ALWAYS_ON;
import static android.provider.Settings.Secure.DOZE_ENABLED;
public final class DozeUtils {
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 DOZE_ENABLE = "doze_enable";
protected static final String ALWAYS_ON_DISPLAY = "always_on_display";
protected static final String CATEG_PICKUP_SENSOR = "pickup_sensor";
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";
public 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);
}
public static void checkDozeService(Context context) {
if (isDozeEnabled(context) && !isAlwaysOnEnabled(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 enableDoze(Context context, boolean enable) {
return Settings.Secure.putInt(context.getContentResolver(),
DOZE_ENABLED, enable ? 1 : 0);
}
public static boolean isDozeEnabled(Context context) {
return Settings.Secure.getInt(context.getContentResolver(),
DOZE_ENABLED, 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 boolean enableAlwaysOn(Context context, boolean enable) {
return Settings.Secure.putIntForUser(context.getContentResolver(),
DOZE_ALWAYS_ON, enable ? 1 : 0, UserHandle.USER_CURRENT);
}
protected static boolean isAlwaysOnEnabled(Context context) {
final boolean enabledByDefault = context.getResources()
.getBoolean(com.android.internal.R.bool.config_dozeAlwaysOnEnabled);
return Settings.Secure.getIntForUser(context.getContentResolver(),
DOZE_ALWAYS_ON, alwaysOnDisplayAvailable(context) && enabledByDefault ? 1 : 0,
UserHandle.USER_CURRENT) != 0;
}
protected static boolean alwaysOnDisplayAvailable(Context context) {
return new AmbientDisplayConfiguration(context).alwaysOnAvailable();
}
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);
}
public static boolean sensorsEnabled(Context context) {
return isPickUpEnabled(context) || isHandwaveGestureEnabled(context)
|| isPocketGestureEnabled(context);
}
protected static Sensor getSensor(SensorManager sm, String type) {
for (Sensor sensor : sm.getSensorList(Sensor.TYPE_ALL)) {
if (type.equals(sensor.getStringType())) {
return sensor;
}
}
return null;
}
}

View File

@@ -0,0 +1,93 @@
/*
* 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 PickupSensor implements SensorEventListener {
private static final boolean DEBUG = false;
private static final String TAG = "PickupSensor";
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 PickupSensor(Context context) {
mContext = context;
mSensorManager = mContext.getSystemService(SensorManager.class);
mSensor = DozeUtils.getSensor(mSensorManager, "xiaomi.sensor.pickup");
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;
}
mEntryTimestamp = SystemClock.elapsedRealtime();
if (event.values[0] == 1) {
DozeUtils.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);
mEntryTimestamp = SystemClock.elapsedRealtime();
});
}
protected void disable() {
if (DEBUG) Log.d(TAG, "Disabling");
submit(() -> {
mSensorManager.unregisterListener(this, mSensor);
});
}
}

View File

@@ -0,0 +1,107 @@
/*
* 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)) {
DozeUtils.launchDozePulse(mContext);
}
} else {
mInPocketTime = event.timestamp;
}
mSawNear = isNear;
}
private boolean shouldPulse(long timestamp) {
long delta = timestamp - mInPocketTime;
if (DozeUtils.isHandwaveGestureEnabled(mContext) &&
DozeUtils.isPocketGestureEnabled(mContext)) {
return true;
} else if (DozeUtils.isHandwaveGestureEnabled(mContext)) {
return delta < HANDWAVE_MAX_DELTA_NS;
} else if (DozeUtils.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);
});
}
}

View File

@@ -120,6 +120,10 @@ PRODUCT_PACKAGES += \
PRODUCT_COPY_FILES += \
$(LOCAL_PATH)/configs/component-overrides.xml:$(TARGET_COPY_OUT_VENDOR)/etc/sysconfig/component-overrides.xml
# Device-specific settings
PRODUCT_PACKAGES += \
XiaomiParts
# Display
PRODUCT_PACKAGES += \
android.hardware.graphics.mapper@2.0-impl-qti-display \