(Ffos Gecko & Gaia) OTA-The real download

Source: Internet
Author: User

The previous analysis of so much, has not really come to the download process. This article is to understand the real downloader.

1. Updateservice.downloadupdate

It seems that the right worker is the last new downloader.

Downloadupdate:functionaus_downloadupdate (update, background) {if(!update)ThrowCr.ns_error_null_pointer; //Don ' t download the update if the update ' s version is less than the  //Current application's version or the update ' s version is the same as the  //application ' s version and the build ID is the same as the application ' s  //build ID.  if(Update.appversion &&(Services.vc.compare (update.appversion, Services.appinfo.version)< 0 | |Update.buildid&& Update.buildid = = Services.appinfo.appBuildID &&update.appversion==Services.appinfo.version)) {LOG ("Updateservice:downloadupdate-canceling download of update since" + "it is for a earlier or same application ve Rsion and build id.\n "+" Current application version: "+ Services.appinfo.version +" \ n "+" update Applica tion version: "+ update.appversion +" \ n "+" Current Build ID: "+ Services.appinfo.appBuildID +" \ n "+" U Pdate build ID: "+Update.buildid);    Cleanupactiveupdate (); returnState_none; }  //If A download request is in progress vs. a download ready to resume  if( This. isdownloading) {    if(Update.iscompleteupdate = = This. _downloader.iscompleteupdate &&background== This. _downloader.background) {LOG ("Updateservice:downloadupdate-no support for downloading more" + "than one update at a time"); returnReadstatusfile (Getupdatesdir ()); }     This. _downloader.cancel (); }  if(Appconstants.platform = = "Gonk") {Let um= cc["@mozilla. Org/updates/update-manager;1"].    GetService (Ci.nsiupdatemanager); Let Activeupdate=um.activeupdate; if(Activeupdate &&(Activeupdate.appversion! = Update.appversion | |Activeupdate.buildid!=Update.buildid)) {//We have a activeupdate (which presumably was interrupted), and is      //About start downloading a new one. Make sure we remove all traces      //Of the active one (otherwise we ll start appending the new Update.mar      //The one that's been partially downloaded).LOG ("updateservice:downloadupdate-removing stale active update."));    Cleanupactiveupdate (); }  }  //Set the previous application version prior to downloading the update.  update.previousappversion = Services.appinfo.version;  this. _downloader = new downloader (background, this);  return   This . _downloader.downloadupdate (update);},

2. Downloader.downloadupdate

Because the Downloadupdate function is longer, only part of the code is posted here

/* * * Download and stage the given update. * @param   Update *          */function  Dow Nloader_downloadupdate (update) {
...
Get Update save location
var updatedir = Getupdatesdir ();
...
According to the preset policy, return one of the updatepatch in the update to download the
This._patch = This._selectpatch (update, UPDATEDIR);
...

Only used by Gonk
let status = State_none;
if (Appconstants.platform = = "Gonk") {

...

Whether interrupted update is available before detection

}
...
Get the patch URL
  var uri = Services.io.newURI (this._patch. URL, NULL, NULL);
Create a nsiincrementaldownload component to download
This._request = cc["@mozilla. Org/network/incremental-download;1"]. CreateInstance (ci.nsiincrementaldownload);

LOG ("downloader:downloadupdate-downloading from" + Uri.spec + "to" + Patchfile.path);
var interval = This.background? Getpref ("Getintpref",
Pref_app_update_background_interval, Download_background_interval): Download_foreground_interval;
This._request.init (URI, Patchfile, download_chunk_size, interval);

This is passed because downloader implements the Nsirequest and Nsiprocesseventsink interfaces to enable callbacks for download completion, download progress, etc.
This._request.start (this, null);

Writestatusfile (Updatedir, state_downloading);
This._patch. QueryInterface (Ci.nsiwritablepropertybag);

This._patch.state = state_downloading;

Save the current download update via Updatemanager

var um = cc["@mozilla. Org/updates/update-manager;1"].getservice (Ci.nsiupdatemanager);
Um.saveupdates ();

return state_downloading;

}

3. Downloader.onstoprequest Download complete

The code is long and the key part is pasted

/** When data transfer ceases * @param request *, the Nsirequest object for the transfer * @param    Context * Additional data * @param status * Status code containing the reason for the cessation. */onstoprequest:functionDownloader_onstoprequest (Request, context, status) {//determine if the download was successful    if(components.issuccesscode (status)) {//Verifying the Update package      if( This . _verifydownload ())    {        ...      } } Else {        ...    } ...     This. _patch.state =State ;  //  Updatemanager Save status     varUm = cc["@mozilla. Org/updates/update-manager;1"].    GetService (Ci.nsiupdatemanager); if(deleteactiveupdate) { This. _update.installdate = (NewDate ()). GetTime (); Um.activeupdate=NULL; }    Else {      if(um.activeupdate) {um.activeUpdate.state=State ;    }} um.saveupdates (); ...    if(shouldshowprompt) {//Notify The user that a update has been downloaded and are ready for      //installation (i.e. that they should restart the application). We Do      //Not notify on failed update attempts.Let prompter = cc["@mozilla. Org/updates/update-prompt;1"].      CreateInstance (ci.nsiupdateprompt);  //  notification updateprompt,update Download complete prompter.showupdatedownloaded (this. _update, true< /c6>); }  }

(Ffos Gecko & Gaia) OTA-The real download

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.