38

I have system-level app with android:sharedUserId="android.uid.system" (UID: 1000).

Device is not rooted! INSTALL_PACKAGES permission is included to Manifest.

Can I install downloaded *.apk silently?

yuralife
  • 1,545
  • 2
  • 21
  • 35

2 Answers2

45

I`ve found the issue.

  1. Added "android.permission.INSTALL_PACKAGES" permission.
  2. I signed my application using "signapk.jar" with certificate that I`ve got from manufacturer of my device.
  3. And now this app can install others using "pm install /.../app.apk" without "su".

It works!

P.S. Updating application using just "pm install" doesn`t replace existing application with new one, but returns exit_value = 0. So to update there are two ways:

  • use "pm install -r /.../app.apk";
  • firstly delete app using "pm uninstall com.mydomain.myapp" (you need "android.permission.DELETE_PACKAGES" permission) and then install new one.
yuralife
  • 1,545
  • 2
  • 21
  • 35
  • How to upgrade itself? I have an apk which has auto-update functions. But it put in /system/app, now only pm install seems not work. – brucenan May 03 '13 at 09:15
  • @3c71, this update command will update APK accordingly to versions? (I mean update will process only if we update with newer version?) – yuralife May 17 '13 at 08:35
  • 2
    Not sure actually. I was expecting -r to replace the existing app with whatever the APK is, be it the same version, newer or older. While the pm install would only replace if version is newer, not the same. – 3c71 May 18 '13 at 09:34
  • @yuralife I am not sure on this are u able to install apk without rooting? – Utsav Gupta Aug 24 '14 at 08:20
  • @yuralife Ok. While you are at it..can you also explain how do you install a System app on device..I am on the same lines but unable to figure out. Thanks – Utsav Gupta Aug 26 '14 at 08:56
  • @yuralife can you please eplain how to contact the manufacturers? – amalBit Jan 22 '15 at 13:30
  • 1
    Work like a charm with the manufacturer certificate!! Thanks!! – Maxime Sep 04 '15 at 21:35
  • Hello, how do I get the "certficate manufacturer" of my device? – img.simone Jan 27 '17 at 10:26
  • What will happen if app is currently playing and you try to run the update? Will it restart,crash or something else? Another question... Is this code in app we are trying to update or in some other app which will update mine? – NixSam Feb 01 '18 at 14:54
  • @NixSam 1. App will closed without any crash; 2. You can not update the app by itself, that code should be executed in another app. – yuralife Feb 01 '18 at 16:12
  • @yuralife thanks for quick response. I tried it, but I have some problems executing any command. I tried just executing pwd command and I got Error running exec(). Command: [pwd] Working Directory: null Environment: null. No matter what I do, I got Working Directory: null Environment: null. It is a rooted emulator, I've checked it. I have write permission in manifest. Do you know maybe where is a problem? I lost bunch of hours to figure it out, don't know what it could be. – NixSam Feb 03 '18 at 19:36
  • @NixSam you should try that on real device, because as I know sometimes emulator can have different behavior especially at such specific tests. – yuralife Feb 05 '18 at 21:56
  • how do I get the "certficate manufacturer" of my device? please explain the way ? – hkh114 May 07 '18 at 07:57
6

No, you cannot. Simply having the same UID isn't enough. You must also be signed with the same key as the ROM itself.

Silently installing apps, or updates to your own app, isn't allowed for security reasons.

Raghav Sood
  • 81,899
  • 22
  • 187
  • 195
  • 3
    But my app is signed with certificate that I`ve got from manufacturer. This app will run only on ONE type and model of device. – yuralife Mar 25 '13 at 16:36
  • @yuralife In such a case, the manufacturer should build your app into the system image, where it can be autoupdates with other preinstalled apps. – Raghav Sood Mar 25 '13 at 16:37
  • 1
    Ok, but this built-in main-app should be able to install simple apps without user confirmation. And I don`t know how to implement this? – yuralife Mar 25 '13 at 16:41
  • @yuralife You don't need to. It is the manufacturers responsibility. Your app will update the same way as Gmail etc. – Raghav Sood Mar 25 '13 at 16:42
  • 1
    But I need to control this updating and its not a market app. For example, before updating I need to check if it`s not using by user. – yuralife Mar 25 '13 at 16:48
  • @yuralife You can't install updates, market or otherwise, silently unless your app is in the system partition, where it can be put only by the OEM. Once there, you can use terminal commands to copy your app. However, this will have to be done through another proxy app, as your own process will be killed during the copy process if you overwrite your own app, stopping the update in the middle. OEMs usually have such proxy apps. – Raghav Sood Mar 25 '13 at 16:52
  • One way - copy my app I need to install/update to /data/app and it`s possible to system-level app? – yuralife Mar 25 '13 at 17:16
  • data/app is normall apps. System apps are in system/app – Raghav Sood Mar 25 '13 at 17:16
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/26886/discussion-between-yuralife-and-raghav-sood) – yuralife Mar 25 '13 at 17:19