forked from firebase/flutterfire
-
Notifications
You must be signed in to change notification settings - Fork 0
/
platform_interface_crashlytics.dart
191 lines (167 loc) 路 7.55 KB
/
platform_interface_crashlytics.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
// ignore_for_file: require_trailing_commas
// Copyright 2020, the Chromium project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:meta/meta.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
import '../method_channel/method_channel_crashlytics.dart';
/// The Firebase Crashlytics platform interface.
///
/// This class should be extended by any classes implementing the plugin on
/// other Flutter supported platforms.
abstract class FirebaseCrashlyticsPlatform extends PlatformInterface {
/// The [FirebaseApp] this instance was initialized with.
FirebaseCrashlyticsPlatform({required this.appInstance})
: super(token: _token);
/// Create an instance using [app] using the existing implementation
factory FirebaseCrashlyticsPlatform.instanceFor(
{required FirebaseApp app,
required Map<dynamic, dynamic> pluginConstants}) {
// Only the default app is supported on Crashlytics.
assert(app.name == defaultFirebaseAppName);
// Must have bool collection enabled constant.
assert(pluginConstants['isCrashlyticsCollectionEnabled'] != null);
return FirebaseCrashlyticsPlatform.instance.setInitialValues(
isCrashlyticsCollectionEnabled:
pluginConstants['isCrashlyticsCollectionEnabled'],
);
}
/// The [FirebaseApp] this instance was initialized with.
@protected
final FirebaseApp appInstance;
/// Create an instance using [app]
static final Object _token = Object();
/// Returns the [FirebaseApp] for the current instance.
FirebaseApp get app {
return appInstance;
}
static FirebaseCrashlyticsPlatform? _instance;
/// The current default [FirebaseCrashlyticsPlatform] instance.
///
/// It will always default to [MethodChannelFirebaseCrashlytics]
/// if no other implementation was provided.
static FirebaseCrashlyticsPlatform get instance {
return _instance ??= MethodChannelFirebaseCrashlytics(app: Firebase.app());
}
/// Sets the [FirebaseCrashlyticsPlatform.instance]
static set instance(FirebaseCrashlyticsPlatform instance) {
PlatformInterface.verifyToken(instance, _token);
_instance = instance;
}
/// Whether the current Crashlytics instance is collecting reports. If false,
/// then no crash reporting data is sent to Firebase.
///
/// See [setCrashlyticsCollectionEnabled] for toggling collection status.
bool get isCrashlyticsCollectionEnabled {
throw UnimplementedError(
'isCrashlyticsCollectionEnabled is not implemented');
}
/// Checks a device for any fatal or non-fatal crash reports that haven't yet
/// been sent to Crashlytics.
///
/// If automatic data collection is enabled, then reports are uploaded
/// automatically and this always returns false. If automatic data collection
/// is disabled, this method can be used to check whether the user opts-in to
/// send crash reports from their device.
Future<bool> checkForUnsentReports() {
throw UnimplementedError('checkForUnsentReports() is not implemented');
}
/// Causes the app to crash (natively).
///
/// This should only be used for testing purposes in cases where you wish to
/// simulate a native crash to view the results on the Firebase Console.
///
/// Note: crash reports will not include a stack trace and crash reports are
/// not sent until the next application startup.
void crash() {
throw UnimplementedError('crash() is not implemented');
}
/// If automatic data collection is disabled, this method queues up all the
/// reports on a device for deletion. Otherwise, this method is a no-op.
Future<void> deleteUnsentReports() {
throw UnimplementedError('deleteUnsentReports() is not implemented');
}
/// Checks whether the app crashed on its previous run.
Future<bool> didCrashOnPreviousExecution() {
throw UnimplementedError(
'didCrashOnPreviousExecution() is not implemented');
}
/// Submits a Crashlytics report of a caught error.
Future<void> recordError({
required String exception,
required String information,
required String reason,
bool fatal = false,
List<Map<String, String>>? stackTraceElements,
}) {
throw UnimplementedError('recordError() is not implemented');
}
/// Logs a message that's included in the next fatal or non-fatal report.
///
/// Logs are visible in the session view on the Firebase Crashlytics console.
///
/// Newline characters are stripped and extremely long messages are truncated.
/// The maximum log size is 64k. If exceeded, the log rolls such that messages
/// are removed, starting from the oldest.
Future<void> log(String message) {
throw UnimplementedError('log() is not implemented');
}
/// If automatic data collection is disabled, this method queues up all the
/// reports on a device to send to Crashlytics. Otherwise, this method is a no-op.
Future<void> sendUnsentReports() {
throw UnimplementedError('sendUnsentReports() is not implemented');
}
/// Enables/disables automatic data collection by Crashlytics.
///
/// If this is set, it overrides the data collection settings provided by the
/// Android Manifest, iOS Plist settings, as well as any Firebase-wide automatic
/// data collection settings.
///
/// If automatic data collection is disabled for Crashlytics, crash reports are
/// stored on the device. To check for reports, use the [checkForUnsentReports]
/// method. Use [sendUnsentReports] to upload existing reports even when automatic
/// data collection is disabled. Use [deleteUnsentReports] to delete any reports
/// stored on the device without sending them to Crashlytics.
Future<void> setCrashlyticsCollectionEnabled(bool enabled) {
throw UnimplementedError(
'setCrashlyticsCollectionEnabled() is not implemented');
}
/// Records a user ID (identifier) that's associated with subsequent fatal and
/// non-fatal reports.
///
/// The user ID is visible in the session view on the Firebase Crashlytics console.
/// Identifiers longer than 1024 characters will be truncated.
///
/// Ensure you have collected permission to store any personal identifiable information
/// from the user if required.
Future<void> setUserIdentifier(String identifier) {
throw UnimplementedError('setUserIdentifier() is not implemented');
}
/// Sets a custom key and value that are associated with subsequent fatal and
/// non-fatal reports.
///
/// Multiple calls to this method with the same key update the value for that key.
/// The value of any key at the time of a fatal or non-fatal event is associated
/// with that event. Keys and associated values are visible in the session view
/// on the Firebase Crashlytics console.
///
/// Accepts a maximum of 64 key/value pairs. New keys beyond that limit are
/// ignored. Keys or values that exceed 1024 characters are truncated.
Future<void> setCustomKey(String key, String value) {
throw UnimplementedError('setCustomKey() is not implemented');
}
/// Sets any initial values on the instance.
///
/// Platforms with Method Channels can provide constant values to be available
/// before the instance has initialized to prevent any unnecessary async
/// calls.
@protected
FirebaseCrashlyticsPlatform setInitialValues({
required bool isCrashlyticsCollectionEnabled,
}) {
throw UnimplementedError('setInitialValues() is not implemented');
}
}