




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
ScopedStorageScopedStorageAndroidQScopedStorageScopedStorageAndroidQAndroid版本中,APPScopedStorageApp-specificAPPspecific中,APP無需任何權(quán)限即可讀寫,而在公共目錄中,APPMediaStoreSAF也就是說,AndroidQAPPApp-specific而在外部存儲的其他空間上,APP讀寫是被更加嚴格地限制的,具體來說,APP需要申請app做限制)。ScopedStorage1.2.3.SAF4.MediaProviderAPPAndroidManifest.xmlandroid:requestLegacyExternalStorage=”truefalse”來設(shè)定APP外部存儲視圖模式。新屬性在PackageParser.java里被解析并添加到PermissionPolicyServicePermissionPolicyServiceApplicationInfoAPPAppPermissionPolicyService.onStartUser開始,包括/APPAPP申請了AppOpsManager.OP_LEGACY_STORAGEAPPappopAPPlegacyviewAPKappopmountAPKAPPAPPgroupidmountmodegids包括從packagemanager獲取的應(yīng)用的permGids,和一些補充gids,其中參數(shù)mountExtStorageFull默認是false,所以mountmode由StorageManagerServiceENABLE_ISOLATED_STORAGEisolatedstorageENABLE_ISOLATED_STORAGEisolatedstoragescopedstorage特性開關(guān)是否打開了,有兩個:PRO_ISOLATED_STORAGE_SNAPTSHOT(高優(yōu)先級)AndroidQBeta4mountmodegetMountMode->1.Isolatedprocess(uid:99000-999991.Isolatedprocess(uid:99000-9999990000-98999),MOUNT_EXTERNAL_NONE3.APPREAD_EXTERNAL_STORAGE/WRITE_EXTERNAL_STORAGE分別對應(yīng)于WRITE_MEDIA_STORAGE權(quán)限對應(yīng)hasFull,從字面意義上就表示了全部權(quán)限。User-launchable的應(yīng)用不允許申請該權(quán)限。 對應(yīng)hasLegacy。它正是之前分析的當(dāng) 時: 對應(yīng)MOUNT_EXTERNAL_WRITE, 對MOUNT_EXTERNAL_READlegacyview模式時,MOUNT_EXTERNAL_DEFAULT。MountmodeNONE:APPmountspecificFULL:READ:gidsmountmode之后,processListzygotefork(->(->->->通過程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。對于 /mnt/runtime/write/<volumeLabel>[/userId]/Android/sandbox/<sandboxId>bind /mnt/runtime/write/<volumeLabel>[/userId]/Android/obbbindmount/storage/<volumeLabel>[/userId]/Android/obb(對于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來確定需要檢查的權(quán)限BlockGuardOs.open(Stringpath,intflags,intmode)(mode僅在創(chuàng)建文件時使用Linux.open(Stringpath,intflags,intmode)(native方法->open(path.c_str(),flags,APPspecifcdirs/mnt/runtime/write/<volumeLabel>/[/userId]/Android/(data/media/obb)/packagebindAPPspecificdirs(T卡)APP進程的過程中,可以看到將/mnt/runtime/<mountmode>bindmount到/storagemountmodeAPPmountmodewrite,那么APP可以直接使用路徑對文件進行讀寫,例如legacy視圖模式且申請了WRITE_EXTERNAL_STORAGEmountmodefullAPP對所有外部存儲APPmountmode3SAFSAFSystemAccessFramework。APPSAF選擇文件、選擇目錄、創(chuàng)建文件,SAFUriAPP。APPUriUriAPP。APPUriSAF1.DocumentsProviderContentProviderMtpDocumentsProvider、MediaDocumentsProvider、ExternalStorageProvider2.文檔選取器是客戶端程序與文檔提供程序之間的橋梁。因為文檔需要受到保護,DocumentsProviderread/writepermissionMANAGE_DOCUMETS,而這個權(quán)限的等級是signatureDocumentsProviderUriDocumentUI的picker部分。APPintentDocumentUIPickActivity,DocumentUI向用戶展示有層DocumentUIAPPuripermissionAndroid4.3ACTION_PICKACTION_GET_CONTENTUIAndroid4.4及更高版本,使用ACTION_OPEN_DOCUMENT可以調(diào)起系統(tǒng)提供的選擇器注意:CTSMANAGE_DOCUMENTSpackagevendorAPP是想讀取/ACTION_GET_CONTENT,使用此方法時,APP會導(dǎo)入數(shù)據(jù)的副APPAPPDocumentsProvider3.1DocumentsProviderAPPDocumentsProvider3.1DocumentsProvider1.一個DocumentsProvider可以提供多棵文件樹,每棵樹都定義了一個rootCOLUMN_ROOT_ID標記。rootCOLUMN_DOCUMENT_ID標記。root表征COLUMN_DOCUMENT_IDURI2.COLUMN_FLAGS下文檔的元數(shù)據(jù),其中的COLUMN_FLAGS就展示了這個Uri支持的操作,例如有3.COLUMN_DOCUMENT_ID4.permission必須是MANAGE_DOCUMENT,否則系統(tǒng)文檔選擇器無法使用定義的enableAPIenableAPItrue/falseAndroid4.3falseAPPACTION_GET_CONTENTpickeractivity,那么需要在運行設(shè)備Android4.4ACTION_GET_CONTENT這個過濾器。否則系統(tǒng)文檔選擇器打開時,APP會有兩個入口。Intent-filterDOCUMENT_PROVIDERactioncontentproviderSAFdocumentprovider,系統(tǒng)的文檔選擇器選擇文檔數(shù)據(jù)源時,就是用這個action來匹配documentproviderDocumentsProvider1)queryRoots(String[]rootrootdocument才會出現(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)聽某個目錄下所有子目錄/UriDocumentsProvidernotifyChangeUri3)DocumentsProvidernotifyChangeUri3)queryDocument(StringdocumentId,String[]返回指定文件的metadata。 DocumentsContract.Document 4)openDocument(StringdocumentId,Stringmode,CancellationSignalParcelFileDescriptor。mode是打開文件的模式,”r”4DocumentsProvider4DocumentsProvider如queryRecentDocuments(如果DocumentsProvider返回的root定義了件搜索,如果支持就需要實現(xiàn)這個方法,queryArgs決定)3.2DocumentUIAPP中。DocumentUIpackage主要有兩個:filespicker。files對應(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)聽所有的DocumentsProvider的roots變化-mRecentRoots:-mRoots:Multimap<String,(保存所有authority和root的對應(yīng)關(guān)系-mStoppedAuthorities:-mObservedAuthoritiesDetails:Map<String,PackageDetails>loadRootsForAuthority:檢查exported、grantUriPermissions、添加PackageDetails到構(gòu)建rootsUri(content://<authority>/root),并注冊如果不是強制刷新,嘗試從systemCache中獲取authority對應(yīng)的provider的所有RootInfo根據(jù)rootsUri,從provider中查詢數(shù)據(jù),并根據(jù)各個字段構(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這個ntnt查詢到合適的ContntPovider(即ocumntPovdr)。對每個ContntPovider,如果它的ppliaionnf里顯示它所在的應(yīng)用是toppd,就加入makSoppedAuhoriis;否則,查詢DocumntPovdr中的所有roos,加入到makoot中。在同步代碼塊中,為ProvidersCache的mRoots和發(fā)送com.android.documentsui.action.ROOT_CHANGED的本地廣播。internalstorageroot是否要展示;fileTypeLookupmimeTypelabel的匹配表;appsRowManagerRootFragmentitemview的構(gòu)建與顯一些選擇過程中的數(shù)據(jù),例如mRepeatedPickTimes,這個數(shù)據(jù)會被保存到getRootDocument組件中最重要的是Model類:它存儲了當(dāng)前加載的目錄的數(shù)據(jù)模型。在updateDirectoryLoader去加載當(dāng)前目錄的子文件/DirectoryLoader 信息找到對應(yīng)的 authority,然后利用最終會調(diào)用到對應(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)前處于的文檔樹;mList,維護了從文檔樹rootdocument5.4.mRoot表示當(dāng)前處于的文檔樹;mList,維護了從文檔樹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:過濾查詢到的-mDoc:查詢uri對應(yīng)的dir的doc-mResult:持有cursor的結(jié)果查詢uri的由來:工具類,主要是再次封裝了DocumentsContract中的一些合約方法,實現(xiàn)從Uri工具類,主要是再次封裝了DocumentsContract中的一些合約方法,實現(xiàn)從Uri6.LastAccessedProvider中存儲了上次選擇文檔完成時的DocumentStackdocumentstackprovidercallbackonPickFinishedonPickFinishedUriIntentpickresult(UI。-getLastAccessed:-setLastAccessed:(finishpicking或者createpickeddocument的時候更新設(shè)置-setLastAccessedToExternalApp:voidsubclassRuntimeLastAccessedStorage讀寫lastaccess到3.3SAFSAF3.3SAFSAFAPPAndroidAPPSAF,APPACTION...DocumentsProvidercreateDocument方法urur)SUPPORTS_DELETEDocumentsProviderdeleteDocument方法takeFlag)URIURI可能會失效,例如其他應(yīng)用已經(jīng)修改或刪除了文件,URIgetContentResolver().takePersistableUriPermission()以檢3.SAFDocumentsContractdocumentUritreedocumentdocumenturi可以直接打開輸入/FDtreeUri持有對應(yīng)目錄的子目錄/文檔的權(quán)限。查詢到子目錄/documentDocumentsContract.findDocumentPathuriPathdocumentiddocumenturidocumentidtreeuricontent://Uricontent://Uri(UriGrantsManagerServiceUriSparseArray<ArrayMap<GrantUri,UriPermission>>Uiduri授(UriGrantsManagerServiceuriactivity、sendactivityresult(UriGrantsManagerServiceuriactivity、sendactivityresult接口加入數(shù)據(jù)緩存4MediaProviderScopedStorage新特性引入后,APPMediaStore1.無需權(quán)限,APPMediaStore2.READ_EXTERNAL_
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025屆廣東省深圳市翻身實驗學(xué)校高三第六次模擬考試化學(xué)試卷含解析
- 2025年運維軟件項目合作計劃書
- 河北雄安新區(qū)博奧高級中學(xué)2025年高三考前熱身化學(xué)試卷含解析
- 快速學(xué)習(xí)工作總結(jié)
- 2025屆河北大名一中高三下學(xué)期第六次檢測化學(xué)試卷含解析
- 中學(xué)網(wǎng)絡(luò)安全知識競賽含答案
- 云南省玉溪市第二中學(xué)2025屆高考化學(xué)倒計時模擬卷含解析
- 護理崗位述職報告
- 2025年拖拉機及農(nóng)林牧漁用掛車項目發(fā)展計劃
- 2025年厚膜工藝電源項目建議書
- 全國青少年機器人技術(shù)等級考試:二級培訓(xùn)全套課件
- 工程量清單和招標控制價的編制畢業(yè)論文
- 山羊不吃天堂草 (1)課件
- 腹股溝疝區(qū)域神經(jīng)阻滯(“麻醉”文檔)共30張
- 配電房檢查保養(yǎng)記錄表
- 農(nóng)產(chǎn)品物流管理教材文件
- 公安派出所建筑外觀形象設(shè)計規(guī)范1
- DB11-T1785-2020二氧化碳排放核算和報告要求服務(wù)業(yè)
- 碳酸鈣在各行業(yè)中的應(yīng)用課件
- 勤奮與懶惰小學(xué)心理健康課教案——告別懶惰.doc
- 麥肯錫——大數(shù)據(jù):創(chuàng)新、競爭和生產(chǎn)力的下一個前沿
評論
0/150
提交評論