說(shuō)明原理分析scopedstorage_第1頁(yè)
說(shuō)明原理分析scopedstorage_第2頁(yè)
說(shuō)明原理分析scopedstorage_第3頁(yè)
說(shuō)明原理分析scopedstorage_第4頁(yè)
說(shuō)明原理分析scopedstorage_第5頁(yè)
已閱讀5頁(yè),還剩28頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

ScopedStorageScopedStorageAndroidQScopedStorageScopedStorageAndroidQAndroid版本中,APPScopedStorageApp-specificAPPspecific中,APP無(wú)需任何權(quán)限即可讀寫,而在公共目錄中,APPMediaStoreSAF也就是說(shuō),AndroidQAPPApp-specific而在外部存儲(chǔ)的其他空間上,APP讀寫是被更加嚴(yán)格地限制的,具體來(lái)說(shuō),APP需要申請(qǐng)app做限制)。ScopedStorage1.2.3.SAF4.MediaProviderAPPAndroidManifest.xmlandroid:requestLegacyExternalStorage=”truefalse”來(lái)設(shè)定APP外部存儲(chǔ)視圖模式。新屬性在PackageParser.java里被解析并添加到PermissionPolicyServicePermissionPolicyServiceApplicationInfoAPPAppPermissionPolicyService.onStartUser開(kāi)始,包括/APPAPP申請(qǐng)了AppOpsManager.OP_LEGACY_STORAGEAPPappopAPPlegacyviewAPKappopmountAPKAPPAPPgroupidmountmodegids包括從packagemanager獲取的應(yīng)用的permGids,和一些補(bǔ)充gids,其中參數(shù)mountExtStorageFull默認(rèn)是false,所以mountmode由StorageManagerServiceENABLE_ISOLATED_STORAGEisolatedstorageENABLE_ISOLATED_STORAGEisolatedstoragescopedstorage特性開(kāi)關(guān)是否打開(kāi)了,有兩個(gè):PRO_ISOLATED_STORAGE_SNAPTSHOT(高優(yōu)先級(jí))AndroidQBeta4mountmodegetMountMode->1.Isolatedprocess(uid:99000-999991.Isolatedprocess(uid:99000-9999990000-98999),MOUNT_EXTERNAL_NONE3.APPREAD_EXTERNAL_STORAGE/WRITE_EXTERNAL_STORAGE分別對(duì)應(yīng)于WRITE_MEDIA_STORAGE權(quán)限對(duì)應(yīng)hasFull,從字面意義上就表示了全部權(quán)限。User-launchable的應(yīng)用不允許申請(qǐng)?jiān)摍?quán)限。 對(duì)應(yīng)hasLegacy。它正是之前分析的當(dāng) 時(shí): 對(duì)應(yīng)MOUNT_EXTERNAL_WRITE, 對(duì)MOUNT_EXTERNAL_READlegacyview模式時(shí),MOUNT_EXTERNAL_DEFAULT。MountmodeNONE:APPmountspecificFULL:READ:gidsmountmode之后,processListzygotefork(->(->->->通過(guò)程Beta3mountdisable了,Beta4mounttargetBeta3mountdisable了,Beta4mounttargetAndroidPAPPsandbox(specificdirs)->->->->1.isolatedstorage模式,userstartAPPuser2.APPuserAPPappIdsandboxId3.volumevolumevisibleVolLabels->1.volumevolumeRoot=(->1.volumevolumeRoot=(primaryvolumeuserId:volumeRoot(primaryvolume然后新建文件夾:sandboxRoot2.sandbox2.1mntTargetRoot2.2volume新建primaryvolume2.3mntTargetRoot2.3mntTargetRoot3.rootName=mntFullSb=mntWriteSb=obbMountDir=循環(huán)/procpackagepidName=調(diào)用 獲取mountMode。對(duì)于 /mnt/runtime/write/<volumeLabel>[/userId]/Android/sandbox/<sandboxId>bind /mnt/runtime/write/<volumeLabel>[/userId]/Android/obbbindmount/storage/<volumeLabel>[/userId]/Android/obb(對(duì)于mountmodeapksandbox(specificdirs)packagesapkapksdVolumeManagersandbox(specificdirs)2.VolumeManagersandbox(specificdirs)2.filepathFileFileOutputStream/InputStreamFileOutputStream.FileOutputStream(Filefile,booleanappend)(構(gòu)造函數(shù)IoBridge.open(Stringpath,intflags)(fd,flagO_WRONLY|O_CREAT|O_APPENDflag來(lái)確定需要檢查的權(quán)限BlockGuardOs.open(Stringpath,intflags,intmode)(mode僅在創(chuàng)建文件時(shí)使用Linux.open(Stringpath,intflags,intmode)(native方法->open(path.c_str(),flags,APPspecifcdirs/mnt/runtime/write/<volumeLabel>/[/userId]/Android/(data/media/obb)/packagebindAPPspecificdirs(T卡)APP進(jìn)程的過(guò)程中,可以看到將/mnt/runtime/<mountmode>bindmount到/storagemountmodeAPPmountmodewrite,那么APP可以直接使用路徑對(duì)文件進(jìn)行讀寫,例如legacy視圖模式且申請(qǐng)了WRITE_EXTERNAL_STORAGEmountmodefullAPP對(duì)所有外部存儲(chǔ)APPmountmode3SAFSAFSystemAccessFramework。APPSAF選擇文件、選擇目錄、創(chuàng)建文件,SAFUriAPP。APPUriUriAPP。APPUriSAF1.DocumentsProviderContentProviderMtpDocumentsProvider、MediaDocumentsProvider、ExternalStorageProvider2.文檔選取器是客戶端程序與文檔提供程序之間的橋梁。因?yàn)槲臋n需要受到保護(hù),DocumentsProviderread/writepermissionMANAGE_DOCUMETS,而這個(gè)權(quán)限的等級(jí)是signatureDocumentsProviderUriDocumentUI的picker部分。APPintentDocumentUIPickActivity,DocumentUI向用戶展示有層DocumentUIAPPuripermissionAndroid4.3ACTION_PICKACTION_GET_CONTENTUIAndroid4.4及更高版本,使用ACTION_OPEN_DOCUMENT可以調(diào)起系統(tǒng)提供的選擇器注意:CTSMANAGE_DOCUMENTSpackagevendorAPP是想讀取/ACTION_GET_CONTENT,使用此方法時(shí),APP會(huì)導(dǎo)入數(shù)據(jù)的副APPAPPDocumentsProvider3.1DocumentsProviderAPPDocumentsProvider3.1DocumentsProvider1.一個(gè)DocumentsProvider可以提供多棵文件樹(shù),每棵樹(shù)都定義了一個(gè)rootCOLUMN_ROOT_ID標(biāo)記。rootCOLUMN_DOCUMENT_ID標(biāo)記。root表征COLUMN_DOCUMENT_IDURI2.COLUMN_FLAGS下文檔的元數(shù)據(jù),其中的COLUMN_FLAGS就展示了這個(gè)Uri支持的操作,例如有3.COLUMN_DOCUMENT_ID4.permission必須是MANAGE_DOCUMENT,否則系統(tǒng)文檔選擇器無(wú)法使用定義的enableAPIenableAPItrue/falseAndroid4.3falseAPPACTION_GET_CONTENTpickeractivity,那么需要在運(yùn)行設(shè)備Android4.4ACTION_GET_CONTENT這個(gè)過(guò)濾器。否則系統(tǒng)文檔選擇器打開(kāi)時(shí),APP會(huì)有兩個(gè)入口。Intent-filterDOCUMENT_PROVIDERactioncontentproviderSAFdocumentprovider,系統(tǒng)的文檔選擇器選擇文檔數(shù)據(jù)源時(shí),就是用這個(gè)action來(lái)匹配documentproviderDocumentsProvider1)queryRoots(String[]rootrootdocument才會(huì)出現(xiàn)在系統(tǒng)文檔選擇器的第三方欄目中。root的metadata被定義在合約類documentidprojection表示調(diào)用方想要返回的字段集合。rootnotifyChangerooturirootnotifyChangerooturirootUrirootUri2)queryChildDocuments(StringparentDocumentId,String[]projection,String返回指定目錄下的子目錄和文檔,不遞歸。parentDocumentId是指定目錄documentprojection是想要返回的字段集合,sortOrderTargetSDK26(O)APPqueryChildDocuments(String,String[],Bundle)APP如果想要監(jiān)聽(tīng)某個(gè)目錄下所有子目錄/UriDocumentsProvidernotifyChangeUri3)DocumentsProvidernotifyChangeUri3)queryDocument(StringdocumentId,String[]返回指定文件的metadata。 DocumentsContract.Document 4)openDocument(StringdocumentId,Stringmode,CancellationSignalParcelFileDescriptor。mode是打開(kāi)文件的模式,”r”4DocumentsProvider4DocumentsProvider如queryRecentDocuments(如果DocumentsProvider返回的root定義了件搜索,如果支持就需要實(shí)現(xiàn)這個(gè)方法,queryArgs決定)3.2DocumentUIAPP中。DocumentUIpackage主要有兩個(gè):filespicker。files對(duì)應(yīng)了文件管理器,提供了文件管理的UI,用戶可以查看、操作所有pickActivityrootroot下具體的文件/1.性復(fù)制大量文件的情況;DocumentClipperAPP內(nèi)復(fù)制剪切操作的類。其中最重要ProvidersCacheDocumentsProvider。2.-mProviders:-mThumbnailCache:-mClipStore:-mClipper:-mDragAndDropManager:-mFileTypeLookup:Lookup<String,DocumentsApplicationonCreateDocumentsApplicationonCreateProvidersCacheUpdateTaskDocumentsProvider并緩存從它們中查詢到的rootStoppedpackage里的DocumentsProviderDocumentUIAPPUIProvidersCache3.PickActivityPickActivityUIInjector<Textends-mObserver:(監(jiān)聽(tīng)所有的DocumentsProvider的roots變化-mRecentRoots:-mRoots:Multimap<String,(保存所有authority和root的對(duì)應(yīng)關(guān)系-mStoppedAuthorities:-mObservedAuthoritiesDetails:Map<String,PackageDetails>loadRootsForAuthority:檢查exported、grantUriPermissions、添加PackageDetails到構(gòu)建rootsUri(content://<authority>/root),并注冊(cè)如果不是強(qiáng)制刷新,嘗試從systemCache中獲取authority對(duì)應(yīng)的provider的所有RootInfo根據(jù)rootsUri,從provider中查詢數(shù)據(jù),并根據(jù)各個(gè)字段構(gòu)建(authority/rootId/flags/icon/tilte/summary/availableBytes/mimeTypes/qeuryArgs/derivedType/把查詢構(gòu)建的結(jié)果保存到systemCache中class-mForceRefreshAll:-mForceRefreshPackage:-mTaskRoots:Multimap<String,-mTaskStoppedAuthorities:HashSet<String>根據(jù)nt.cio.OCUET_POVDE這個(gè)ntnt查詢到合適的ContntPovider(即ocumntPovdr)。對(duì)每個(gè)ContntPovider,如果它的ppliaionnf里顯示它所在的應(yīng)用是toppd,就加入makSoppedAuhoriis;否則,查詢DocumntPovdr中的所有roos,加入到makoot中。在同步代碼塊中,為ProvidersCache的mRoots和發(fā)送com.android.documentsui.action.ROOT_CHANGED的本地廣播。internalstorageroot是否要展示;fileTypeLookupmimeTypelabel的匹配表;appsRowManagerRootFragmentitemview的構(gòu)建與顯一些選擇過(guò)程中的數(shù)據(jù),例如mRepeatedPickTimes,這個(gè)數(shù)據(jù)會(huì)被保存到getRootDocument組件中最重要的是Model類:它存儲(chǔ)了當(dāng)前加載的目錄的數(shù)據(jù)模型。在updateDirectoryLoader去加載當(dāng)前目錄的子文件/DirectoryLoader 信息找到對(duì)應(yīng)的 authority,然后利用最終會(huì)調(diào)用到對(duì)應(yīng)的DocumentsProvider的queryChildDocuments或者querySearchDocumentsitemview中。Injector<TextendsActionHandler>-features:-config:-prefs:-messages:-fileTypeLookup:Lookup<String,-shortcutsUpdater:-menuManager:-dialogs:-searchManager:-appsRowManager:-pickResult:-actionModeController:-actions:-focusManager:-selectionMgr:-mModel:-getModel:-getFocusManager:-getActionModeController:-getActionHandler:-updateSharedSelectionTracker:當(dāng)前加載的目錄的數(shù)據(jù)模型-info:當(dāng)前加載的目錄的數(shù)據(jù)模型-info:-error:-doc:-mFeatures:-mPositions:Map<String,-mFileNames:-mUpdateListener:List<EventListener<Update>>-mCursor:-mCursorCount:-mIds:-addUpdateListener:-removeUpdateListener:-notifyUpdateListener:-reset:-update(DirectoryResultresult):-updateModelData():mIds與cursor中的數(shù)據(jù)順序相同,id=mFileNames添加cursor中的_display_namemPositions添加id與cursorposition-getDocuments(Selection<String>selection):-getDocument(StringmodelId):-getItemUri(StringmodelId):4.mRoot表示當(dāng)前處于的文檔樹(shù);mList,維護(hù)了從文檔樹(shù)rootdocument5.4.mRoot表示當(dāng)前處于的文檔樹(shù);mList,維護(hù)了從文檔樹(shù)rootdocument5.-getRootDocument(RootInforoot):-getDocument(Uriuri):-getArchiveDocument(Uriuri):-isDocumentUri(Uri-findDocumentPath(Uriuri):-getDocuments(Stringauthority,List<String>docIds):-createDocument(DocumentInfoparentDoc,StringmimeType,StringdisplayName):UrisubclassRuntimeDocumentAccess-mList:-mRoot:當(dāng)前root下的documentinfo-mObserver:監(jiān)視被查詢的Uri-mRoot:被查詢的dir所在的-mUri:查詢用的-mModel:封裝查詢到的cursor-mFileTypeLookup:Lookup<String,String>type匹配緩存-mSearchMode:判斷是否在搜索模式下-mQueryArgs:僅在搜索模式下使用-mPhotoPicking:過(guò)濾查詢到的-mDoc:查詢uri對(duì)應(yīng)的dir的doc-mResult:持有cursor的結(jié)果查詢uri的由來(lái):工具類,主要是再次封裝了DocumentsContract中的一些合約方法,實(shí)現(xiàn)從Uri工具類,主要是再次封裝了DocumentsContract中的一些合約方法,實(shí)現(xiàn)從Uri6.LastAccessedProvider中存儲(chǔ)了上次選擇文檔完成時(shí)的DocumentStackdocumentstackprovidercallbackonPickFinishedonPickFinishedUriIntentpickresult(UI。-getLastAccessed:-setLastAccessed:(finishpicking或者createpickeddocument的時(shí)候更新設(shè)置-setLastAccessedToExternalApp:voidsubclassRuntimeLastAccessedStorage讀寫lastaccess到3.3SAFSAF3.3SAFSAFAPPAndroidAPPSAF,APPACTION...DocumentsProvidercreateDocument方法urur)SUPPORTS_DELETEDocumentsProviderdeleteDocument方法takeFlag)URIURI可能會(huì)失效,例如其他應(yīng)用已經(jīng)修改或刪除了文件,URIgetContentResolver().takePersistableUriPermission()以檢3.SAFDocumentsContractdocumentUritreedocumentdocumenturi可以直接打開(kāi)輸入/FDtreeUri持有對(duì)應(yīng)目錄的子目錄/文檔的權(quán)限。查詢到子目錄/documentDocumentsContract.findDocumentPathuriPathdocumentiddocumenturidocumentidtreeuricontent://Uricontent://Uri(UriGrantsManagerServiceUriSparseArray<ArrayMap<GrantUri,UriPermission>>Uiduri授(UriGrantsManagerServiceuriactivity、sendactivityresult(UriGrantsManagerServiceuriactivity、sendactivityresult接口加入數(shù)據(jù)緩存4MediaProviderScopedStorage新特性引入后,APPMediaStore1.無(wú)需權(quán)限,APPMediaStore2.READ_EXTERNAL_

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論