MobileAds.initialize crashes in direct boot mode

426 views
Skip to first unread message

alexander...@gmail.com

unread,
Jun 1, 2022, 11:48:22 AM6/1/22
to Google Mobile Ads SDK Developers
I have an alarm app which must run already in direct boot mode triggered by an alarm. But MobileAds.initialize crashes the whole app when the device is still in direct boot mode, for example after a reboot:

E/AndroidRuntime: FATAL EXCEPTION: Thread-2
    Process: , PID: 1513
    java.lang.IllegalStateException: SharedPreferences in credential encrypted storage are not available until after user is unlocked
        at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:556)
        at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:541)
        at com.google.android.gms.internal.ads.zzbld.zza(com.google.android.gms:play-services-ads-lite@@20.6.0:1)
        at com.google.android.gms.internal.ads.zzblh.zze(com.google.android.gms:play-services-ads-lite@@20.6.0:8)
        at com.google.android.gms.internal.ads.zzbli.zza(com.google.android.gms:play-services-ads-lite@@20.6.0:1)
        at com.google.android.gms.internal.ads.zzbll.zza(com.google.android.gms:play-services-ads-lite@@20.6.0:7)
        at com.google.android.gms.internal.ads.zzblj.zzc(com.google.android.gms:play-services-ads-lite@@20.6.0:1)
        at com.google.android.gms.internal.ads.zzbwz.run(com.google.android.gms:play-services-ads-lite@@20.6.0:1)
        at java.lang.Thread.run(Thread.java:920)
       

The standard SharedPreferences are not available in direct boot mode. Android N and above must use a device-protected-storage context and give this context to SharedPreferences. I am giving such a context to the init function of AdMob but it does not seem to be used and another context is used which cause the app to crash.

How to reproduce:

1. Create an Application class where MobileAds is initialized like this:

public class BaseApplication extends Application {

    public Context getDeviceProtectedContext() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
            return getApplicationContext().createDeviceProtectedStorageContext();
        else
            return getApplicationContext();
    }

    @Override
    public void onCreate() {
        super.onCreate();
        MobileAds.initialize(getDeviceProtectedContext(), initializationStatus -> {
        });
    }
}


2. define your main Activity as direct boot aware
 <activity android:directBootAware="true" ...
 
3. Reboot the emulator so it starts in direct boot mode
adb reboot-bootloader

4. Flash the application without entering a security key

Mobile Ads SDK Forum Advisor

unread,
Jun 1, 2022, 10:22:10 PM6/1/22
to alexander...@gmail.com, google-adm...@googlegroups.com
Hi Alexander,

Thank you for reporting this to us. Would it be possible for you to provide a sample app where the issue is reproducible? You may provide it to us by following this guide below.

1. Navigate to

https://docs.google.com/forms/d/e/1FAIpQLSfkAiXMeYP-fw1W3Z-tT9uwmATEKO5X6S-th0gR2ezdKaaqfg/viewform?usp=pp_url&entry.400550049=Mobile+Ads+SDK&entry.460850823=5004Q00002baqQBQAY&entry.80707362=00109708

2. Fill out all fields, and attach your file(s).

3. Please reply back on this thread when you have uploaded your file(s).

Regards,

Google Logo
Teejay Wennie
Mobile Ads SDK Team
 


ref:_00D1U1174p._5004Q2baqQB:ref
Message has been deleted

Mobile Ads SDK Forum Advisor

unread,
Jun 7, 2022, 10:01:06 AM6/7/22
to alexander...@gmail.com, google-adm...@googlegroups.com

Hi Alexander,

Thank you for your response.

Upon checking your sample app and following the steps included on it, I wasn't able to replicate the crashes that you encounter. With that, can you provide us a screen recording capturing this behavior so that we can better look into it?

Regards,

Google Logo
Princess Pamela
Mobile Ads SDK Team
 


ref:_00D1U1174p._5004Q2baqQB:ref

alexander...@gmail.com

unread,
Jun 7, 2022, 10:56:52 AM6/7/22
to Google Mobile Ads SDK Developers
here is the video: https://youtu.be/eAK5wKahFH4

Mobile Ads SDK Forum Advisor

unread,
Jun 7, 2022, 9:43:09 PM6/7/22
to alexander...@gmail.com, google-adm...@googlegroups.com
Hi Alexander,

Thank you for sharing the requested information. I've raised this (including the discussion and findings thus far) to the rest of the team for further investigation. We'll update this thread the soonest the team team share their insight.

Regards,
Google Logo
Teejay Wennie
Mobile Ads SDK Team
 


ref:_00D1U1174p._5004Q2baqQB:ref

Mobile Ads SDK Forum Advisor

unread,
Apr 5, 2023, 3:57:52 AM4/5/23
to google-adm...@googlegroups.com, alexander...@gmail.com
Hello,

Thank you for your patience. The team was able to check the issue reported here and mentioned that the crash is expected for your use case. As per discussion, the team recommends that you should wait until your user has unlocked the device before trying to use the SDK.

Regards,
Google Logo Mobile Ads SDK Team


ref:_00D1U1174p._5004Q2baqQB:ref
Reply all
Reply to author
Forward
0 new messages