[WebLayer] Move ChromeFeatureList.GENERIC_SENSOR_EXTRA_CLASSES to //services/device
This CL moves the Java-side definition of the kGenericSensorExtraClasses Feature from ChromeFeatureList to a new DeviceFeatureList class that lives in //services/device/public/java. This will allow non-Chrome embedders to query the status of the Feature from Java. Bug: 1058597 Change-Id: Iab3c75fea6c8755de52714be7776547a774842d4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2095445 Commit-Queue: Robbie McElrath <rmcelrath@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Reviewed-by: Ted Choc <tedchoc@chromium.org> Reviewed-by: Colin Blundell <blundell@chromium.org> Cr-Commit-Position: refs/heads/master@{#750245}
This commit is contained in:

committed by
Commit Bot

parent
fb4a98ca1f
commit
27d1fe94c6
@ -353,6 +353,7 @@ android_library("chrome_java") {
|
||||
"//net/android:net_java",
|
||||
"//printing:printing_java",
|
||||
"//services/data_decoder/public/cpp/android:safe_json_java",
|
||||
"//services/device/public/java:device_feature_list_java",
|
||||
"//services/media_session/public/cpp/android:media_session_java",
|
||||
"//services/media_session/public/mojom:mojom_java",
|
||||
"//services/network/public/mojom:mojom_java",
|
||||
|
@ -28,5 +28,6 @@ include_rules = [
|
||||
"+components/viz/common/java",
|
||||
"+jni",
|
||||
"+media/base/android/java",
|
||||
"+services/device/public",
|
||||
"+services/media_session/public",
|
||||
]
|
||||
|
@ -15,8 +15,8 @@ import androidx.annotation.Nullable;
|
||||
import org.chromium.base.ApiCompatibilityUtils;
|
||||
import org.chromium.base.ThreadUtils;
|
||||
import org.chromium.chrome.R;
|
||||
import org.chromium.chrome.browser.flags.ChromeFeatureList;
|
||||
import org.chromium.components.content_settings.ContentSettingsType;
|
||||
import org.chromium.device.DeviceFeatureList;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -190,15 +190,15 @@ public class ContentSettingsResources {
|
||||
int sensorsBlockedDescription =
|
||||
R.string.website_settings_category_motion_sensors_blocked;
|
||||
try {
|
||||
if (ChromeFeatureList.isEnabled(ChromeFeatureList.GENERIC_SENSOR_EXTRA_CLASSES)) {
|
||||
if (DeviceFeatureList.isEnabled(DeviceFeatureList.GENERIC_SENSOR_EXTRA_CLASSES)) {
|
||||
sensorsPermissionTitle = R.string.sensors_permission_title;
|
||||
sensorsAllowedDescription = R.string.website_settings_category_sensors_allowed;
|
||||
sensorsBlockedDescription = R.string.website_settings_category_sensors_blocked;
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
// We can hit this in tests that use the @Features annotation, as it calls
|
||||
// ChromeFeatureList.setTestFeatures() with a map that should not need to contain
|
||||
// ChromeFeatureList.GENERIC_SENSOR_EXTRA_CLASSES.
|
||||
// FeatureList.setTestFeatures() with a map that should not need to contain
|
||||
// DeviceFeatureList.GENERIC_SENSOR_EXTRA_CLASSES.
|
||||
}
|
||||
localMap.put(ContentSettingsType.SENSORS,
|
||||
new ResourceItem(R.drawable.settings_sensors, sensorsPermissionTitle,
|
||||
|
@ -3025,6 +3025,7 @@ jumbo_static_library("browser") {
|
||||
"//rlz:rlz_utils",
|
||||
"//sandbox",
|
||||
"//sandbox:sandbox_buildflags",
|
||||
"//services/device/public/cpp:device_feature_list",
|
||||
"//services/proxy_resolver:lib",
|
||||
"//third_party/android_ndk:cpu_features",
|
||||
"//third_party/android_opengl/etc1",
|
||||
|
@ -285,7 +285,6 @@ public abstract class ChromeFeatureList {
|
||||
public static final String EXPLORE_SITES = "ExploreSites";
|
||||
public static final String FOCUS_OMNIBOX_IN_INCOGNITO_TAB_INTENTS =
|
||||
"FocusOmniboxInIncognitoTabIntents";
|
||||
public static final String GENERIC_SENSOR_EXTRA_CLASSES = "GenericSensorExtraClasses";
|
||||
public static final String GRANT_NOTIFICATIONS_TO_DSE = "GrantNotificationsToDSE";
|
||||
public static final String HANDLE_MEDIA_INTENTS = "HandleMediaIntents";
|
||||
public static final String HOMEPAGE_LOCATION_POLICY = "HomepageLocationPolicy";
|
||||
|
@ -349,6 +349,7 @@ if (is_android) {
|
||||
generate_jni("device_service_jni_headers") {
|
||||
sources = [
|
||||
"android/java/src/org/chromium/services/device/InterfaceRegistrar.java",
|
||||
"public/java/src/org/chromium/device/DeviceFeatureList.java",
|
||||
]
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,17 @@ component("device_features") {
|
||||
defines = [ "DEVICE_FEATURES_IMPLEMENTATION" ]
|
||||
}
|
||||
|
||||
if (is_android) {
|
||||
source_set("device_feature_list") {
|
||||
sources = [ "device_feature_list.cc" ]
|
||||
deps = [
|
||||
":device_features",
|
||||
"//base",
|
||||
"//services/device:device_service_jni_headers",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
source_set("test_support") {
|
||||
testonly = true
|
||||
|
||||
|
50
services/device/public/cpp/device_feature_list.cc
Normal file
50
services/device/public/cpp/device_feature_list.cc
Normal file
@ -0,0 +1,50 @@
|
||||
// Copyright 2020 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "base/android/jni_string.h"
|
||||
#include "base/feature_list.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "services/device/device_service_jni_headers/DeviceFeatureList_jni.h"
|
||||
#include "services/device/public/cpp/device_features.h"
|
||||
|
||||
using base::android::ConvertJavaStringToUTF8;
|
||||
using base::android::JavaParamRef;
|
||||
|
||||
namespace features {
|
||||
|
||||
namespace {
|
||||
|
||||
// Array of features exposed through the Java ContentFeatureList API. Entries in
|
||||
// this array may either refer to features defined in the header of this file or
|
||||
// in other locations in the code base (e.g. content_features.h).
|
||||
const base::Feature* kFeaturesExposedToJava[] = {
|
||||
&kGenericSensorExtraClasses,
|
||||
};
|
||||
|
||||
// TODO(crbug.com/1060097): Removethis once a generalized FeatureList exists.
|
||||
const base::Feature* FindFeatureExposedToJava(const std::string& feature_name) {
|
||||
for (size_t i = 0; i < base::size(kFeaturesExposedToJava); ++i) {
|
||||
if (kFeaturesExposedToJava[i]->name == feature_name)
|
||||
return kFeaturesExposedToJava[i];
|
||||
}
|
||||
NOTREACHED() << "Queried feature cannot be found in DeviceFeatureList: "
|
||||
<< feature_name;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
static jboolean JNI_DeviceFeatureList_IsInitialized(JNIEnv* env) {
|
||||
return !!base::FeatureList::GetInstance();
|
||||
}
|
||||
|
||||
static jboolean JNI_DeviceFeatureList_IsEnabled(
|
||||
JNIEnv* env,
|
||||
const JavaParamRef<jstring>& jfeature_name) {
|
||||
const base::Feature* feature =
|
||||
FindFeatureExposedToJava(ConvertJavaStringToUTF8(env, jfeature_name));
|
||||
return base::FeatureList::IsEnabled(*feature);
|
||||
}
|
||||
|
||||
} // namespace features
|
@ -4,6 +4,15 @@
|
||||
|
||||
import("//build/config/android/rules.gni")
|
||||
|
||||
android_library("device_feature_list_java") {
|
||||
sources = [ "src/org/chromium/device/DeviceFeatureList.java" ]
|
||||
deps = [
|
||||
"//base:base_java",
|
||||
"//base:jni_java",
|
||||
]
|
||||
annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ]
|
||||
}
|
||||
|
||||
android_library("nfc_java") {
|
||||
sources = [ "src/org/chromium/device/nfc/NfcDelegate.java" ]
|
||||
deps = [ "//base:base_java" ]
|
||||
|
@ -0,0 +1,63 @@
|
||||
// Copyright 2020 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package org.chromium.device;
|
||||
|
||||
import org.chromium.base.FeatureList;
|
||||
import org.chromium.base.annotations.JNINamespace;
|
||||
import org.chromium.base.annotations.MainDex;
|
||||
import org.chromium.base.annotations.NativeMethods;
|
||||
import org.chromium.base.library_loader.LibraryLoader;
|
||||
|
||||
/**
|
||||
* Provides an API for querying the status of Device Service Features.
|
||||
*/
|
||||
// TODO(crbug.com/1060097): Remove/update this once a generalized FeatureList exists.
|
||||
@JNINamespace("features")
|
||||
@MainDex
|
||||
public class DeviceFeatureList {
|
||||
public static final String GENERIC_SENSOR_EXTRA_CLASSES = "GenericSensorExtraClasses";
|
||||
|
||||
private DeviceFeatureList() {}
|
||||
|
||||
/**
|
||||
* Returns whether the specified feature is enabled or not.
|
||||
*
|
||||
* Note: Features queried through this API must be added to the array
|
||||
* |kFeaturesExposedToJava| in //services/device/public/cpp/device_features.cc
|
||||
*
|
||||
* @param featureName The name of the feature to query.
|
||||
* @return Whether the feature is enabled or not.
|
||||
*/
|
||||
public static boolean isEnabled(String featureName) {
|
||||
Boolean testValue = FeatureList.getTestValueForFeature(featureName);
|
||||
if (testValue != null) return testValue;
|
||||
assert isNativeInitialized();
|
||||
return DeviceFeatureListJni.get().isEnabled(featureName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Whether the native FeatureList is initialized or not.
|
||||
*/
|
||||
private static boolean isNativeInitialized() {
|
||||
if (FeatureList.hasTestFeatures()) return true;
|
||||
|
||||
if (!LibraryLoader.getInstance().isInitialized()) return false;
|
||||
// Even if the native library is loaded, the C++ FeatureList might not be initialized yet.
|
||||
// In that case, accessing it will not immediately fail, but instead cause a crash later
|
||||
// when it is initialized. Return whether the native FeatureList has been initialized,
|
||||
// so the return value can be tested, or asserted for a more actionable stack trace
|
||||
// on failure.
|
||||
//
|
||||
// The FeatureList is however guaranteed to be initialized by the time
|
||||
// AsyncInitializationActivity#finishNativeInitialization is called.
|
||||
return DeviceFeatureListJni.get().isInitialized();
|
||||
}
|
||||
|
||||
@NativeMethods
|
||||
interface Natives {
|
||||
boolean isInitialized();
|
||||
boolean isEnabled(String featureName);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user