25

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?
Kostas Trakos
  • 731
  • 2
  • 7
  • 9
  • It looks like whatever mobile ad library you're using is doing it. It is a risk, it means that you need to keep that library updated if a new version of android breaks that. – Gabe Sechan Oct 07 '18 at 16:14
  • Looking at what its actually doing- it looks like they're trying to use features of Android9 that may have existed before that via reflection. Which is fairly safe. What they're doing it trying to manipulate the text classification subsystem to change what's displayed in the contextual action bar (things like copy, paste, etc). – Gabe Sechan Oct 07 '18 at 16:23
  • Hello @Gabe, i use: `implementation 'com.google.android.gms:play-services-ads:9.8.0'` and some other google-play-services. If i update to current 16.0.0 i can build and run without problem except that i get 71 lint Deprecated API usage warnings But the Accessing hidden logcat remains the same with google-play-services:9.8.0 Could you please tell me, if i update to google-play-services:16.0.0 and replace the Deprecated API usage 71 Warnings this problem will be fixed? – Kostas Trakos Oct 07 '18 at 18:54
  • I wouldn't worry about the warnings. Like I said- it looks like this functionality existed before Android 9, was made public in Android 9, but they're trying to make use of it in some older versions where it exists. That's a safe usage. When Android 9.1 or 10 comes out your should double check nothing breaks on them, but I think it unlikely. – Gabe Sechan Oct 07 '18 at 19:03
  • When Android 9.1 or 10 will come, if something breaks on them which will be the steps to fix it? – Kostas Trakos Oct 07 '18 at 19:52
  • It's in a library, so update the library and hope they fixed it – Gabe Sechan Oct 07 '18 at 19:55
  • Is there a way for me to find out in which library? I assume google-play-services – Kostas Trakos Oct 07 '18 at 20:46
  • Yes. Its in google-play-services-ads – Gabe Sechan Oct 07 '18 at 20:47
  • If i update to the latest release google-play-services-ads:16.0.0 i get still the same Accessing hidden logcat – Kostas Trakos Oct 07 '18 at 21:11
  • Right. They haven't fixed it, because its not actually broken. If in the future it does break, I'd expect them to fix it and then you'd need to update. – Gabe Sechan Oct 07 '18 at 21:16
  • That means i have to wait to see if it gets dark-greylisted and then to update? – Kostas Trakos Oct 07 '18 at 21:41

1 Answers1

3

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

Ramesh Yankati
  • 1,197
  • 9
  • 13