首页 文章 精选 留言 我的

精选列表

搜索[代码生成],共10000篇文章
优秀的个人博客,低调大师

Android应用程序安装过程源代码分析(3)

Step 7.PackageManagerService.main 这个函数定义在frameworks/base/services/java/com/android/server/PackageManagerService.java文件中: [cpp] view plain copy classPackageManagerServiceextendsIPackageManager.Stub{ ...... publicstaticfinalIPackageManagermain(Contextcontext,booleanfactoryTest){ PackageManagerServicem=newPackageManagerService(context,factoryTest); ServiceManager.addService("package",m); returnm; } ...... } 这个函数创建了一个PackageManagerService服务实例,然后把这个服务添加到ServiceManager中去,ServiceManager是Android系统Binder进程间通信机制的守护进程,负责管理系统中的Binder对象,具体可以参考 浅谈Service Manager成为Android进程间通信(IPC)机制Binder守护进程之路 一文。 在创建这个PackageManagerService服务实例时,会在PackageManagerService类的构造函数中开始执行安装应用程序的过程: [java] view plain copy classPackageManagerServiceextendsIPackageManager.Stub{ ...... publicPackageManagerService(Contextcontext,booleanfactoryTest){ ...... synchronized(mInstallLock){ synchronized(mPackages){ ...... FiledataDir=Environment.getDataDirectory(); mAppDataDir=newFile(dataDir,"data"); mSecureAppDataDir=newFile(dataDir,"secure/data"); mDrmAppPrivateInstallDir=newFile(dataDir,"app-private"); ...... mFrameworkDir=newFile(Environment.getRootDirectory(),"framework"); mDalvikCacheDir=newFile(dataDir,"dalvik-cache"); ...... //Findbaseframeworks(resourcepackageswithoutcode). mFrameworkInstallObserver=newAppDirObserver( mFrameworkDir.getPath(),OBSERVER_EVENTS,true); mFrameworkInstallObserver.startWatching(); scanDirLI(mFrameworkDir,PackageParser.PARSE_IS_SYSTEM |PackageParser.PARSE_IS_SYSTEM_DIR, scanMode|SCAN_NO_DEX,0); //Collectallsystempackages. mSystemAppDir=newFile(Environment.getRootDirectory(),"app"); mSystemInstallObserver=newAppDirObserver( mSystemAppDir.getPath(),OBSERVER_EVENTS,true); mSystemInstallObserver.startWatching(); scanDirLI(mSystemAppDir,PackageParser.PARSE_IS_SYSTEM |PackageParser.PARSE_IS_SYSTEM_DIR,scanMode,0); //Collectallvendorpackages. mVendorAppDir=newFile("/vendor/app"); mVendorInstallObserver=newAppDirObserver( mVendorAppDir.getPath(),OBSERVER_EVENTS,true); mVendorInstallObserver.startWatching(); scanDirLI(mVendorAppDir,PackageParser.PARSE_IS_SYSTEM |PackageParser.PARSE_IS_SYSTEM_DIR,scanMode,0); mAppInstallObserver=newAppDirObserver( mAppInstallDir.getPath(),OBSERVER_EVENTS,false); mAppInstallObserver.startWatching(); scanDirLI(mAppInstallDir,0,scanMode,0); mDrmAppInstallObserver=newAppDirObserver( mDrmAppPrivateInstallDir.getPath(),OBSERVER_EVENTS,false); mDrmAppInstallObserver.startWatching(); scanDirLI(mDrmAppPrivateInstallDir,PackageParser.PARSE_FORWARD_LOCK, scanMode,0); ...... } } } ...... } 这里会调用scanDirLI函数来扫描移动设备上的下面这五个目录中的Apk文件 /system/framework /system/app /vendor/app /data/app /data/app-private Step 8.PackageManagerService.scanDirLI 这个函数定义在frameworks/base/services/java/com/android/server/PackageManagerService.java文件中: [java] view plain copy classPackageManagerServiceextendsIPackageManager.Stub{ ...... privatevoidscanDirLI(Filedir,intflags,intscanMode,longcurrentTime){ String[]files=dir.list(); ...... inti; for(i=0;i<files.length;i++){ Filefile=newFile(dir,files[i]); if(!isPackageFilename(files[i])){ //Ignoreentrieswhicharenotapk's continue; } PackageParser.Packagepkg=scanPackageLI(file, flags|PackageParser.PARSE_MUST_BE_APK,scanMode,currentTime); //Don'tmessaroundwithappsinsystempartition. if(pkg==null&&(flags&PackageParser.PARSE_IS_SYSTEM)==0&& mLastScanError==PackageManager.INSTALL_FAILED_INVALID_APK){ //Deletetheapk Slog.w(TAG,"Cleaningupfailedinstallof"+file); file.delete(); } } } ...... } 对于目录中的每一个文件,如果是以后Apk作为后缀名,那么就调用scanPackageLI函数来对它进行解析和安装。 Step 9.PackageManagerService.scanPackageLI 这个函数定义在frameworks/base/services/java/com/android/server/PackageManagerService.java文件中: [java] view plain copy classPackageManagerServiceextendsIPackageManager.Stub{ ...... privatePackageParser.PackagescanPackageLI(FilescanFile, intparseFlags,intscanMode,longcurrentTime){ ...... StringscanPath=scanFile.getPath(); parseFlags|=mDefParseFlags; PackageParserpp=newPackageParser(scanPath); ...... finalPackageParser.Packagepkg=pp.parsePackage(scanFile, scanPath,mMetrics,parseFlags); ...... returnscanPackageLI(pkg,parseFlags,scanMode|SCAN_UPDATE_SIGNATURE,currentTime); } ...... } 这个函数首先会为这个Apk文件创建一个PackageParser实例,接着调用这个实例的parsePackage函数来对这个Apk文件进行解析。这个函数最后还会调用另外一个版本的scanPackageLI函数把来解析后得到的应用程序信息保存在PackageManagerService中。 本文转自 Luoshengyang 51CTO博客,原文链接:http://blog.51cto.com/shyluo/966522,如需转载请自行联系原作者

优秀的个人博客,低调大师

OpenStack nova-network 支持多vlan技术实现片段代码

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 #-*-encoding:utf-8-*- # #Copyright2012RedHat,Inc # #Author:EoghanGlynn<eglynn@redhat.com> # #LicensedundertheApacheLicense,Version2.0(the"License");youmay #notusethisfileexceptincompliancewiththeLicense.Youmayobtain #acopyoftheLicenseat # #http://www.apache.org/licenses/LICENSE-2.0 # #Unlessrequiredbyapplicablelaworagreedtoinwriting,software #distributedundertheLicenseisdistributedonan"ASIS"BASIS,WITHOUT #WARRANTIESORCONDITIONSOFANYKIND,eitherexpressorimplied.Seethe #Licenseforthespecificlanguagegoverningpermissionsandlimitations #undertheLicense. """ImplementationofInspectorabstractionforlibvirt.""" import libvirt import os,sys,time import traceback from lxml import etree from oslo.config import cfg from nova.openstack.common import logaslogging from nova import utils libvirt = None LOG = logging.getLogger(__name__) libvirt_opts = [ cfg.StrOpt( 'libvirt_type' , default = 'kvm' , help = 'Libvirtdomaintype(validoptionsare:' 'kvm,lxc,qemu,uml,xen)' ), cfg.StrOpt( 'libvirt_uri' , default = '', help = 'OverridethedefaultlibvirtURI' '(whichisdependentonlibvirt_type)' ), cfg.StrOpt( 'network_script_path' , default = '/etc/sysconfig/network-scripts/' , help = 'Centos6.6systemnetworkconfigpath' ), ] CONF = cfg.CONF CONF.register_opts(libvirt_opts) class LibvirtNetwork( object ): per_type_uris = dict (uml = 'uml:///system' ,xen = 'xen:///' ,lxc = 'lxc:///' ) def __init__( self ): self .uri = self ._get_uri() self .connection = None def _get_uri( self ): return CONF.libvirt_uri or self .per_type_uris.get(CONF.libvirt_type, 'qemu:///system' ) def _get_connection( self ): if not self .connection or not self ._test_connection(): global libvirt if libvirt is None : libvirt = __import__ ( 'libvirt' ) LOG.debug( 'Connectingtolibvirt:%s' , self .uri) self .connection = libvirt.openReadOnly( self .uri) return self .connection def _test_connection( self ): try : self .connection.getCapabilities() return True except libvirt.libvirtErrorase: print '*' * 100 if (e.get_error_code() = = libvirt.VIR_ERR_SYSTEM_ERROR and e.get_error_domain() in (libvirt.VIR_FROM_REMOTE, libvirt.VIR_FROM_RPC)): LOG.debug( 'Connectiontolibvirtbroke' ) return False raise def _lookup_by_name( self ,instance_name): try : return self ._get_connection().lookupByName(instance_name) except Exceptionasex: if not libvirt or not isinstance (ex,libvirt.libvirtError): LOG.error(ex) error_code = ex.get_error_code() msg = ( "Errorfromlibvirtwhilelookingup%(instance_name)s:" "[ErrorCode%(error_code)s]" "%(ex)s" % { 'instance_name' :instance_name, 'error_code' :error_code, 'ex' :ex}) LOG.error(msg) def get_vnic_name( self ,instance_name): domain = self ._lookup_by_name(instance_name) tree = etree.fromstring(domain.XMLDesc( 0 )) for iface in tree.findall( 'devices/interface' ): target = iface.find( 'target' ) if target is not None : vnic_name = target.get( 'dev' ) else : continue mac = iface.find( 'mac' ) if mac is not None : mac_address = mac.get( 'address' ) else : continue fref = iface.find( 'filterref' ) if fref is not None : fref = fref.get( 'filter' ) return vnic_name #Addwilliam,Bridgesupportsmultiplevlantechnology def bridge_multiple_vlan( self ,instance): network_info = dict () try : new_source_dev = instance[ 'hostname' ].split( '.' )[ - 1 ] if not new_source_dev: new_source_dev = 'br100' if 'vlan' not in new_source_dev: new_source_dev = 'br100' network_info[ 'vlan_name' ] = new_source_dev network_info[ 'instances_name' ] = instance[ 'name' ] #network_info['vnet_name']=self.get_vnic_name(instance['name']) network_info[ 'bond_name' ] = os.listdir( '/proc/net/bonding' )[ 0 ] network_info[ 'bond_dev' ] = '%s.%s' % (network_info[ 'bond_name' ],new_source_dev.split( 'vlan' )[ - 1 ]) network_info[ 'vlan_id' ] = new_source_dev.split( 'vlan' )[ - 1 ] check_result = self .check_bridge_vlan(network_info[ 'vlan_name' ],network_info[ 'bond_dev' ]) if not check_result: self .add_bridge_vlan(network_info) else : LOG.info( "Addwilliam,%sisexists,soisnotcreate" % network_info[ 'vlan_name' ]) except : LOG.error(traceback.format_exc()) def add_bridge_vlan( self ,network_info): utils.execute( "vconfig" , "add" ,network_info[ 'bond_name' ],network_info[ 'vlan_id' ],run_as_root = True ) LOG.info( "Addwilliam,utils.exeuctevconfigadd%s%s" % (network_info[ 'bond_name' ],network_info[ 'vlan_id' ])) utils.execute( "ifconfig" ,network_info[ 'bond_dev' ], "up" ,run_as_root = True ) LOG.info( "Addwilliam,utils.executeifconfig%sup" % (network_info[ 'bond_dev' ])) utils.execute( "brctl" , "addbr" ,network_info[ 'vlan_name' ],run_as_root = True ) LOG.info( "Addwilliam,utils.executebrctladdbr%s" % (network_info[ 'vlan_name' ])) utils.execute( "brctl" , "addif" ,network_info[ 'vlan_name' ],network_info[ 'bond_dev' ],run_as_root = True ) LOG.info( "Addwilliam,utils.executebrctladdif%s%s" % (network_info[ 'vlan_name' ],network_info[ 'bond_dev' ])) utils.execute( "ifconfig" ,network_info[ 'vlan_name' ], "up" ,run_as_root = True ) LOG.info("") #utils.execute("brctl","addif",network_info['vlan_name'],network_info['vnet_name'],run_as_root=True) bond_script = "%s/ifcfg-%s" % (CONF.network_script_path,network_info[ 'bond_dev' ]) vlan_script = "%s/ifcfg-%s" % (CONF.network_script_path,network_info[ 'vlan_name' ]) utils.execute( "chmod" , "777" ,CONF.network_script_path,run_as_root = True ) fp = open (bond_script, 'w' ) fp.write( "DEVICE=%s\n" % network_info[ 'bond_dev' ]) fp.write( "ONBOOT=yes\n" ) fp.write( "NM_CONTROLLED=no\n" ) fp.write( "BOOTPROTO=static\n" ) fp.write( "VLAN=yes\n" ) fp.close() fp = open (vlan_script, 'w' ) fp.write( "DEVICE=%s\n" % network_info[ 'vlan_name' ]) fp.write( "BOOTPROTO=static\n" ) fp.write( "ONBOOT=yes\n" ) fp.write( "TYPE=Bridge\n" ) fp.close() utils.execute( "chmod" , "755" ,CONF.network_script_path,run_as_root = True ) def check_bridge_vlan( self ,vlan_dev,bond_dev): vlan_list = bond_list = list () vlan = bond = False vlan_info = os.popen( "brctlshow|grepvlan|awk'{print$1}'" ).readlines() for i in vlan_info: vlan_list.append(i.strip()) bond_info = os.popen( "ifconfig|grepbond0|awk'{print$1}'" ).readlines() for i in bond_info: bond_list.append(i.strip()) if vlan_dev in vlan_list: vlan = True if bond_dev in bond_list: bond = True if vlan and bond: return True else : return False if __name__ = = "__main__" : instance = {u 'vm_state' :u 'building' ,u 'internal_id' : None ,u 'availability_zone' :u 'nova' ,u 'terminated_at' : None ,u 'ephemeral_gb' : 100 ,u 'instance_type_id' : 26 ,u 'user_data' : None ,u 'cleaned' : 0 ,u 'vm_mode' : None ,u 'deleted_at' : None ,u 'reservation_id' :u 'r-z2zsdcvl' ,u 'id' : 299 ,u 'security_groups' :[{u 'project_id' :u '50fd5d79ab184c399cdc22da78b8a7bc' ,u 'user_id' :u '373ddabe004846ebba268d7e88d13e16' ,u 'name' :u 'default' ,u 'deleted' : 0 ,u 'created_at' :u '2014-09-30T07:49:38.000000' ,u 'updated_at' : None ,u 'rules' :[],u 'deleted_at' : None ,u 'id' : 1 ,u 'description' :u 'default' }],u 'disable_terminate' : False ,u 'root_device_name' :u '/dev/vda' ,u 'user_id' :u '373ddabe004846ebba268d7e88d13e16' ,u 'uuid' :u 'c4cf7bc1-72bd-4523-bab0-fdd0f837fb46' ,u 'default_swap_device' : None ,u 'info_cache' :{u 'instance_uuid' :u 'c4cf7bc1-72bd-4523-bab0-fdd0f837fb46' ,u 'deleted' : 0 ,u 'created_at' :u '2015-04-16T03:36:51.000000' ,u 'updated_at' :u '2015-04-16T03:36:52.000000' ,u 'network_info' :u '[{"ovs_interfaceid":null,"network":{"bridge":"br100","subnets":[{"ips":[{"meta":{},"version":4,"type":"fixed","floating_ips":[],"address":"192.168.221.164"}],"version":4,"meta":{"dhcp_server":"192.168.221.11"},"dns":[{"meta":{},"version":4,"type":"dns","address":"192.168.252.25"},{"meta":{},"version":4,"type":"dns","address":"192.168.252.24"}],"routes":[],"cidr":"192.168.220.0/19","gateway":{"meta":{},"version":4,"type":"gateway","address":"192.168.192.1"}},{"ips":[],"version":null,"meta":{"dhcp_server":"192.168.221.11"},"dns":[],"routes":[],"cidr":null,"gateway":{"meta":{},"version":null,"type":"gateway","address":null}}],"meta":{"tenant_id":"50fd5d79ab184c399cdc22da78b8a7bc","multi_host":true,"should_create_bridge":true,"should_create_vlan":true,"bridge_interface":"bond0"},"id":"4a8546f2-3919-445a-9f87-b938491d41a5","label":"publics"},"devname":null,"qbh_params":null,"meta":{},"address":"fa:16:3e:c5:be:93","type":"bridge","id":"a7a69211-6aeb-4b54-9a20-803b96df73bf","qbg_params":null}]' ,u 'deleted_at' : None ,u 'id' : 299 },u 'hostname' :u 'gg-esc-web.vlan203' ,u 'launched_on' :u 'localhost' ,u 'display_description' :u 'gg-esc-web.vlan201' ,u 'key_data' : None ,u 'deleted' : 0 ,u 'scheduled_at' :u '2015-04-16T03:36:51.000000' ,u 'power_state' : 0 ,u 'default_ephemeral_device' : None ,u 'progress' : 0 ,u 'project_id' :u '50fd5d79ab184c399cdc22da78b8a7bc' ,u 'launched_at' : None ,u 'config_drive' :u' ',u' node ':u' localhost ',u' ramdisk_id ':u' ',u' access_ip_v6 ':None,u' access_ip_v4 ':None,u' kernel_id ':u' ',u' key_name ':None,u' updated_at ':u' 2015 - 04 - 16T03 : 36 : 52.727467 ',u' host ':u' localhost ',u' display_name ':u' gg - esc - web.vlan201 ',u' system_metadata ':[{u' instance_uuid ':u' c4cf7bc1 - 72bd - 4523 - bab0 - fdd0f837fb46 ',u' deleted ':0,u' created_at ':u' 2015 - 04 - 16T03 : 36 : 51.000000 ',u' updated_at ':None,u' value ':u' windows ',u' key ':u' image_os_type ',u' deleted_at ':None,u' id ':4889},{u' instance_uuid ':u' c4cf7bc1 - 72bd - 4523 - bab0 - fdd0f837fb46 ',u' deleted ':0,u' created_at ':u' 2015 - 04 - 16T03 : 36 : 51.000000 ',u' updated_at ':None,u' value ':u' 8192 ',u' key ':u' instance_type_memory_mb ',u' deleted_at ':None,u' id ':4890},{u' instance_uuid ':u' c4cf7bc1 - 72bd - 4523 - bab0 - fdd0f837fb46 ',u' deleted ':0,u' created_at ':u' 2015 - 04 - 16T03 : 36 : 51.000000 ',u' updated_at ':None,u' value ':u' 0 ',u' key ':u' instance_type_swap ',u' deleted_at ':None,u' id ':4891},{u' instance_uuid ':u' c4cf7bc1 - 72bd - 4523 - bab0 - fdd0f837fb46 ',u' deleted ':0,u' created_at ':u' 2015 - 04 - 16T03 : 36 : 51.000000 ',u' updated_at ':None,u' value ':None,u' key ':u' instance_type_vcpu_weight ',u' deleted_at ':None,u' id ':4892},{u' instance_uuid ':u' c4cf7bc1 - 72bd - 4523 - bab0 - fdd0f837fb46 ',u' deleted ':0,u' created_at ':u' 2015 - 04 - 16T03 : 36 : 51.000000 ',u' updated_at ':None,u' value ':u' 60 ',u' key ':u' instance_type_root_gb ',u' deleted_at ':None,u' id ':4893},{u' instance_uuid ':u' c4cf7bc1 - 72bd - 4523 - bab0 - fdd0f837fb46 ',u' deleted ':0,u' created_at ':u' 2015 - 04 - 16T03 : 36 : 51.000000 ',u' updated_at ':None,u' value ':u' 26 ',u' key ':u' instance_type_id ',u' deleted_at ':None,u' id ':4894},{u' instance_uuid ':u' c4cf7bc1 - 72bd - 4523 - bab0 - fdd0f837fb46 ',u' deleted ':0,u' created_at ':u' 2015 - 04 - 16T03 : 36 : 51.000000 ',u' updated_at ':None,u' value ':u' windows - 16 - 8G - 100G ',u' key ':u' instance_type_name ',u' deleted_at ':None,u' id ':4895},{u' instance_uuid ':u' c4cf7bc1 - 72bd - 4523 - bab0 - fdd0f837fb46 ',u' deleted ':0,u' created_at ':u' 2015 - 04 - 16T03 : 36 : 51.000000 ',u' updated_at ':None,u' value ':u' 100 ',u' key ':u' instance_type_ephemeral_gb ',u' deleted_at ':None,u' id ':4896},{u' instance_uuid ':u' c4cf7bc1 - 72bd - 4523 - bab0 - fdd0f837fb46 ',u' deleted ':0,u' created_at ':u' 2015 - 04 - 16T03 : 36 : 51.000000 ',u' updated_at ':None,u' value ':u' 1 ',u' key ':u' instance_type_rxtx_factor ',u' deleted_at ':None,u' id ':4897},{u' instance_uuid ':u' c4cf7bc1 - 72bd - 4523 - bab0 - fdd0f837fb46 ',u' deleted ':0,u' created_at ':u' 2015 - 04 - 16T03 : 36 : 51.000000 ',u' updated_at ':None,u' value ':u' qcow2 ',u' key ':u' image_disk_format ',u' deleted_at ':None,u' id ':4898},{u' instance_uuid ':u' c4cf7bc1 - 72bd - 4523 - bab0 - fdd0f837fb46 ',u' deleted ':0,u' created_at ':u' 2015 - 04 - 16T03 : 36 : 51.000000 ',u' updated_at ':None,u' value ':u' 74c9f78a - 06d6 - 432d - 8051 - 4eeecf8ebff7 ',u' key ':u' instance_type_flavorid ',u' deleted_at ':None,u' id ':4899},{u' instance_uuid ':u' c4cf7bc1 - 72bd - 4523 - bab0 - fdd0f837fb46 ',u' deleted ':0,u' created_at ':u' 2015 - 04 - 16T03 : 36 : 51.000000 ',u' updated_at ':None,u' value ':u' ovf ',u' key ':u' image_container_format ',u' deleted_at ':None,u' id ':4900},{u' instance_uuid ':u' c4cf7bc1 - 72bd - 4523 - bab0 - fdd0f837fb46 ',u' deleted ':0,u' created_at ':u' 2015 - 04 - 16T03 : 36 : 51.000000 ',u' updated_at ':None,u' value ':u' 16 ',u' key ':u' instance_type_vcpus ',u' deleted_at ':None,u' id ':4901},{u' instance_uuid ':u' c4cf7bc1 - 72bd - 4523 - bab0 - fdd0f837fb46 ',u' deleted ':0,u' created_at ':u' 2015 - 04 - 16T03 : 36 : 51.000000 ',u' updated_at ':None,u' value ':u' 0 ',u' key ':u' image_min_ram ',u' deleted_at ':None,u' id ':4902},{u' instance_uuid ':u' c4cf7bc1 - 72bd - 4523 - bab0 - fdd0f837fb46 ',u' deleted ':0,u' created_at ':u' 2015 - 04 - 16T03 : 36 : 51.000000 ',u' updated_at ':None,u' value ':u' 60 ',u' key ':u' image_min_disk ',u' deleted_at ':None,u' id ':4903},{u' instance_uuid ':u' c4cf7bc1 - 72bd - 4523 - bab0 - fdd0f837fb46 ',u' deleted ':0,u' created_at ':u' 2015 - 04 - 16T03 : 36 : 51.000000 ',u' updated_at ':None,u' value ':u' 406c0425 - b8d3 - 4607 - beff - 8fa529b46b7a ',u' key ':u' image_base_image_ref ',u' deleted_at ':None,u' id ':4904}],u' task_state ':u' spawning ',u' shutdown_terminate ':False,u' cell_name ':None,u' root_gb ':60,u' locked ':False,u' name ':u' instance - 0000012b ',u' created_at ':u' 2015 - 04 - 16T03 : 36 : 51.000000 ',u' locked_by ':None,u' launch_index ':0,u' memory_mb ':8192,u' vcpus ':16,u' image_ref ':u' 406c0425 - b8d3 - 4607 - beff - 8fa529b46b7a ',u' architecture ':None,u' auto_disk_config ':False,u' os_type ':u' windows ',u' metadata':[]} sc = LibvirtNetwork() sc.bridge_multiple_vlan(instance) 本文转自 swq499809608 51CTO博客,原文链接:http://blog.51cto.com/swq499809608/1633811

优秀的个人博客,低调大师

Android应用程序启动过程源代码分析(5)

Step 35. MainActivity.onCreate 这个函数定义在packages/experimental/Activity/src/shy/luo/activity/MainActivity.java文件中,这是我们自定义的app工程文件: publicclassMainActivityextendsActivityimplementsOnClickListener{ ...... @Override publicvoidonCreate(BundlesavedInstanceState){ ...... Log.i(LOG_TAG,"MainActivityCreated."); } ...... } 这样,MainActivity就启动起来了,整个应用程序也启动起来了。 整个应用程序的启动过程要执行很多步骤,但是整体来看,主要分为以下五个阶段: 一. Step1 - Step 11:Launcher通过Binder进程间通信机制通知ActivityManagerService,它要启动一个Activity; 二. Step 12 - Step 16:ActivityManagerService通过Binder进程间通信机制通知Launcher进入Paused状态; 三. Step 17 - Step 24:Launcher通过Binder进程间通信机制通知ActivityManagerService,它已经准备就绪进入Paused状态,于是ActivityManagerService就创建一个新的进程,用来启动一个ActivityThread实例,即将要启动的Activity就是在这个ActivityThread实例中运行; 四. Step 25 - Step 27:ActivityThread通过Binder进程间通信机制将一个ApplicationThread类型的Binder对象传递给ActivityManagerService,以便以后ActivityManagerService能够通过这个Binder对象和它进行通信; 五. Step 28 - Step 35:ActivityManagerService通过Binder进程间通信机制通知ActivityThread,现在一切准备就绪,它可以真正执行Activity的启动操作了。 这里不少地方涉及到了Binder进程间通信机制,相关资料请参考Android进程间通信(IPC)机制Binder简要介绍和学习计划一文。 这样,应用程序的启动过程就介绍完了,它实质上是启动应用程序的默认Activity,在下一篇文章中,我们将介绍在应用程序内部启动另一个Activity的过程,即新的Activity与启动它的Activity将会在同一个进程(Process)和任务(Task)运行,敬请关注。 本文转自 Luoshengyang 51CTO博客,原文链接:http://blog.51cto.com/shyluo/965993,如需转载请自行联系原作者

优秀的个人博客,低调大师

Android应用程序安装过程源代码分析(4)

Step 12.PackageManagerService.scanPackageLI 这个函数定义在frameworks/base/services/java/com/android/server/PackageManagerService.java文件中: [java] view plain copy classPackageManagerServiceextendsIPackageManager.Stub{ ...... //KeysareString(packagename),valuesarePackage.Thisalsoserves //asthelockfortheglobalstate.Methodsthatmustbecalledwith //thislockheldhavetheprefix"LP". finalHashMap<String,PackageParser.Package>mPackages= newHashMap<String,PackageParser.Package>(); ...... //Allavailableactivities,foryourresolvingpleasure. finalActivityIntentResolvermActivities= newActivityIntentResolver(); //Allavailablereceivers,foryourresolvingpleasure. finalActivityIntentResolvermReceivers= newActivityIntentResolver(); //Allavailableservices,foryourresolvingpleasure. finalServiceIntentResolvermServices=newServiceIntentResolver(); //KeysareString(providerclassname),valuesareProvider. finalHashMap<ComponentName,PackageParser.Provider>mProvidersByComponent= newHashMap<ComponentName,PackageParser.Provider>(); ...... privatePackageParser.PackagescanPackageLI(PackageParser.Packagepkg, intparseFlags,intscanMode,longcurrentTime){ ...... synchronized(mPackages){ ...... //AddthenewsettingtomPackages mPackages.put(pkg.applicationInfo.packageName,pkg); ...... intN=pkg.providers.size(); inti; for(i=0;i<N;i++){ PackageParser.Providerp=pkg.providers.get(i); p.info.processName=fixProcessName(pkg.applicationInfo.processName, p.info.processName,pkg.applicationInfo.uid); mProvidersByComponent.put(newComponentName(p.info.packageName, p.info.name),p); ...... } N=pkg.services.size(); for(i=0;i<N;i++){ PackageParser.Services=pkg.services.get(i); s.info.processName=fixProcessName(pkg.applicationInfo.processName, s.info.processName,pkg.applicationInfo.uid); mServices.addService(s); ...... } N=pkg.receivers.size(); r=null; for(i=0;i<N;i++){ PackageParser.Activitya=pkg.receivers.get(i); a.info.processName=fixProcessName(pkg.applicationInfo.processName, a.info.processName,pkg.applicationInfo.uid); mReceivers.addActivity(a,"receiver"); ...... } N=pkg.activities.size(); for(i=0;i<N;i++){ PackageParser.Activitya=pkg.activities.get(i); a.info.processName=fixProcessName(pkg.applicationInfo.processName, a.info.processName,pkg.applicationInfo.uid); mActivities.addActivity(a,"activity"); ...... } ...... } ...... returnpkg; } ...... } 这个函数主要就是把前面解析应用程序得到的package、provider、service、receiver和activity等信息保存在PackageManagerService服务中了。 这样,在Android系统启动的时候安装应用程序的过程就介绍完了,但是,这些应用程序只是相当于在PackageManagerService服务注册好了,如果我们想要在Android桌面上看到这些应用程序,还需要有一个Home应用程序,负责从PackageManagerService服务中把这些安装好的应用程序取出来,并以友好的方式在桌面上展现出来,例如以快捷图标的形式。在Android系统中,负责把系统中已经安装的应用程序在桌面中展现出来的Home应用程序就是Launcher了,在下一篇文章中,我们将介绍Launcher是如何启动的以及它是如何从PackageManagerService服务中把系统中已经安装好的应用程序展现出来的,敬请期待。 本文转自 Luoshengyang 51CTO博客,原文链接:http://blog.51cto.com/shyluo/966524,如需转载请自行联系原作者

优秀的个人博客,低调大师

Android应用程序安装过程源代码分析(2)

Step 4. AndroidRuntime.callStatic 这个函数定义在frameworks/base/core/jni/AndroidRuntime.cpp文件中: [cpp] view plain copy /* *CallastaticJavaProgrammingLanguagefunctionthattakesnoargumentsandreturnsvoid. */ status_tAndroidRuntime::callStatic(constchar*className,constchar*methodName) { JNIEnv*env; jclassclazz; jmethodIDmethodId; env=getJNIEnv(); if(env==NULL) returnUNKNOWN_ERROR; clazz=findClass(env,className); if(clazz==NULL){ LOGE("ERROR:couldnotfindclass'%s'\n",className); returnUNKNOWN_ERROR; } methodId=env->GetStaticMethodID(clazz,methodName,"()V"); if(methodId==NULL){ LOGE("ERROR:couldnotfindmethod%s.%s\n",className,methodName); returnUNKNOWN_ERROR; } env->CallStaticVoidMethod(clazz,methodId); returnNO_ERROR; } 这个函数调用由参数className指定的java类的静态成员函数,这个静态成员函数是由参数methodName指定的。上面传进来的参数className的值为"com/android/server/SystemServer",而参数methodName的值为"init2",因此,接下来就会调用SystemServer类的init2函数了。 Step 5.SystemServer.init2 这个函数定义在frameworks/base/services/java/com/android/server/SystemServer.java文件中: [java] view plain copy publicclassSystemServer { ...... publicstaticfinalvoidinit2(){ Slog.i(TAG,"EnteredtheAndroidsystemserver!"); Threadthr=newServerThread(); thr.setName("android.server.ServerThread"); thr.start(); } } 这个函数创建了一个ServerThread线程,PackageManagerService服务就是这个线程中启动的了。这里调用了ServerThread实例thr的start函数之后,下面就会执行这个实例的run函数了。 Step 6.ServerThread.run 这个函数定义在frameworks/base/services/java/com/android/server/SystemServer.java文件中: [java] view plain copy classServerThreadextendsThread{ ...... @Override publicvoidrun(){ ...... IPackageManagerpm=null; ...... //Criticalservices... try{ ...... Slog.i(TAG,"PackageManager"); pm=PackageManagerService.main(context, factoryTest!=SystemServer.FACTORY_TEST_OFF); ...... }catch(RuntimeExceptione){ Slog.e("System","Failurestartingcoreservice",e); } ...... } ...... } 这个函数除了启动PackageManagerService服务之外,还启动了其它很多的服务,例如在前面学习Activity和Service的几篇文章中经常看到的ActivityManagerService服务,有兴趣的读者可以自己研究一下。 本文转自 Luoshengyang 51CTO博客,原文链接:http://blog.51cto.com/shyluo/966521,如需转载请自行联系原作者

资源下载

更多资源
腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册