13

I'm trying to install programmatically an app without user interaction and i'm getting this error

 SecurityException: Neither user 10057 nor current process has android.permission.INSTALL_PACKAGES

My installer is located in /system/app on rooted phone, "Install non market apps" is checked , the installer has permission

<uses-permission android:name="android.permission.INSTALL_PACKAGES"/>

This is my call function

 private void puk(Context context) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException{

    String fileName = PAKAGE_FILE_NAME ;
    String dir_type = Environment.DIRECTORY_DOWNLOADS;

    File dir= Environment.getExternalStoragePublicDirectory(dir_type);
    java.io.File file = new java.io.File(dir ,fileName);
    Uri packageUri = Uri.fromFile(file);

    PackageManager pm = context.getPackageManager();

    Class<? extends PackageManager> o = pm.getClass();
    Method[] allMethods=o.getMethods();

    for (Method m : allMethods) {
        if (m.getName().equals("installPackage")) { 
            Log.e(TAG, "installing the app.." );
            m.invoke(pm,new Object[] { packageUri, null, 1, "com.mic.zapp"});
            break;
        }
    }

}  

I'm getting this error

 11-15 02:46:23.320: W/System.err(10848): java.lang.reflect.InvocationTargetException
 11-15 02:46:23.330: W/System.err(10848):   at java.lang.reflect.Method.invokeNative(Native Method)
 11-15 02:46:23.330: W/System.err(10848):   at java.lang.reflect.Method.invoke(Method.java:507)
 11-15 02:46:23.330: W/System.err(10848):   at com.mic.pvtapi.PvtApiReflectActivity.puk(PvtApiReflectActivity.java:56)
 11-15 02:46:23.330: W/System.err(10848):   at com.mic.pvtapi.PvtApiReflectActivity.onCreate(PvtApiReflectActivity.java:28)
 11-15 02:46:23.330: W/System.err(10848):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
 11-15 02:46:23.330: W/System.err(10848):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
 11-15 02:46:23.330: W/System.err(10848):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
 11-15 02:46:23.330: W/System.err(10848):   at android.app.ActivityThread.access$1500(ActivityThread.java:123)
 11-15 02:46:23.330: W/System.err(10848):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
 11-15 02:46:23.330: W/System.err(10848):   at android.os.Handler.dispatchMessage(Handler.java:99)
 11-15 02:46:23.330: W/System.err(10848):   at android.os.Looper.loop(Looper.java:130)
 11-15 02:46:23.330: W/System.err(10848):   at android.app.ActivityThread.main(ActivityThread.java:3835)
 11-15 02:46:23.330: W/System.err(10848):   at java.lang.reflect.Method.invokeNative(Native Method)
 11-15 02:46:23.330: W/System.err(10848):   at java.lang.reflect.Method.invoke(Method.java:507)
 11-15 02:46:23.330: W/System.err(10848):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
 11-15 02:46:23.330: W/System.err(10848):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
 11-15 02:46:23.330: W/System.err(10848):   at dalvik.system.NativeStart.main(Native Method)
 11-15 02:46:23.330: W/System.err(10848): Caused by: java.lang.SecurityException: Neither user 10057 nor current process has android.permission.INSTALL_PACKAGES.
 11-15 02:46:23.340: W/System.err(10848):   at android.os.Parcel.readException(Parcel.java:1322)
 11-15 02:46:23.340: W/System.err(10848):   at android.os.Parcel.readException(Parcel.java:1276)
 11-15 02:46:23.340: W/System.err(10848):   at android.content.pm.IPackageManager$Stub$Proxy.installPackage(IPackageManager.java:2037)
 11-15 02:46:23.340: W/System.err(10848):   at android.app.ContextImpl$ApplicationPackageManager.installPackage(ContextImpl.java:2613)

I have readed that ti is possible to gain INSTALL_PAKAGES permissions in two ways: signing the app with firmware's key or putting the app in the firmware. My app is runng from /system/app so it has to gain privileges.

Some one know what is wrong and give me some hints? Thanks

EDIT:

One step forward, two steps backward

i'we added new permission to the app

 <permission 
        android:name="com.mic.pvtapi.permission.INS_AP"
    android:label="etichetta_perm"
    android:protectionLevel="signatureOrSystem" />

<uses-permission android:name="com.mic.pvtapi.permission.INS_AP"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

no more error

Neither user 10057 nor current process has android.permission.INSTALL_PACKAGES

