Install Apps Silently, With Granted Install_Packages Permission

Install apps silently, with granted INSTALL_PACKAGES permission

Your first bet is to look into Android's native PackageInstaller. I would recommend modifying that app the way you like, or just extract required functionality.


Specifically, if you look into PackageInstallerActivity and its method onClickListener:

 public void onClick(View v) {
if(v == mOk) {
// Start subactivity to actually install the application
Intent newIntent = new Intent();
...
newIntent.setClass(this, InstallAppProgress.class);
...
startActivity(newIntent);
finish();
} else if(v == mCancel) {
// Cancel and finish
finish();
}
}

Then you'll notice that actual installer is located in InstallAppProgress class. Inspecting that class you'll find that initView is the core installer function, and the final thing it does is call to PackageManager's installPackage function:

public void initView() {
...
pm.installPackage(mPackageURI, observer, installFlags, installerPackageName);
}

Next step is to inspect PackageManager, which is abstract class. You'll find installPackage(...) function there. The bad news is that it's marked with @hide. This means it's not directly available (you won't be able to compile with call to this method).

 /**
* @hide
* ....
*/
public abstract void installPackage(Uri packageURI,
IPackageInstallObserver observer,
int flags,String installerPackageName);

But you will be able to access this methods via reflection.

If you are interested in how PackageManager's installPackage function is implemented, take a look at PackageManagerService.

Summary

You'll need to get package manager object via Context's getPackageManager(). Then you will call installPackage function via reflection.

Troubles installing programmatically an app with INSTALL_PACKAGES permission from /system/app

Refer to signatureOrSystem permissions on custom ROM

Basically,

  1. add the required <uses-permission>
  2. push apk to /system/priv-app

Done (well, at least works for me).

You do not need to add android:protectionLevel="signatureOrSystem" or android:sharedUserId="android.uid.system". You could sign with any certification.

Android INSTALL_PACKAGES Permission and Non-PlayStore Apps

My needs are just these: Users with "unknown sources" deactivated should be able to install the 2nd app. And: The user should never be redirected to Google Play store.

This combination is impossible, barring a major security flaw in Android and/or the Play Store. The only way to install apps through the Play Store is via the Play Store app.

I would like a solution, where I sent an intent to the PlayStore app and it displayed the app name, permissions and the install button.

That activity is not exported. You are welcome to use a market:// Uri to lead the user to the Play Store, where they can review this second app and decide, for themselves, whether or not to download and install it.

since the user already accepted that my app may install packages

Your app cannot install packages directly, unless it is signed with the firmware signing key or is installed on the system partition (e.g., by a rooted device user), as that is the only way that you can hold the INSTALL_PACKAGES permission. Ordinary SDK apps are welcome to create an ACTION_VIEW or ACTION_INSTALL_PACKAGE Intent to request that the app be installed, but the user will need "unknown sources" enabled.

Unable to retrieve if REQUEST_INSTALL_PACKAGES permission is granted for other apps

Because this permmission has a signature protection level. According to documentation:

A permission that the system grants only if the requesting application is signed with the same certificate as the application that declared the permission

So requestedPermissionsFlags is correct - only com.android.nfc is granted.

Actually REQUEST_INSTALL_PACKAGES has a signature|appop protection level, that's why not only system apps can use it although this perrmission is not granted for them. For a little bit more details - Acquiring Android Permission with Signature Protection Level.

Android: How to Install Apk like Android Market does

There is some information here :

Install apps silently, with granted INSTALL_PACKAGES permission

and here :

How does AppBrain's installation app work?

I don't think is a really good idea to install something without telling it to the user and/or without showing him the permissions you're asking for. In the second link, CommonsWare give a really good comment about this idea.

You can take a look on the Android's Developer Distribution Agreement, article 4.5, if you want to publish your app on the Play Store.



Related Topics



Leave a reply



Submit