π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][photos] Gate mosaic layout to internal users
ashil-pilot41fd852526e7
diff --git a/mobile/apps/photos/lib/main.dart b/mobile/apps/photos/lib/main.dartindex ec39904f35..327461bd37 100644--- a/mobile/apps/photos/lib/main.dart+++ b/mobile/apps/photos/lib/main.dart@@ -36,6 +36,7 @@ import 'package:photos/db/files_db.dart';import "package:photos/db/ml/db.dart";import 'package:photos/ente_theme_data.dart';import "package:photos/locale.dart";+import "package:photos/models/gallery/gallery_layout_config.dart";import 'package:photos/module/upload/service/file_uploader.dart';import 'package:photos/module/upload/service/local_file_update_service.dart';import "package:photos/service_locator.dart";@@ -599,13 +600,17 @@ void _logRustEntry(Logger logger, String level, String target, String body) {}void logLocalSettings() {+ final storedGalleryLayout = localSettings.getGalleryLayoutType();+ final effectiveGalleryLayout = resolveGalleryLayoutType(storedGalleryLayout);final settings = {'Show memories': memoriesCacheService.showAnyMemories,'Smart memories enabled': localSettings.isSmartMemoriesEnabled,'ML enabled': flagService.hasGrantedMLConsent,'ML local indexing enabled': localSettings.isMLLocalIndexingEnabled,'Multipart upload enabled': localSettings.userEnabledMultiplePart,- 'Gallery layout': localSettings.getGalleryLayoutType().name,+ 'Gallery layout': effectiveGalleryLayout.name,+ if (storedGalleryLayout != effectiveGalleryLayout)+ 'Stored gallery layout': storedGalleryLayout.name,'Gallery grid size': localSettings.getPhotoGridSize(),'Video streaming enabled':VideoPreviewService.instance.isVideoStreamingEnabled,diff --git a/mobile/apps/photos/lib/models/gallery/gallery_groups.dart b/mobile/apps/photos/lib/models/gallery/gallery_groups.dartindex bbf7c6b9ba..27cc7d9582 100644--- a/mobile/apps/photos/lib/models/gallery/gallery_groups.dart+++ b/mobile/apps/photos/lib/models/gallery/gallery_groups.dart@@ -8,6 +8,7 @@ import "package:photos/models/file/dummy_file.dart";import "package:photos/models/file/file.dart";import "package:photos/models/gallery/fixed_extent_grid_row.dart";import "package:photos/models/gallery/fixed_extent_section_layout.dart";+import "package:photos/models/gallery/gallery_layout_config.dart";import "package:photos/models/gallery/mosaic_grid_row.dart";import "package:photos/models/gallery/mosaic_layout.dart";import "package:photos/models/gallery/section_layout.dart";@@ -30,6 +31,7 @@ class GalleryGroups {final _logger = Logger("GalleryGroups");final bool showGallerySettingsCTA;final GalleryLayoutType? layoutTypeOverride;+ final bool mosaicLayoutAvailable;final bool sortOrderAsc;final double widthAvailable;@@ -46,6 +48,7 @@ class GalleryGroups {this.limitSelectionToOne = false,this.showGallerySettingsCTA = false,this.layoutTypeOverride,+ required this.mosaicLayoutAvailable,}) {init();if (!groupType.showGroupHeader()) {@@ -260,7 +263,10 @@ class GalleryGroups {void init() {crossAxisCount = localSettings.getPhotoGridSize();- layoutType = layoutTypeOverride ?? localSettings.getGalleryLayoutType();+ layoutType = resolveGalleryLayoutType(+ layoutTypeOverride ?? localSettings.getGalleryLayoutType(),+ mosaicLayoutAvailable: mosaicLayoutAvailable,+ );_buildGroups();_groupLayouts = switch (layoutType) {diff --git a/mobile/apps/photos/lib/models/gallery/gallery_layout_config.dart b/mobile/apps/photos/lib/models/gallery/gallery_layout_config.dartnew file mode 100644index 0000000000..3950050be3--- /dev/null+++ b/mobile/apps/photos/lib/models/gallery/gallery_layout_config.dart@@ -0,0 +1,17 @@+import "package:photos/service_locator.dart";+import "package:photos/settings/local_settings.dart";++// FlagService treats debug builds as internal while still honoring the+// developer setting that disables internal-user features.+bool get isMosaicLayoutAvailable => flagService.internalUser;++GalleryLayoutType resolveGalleryLayoutType(+ GalleryLayoutType preferredLayoutType, {+ bool? mosaicLayoutAvailable,+}) {+ final isAvailable = mosaicLayoutAvailable ?? isMosaicLayoutAvailable;+ if (preferredLayoutType == GalleryLayoutType.mosaic && !isAvailable) {+ return GalleryLayoutType.grid;+ }+ return preferredLayoutType;+}diff --git a/mobile/apps/photos/lib/ui/settings/gallery_settings_screen.dart b/mobile/apps/photos/lib/ui/settings/gallery_settings_screen.dartindex 2f6aa6b91d..6ca11eddb0 100644--- a/mobile/apps/photos/lib/ui/settings/gallery_settings_screen.dart+++ b/mobile/apps/photos/lib/ui/settings/gallery_settings_screen.dart@@ -5,6 +5,7 @@ import "package:photos/core/constants.dart";import "package:photos/core/event_bus.dart";import "package:photos/events/gallery_layout_changed_event.dart";import "package:photos/events/hide_shared_items_from_home_gallery_event.dart";+import "package:photos/models/gallery/gallery_layout_config.dart";import "package:photos/service_locator.dart";import "package:photos/settings/local_settings.dart";import "package:photos/ui/viewer/gallery/component/group/type.dart";@@ -28,7 +29,9 @@ class _GallerySettingsScreenState extends State<GallerySettingsScreen> {@overridevoid initState() {super.initState();- _layoutType = localSettings.getGalleryLayoutType();+ _layoutType = resolveGalleryLayoutType(+ localSettings.getGalleryLayoutType(),+ );_photoGridSize = localSettings.getPhotoGridSize();_groupType = localSettings.getGalleryGroupType();}@@ -40,15 +43,17 @@ class _GallerySettingsScreenState extends State<GallerySettingsScreen> {return SettingsPageScaffold(title: l10n.gallery,children: [- SettingsItem(- title: l10n.layout,- trailing: _trailingLabel(- context,- _layoutTypeLabel(context, _layoutType),+ if (isMosaicLayoutAvailable) ...[+ SettingsItem(+ title: l10n.layout,+ trailing: _trailingLabel(+ context,+ _layoutTypeLabel(context, _layoutType),+ ),+ onTap: () async => _showLayoutTypeSheet(context),),- onTap: () async => _showLayoutTypeSheet(context),- ),- const SizedBox(height: 8),+ const SizedBox(height: 8),+ ],SettingsItem(title: l10n.photoGridSize,trailing: _trailingLabel(context, _photoGridSize.toString()),@@ -104,6 +109,7 @@ class _GallerySettingsScreenState extends State<GallerySettingsScreen> {}Future<void> _showLayoutTypeSheet(BuildContext context) async {+ if (!isMosaicLayoutAvailable) return;final l10n = context.strings;await showBottomSheetComponent<void>(context: context,@@ -135,6 +141,9 @@ class _GallerySettingsScreenState extends State<GallerySettingsScreen> {}Future<void> _setLayoutType(GalleryLayoutType layoutType) async {+ if (layoutType == GalleryLayoutType.mosaic && !isMosaicLayoutAvailable) {+ return;+ }if (localSettings.getGalleryLayoutType() == layoutType) return;await localSettings.setGalleryLayoutType(layoutType);if (mounted) {diff --git a/mobile/apps/photos/lib/ui/settings/search/settings_search_registry.dart b/mobile/apps/photos/lib/ui/settings/search/settings_search_registry.dartindex 66c1182d84..2b5121f8aa 100644--- a/mobile/apps/photos/lib/ui/settings/search/settings_search_registry.dart+++ b/mobile/apps/photos/lib/ui/settings/search/settings_search_registry.dart@@ -6,6 +6,7 @@ import "package:flutter/foundation.dart";import "package:flutter/material.dart";import "package:hugeicons/hugeicons.dart";import "package:photos/core/configuration.dart";+import "package:photos/models/gallery/gallery_layout_config.dart";import "package:photos/service_locator.dart";import "package:photos/ui/settings/about/about_us_page.dart";import "package:photos/ui/settings/account/account_settings_page.dart";@@ -27,6 +28,7 @@ class SettingsSearchRegistry {final hasLoggedIn = Configuration.instance.isLoggedIn();final isLocalGallery = isLocalGalleryMode;final showThemeControls = Platform.isAndroid || kDebugMode;+ final showMosaicLayout = isMosaicLayoutAvailable;final items = <SettingsSearchItem>[];if (hasLoggedIn && !isLocalGallery) {@@ -315,22 +317,30 @@ class SettingsSearchRegistry {routeBuilder: (_) =>const GallerySettingsScreen(fromGalleryLayoutSettingsCTA: false),isSubPage: true,- keywords: ["grid size", "group by", "layout", "masonry", "mosaic"],+ keywords: [+ "grid size",+ "group by",+ "layout",+ if (showMosaicLayout) "masonry",+ if (showMosaicLayout) "mosaic",+ ],),);- items.add(- SettingsSearchItem(- title: l10n.layout,- subtitle: l10n.gallery,- sectionPath: "${l10n.appearance} > ${l10n.gallery}",- icon: HugeIcons.strokeRoundedDashboardSquare02,- routeBuilder: (_) =>- const GallerySettingsScreen(fromGalleryLayoutSettingsCTA: false),- isSubPage: true,- keywords: ["layout", "grid", "masonry", "mosaic", "justified"],- ),- );+ if (showMosaicLayout) {+ items.add(+ SettingsSearchItem(+ title: l10n.layout,+ subtitle: l10n.gallery,+ sectionPath: "${l10n.appearance} > ${l10n.gallery}",+ icon: HugeIcons.strokeRoundedDashboardSquare02,+ routeBuilder: (_) =>+ const GallerySettingsScreen(fromGalleryLayoutSettingsCTA: false),+ isSubPage: true,+ keywords: ["layout", "grid", "masonry", "mosaic", "justified"],+ ),+ );+ }items.add(SettingsSearchItem(diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart b/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dartindex a71ce66422..efcaf1cad7 100644--- a/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart+++ b/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart@@ -19,6 +19,7 @@ import 'package:photos/events/tab_changed_event.dart';import 'package:photos/models/file/file.dart';import 'package:photos/models/file_load_result.dart';import "package:photos/models/gallery/gallery_groups.dart";+import "package:photos/models/gallery/gallery_layout_config.dart";import "package:photos/models/gallery_type.dart";import 'package:photos/models/selected_files.dart';import "package:photos/service_locator.dart" show localSettings;@@ -395,6 +396,7 @@ class GalleryState extends State<Gallery> {limitSelectionToOne: widget.limitSelectionToOne,showGallerySettingsCTA: widget.showGallerySettingsCTA,layoutTypeOverride: widget.layoutTypeOverride,+ mosaicLayoutAvailable: isMosaicLayoutAvailable,);galleryGroups = groups;diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/layout_settings.dart b/mobile/apps/photos/lib/ui/viewer/gallery/layout_settings.dartindex 288fee6020..827dd6802f 100644--- a/mobile/apps/photos/lib/ui/viewer/gallery/layout_settings.dart+++ b/mobile/apps/photos/lib/ui/viewer/gallery/layout_settings.dart@@ -6,6 +6,7 @@ import "package:ente_strings/ente_strings.dart";import "package:flutter/material.dart";import "package:photos/core/event_bus.dart";import "package:photos/events/gallery_layout_changed_event.dart";+import "package:photos/models/gallery/gallery_layout_config.dart";import "package:photos/service_locator.dart";import "package:photos/settings/local_settings.dart";import "package:photos/ui/settings/gallery_settings_screen.dart";@@ -19,30 +20,35 @@ class GalleryLayoutSettings extends StatefulWidget {}class _GalleryLayoutSettingsState extends State<GalleryLayoutSettings> {- bool isDayLayout =- localSettings.getGalleryLayoutType() == GalleryLayoutType.grid &&- localSettings.getGalleryGroupType() == GroupType.day &&- localSettings.getPhotoGridSize() == 3;- bool isMonthLayout =- localSettings.getGalleryLayoutType() == GalleryLayoutType.grid &&- localSettings.getGalleryGroupType() == GroupType.month &&- localSettings.getPhotoGridSize() == 5;- bool isMosaicLayout =- localSettings.getGalleryLayoutType() == GalleryLayoutType.mosaic;+ late bool isDayLayout;+ late bool isMonthLayout;+ late bool isMosaicLayout;++ @override+ void initState() {+ super.initState();+ _readLatestSetting();+ }++ void _readLatestSetting() {+ final layoutType = resolveGalleryLayoutType(+ localSettings.getGalleryLayoutType(),+ );+ isDayLayout =+ layoutType == GalleryLayoutType.grid &&+ localSettings.getGalleryGroupType() == GroupType.day &&+ localSettings.getPhotoGridSize() == 3;+ isMonthLayout =+ layoutType == GalleryLayoutType.grid &&+ localSettings.getGalleryGroupType() == GroupType.month &&+ localSettings.getPhotoGridSize() == 5;+ isMosaicLayout = layoutType == GalleryLayoutType.mosaic;+ }void _reloadWithLatestSetting() {if (!mounted) return;setState(() {- isDayLayout =- localSettings.getGalleryLayoutType() == GalleryLayoutType.grid &&- localSettings.getGalleryGroupType() == GroupType.day &&- localSettings.getPhotoGridSize() == 3;- isMonthLayout =- localSettings.getGalleryLayoutType() == GalleryLayoutType.grid &&- localSettings.getGalleryGroupType() == GroupType.month &&- localSettings.getPhotoGridSize() == 5;- isMosaicLayout =- localSettings.getGalleryLayoutType() == GalleryLayoutType.mosaic;+ _readLatestSetting();});}@@ -71,15 +77,16 @@ class _GalleryLayoutSettingsState extends State<GalleryLayoutSettings> {showOnlyLoadingState: true,onTap: () => _applyLayout(GroupType.month, 5),),- MenuComponent(- title: context.strings.layoutMasonry,- leading: const Icon(Icons.view_quilt_outlined),- trailing: isMosaicLayout- ? Icon(Icons.check, color: colors.primary)- : null,- showOnlyLoadingState: true,- onTap: _applyMosaicLayout,- ),+ if (isMosaicLayoutAvailable)+ MenuComponent(+ title: context.strings.layoutMasonry,+ leading: const Icon(Icons.view_quilt_outlined),+ trailing: isMosaicLayout+ ? Icon(Icons.check, color: colors.primary)+ : null,+ showOnlyLoadingState: true,+ onTap: _applyMosaicLayout,+ ),MenuComponent(title: context.strings.custom,trailing: Row(@@ -126,6 +133,7 @@ class _GalleryLayoutSettingsState extends State<GalleryLayoutSettings> {}Future<void> _applyMosaicLayout() async {+ if (!isMosaicLayoutAvailable) return;if (localSettings.getGalleryLayoutType() != GalleryLayoutType.mosaic) {await localSettings.setGalleryLayoutType(GalleryLayoutType.mosaic);Bus.instance.fire(GalleryLayoutChangedEvent());diff --git a/mobile/apps/photos/plugins/ente_feature_flag/lib/src/service.dart b/mobile/apps/photos/plugins/ente_feature_flag/lib/src/service.dartindex c8e441f188..17802b4926 100644--- a/mobile/apps/photos/plugins/ente_feature_flag/lib/src/service.dart+++ b/mobile/apps/photos/plugins/ente_feature_flag/lib/src/service.dart@@ -23,22 +23,28 @@ class FlagService {final SharedPreferences _prefs;final Dio _enteDio;- FlagService(this._prefs, this._enteDio) {- Future.delayed(const Duration(seconds: 5), () {- _fetch();- });+ FlagService(this._prefs, this._enteDio, {bool autoRefresh = true}) {+ if (autoRefresh) {+ Future.delayed(const Duration(seconds: 5), () {+ _fetch();+ });+ }}RemoteFlags? _flags;+ String? _flagsJson;RemoteFlags get flags {try {if (!_prefs.containsKey("remote_flags")) {_fetch().ignore();}- _flags ??= RemoteFlags.fromMap(- jsonDecode(_prefs.getString("remote_flags") ?? "{}"),- );+ final flagsJson = _prefs.getString("remote_flags");+ if (_flags == null || flagsJson != _flagsJson) {+ final flags = RemoteFlags.fromMap(jsonDecode(flagsJson ?? "{}"));+ _flags = flags;+ _flagsJson = flagsJson;+ }return _flags!;} catch (e) {debugPrint("Failed to get feature flags $e");@@ -154,30 +160,60 @@ class FlagService {}Completer<void>? _fetchCompleter;+ String? _fetchToken;+ int? _fetchUserID;+Future<void> _fetch() async {- if (!_prefs.containsKey("token")) {+ final requestToken = _prefs.getString("token");+ final requestUserID = _prefs.getInt(_userIdKey);+ if (requestToken == null) {log("token not found, skip", name: "FlagService");return;}- if (_fetchCompleter != null) {- await _fetchCompleter!.future;++ final pendingFetch = _fetchCompleter;+ if (pendingFetch != null) {+ final isSameAccount =+ _fetchToken == requestToken && _fetchUserID == requestUserID;+ await pendingFetch.future;+ if (!isSameAccount && _isCurrentAccount(requestToken, requestUserID)) {+ await _fetch();+ }return;}- _fetchCompleter = Completer<void>();++ final fetchCompleter = Completer<void>();+ _fetchCompleter = fetchCompleter;+ _fetchToken = requestToken;+ _fetchUserID = requestUserID;try {log("fetching feature flags", name: "FlagService");final response = await _enteDio.get("/remote-store/feature-flags");+ if (!_isCurrentAccount(requestToken, requestUserID)) {+ log(+ "discarding feature flags fetched for a stale account",+ name: "FlagService",+ );+ return;+ }final remoteFlags = RemoteFlags.fromMap(response.data);- await _prefs.setString("remote_flags", remoteFlags.toJson());+ final flagsJson = remoteFlags.toJson();+ await _prefs.setString("remote_flags", flagsJson);_flags = remoteFlags;+ _flagsJson = flagsJson;} catch (e) {debugPrint("Failed to sync feature flags $e");} finally {- _fetchCompleter?.complete();_fetchCompleter = null;+ _fetchToken = null;+ _fetchUserID = null;+ fetchCompleter.complete();}}+ bool _isCurrentAccount(String token, int? userID) =>+ _prefs.getString("token") == token && _prefs.getInt(_userIdKey) == userID;+Future<void> _updateKeyValue(String key, String value) async {try {final response = await _enteDio.post(@@ -194,8 +230,10 @@ class FlagService {}void _updateFlags(RemoteFlags flags) {+ final flagsJson = flags.toJson();_flags = flags;- _prefs.setString("remote_flags", flags.toJson());+ _flagsJson = flagsJson;+ _prefs.setString("remote_flags", flagsJson);_fetch().ignore();}diff --git a/mobile/apps/photos/test/models/gallery_groups_mosaic_test.dart b/mobile/apps/photos/test/models/gallery_groups_mosaic_test.dartindex b03778186d..1f5502a284 100644--- a/mobile/apps/photos/test/models/gallery_groups_mosaic_test.dart+++ b/mobile/apps/photos/test/models/gallery_groups_mosaic_test.dart@@ -216,6 +216,55 @@ void main() {expect(groups.layoutType, GalleryLayoutType.grid);expect(groups.groupLayouts, everyElement(isA<FixedExtentSectionLayout>()));});++ test("mosaic falls back to grid when the rollout is unavailable", () {+ final files = List<EnteFile>.generate(+ 12,+ (index) => _file(+ index: index,+ creationTime: DateTime(2026, 8, 19).microsecondsSinceEpoch,+ width: index.isEven ? 100 : 400,+ height: index.isEven ? 400 : 100,+ ),+ growable: false,+ );++ final publicGroups = _galleryGroups(+ files: files,+ groupType: GroupType.none,+ groupHeaderExtent: GalleryGroups.spacing,+ mosaicLayoutAvailable: false,+ );+ final publicOverrideGroups = _galleryGroups(+ files: files,+ groupType: GroupType.none,+ groupHeaderExtent: GalleryGroups.spacing,+ layoutTypeOverride: GalleryLayoutType.mosaic,+ mosaicLayoutAvailable: false,+ );+ final internalGroups = _galleryGroups(+ files: files,+ groupType: GroupType.none,+ groupHeaderExtent: GalleryGroups.spacing,+ );++ expect(+ localSettings.getGalleryLayoutType(),+ GalleryLayoutType.mosaic,+ reason: "the raw preference should be preserved across rollout changes",+ );+ expect(publicGroups.layoutType, GalleryLayoutType.grid);+ expect(+ publicGroups.groupLayouts,+ everyElement(isA<FixedExtentSectionLayout>()),+ );+ expect(publicOverrideGroups.layoutType, GalleryLayoutType.grid);+ expect(internalGroups.layoutType, GalleryLayoutType.mosaic);+ expect(+ internalGroups.groupLayouts,+ everyElement(isA<MosaicSectionLayout>()),+ );+ });}GalleryGroups _galleryGroups({@@ -224,6 +273,7 @@ GalleryGroups _galleryGroups({required double groupHeaderExtent,bool sortOrderAsc = false,GalleryLayoutType? layoutTypeOverride,+ bool mosaicLayoutAvailable = true,}) {return GalleryGroups(allFiles: files,@@ -235,6 +285,7 @@ GalleryGroups _galleryGroups({groupHeaderExtent: groupHeaderExtent,showSelectAll: false,layoutTypeOverride: layoutTypeOverride,+ mosaicLayoutAvailable: mosaicLayoutAvailable,);}diff --git a/mobile/apps/photos/test/services/flag_service_cache_test.dart b/mobile/apps/photos/test/services/flag_service_cache_test.dartnew file mode 100644index 0000000000..3235f69452--- /dev/null+++ b/mobile/apps/photos/test/services/flag_service_cache_test.dart@@ -0,0 +1,94 @@+import "dart:async";+import "dart:convert";++import "package:dio/dio.dart";+import "package:ente_feature_flag/ente_feature_flag.dart";+import "package:flutter_test/flutter_test.dart";+import "package:shared_preferences/shared_preferences.dart";++void main() {+ TestWidgetsFlutterBinding.ensureInitialized();++ test("feature flags follow preference changes across accounts", () async {+ SharedPreferences.setMockInitialValues({});+ final preferences = await SharedPreferences.getInstance();+ final service = FlagService(preferences, Dio(), autoRefresh: false);++ await preferences.setString(+ "remote_flags",+ jsonEncode({"customDomain": "first.example"}),+ );+ expect(service.flags.customDomain, "first.example");++ await preferences.setString(+ "remote_flags",+ jsonEncode({"customDomain": "second.example"}),+ );+ expect(service.flags.customDomain, "second.example");++ await preferences.remove("remote_flags");+ expect(service.flags.customDomain, isEmpty);+ });++ test("an account switch discards an in-flight flag response", () async {+ SharedPreferences.setMockInitialValues({+ "token": "account-a-token",+ "user_id": 1,+ });+ final preferences = await SharedPreferences.getInstance();+ final firstRequestStarted = Completer<void>();+ final firstResponse = Completer<Map<String, dynamic>>();+ var requestCount = 0;+ final dio = Dio();+ dio.interceptors.add(+ InterceptorsWrapper(+ onRequest: (options, handler) {+ requestCount++;+ if (requestCount == 1) {+ firstRequestStarted.complete();+ firstResponse.future.then((data) {+ handler.resolve(+ Response<dynamic>(+ requestOptions: options,+ data: data,+ statusCode: 200,+ ),+ );+ });+ } else {+ handler.resolve(+ Response<dynamic>(+ requestOptions: options,+ data: {+ "internalUser": false,+ "customDomain": "account-b.example",+ },+ statusCode: 200,+ ),+ );+ }+ },+ ),+ );+ final service = FlagService(preferences, dio, autoRefresh: false);++ final accountARefresh = service.tryRefreshFlags();+ await firstRequestStarted.future;+ expect(requestCount, 1);++ await preferences.clear();+ await preferences.setString("token", "account-b-token");+ await preferences.setInt("user_id", 2);+ final accountBRefresh = service.tryRefreshFlags();++ firstResponse.complete({+ "internalUser": true,+ "customDomain": "account-a.example",+ });+ await Future.wait([accountARefresh, accountBRefresh]);++ expect(requestCount, 2);+ expect(service.flags.internalUser, isFalse);+ expect(service.flags.customDomain, "account-b.example");+ });+}diff --git a/mobile/apps/photos/test/ui/viewer/gallery/gallery_layout_availability_test.dart b/mobile/apps/photos/test/ui/viewer/gallery/gallery_layout_availability_test.dartnew file mode 100644index 0000000000..0a085d085a--- /dev/null+++ b/mobile/apps/photos/test/ui/viewer/gallery/gallery_layout_availability_test.dart@@ -0,0 +1,133 @@+import "package:dio/dio.dart";+import "package:ente_strings/ente_strings.dart";+import "package:ente_ui/models/settings_search_item.dart";+import "package:flutter/material.dart";+import "package:flutter_test/flutter_test.dart";+import "package:package_info_plus/package_info_plus.dart";+import "package:photos/core/configuration.dart";+import "package:photos/ente_theme_data.dart";+import "package:photos/models/gallery/gallery_layout_config.dart";+import "package:photos/service_locator.dart";+import "package:photos/settings/local_settings.dart";+import "package:photos/ui/settings/gallery_settings_screen.dart";+import "package:photos/ui/settings/search/settings_search_registry.dart";+import "package:photos/ui/viewer/gallery/layout_settings.dart";+import "package:shared_preferences/shared_preferences.dart";++void main() {+ TestWidgetsFlutterBinding.ensureInitialized();++ setUpAll(() async {+ SharedPreferences.setMockInitialValues({});+ final preferences = await SharedPreferences.getInstance();+ ServiceLocator.instance.init(+ preferences,+ Dio(),+ Dio(),+ Dio(),+ PackageInfo(+ appName: "Photos",+ packageName: "photos",+ version: "1.0.0",+ buildNumber: "1",+ ),+ );+ try {+ await Configuration.instance.init(preferences);+ } catch (_) {}++ // Construct the delayed flag refresher outside the widget-test fake clock.+ expect(flagService.internalUser, isTrue);+ });++ setUp(() async {+ await localSettings.setInternalUserDisabled(false);+ await localSettings.setGalleryLayoutType(GalleryLayoutType.mosaic);+ });++ tearDown(() async {+ await localSettings.setInternalUserDisabled(false);+ await localSettings.setGalleryLayoutType(GalleryLayoutType.grid);+ });++ testWidgets("public users cannot discover mosaic layout controls", (+ tester,+ ) async {+ await localSettings.setInternalUserDisabled(true);+ expect(isMosaicLayoutAvailable, isFalse);++ await tester.pumpWidget(+ _testApp(const GallerySettingsScreen(fromGalleryLayoutSettingsCTA: true)),+ );+ await tester.pumpAndSettle();+ var context = tester.element(find.byType(GallerySettingsScreen));+ var l10n = context.strings;+ expect(find.text(l10n.layout), findsNothing);+ expect(find.text(l10n.layoutMasonry), findsNothing);++ await tester.pumpWidget(_testApp(const GalleryLayoutSettings()));+ await tester.pumpAndSettle();+ context = tester.element(find.byType(GalleryLayoutSettings));+ l10n = context.strings;+ expect(find.text(l10n.layoutMasonry), findsNothing);++ final searchItems = SettingsSearchRegistry.getSearchableItems(context);+ expect(+ searchItems.every(+ (item) =>+ item.matchType("mosaic") == SettingsSearchMatchType.none &&+ item.matchType("masonry") == SettingsSearchMatchType.none,+ ),+ isTrue,+ );+ expect(searchItems.where((item) => item.title == l10n.layout), isEmpty);+ expect(localSettings.getGalleryLayoutType(), GalleryLayoutType.mosaic);+ });++ testWidgets("internal and debug users can discover mosaic layout controls", (+ tester,+ ) async {+ expect(isMosaicLayoutAvailable, isTrue);++ await tester.pumpWidget(_testApp(const GalleryLayoutSettings()));+ await tester.pumpAndSettle();+ var context = tester.element(find.byType(GalleryLayoutSettings));+ var l10n = context.strings;+ expect(find.text(l10n.layoutMasonry), findsOneWidget);++ await localSettings.setGalleryLayoutType(GalleryLayoutType.grid);+ await tester.pumpWidget(+ _testApp(const GallerySettingsScreen(fromGalleryLayoutSettingsCTA: true)),+ );+ await tester.pumpAndSettle();+ context = tester.element(find.byType(GallerySettingsScreen));+ l10n = context.strings;+ expect(find.text(l10n.layout), findsOneWidget);+ await tester.tap(find.text(l10n.layout));+ await tester.pumpAndSettle();+ expect(find.text(l10n.layoutMasonry), findsOneWidget);+ await tester.tap(find.byKey(const ValueKey(GalleryLayoutType.mosaic)));+ await tester.pumpAndSettle();+ expect(localSettings.getGalleryLayoutType(), GalleryLayoutType.mosaic);++ final searchItems = SettingsSearchRegistry.getSearchableItems(context);+ expect(+ searchItems.any(+ (item) =>+ item.matchType("mosaic") != SettingsSearchMatchType.none &&+ item.matchType("masonry") != SettingsSearchMatchType.none,+ ),+ isTrue,+ );+ expect(searchItems.where((item) => item.title == l10n.layout), isNotEmpty);+ });+}++Widget _testApp(Widget child) {+ return MaterialApp(+ theme: lightThemeData,+ localizationsDelegates: StringsLocalizations.localizationsDelegates,+ supportedLocales: StringsLocalizations.supportedLocales,+ home: Scaffold(body: child),+ );+}diff --git a/mobile/apps/photos/test/ui/viewer/gallery/gallery_layout_changed_event_test.dart b/mobile/apps/photos/test/ui/viewer/gallery/gallery_layout_changed_event_test.dartindex 4420a8a0db..27fedbbbc5 100644--- a/mobile/apps/photos/test/ui/viewer/gallery/gallery_layout_changed_event_test.dart+++ b/mobile/apps/photos/test/ui/viewer/gallery/gallery_layout_changed_event_test.dart@@ -11,6 +11,8 @@ import "package:photos/models/file/dummy_file.dart";import "package:photos/models/file/file.dart";import "package:photos/models/file/file_type.dart";import "package:photos/models/file_load_result.dart";+import "package:photos/models/gallery/fixed_extent_section_layout.dart";+import "package:photos/models/gallery/gallery_layout_config.dart";import "package:photos/models/metadata/file_magic.dart";import "package:photos/service_locator.dart";import "package:photos/settings/local_settings.dart";@@ -43,6 +45,17 @@ void main() {try {await Configuration.instance.init(preferences);} catch (_) {}++ // Construct the delayed flag refresher outside the widget-test fake clock.+ expect(flagService.internalUser, isTrue);+ });++ setUp(() async {+ await localSettings.setInternalUserDisabled(false);+ });++ tearDown(() async {+ await localSettings.setInternalUserDisabled(false);});testWidgets(@@ -135,6 +148,56 @@ void main() {},);+ testWidgets("public galleries ignore a persisted mosaic preference", (+ tester,+ ) async {+ await localSettings.setGalleryLayoutType(GalleryLayoutType.mosaic);+ await localSettings.setInternalUserDisabled(true);+ expect(isMosaicLayoutAvailable, isFalse);++ final galleryKey = GlobalKey<GalleryState>();+ final file = _dummyFile("public");+ await tester.pumpWidget(+ MaterialApp(+ theme: lightThemeData,+ localizationsDelegates: StringsLocalizations.localizationsDelegates,+ supportedLocales: StringsLocalizations.supportedLocales,+ home: _galleryHost(+ Gallery(+ key: galleryKey,+ asyncLoader: (start, end, {limit, asc}) async =>+ FileLoadResult([file], false),+ tagPrefix: "public_",+ limitSelectionToOne: true,+ showSelectAll: false,+ ),+ ),+ ),+ );+ await tester.pumpAndSettle();+ await tester.pump(const Duration(milliseconds: 750));+ await tester.pump();++ final initialGroups = galleryKey.currentState!.galleryGroups!;+ expect(localSettings.getGalleryLayoutType(), GalleryLayoutType.mosaic);+ expect(initialGroups.layoutType, GalleryLayoutType.grid);+ expect(+ initialGroups.groupLayouts,+ everyElement(isA<FixedExtentSectionLayout>()),+ );++ Bus.instance.fire(GalleryLayoutChangedEvent());+ await tester.pumpAndSettle();++ final rebuiltGroups = galleryKey.currentState!.galleryGroups!;+ expect(rebuiltGroups, isNot(same(initialGroups)));+ expect(rebuiltGroups.layoutType, GalleryLayoutType.grid);+ expect(localSettings.getGalleryLayoutType(), GalleryLayoutType.mosaic);++ await tester.pumpWidget(const SizedBox.shrink());+ await tester.pump();+ });+testWidgets("a deep layout change preserves partial-row progress", (tester,) async {