Android中Permission權(quán)限機(jī)制的具體使用
由上篇Android Permission權(quán)限機(jī)制引子,我們知道Android 通過(guò)在每臺(tái)設(shè)備上實(shí)施了基于權(quán)限的安全策略來(lái)處理安全問(wèn)題,采用權(quán)限來(lái)限制安裝應(yīng)用程序的能力。本篇文章繼續(xù)來(lái)探討和Android權(quán)限相關(guān)的話(huà)題,主要集中在權(quán)限級(jí)別、ICC(inter- component communication)權(quán)限保護(hù)兩個(gè)方面。
權(quán)限級(jí)別 protection level
每一個(gè)Permission權(quán)限都設(shè)有了權(quán)限級(jí)別(protection level),分別如下:
“normal”
The default value. A lower-risk permission that gives requesting applications access to isolated application-level features, with minimal risk to other applications, the system, or the user. The system automatically grants this type of permission to a requesting application at installation, without asking for the user's explicit approval (though the user always has the option to review these permissions before installing).
normal級(jí)別是一些比較低風(fēng)險(xiǎn)的權(quán)限,我們?cè)诎惭b一個(gè)新app到手機(jī)時(shí),一般會(huì)被折疊起來(lái)的權(quán)限就是normal級(jí)別的。
“dangerous”
A higher-risk permission that would give a requesting application access to private user data or control over the device that can negatively impact the user. Because this type of permission introduces potential risk, the system may not automatically grant it to the requesting application. For example, any dangerous permissions requested by an application may be displayed to the user and require confirmation before proceeding, or some other approach may be taken to avoid the user automatically allowing the use of such facilities.
dangerous則是那些比較高風(fēng)險(xiǎn)的權(quán)限,在安裝時(shí)會(huì)明顯提示用戶(hù)該app具有這些權(quán)限,并且需要用戶(hù)同意確認(rèn)才能正確安裝app的權(quán)限。
“signature”
A permission that the system grants only if the requesting application is signed with the same certificate as the application that declared the permission. If the certificates match, the system automatically grants the permission without notifying the user or asking for the user's explicit approval.
signature則在我們用戶(hù)自定義權(quán)限custom時(shí),會(huì)用得到的,具體做法我會(huì)在另一篇博文:Android 自定義權(quán)限中具體研究的,這里簡(jiǎn)述之:
用戶(hù)在某一個(gè)app(先稱(chēng)permisson app)中自定義了permission時(shí),并且指定了某些組件需要該自定義權(quán)限才能打開(kāi),這是前提,然后用戶(hù)又開(kāi)發(fā)了另外一個(gè)app(稱(chēng)為permission client),這個(gè)permission client如果想訪問(wèn)permisson app中指定了自定義權(quán)限的組件,那么這兩個(gè)app必須具備相同的signature,這就是signature級(jí)別的意思。
“signatureOrSystem”
A permission that the system grants only to applications that are in the Android system image or that are signed with the same certificates as those in the system image. Please avoid using this option, as the signature protection level should be sufficient for most needs and works regardless of exactly where applications are installed. The “signatureOrSystem” permission is used for certain special situations where multiple vendors have applications built into a system image and need to share specific features explicitly because they are being built together.
這個(gè)同上,但多了一個(gè)Or,or是指除了相同的signature之外還可以指定為相同的Android img也可以訪問(wèn),這個(gè)img其實(shí)就是系統(tǒng)級(jí)別的定制了,一般用的很少。
ICC(inter-component communication)權(quán)限保護(hù)
<application>元素和組件元素都有android:permission的屬性,在這里我們稱(chēng)這個(gè)屬性分別為應(yīng)用程序和組件的權(quán)限標(biāo)簽。應(yīng)用程序內(nèi)的組件可以繼承應(yīng)用程序元素設(shè)置的權(quán)限標(biāo)簽,當(dāng)某一組件啟動(dòng) ICC 時(shí),相關(guān)的訪問(wèn)控制器就會(huì)查看組件和組件所在應(yīng)用程序的權(quán)限標(biāo)簽集合,如目標(biāo)組件的訪問(wèn)權(quán)限標(biāo)簽在以上的集合內(nèi),允許 ICC 的建立繼續(xù)進(jìn)行,否則將會(huì)被拒絕,即使這兩個(gè)組件在同一應(yīng)用程序內(nèi)。

改圖描述了該邏輯的進(jìn)程:組件A是否可以訪問(wèn)組件B和C,取決于比較B和C內(nèi)的訪問(wèn)權(quán)限標(biāo)簽與應(yīng)用程序1內(nèi)的標(biāo)簽集合的結(jié)果。B和應(yīng)用程序1內(nèi)都有i1標(biāo)簽,所以組件A可以訪問(wèn)組件B,相反應(yīng)用程序1內(nèi)沒(méi)有標(biāo)簽i2,組件A 不可以訪問(wèn)組件B。
相關(guān)文章
Android TabLayout實(shí)現(xiàn)京東詳情效果
這篇文章主要為大家詳細(xì)介紹了android TabLayout實(shí)現(xiàn)京東詳情效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-09-09
Android開(kāi)發(fā)之繪制平面上的多邊形功能分析
這篇文章主要介紹了Android開(kāi)發(fā)之繪制平面上的多邊形功能,結(jié)合實(shí)例形式分析了Android多邊形圖形繪制的原理、步驟、相關(guān)操作技巧與注意事項(xiàng),需要的朋友可以參考下2017-09-09
Jetpack Compose實(shí)現(xiàn)對(duì)話(huà)框和進(jìn)度條實(shí)例解析
對(duì)話(huà)框和進(jìn)度條其實(shí)并無(wú)多大聯(lián)系,放在一起寫(xiě)是因?yàn)閮烧叩膬?nèi)容都不多,所以湊到一起,對(duì)話(huà)框是我們平時(shí)開(kāi)發(fā)使用得比較多的組件,進(jìn)度條的使用頻率也很高,比如下載文件,上傳文件,處理任務(wù)時(shí)都可以使用進(jìn)度條2023-04-04
Android Handler移除Message詳解及實(shí)例代碼
這篇文章主要介紹了Android Handler移除Message詳解及實(shí)例代碼的相關(guān)資料,需要的朋友可以參考下2017-02-02
Android 第三方庫(kù)lottie、mmkv的使用詳解
lottie是Airbnb開(kāi)源的一個(gè)面向 iOS、Android、React Native 的動(dòng)畫(huà)庫(kù),能實(shí)現(xiàn)精美、復(fù)雜的動(dòng)畫(huà)效果,本文通過(guò)實(shí)例代碼給大家介紹Android 第三方庫(kù)lottie、mmkv的使用,感興趣的的朋友一起看看吧2021-04-04
Android開(kāi)發(fā)之自動(dòng)朗讀TTS用法分析
這篇文章主要介紹了Android開(kāi)發(fā)之自動(dòng)朗讀TTS用法,較為詳細(xì)的分析了TTS的概念、功能、使用方法與相關(guān)注意事項(xiàng),需要的朋友可以參考下2016-06-06
Android RadioGroup 設(shè)置某一個(gè)選中或者不可選中的方法
下面小編就為大家?guī)?lái)一篇Android RadioGroup 設(shè)置某一個(gè)選中或者不可選中的方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-04-04
Kotlin Flow封裝類(lèi)SharedFlow StateFlow LiveData使用
這篇文章主要為大家介紹了Kotlin Flow封裝類(lèi)SharedFlow StateFlow LiveData使用對(duì)比,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-08-08

