Skip to content

Commit

Permalink
Active plugins (#4553)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/488551667048375/1207335546470303/f

### Description
This PR adds active plugin points, ie. plugin points that are automatically guarded by remote feature flags.

See [this](https://app.asana.com/0/1202552961248957/1207322408444916/f) for more context

### Steps to test this PR
_Test Main Process_
- [x] build and install from #4554
- [x] filter logcat by `UserOfThePluginPoint | Aitor`
- [x] launch the app
- [x] verify `Main`, `Baz`, `Bar`, `Second Main` plugins print in that order and `In Process main`
- [x] Enable AppTP
- [x] verify `Main`, `Baz`, `Bar`, `Second Main` plugins print in that order and `In Process vpn`
- [x] Disable Baz plugin
```
    "pluginPointMyPlugin": {
      "exceptions": [],
      "state": "enabled",
      "hash": "1",
      "features": {
        "pluginBazActivePlugin": {
          "state": "disabled"
        }
      }
    }
```
- [x] use fire button to update remote config
- [x] verify `Main`, `Bar`, `Second Main` plugins print in that order and `In Process main`
- [x] Disable and re-enable AppTP
- [x] verify `Main`, `Bar`, `Second Main` plugins print in that order and `In Process vpn`
- [x] Disable Bar plugin
```
    "pluginPointMyPlugin": {
      "exceptions": [],
      "state": "enabled",
      "hash": "2",
      "features": {
        "pluginBarActivePlugin": {
          "state": "disabled"
        }
      }
    }
```
- [x] verify `Main`, `Second Main` plugins print in that order and `In Process main`
- [x] Disable and re-enable AppTP
- [x] verify `Main`, `Second Main` plugins print in that order and `In Process vpn`
- [x] Disable plugin point
```
    "pluginPointMyPlugin": {
      "exceptions": [],
      "state": "disabled",
      "hash": "3",
      "features": {
      }
    }
```
- [x] verify no plugin prints any message
- [x] Disable and re-enable AppTP
- [x] verify no plugin prints any message
- [x] re-enable plugin point and all plugins
```
    "pluginPointMyPlugin": {
      "hash": "5",
      "exceptions": [],
      "state": "enabled",
      "features": {
        "pluginBazActivePlugin": {
          "state": "enabled"
        },
        "pluginBarActivePlugin": {
          "state": "enabled"
        }
      }
    }
```
- [x] verify `Main`, `Baz`, `Bar`, `Second Main` plugins print in that order and `In Process main`
- [x] Disable and re-enable AppTP
- [x] verify `Main`, `Baz`, `Bar`, `Second Main` plugins print in that order and `In Process vpn`
- [x] disable all plugins individually
```
    "pluginPointMyPlugin": {
      "exceptions": [],
      "state": "enabled",
      "hash": "6",
      "features": {
        "pluginBazActivePlugin": {
          "state": "disabled"
        },
        "pluginBarActivePlugin": {
          "state": "disabled"
        },
        "pluginFooActivePlugin": {
          "state": "disabled"
        },
        "pluginMainActivePlugin": {
          "state": "disabled"
        },
        "pluginSecondMainActivePlugin": {
          "state": "disabled"
        }
      }
    }
```
- [x] verify no plugin prints any message
- [x] Disable and re-enable AppTP
- [x] verify no plugin prints any message
- [x] re-enable all individually
- [x] verify `Main`, `Baz`, `Bar`, `Second Main` plugins print in that order and `In Process main`
- [x] Disable and re-enable AppTP
- [x] verify `Main`, `Baz`, `Bar`, `Second Main` plugins print in that order and `In Process vpn`
  • Loading branch information
aitorvs authored May 23, 2024
1 parent 77fcbb6 commit ad43235
Show file tree
Hide file tree
Showing 9 changed files with 1,116 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright (c) 2024 DuckDuckGo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.duckduckgo.anvil.annotations

import kotlin.reflect.KClass

/**
* Anvil annotation to contribute plugins into an Active Plugin Point.
* Active plugins are also guarded by remote feature flags
*
* This annotation is the counterpart of [ContributesActivePluginPoint]
*
* Usage:
* ```kotlin
* @ContributesActivePlugin(SomeDaggerScope::class)
* class MyPluginImpl : MyPlugin {
*
* }
*
* interface MyPlugin : ActivePluginPoint.ActivePlugin {...}
* ```
*/
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
annotation class ContributesActivePlugin(
/** The scope in which to include this contributed PluginPoint */
val scope: KClass<*>,

/**
* This is the type of the plugin the annotated class is extending from
* This is a required member to help the code generation.
*/
val boundType: KClass<*>,

/**
* The default value of remote feature flag.
* Default is true (ie. enabled)
*/
val defaultActiveValue: Boolean = true,

/**
* The priority for the plugin.
* Lower priority values mean the associated plugin comes first in the list of plugins.
*
* This is equivalent to the [PriorityKey] annotation we use with [ContributesMultibinding] for normal plugins.
* The [ContributesActivePlugin] coalesce both
*/
val priority: Int = 0,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2024 DuckDuckGo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.duckduckgo.anvil.annotations

import kotlin.reflect.KClass

/**
* Anvil annotation to generate plugin points that are guarded by a remote feature flag.
*
* Active plugins need to extend from [ActivePluginPoint.ActivePlugin]
*
* Usage:
* ```kotlin
* @ContributesActivePluginPoint(SomeDaggerScope::class)
* interface MyPlugin : ActivePluginPoint.ActivePlugin {
*
* }
* ```
*/
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
annotation class ContributesActivePluginPoint(
/** The scope in which to include this contributed PluginPoint */
val scope: KClass<*>,

/**
* The type that the plugin point will be bound to. This is useful when the plugin interfaces are defined in
* modules where we don't want or can't generate code, eg. API gradle modules.
*
* usage:
* ```kotlin
* @ContributesActivePluginPoint(
* scope = AppScope::class,
* boundType: MyPlugin::class
* )
* interface MyPluginPoint : MyPlugin
*
* interface MyPlugin : ActivePluginPoint.ActivePlugin {...}
* ```
*/
val boundType: KClass<*> = Unit::class,
)
Loading

0 comments on commit ad43235

Please sign in to comment.