본문 바로가기
프로그래밍 놀이터/안드로이드, Java

[android] Pie 에서 앱 잘 작동하는지 확인하기

by 돼지왕 왕돼지 2019. 7. 30.
반응형

[android] Pie 에서 앱 잘 작동하는지 확인하기


https://developer.android.com/about/versions/pie/android-9.0-migration#ct


3rd part lib, access to camera, adb non sdk api, all apps android p, all apps pie, blacklist, camera background, camera idle, crypto provider, cts test fail, dark graylist, dark greylist, dark-greylist, detectNonSdkApiUsage, graylist, greylist, hiddenapi-aosp-blacklist, jca provider, JNI, light greylist, light-greylist, mic background, microphone background, microphone idle, non sdk api enable, non sdk debuggable toast, non sdk sign, non sdk strictmode, non-sdk interface, nosuchfielderror, nosuchfieldexception, nosuchmethoderror, NoSuchMethodException, package whitelist, platform key sign, Reflection, sensor background, sensor idle, stricter utf-8 decoder, targetsdk, targetsdk dark grey list, veridex, veridex limitation, what is dark greylist, [android] Pie 에서 앱 잘 작동하는지 확인하기


-

targetSdkVersion 을 올리지 않아도 pie(android 9) 에서 제대로 작동하지 않는 경우가 있다.

그래서 아래의 것들을 확인해봐야한다.





* non-SDK interface 에 대한 제약


-

특정 non-SDK interface 에 대한 접근이 막힌다. 이것이 직접적 사용이던, JNI 를 통하던 reflection 을 통하던 말이다.

제한된 interface 에 접근하는 것은 NoSuchFieldException 또는 NoSuchMethodException 을 발생시킨다.

이에 대한 자세한 내용은.. https://developer.android.com/about/versions/pie/restrictions-non-sdk-interfaces



-

Android 9 에서 non-SDK interface 에 접근하면 아래와 같은 메시지가 출력된다.

이 메시지는 greylist 에 있냐, blacklist 에 있냐에 따라 다르다.

Accessing hidden field Landroid/os/Message;->flags:I (light greylist, JNI)



-

greylist 에 있는 non-SDK interface 들은 android 9 에서 사용은 가능하다.

그렇지만 추후 언제 없어질지 모른다.

그렇기 때문에 조취를 취하는 warning 으로 볼 수 있다.



-

blacklist 에 있는 API 들은 exception 을 발생시킨다.

NoSuchFieldError, NoSuchMethodError, NoSuchFieldException, NoSuchMethodException 등이 발생하며, reflection 을 사용할 때 기존에는 결과로 나왔던 것들이 결과로 튀어나오지 않을 수 있다.



-

Android 9 은 non-SDK interface 사용에 대한 StrictMode 를 제공한다.

detectNonSdkApiUsage 를 호출하도록 하자.

그러면 greylisted 된 interface call 도 detect 할 수 있다.



-

greylist 에는 엄밀하게 light-greylist 와 dark-greylist 란 것이 있다.

light-greylist 가 위에서 설명한 greylist 에는 있지만 아직 사용 가능한 녀석들이고,

dark-greylist 는 아래와 같은 조건을 따른다.

    targetSdk 가 28 미만 (pie 미만) 인 경우는 light-greylist 처럼 작동한다.

    targetSdk 가 28 이상이면 blacklist 처럼 작동한다.



-

3rd party lib 을 사용하는 경우 그들이 non-SDK interface 를 사용하는지 알기 어렵다.

이 때는 veridex(https://android.googlesource.com/platform/prebuilts/runtime/+/master/appcompat) 를 사용하여 분석할 수 있다.


단, 아래의 제약사항은 있다.


    JNI 를 통한 접근은 찾을 수 없다.

    reflection 을 통한 invocation 의 일부만 찾을 수 있다.

    inactive code path 는 API level check 에 한한다.



-

위에 설명한데로 locat warning 이 나오기도 하지만..

debuggable app 에 대해서는 toast message 도 출력된다.






-

non-SDK API 의 enabling 은 dev device(rooting 은 필요하지 않다) 에 adb 를 사용해서 가능하다.

adb shell settings put global hidden_api_policy_pre_p_apps  1

adb shell settings put global hidden_api_policy_p_apps 1


마지막 integer 값의 의미는 다음과 같다.


0 : disable non-SDK API usage detection. logging 도 하지 않고, strict mode 도 무시한다. 이 옵션은 추천되지 않는다.

1 : “Just warn” 으로 warning log 만 보여주며, strict mode 는 작동한다.

2 : dark grey, black listed api 의 사용을 금지한다.

3 : black listed api 의 사용을 금지하지만, dark grey 는 허용한다.


reset 은 다음과 같이 한다.

adb shell settings delete global hidden_api_policy_pre_p_apps

adb shell settings delete global hidden_api_policy_p_apps



-

greylist, blacklist 내용은 어디서 볼 수 있나?

https://android.googlesource.com/platform/prebuilts/runtime/+/master/appcompat/



-

black list 와 dark grey list 는 build time 에 따라 다르다.

AOSP 를 다운로드해서 다음 명령어로 blacklist 를 뽑아낼 수 있다.

make hiddenapi-aosp-blacklist

output file 의 위치는 : out/target/common/obj/PACKAGING/hiddenapi-aosp-blacklist.txt



-

OEM(제조사) 이 그들의 api 를 blacklist 에 추가할 수는 있지만, original/AOSP black, grey list 를 제거할 수는 없다.

CDD 에서 이런 변경을 금지하고 있고, CTS test 에 fail 할 것이다.



-

non-SDK interface restriction 은 system, first-party app 에도 적용된다.

그러나 platform key 로 sign 된 앱들은 예외이다.

그리고 몇개의 system image app 에 대해 package whitelist 를 처리할 수 있다.

이 예외들은 system image 안에 들어 있어야 한다.



-

현재 이 non-SDK interface restriction 을 회피하는 방법들도 나오고 있는데,

이에 대해 구글은 “완강히” 대처할 계획은 아니고 balancing 을 하려고 한다.

목적은 가급적 public api 만 사용하도록 하는 것이기 때문.





* Crypto provider 의 제거

    Android 9 부터 Crypto JCA provider 가 제거된다.

    SecureRandom.getInstance(“SHA1PRNG”, “Crypto”) 호출은 NoSuchProviderException 을 발생시킨다.





* Stricter UTF-8 decoder

    Android 9에서는 UTF-8 decoder 가 Unicode standard 를 따르도록 더 엄격해졌다.





* Access to camera, microphone, and sensors blocked for idle apps

    앱이 idle 한 중에는 더 이상 camera, microphone, SensorManager sensor 에 접근할 수 없다.





* 기타 내용


    다음 링크를 참조하자.

    https://developer.android.com/about/versions/pie/android-9.0-changes-all




반응형

댓글