Research and Implementation of High-speed download from sogou market and activation of APP pages on the webpage, and high-speed download of apps

Source: Internet
Author: User
Tags chrome developer chrome developer tools

Research and Implementation of High-speed download from sogou market and activation of APP pages on the webpage, and high-speed download of apps

Github blog address. Updates may not be timely.


I haven't written a blog for a long time. Just now, I just completed the high-speed download function of sogou market, so I entered this pitfall.

In order to increase the number of users, increase user activity, and cooperate with the promotion, the product requires bundling and downloading to see these features in other markets. WTF.

Of course, the task is still to be completed.

The specific requirements are as follows,1. when you enter the application details page, open the details page in this application (sogou market) 2. if the application has been installed, call this application to download the application. Otherwise, download the bundle of the application. After the installation is complete, before the application is opened, download the application that the user wants to download.How can we implement these two functions? Perform the following step-by-step analysis:

1. Functional Requirements

As described earlier.

In general, the previous two functions generally require the application to be installed and run in the background (the simplest understanding is that the application has opened the application and is not killed by other programs ), therefore, the application is installed by default. Otherwise, the application is considered to be not installed (this is the case if not described below ).

2. Competitive Product Analysis

Of course, since competing products have these features, let's take the arguments first and study how they do it. Through Chrome packet capture analysis, the final analysis is as follows.

Baidu mobile assistant http: // 127.0.0.1: 6259/

Sogou mobile assistant http: // 127.0.0.1: 12388/

Arms custom protocol wandoujia: // detail/app/cn. buding. martin

The solutions for Baidu mobile assistant and sogou mobile assistant are basically the same,The local service address 127.0.0.1 (loopback address) of a mobile phone is used, and the port address is different.Pods use a custom protocol. Then, the browser will automatically distribute the protocol to the Activity registered with the wandoujia protocol.

Open application detailsWhen the browser details page is opened, Baidu mobile assistant and sogou mobile assistant access the local loopback address at the same time, pods, however, call the custom protocol by the system to call related applications (generally pods ).

High-speed download PrinciplePods cannot be downloaded by calling the client when the application is installed. When you click Download, you can check whether to download the bundle or the application you want to download directly. (The description is shown in the figure at the end of this article, copywriting is inductive ). Select Download bundle to download the pod installation package with a specific file name. After the installation is complete, scan the specific directory (generally download and the download directory of common browsers). If there is a file that complies with the rules, extract the relevant resource ID, then download the bound APP.

  1. If the application is not installed. The bundle IDs of other packages are different. Other processes are the same as those of pods. If multiple qualified apk files exist, sogou's mobile assistant downloads the latest information. Baidu's mobile assistant has not studied the latest information.
  2. If the mobile APP has been installed. Pods are not implemented, while Baidu mobile assistant and sogou mobile assistant directly request a loopback address (127.0.0.1: port/actionpath? Parameter), port is the port address, Baidu mobile assistant is 6259, and sogou mobile assistant is 12388. Actionpath is the operation to be performed. different operations and different values of parameter are the parameters of related operations. Here, the APP data to be bundled and downloaded is passed. The mobile APP receives the relevant data from the HTTP server in the APP and downloads the data.
3. Final Solution

Call details pageThe HTTP server and the custom protocol can be used, and the custom protocol does not need to run a Service that carries the HTTP server in the background all the time, which saves power.

SubsequentHigh-speed downloadThere is no pea pod. Can you consider using custom protocols for power saving? When the application is not installed, download the bundle directly. If the application is already installed, call the client to download the package. Can custom protocols be implemented? How do I know if the application is installed? Does the browser have corresponding APIs? Obviously not. Even if there is, there may only be some, but all browsers should be supported. The only way is to access the HTTP server and set the timeout time. If there is no response within a certain period of time, the application is not installed and the corresponding bundle is downloaded. In addition, the HTTP server can be used for subsequent extension, and two-way interaction with the Web server can be performed. For example, Baidu mobile assistant can obtain location information through the web. The custom protocols obviously cannot do this. Besides power saving.

