Extract code in private sub methods
This commit is contained in:
parent
6781b5cee7
commit
13d46e0e78
1 changed files with 30 additions and 23 deletions
|
|
@ -37,8 +37,19 @@ class DefaultShareService @Inject constructor(
|
||||||
@ApplicationContext private val context: Context,
|
@ApplicationContext private val context: Context,
|
||||||
) : ShareService {
|
) : ShareService {
|
||||||
override fun observeFeatureFlag(coroutineScope: CoroutineScope) {
|
override fun observeFeatureFlag(coroutineScope: CoroutineScope) {
|
||||||
val shareActivityComponent = context
|
val shareActivityComponent = getShareActivityComponent()
|
||||||
.packageManager
|
?: return Unit.also {
|
||||||
|
Timber.w("ShareActivity not found")
|
||||||
|
}
|
||||||
|
featureFlagService.isFeatureEnabledFlow(FeatureFlags.IncomingShare)
|
||||||
|
.onEach { enabled ->
|
||||||
|
shareActivityComponent.enableOrDisable(enabled)
|
||||||
|
}
|
||||||
|
.launchIn(coroutineScope)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getShareActivityComponent(): ComponentName? {
|
||||||
|
return context.packageManager
|
||||||
.getPackageInfo(
|
.getPackageInfo(
|
||||||
context.packageName,
|
context.packageName,
|
||||||
PackageManager.GET_ACTIVITIES or PackageManager.MATCH_DISABLED_COMPONENTS
|
PackageManager.GET_ACTIVITIES or PackageManager.MATCH_DISABLED_COMPONENTS
|
||||||
|
|
@ -51,26 +62,22 @@ class DefaultShareService @Inject constructor(
|
||||||
shareActivityInfo.name,
|
shareActivityInfo.name,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
?: return Unit.also {
|
}
|
||||||
Timber.w("ShareActivity not found")
|
|
||||||
}
|
private fun ComponentName.enableOrDisable(enabled: Boolean) {
|
||||||
featureFlagService.isFeatureEnabledFlow(FeatureFlags.IncomingShare)
|
val state = if (enabled) {
|
||||||
.onEach { enabled ->
|
PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
|
||||||
val state = if (enabled) {
|
} else {
|
||||||
PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
|
PackageManager.COMPONENT_ENABLED_STATE_DISABLED
|
||||||
} else {
|
}
|
||||||
PackageManager.COMPONENT_ENABLED_STATE_DISABLED
|
try {
|
||||||
}
|
context.packageManager.setComponentEnabledSetting(
|
||||||
try {
|
this,
|
||||||
context.packageManager.setComponentEnabledSetting(
|
state,
|
||||||
shareActivityComponent,
|
PackageManager.DONT_KILL_APP,
|
||||||
state,
|
)
|
||||||
PackageManager.DONT_KILL_APP,
|
} catch (e: Exception) {
|
||||||
)
|
Timber.e(e, "Failed to enable or disable the component")
|
||||||
} catch (e: Exception) {
|
}
|
||||||
Timber.e(e, "Failed to enable or disable the component")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.launchIn(coroutineScope)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue