You're better off with Izzy's advise and find and weed out the app trying to install that Clean Master app. Anyhow, there you go with an another solution.
When you attempt to sideload an apk using UI or any app that attempts to install an apk and isn't granted the permission android.permission.INSTALL_PACKAGES, Package Installer app comes into action and its activity PackageInstallerActivity
is launched. The setting for unknown sources (install_non_market_apps) under Settings Storage's database is checked and based on that, you're either shown that prompt (dialog) or the permissions and the install button.
Even if you manage to find a hack that disables that prompt from being shown, Package Installer would still be launched and the UI would look awkward since only app's label and white space would be visible to you, which would do naught but create confusion.
For rooted Android
The solution I ended up with is to get rid of the activity PackageInstallerActivity
. You can use Elixir 2 to disable that activity.
Launch it → Application → tap → System applications → Package Installer → find and disable the said activity
You can also use adb in this case
adb shell su -c pm disable com.android.packageinstaller/.PackageInstallerActivity # Disables the activity
adb shell su -c pm enable com.android.packageinstaller/.PackageInstallerActivity # Use it to enable the activity
Now whenever you or an app attempt to sideload an apk which requires launching the Package Installer app, you may either get a toast like in the following image or an app registered to open/explore an apk would be launched or be suggested by system.
(Click image to enlarge)
If the toast becomes noisy, hide it using EnhancedToast1 or UnToaster2. Since they are Xposed modules, you would need Xposed Framework appropriate3 for your Android version.
Note that disabling that activity wouldn't affect the ability of Play Store to install an app, neither would it affect adb install
because the underlying package manager is intact.
You can use automation here too. Example, whenever your preferred file manager is active on screen, enable that activity so that you can continue to sideload an apk, should you decide to, and keep it disabled for any other on-screen active app.
For non-rooted Android
You (KitKat or Lollipop users) can hide/block the whole Package Installer app. You definitely need adb for that.
adb shell pm block com.android.packageinstaller # for KitKat
adb shell pm hide com.android.packageinstaller # for Lollipop
The biggest inconvenience here is that you won't be able to uninstall an app using Settings app because it uses Package Installer's activity named UninstallerActivity
and UninstallAppProgress
. Attempt to removal of an app using Settings app would cause the latter to crash.
Every time you intend to remove an app using Settings app or sideload an apk using UI, you must unhide/unblock Package Installer app.
To unblock/unhide, do
adb shell pm unblock com.android.packageinstaller # for KitKat
adb shell pm unhide com.android.packageinstaller # for Lollipop
Note that hiding/blocking that app wouldn't affect the ability of Play Store to install an app, neither would it affect adb install
because the underlying package manager is intact.
1: XDA: EnhancedToast
2: XDA: UnToaster
3. Xposed Framework: Android 4.x, Android 5.x and 6.x