Skip to content

Commit

Permalink
Merge 1.4.0 (#493)
Browse files Browse the repository at this point in the history
* Features: Set defaults from manifest on boot (#478)

* RPPL-1808:Read /etc/rippleversion.txt and update version (#485)

* RPPL-1808:Read /etc/rippleversion.txt and update version

* Resolve clippy issue

* Fix run clippy job

* Fix PR check errors

* Thunder plugin handling (#487)

* fix: Thunder Plugin handling errors
* fix: Add timeout for plugin activation
* fix: unit tests
* fix: Corrected the usage of 'check_thunder_response_success' function to handle error cases.
* fix: Fixed infinite wait loop issue on StartExtnChannelsStep on extension ready case.
* fix: Added parsing of json string returned from Value.get() function.

---------

Co-authored-by: Vinod Sathyaseelan <vinod_sathyaseelan@comcast.com>

* fix: Handling Thunder status for plugin (#490)

* fix: Handling Thunder status for plugin

* fix: Handling Thunder status for plugin

---------

Co-authored-by: pahearn73 <pahearn73@users.noreply.github.com>
Co-authored-by: punam0928 <76198157+pkumbh631@users.noreply.github.com>
Co-authored-by: Vinod Sathyaseelan <vinod_sathyaseelan@comcast.com>
  • Loading branch information
4 people authored Apr 3, 2024
1 parent afcb10c commit c48e3c7
Show file tree
Hide file tree
Showing 16 changed files with 589 additions and 257 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main", "1.2.0.rc","1.3.0.rc" ]
branches: [ "main", "1.4.0.rc" ]

env:
CARGO_TERM_COLOR: always
Expand Down
31 changes: 13 additions & 18 deletions core/main/src/bootstrap/extn/start_extn_channel_step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@
// SPDX-License-Identifier: Apache-2.0
//

use std::time::Duration;

use ripple_sdk::{
api::status_update::ExtnStatus,
async_trait::async_trait,
framework::{bootstrap::Bootstep, RippleResponse},
log::error,
tokio::{sync::mpsc, time::timeout},
log::{error, warn},
tokio::sync::mpsc,
utils::error::RippleError,
};

Expand Down Expand Up @@ -77,28 +75,25 @@ impl Bootstep<BootstrapState> for StartExtnChannelsStep {
}
}
}
let t = state.platform_state.get_manifest().get_timeout();
for extn_id in extn_ids {
let (tx, mut tr) = mpsc::channel(1);
if !state
.extn_state
.add_extn_status_listener(extn_id.clone(), tx)
{
match timeout(Duration::from_millis(t), tr.recv()).await {
Ok(Some(v)) => {
state.extn_state.clear_status_listener(extn_id);
match v {
ExtnStatus::Ready => continue,
_ => return Err(RippleError::BootstrapError),
while let Some(v) = tr.recv().await {
match v {
ExtnStatus::Ready => break,
// When Extension is in this state means it has minimal success criteria for continuing
// yet not fully ready due to some errors.
// Expectation of the system here progressive to wait for an eventual success
// without exiting with the error
ExtnStatus::Interrupted => warn!("{} extension is interrupted state. Bootstrap currently paused until extension becomes ready.", extn_id.to_string()),
ExtnStatus::Error => {
error!("{} extension failed to load. Ripple needs to be restarted.",extn_id.to_string());
return Err(RippleError::BootstrapError);
}
}
Ok(None) => {
error!("Extn={:?} dropped its memory", extn_id);
}
Err(_) => {
error!("Extn={:?} failed to load timeout occurred", extn_id);
return Err(RippleError::BootstrapError);
}
}
}
}
Expand Down
12 changes: 4 additions & 8 deletions core/main/src/firebolt/firebolt_ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,12 @@ impl FireboltWs {
error!("Error registering the connection {:?}", e);
return;
}
if !gateway_secure {
state
.session_state
.add_pending_session(app_id.clone(), None);
if PermissionHandler::fetch_and_store(&state, &app_id, false)
if !gateway_secure
&& PermissionHandler::fetch_and_store(&state, &app_id, false)
.await
.is_err()
{
error!("Couldnt pre cache permissions");
}
{
error!("Couldnt pre cache permissions");
}

let (mut sender, mut receiver) = ws_stream.split();
Expand Down
11 changes: 10 additions & 1 deletion core/main/src/service/context_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
//

use crate::state::platform_state::PlatformState;
use ripple_sdk::api::context::RippleContextUpdateRequest;
use ripple_sdk::api::config::FEATURE_CLOUD_PERMISSIONS;
use ripple_sdk::api::context::{FeatureUpdate, RippleContextUpdateRequest};
use ripple_sdk::api::device::device_events::{
DeviceEvent, DeviceEventCallback, DeviceEventRequest,
};
Expand Down Expand Up @@ -93,6 +94,14 @@ impl ContextManager {

// Asynchronously get context and update the state
tokio::spawn(async move {
// Set default cloud permissions value
ps_c.get_client().get_extn_client().context_update(
RippleContextUpdateRequest::UpdateFeatures(vec![FeatureUpdate::new(
FEATURE_CLOUD_PERMISSIONS.into(),
ps_c.get_device_manifest().get_features().cloud_permissions,
)]),
);

// Get Initial power state
if let Ok(resp) = ps_c
.get_client()
Expand Down
5 changes: 2 additions & 3 deletions core/main/src/state/bootstrap_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,11 @@ impl BootstrapState {
Err(err) => {
warn!(
"error reading versions from {}, err={:?}",
version_file_name.clone(),
err
version_file_name, err
);
}
}
warn!("error reading versions from {}", version_file_name.clone(),);
warn!("error reading versions from {}", version_file_name,);
None
}
Ok(BootstrapState {
Expand Down
12 changes: 6 additions & 6 deletions core/main/src/state/cap/permitted_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::{

use ripple_sdk::{
api::{
config::FEATURE_CLOUD_PERMISISONS,
config::FEATURE_CLOUD_PERMISSIONS,
device::device_apps::AppsRequest,
//config::Config,
distributor::distributor_permissions::{PermissionRequest, PermissionResponse},
Expand Down Expand Up @@ -150,11 +150,15 @@ impl PermissionHandler {
app_id: &str,
allow_cached: bool,
) -> RippleResponse {
if state.open_rpc_state.is_app_excluded(app_id) {
return Ok(());
}

if state
.get_client()
.get_extn_client()
.get_features()
.contains(&String::from(FEATURE_CLOUD_PERMISISONS))
.contains(&String::from(FEATURE_CLOUD_PERMISSIONS))
{
if allow_cached {
if let Some(permissions) =
Expand Down Expand Up @@ -206,10 +210,6 @@ impl PermissionHandler {
}

pub async fn device_fetch_and_store(state: &PlatformState, app_id: &str) -> RippleResponse {
if state.open_rpc_state.is_app_excluded(app_id) {
return Ok(());
}

let mut client = state.get_client().get_extn_client();
let resp = client
.request(AppsRequest::GetFireboltPermissions(app_id.to_string()))
Expand Down
2 changes: 1 addition & 1 deletion core/sdk/src/api/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use super::manifest::{

use super::manifest::device_manifest::AppLibraryEntry;

pub const FEATURE_CLOUD_PERMISISONS: &str = "cloud_permissions";
pub const FEATURE_CLOUD_PERMISSIONS: &str = "cloud_permissions";

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
pub enum Config {
Expand Down
143 changes: 138 additions & 5 deletions core/sdk/src/api/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,26 @@ pub enum RippleContextUpdateType {
}

impl RippleContext {
pub fn new(
activation_status: Option<ActivationStatus>,
internet_connectivity: Option<InternetConnectionStatus>,
system_power_state: Option<SystemPowerState>,
time_zone: Option<TimeZone>,
update_type: Option<RippleContextUpdateType>,
features: Vec<String>,
metrics_context: Option<MetricsContext>,
) -> RippleContext {
RippleContext {
activation_status,
internet_connectivity,
system_power_state,
time_zone,
update_type,
features,
metrics_context,
}
}

pub fn is_ripple_context(msg: &ExtnPayload) -> Option<Self> {
RippleContext::get_from_payload(msg.clone())
}
Expand Down Expand Up @@ -141,14 +161,25 @@ impl RippleContext {
false
// This is not an update request so need not to honour it
}
RippleContextUpdateRequest::Features(features) => {
RippleContextUpdateRequest::UpdateFeatures(features) => {
let mut changed = false;
for feature in features {
if !self.features.contains(&feature) {
self.features.push(feature);
changed = true;
match feature.enabled {
true => {
if !self.features.contains(&feature.name) {
self.features.push(feature.name);
changed = true;
}
}
false => {
if self.features.contains(&feature.name) {
self.features.retain(|f| !f.eq(&feature.name));
changed = true;
}
}
}
}

if changed {
self.update_type = Some(RippleContextUpdateType::FeaturesChanged);
}
Expand Down Expand Up @@ -216,14 +247,26 @@ impl ExtnPayloadProvider for RippleContext {
}
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
pub struct FeatureUpdate {
name: String,
enabled: bool,
}

impl FeatureUpdate {
pub fn new(name: String, enabled: bool) -> FeatureUpdate {
FeatureUpdate { name, enabled }
}
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
pub enum RippleContextUpdateRequest {
Activation(bool),
Token(AccountToken),
InternetStatus(InternetConnectionStatus),
PowerState(SystemPowerState),
TimeZone(TimeZone),
Features(Vec<String>),
UpdateFeatures(Vec<FeatureUpdate>),
MetricsContext(MetricsContext),
RefreshContext(Option<RippleContextUpdateType>),
}
Expand Down Expand Up @@ -286,4 +329,94 @@ mod tests {
let contract_type: RippleContract = RippleContract::RippleContext;
test_extn_payload_provider(ripple_context, contract_type);
}

#[test]
fn test_update_features_enabled_not_exists() {
let name = String::from("foo");
let some_other_feature = String::from("bar");
let mut ripple_context = RippleContext::new(
None,
None,
None,
None,
None,
vec![some_other_feature.clone()],
None,
);
let changed = ripple_context.update(RippleContextUpdateRequest::UpdateFeatures(vec![
FeatureUpdate::new(name.clone(), true),
]));
assert!(changed);
assert!(ripple_context.features.contains(&name));
assert!(ripple_context.features.contains(&some_other_feature));
}

#[test]
fn test_update_features_enabled_exists() {
let name = String::from("foo");
let some_other_feature = String::from("bar");
let mut ripple_context = RippleContext::new(
None,
None,
None,
None,
None,
vec![some_other_feature.clone()],
None,
);
ripple_context.update(RippleContextUpdateRequest::UpdateFeatures(vec![
FeatureUpdate::new(name.clone(), true),
]));
let changed = ripple_context.update(RippleContextUpdateRequest::UpdateFeatures(vec![
FeatureUpdate::new(name.clone(), true),
]));
assert!(!changed);
assert!(ripple_context.features.contains(&name));
assert!(ripple_context.features.contains(&some_other_feature));
}

#[test]
fn test_update_features_disabled_not_exists() {
let name = String::from("foo");
let some_other_feature = String::from("bar");
let mut ripple_context = RippleContext::new(
None,
None,
None,
None,
None,
vec![some_other_feature.clone()],
None,
);
let changed = ripple_context.update(RippleContextUpdateRequest::UpdateFeatures(vec![
FeatureUpdate::new(name.clone(), false),
]));
assert!(!changed);
assert!(!ripple_context.features.contains(&name));
assert!(ripple_context.features.contains(&some_other_feature));
}

#[test]
fn test_update_features_disabled_exists() {
let name = String::from("foo");
let some_other_feature = String::from("bar");
let mut ripple_context = RippleContext::new(
None,
None,
None,
None,
None,
vec![some_other_feature.clone()],
None,
);
ripple_context.update(RippleContextUpdateRequest::UpdateFeatures(vec![
FeatureUpdate::new(name.clone(), true),
]));
let changed = ripple_context.update(RippleContextUpdateRequest::UpdateFeatures(vec![
FeatureUpdate::new(name.clone(), false),
]));
assert!(changed);
assert!(!ripple_context.features.contains(&name));
assert!(ripple_context.features.contains(&some_other_feature));
}
}
2 changes: 1 addition & 1 deletion core/sdk/src/api/device/device_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl FromStr for NetworkType {
}
}

#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase")]
pub struct HDCPStatus {
pub is_connected: bool,
Expand Down
2 changes: 1 addition & 1 deletion core/sdk/src/extn/client/extn_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ pub trait ExtnRequestProcessor: ExtnStreamProcessor + Send + Sync + 'static {
}

async fn ack(mut extn_client: ExtnClient, request: ExtnMessage) -> RippleResponse {
return extn_client.send_message(request.ack()).await;
extn_client.send_message(request.ack()).await
}

async fn run(&mut self) {
Expand Down
Loading

0 comments on commit c48e3c7

Please sign in to comment.