Can Android implement the silent installation mode?

Source: Internet
Author: User

(1) I searched for a solution to this problem on the Internet and consulted the android development documentation. I did not find any display API call that can implement this function. Many people on the internet asked the same question, but none of them can provide a solution. Android has blocked this method for user security, and the third method cannot implement Silent Installation.
(2) then I tried to see the source code file for implementing the common installation program in Android. can I find a solution and try to bypass the prompt box during normal installation, directly call the function called after confirmation for installation. After checking the general installation process of the android application, it is found that the method calling process of the application installation process is: first, go to com/Android/packageinstaller/packageinstalleractivity. in the Java activity, first check whether the program installed by the supervisor is the correct installation file and whether the application has been installed in the current system, prompting the user to repeat the installation, in addition, you can obtain the permissions used by the program installed by the supervisor, and then send the information to the user through a dialog box. When the user confirms the installation, start COM. android. packageinstaller. installappprogress. java activity. In this activity, call

Android. content. PM. packagemanager. installpackage (URI packageuri, ipackageinstallobserver observer, int flags, string installerpackagename) to install the application. packagemanager obtained in installappprogress is obtained through packagemanager PM = getpackagemanager, the obtained object is an android. app. contextimpl. applicationpackagemanager object, and

Applicationpackagemanager object is encapsulated,

Applicationpackagemanager (contextimpl context,
Ipackagemanager pm ){
Mcontext = context;
MPM = PM;
}
The installpackage method is
@ Override
Public void installpackage (URI packageuri, ipackageinstallobserver observer, int flags,
String installerpackagename ){
Try {
MPM. installpackage (packageuri, observer, flags, installerpackagename );
} Catch (RemoteException e ){
// Shocould never happen!
}
}

The installpackage method called is ipackagemanager. installpackage (packageuri, observer, flags, installerpackagename );
In contextimpl, ipackagemanager PM = activitythread. getpackagemanager () obtains the ipackagemanager instance object. In the activitythread. getpackagemanager () method,
Static ipackagemanager spackagemanager;
Public static ipackagemanager getpackagemanager (){
If (spackagemanager! = NULL ){
Return spackagemanager;
}
Ibinder B = servicemanager. getservice ("package ");
Spackagemanager = ipackagemanager. stub. asinterface (B );
Return spackagemanager;
}

The final installpackage is indeed the ipackagemanager. installpackage method;

Because class packagemanagerservice extends ipackagemanager. stub, ipackagemanager. installpackage calls: packagemanagerservice. Java (frameworks/base/services/Java/COM/Android/Server) File
/* Called when a downloaded package installation has been confirmed by the user */
Public void installpackage (
Final URI packageuri, final ipackageinstallobserver observer, final int flags ){
Installpackage (packageuri, observer, flags, null );
}
(I don't understand why ipackagemanager. the installpackage method calls packagemanagerservice. java, but in an online article, it gives the above reason, because class packagemanagerservice extends ipackagemanager. stub, I don't understand, but no other functions can be found through packagemanagerservice. java source code, it can be seen that it is indeed installed in the application, so it should be determined that the final call method is

Packagemanagerservice. installpackage (final URI packageuri, final ipackageinstallobserver observer, final int flags ))

So how can we get packagemanagerservice. installpackage () is considered to be installpackage () through reflection. However, it is difficult to obtain the ipackageinstallobserver type in the parameter. ipackageinstallobserver is defined by the aidl file and the features of the aidl file are used, set ipackageinstallobserver. copy the aidl file to a local program to obtain the ipackageinstallobserver class. calss, through which the installpackage () method is reflected. However, when invoke is used, the Instance Object of ipackageinstallobserver cannot be obtained. The instance object of ipackageinstallobserver must pass

Ipackageinstallobserver. stub. asinterface (ibinder binder) method, unable to get the ibinder object bound to it, thus unable to execute the reflected method; in addition, packagemanagerservice. installpackage () does not appear to be executed by third-party applications and has permission restrictions. This seems to be confirmed from the following instances.

(3)execute runtime.getruntime(cmd.exe C ("PM install-R" + new file (environment. getexternalstoragedirectory (),
"Download/Shuffle-1.6.3.apk"), the command is executed on com. android. commands. PM. in pm, directly call ipackagemanager. installpackage (URI. fromfile (new file (apkfilepath), OBS, installflags, installerpackagename) method, in this method,
Ipackagemanager MPM;
MPM = ipackagemanager. stub. asinterface (servicemanager. getservice ("package "));
And class packagemanagerservice extends ipackagemanager. Stub
Therefore, ipackagemanager. installpackage is called in the packagemanagerservice. Java (frameworks/base/services/Java/COM/Android/Server) file.
/* Called when a downloaded package installation has been confirmed by the user */
Public void installpackage (
Final URI packageuri, final ipackageinstallobserver observer, final int flags ){
Installpackage (packageuri, observer, flags, null );
}

In this method, not granting permission Android is displayed. permission. delete_packages is incorrect. This permission cannot be granted to a third-party application, so it cannot be executed in the program. It is the same as the method used to install an application in Android, however, they do not have the permission to execute third-party applications ..

(4) other solutions:

1> Use Android: shareduserid = "android. uid. system" to restrict the system permission of the application program. Check that the program can execute the runtime.getruntime(cmd.exe C ("PM install-r...") method.
2> read the code at the lower layer of Android app installation to check whether the underlying method can be called for installation or the code for implementing an installer by yourself. However, this is unlikely, because this involves calls at the lower layer of Android,

There must be some permission restrictions.
3> A file management program is displayed on the Internet. It is said that the application can be installed in batches, but it indicates that the user needs to confirm the root permission of the mobile phone during running, so it does not make much sense.
4> you can customize your Android system.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.