After high-speed download is enabled, if the application is not installed, how can I know which application the user needs to download after the application is installed? That isIdentification of bundled applications. The initial solution of sogou market was to break a file into the application (under the asset folder) and store the bound Application ID. However, it can be used for a small number of applications (used to test the bundling effect at the beginning). Currently, it cannot be used for a large number of applications. It requires a large number of packages and a lot of storage space.

The solutions for competing products are perfect. However, considering most of the mobile phone security or cleaning software, you will be prompted to delete the installation package after the application is successfully installed, the download directory of the browser may change. Can I scan the entire SD card to find files that meet the conditions? No, it's too time-consuming.

How do I know the bound Application id when the application is not installed or is not running in the background. The above two solutions are not perfect. How can we solve them. I discussed with the back-end Yan Fei that during high-speed apk download, the webpage recorded the bound app id and packagename downloaded by the mobile phone and the unique id (uuid) of the device. Then, when I opened the market, request the corresponding interface and pass in the uuid to obtain the data to download the corresponding application. The idea is superb. Later I found that there is no practical value. uuid has no reasonable solution. The key lies in that both ends must be unique, mac, ip? How to generate?

After dinner and discussion with Guo Chang, can I call local code to execute related tasks? However, after careful consideration, we found that WebView interacts with js. However, the current use cases cannot be achieved at all. This Webview must be in its own application.

Considering many factors, we finally decided to refer to the solutions of Baidu mobile assistant and sogou mobile assistant, despite the defects. For more information about the custom protocol mode, see this article. The android custom protocol and the custom protocol used to automatically call local apps during html loading, and Android registration listening are not described in this article.

The final solution is to run an HttpServer on the mobile phone background through the Service to listen to port 12307.

Call the client

1. High-speed download

When you click high-speed download on the webpage side, access http: // 127.0.0.1: 12307/appdown? Downid = 1 & packagename = com. sogou. map

If the request succeeds, the json string is returned.

{"Status": 1, "message": "OK "}

If the value of status is 0, the operation fails. If the value of status is 1, the operation succeeds. Message is a specific description.

If the mobile phone does not respond within a certain period of time, the app is not installed by default. Download the bundled APK package.

If the mobile phone responds, the web page will not be processed. The mobile phone will obtain the corresponding downid and packagename. First, determine whether the application has been installed. If yes, the system will prompt that the application has been installed, if the application is not installed, the system prompts that the application is being downloaded and adds it to the download list.

2. Open the details page

Http: // 127.0.0.1: 12307/godetail? When downid = 1 & packagename = com. sogou. map & backtohome = ture backtohome is true, press the return button on the mobile phone to return to the application homepage. If it is false, the browser is returned. (Refer to the pea pod, for example, (http://www.wandoujia.com/apps/com.tencent.mm) [http://www.wandoujia.com/#/com.tencent.mm???#mobile terminal, user-agentand pc=different)

Installation Package application bundling

How to identify which application is bound?

For more information, see the implementation method of competing products. download files with different file names (with rules for file names), read the download folder after the user installs the application and opens the application, and check whether the apk meets the rules. If yes, extract the corresponding id for the download. As long as the server provides an interface for the browser to display different file names when downloading the same file.

For example, sogou mobile assistant a detailed address for http://wap.sogou.com/app/apkdetail.jsp? Ppid = 34 & cid = 49 & docid = 8271386494777466339 & e = 1394, what is the http://download.zhushou.sogou.com/zhushou/android/MobileTools.apk address for the high-speed download installation package? Dn=MobileTools_8271386494777466339_71.apk the downloaded API name is mobiletools_8271386494777466339_71.apk. The bound Application id is 8271386494777466339 and the Application id is. You can set the Content-Disposition field of the headers returned by HTTP to attachment; filename = "MobileTools_8271386494777466339_71.apk". Generally, mainstream browsers support this attribute.

