diff options
author | 2023-07-17 10:27:43 -0400 | |
---|---|---|
committer | 2023-08-02 09:08:02 -0400 | |
commit | cf0a09f6c54ee6060469bcd85acbefd382eba439 (patch) | |
tree | 33230195f4a909318cdef8800313dbb66ca8412e | |
parent | 74d984cb193e6068bb1c3c4f010b2fd1c59fb161 (diff) |
Creates ChooserActivity alias
This alias allows us to avoid a bug that caused Share Sheet to crash any
app that tried to use it. It also removes the previous solution as it
had the potential to not take effect if too many receivers tried to act
on the BOOT_COMPLETE broadcast.
Test: $ adb root
Test: $ adb shell pm disable com.android.intentresolver/.ChooserActivity
Test: $ adb shell pm resolve-activity -a android.intent.action.CHOOSER
Test: Verify that the activity resolves
BUG: 283722356
FIX: 283722356
Change-Id: I820c5f88204c83e635cb877b222bdf6cbe53aaff
-rw-r--r-- | AndroidManifest-app.xml | 32 | ||||
-rw-r--r-- | java/src/com/android/intentresolver/ChooserActivityReEnabler.kt | 40 | ||||
-rw-r--r-- | java/src/com/android/intentresolver/dagger/ReceiverBinderModule.kt | 10 |
3 files changed, 18 insertions, 64 deletions
diff --git a/AndroidManifest-app.xml b/AndroidManifest-app.xml index d542e627..482c9f38 100644 --- a/AndroidManifest-app.xml +++ b/AndroidManifest-app.xml @@ -34,15 +34,12 @@ tools:replace="android:appComponentFactory" android:appComponentFactory=".IntentResolverAppComponentFactory"> - <activity android:name=".ChooserActivity" - android:theme="@style/Theme.DeviceDefault.Chooser" - android:finishOnCloseSystemDialogs="true" - android:excludeFromRecents="true" - android:documentLaunchMode="never" - android:relinquishTaskIdentity="true" - android:configChanges="screenSize|smallestScreenSize|screenLayout|keyboard|keyboardHidden" - android:visibleToInstantApps="true" - android:exported="true"> + <!-- This alias needs to be maintained until there are no more devices that could be + upgrading from T QPR3. (b/283722356) --> + <activity-alias + android:name=".ChooserActivityLauncher" + android:targetActivity=".ChooserActivity" + android:exported="true"> <!-- This intent filter is assigned a priority greater than 100 so that it will take precedence over the framework ChooserActivity @@ -53,14 +50,17 @@ <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.VOICE" /> </intent-filter> - </activity> + </activity-alias> - <receiver android:name=".ChooserActivityReEnabler" - android:exported="true"> - <intent-filter> - <action android:name="android.intent.action.BOOT_COMPLETED" /> - </intent-filter> - </receiver> + <activity android:name=".ChooserActivity" + android:theme="@style/Theme.DeviceDefault.Chooser" + android:finishOnCloseSystemDialogs="true" + android:excludeFromRecents="true" + android:documentLaunchMode="never" + android:relinquishTaskIdentity="true" + android:configChanges="screenSize|smallestScreenSize|screenLayout|keyboard|keyboardHidden" + android:visibleToInstantApps="true" + android:exported="false"/> </application> diff --git a/java/src/com/android/intentresolver/ChooserActivityReEnabler.kt b/java/src/com/android/intentresolver/ChooserActivityReEnabler.kt deleted file mode 100644 index 8c2b3d0d..00000000 --- a/java/src/com/android/intentresolver/ChooserActivityReEnabler.kt +++ /dev/null @@ -1,40 +0,0 @@ -package com.android.intentresolver - -import android.content.BroadcastReceiver -import android.content.ComponentName -import android.content.Context -import android.content.Intent -import android.content.pm.PackageManager -import javax.inject.Inject - -/** - * Ensures that the unbundled version of [ChooserActivity] does not get stuck in a disabled state. - */ -class ChooserActivityReEnabler @Inject constructor() : BroadcastReceiver() { - - override fun onReceive(context: Context, intent: Intent) { - if (intent.action == Intent.ACTION_BOOT_COMPLETED) { - context.packageManager.setComponentEnabledSetting( - CHOOSER_COMPONENT, - PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, - /* flags = */ 0, - ) - - // This only needs to be run once, so we disable ourself to avoid additional startup - // process on future boots - context.packageManager.setComponentEnabledSetting( - SELF_COMPONENT, - PackageManager.COMPONENT_ENABLED_STATE_DISABLED, - /* flags = */ 0, - ) - } - } - - companion object { - private const val CHOOSER_PACKAGE = "com.android.intentresolver" - private val CHOOSER_COMPONENT = - ComponentName(CHOOSER_PACKAGE, "$CHOOSER_PACKAGE.ChooserActivity") - private val SELF_COMPONENT = - ComponentName(CHOOSER_PACKAGE, "$CHOOSER_PACKAGE.ChooserActivityReEnabler") - } -} diff --git a/java/src/com/android/intentresolver/dagger/ReceiverBinderModule.kt b/java/src/com/android/intentresolver/dagger/ReceiverBinderModule.kt index 1f587f18..32ce2f45 100644 --- a/java/src/com/android/intentresolver/dagger/ReceiverBinderModule.kt +++ b/java/src/com/android/intentresolver/dagger/ReceiverBinderModule.kt @@ -1,18 +1,12 @@ package com.android.intentresolver.dagger import android.content.BroadcastReceiver -import com.android.intentresolver.ChooserActivityReEnabler -import dagger.Binds import dagger.Module -import dagger.multibindings.ClassKey -import dagger.multibindings.IntoMap +import dagger.multibindings.Multibinds /** Injection instructions for injectable [BroadcastReceivers][BroadcastReceiver] */ @Module interface ReceiverBinderModule { - @Binds - @IntoMap - @ClassKey(ChooserActivityReEnabler::class) - fun bindChooserActivityReEnabler(receiver: ChooserActivityReEnabler): BroadcastReceiver + @Multibinds fun bindReceivers(): Map<Class<*>, @JvmSuppressWildcards BroadcastReceiver> } |