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

New api support #177

Merged
merged 9 commits into from
Jul 31, 2023
2 changes: 1 addition & 1 deletion core/launcher/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

[package]
name = "launcher"
version.workspace = true
version = "0.7.0"
edition = "2021"

# See more keys and their definitions at https:#doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
28 changes: 19 additions & 9 deletions core/launcher/src/manager/app_launcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use ripple_sdk::{
device::{
device_browser::{BrowserNameRequestParams, BrowserRequest},
device_info_request::DeviceInfoRequest,
entertainment_data::{HomeIntent, NavigationIntent},
entertainment_data::{HomeIntent, NavigationIntent, NavigationIntentStrict},
},
firebolt::{
fb_discovery::{DiscoveryContext, LaunchRequest},
Expand Down Expand Up @@ -302,7 +302,10 @@ impl AppLauncher {
// Only add the container if app is not launching to suspend and not launched due to
// a pending provider request.
if !app.launch_params.suspend {
if let NavigationIntent::ProviderRequest(_) = app.current_intent {
if let NavigationIntent::NavigationIntentStrict(
NavigationIntentStrict::ProviderRequest(_),
) = app.current_intent
{
// Do nothing if the current intent is a provider request
} else {
let props = app.container_props.clone();
Expand Down Expand Up @@ -498,7 +501,10 @@ impl AppLauncher {
let iter_apps = state.app_launcher_state.get_apps();
for app in iter_apps {
if app.container_props.view_id == props.view_id {
if let NavigationIntent::ProviderRequest(_) = app.current_intent {
if let NavigationIntent::NavigationIntentStrict(
NavigationIntentStrict::ProviderRequest(_),
) = app.current_intent
{
Self::set_state(state.clone(), props.name, LifecycleState::Inactive)
.await
.ok();
Expand Down Expand Up @@ -541,7 +547,7 @@ impl AppLauncher {
transport: Self::get_transport(manifest.start_page),
}),
launch: AppLaunchInfo {
intent,
intent: Some(intent),
second_screen: None,
inactive: false,
},
Expand Down Expand Up @@ -598,11 +604,15 @@ impl AppLauncher {
return Err(AppError::NotSupported);
};

let intent = request.intent.unwrap_or(NavigationIntent::Home(HomeIntent {
context: DiscoveryContext {
source: "device".into(),
},
}));
let intent = request
.intent
.unwrap_or(NavigationIntent::NavigationIntentStrict(
NavigationIntentStrict::Home(HomeIntent {
context: DiscoveryContext {
source: "device".into(),
},
}),
));

if let Err(_) = Self::pre_launch(
&state,
Expand Down
2 changes: 1 addition & 1 deletion core/main/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

[package]
name = "main"
version.workspace = true
version = "0.7.0"
edition = "2021"
repository = "https://github.com/rdkcentral/Ripple"
build = "build.rs"
Expand Down
10 changes: 6 additions & 4 deletions core/main/src/bootstrap/extn/check_launcher_step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use ripple_sdk::{
api::{
apps::{AppMethod, AppRequest, AppResponse},
device::entertainment_data::{LaunchIntent, NavigationIntent},
device::entertainment_data::{LaunchIntent, NavigationIntent, NavigationIntentStrict},
firebolt::fb_discovery::{DiscoveryContext, LaunchRequest},
},
async_trait::async_trait,
Expand Down Expand Up @@ -51,9 +51,11 @@ impl Bootstep<BootstrapState> for CheckLauncherStep {
let app_request = AppRequest::new(
AppMethod::Launch(LaunchRequest {
app_id: app.app_id,
intent: Some(NavigationIntent::Launch(LaunchIntent {
context: DiscoveryContext::new("device"),
})),
intent: Some(NavigationIntent::NavigationIntentStrict(
NavigationIntentStrict::Launch(LaunchIntent {
context: DiscoveryContext::new("device"),
}),
)),
}),
app_resp_tx,
);
Expand Down
35 changes: 28 additions & 7 deletions core/main/src/firebolt/firebolt_gatekeeper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use ripple_sdk::api::gateway::rpc_gateway_api::RpcRequest;
use ripple_sdk::log::trace;

use crate::service::user_grants::GrantState;
use crate::state::openrpc_state::ApiSurface;
use crate::state::{cap::permitted_state::PermissionHandler, platform_state::PlatformState};

pub struct FireboltGatekeeper {}
Expand Down Expand Up @@ -51,12 +52,26 @@ impl FireboltGatekeeper {
fn get_resolved_caps_for_method(
platform_state: &PlatformState,
method: &str,
) -> Vec<FireboltPermission> {
let perm_based_on_spec = platform_state.open_rpc_state.get_perms_for_method(method);
secure: bool,
) -> Option<Vec<FireboltPermission>> {
let mut api_surface = vec![ApiSurface::Firebolt];
if !secure {
api_surface.push(ApiSurface::Ripple);
}
let perm_based_on_spec_opt = platform_state
.open_rpc_state
.get_perms_for_method(method, api_surface);
if perm_based_on_spec_opt.is_none() {
return None;
}
let perm_based_on_spec = perm_based_on_spec_opt.unwrap();
if perm_based_on_spec.len() == 0 {
return perm_based_on_spec;
return Some(perm_based_on_spec);
}
Self::resolve_dependencies(platform_state, &perm_based_on_spec)
Some(Self::resolve_dependencies(
platform_state,
&perm_based_on_spec,
))
}
// TODO return Deny Reason into ripple error
pub async fn gate(state: PlatformState, request: RpcRequest) -> Result<(), DenyReasonWithCap> {
Expand All @@ -65,9 +80,15 @@ impl FireboltGatekeeper {
trace!("Method is exluded from gating");
return Ok(());
}
// if let Some(caps) = open_rpc_state.get_caps_for_method(&request.method) {
// let caps = open_rpc_state.get_perms_for_method(&request.method);
let caps = Self::get_resolved_caps_for_method(&state, &request.method);
let caps_opt =
Self::get_resolved_caps_for_method(&state, &request.method, request.ctx.gateway_secure);
if caps_opt.is_none() {
return Err(DenyReasonWithCap {
reason: DenyReason::NotFound,
caps: Vec::new(),
});
}
let caps = caps_opt.unwrap();
if caps.len() > 0 {
// Supported and Availability checks
trace!(
Expand Down
4 changes: 4 additions & 0 deletions core/main/src/firebolt/firebolt_ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ impl FireboltWs {
ws_stream,
connect_rx,
state_for_connection_c.clone(),
secure,
)
.await;
});
Expand All @@ -195,6 +196,7 @@ impl FireboltWs {
ws_stream: WebSocketStream<TcpStream>,
connect_rx: oneshot::Receiver<ClientIdentity>,
state: PlatformState,
gateway_secure: bool,
) {
let identity = connect_rx.await.unwrap();
let client = state.get_client();
Expand All @@ -203,6 +205,7 @@ impl FireboltWs {
let ctx = ClientContext {
session_id: identity.session_id.clone(),
app_id: app_id.clone(),
gateway_secure,
};
let session = Session::new(
identity.app_id.clone(),
Expand Down Expand Up @@ -263,6 +266,7 @@ impl FireboltWs {
ctx.session_id.clone(),
req_id.clone(),
Some(connection_id.clone()),
ctx.gateway_secure,
) {
debug!(
"Received Firebolt request {} {} {}",
Expand Down
59 changes: 57 additions & 2 deletions core/main/src/firebolt/handlers/discovery_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use jsonrpsee::{
use ripple_sdk::api::{
device::entertainment_data::*,
firebolt::{
fb_discovery::{EVENT_ON_SIGN_IN, EVENT_ON_SIGN_OUT},
fb_general::{ListenRequest, ListenerResponse},
provider::ExternalProviderResponse,
},
Expand Down Expand Up @@ -90,6 +91,18 @@ pub trait Discovery {
async fn sign_in(&self, ctx: CallContext, sign_in_info: SignInInfo) -> RpcResult<bool>;
#[method(name = "discovery.signOut")]
async fn sign_out(&self, ctx: CallContext) -> RpcResult<bool>;
#[method(name = "discovery.onSignIn")]
async fn on_sign_in(
&self,
ctx: CallContext,
request: ListenRequest,
) -> RpcResult<ListenerResponse>;
#[method(name = "discovery.onSignOut")]
async fn on_sign_out(
&self,
ctx: CallContext,
request: ListenRequest,
) -> RpcResult<ListenerResponse>;
#[method(name = "discovery.watched")]
async fn watched(&self, ctx: CallContext, watched_info: WatchedInfo) -> RpcResult<bool>;
#[method(name = "discovery.watchNext")]
Expand Down Expand Up @@ -277,15 +290,30 @@ impl DiscoveryImpl {
ctx: CallContext,
is_signed_in: bool,
) -> RpcResult<bool> {
Ok(self
let app_id = ctx.app_id.to_owned();
let res = self
.state
.get_client()
.send_extn_request(match is_signed_in {
true => AccountLinkRequest::SignIn(ctx),
false => AccountLinkRequest::SignOut(ctx),
})
.await
.is_ok())
.is_ok();
if res {
AppEvents::emit(
&self.state,
if is_signed_in {
EVENT_ON_SIGN_IN
} else {
EVENT_ON_SIGN_OUT
},
&serde_json::json!({"appId": app_id,}),
)
.await;
return Ok(true);
}
return Ok(false);
}

async fn content_access(
Expand Down Expand Up @@ -404,6 +432,33 @@ impl DiscoveryServer for DiscoveryImpl {
self.process_sign_in_request(ctx.clone(), false).await
}

async fn on_sign_in(
&self,
ctx: CallContext,
request: ListenRequest,
) -> RpcResult<ListenerResponse> {
let listen = request.listen;
AppEvents::add_listener(&&self.state, EVENT_ON_SIGN_IN.to_string(), ctx, request);

Ok(ListenerResponse {
listening: listen,
event: EVENT_ON_SIGN_IN.to_owned(),
})
}
async fn on_sign_out(
&self,
ctx: CallContext,
request: ListenRequest,
) -> RpcResult<ListenerResponse> {
let listen = request.listen;
AppEvents::add_listener(&&self.state, EVENT_ON_SIGN_OUT.to_string(), ctx, request);

Ok(ListenerResponse {
listening: listen,
event: EVENT_ON_SIGN_OUT.to_owned(),
})
}

async fn watched(&self, ctx: CallContext, watched_info: WatchedInfo) -> RpcResult<bool> {
info!("Discovery.watched");
match self
Expand Down
56 changes: 56 additions & 0 deletions core/main/src/firebolt/handlers/localization_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,17 @@ use crate::{
firebolt::rpc::RippleRPCProvider, processor::storage::storage_manager::StorageManager,
service::apps::provider_broker::ProviderBroker, state::platform_state::PlatformState,
};
use serde::Deserialize;

#[derive(Deserialize, Debug)]
pub struct SetMapEntryProperty {
pub key: String,
pub value: String,
}
#[derive(Deserialize, Debug)]
pub struct RemoveMapEntryProperty {
pub key: String,
}
#[rpc(server)]
pub trait Localization {
#[method(name = "localization.locality")]
Expand Down Expand Up @@ -121,6 +131,19 @@ pub trait Localization {
ctx: CallContext,
set_request: SetStringProperty,
) -> RpcResult<()>;
#[method(name = "localization.addAdditionalInfo")]
async fn add_additional_info(
&self,
ctx: CallContext,
set_map_entry_property: SetMapEntryProperty,
) -> RpcResult<()>;
#[method(name = "localization.removeAdditionalInfo")]
async fn remove_additional_info(
&self,
ctx: CallContext,
remove_map_entry_property: RemoveMapEntryProperty,
) -> RpcResult<()>;

#[method(name = "localization.onAdditionalInfoChanged")]
async fn on_additional_info_changed(
&self,
Expand Down Expand Up @@ -402,6 +425,39 @@ impl LocalizationServer for LocalizationImpl {
.await
}

// #[instrument(skip(self))]
async fn add_additional_info(
&self,
_ctx: CallContext,
set_map_entry_property: SetMapEntryProperty,
) -> RpcResult<()> {
/*
Per FIRE-189, AdditionalInfo is now individually updatable, so read the entire map out, and update
value in place, and then write entire map out

*/
StorageManager::set_value_in_map(
&self.platform_state,
StorageProperty::AdditionalInfo,
set_map_entry_property.key,
set_map_entry_property.value,
)
.await
}
// #[instrument(skip(self))]
async fn remove_additional_info(
&self,
_ctx: CallContext,
remove_map_entry_property: RemoveMapEntryProperty,
) -> RpcResult<()> {
StorageManager::remove_value_in_map(
&self.platform_state,
StorageProperty::AdditionalInfo,
remove_map_entry_property.key,
)
.await
}

async fn on_additional_info_changed(
&self,
ctx: CallContext,
Expand Down
Loading