Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

- The `--pbcopy` flag has been removed from nimbus-cli. ([#7825](https://github.com/mozilla/application-services/pull/7825))
- The `start-server` subcommand has been removed from nimbus-cli. ([#7826](https://github.com/mozilla/application-services/pull/7826))
- Deeplink support has been removed from nimbus-cli. ([#7828](https://github.com/mozilla/application-services/pull/7828))

## ✨ What's Changed ✨

Expand Down
3 changes: 0 additions & 3 deletions components/support/nimbus-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ Options:
--preserve-bucketing
Preserves the original experiment bucketing

--deeplink <DEEPLINK>
Optional deeplink. If present, launch with this link

--reset-app
Resets the app back to its initial state before launching

Expand Down
16 changes: 0 additions & 16 deletions components/support/nimbus-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,6 @@ pub(crate) enum CliCommand {
Open {
#[command(flatten)]
open: OpenArgs,

/// By default, the app is terminated before sending the a deeplink.
///
/// If this flag is set, then do not terminate the app if it is already running.
#[arg(long, default_value = "false")]
no_clobber: bool,
},

/// Reset the app back to its just installed state
Expand Down Expand Up @@ -303,10 +297,6 @@ pub(crate) struct ManifestArgs {

#[derive(Args, Clone, Debug, Default)]
pub(crate) struct OpenArgs {
/// Optional deeplink. If present, launch with this link.
#[arg(long, value_name = "DEEPLINK")]
pub(crate) deeplink: Option<String>,

/// Resets the app back to its initial state before launching
#[arg(long, default_value = "false")]
pub(crate) reset_app: bool,
Expand All @@ -321,12 +311,6 @@ pub(crate) struct OpenArgs {
#[arg(last = true, value_name = "PASSTHROUGH_ARGS")]
pub(crate) passthrough: Vec<String>,

/// Attempt to trigger Firefox via the legacy codepath.
///
/// This is required for some older Firefox versions.
#[arg(long = "legacy-open")]
pub(crate) legacy_open_mode: bool,

/// An optional file to dump experiments into.
///
/// If present, then the app is not launched, so this option does not work with
Expand Down
146 changes: 49 additions & 97 deletions components/support/nimbus-cli/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use nimbus_fml::intermediate_representation::FeatureManifest;
use serde_json::{Value, json};
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};

use crate::output::deeplink;
use crate::protocol::StartAppProtocol;
use crate::sources::ManifestSource;
use crate::value_utils::{
Expand Down Expand Up @@ -607,58 +606,17 @@ impl LaunchableApp {
}

fn android_start(&self, app_protocol: StartAppProtocol, open: &AppOpenArgs) -> Result<Command> {
if let Self::Android {
package_name,
activity_name,
..
} = self
{
if let Self::Android { package_name, .. } = self {
let mut args: Vec<String> = Vec::new();

let (start_args, ending_args) = open.args();
args.extend_from_slice(start_args);

// If app_protocol is Default::default(), we are doing an open
// command and need to launch the browser with am start.
let legacy_open_mode = open.legacy_open_mode
|| (!app_protocol.reset_db
&& app_protocol.experiments.is_none()
&& !app_protocol.log_state
&& app_protocol.jexl_expression.is_none());

let am_cmd = if legacy_open_mode {
"start"
} else {
"broadcast"
};

match (open.legacy_open_mode, self.deeplink(open)?) {
(true, Some(deeplink)) => {
args.extend([
"-a android.intent.action.VIEW".to_string(),
"-c android.intent.category.DEFAULT".to_string(),
"-c android.intent.category.BROWSABLE".to_string(),
format!("-d {}", deeplink),
]);
}
(true, None) => {
args.extend([
format!("-n {}/{}", package_name, activity_name),
"-a android.intent.action.MAIN".to_string(),
"-c android.intent.category.LAUNCHER".to_string(),
]);
}
(false, Some(_)) => {
bail!("--deeplink is unsupported without --legacy-open");
}
(false, None) => {
args.extend([
format!("-p {}", package_name),
"-a org.mozilla.fenix.NIMBUS_TOOLING".to_string(),
"-f 0x20".to_string(), // android.content.Intent.FLAG_INCLUDE_STOPPED_PACKAGES
]);
}
}
args.extend([
format!("-p {}", package_name),
"-a org.mozilla.fenix.NIMBUS_TOOLING".to_string(),
"-f 0x20".to_string(), // android.content.Intent.FLAG_INCLUDE_STOPPED_PACKAGES
]);

let StartAppProtocol {
reset_db,
Expand All @@ -674,20 +632,24 @@ impl LaunchableApp {
if reset_db {
args.push("--ez reset-db true".to_string());
}

if let Some(s) = experiments {
let json = s.to_string().replace('\'', "&apos;");
args.push(format!("--es experiments '{}'", json))
}

if log_state {
args.push("--ez log-state true".to_string());
}

if let Some(expr) = jexl_expression {
let escaped = expr.replace('\'', "&apos;");
args.push(format!("--es eval-jexl '{}'", escaped));
};

args.extend_from_slice(ending_args);

let sh = format!(r#"am {am_cmd} {}"#, args.join(" \\\n "),);
let sh = format!(r#"am broadcast {}"#, args.join(" \\\n "),);
let mut stdout = StandardStream::stdout(ColorChoice::Auto);
write_prompt(&mut stdout, &format!("adb shell \"{}\"", sh))?;
let mut cmd = self.exe()?;
Expand All @@ -703,60 +665,50 @@ impl LaunchableApp {
app_id, device_id, ..
} = self
{
if open.legacy_open_mode {
bail!("--legacy-open unsupported for iOS");
}

let mut args: Vec<String> = Vec::new();

let (starting_args, ending_args) = open.args();

if let Some(deeplink) = self.deeplink(open)? {
let deeplink = deeplink::longform_deeplink_url(&deeplink, &app_protocol)?;
if deeplink.len() >= 2047 {
anyhow::bail!("Deeplink is too long for xcrun simctl openurl.")
}
args.push("openurl".to_string());
args.extend_from_slice(starting_args);
args.extend([device_id.to_string(), deeplink]);
} else {
args.push("launch".to_string());
args.extend_from_slice(starting_args);
args.extend([device_id.to_string(), app_id.to_string()]);

let StartAppProtocol {
log_state,
experiments,
reset_db,
jexl_expression,
} = app_protocol;

if log_state || experiments.is_some() || reset_db || jexl_expression.is_some() {
args.extend([
"--nimbus-cli".to_string(),
"--version".to_string(),
"1".to_string(),
]);
}
args.push("launch".to_string());
args.extend_from_slice(starting_args);
args.extend([device_id.to_string(), app_id.to_string()]);

if reset_db {
// We don't check launch here, because reset-db is never used
// without enroll.
args.push("--reset-db".to_string());
}
if let Some(s) = experiments {
args.extend([
"--experiments".to_string(),
s.to_string().replace('\'', "&apos;"),
]);
}
if log_state {
args.push("--log-state".to_string());
}
if let Some(expr) = jexl_expression {
args.extend(["--eval-jexl".to_string(), expr.replace('\'', "&apos;")]);
}
let StartAppProtocol {
log_state,
experiments,
reset_db,
jexl_expression,
} = app_protocol;

if log_state || experiments.is_some() || reset_db || jexl_expression.is_some() {
args.extend([
"--nimbus-cli".to_string(),
"--version".to_string(),
"1".to_string(),
]);
}

if reset_db {
// We don't check launch here, because reset-db is never used
// without enroll.
args.push("--reset-db".to_string());
}

if let Some(s) = experiments {
args.extend([
"--experiments".to_string(),
s.to_string().replace('\'', "&apos;"),
]);
}

if log_state {
args.push("--log-state".to_string());
}

if let Some(expr) = jexl_expression {
args.extend(["--eval-jexl".to_string(), expr.replace('\'', "&apos;")]);
}

args.extend_from_slice(ending_args);

let mut cmd = self.exe()?;
Expand Down
58 changes: 14 additions & 44 deletions components/support/nimbus-cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,36 +52,19 @@ impl fmt::Display for Channel {
}

struct ApplicationConfig {
channels: HashMap<Channel, ChannelConfig>,
}

struct ChannelConfig {
package: &'static str,
scheme: &'static str,
package_by_channel: HashMap<Channel, &'static str>,
}

static APPLICATIONS: LazyLock<HashMap<App, ApplicationConfig>> = LazyLock::new(|| {
hashmap! {
// Firefox for Android defines per channel deeplink schemes in the app/build.gradle.
// e.g. https://github.com/mozilla-mobile/firefox-android/blob/5d18e7ffe2f3e4505ea815d584d20e66ad10f515/fenix/app/build.gradle#L154
App::Fenix => ApplicationConfig {
channels: hashmap! {
Channel::Developer => ChannelConfig {
package: "org.mozilla.fenix.debug",
scheme: "fenix-dev",
},
Channel::Nightly => ChannelConfig {
package: "org.mozilla.fenix",
scheme: "fenix-nightly",
},
Channel::Beta => ChannelConfig {
package: "org.mozilla.firefox_beta",
scheme: "fenix-beta",
},
Channel::Release => ChannelConfig {
package: "org.mozilla.firefox",
scheme: "fenix",
},
package_by_channel: hashmap! {
Channel::Developer => "org.mozilla.fenix.debug",
Channel::Nightly => "org.mozilla.fenix",
Channel::Beta =>"org.mozilla.firefox_beta",
Channel::Release => "org.mozilla.firefox",
},
},

Expand All @@ -93,19 +76,10 @@ static APPLICATIONS: LazyLock<HashMap<App, ApplicationConfig>> = LazyLock::new(|
// public, so very useful for launching the specific app on a phone where you
// have multiple versions installed.
App::FirefoxIos => ApplicationConfig {
channels: hashmap! {
Channel::Developer => ChannelConfig {
package: "org.mozilla.ios.Fennec",
scheme: "fennec",
},
Channel::Beta => ChannelConfig {
package: "org.mozilla.ios.FirefoxBeta",
scheme: "firefox-beta",
},
Channel::Release => ChannelConfig {
package: "org.mozilla.ios.Firefox",
scheme: "firefox-internal",
},
package_by_channel: hashmap! {
Channel::Developer => "org.mozilla.ios.Fennec",
Channel::Beta => "org.mozilla.ios.FirefoxBeta",
Channel::Release => "org.mozilla.ios.Firefox",
},
}
}
Expand Down Expand Up @@ -138,9 +112,9 @@ impl LaunchableApp {
};

let app_cfg = &(*APPLICATIONS)[&app];
let Some(channel_cfg) = app_cfg.channels.get(&channel) else {
let Some(package) = app_cfg.package_by_channel.get(&channel).cloned() else {
let supported_channels = app_cfg
.channels
.package_by_channel
.keys()
.map(ToString::to_string)
.collect::<Vec<_>>()
Expand All @@ -150,16 +124,12 @@ impl LaunchableApp {

Ok(match app {
App::Fenix => Self::Android {
package_name: channel_cfg.package.into(),
activity_name: ".App".into(),
package_name: package.into(),
device_id: device_id.map(Into::into),
scheme: channel_cfg.scheme.into(),
open_deeplink: "open".into(),
},
App::FirefoxIos => Self::Ios {
app_id: channel_cfg.package.into(),
app_id: package.into(),
device_id: device_id.unwrap_or("booted").into(),
scheme: channel_cfg.scheme.into(),
},
})
}
Expand Down
Loading