From fc4c8ccc838b61e008a4a83be4b26b05dc3603d0 Mon Sep 17 00:00:00 2001
From: huangcm <null@gmail.com>
Date: Sat, 24 Aug 2024 09:06:35 +0000
Subject: [PATCH] feat(test): add factory test app

---
 android/vendor/aw/homlet/prebuild/FT618/FT618.apk                                            |    0 
 android/vendor/aw/homlet/prebuild/Android.mk                                                 |   22 ++++
 android/frameworks/base/services/core/java/com/android/server/policy/TvWindowManager.java    |  114 ++++++++++++++++++++++
 android/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java |  125 +++++++++++++++++++++++++
 android/vendor/aw/homlet/prebuild/FT618/Android.mk                                           |   30 ++++++
 android/device/softwinner/ceres-c3/ceres_c3.mk                                               |    3 
 6 files changed, 294 insertions(+), 0 deletions(-)

diff --git a/android/device/softwinner/ceres-c3/ceres_c3.mk b/android/device/softwinner/ceres-c3/ceres_c3.mk
index 55f9724..a0bf64a 100755
--- a/android/device/softwinner/ceres-c3/ceres_c3.mk
+++ b/android/device/softwinner/ceres-c3/ceres_c3.mk
@@ -159,6 +159,9 @@
 PRODUCT_PACKAGES += \
     SoundRecorder
 
+PRODUCT_PACKAGES += \
+    FT618
+
 #PRODUCT_PACKAGES += AllwinnerGmsIntegration
 
 ############################### 3G Dongle Support ###############################
diff --git a/android/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java b/android/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
index 8d37f09..03a4fa9 100644
--- a/android/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
+++ b/android/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
@@ -232,6 +232,8 @@
 import java.io.PrintWriter;
 import java.util.HashSet;
 import java.util.List;
