LG8n: Import DT2w service from HOAMSI's rom

Signed-off-by: Shirayuki39 <lorddemecrius83@proton.me>
This commit is contained in:
Shirayuki39 2024-08-13 22:48:39 +08:00
parent 70cd3788d3
commit 64ff4cb6e8
8 changed files with 183 additions and 0 deletions

View file

@ -151,6 +151,10 @@ PRODUCT_PACKAGES += \
PRODUCT_PACKAGES += \ PRODUCT_PACKAGES += \
android.hardware.drm@1.4.vendor android.hardware.drm@1.4.vendor
# DT2W
PRODUCT_PACKAGES += \
DT2W-Service-MT6789
# Dynamic partitions # Dynamic partitions
PRODUCT_USE_DYNAMIC_PARTITIONS := true PRODUCT_USE_DYNAMIC_PARTITIONS := true

50
dt2w/Android.bp Normal file
View file

@ -0,0 +1,50 @@
/*
* 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: "DT2W-Service-MT6789",
srcs: ["src/**/*.java"],
resource_dirs: ["res"],
certificate: "platform",
platform_apis: true,
privileged: true,
optimize: {
enabled: false,
},
required: [
"privapp-permissions_co.potatoproject.dt2w.MT6789",
"xiaomi-touch"
]
}
prebuilt_etc {
name: "privapp-permissions_co.potatoproject.dt2w.MT6789",
sub_dir: "permissions",
src: "privapp-permissions_co.potatoproject.dt2w.MT6789.xml",
filename_from_src: true,
}
cc_binary {
name: "xiaomi-touch",
srcs: [
"xiaomi-touch.cpp",
],
}

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="co.potatoproject.dt2w.MT6789"
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=".DT2WServiceMT6789" />
</application>
</manifest>

View file

@ -0,0 +1,18 @@
<?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="co.potatoproject.dt2w.MT6789">
<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">双击唤醒服务</string>
</resources>

View file

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

View file

@ -0,0 +1,66 @@
package co.potatoproject.dt2w.MT6789;
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 DT2WServiceMT6789 extends Service {
private static final String TAG = "DT2WServiceMT6789";
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.MT6789.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 co.potatoproject.dt2w.MT6789;
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, DT2WServiceMT6789.class);
context.startServiceAsUser(sIntent, UserHandle.CURRENT);
}
}