Android Service 訪問安全

來源:互聯網
上載者:User

《Application Security for the Android Platform》55頁說到service的安全

1
startService(new Intent(this,MyService.class))
這種內部自己調用的是無視許可權各種限制的,後面的自訂許可權這這種沒影響。

如果service沒有  <intent-filter />屬性,那麼任何其他非當前應用都無法使用該service,一用就報許可權錯誤(就算你給service弄了自訂的許可權,然後調用其的應用也有該自訂的許可權依然不行),沒有  <intent-filter />就只能給自己用。

然後是  <intent-filter />留空,這樣的話隨便調用,只要知道具體的class路徑

比如

1
Intent i = new Intent();
2
i.setClassName("org.qii.security.three","org.qii.security.three.MyService");
3
startService(i);
之後是在 <intent-filter />留空的情況下提供受限制的共用,就是加自訂許可權,只許自己的其他程式用。

自訂許可權的name一定是需要一個逗號……不然Android不認,不認也就罷了也不報錯……坑爹的

最簡單的自訂許可權就是這樣,當然這wo.cao命名是亂來的,正常來說前面是包名。


1
<permission android:name="wo.cao"/>
2
<uses-permission android:name="wo.cao"/>
3
 
4
   <service android:name="MyService"
5
            android:permission="wo.cao">
6
       <intent-filter/>
7
   </service>
其他應用如果要調用這個MyService,必須聲明 <uses-permission android:name="wo.cao"/>,當然自訂許可權還有很多選項可以細調,最簡單的就是這樣了。

沒聲明許可權就去用,就會這樣:

1
Caused by: java.lang.SecurityException: Not allowed to start service Intent { cmp=org.qii.security.three/.MyService } without permission wo.cao 


摘自  心之所在

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.