Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Android P - Restrictions on non-SDK interfaces

Android P - Restrictions on non-SDK interfaces

operandoOS

June 21, 2018
Tweet

More Decks by operandoOS

Other Decks in Technology

Transcript

  1. What are non-SDK interfaces? "They are Java fields and methods

    that are not part of the official Android SDK."
  2. What are non-SDK interfaces? • ϦϑϨΫγϣϯΛ࢖ͬͯΞΫηε͢ΔΑ͏ͳ fields and methods •

    Android frameworkͷSDKυΩϡϝϯτʹ
 هࡌ͞Ε͍ͯͳ͍ͷ͸non-SDKͱߟ͑ͯྑͦ͞͏
  3. ϝδϟʔͳϥΠϒϥϦʹ͸ issue্͕͕Γ࢝ΊͯΔ • okhttp reflection meet Android P DP1 non-sdk

    restriction • https://github.com/square/okhttp/issues/ 3980 • [ Important ] Violations on android P • https://github.com/facebook/react-native/ issues/19067
  4. React Nativͷissue • [ Important ] Violations on android P

    • https://github.com/facebook/react-native/ issues/19067
  5. try { // Get the original cursor drawable resource. Field

    cursorDrawableResField = TextView.class.getDeclaredField("mCursorDrawableRes"); cursorDrawableResField.setAccessible(true); int drawableResId = cursorDrawableResField.getInt(view); ..... } catch (NoSuchFieldException ex) { // Ignore errors to avoid crashing if these private fields don't exist on modified // or future android versions. } issueͰ৮ΕΒΕͯΔ෦෼ͷίʔυ
  6. How can I enable access to non-SDK APIs? • adbͰglobal

    settingΛ͍͡Δ͜ͱͰɺಈ࡞Λม͑Δ ͜ͱ͕Ͱ͖·͢ adb shell settings put global hidden_api_policy_pre_p_apps 1 adb shell settings put global hidden_api_policy_p_apps 1
  7. How can I enable access to non-SDK APIs? • ಈ࡞֬ೝऴΘͬͨΒઃఆͨ͠஋͸ফ͠·͠ΐ

    adb shell settings delete global hidden_api_policy_pre_p_apps adb shell settings delete global hidden_api_policy_p_apps
  8. StrictMode policy violation: android.os.strictmode.NonSdkApiUsedViolation: Landroid/widget/ Toast;->mDuration:I at android.os.StrictMode.lambda$static$1(StrictMode.java:428) at android.os.-$$Lambda$StrictMode$lu9ekkHJ2HMz0jd3F8K8MnhenxQ.accept(Unknown

    Source:2) at java.lang.Class.getDeclaredField(Native Method) at com.os.operando.non_sdkinterfaces.sample.MainActivity$onCreate$3.onClick(MainActivity.kt:49) at android.view.View.performClick(View.java:6597) at android.view.View.performClickInternal(View.java:6574) at android.view.View.access$3100(View.java:778) at android.view.View$PerformClick.run(View.java:25883) at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6642) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
  9. Are the blacklist / greylists the same on different OEM

    devices with the same Android versions? "Yes OEMs can add their own apis to the blacklist, but cannot remove things from the original/AOSP black or grey lists. The CDD prevents such changes and CTS tests ensure that the Android Runtime is enforcing the list."
  10. ࢥͬͨ͜ͱͳͲͳͲ • non-SDKΛ࢖ͬͯΔ৔߹ʹGoogle Play Consoleͱ͔ʹ΋ग़ͯ͠΄͍͔͠΋ • release buildͰ΋ग़ͯ͠΄͍͔͠΋ͳʔ • non-SDKͷ֤Ϧετͷ಺༰ͷߋ৽͸OSΞοϓσʔτͷλΠϛϯάͱ͔Ͱ͞ΕΔʁ

    • ύονϨϕϧͰ͸ߋ৽ͳͦ͞͏ • ͋Δͱ͢Ε͹OSόʔδϣϯΞοϓ͘Β͍ͷΞοϓσʔτͷ͔࣌΋Ͷ • ࢖༻ͯ͠ΔϥΠϒϥϦ͕non-SDKΛ࢖͍ͬͯͨΒissue΍PRΛग़ͦ͏ • Contribute chance
  11. ࢀߟࢿྉ • Restrictions on non-SDK interfaces • https://developer.android.com/preview/restrictions-non-sdk- interfaces •

    Improving Stability by Reducing Usage of non-SDK Interfaces • https://android-developers.googleblog.com/2018/02/ improving-stability-by-reducing-usage.html • An Update on non-SDK restrictions in Android P • https://android-developers.googleblog.com/2018/06/an- update-on-non-sdk-restrictions-in.html