Running shell commands on Android using Runtime.getRuntime
Looking at the source code of PackageInstallerSession I found that it was changed to :-
switch (Binder.getCallingUid()) {
case android.os.Process.SHELL_UID:
case android.os.Process.ROOT_UID:
break;
default:
throw new SecurityException("Reverse mode only supported from shell");
}
Source So even if it is a system app, the shell command for install might not work. From the commit messages it seems, this was done to let PackageInstaller do this job.
However it seems this again got changed to at some point, but probably is not included in android 9:-
switch (Binder.getCallingUid()) {
case android.os.Process.SHELL_UID:
case android.os.Process.ROOT_UID:
case android.os.Process.SYSTEM_UID:
break;
default:
throw new SecurityException(
"Reverse mode only supported from shell or system");
}
Source
So if the app is a system app , then the best way would be to use PackageInstaller.