UFO ET IT

android-시스템 서비스에서 수신하기위한 수신자에 대한 "내 보낸 수신자에 권한이 필요하지 않음"

ufoet 2020. 11. 30. 20:25
반응형

android-시스템 서비스에서 수신하기위한 수신자에 대한 "내 보낸 수신자에 권한이 필요하지 않음"


내 AndroidManifest에 선언 된 수신기가 있습니다.

<!-- no warning -->
<receiver
    android:name=".receivers.TriggerMonitoringBootReceiver"
    android:enabled="false">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
    </intent-filter>
</receiver>

<!-- no warning -->
<receiver
    android:name=".receivers.ScanResultsReceiver"
    android:enabled="false">
    <intent-filter>
        <action android:name="android.net.wifi.SCAN_RESULTS" />
    </intent-filter>
</receiver>

<!-- warning : Exported receiver does not require permission-->
<receiver
    android:name=".receivers.BatteryMonitoringReceiver"
    android:enabled="false">
    <intent-filter>
        <action android:name="@string/intent_action_setup_alarm" />
        <action android:name="@string/intent_action_cancel_alarm" />
        <action android:name="@string/intent_action_monitor" />
    </intent-filter>
</receiver>

첫 번째는 BOOT_COMPLETED행동 을 받기위한 것 입니다. 두 번째는 수신을 의미합니다 android.net.wifi.SCAN_RESULTS. 세 번째는 내가 브로드 캐스트 한 일부 작업 (intent_action_monitor)과 AlarmManager(intent_action_setup_alarm 등) 에서 브로드 캐스트하는 일부 작업을 수신하기위한 것 입니다.

두 가지 질문 :

  • 모든 수신기에서 경고를받지 못하는 이유는 무엇입니까?
  • 경고를 수정하기 위해 시스템 서비스에서 수신하려는 수신자에 대해 설정해야하는 권한은 무엇입니까? (나는 그것이 무엇인지 이해하고 다른 사람이 내 수신자를 사용하는 것을 원하지 않습니다)? exported="false" 부팅 수신기, 와이파이 수신기, 경보 수신기 등을 위해 ?
    사용자 지정 권한을 사용하려고 생각 android:protectionLevel="signatureOrSystem"했지만 문서는이 보호 수준사용자 지정 권한 모두에 대해 조언 합니다. 그렇다면이 경고를 어떻게 처리해야합니까?

문서 및 / 또는 일부 코드에 대한 링크를 많이 주시면 감사하겠습니다.


모든 수신기에서 경고를받지 못하는 이유는 무엇입니까?

처음 두 개는 Android에서 방송하도록 명확하게 설계 되었기 때문입니다. 마지막 항목은 알 수 없습니다. 부분적으로는 문자열 리소스 값을 제공하지 않았고 고유 한 작업 문자열이기 때문일 수 있습니다.

경고를 수정하기 위해 시스템 서비스에서 수신하려는 수신자에 대해 어떤 권한을 설정해야합니까?

올바른 해결책은 <intent-filter>. 당신이이 방송하는 경우 Intents, 또는 당신이 포장하는 경우 IntentA의 getBroadcast() PendingIntent, 당신은 액션 문자열이 필요하지 않습니다. IntentJava 클래스 객체를 두 번째 매개 변수로 사용하는 생성자를 사용하고 다음을 사용합니다.

new Intent(this, BatteryMonitoringReceiver.class)

원하는 경우 여전히 액션 문자열을 해당에 첨부 Intent할 수 있지만 덤프 할 수 있습니다 <intent-filter>(라우팅은 제공된 구성 요소,이 경우 Java 클래스를 기반으로 함).

<intent-filter>OS 또는 타사 앱이 Intent자체적 으로 시작될 것으로 예상 하는 경우 에만를 사용 하십시오 ( PendingIntent생성 한를 실행하는 것은 포함되지 않음).


"내 보낸 수신기에 권한이 필요하지 않습니다" 라는 경고 는 다음을 의미합니다 intent-filter. 일부 작업이 있음을 의미합니다 (기본적으로 사용자가 android:exported="true"설정했으며 이제 receive broadcasts외부의 모든 브로드 캐스터 에서 application할 수 receive broadcasts있음 ). broadcasters애플리케이션 외부의 모든 브로드 캐스터 에서 할 수 있으므로 경고합니다. 말로 "이봐, 당신은 반드시 모든 방송사가 내 생각에? 당신을 호출 할 수 있습니다 당신 만이 허용하는 경우, 그것은 더 broadcasters이 당신을 호출 permission이 설정 한 receiver을 통해android:permission"

android:exported="false"수신자 태그 에 추가하여이 경고를 제거 할 수 있습니다.


If you do want to export your receiver to other processes, you can add your own permission definition in your android-manifest file for avoiding this warning, like

<permission
    android:name="com.yourpage.permission.YOUR_PERMISSION"
    android:protectionLevel="normal" />

<uses-permission
    android:name="com.yourpage.permission.YOUR_PERMISSION" />

<receiver <!-- warning : Exported receiver does not require permission-->
    android:name=".receivers.BatteryMonitoringReceiver"
    android:permission="com.yourpage.permission.YOUR_PERMISSION"
    android:enabled="false" >
    <intent-filter>
        <action android:name="@string/intent_action_setup_alarm" />
        <action android:name="@string/intent_action_cancel_alarm" />
        <action android:name="@string/intent_action_monitor" />
    </intent-filter>
</receiver> 

for more information, you can refer to http://developer.android.com/training/articles/security-tips.html


If, like me, you are here because your app built with a previous SDK version stopped working with more recent versions and you would like to fix it with minimal change, just add

android:exported=false

to the receiver tag in the manifest file. The solution by CommonsWare is obviously the one to go with for the long term but this fixes the issue temporarily if you are using custom intents and don't mean to export them.

Going by Lubo's way, you would need to export this custom permission, which would prompt the user before installation. That means the descriptive text for the permission needs to be well written so you don't end up scaring the user into changing his mind about installing the app. Also, it would need to be translated into all your target languages.

참고URL : https://stackoverflow.com/questions/16112470/android-exported-receiver-does-not-require-permission-on-receivers-meant-to

반응형