OSDN Git Service

DO NOT MERGE Backporting potential usb tapjacking precaution.
authorBeverly <beverlyt@google.com>
Wed, 6 Sep 2017 14:23:29 +0000 (10:23 -0400)
committerNikoli Cartagena <dargeren@google.com>
Tue, 14 Nov 2017 01:29:51 +0000 (17:29 -0800)
Bug: 62187985
Test: manual, backport
Change-Id: I6a4997ef71340d01b352e07ff035c28e19d36c34
(cherry picked from commit c8752a515963b1c8b67a553e2cb666f367743f32)

packages/SystemUI/res/values/strings.xml
packages/SystemUI/src/com/android/systemui/usb/UsbDebuggingActivity.java

index 4a51329..1ba90c3 100644 (file)
     <!-- Text body for dialog alerting user that their phone has reached a certain temperature and may start to slow down in order to cool down. [CHAR LIMIT=300] -->
     <string name="high_temp_dialog_message">Your phone will automatically try to cool down. You can still use your phone, but it may run slower.\n\nOnce your phone has cooled down, it will run normally.</string>
 
+    <!-- Warning shown when user input has been blocked due to another app overlaying screen
+         content. Since we don't know what the app is showing on top of the input target, we
+         can't verify user consent. [CHAR LIMIT=NONE] -->
+    <string name="touch_filtered_warning">Because an app is obscuring a permission request, Settings
+        can’t verify your response.</string>
 </resources>
index f5447a2..6b71179 100644 (file)
@@ -31,12 +31,15 @@ import android.os.ServiceManager;
 import android.os.SystemProperties;
 import android.util.Log;
 import android.view.LayoutInflater;
+import android.view.MotionEvent;
 import android.view.View;
+import android.view.Window;
+import android.view.WindowManager;
 import android.widget.CheckBox;
-
 import com.android.internal.app.AlertActivity;
 import com.android.internal.app.AlertController;
 import com.android.systemui.R;
+import android.widget.Toast;
 
 public class UsbDebuggingActivity extends AlertActivity
                                   implements DialogInterface.OnClickListener {
@@ -48,6 +51,10 @@ public class UsbDebuggingActivity extends AlertActivity
 
     @Override
     public void onCreate(Bundle icicle) {
+        Window window = getWindow();
+        window.addPrivateFlags(WindowManager.LayoutParams.PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
+        window.setType(WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG);
+
         super.onCreate(icicle);
 
         if (SystemProperties.getInt("service.adb.tcp.port", 0) == 0) {
@@ -79,6 +86,26 @@ public class UsbDebuggingActivity extends AlertActivity
         ap.mView = checkbox;
 
         setupAlert();
+
+        // adding touch listener on affirmative button - checks if window is obscured
+        // if obscured, do not let user give permissions (could be tapjacking involved)
+        final View.OnTouchListener filterTouchListener = new View.OnTouchListener() {
+
+            public boolean onTouch(View v, MotionEvent event) {
+                // Filter obscured touches by consuming them.
+                if (((event.getFlags() & MotionEvent.FLAG_WINDOW_IS_OBSCURED) != 0)
+                        || ((event.getFlags() & MotionEvent.FLAG_WINDOW_IS_PARTIALLY_OBSCURED) != 0)) {
+                    if (event.getAction() == MotionEvent.ACTION_UP) {
+                        Toast.makeText(v.getContext(),
+                                R.string.touch_filtered_warning,
+                                Toast.LENGTH_SHORT).show();
+                    }
+                    return true;
+                }
+                return false;
+            }
+        };
+        mAlert.getButton(BUTTON_POSITIVE).setOnTouchListener(filterTouchListener);
     }
 
     private class UsbDisconnectedReceiver extends BroadcastReceiver {