安装应用程序默默,与授予INSTALL_PACKAGES许可 [英] Install apps silently, with granted INSTALL_PACKAGES permission

查看:1699
本文介绍了安装应用程序默默,与授予INSTALL_PACKAGES许可的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想静默安装APK到系统中。 我的应用程序位于/系统/应用程序,并成功获准android.permission.INSTALL_PACKAGES

I am trying to silently install apk into the system. My app is located in /system/app and successfully granted permission "android.permission.INSTALL_PACKAGES"

但我找不到任何地方如何使用此权限。我试图把文件复制到/数据/应用程序,并没有成功。我也尝试过使用这种code

However I can't find anywhere how to use this permission. I tried to copy files to /data/app and had no success. Also I tried using this code

    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(
            Uri.parse("file:///sdcard/app.apk"),
            "application/vnd.android.package-archive");
    startActivity(intent);

但是,这code打开标准安装对话框。如何安装应用程序默默无根与授予 android.permission.INSTALL_PACKAGES

PS我写一个应用程序,会从文件夹中安装许多的apk到系统上的第一次启动(更换安装向导)。我需要它做固件更轻。

PS I am writing an app that will install many apks from folder into the system on the first start (replace Setup Wizard). I need it to make firmware lighter.

如果你认为我写一个病毒:所有的程序都安装到/数据/应用程序。许可Install_packages只能授予位于/系统/应用程序或系统密钥签名的系统级程序。因此,病毒就无法到达那里。

If you think that I am writing a virus: All programs are installed into /data/app. Permission Install_packages can only be granted to system-level programs located in /system/app or signed with the system key. So virus can't get there.

正如所说<一个href="http://www.mail-archive.com/android-porting@googlegroups.com/msg06281.html">http://www.mail-archive.com/android-porting@googlegroups.com/msg06281.html应用程序可以是沉默的安装,如果他们有install_packages权限。而且你不需要Install_packages权限安装软件包不是悄无声息。加上<一href="http://www.androidzoom.com/android_applications/tools/silent-installer_wgqi.html">http://www.androidzoom.com/android_applications/tools/silent-installer_wgqi.html

As said http://www.mail-archive.com/android-porting@googlegroups.com/msg06281.html apps CAN be silent installed if they have install_packages permission. Moreover you don't need Install_packages permission to install packages not silently. Plus http://www.androidzoom.com/android_applications/tools/silent-installer_wgqi.html

推荐答案

你的第一个选择是寻找到Android的原生<一href="http://$c$csearch.google.com/$c$csearch/p?hl=en#cZwlSNS7aEw/packages/apps/PackageInstaller/src/com/android/packageinstaller/PackageInstallerActivity.java&d=3">PackageInstaller.我建议修改应用程序,你喜欢的方式,或只提取所需的功能。

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.

特别是,如果你看看<一href="http://$c$csearch.google.com/$c$csearch/p?hl=en#cZwlSNS7aEw/packages/apps/PackageInstaller/src/com/android/packageinstaller/PackageInstallerActivity.java&d=3">PackageInstallerActivity其方法 onClickListener

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();
    }
}

然后你会发现,实际的安装程序位于<一href="http://$c$csearch.google.com/$c$csearch/p?hl=en#cZwlSNS7aEw/packages/apps/PackageInstaller/src/com/android/packageinstaller/InstallAppProgress.java&d=3">InstallAppProgress类。检查的类,你会发现, initView 是核心安装程序的功能,而且它的最后一件事是调用 PackageManager installPackage 功能:

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);
}

下一步是检查<一href="http://$c$csearch.google.com/$c$csearch/p?hl=en#cZwlSNS7aEw/frameworks/base/core/java/android/content/pm/PackageManager.java&d=3">PackageManager,这就是抽象类。你会发现 installPackage(...)函数存在。坏消息是,它的标有@hide。这意味着它不能直接使用(你将不能够与调用编译此方法)。

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.

如果你有兴趣在如何 PackageManager installPackage 函数的实现,看看<一href="http://$c$csearch.google.com/$c$csearch/p?hl=en#uX1GffpyOZk/services/java/com/android/server/PackageManagerService.java&q=IPackageManager%20service">PackageManagerService.

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

您需要通过上下文来获取软件包管理器对象 getPackageManager()。然后,你将通过反射调用 installPackage 功能。

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

这篇关于安装应用程序默默,与授予INSTALL_PACKAGES许可的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