+import android.widget.Toast;
+import android.content.ComponentName;
 
 /**
  * WindowManagerPolicy implementation for the Android phone UI.  This
@@ -248,6 +250,7 @@
     static final boolean DEBUG_SPLASH_SCREEN = false;
     static final boolean DEBUG_WAKEUP = false;
     static final boolean SHOW_SPLASH_SCREENS = true;
+    private static final int MSG_SHOW_TOAST = 88;
 
     // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
     // No longer recommended for desk docks;
@@ -386,6 +389,7 @@
     private boolean mHasFeatureWatch;
     private boolean mHasFeatureLeanback;
     private boolean mHasFeatureHdmiCec;
+    private String pwd="";
 
     // Assigned on main thread, accessed on UI thread
     volatile VrManagerInternal mVrManagerInternal;
@@ -731,6 +735,9 @@
                     break;
                 case MSG_RINGER_TOGGLE_CHORD:
                     handleRingerChordGesture();
+                    break;
+                case MSG_SHOW_TOAST:
+                    Toast.makeText(mContext, (String)msg.obj , Toast.LENGTH_SHORT).show();
                     break;
                 case MSG_MOVE_DISPLAY_TO_TOP:
                     mWindowManagerFuncs.moveDisplayToTop(msg.arg1);
@@ -1918,6 +1925,12 @@
         filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
         context.registerReceiver(mMultiuserReceiver, filter);
 
+        filter = new IntentFilter();
+        filter.addAction(Intent.ACTION_SCREEN_OFF);
+        filter.addAction(Intent.ACTION_SCREEN_ON);
+        filter.addAction(Intent.ACTION_SHUTDOWN);
+        context.registerReceiver(mScreenReceiver, filter);
+
         mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
         mLongPressVibePattern = getLongIntArray(mContext.getResources(),
                 com.android.internal.R.array.config_longPressVibePattern);
@@ -2629,6 +2642,104 @@
         if (DEBUG_INPUT) {
             Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
                     + repeatCount + " keyguardOn=" + keyguardOn + " canceled=" + canceled);
+        }
+
+        if(down) {
+            pwd += String.valueOf(keyCode);
+            if(pwd.contains("3822020")){            // home  menu 2down
+                try {
+                    Intent intent = new Intent(Intent.ACTION_MAIN);
+                    ComponentName cn = new ComponentName("com.oranth.activate","com.oranth.activate.MainActivity");
+                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+                    intent.setComponent(cn);
+                    mContext.startActivity(intent);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+                pwd = "";
+            }else if(pwd.contains("438282")){               //back home 2menu
+                try {
+                    Intent intent = new Intent(Intent.ACTION_MAIN);
+                    ComponentName cn = new ComponentName("com.oranth.setmac","com.oranth.setmac.MainActivity");
+                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+                    intent.setComponent(cn);
+                    mContext.startActivity(intent);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+                pwd = "";
+            } else if(pwd.contains("348282")){ //home+back+2menu
+                try {
+                    Intent intent = new Intent(Intent.ACTION_MAIN);
+                    ComponentName cn = new ComponentName("com.oranth.factory","com.oranth.factory.MainActivity");
+                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+                    intent.setComponent(cn);
+                    mContext.startActivity(intent);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+                pwd = "";
+            } else if(pwd.contains("1412151298")){ //758521
+                try {
+                    Intent intent = new Intent(Intent.ACTION_MAIN);
+                    ComponentName cn = new ComponentName("com.oranth.factory","com.oranth.factory.MainActivity");
+                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+                    intent.setComponent(cn);
+                    mContext.startActivity(intent);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+                pwd = "";
+            } else if(pwd.contains("1412151299")){ //758522
+                try {
+                    Intent intent = new Intent(Intent.ACTION_MAIN);
+                    ComponentName cn = new ComponentName("com.DeviceTest","com.DeviceTest.DeviceTest");
+                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+                    intent.setComponent(cn);
+                    mContext.startActivity(intent);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+                pwd = "";
+            } else if(pwd.contains("1412151297")){ //758520
+                String irConfig = SystemProperties.get("vendor.kickpi.irkey.enable","0");
+                if("1".equals(irConfig)) {
+                    SystemProperties.set("vendor.kickpi.irkey.enable","0");
+                    mHandler.removeMessages(MSG_SHOW_TOAST);
+                    mHandler.sendMessage(mHandler.obtainMessage(MSG_SHOW_TOAST, "Close IR Key"));
+                } else {
+                    SystemProperties.set("vendor.kickpi.irkey.enable","1");
+                    mHandler.removeMessages(MSG_SHOW_TOAST);
+                    mHandler.sendMessage(mHandler.obtainMessage(MSG_SHOW_TOAST, "Open IR Key"));
+                }
+                pwd = "";
+            } else if(pwd.contains("14121512910")){ // 8521  adb switch
+                String adbConfig = SystemProperties.get("persist.vendor.adb.enable","0");
+                if("1".equals(adbConfig)) {
+                    SystemProperties.set("persist.vendor.adb.enable","0");
+                    mHandler.removeMessages(MSG_SHOW_TOAST);
+                    mHandler.sendMessage(mHandler.obtainMessage(MSG_SHOW_TOAST, "Close Adb Debug"));
+                } else {
+                    SystemProperties.set("persist.vendor.adb.enable","1");
+                    mHandler.removeMessages(MSG_SHOW_TOAST);
+                    mHandler.sendMessage(mHandler.obtainMessage(MSG_SHOW_TOAST, "Open Adb Debug"));
+                    SystemProperties.set("vendor.remote.logging.upload","1");
+                }
+                pwd = "";
+            }
+
+            if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT || keyCode == KeyEvent.KEYCODE_DPAD_LEFT ||
+                            keyCode == KeyEvent.KEYCODE_DPAD_CENTER ||
+                            keyCode == KeyEvent.KEYCODE_DPAD_UP) {
+                pwd = "";
+            }
+        }
+
+        String IRKeyProp = SystemProperties.get("vendor.kickpi.irkey.enable");
+        if ("1".equals(IRKeyProp)) {
+                mHandler.removeMessages(MSG_SHOW_TOAST);
+                mHandler.sendMessage(mHandler.obtainMessage(MSG_SHOW_TOAST, "Close IR Key"));
+                return -1;
         }
 
         // If we think we might have a volume down & power key chord on the way
@@ -4415,6 +4526,20 @@
         }
     };
 
+    BroadcastReceiver mScreenReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            String action = intent.getAction();
+            if (Intent.ACTION_SCREEN_ON.equals(action)) {
+                    SystemProperties.set("vendor.power.status","1");
+            } else if (Intent.ACTION_SCREEN_OFF.equals(action)) {
+                    SystemProperties.set("vendor.power.status","0");
+            } else if (Intent.ACTION_SHUTDOWN.equals(action)) {
+                    SystemProperties.set("vendor.power.status","0");
+            }
+        }
+    };
+
     // Called on the PowerManager's Notifier thread.
     @Override
     public void startedGoingToSleep(int why) {
diff --git a/android/frameworks/base/services/core/java/com/android/server/policy/TvWindowManager.java b/android/frameworks/base/services/core/java/com/android/server/policy/TvWindowManager.java
index cf01527..c2b287e 100644
--- a/android/frameworks/base/services/core/java/com/android/server/policy/TvWindowManager.java
+++ b/android/frameworks/base/services/core/java/com/android/server/policy/TvWindowManager.java
@@ -129,6 +129,7 @@
 
 import java.io.File;
 import java.io.FileReader;
+import java.io.FileWriter;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.util.HashSet;
@@ -240,6 +241,53 @@
         }
     };
 */
