Commit c028d708 authored by Sheng-Hao Tsao's avatar Sheng-Hao Tsao Committed by Commit Bot

Only open GCA if ARC is P or above

This CL changes the consolidated camera app icon logic so that it
launches GCA/GCA migration app only if ARC is P or above. This is to
address 2 problems:

1. Android N and below do not support external cameras. We would like
users to use CCA so that they can still utilize external cameras.
2. Managed users in Android N still have the problem where GCA could be
stripped out.

Bug: b:118860552,chromium:896140
Test: Used N devices (caroline) with google.com account and verified
that CCA is opened.

Change-Id: I7836d2b4256856028901e5e542f460e7107fc8db
Reviewed-on: https://chromium-review.googlesource.com/c/1316982
Commit-Queue: Sheng-hao Tsao <shenghao@google.com>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarTao Wu <wutao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606795}
parent 652ddcf5
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "chromeos/chromeos_features.h" #include "chromeos/chromeos_features.h"
#include "chromeos/chromeos_switches.h" #include "chromeos/chromeos_switches.h"
#include "components/arc/arc_features_parser.h"
#include "components/arc/metrics/arc_metrics_constants.h" #include "components/arc/metrics/arc_metrics_constants.h"
#include "components/arc/property/arc_property_bridge.h" #include "components/arc/property/arc_property_bridge.h"
#include "components/crx_file/id_util.h" #include "components/crx_file/id_util.h"
...@@ -151,6 +152,31 @@ int GetIconResourceIdByAppId(const std::string& app_id) { ...@@ -151,6 +152,31 @@ int GetIconResourceIdByAppId(const std::string& app_id) {
return app ? app->icon_resource_id : 0; return app ? app->icon_resource_id : 0;
} }
void OpenChromeCameraApp(Profile* profile,
int event_flags,
const extensions::Extension* extension) {
AppListClientImpl* controller = AppListClientImpl::GetInstance();
AppLaunchParams params = CreateAppLaunchParamsWithEventFlags(
profile, extension, event_flags, extensions::SOURCE_APP_LAUNCHER,
controller->GetAppListDisplayId());
params.launch_id = ash::ShelfID(extension->id()).launch_id;
OpenApplication(params);
VLOG(1) << "Launched CCA.";
}
void ShowWebStore(Profile* profile,
int event_flags,
const std::string chrome_app_id) {
AppListClientImpl* controller = AppListClientImpl::GetInstance();
const GURL store_url = net::AppendQueryParameter(
GURL(extension_urls::GetWebstoreItemDetailURLPrefix() + chrome_app_id),
extension_urls::kWebstoreSourceField,
extension_urls::kLaunchSourceAppListSearch);
controller->OpenURL(profile, store_url, ui::PAGE_TRANSITION_LINK,
ui::DispositionFromEventFlags(event_flags));
VLOG(1) << "Launched CWS.";
}
void OnGetMigrationProperty(Profile* profile, void OnGetMigrationProperty(Profile* profile,
int event_flags, int event_flags,
const base::Optional<std::string>& result) { const base::Optional<std::string>& result) {
...@@ -161,17 +187,48 @@ void OnGetMigrationProperty(Profile* profile, ...@@ -161,17 +187,48 @@ void OnGetMigrationProperty(Profile* profile,
} }
AppListClientImpl* controller = AppListClientImpl::GetInstance(); AppListClientImpl* controller = AppListClientImpl::GetInstance();
if (!arc::LaunchApp(profile, app_id, event_flags, if (arc::LaunchApp(profile, app_id, event_flags,
arc::UserInteractionType::APP_STARTED_FROM_LAUNCHER, arc::UserInteractionType::APP_STARTED_FROM_LAUNCHER,
controller->GetAppListDisplayId())) { controller->GetAppListDisplayId())) {
arc::LaunchApp(profile, kAndroidLegacyCameraAppId, event_flags, VLOG(1) << "Launched "
arc::UserInteractionType::APP_STARTED_FROM_LAUNCHER, << (app_id == kAndroidCameraAppId ? " GCA." : "GCA migration.");
controller->GetAppListDisplayId()); return;
}
if (arc::LaunchApp(profile, kAndroidLegacyCameraAppId, event_flags,
arc::UserInteractionType::APP_STARTED_FROM_LAUNCHER,
controller->GetAppListDisplayId())) {
VLOG(1) << "Launched legacy GCA.";
return;
} }
LOG(ERROR) << "Failed to launch any camera apps. Fallback to CCA.";
const std::string chrome_app_id(kChromeCameraAppId);
const extensions::ExtensionRegistry* registry =
extensions::ExtensionRegistry::Get(profile);
const extensions::Extension* extension =
registry->GetInstalledExtension(chrome_app_id);
if (extension)
OpenChromeCameraApp(profile, event_flags, extension);
else
ShowWebStore(profile, event_flags, chrome_app_id);
}
bool IsArcPOrAbove(const base::Optional<arc::ArcFeatures>& read_result) {
if (read_result == base::nullopt)
return false;
const std::string version_str =
read_result.value().build_props.at("ro.build.version.sdk");
int version = 0;
VLOG(1) << "ARC version is " << version_str;
return base::StringToInt(version_str, &version) && version >= 28;
} }
void ShowCameraApp(Profile* profile, int event_flags) { void OnArcFeaturesRead(Profile* profile,
std::string chrome_app_id(kChromeCameraAppId); int event_flags,
base::Optional<arc::ArcFeatures> read_result) {
bool arc_p_or_above = IsArcPOrAbove(read_result);
const std::string chrome_app_id(kChromeCameraAppId);
const extensions::ExtensionRegistry* registry = const extensions::ExtensionRegistry* registry =
extensions::ExtensionRegistry::Get(profile); extensions::ExtensionRegistry::Get(profile);
const extensions::Extension* extension = const extensions::Extension* extension =
...@@ -180,9 +237,13 @@ void ShowCameraApp(Profile* profile, int event_flags) { ...@@ -180,9 +237,13 @@ void ShowCameraApp(Profile* profile, int event_flags) {
bool arc_enabled = arc::IsArcPlayStoreEnabledForProfile(profile); bool arc_enabled = arc::IsArcPlayStoreEnabledForProfile(profile);
bool chrome_camera_migrated = bool chrome_camera_migrated =
profile->GetPrefs()->GetBoolean(prefs::kCameraMediaConsolidated); profile->GetPrefs()->GetBoolean(prefs::kCameraMediaConsolidated);
AppListClientImpl* controller = AppListClientImpl::GetInstance();
if (arc_enabled && (!extension || chrome_camera_migrated)) { VLOG(1) << "Launching camera app. arc_enabled = " << arc_enabled
<< " arc_p_or_above = " << arc_p_or_above
<< " chrome_camera_migrated = " << chrome_camera_migrated
<< " cca_exist = " << (extension != nullptr);
if (arc_enabled && arc_p_or_above && (!extension || chrome_camera_migrated)) {
// Open Google camera app or GCA migration app according to GCA // Open Google camera app or GCA migration app according to GCA
// migration system property. // migration system property.
arc::ArcPropertyBridge* property = arc::ArcPropertyBridge* property =
...@@ -190,20 +251,9 @@ void ShowCameraApp(Profile* profile, int event_flags) { ...@@ -190,20 +251,9 @@ void ShowCameraApp(Profile* profile, int event_flags) {
property->GetGcaMigrationProperty( property->GetGcaMigrationProperty(
base::BindOnce(&OnGetMigrationProperty, profile, event_flags)); base::BindOnce(&OnGetMigrationProperty, profile, event_flags));
} else if (extension) { } else if (extension) {
// Open Chrome camera app. OpenChromeCameraApp(profile, event_flags, extension);
AppLaunchParams params = CreateAppLaunchParamsWithEventFlags(
profile, extension, event_flags, extensions::SOURCE_APP_LAUNCHER,
controller->GetAppListDisplayId());
params.launch_id = ash::ShelfID(extension->id()).launch_id;
OpenApplication(params);
} else { } else {
// Open Chrome camera app detail page in CWS. ShowWebStore(profile, event_flags, chrome_app_id);
const GURL store_url = net::AppendQueryParameter(
GURL(extension_urls::GetWebstoreItemDetailURLPrefix() + chrome_app_id),
extension_urls::kWebstoreSourceField,
extension_urls::kLaunchSourceAppListSearch);
controller->OpenURL(profile, store_url, ui::PAGE_TRANSITION_LINK,
ui::DispositionFromEventFlags(event_flags));
} }
} }
...@@ -215,7 +265,8 @@ void OpenInternalApp(const std::string& app_id, ...@@ -215,7 +265,8 @@ void OpenInternalApp(const std::string& app_id,
} else if (app_id == kInternalAppIdSettings) { } else if (app_id == kInternalAppIdSettings) {
chrome::ShowSettingsSubPageForProfile(profile, std::string()); chrome::ShowSettingsSubPageForProfile(profile, std::string());
} else if (app_id == kInternalAppIdCamera) { } else if (app_id == kInternalAppIdCamera) {
ShowCameraApp(profile, event_flags); arc::ArcFeaturesParser::GetArcFeatures(
base::BindOnce(&OnArcFeaturesRead, profile, event_flags));
} else if (app_id == kInternalAppIdDiscover) { } else if (app_id == kInternalAppIdDiscover) {
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
base::RecordAction(base::UserMetricsAction("ShowDiscover")); base::RecordAction(base::UserMetricsAction("ShowDiscover"));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment