sm6375-common: Add DT2W Services

DT2W Services feature are finished now
This commit is contained in:
Andy | アンディ
2023-09-06 13:29:44 +08:00
parent 607a67ad90
commit f3a447da69
10 changed files with 181 additions and 3 deletions

View File

@@ -164,9 +164,6 @@ BOARD_VENDOR := xiaomi
BOARD_USES_QCOM_HARDWARE := true
TARGET_BOARD_PLATFORM := holi
# Power
TARGET_POWERHAL_MODE_EXT := $(COMMON_PATH)/power/power-mode.cpp
# Properties
TARGET_ODM_PROP += $(COMMON_PATH)/properties/odm.prop
TARGET_PRODUCT_PROP += $(COMMON_PATH)/properties/product.prop

41
dt2w/Android.bp Normal file
View File

@@ -0,0 +1,41 @@
/*
* Copyright (C) 2020 The Potato Open Sauce 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.
*/
android_app {
name: "DT2WServiceSM6375",
srcs: ["src/**/*.java"],
resource_dirs: ["res"],
certificate: "platform",
platform_apis: true,
privileged: true,
optimize: {
enabled: false,
},
required: [
"privapp-permissions_org.lineageos.dt2w.sm6375"
]
}
prebuilt_etc {
name: "privapp-permissions_org.lineageos.dt2w.sm6375",
sub_dir: "permissions",
src: "privapp-permissions_org.lineageos.dt2w.sm6375.xml",
filename_from_src: true,
}

23
dt2w/AndroidManifest.xml Normal file
View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.lineageos.dt2w.sm6375"
android:versionCode="1"
android:versionName="1.0"
android:sharedUserId="android.uid.system">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />
<application android:label="@string/app_name">
<receiver android:name=".OnBootCompleteReceiver" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:enabled="true" android:name=".DT2WServiceSM6375" />
</application>
</manifest>

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 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.
-->
<permissions>
<privapp-permissions package="org.lineageos.dt2w.sm6375">
<permission name="android.permission.WRITE_SECURE_SETTINGS"/>
</privapp-permissions>
</permissions>

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">DT2W Service for SM6375</string>
</resources>

View File

@@ -0,0 +1,66 @@
package org.lineageos.dt2w.sm6375;
import android.app.Service;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.provider.Settings.Secure;
public class DT2WServiceSM6375 extends Service {
private static final String TAG = "DT2WServiceSM6375";
private Context mContext;
private Handler mHandler;
private CustomSettingsObserver mCustomSettingsObserver;
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onDestroy() {
super.onDestroy();
}
@Override
public int onStartCommand(Intent intent, int flags, int startid) {
mContext = this;
mHandler = new Handler(Looper.getMainLooper());
mCustomSettingsObserver = new CustomSettingsObserver(mHandler);
mCustomSettingsObserver.observe();
mCustomSettingsObserver.update();
return START_STICKY;
}
private class CustomSettingsObserver extends ContentObserver {
CustomSettingsObserver(Handler handler) {
super(handler);
}
void observe() {
ContentResolver resolver = mContext.getContentResolver();
resolver.registerContentObserver(Secure.getUriFor(Secure.DOUBLE_TAP_TO_WAKE),
false, this, UserHandle.USER_CURRENT);
}
void update() {
int dt2wValue = Secure.getInt(mContext.getContentResolver(), Secure.DOUBLE_TAP_TO_WAKE, 0);
boolean dt2wEnabled = dt2wValue == 1;
SystemProperties.set("persist.sys.sm6375.dt2w", dt2wEnabled ? "1" : "0");
}
@Override
public void onChange(boolean selfChange, Uri uri) {
if (uri.equals(Secure.getUriFor(Secure.DOUBLE_TAP_TO_WAKE))) {
update();
}
}
}
}

View File

@@ -0,0 +1,14 @@
package org.lineageos.dt2w.sm6375;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.UserHandle;
public class OnBootCompleteReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
Intent sIntent = new Intent(context, DT2WServiceSM6375.class);
context.startServiceAsUser(sIntent, UserHandle.CURRENT);
}
}

View File

@@ -144,6 +144,10 @@ PRODUCT_PACKAGES += \
PRODUCT_PACKAGES += \
libdrm.vendor
# DT2W Services
PRODUCT_PACKAGES += \
DT2WServiceSM6375
# Fastbootd
PRODUCT_PACKAGES += \
android.hardware.fastboot@1.1-impl-mock \

View File

@@ -280,3 +280,9 @@ on property:persist.sys.mcc.mnc=*
on property:sys.boot_completed=1
start vendor.goodix-events
on property:persist.sys.sm6375.dt2w=0
exec /system/bin/sendevent /dev/input/event4 0 1 4
on property:persist.sys.sm6375.dt2w=1
exec /system/bin/sendevent /dev/input/event4 0 1 5

View File

@@ -1 +1,3 @@
allow toolbox toolbox:capability { sys_admin kill };
allow toolbox input_device:dir { search };
allow toolbox input_device:chr_file rw_file_perms;