From 91314059d0286ce81a2bbbda03a33fde0ecc4403 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Fri, 10 May 2024 10:37:30 +0200 Subject: [PATCH] augment FUS consent condition to honor the usage of non-commercial license (required for IJPL-149367) GitOrigin-RevId: 33537ccf18914b7f3d4a28b6467b566c16d9b686 --- platform/core-api/api-dump-unreviewed.txt | 1 + .../intellij/ide/ConsentOptionsProvider.java | 4 +++- .../ide/gdpr/ConsentOptionsProviderImpl.java | 11 +++++++++- .../utils/StatisticsUploadAssistant.java | 21 ++++++++++++++----- 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/platform/core-api/api-dump-unreviewed.txt b/platform/core-api/api-dump-unreviewed.txt index 11176b067bd1..cccc7e72ed00 100644 --- a/platform/core-api/api-dump-unreviewed.txt +++ b/platform/core-api/api-dump-unreviewed.txt @@ -257,6 +257,7 @@ e:com.intellij.formatting.FormattingMode - s:valueOf(java.lang.String):com.intellij.formatting.FormattingMode - s:values():com.intellij.formatting.FormattingMode[] com.intellij.ide.ConsentOptionsProvider +- a:isActivatedWithFreeLicense():Z - a:isEAP():Z - a:isSendingUsageStatsAllowed():Z - a:setSendingUsageStatsAllowed(Z):V diff --git a/platform/core-api/src/com/intellij/ide/ConsentOptionsProvider.java b/platform/core-api/src/com/intellij/ide/ConsentOptionsProvider.java index 647cc7aad228..8506278ffe0e 100644 --- a/platform/core-api/src/com/intellij/ide/ConsentOptionsProvider.java +++ b/platform/core-api/src/com/intellij/ide/ConsentOptionsProvider.java @@ -1,10 +1,12 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.ide; public interface ConsentOptionsProvider { boolean isEAP(); + boolean isActivatedWithFreeLicense(); + void setSendingUsageStatsAllowed(boolean allowed); boolean isSendingUsageStatsAllowed(); diff --git a/platform/platform-impl/src/com/intellij/ide/gdpr/ConsentOptionsProviderImpl.java b/platform/platform-impl/src/com/intellij/ide/gdpr/ConsentOptionsProviderImpl.java index 52466ca32358..f74f9ca6731d 100644 --- a/platform/platform-impl/src/com/intellij/ide/gdpr/ConsentOptionsProviderImpl.java +++ b/platform/platform-impl/src/com/intellij/ide/gdpr/ConsentOptionsProviderImpl.java @@ -1,7 +1,8 @@ -// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.ide.gdpr; import com.intellij.ide.ConsentOptionsProvider; +import com.intellij.ui.LicensingFacade; final class ConsentOptionsProviderImpl implements ConsentOptionsProvider { @Override @@ -9,6 +10,14 @@ final class ConsentOptionsProviderImpl implements ConsentOptionsProvider { return ConsentOptions.getInstance().isEAP(); } + @Override + public boolean isActivatedWithFreeLicense() { + // Using free non-commercial license is by EULA a consent to sending feature usage statistics for product improvements + LicensingFacade facade = LicensingFacade.getInstance(); + String meta = facade != null? facade.metadata : null; + return meta != null && meta.length() > 10 && meta.charAt(10) == 'F'; + } + @Override public void setSendingUsageStatsAllowed(boolean allowed) { ConsentOptions.getInstance().setSendingUsageStatsAllowed(allowed); diff --git a/platform/statistics/src/com/intellij/internal/statistic/utils/StatisticsUploadAssistant.java b/platform/statistics/src/com/intellij/internal/statistic/utils/StatisticsUploadAssistant.java index 48796e61b988..cfd6bc65f2be 100755 --- a/platform/statistics/src/com/intellij/internal/statistic/utils/StatisticsUploadAssistant.java +++ b/platform/statistics/src/com/intellij/internal/statistic/utils/StatisticsUploadAssistant.java @@ -1,6 +1,7 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.internal.statistic.utils; +import com.intellij.ide.ConsentOptionsProvider; import com.intellij.internal.statistic.eventLog.*; import com.intellij.internal.statistic.eventLog.connection.EventLogSendListener; import com.intellij.internal.statistic.eventLog.connection.EventLogStatisticsService; @@ -34,8 +35,7 @@ public final class StatisticsUploadAssistant { return isHeadlessStatisticsEnabled(); } - UsageStatisticsPersistenceComponent settings = UsageStatisticsPersistenceComponent.getInstance(); - return settings != null && settings.isAllowed(); + return isAllowedByUserConsent(); } public static boolean isCollectAllowed() { @@ -44,14 +44,25 @@ public final class StatisticsUploadAssistant { } if (!isDisableCollectStatistics() && !isCollectionForceDisabled()) { - UsageStatisticsPersistenceComponent settings = UsageStatisticsPersistenceComponent.getInstance(); - if ((settings != null && settings.isAllowed()) || isLocalStatisticsWithoutReport()) { + if (isAllowedByUserConsent() || isLocalStatisticsWithoutReport()) { return true; } } return false; } + public static boolean isAllowedByUserConsent() { + UsageStatisticsPersistenceComponent settings = UsageStatisticsPersistenceComponent.getInstance(); + if (settings != null && settings.isAllowed()) { + return true; + } + ConsentOptionsProvider consentsProvider = ApplicationManager.getApplication().getService(ConsentOptionsProvider.class); + if (consentsProvider != null && consentsProvider.isActivatedWithFreeLicense()) { + return true; + } + return false; + } + private static boolean isForceCollectEnabled() { return StatisticsEventLogProviderUtil.forceLoggingAlwaysEnabled(); }