阅读:2651回复:0

小需求:在任意界面的左上角连击5次,弹框,清除客户App数据和用户安装的版本

楼主#
更多 发布于:2022-02-15 18:23
diff --git a/base/services/core/java/com/android/server/policy/PhoneWindowManager.java b/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
index 9e13ea766..198738c92 100755
--- a/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
+++ b/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
@@ -158,6 +158,7 @@ import android.app.ActivityManagerInternal;
 import android.app.ActivityManagerInternal.SleepToken;
 import android.app.ActivityThread;
 import android.app.AppOpsManager;
+import android.app.AlertDialog;
 import android.app.IUiModeManager;
 import android.app.ProgressDialog;
 import android.app.SearchManager;
@@ -167,6 +168,7 @@ import android.content.ActivityNotFoundException;
 import android.content.BroadcastReceiver;
 import android.content.ContentResolver;
 import android.content.Context;
+import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.pm.ActivityInfo;
@@ -2294,6 +2296,11 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                     public void onMouseLeaveFromEdge() {
                         mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
                     }
+
+                                       @Override
+                    public void showResetDialog() {
+                        showResetDialog1();
+                                       }
                 });
         mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
         mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
@@ -2350,6 +2357,55 @@ public class PhoneWindowManager implements WindowManagerPolicy {
         mScreenshotHelper = new ScreenshotHelper(mContext);
     }
 弹框方式:TYPE_BOOT_PROGRESS,默认的dialog必须附属在activity上,而PhoneWindowManager中的mContext明显不是Activity类型的实例
+       private AlertDialog resetDialog;
+       private void showResetDialog1() {
+               int theme;
+               if (mContext.getPackageManager().hasSystemFeature(FEATURE_LEANBACK)) {
+                       theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
+               } else {
+                       theme = 0;
+               }
+
+        AlertDialog.Builder builder = new AlertDialog.Builder(mContext, theme);
+               String str = mContext.getString(com.android.internal.R.string.reset) + " App?";
+        builder.setMessage(str);
+        builder.setPositiveButton(com.android.internal.R.string.yes, new DialogInterface.OnClickListener() {
+            @Override
+            public void onClick(DialogInterface dialogInterface, int i) {
+                               Intent intent = new Intent("intent.action.xiao.qiao.APP_RESET");
+                mContext.sendBroadcast(intent);
+                Slog.e(TAG, "todo: reset app herer");
+            }
+        });
+
+        builder.setNegativeButton(com.android.internal.R.string.no, new DialogInterface.OnClickListener() {
+            @Override
+            public void onClick(DialogInterface dialogInterface, int i) {
+                Slog.e(TAG, "cancel here");
+                resetDialog.dismiss();
+            }
+        });
+        builder.setCancelable(false);
+        builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
+            @Override
+            public void onDismiss(DialogInterface dialogInterface) {
+                Slog.e(TAG, "onDismiss");
+                mSystemGestures.resetStatus();
+            }
+        });
+        resetDialog = builder.create();
+               resetDialog.getWindow().setType(
+                               WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
+               // resetDialog.getWindow().addFlags(
+                               // WindowManager.LayoutParams.FLAG_DIM_BEHIND
+                               // | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
+               // resetDialog.getWindow().setDimAmount(1);
+               // WindowManager.LayoutParams lp = resetDialog.getWindow().getAttributes();
+               // lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
+               // resetDialog.getWindow().setAttributes(lp);
+               resetDialog.show();
+    }
+
     /**
      * Read values from config.xml that may be overridden depending on
      * the configuration of the device.
diff --git a/base/services/core/java/com/android/server/policy/SystemGesturesPointerEventListener.java b/base/services/core/java/com/android/server/policy/SystemGesturesPointerEventListener.java
old mode 100644
new mode 100755
index d3cc8effb..212622bb3
--- a/base/services/core/java/com/android/server/policy/SystemGesturesPointerEventListener.java
+++ b/base/services/core/java/com/android/server/policy/SystemGesturesPointerEventListener.java
@@ -65,6 +65,10 @@ public class SystemGesturesPointerEventListener implements PointerEventListener
     private boolean mMouseHoveringAtEdge;
     private long mLastFlingTime;
 
+    private float[] hitBoxTicks = {0, 0, 0, 0, 0};
+    private int currentClickIndex = 0;
+
+
     public SystemGesturesPointerEventListener(Context context, Callbacks callbacks) {
         mContext = context;
         mCallbacks = checkNull("callbacks", callbacks);
@@ -241,6 +245,21 @@ public class SystemGesturesPointerEventListener implements PointerEventListener
         return SWIPE_NONE;
     }
 
+       private boolean isResetDialogShowing = false;
+
+       public void resetStatus() {
+               isResetDialogShowing = false;
+               hitBoxTicks = new float[]{0, 0, 0, 0, 0};
+       }
+
+       private boolean isEventTargetBox(MotionEvent e) {
+        float x = e.getX();
+        float y = e.getY();
+        Slog.e(TAG, "isEventTargetBox, x: " + x + ", y: " + y);
+        return (x > 0 && x < 100 && y > 0 && y < 100 );//点击区域 100x100
+
+    }
+
     private final class FlingGestureDetector extends GestureDetector.SimpleOnGestureListener {
         @Override
         public boolean onSingleTapUp(MotionEvent e) {
@@ -268,6 +287,24 @@ public class SystemGesturesPointerEventListener implements PointerEventListener
             mCallbacks.onFling(duration);
             return true;
         }
+
+        @Override
+        public boolean onDown(MotionEvent e) {
在此监听点击事件,用数组hitBoxTicks记录点击的时间,并与前第5次点击时间比较
+            if (isEventTargetBox(e)) {
+                hitBoxTicks[currentClickIndex] = System.currentTimeMillis();
+                currentClickIndex ++;
+                if (currentClickIndex == 5) currentClickIndex = 0;
+                Slog.e(TAG, "currentClickIndex: " + currentClickIndex);
+                               Slog.e(TAG, "1: " + hitBoxTicks[(currentClickIndex + 4) %5] + ", 2: " + hitBoxTicks[currentClickIndex]);
+                if (hitBoxTicks[(currentClickIndex + 4) %5] - hitBoxTicks[currentClickIndex] < 10000 && !isResetDialogShowing) {
+                                       isResetDialogShowing = true;
+                    mCallbacks.showResetDialog();
+                }
+                return true;
+            } else {
+                return super.onDown(e);
+            }
+        }
     }
 
     interface Callbacks {
@@ -282,5 +319,6 @@ public class SystemGesturesPointerEventListener implements PointerEventListener
         void onMouseHoverAtBottom();
         void onMouseLeaveFromEdge();
         void onDebug();
+               void showResetDialog();
     }
 }


在一个service里加广播intent.action.xiao.qiao.APP_RESET的处理,对系统app来说,直接uninstall app就可以了。

+       private void uninstallXQApp(String packageName, Context context) {
+               Log.e(TAG, "uninstallXQApp");
+        Intent intent = new Intent(context, OpenApiReceiver.class);
+        PendingIntent sender = PendingIntent.getActivity(context, 0, intent, 0);
+        PackageInstaller packageInstaller = getPackageManager().getPackageInstaller();
+        packageInstaller.uninstall(packageName, sender.getIntentSender());
+    }

最新喜欢:

PazivalPaziva... zhaoyf13zhaoyf... VastStarGamesVastSt...
游客

返回顶部