Accessing hidden method logcat warnings and Restrictions on non-SDK interfaces

Kostas Trakos picture Kostas Trakos · Oct 7, 2018 · Viewed 31.3k times · Source

I have read in Android docs about "Restrictions on non-SDK interfaces":

These restrictions are applied whenever an app references a non-SDK interface or attempts to obtain its handle using reflection or JNI... Handling of non-SDK interfaces is an implementation detail that the API abstracts away; it is subject to change without notice... Greylisted non-SDK interfaces encompass methods and fields which continue to function in Android 9, but to which we don't guarantee access in future versions of the platform... You can use adb logcat to access these log messages, which appear under the PID of the running app...

Here are the relevant parts of my code running on an API 28 Emulator:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState); 

           ................       

    MobileAds.initialize(this,  "ca-app-pub-3940256099942544~3347511713");

           ................

    adView = new AdView(this);

    adView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");
    adView.setAdSize(AdSize.BANNER);
    adView.setBackgroundColor(Color.TRANSPARENT);
    adView.setVisibility(View.GONE);            
    adView.loadAd(adBuilder());

           ................

    interstitial = new InterstitialAd(GLGame.this);            
    interstitial.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
    interstitial.loadAd(adBuilder());        

    mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(this);
    mRewardedVideoAd.setRewardedVideoAdListener(this);        
    loadRewardedVideoAd();        
}

AdRequest adBuilder() {
    return new AdRequest.Builder().build();
}
public void loadRewardedVideoAd() {        
    mRewardedVideoAd.loadAd("ca-app-pub-3940256099942544/5224354917", new AdRequest.Builder().build());        
}

I found that with

MobileAds.initialize(this,  "ca-app-pub-3940256099942544~3347511713");
adView.loadAd(adBuilder());
interstitial.loadAd(adBuilder());

my Logcat output is:

W: Accessing hidden method Landroid/view/textclassifier/logging/SmartSelectionEventTracker;-><init>(Landroid/content/Context;I)V (light greylist, reflection)
W: Accessing hidden method Landroid/view/textclassifier/logging/SmartSelectionEventTracker;->logEvent(Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;)V (light greylist, reflection)
W: Accessing hidden method Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;->selectionStarted(I)Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent; (light greylist, reflection)
W: Accessing hidden method Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;->selectionModified(II)Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent; (light greylist, reflection)
W: Accessing hidden method Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;->selectionModified(IILandroid/view/textclassifier/TextClassification;)Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent; (light greylist, reflection)
W: Accessing hidden method Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;->selectionModified(IILandroid/view/textclassifier/TextSelection;)Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent; (light greylist, reflection)
W: Accessing hidden method Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;->selectionAction(III)Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent; (light greylist, reflection)
W: Accessing hidden method Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;->selectionAction(IIILandroid/view/textclassifier/TextClassification;)Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent; (light greylist, reflection)

if i disable by commenting

//MobileAds.initialize(this,  "ca-app-pub-3940256099942544~3347511713");
//adView.loadAd(adBuilder());
//interstitial.loadAd(adBuilder());

the Accessing hidden logcat goes away.

Same as before i got Logcat output:

W: Accessing hidden method Landroid/media/AudioTrack;->getLatency()I (light greylist, reflection)

if i disable by commenting

//loadRewardedVideoAd();

the Accessing hidden logcat goes away.

As you can see the code:

MobileAds.initialize(this,  "ca-app-pub-3940256099942544~3347511713");
adView.loadAd(adBuilder());
interstitial.loadAd(adBuilder());
loadRewardedVideoAd();

caused a lot of Accessing hidden logcat.

My questions are:

  1. These are a problem of the emulator?
  2. Is it possible that i make usage of NON-SDK interfaces (see Accessing hidden methods, light greylist, reflection) that will break my app in future versions of the platform?
  3. How can this be fixed?

Answer

Ramesh Yankati picture Ramesh Yankati · Oct 7, 2018

Greylisted non-SDK interfaces means methods and fields which continue to function in Android 9, but to which google doesn't guarantee access in future versions of the platform. If there is a reason that you cannot implement an alternative strategy to a greylisted API, you may file a bug to request reconsideration of the restriction.

https://issuetracker.google.com/issues/new?component=328403&template=1027267