aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNauval Rizky <enuma.alrizky@gmail.com>2021-06-21 10:19:21 +0700
committernebrassy <nebras30@gmail.com>2022-06-12 16:30:55 +0200
commit469e58fe1491724de537c96fad93ad6cedc61350 (patch)
tree51af4f68182b14f1f116e09d3791bafcf2fe0ae4
parentaf1b8095db374368353995f0abf245cde4ce27ee (diff)
vayu: parts: Introduce haptic feedback level adjustment
Since our kernel already expose vmax_mv as adjustable level, lets add a simple UI for it. Co-authored-by: David Setiawan <fryevia@foxmail.com> Signed-off-by: Nauval Rizky <enuma.alrizky@gmail.com> Signed-off-by: David Setiawan <fryevia@foxmail.com> Change-Id: I7bd5172989ec67845a22265c49b9aafbe7595c6f
-rw-r--r--parts/AndroidManifest.xml12
-rw-r--r--parts/res/layout/haptic.xml23
-rw-r--r--parts/res/values/integers.xml19
-rw-r--r--parts/res/values/strings.xml9
-rw-r--r--parts/res/xml/haptic_settings.xml27
-rw-r--r--parts/src/org/lineageos/settings/BootCompletedReceiver.java2
-rw-r--r--parts/src/org/lineageos/settings/haptic/HapticLevelActivity.java34
-rw-r--r--parts/src/org/lineageos/settings/haptic/HapticLevelFragment.java69
-rw-r--r--parts/src/org/lineageos/settings/haptic/HapticUtils.java55
-rw-r--r--rootdir/etc/init.target.rc5
-rw-r--r--sepolicy/private/devicesettings_app.te4
-rw-r--r--sepolicy/vendor/file_contexts3
-rw-r--r--sepolicy/vendor/genfs_contexts3
-rw-r--r--sepolicy/vendor/init.te4
14 files changed, 268 insertions, 1 deletions
diff --git a/parts/AndroidManifest.xml b/parts/AndroidManifest.xml
index dd2948c..09e7f13 100644
--- a/parts/AndroidManifest.xml
+++ b/parts/AndroidManifest.xml
@@ -24,6 +24,7 @@
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
+ <uses-permission android:name="android.permission.VIBRATE" />
<protected-broadcast android:name="com.android.systemui.doze.pulse" />
@@ -105,5 +106,16 @@
android:name=".thermal.ThermalService"
android:permission="ThermalService">
</service>
+
+ <activity
+ android:name=".haptic.HapticLevelActivity"
+ android:label="@string/haptic_title"
+ android:theme="@style/Theme.Main">
+ <intent-filter>
+ <action android:name="com.android.settings.action.IA_SETTINGS" />
+ </intent-filter>
+ <meta-data android:name="com.android.settings.category"
+ android:value="com.android.settings.category.ia.sound" />
+ </activity>
</application>
</manifest>
diff --git a/parts/res/layout/haptic.xml b/parts/res/layout/haptic.xml
new file mode 100644
index 0000000..a974e53
--- /dev/null
+++ b/parts/res/layout/haptic.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+** Copyright 2014, The Android Open Source 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.
+*/
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_height="match_parent"
+ android:layout_width="match_parent"/>
diff --git a/parts/res/values/integers.xml b/parts/res/values/integers.xml
new file mode 100644
index 0000000..ca96e89
--- /dev/null
+++ b/parts/res/values/integers.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 20 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.
+-->
+
+<resources>
+ <!-- Haptic Feedback Levels -->
+ <integer name="haptic_level_default">80</integer>
+ <integer name="haptic_level_max">100</integer>
+</resources>
diff --git a/parts/res/values/strings.xml b/parts/res/values/strings.xml
index cbe7a51..57645db 100644
--- a/parts/res/values/strings.xml
+++ b/parts/res/values/strings.xml
@@ -83,5 +83,12 @@
<!-- Raise to wake strings-->
<string name="raise_to_wake_gesture_title">Raise to wake</string>
<string name="raise_to_wake_gesture_summary">Wake up the device instead of pulsing notification</string>
-
+
+
+ <!-- Haptic Level Settings -->
+ <string name="haptic_title">Haptic feedback</string>
+ <string name="haptic_level_title">Feedback strength level</string>
+ <string name="haptic_level_summary">Adjust the strength level of overall haptic feedback</string>
+ <string name="haptic_level_summary_incompatible">Your kernel did not support custom QTI Haptic Strength Level</string>
+
</resources>
diff --git a/parts/res/xml/haptic_settings.xml b/parts/res/xml/haptic_settings.xml
new file mode 100644
index 0000000..cab31ce
--- /dev/null
+++ b/parts/res/xml/haptic_settings.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 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.
+-->
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
+
+ <org.lineageos.settings.widget.SeekBarPreference
+ android:key="haptic_level_pref"
+ android:title="@string/haptic_level_title"
+ android:summary="@string/haptic_level_summary"
+ android:layout="@layout/preference_slider"
+ android:defaultValue="@integer/haptic_level_default"
+ android:max="@integer/haptic_level_max" />
+
+</PreferenceScreen>
diff --git a/parts/src/org/lineageos/settings/BootCompletedReceiver.java b/parts/src/org/lineageos/settings/BootCompletedReceiver.java
index 1abfdf0..958d706 100644
--- a/parts/src/org/lineageos/settings/BootCompletedReceiver.java
+++ b/parts/src/org/lineageos/settings/BootCompletedReceiver.java
@@ -25,6 +25,7 @@ import android.util.Log;
import org.lineageos.settings.dirac.DiracUtils;
import org.lineageos.settings.doze.DozeUtils;
+import org.lineageos.settings.haptic.HapticUtils;
import org.lineageos.settings.thermal.ThermalUtils;
public class BootCompletedReceiver extends BroadcastReceiver {
@@ -42,5 +43,6 @@ public class BootCompletedReceiver extends BroadcastReceiver {
}
DozeUtils.checkDozeService(context);
ThermalUtils.startService(context);
+ HapticUtils.restoreLevel(context);
}
}
diff --git a/parts/src/org/lineageos/settings/haptic/HapticLevelActivity.java b/parts/src/org/lineageos/settings/haptic/HapticLevelActivity.java
new file mode 100644
index 0000000..a490d00
--- /dev/null
+++ b/parts/src/org/lineageos/settings/haptic/HapticLevelActivity.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2021 chaldeaprjkt
+ *
+ * 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.haptic;
+
+import android.os.Bundle;
+import android.preference.PreferenceActivity;
+
+public class HapticLevelActivity extends PreferenceActivity {
+
+ private final String TAG_HAPTIC = "haptic_level";
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ getFragmentManager().beginTransaction().replace(android.R.id.content,
+ new HapticLevelFragment(), TAG_HAPTIC)
+ .commit();
+ }
+}
diff --git a/parts/src/org/lineageos/settings/haptic/HapticLevelFragment.java b/parts/src/org/lineageos/settings/haptic/HapticLevelFragment.java
new file mode 100644
index 0000000..e2ae9e8
--- /dev/null
+++ b/parts/src/org/lineageos/settings/haptic/HapticLevelFragment.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2021 chaldeaprjkt
+ *
+ * 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.haptic;
+
+import android.app.ActionBar;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import androidx.preference.Preference;
+import androidx.preference.Preference.OnPreferenceChangeListener;
+import androidx.preference.PreferenceFragment;
+
+import org.lineageos.settings.R;
+import org.lineageos.settings.utils.FileUtils;
+import org.lineageos.settings.widget.SeekBarPreference;
+
+public class HapticLevelFragment extends PreferenceFragment implements OnPreferenceChangeListener {
+
+ @Override
+ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
+ addPreferencesFromResource(R.xml.haptic_settings);
+
+ final ActionBar actionBar = getActivity().getActionBar();
+ actionBar.setTitle(R.string.haptic_title);
+ actionBar.setDisplayHomeAsUpEnabled(true);
+
+ final SeekBarPreference mHapticLevel = (SeekBarPreference) findPreference(HapticUtils.PREF_LEVEL);
+ if (FileUtils.fileExists(HapticUtils.PATH_LEVEL)) {
+ mHapticLevel.setEnabled(true);
+ mHapticLevel.setOnPreferenceChangeListener(this);
+ } else {
+ mHapticLevel.setSummary(R.string.haptic_level_summary_incompatible);
+ mHapticLevel.setEnabled(false);
+ }
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ final View view = LayoutInflater.from(getContext()).inflate(R.layout.haptic, container, false);
+ ((ViewGroup) view).addView(super.onCreateView(inflater, container, savedInstanceState));
+ return view;
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ if (HapticUtils.PREF_LEVEL.equals(preference.getKey())) {
+ HapticUtils.applyLevel(getContext(), (int) newValue, true);
+ }
+
+ return true;
+ }
+}
diff --git a/parts/src/org/lineageos/settings/haptic/HapticUtils.java b/parts/src/org/lineageos/settings/haptic/HapticUtils.java
new file mode 100644
index 0000000..d0c7f4d
--- /dev/null
+++ b/parts/src/org/lineageos/settings/haptic/HapticUtils.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2021 chaldeaprjkt
+ *
+ * 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.haptic;
+
+import android.content.Context;
+import android.os.VibrationEffect;
+import android.os.Vibrator;
+import android.provider.Settings;
+
+import java.lang.Math;
+
+import org.lineageos.settings.utils.FileUtils;
+
+public final class HapticUtils {
+
+ final static String PREF_LEVEL = "haptic_level_pref";
+ final static String PATH_LEVEL = "/sys/module/qti_haptics/parameters/level";
+
+ final static int MIN_LEVEL = 1;
+ final static int MAX_LEVEL = 3596;
+
+ public static void applyLevel(Context context, int value, boolean test) {
+ if (FileUtils.fileExists(PATH_LEVEL)) {
+ double level = value / 100.0 * (MAX_LEVEL - MIN_LEVEL) + MIN_LEVEL;
+ int newValue = (int) Math.round(level);
+ FileUtils.writeLine(PATH_LEVEL, String.valueOf(newValue));
+
+ if (test) {
+ Vibrator dev = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
+ if (dev.hasVibrator()) {
+ dev.vibrate(VibrationEffect.createOneShot(15, VibrationEffect.DEFAULT_AMPLITUDE));
+ }
+ }
+ }
+ }
+
+ public static void restoreLevel(Context context) {
+ applyLevel(context, Settings.Secure.getInt(
+ context.getContentResolver(), PREF_LEVEL, 80), false);
+ }
+}
diff --git a/rootdir/etc/init.target.rc b/rootdir/etc/init.target.rc
index 80e847b..52051de 100644
--- a/rootdir/etc/init.target.rc
+++ b/rootdir/etc/init.target.rc
@@ -274,3 +274,8 @@ service vendor.nfc_hal_service /vendor/bin/hw/android.hardware.nfc@1.2-service
group nfc
task_profiles ServiceCapacityLow
disabled
+
+on post-fs-data
+ # Allow system to adjust haptic level directly
+ chown system system /sys/module/qti_haptics/parameters/level
+ chmod 0664 /sys/module/qti_haptics/parameters/level
diff --git a/sepolicy/private/devicesettings_app.te b/sepolicy/private/devicesettings_app.te
index a915e9a..615020a 100644
--- a/sepolicy/private/devicesettings_app.te
+++ b/sepolicy/private/devicesettings_app.te
@@ -34,3 +34,7 @@ allow devicesettings_app {
sysfs_leds
sysfs_thermal
}:{ file lnk_file } rw_file_perms;
+
+# Allow xiaomi_settings to read and write to sysfs_vibrator
+allow devicesettings_app sysfs_vibrator:dir search;
+allow devicesettings_app sysfs_vibrator:file rw_file_perms;
diff --git a/sepolicy/vendor/file_contexts b/sepolicy/vendor/file_contexts
index 524c1b3..f97729a 100644
--- a/sepolicy/vendor/file_contexts
+++ b/sepolicy/vendor/file_contexts
@@ -49,6 +49,9 @@
# Health
/sys/devices/platform/soc/c440000.qcom,spmi/spmi-0/spmi0-02/c440000.qcom,spmi:qcom,pm8150b@2:qcom,qpnp-smb5/power_supply/wireless(/.*)? u:object_r:sysfs_wireless_supply:s0
+# Haptic
+/sys/module/qti_haptics/parameters/level u:object_r:sysfs_vibrator:s0
+
# IR
/dev/ir_spi u:object_r:lirc_device:s0
/dev/lirc[0-9] u:object_r:lirc_device:s0
diff --git a/sepolicy/vendor/genfs_contexts b/sepolicy/vendor/genfs_contexts
index d649272..adb96b3 100644
--- a/sepolicy/vendor/genfs_contexts
+++ b/sepolicy/vendor/genfs_contexts
@@ -23,6 +23,9 @@ genfscon sysfs /devices/platform/soc/soc:fingerprint_fpc/power_cfg
genfscon sysfs /devices/platform/soc/soc:fingerprint_fpc/request_vreg u:object_r:vendor_sysfs_fingerprint:s0
genfscon sysfs /devices/platform/soc/soc:fingerprint_fpc/wakeup_enable u:object_r:vendor_sysfs_fingerprint:s0
+# Haptic
+genfscon sysfs /module/qti_haptics/parameters/level u:object_r:sysfs_vibrator:s0
+
# Health
genfscon sysfs /class/power_supply/battery/capacity u:object_r:sysfs_battery_supply:s0
genfscon sysfs /devices/platform/soc/884000.i2c/i2c-3/3-0066/power_supply/bq2597x-standalone u:object_r:sysfs_battery_supply:s0
diff --git a/sepolicy/vendor/init.te b/sepolicy/vendor/init.te
index 9816992..c85f4f6 100644
--- a/sepolicy/vendor/init.te
+++ b/sepolicy/vendor/init.te
@@ -12,3 +12,7 @@ allow init adsprpcd_file:file mounton;
allow init per_boot_file:file ioctl;
allowxperm init per_boot_file:file ioctl { F2FS_IOC_SET_PIN_FILE };
+
+# Allow init to read and write to sysfs_vibrator
+allow init sysfs_vibrator:dir search;
+allow init sysfs_vibrator:file rw_file_perms;