+
+
+    private static final String ROOT_PROPERTY = "persist.vendor.root.enabled";
+    private static final String ADB_PROPERTY = "persist.vendor.adb.enabled";
+
+    private void switchRoot() {
+        boolean enabled = SystemProperties.getBoolean(ROOT_PROPERTY, false);
+        if (enabled) {
+            SystemProperties.set(ROOT_PROPERTY, "0");
+            mHandler.post(new Runnable() {
+                @Override
+                public void run() {
+                    Toast.makeText(mContext, "Root disabled!", Toast.LENGTH_SHORT).show();
+                }
+            });
+        } else {
+            SystemProperties.set(ROOT_PROPERTY, "1");
+            mHandler.post(new Runnable() {
+                @Override
+                public void run() {
+                    Toast.makeText(mContext, "Root enabled!", Toast.LENGTH_SHORT).show();
+                }
+            });
+        }
+    }
+
+    private void switchAdb() {
+        boolean enabled = SystemProperties.getBoolean(ADB_PROPERTY, false);
+        if (enabled) {
+            SystemProperties.set(ADB_PROPERTY, "0");
+            mHandler.post(new Runnable() {
+                @Override
+                public void run() {
+                    Toast.makeText(mContext, "ADB disabled!", Toast.LENGTH_SHORT).show();
+                }
+            });
+        } else {
+            SystemProperties.set(ADB_PROPERTY, "1");
+            mHandler.post(new Runnable() {
+                @Override
+                public void run() {
+                    Toast.makeText(mContext, "ADB enabled!", Toast.LENGTH_SHORT).show();
+                }
+            });
+        }
+    }
+
     /** {@inheritDoc} */
     @Override
     public void init(Context context, IWindowManager windowManager,
@@ -263,6 +311,7 @@
 */
     }
 
