Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/flutter/devtools into rea…
Browse files Browse the repository at this point in the history
…dAppRoot
  • Loading branch information
hannah-hyj committed Mar 19, 2024
2 parents 8a5318a + 28cc335 commit 2cb2417
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/devtools_app/benchmark/web_bundle_size_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'package:test/test.dart';

// Benchmark size in kB.
const int bundleSizeBenchmark = 4800;
const int gzipBundleSizeBenchmark = 1400;
const int gzipBundleSizeBenchmark = 1450;

void main() {
group('Web Compile', () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ class DeepLinksController extends DisposableController {
}

final selectedProject = ValueNotifier<FlutterProject?>(null);
final googlePlayFingerprintsAvailability = ValueNotifier<bool>(false);
final localFingerprint = ValueNotifier<String?>(null);
final selectedLink = ValueNotifier<LinkData?>(null);
final pagePhase = ValueNotifier<PagePhase>(PagePhase.emptyState);
Expand Down Expand Up @@ -342,11 +343,14 @@ class DeepLinksController extends DisposableController {
late final Map<String, List<DomainError>> domainErrors;

try {
domainErrors = await deepLinksServices.validateAndroidDomain(
final result = await deepLinksServices.validateAndroidDomain(
domains: domains,
applicationId: applicationId,
localFingerprint: localFingerprint.value,
);
domainErrors = result.domainErrors;
googlePlayFingerprintsAvailability.value =
result.googlePlayFingerprintsAvailability;
} catch (_) {
//TODO(hangyujin): Add more error handling for cases like RPC error and invalid json.
pagePhase.value = PagePhase.errorPage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const String _errorCodeKey = 'errorCode';
const String _appLinkDomainsKey = 'app_link_domains';
const String _fingerprintsKey = 'supplemental_sha256_cert_fingerprints';
const String _validationResultKey = 'validationResult';
const String _googlePlayFingerprintsAvailabilityKey =
'_googlePlayFingerprintsAvailability';
const String _googlePlayFingerprintsAvailableValue = 'FINGERPRINTS_AVAILABLE';
const String _domainNameKey = 'domainName';
const String _checkNameKey = 'checkName';
const String _failedChecksKey = 'failedChecks';
Expand All @@ -44,8 +47,17 @@ class GenerateAssetLinksResult {
String generatedString;
}

class ValidateAndroidDomainResult {
ValidateAndroidDomainResult(
this.googlePlayFingerprintsAvailability,
this.domainErrors,
);
bool googlePlayFingerprintsAvailability;
Map<String, List<DomainError>> domainErrors;
}

class DeepLinksServices {
Future<Map<String, List<DomainError>>> validateAndroidDomain({
Future<ValidateAndroidDomainResult> validateAndroidDomain({
required List<String> domains,
required String applicationId,
required String? localFingerprint,
Expand All @@ -64,6 +76,7 @@ class DeepLinksServices {
: (index + 1) * _domainBatchSize,
),
);
late bool googlePlayFingerprintsAvailable;

for (final domainList in domainsBybatch) {
final response = await http.post(
Expand All @@ -80,6 +93,9 @@ class DeepLinksServices {
json.decode(response.body) as Map<String, dynamic>;

final validationResult = result[_validationResultKey] as List;
googlePlayFingerprintsAvailable =
result[_googlePlayFingerprintsAvailabilityKey] ==
_googlePlayFingerprintsAvailableValue;
for (final Map<String, dynamic> domainResult in validationResult) {
final String domainName = domainResult[_domainNameKey];
final List? failedChecks = domainResult[_failedChecksKey];
Expand All @@ -95,7 +111,10 @@ class DeepLinksServices {
}
}

return domainErrors;
return ValidateAndroidDomainResult(
googlePlayFingerprintsAvailable,
domainErrors,
);
}

Future<GenerateAssetLinksResult> generateAssetLinks({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,75 @@ class _DomainCheckTable extends StatelessWidget {
),
],
),
_Fingerprint(controller: controller),
if (linkData.domainErrors.isNotEmpty)
_DomainFixPanel(controller: controller),
const SizedBox(height: intermediateSpacing),
_LocalFingerprint(controller: controller),
],
);
}
}

class _Fingerprint extends StatelessWidget {
const _Fingerprint({
required this.controller,
});

final DeepLinksController controller;

@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return ValueListenableBuilder<String?>(
valueListenable: controller.localFingerprint,
builder: (context, localFingerprint, _) {
final hasPdcFingerpint =
controller.googlePlayFingerprintsAvailability.value;
final haslocalFingerpint = localFingerprint != null;
return ExpansionTile(
title: hasPdcFingerpint
? const Text(
'PDC fingerprint detected, enter a local fingerprint if needed',
)
: haslocalFingerpint
? const Text('Local fingerprint detected')
: const _ErrorText(
'Can\'t proceed check due to no fingerprint detected',
),
children: [
Padding(
padding: const EdgeInsets.all(largeSpacing),
child: RoundedOutlinedBorder(
child: Padding(
padding: const EdgeInsets.all(largeSpacing),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (!hasPdcFingerpint && !haslocalFingerpint) ...[
const Text('Fix guide:'),
const SizedBox(height: denseSpacing),
Text(
'To fix this issue, release your app on Play Developer Console to get a fingerprint. '
'If you are not ready to release your app, enter a local fingerprint below can also allow you'
'to proceed Android domain check.',
style: theme.subtleTextStyle,
),
const SizedBox(height: denseSpacing),
],
// User can add local fingerprint no matter PDC fingerpint is detected or not.
_LocalFingerprint(controller: controller),
],
),
),
),
),
],
);
},
);
}
}

class _LocalFingerprint extends StatelessWidget {
const _LocalFingerprint({
required this.controller,
Expand Down Expand Up @@ -434,17 +494,7 @@ class _FailureDetails extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: densePadding),
Row(
children: [
Icon(
Icons.error,
color: Theme.of(context).colorScheme.error,
size: defaultIconSize,
),
const SizedBox(width: denseSpacing),
Text('Issue ${i + 1} : ${linkData.domainErrors[i].title}'),
],
),
_ErrorText('Issue ${i + 1} : ${linkData.domainErrors[i].title}'),
const SizedBox(height: densePadding),
Padding(
padding: EdgeInsets.only(
Expand Down Expand Up @@ -672,3 +722,23 @@ class _NoIssueText extends StatelessWidget {
);
}
}

class _ErrorText extends StatelessWidget {
const _ErrorText(this.text);
final String text;

@override
Widget build(BuildContext context) {
return Row(
children: [
Icon(
Icons.error,
color: Theme.of(context).colorScheme.error,
size: defaultIconSize,
),
const SizedBox(width: denseSpacing),
Text(text),
],
);
}
}

0 comments on commit 2cb2417

Please sign in to comment.