For this reason, APK is named sogouappmall_binding_downid_9.apk, and downid (downid must be an integer) is extracted when the application is determined to be in this format (through regular expression matching ). If the application is not installed, click Download to download the apk named by the preceding rule to the folder. When you install an application and open the application, you can scan the apk in common download folders (Common/download,/downloads, and Browser download folders, if the rule is met, extract the id of a file. After the extraction, download the file and delete the installation package (to prevent subsequent interference ). Considering that the same folder may have multiple installation packages that comply with the rules, the latest two packages that comply with the rules of the current folder are retrieved in chronological order. The other folders are ignored, wait for the next start and then process (usually this case is rare ). Of course, there are other details to be processed. We will not discuss them here.

4. Performance Optimization and prospects

Program optimization is something that must be done by the target siege attacker. Therefore, of course, optimization is required.

To reduce power consumption, the following two policies are specified.

1. When the network changes, if there is no network, the service is disabled. If there is a network, the service is enabled. Enable or disable the service when you unlock the screen or lock the screen.

2. There is a network, and the screen is a necessary condition to trigger the service to start. It can reduce the power consumption problems caused by network changes in the screen lock status of applications.

The preceding two policies can be used in combination and may cause some problems. For example, if the conditions are met but the service is not enabled (frequent network switching may cause this ).

The reason for setting the above conditions is that subsequent operations can be completed only through the network. Secondly, in the screen lock status, the user cannot trigger the related process, unless the program is automatically triggered (Instant Messaging Software receives information such as, or automatically downloads, but this is too rogue), it is necessary to run in the background when the screen is locked.

The HTTP server is an open-source Nanohttpd on Github. In addition to high-speed download, the http server can also be used in many aspects, such as data transmission to a computer and interaction between applications and webpages.

5. Final Implementation

Access http://m.app.sogou.com/to view final results.

The general idea is the above description. I hope to inspire everyone and give them a valuable role.

It is not available yet. It is estimated that it will wait until November 5.

6. Related tools and Appendices

(1) Chrome Developer Tools + device mode (data packet capture)

(2) demo addresses for downloading from three markets: Baidu mobile assistant, sogou mobile assistant, and mapoa

At that time (the page for was as follows)


(3) The APK download path of a Common Browser (# indicates that the modified line is a comment, with one directory per line. Currently, subdirectories cannot be traversed)


# This is the binding apk file path # this is a comment # some system default, Chrome, Opera, Opera mini, Sogou Broswer, ES File Explorer, doldolphin Browserdownload # meizu browser, some system defaultdownload/downloads # uc examples # QQ BroswerQQBrowser/installation package QQBrowser/download qqbrowser/download # QQ Broswer HDQQBrowser # baidu examples/flyflow/downloads # baidu appbaidu/searchbox/downloads # Maxthon Broswer /DownloadsTTDownload/installapkApplicationThunderDownload # liebao downloads/download/download #2345 broswerDownload/2345 Browser download/installation package # downloads/down/downloads/ DOWNLOADapc/ApcBrowser/downloads # YueDong Broswer, ignore, The apk file name is changed by the broswer, the same with 4G Explorer (do not support header's Content-Disposition attribute) # ydBrowser/download # 4G-explorer/apks


Hahahaha, perfect solution to all problems. And can be expanded later.






This article is from the RxRead's Blog. You are welcome to reprint it.




I use the sogou high-speed browser. Every time I open a webpage, all webpages appear in the same webpage as multiple tags,

It is easy to switch between multiple labels to minimize the number of icons in the window and taskbar.
If you want to open several web pages and open another window separately, you can click-file-new window in the menu bar in the upper right corner.
If you still like the traditional way, each web page is opened through multiple windows. In the top-right corner of sogou browser, choose "Tools"> "general"> "enable multiple web pages": Select multiple windows.

The sogou expressway browser opens several webpages. Which one is the current webpage?

You can change your skin to see the current tag.
Sogou browser 2.2 or later versions can be set
Open "tool -- sogou browser option -- Label appearance" in the menu bar.

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.