Using TYPE_ACCESSIBILITY_OVERLAY as type
in the WindowManager.LayoutParams
when adding the view from within the accessibility service seems to do the trick. I did a quick test and the overlay window was shown even in the settings menu. The overlay window also received touch events. This worked also without the SYSTEM_ALERT_WINDOW
permission in the manifest and also without setting the "Display over other apps" permission interactively by the user. I did my testing using target SDK 29.
Sorry, I cannot answer to your third question about what specific restrictions apply.
EDIT: By looking at the old tutorial of Google here, here's a short sample:
GlobalActionBarService.java
public class GlobalActionBarService extends AccessibilityService {
FrameLayout mLayout;
@Override
protected void onServiceConnected() {
// Create an overlay and display the action bar
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
mLayout = new FrameLayout(this);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.type = WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY;
lp.format = PixelFormat.TRANSLUCENT;
lp.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
lp.width = WindowManager.LayoutParams.WRAP_CONTENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
lp.gravity = Gravity.TOP;
LayoutInflater inflater = LayoutInflater.from(this);
inflater.inflate(R.layout.action_bar, mLayout);
wm.addView(mLayout, lp);
}
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
}
@Override
public void onInterrupt() {
}
}
manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
package="com.lb.myapplication">
<application
android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true"
android:theme="@style/Theme.MyApplication" tools:ignore="AllowBackup">
<activity
android:name=".MainActivity" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".GlobalActionBarService" android:exported="false"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>
<meta-data
android:name="android.accessibilityservice" android:resource="@xml/global_action_bar_service" />
</service>
</application>
</manifest>
global_action_bar_service.xml
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:accessibilityFeedbackType="feedbackGeneric" android:accessibilityFlags="flagDefault"
android:canPerformGestures="true" android:canRetrieveWindowContent="true" />
action_bar.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="wrap_content" android:orientation="horizontal">
<Button
android:id="@+id/power" android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="@string/power" />
<Button
android:id="@+id/volume_up" android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="@string/volume" />
<Button
android:id="@+id/scroll" android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="@string/scroll" />
<Button
android:id="@+id/swipe" android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="@string/swipe" />
</LinearLayout>
How come maven dependencies can't be used?
Also I didnt downvote – EskimoWindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY
wasn't found in your search? – Kayser