diff --git a/device.mk b/device.mk index 0df809c..90f93a6 100644 --- a/device.mk +++ b/device.mk @@ -151,6 +151,10 @@ PRODUCT_PACKAGES += \ PRODUCT_PACKAGES += \ android.hardware.drm@1.4.vendor +# DT2W +PRODUCT_PACKAGES += \ + DT2W-Service-MT6789 + # Dynamic partitions PRODUCT_USE_DYNAMIC_PARTITIONS := true diff --git a/dt2w/Android.bp b/dt2w/Android.bp new file mode 100644 index 0000000..14f6273 --- /dev/null +++ b/dt2w/Android.bp @@ -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", + ], +} diff --git a/dt2w/AndroidManifest.xml b/dt2w/AndroidManifest.xml new file mode 100644 index 0000000..e2fd689 --- /dev/null +++ b/dt2w/AndroidManifest.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + diff --git a/dt2w/privapp-permissions_co.potatoproject.dt2w.MT6789.xml b/dt2w/privapp-permissions_co.potatoproject.dt2w.MT6789.xml new file mode 100644 index 0000000..0d215d8 --- /dev/null +++ b/dt2w/privapp-permissions_co.potatoproject.dt2w.MT6789.xml @@ -0,0 +1,18 @@ + + + + + + + \ No newline at end of file diff --git a/dt2w/res/values-zh-rCN/strings.xml b/dt2w/res/values-zh-rCN/strings.xml new file mode 100644 index 0000000..de95df6 --- /dev/null +++ b/dt2w/res/values-zh-rCN/strings.xml @@ -0,0 +1,4 @@ + + + 双击唤醒服务 + diff --git a/dt2w/res/values/strings.xml b/dt2w/res/values/strings.xml new file mode 100644 index 0000000..a25f217 --- /dev/null +++ b/dt2w/res/values/strings.xml @@ -0,0 +1,4 @@ + + + DT2W Service + diff --git a/dt2w/src/co/potatoproject/dt2w/MT6789/DT2WServiceMT6789.java b/dt2w/src/co/potatoproject/dt2w/MT6789/DT2WServiceMT6789.java new file mode 100644 index 0000000..3a0e76d --- /dev/null +++ b/dt2w/src/co/potatoproject/dt2w/MT6789/DT2WServiceMT6789.java @@ -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(); + } + } + } +} diff --git a/dt2w/src/co/potatoproject/dt2w/MT6789/OnBootCompleteReceiver.java b/dt2w/src/co/potatoproject/dt2w/MT6789/OnBootCompleteReceiver.java new file mode 100644 index 0000000..1b892c9 --- /dev/null +++ b/dt2w/src/co/potatoproject/dt2w/MT6789/OnBootCompleteReceiver.java @@ -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); + } +}