+    private String pwd = "";
     @Override
     public void onSystemUiStarted() {
         super.onSystemUiStarted();
@@ -282,6 +331,26 @@
 
         if(down && keyCode != KeyEvent.KEYCODE_POWER && keyCode != KeyEvent.KEYCODE_UNKNOWN){
             startFlicker();
+        }
+
+		if (down) {
+			pwd += String.valueOf(keyCode);
+			if (pwd.contains("1412151298")) {           // factory test(password 758521)
+                startApp("com.oranth.factory", "com.oranth.factory.MainActivity");
+				pwd = "";
+			} else if (pwd.contains("1412151299")) {    // root switch(password 758522)
+                switchRoot();
+                pwd = "";
+            } else if (pwd.contains("14121512910")) {    // adb switch(password 758523)
+                switchAdb();
+                pwd = "";
+            }
+
+			if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT || keyCode == KeyEvent.KEYCODE_DPAD_LEFT ||
+					keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_DPAD_DOWN ||
+					keyCode == KeyEvent.KEYCODE_DPAD_UP) {
+				pwd = "";
+			}
         }
 
         if (keyCode == KeyEvent.KEYCODE_MOUSE) {
@@ -433,6 +502,51 @@
         mFocusedTvWindow = newFocus;
     }
 
+    private int startApp(String propertyPkg, Bundle bundle) {
+        Intent launchIntent;
+        PackageManager packageManager = mContext.getPackageManager();
+        String packageName = SystemProperties.get(propertyPkg);
+
+        if ((packageName == null) || (packageName.length() == 0)) {
+            Log.e(TAG, "[startApp] propertyPkg: " + propertyPkg + " is empty!");
+            return -1;
+        }
+
+        launchIntent = packageManager.getLaunchIntentForPackage(packageName);
+        if (launchIntent == null) {
+            launchIntent = packageManager.getLeanbackLaunchIntentForPackage(packageName);
+            if (launchIntent == null) {
+                Log.e(TAG, "[startApp] can not get intent for package: " + packageName);
+                return -1;
+            }
+        }
+        if (bundle != null)
+            launchIntent.putExtras(bundle);
+
+        mContext.startActivity(launchIntent);
+        return 0;
+    }
+
+    private int startApp(String propertyPkg) {
+        Bundle bundle = null;
+        return startApp(propertyPkg, bundle);
+    }
+
+    private int startApp(String propertyPkg, String propertyCls, Bundle bundle) {
+
+        Intent intent = new Intent();
+        intent.setComponent(new ComponentName(propertyPkg, propertyCls));
+        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        if (bundle != null)
+            intent.putExtras(bundle);
+        mContext.startActivity(intent);
+        return 0;
+    }
+
+    private int startApp(String propertyPkg, String propertyCls) {
+        return startApp(propertyPkg, propertyCls, null);
+    }
+
     @Override
     public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
         int keyCode = event.getKeyCode();
diff --git a/android/vendor/aw/homlet/prebuild/Android.mk b/android/vendor/aw/homlet/prebuild/Android.mk
new file mode 100755
index 0000000..eacc45b
--- /dev/null
+++ b/android/vendor/aw/homlet/prebuild/Android.mk
@@ -0,0 +1,22 @@
+
+# Copyright (C) 2008 The Android Open Source Project
+# Copyright (C) 2012 Broadcom Corporation
+#
+# 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.
+#
+
+LOCAL_PATH := $(call my-dir)
+
+
+include $(call all-makefiles-under,$(LOCAL_PATH))
+
diff --git a/android/vendor/aw/homlet/prebuild/FT618/Android.mk b/android/vendor/aw/homlet/prebuild/FT618/Android.mk
new file mode 100755
index 0000000..0f9bd14
--- /dev/null
+++ b/android/vendor/aw/homlet/prebuild/FT618/Android.mk
@@ -0,0 +1,30 @@
+# Copyright (C) 2008 The Android Open Source Project
+# Copyright (C) 2012 Broadcom Corporation
+#
+# 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.
+#
+#
+
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE_CLASS := APPS
+LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
+LOCAL_CERTIFICATE := PRESIGNED
+
+LOCAL_MODULE := FT618
+
+LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
+
+include $(BUILD_PREBUILT)
+
diff --git a/android/vendor/aw/homlet/prebuild/FT618/FT618.apk b/android/vendor/aw/homlet/prebuild/FT618/FT618.apk
new file mode 100755
index 0000000..4e17b0f
--- /dev/null
+++ b/android/vendor/aw/homlet/prebuild/FT618/FT618.apk
Binary files differ

--
Gitblit v1.6.2