but the new one

     11-15 19:43:58.895: I/ActivityManager(1838): Displayed com.mic.pvtapi/.PvtApiReflectActivity: +421ms
 11-15 19:43:58.955: D/dalvikvm(4008): GC_EXPLICIT freed 3K, 51% free 2681K/5379K, external 0K/0K, paused 132ms
 11-15 19:43:58.955: W/ActivityManager(1838): No content provider found for: 
 11-15 19:43:58.955: E/PackageManager(1838): Couldn't create temp file for downloaded package file.
 11-15 19:43:58.955: W/dalvikvm(1838): threadid=13: thread exiting with uncaught exception (group=0x40018560)
 11-15 19:43:58.965: E/AndroidRuntime(1838): *** FATAL EXCEPTION IN SYSTEM PROCESS: PackageManager
 11-15 19:43:58.965: E/AndroidRuntime(1838): java.lang.NullPointerException
 11-15 19:43:58.965: E/AndroidRuntime(1838):    at com.android.server.PackageManagerService$FileInstallArgs.createCopyFile(PackageManagerService.java:5247)
 11-15 19:43:58.965: E/AndroidRuntime(1838):    at com.android.server.PackageManagerService$FileInstallArgs.copyApk(PackageManagerService.java:5255)
 11-15 19:43:58.965: E/AndroidRuntime(1838):    at com.android.server.PackageManagerService$InstallParams.handleStartCopy(PackageManagerService.java:5051)
 11-15 19:43:58.965: E/AndroidRuntime(1838):    at com.android.server.PackageManagerService$HandlerParams.startCopy(PackageManagerService.java:4902)
 11-15 19:43:58.965: E/AndroidRuntime(1838):    at com.android.server.PackageManagerService$PackageHandler.doHandleMessage(PackageManagerService.java:516)
 11-15 19:43:58.965: E/AndroidRuntime(1838):    at com.android.server.PackageManagerService$PackageHandler.handleMessage(PackageManagerService.java:461)
 11-15 19:43:58.965: E/AndroidRuntime(1838):    at android.os.Handler.dispatchMessage(Handler.java:99)
 11-15 19:43:58.965: E/AndroidRuntime(1838):    at android.os.Looper.loop(Looper.java:130)
 11-15 19:43:58.965: E/AndroidRuntime(1838):    at android.os.HandlerThread.run(HandlerThread.java:60)
 11-15 19:43:58.975: I/Process(1838): Sending signal. PID: 1838 SIG: 9
 11-15 19:43:59.005: I/ServiceManager(1637): service 'SurfaceFlinger' died   

make my phone crash, freez and reboot

Zorb
  • 726
  • 11
  • 24

4 Answers4

4

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.

Community
  • 1
  • 1
weidongxu
  • 303
  • 1
  • 7
  • Thanks! More datils here https://groups.google.com/forum/m/#!topic/android-platform/Vsa4IsJcOPE – Zorb Jun 07 '15 at 14:38
  • There seems to be no /system/priv-app folder on fire tv devices :/ – smedasn Aug 28 '16 at 20:15
  • What's the difference between putting it in /system/app or in /system/priv-app ? – M. A. Jul 23 '18 at 14:33
  • @AbdelhafidMadoui Zorb's comment and refernece already said it. /priv-app could have system level permission, while /app cannot. Note this thread is about Android K. It might not be relevant to later major versions (L or M or N). – weidongxu Aug 03 '18 at 02:39
2

I assume that putting it in the /system/app folder is not equivalent to it being loaded in the firmware.

hoffmanc
  • 614
  • 9
  • 16
0

Running these two lines fixes the issue with PackageManager permission error: "Couldn't create temp file for downloaded package file."

adb shell chown system.shell /data/app
adb shell chown system.shell /data/local
Simon
  • 10,932
  • 50
  • 49
0

About the error:

SecurityException: Neither user 10057 nor current process has android.permission.INSTALL_PACKAGES

To get INSTALL_PACKAGES permission:

  1. Put your app in /system/app
  2. Sign the app with the system's key
  3. In the manifest.xml file, put this attribute inside the tag manifest:

    <manifest android:sharedUserId="android.uid.system" ...
    
Ena
  • 3,481
  • 36
  • 34
  • without signing the app with the system's key is not possible as you know? – Zorb Feb 02 '12 at 21:29
  • 1
    I can say that doing all the above works. Referring to http://developer.android.com/guide/topics/manifest/permission-element.html#plevel, INSTALL_PACKAGES is a signatureOrSystem permission. They say "A permission that the system grants only to applications that are in the Android system image or that are signed with the same certificates as those in the system image." So I don't think that putting it in system/app will be enough. – Ena Feb 03 '12 at 17:39
  • so than what does mean "Android system image" if not the read only partition of android where is all the system stuff? (the question is not direc to you but is general: no one can answer me what this mean) your answer is useful (but i can sign it as correct because at the moment it don't solve the problem, sorry) – Zorb Feb 11 '12 at 22:04