Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 91829883 authored by Beverly's avatar Beverly Committed by android-build-merger
Browse files

Merge "USB debug dialog won't give permission if obscured." into oc-mr1-dev

am: 30d87649

Change-Id: I0d60f409c4d2c2d5e86a9789a66d7c25e864ccf4
parents df79ca69 30d87649
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -2051,4 +2051,10 @@
    <!-- Prompt to turn off data usage [CHAR LIMIT=NONE] -->
    <string name="data_usage_disable_mobile" msgid="8656552431969276305">Turn off mobile data?</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>
+30 −0
Original line number Diff line number Diff line
@@ -31,8 +31,12 @@ 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 android.widget.Toast;

import com.android.internal.app.AlertActivity;
import com.android.internal.app.AlertController;
@@ -48,6 +52,9 @@ public class UsbDebuggingActivity extends AlertActivity

    @Override
    public void onCreate(Bundle icicle) {
        Window window = getWindow();
        window.setType(WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG);

        super.onCreate(icicle);

        if (SystemProperties.getInt("service.adb.tcp.port", 0) == 0) {
@@ -79,6 +86,29 @@ 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 = (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);

    }

    @Override
    public void onWindowAttributesChanged(WindowManager.LayoutParams params) {
        super.onWindowAttributesChanged(params);
    }

    private class UsbDisconnectedReceiver extends BroadcastReceiver {