Note: This was originally posted on Android Enthusiasts Stack Exchange but is now moved here because it was found to be off-topic there
Kaspersky Safe Kids, a parental control app, has a feature where it would pop up every time it detects an event that the child was not meant to do (open an app, open anything related to its settings, search something banned on Google and Youtube -- interestingly enough, it doesn't work on other Chromium-based browsers). I've been trying to figure out how it can detect events for my own app, but the usual culprits like the permissions GET_TASKS and READ_LOGS are depreciated (I'm trying to target, and Kaspersky works on, Android 10+). For the actual overlay, I thought it used SYSTEM_ALERT_WINDOW, but in my own experiments in an emulator, when I revoked that permission, it was still able to pop up. So, how does it work, and what permissions do they (and I'm guessing other similar control and productivity apps) work?
The app is Device Admin, so that may play a role, but looking at the permissions a Device Admin has, none of them look like the permissions Kaspersky has.
EDIT: In the comments, Mike M. noted that the app uses Accessibility Services (don't know how I missed that), which makes sense as Accessibility allows you to do quite a lot, including showing your own UI. Coincidentally, a review on the app itself states that the process ends at random times (not sure which process though), probably because it was not whitelisted. I then took a look at its permissions and this one stood out: android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS. This permission allows it to be whitelisted, so that power saving modes don't kill the background processes. For the accessibility itself, android.permission.BIND_ACCESSIBILITY_SERVICE is the permission used to grant it (for the record, you must use adb shell appops set com.kaspersky.safekids android.permission.BIND_ACCESSIBILITY_SERVICE [allow|ignore|deny], not adb shell pm [grant|revoke] com.kaspersky.safekids android.permission.BIND_ACCESSIBILITY_SERVICE (though the android may have to be replaced with Manifest) as BIND_ACCESSIBILITY_SERVICE is a signature permission. For completeness, for Admin, it's android.permission.BIND_DEVICE_ADMIN.
I was able to narrow down the exact permission used -- using ADB OTG (I didn't have a computer near me, so I used my spare Pixel) I did appops set com.kaspersky.safekids BIND_ACCESSIBILITY_SERVICE ignore (I belive deny would work too). Restarted it, and no more pop up. Changed the ignore to allow, then rebooted, and it worked again.
We develop an application which requires several permissions in order to get the user’s location while in the background.
We are having problems requesting the required permissions on Huawei devices. It seems that in addition to location permission and white listing the app from battery optimizations, an additional step is required in order to disable battery optimizations and enable auto launching:
The problem is we found no way of automatically requesting permission from the user, and the only way we found is having the user manually go to these screens and change the settings.
We did find a shortcut to take us “half way”, to the application settings:
Intent intent = new
Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setData(Uri.parse("package:"+context.getPackageName()));
But multiple non intuitive actions are still required from the user.
Our aim:
We would very much like to make the process easier for the user. Optimally, to have a system dialog appear which asks the user for the permissions, instead of having him manually change the settings, much like the whitelisting of normal Android devices:
Is it possible using a Huawei specific SDK extension?
If (1) is not possible, at the very least we need a way to know if the user changes these settings or not. Currently we don’t know and cannot inform the user if the application works properly or not!
Are you expecting that your app displays a permission popup so that users can easily assign related permissions to your app?
If yes, you can integrate HMS Core Location Kit into your app. Before performing an operation requiring a permission, your app dynamically checks its permissions.
If your app does not have the required permission, it will display a popup to prompt the user to assign the permission. You can implement the popup with few code lines and users can easily assign permissions in the popup. For details, visit https://developer.huawei.com/consumer/en/doc/development/HMS-Guides/location-guidev4.
In addition to dynamic authorization, do not forget to apply for static permissions in the Manifest file.
We develop an application which requires several permissions in order to get the user’s location while in the background.
We are having problems requesting the required permissions on Xiaomi devices. It seems that in addition to location permission and white listing the app from battery optimizations, two additional steps are required, specific to Xiaomi devices:
Disabling battery saver:
Enabling auto-start:
The problem is we found no way of automatically requesting permission from the user, and the only way we found is having the user manually go to these screens and change the settings.
We did find shortcuts to take us “half way”.
Going to power settings:
Intent intent = new
Intent("miui.intent.action.POWER_HIDE_MODE_APP_LIST").addCategory(Intent.CATEGORY_DEFAULT);
Going to auto start settings:
Intent intent = new
Intent("miui.intent.action.OP_AUTO_START").addCategory(Intent.CATEGORY_DEFAULT);
But multiple non intuitive actions are still required from the user.
Our aim:
We would very much like to make the process easier for the user. Optimally, to have a system dialog appear which asks the user for the permissions, instead of having him manually change the settings, much like the whitelisting of normal Android devices:
Is it possible using a Xiaomi specific SDK extension?
If (1) is not possible, at the very least we need a way to know if the user changes these settings or not. Currently we don’t know and cannot inform the user if the application works properly or not!
I have Android Marshmallow on a Nexus 6. I am trying to fix the following problem:
If a user is trying to grant permission while a notification is showing, a "Screen overlay detected" message gets displayed and the Request Permission dialog disappears - of course the app does not get the requested permission. (Check screenshot)
I tried to fix the problem by adding "DRAW OVER OTHER APPS" permission - android.permission.SYSTEM_ALERT_WINDOW to the manifest but with no luck.
PS: I am sure the problem is caused by the notification. I do not have any app installed that overlays over other apps, I even turned off all apps with "Draw over other apps" permission in the settings. Did not help..
Anyone knows a solution to that problem?
In the circumstance that I ran across, I was causing the problem myself. It was the result of using a Toast to display information to the user at the same time that I was asking for permission. Both of these actions together cause this type of error.
The other answers might resolve someone else's issue. But I wanted to note that you should be cautious of causing your own overlays errors. Be careful of overlaying something in the view while simultaneously asking for permission.
Uninstall Clean Master app. I uninstalled it and problem solved
This problem appear because of some culprit application like Twilight, cleaner-master, drupe etc..
To solve this problem you have to disable screen overlay for those culprit apps.
i have moto g4 plus, and this is how i solve this problem
Go to Setting --> Select Apps ---> again select setting icon in Apps ---> select draw over other apps ---> and disable culprit apps who trouble for other apps.
what i done is checking each apps by disabling this permission and try to run my app, and i found one app this troubling overlay for other apps, so at the end i disabled only this app.
ScreenShots:
Got insights from multiple answers here and other forums .
Consolidating how I got rid of the issue :
Go to Settings > Apps > (your app which is getting issue)
Press on Power button till window for Power off , reboot , airplane mode comes up
Hold on Power off option
Select reboot in Safe mode
Go to settings > apps > (your app which is getting issue)
Select whichever permissions you want
After Android M update , issues can come up in apps like Messenger , Whatsapp , Prisma etc.
Let me know if any issues .
Note : I am having One plus One mobile.
This popup is caused by the manifest.PERMISSION.SYSTEM_ALERT_WINDOW permission declared by the manifest.
The are 3 categories of permissions, that developer must be aware of :
Normal permission - do nothing with them, just declare in the Manifest
Vulnerable permissions - declare in Manifest and ask for permission at first time. They can be changed through system settings.
Above dangerous permissions: SYSTEM_ALERT_WINDOW and WRITE_SETTINGS belong to this category. They must be granted, but are not visible in system settings. To request for it you don't use a standard way (int checkSelfPermission (String permission)) but you have to check Settings.canDrawOverlays() or Settings.System.canWrite() appropriately and if you not do that you will get exception like
Unable to add window android.view.ViewRootImpl$W#1de28ad -- permission denied for this window type
1-Request this permission by yourself in your code just like given below:
public class MainActivity extends AppCompatActivity {
public final static int REQUEST_CODE = 10000;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (checkDrawOverlayPermission()) {
Toast.makeText(this, "Permission granted", Toast.LENGTH_SHORT).show();
}
}
public boolean checkDrawOverlayPermission() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
return true;
}
if (!Settings.canDrawOverlays(this)) {
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, REQUEST_CODE);
return false;
} else {
return true;
}
}
#Override
#TargetApi(Build.VERSION_CODES.M)
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE) {
if (Settings.canDrawOverlays(this)) {
Toast.makeText(this, "Permission granted", Toast.LENGTH_SHORT).show();
}
}
}
I just deleted my app and turned off my Nexus 6P. After turning it back on, I reinstalled the app and no longer got the "screen overlay" dialogs when giving the app permissions.
You must disable the overlay for all the apps you see in the list. Only this way can you modify authorizations in the app you need.
I've done that in safe mode, and it worked.
At the end I rebooted the phone and now it is working fine.
I updated my Sony Xperia Z3 (Dual Sim) to Android 6.0.1 (Marsmallow). I have been having screen overlay issues. For me i do not have Clean Master, Du Speed, or Du Booster(as the solutions i have read).
So i solved mine looking for any screen overlay apps.
A screen overlap app, is an app that you can use to access other apps on your main home screen without leaving your home screen. So for me the Screen Overlay App here in my situation was the OMNI SWIPE. So if you are facing this problem you need to calm down and check which of your app fits the definition of a screen overlay app.
locate the app and uninstall then restart your phone ..
i just finished doing this and am having a good time with the phone
Best of Luck
As long as Android 6.x is buggy on some devices where this "overlay alert" is displayed without any reason (on 2 to 5% of the devices according to my analytics data), the best solution is to avoid the whole permission process by defining the targetSdk to 22.
Take care that you can't downgrade the target sdk for a new version or this will induce a INSTALL_FAILED_PERMISSION_DOWNGRADE error when the user updates requiring an unisntall/install of the app.
solution is
remove Toast messages from onRequestPermissionsResult method
This happens when you have granted overlay permission to malicious apps. Go to overlay settings and disable the overlay feature on all apps that don't belong to google and you will be good to go.
I got this problem when installing a new app.
The way I got around this problem is to manually enable the permissions for the newly installed app (before running the app).
I’m pretty sure this is a problem with Android and Samsung devices in particular.
Hope this helps
Delete the apps which have screen overlay like CM security, Clean Master, etc.
Even delete and try with Messenger (FB app) if needed.
I googled for an example source code for blocking calls and came across this EXAMPLE, But later I came to know that Google has updated their policy and
android.permission.MODIFY_PHONE_STATE
is an system level permission from android version 2.3, I have very important module placed on blocking a specific call.
How do I get a system level permission?
Please let me know if there is any way I can do this in my application. Its very important for the product and cannot be released without this functionality.
Please Help!
Thanks in advance
At least as of Android 5.0, MODIFY_PHONE_STATE has the following definition:
<permission android:name="android.permission.MODIFY_PHONE_STATE"
android:permissionGroup="android.permission-group.PHONE_CALLS"
android:protectionLevel="signature|system"
android:label="#string/permlab_modifyPhoneState"
android:description="#string/permdesc_modifyPhoneState" />
Your app can only hold this permission and use it to modify the phone state if it is signed by the firmware's signing key (the "your own custom ROM" scenario from Marcin's comment) or if your app is installed on the system partition. The latter can be accomplished by having your app pre-installed on the device (or having a rooted device user move your app to the system partition, as I understand it).