开发者

Error Installing with Admin Permissions

I work for a cell company, our phones are based Android(SDK 1.5) we have the ability to sign our applications in our phones and 开发者_高级运维give it firmware permissions, like:

installing an extern application while using PackageManager.(SDK 1.5)

this is what i did:

 File src = context.getFileStreamPath(fileName);
 Uri mPackageURI = Uri.parse(src.getAbsolutePath());    
PackageManager pm = context.getPackageManager();

int installFlags = 0;

try {
  PackageInfo pi = pm.getPackageInfo(packageName,
    PackageManager.GET_UNINSTALLED_PACKAGES);

  if (pi != null) {
    Log.debug(TAG, TAG + ":replacing  " + fileName);

    installFlags |= PackageManager.REPLACE_EXISTING_PACKAGE;
  }

} catch (NameNotFoundException e) { }

try {
    PackageInstallObserver observer = new PackageInstallObserver();
    pm.installPackage(mPackageURI, observer, installFlags);

} catch (SecurityException e) {
  //if the app is not signed by the manufacture it will get here a security exception
}


class PackageInstallObserver extends IPackageInstallObserver.Stub {
  public void packageInstalled(String packageName, int returnCode) {
  }
}

Now this is the wierd thing i get:

Since we are the manfucatures we dont get any exception while execute pm.installPackage(mPackageURI, observer, installFlags);

since we have signed our app with admin permissions.

but what we do get is this crazy result and the phone being RESTARTED.

threadid=21: thread exiting with uncaught exception (group=0x4000fe70)

07-11 16:29:38.493: ERROR/AndroidRuntime(2561): Uncaught handler: thread PackageManager exiting due to uncaught exception

07-11 16:29:38.493: ERROR/AndroidRuntime(2561): *** EXCEPTION IN SYSTEM PROCESS.  System will crash.

07-11 16:29:38.493: ERROR/AndroidRuntime(2561): java.lang.NullPointerException

07-11 16:29:38.493: ERROR/AndroidRuntime(2561):     at 
com.android.server.PackageManagerService.installPackageLI(PackageManagerService.java:3634)

07-11 16:29:38.493: ERROR/AndroidRuntime(2561):     at com.android.server.PackageManagerService.access$1500(PackageManagerService.java:120)

07-11 16:29:38.493: ERROR/AndroidRuntime(2561):     at com.android.server.PackageManagerService$5.run(PackageManagerService.java:3253)

07-11 16:29:38.493: ERROR/AndroidRuntime(2561):     at android.os.Handler.handleCallback(Handler.java:587)

07-11 16:29:38.493: ERROR/AndroidRuntime(2561):     at android.os.Handler.dispatchMessage(Handler.java:92)

07-11 16:29:38.493: ERROR/AndroidRuntime(2561):     at android.os.Looper.loop(Looper.java:123)

07-11 16:29:38.493: ERROR/AndroidRuntime(2561):     at android.os.HandlerThread.run(HandlerThread.java:60)

Second way: Ive also tried this way and I got diffrent exception:

*very similar to the first way, just the major difference is in this line:

 String src = String.format("file:///data/data/com.mirs.agentcore/files/%s", fileName);

 Uri mPackageURI = Uri.parse(src);

 PackageManager pm = context.getPackageManager();



 String src = String.format("file:///data/data/com.mirs.agentcore/files/%s", fileName);

 Uri mPackageURI = Uri.parse(src);

 PackageManager pm = context.getPackageManager();

 int installFlags = 0;

  .... //the rest of the code is the same as the First way(mention above)

After this code being executed(Second way), the phone continue normally, but I get this exception:

09-12 12:10:16.484: ERROR/PackageManager(6601): Couldn't copy package file to temp file.


I found the 1.5 source for PackageManagerService.java, and this looks like the code that's causing your problem:

 try {
    fd = mContext.getContentResolver().openFileDescriptor(pPackageURI, "r");
 } 
 catch (FileNotFoundException e) {
    Log.e(TAG, "Couldn't open file descriptor from download service.");
    res.returnCode = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE;

    // This break statement was line 3634.
    break main_flow;
 }

The documentation for ContentResolver.openFileDescriptor says:

Throws FileNotFoundException if no file exists under the URI or the mode is invalid.

It looks like the problem is with your mPackageURI, so I would begin evaluating the values of fileName and Uri.parse(src.getAbsolutePath()).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