I am developing an App Locker for android. Everything works except for when you try to delete an app, the popup does not appear. I tried to force the lock-screen dialog to appear manually from within the app, but the results were crashes and ANRs. I thought to myself that the popup is not available because the packageInstaller (System app) is using the screen at the same time, and it gets more priority. Another thing is that when I cancel an uninstall, packageInstaller goes away and then my display appears for a fraction of a second and then disappears. Note that this is after, I need it to be present before, or even while the packageInstaller is running.
My question is if it is possible to put my window at a certain priority, so that goes even above the system app?
In my app check service, in my method that's on repeat constantly I had: `
if (mpackageName.equals("com.google.android.packageinstaller")) {
showUnlockDialog();
}
however, this caused my lock-display to get opened a lot of times (because of the repeat), which caused the app to become irresponsive. What I now have (after omitting) is the dialog appearing after, at the end then going away on its own.
This is my show dialog method: `
{
if (context == null) {
context = getApplicationContext();
}
LayoutInflater layoutInflater = LayoutInflater.from(context);
@SuppressLint("InflateParams") View promptsView;
promptsView = layoutInflater.inflate(R.layout.popup_unlock, null, false);
Lock9View lock9View = (Lock9View) promptsView.findViewById(R.id.lock_9_view);
Button forgetPassword = (Button) promptsView.findViewById(R.id.forgetPassword);
LinearLayout linearLayout = promptsView.findViewById(R.id.popup_background);
TextView textView = promptsView.findViewById(R.id.textView);
linearLayout.setBackgroundResource(R.drawable.gradient_list);
textView.setTextColor(getResources().getColor(R.color.colorWhite));
forgetPassword.setTextColor(getResources().getColor(R.color.colorWhite));
animateBanner1(linearLayout);
lock9View = (Lock9View) promptsView.findViewById(R.id.lock_10_view);
lock9View.setVisibility(View.VISIBLE);
lock9View.setCallBack(new Lock9View.CallBack() {
@Override
public void onFinish(String password) {
if (password.matches(sharedPreference.getPassword(context))) {
dialog.dismiss();
} else {
Toast.makeText(context, "Wrong pattern, try again", Toast.LENGTH_SHORT).show();
}
}
});
forgetPassword.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(AppCheckServices.this, PasswordRecoveryActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
dialog.dismiss();
}
});
dialog = new Dialog(context, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
dialog.setCanceledOnTouchOutside(false);
dialog.setCancelable(false);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Objects.requireNonNull(dialog.getWindow()).setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
}
else {
Objects.requireNonNull(dialog.getWindow()).setType(WindowManager.LayoutParams.TYPE_PHONE);
}
dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
dialog.setContentView(promptsView);
dialog.getWindow().setGravity(Gravity.CENTER);
dialog.setOnKeyListener(new Dialog.OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialog, int keyCode,
KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK
&& event.getAction() == KeyEvent.ACTION_UP) {
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
}
return true;
}
});
}
dialog.show();
}
As I said this works on every other app besides the packageInstaller even if I specifically lock it.
Here are my relevant Manifest Permissions:
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission
android:name="android.permission.INTERNAL_SYSTEM_WINDOW"
tools:ignore="ProtectedPermissions" />
<uses-permission
android:name="android.permission.PACKAGE_USAGE_STATS"
tools:ignore="ProtectedPermissions" />
From What I understand, the highest "setType()" for the window manager is the:
SYSTEM_ALERT_WINDOW
It allows to have the top most display. I thought that by using this, I could block the packageInstaller. However this too requires special permission (2003 from the crashes), and does not get granted easily.
I would appreciate any help in regard to this matter and can post anything else that is relevant. Thanks in advance!
`