Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update launcher activity attribute to Android 12 #2074

Merged
merged 1 commit into from
Feb 27, 2021

Conversation

reneargento
Copy link
Contributor

@reneargento reneargento commented Feb 18, 2021

To be able to target Android 12 all activities that use intent filters must declare the android:exported attribute.
Reference:

 https://developer.android.com/about/versions/12/behavior-changes-12#exported

This pull request adds the attribute on LeakLauncherActivity.
Without it, apps that have a dependency on LeakCanary will not be able to target Android 12.

I got the following error when trying to build an app that depends on LeakCanary targeting Android 12:

Failed to commit install session 473003211 with command cmd package install-commit 473003211. Error: INSTALL_PARSE_FAILED_MANIFEST_MALFORMED: Failed parse during installPackageLI: /data/app/vmdl473003211.tmp/base.apk (at Binary XML file line 752): leakcanary.internal.activity.LeakLauncherActivity: Targeting S+ (version 10000 and above) requires that an explicit value for android:exported be defined when intent filters are present

@CLAassistant
Copy link

CLAassistant commented Feb 18, 2021

CLA assistant check
All committers have signed the CLA.

@reneargento reneargento changed the title Update launcher activity attributes to Android 12 Update launcher activity attribute to Android 12 Feb 18, 2021
@imknown
Copy link

imknown commented Feb 19, 2021

This can be resolved by the app side temporarily:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" ...>
    <application ...>
        <activity-alias
            android:name="leakcanary.internal.activity.LeakLauncherActivity"
            android:exported="true"
            android:targetActivity="leakcanary.internal.activity.LeakActivity"
            tools:node="merge" />
    </application>
</manifest>

However, it will still crash because o thef Android-12-targeting PendingInent API:

E/AndroidRuntime: FATAL EXCEPTION: IntentService[HeapAnalyzerService]
    Process: net.imknown.android.forefrontinfo.debug:leakcanary, PID: 6854
    java.lang.IllegalArgumentException: net.imknown.android.forefrontinfo.debug: Targeting S+ (version 10000 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
    Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
        at android.app.PendingIntent.checkFlags(PendingIntent.java:367)
        at android.app.PendingIntent.getActivityAsUser(PendingIntent.java:452)
        at android.app.PendingIntent.getActivity(PendingIntent.java:437)
        at android.app.PendingIntent.getActivity(PendingIntent.java:401)
        at leakcanary.internal.activity.LeakActivity$Companion.createPendingIntent(LeakActivity.kt:181)
        at leakcanary.DefaultOnHeapAnalyzedListener.showNotification(DefaultOnHeapAnalyzedListener.kt:74)
        at leakcanary.DefaultOnHeapAnalyzedListener.onHeapAnalyzed(DefaultOnHeapAnalyzedListener.kt:66)
        at leakcanary.internal.HeapAnalyzerService.onHandleIntentInForeground(HeapAnalyzerService.kt:73)
        at leakcanary.internal.ForegroundService.onHandleIntent(ForegroundService.kt:55)
        at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:78)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loopOnce(Looper.java:201)
        at android.os.Looper.loop(Looper.java:288)
        at android.os.HandlerThread.run(HandlerThread.java:67)

fun createPendingIntent(
context: Context,
screens: ArrayList<Screen>
): PendingIntent {
val intent = Intent(context, LeakActivity::class.java)
intent.putExtra("screens", screens)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP
return PendingIntent.getActivity(context, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT)
}

So, it may be:

intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP or PendingIntent.FLAG_IMMUTABLE

@pyricau
Copy link
Member

pyricau commented Feb 27, 2021

I'm going to merge this. @imknown you are saying there's still going to be a crash even after exported is merged in, right?

@pyricau pyricau merged commit 4c84b9c into square:main Feb 27, 2021
@pyricau pyricau removed this from the 2.7 milestone Feb 27, 2021
@imknown
Copy link

imknown commented Feb 28, 2021

@pyricau Yes. Crash will happen after dumping.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants