forked from flutter/plugins
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into kg-connectivity-ios-permissions
* master: [url_launcher, url_launcher_web]Added webOnlyWindowName parameter to launch() (flutter#2979) [battery_platform_interface] Introduce package. (flutter#2975) [url_launcher_platform_interface] Add webOnlyWindowName parameter to launch() (flutter#2974) [share] Add sharing file support (android & ios) (flutter#970) [integration_test] add support to get timeline (flutter#2947) [battery] Moved battery to its own subdir (flutter#2969) [integration_test] Fix channel name for iOS, docs (flutter#2972) [integration_test] Show stack trace of widget test errors on the platform side (flutter#2967) [video_player] Fix `setWithOthers` test (flutter#2970) [video_player_platform_interface] fix `setMixIWithOthers` test channel (flutter#2968) Add README instructions for enablePendingPurchases (flutter#2921) Rebase previous commits (flutter#2966) Avoid walleye 26 Updating documentation to use isEmpty check. (flutter#2955) [integration_test] Minor cleanup (flutter#2956) [path_provider, video_player] Tweak pubspecs to pass bulk analysis. (flutter#2959) [android_intent] fix platform package dep (flutter#2948) [shared_preferences_linux] update `file` package dep version to be compatible with framework (flutter#2950)
- Loading branch information
Showing
134 changed files
with
1,294 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
packages/battery/CHANGELOG.md → packages/battery/battery/CHANGELOG.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## 1.0.0 | ||
|
||
- Initial open-source release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2017 The Chromium Authors. All rights reserved. | ||
// | ||
// Redistribution and use in source and binary forms, with or without | ||
// modification, are permitted provided that the following conditions are | ||
// met: | ||
// | ||
// * Redistributions of source code must retain the above copyright | ||
// notice, this list of conditions and the following disclaimer. | ||
// * Redistributions in binary form must reproduce the above | ||
// copyright notice, this list of conditions and the following disclaimer | ||
// in the documentation and/or other materials provided with the | ||
// distribution. | ||
// * Neither the name of Google Inc. nor the names of its | ||
// contributors may be used to endorse or promote products derived from | ||
// this software without specific prior written permission. | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# battery_platform_interface | ||
|
||
A common platform interface for the [`battery`][1] plugin. | ||
|
||
This interface allows platform-specific implementations of the `battery` | ||
plugin, as well as the plugin itself, to ensure they are supporting the | ||
same interface. | ||
|
||
# Usage | ||
|
||
To implement a new platform-specific implementation of `battery`, extend | ||
[`BatteryPlatform`][2] with an implementation that performs the | ||
platform-specific behavior, and when you register your plugin, set the default | ||
`BatteryPlatform` by calling | ||
`BatteryPlatform.instance = MyPlatformBattery()`. | ||
|
||
# Note on breaking changes | ||
|
||
Strongly prefer non-breaking changes (such as adding a method to the interface) | ||
over breaking changes for this package. | ||
|
||
See https://flutter.dev/go/platform-interface-breaking-changes for a discussion | ||
on why a less-clean interface is preferable to a breaking change. | ||
|
||
[1]: ../battery | ||
[2]: lib/battery_platform_interface.dart |
51 changes: 51 additions & 0 deletions
51
packages/battery/battery_platform_interface/lib/battery_platform_interface.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2017 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. | ||
|
||
import 'dart:async'; | ||
|
||
import 'package:plugin_platform_interface/plugin_platform_interface.dart'; | ||
|
||
import 'method_channel/method_channel_battery.dart'; | ||
import 'enums/battery_state.dart'; | ||
|
||
export 'enums/battery_state.dart'; | ||
|
||
/// The interface that implementations of battery must implement. | ||
/// | ||
/// Platform implementations should extend this class rather than implement it as `battery` | ||
/// does not consider newly added methods to be breaking changes. Extending this class | ||
/// (using `extends`) ensures that the subclass will get the default implementation, while | ||
/// platform implementations that `implements` this interface will be broken by newly added | ||
/// [BatteryPlatform] methods. | ||
abstract class BatteryPlatform extends PlatformInterface { | ||
/// Constructs a BatteryPlatform. | ||
BatteryPlatform() : super(token: _token); | ||
|
||
static final Object _token = Object(); | ||
|
||
static BatteryPlatform _instance = MethodChannelBattery(); | ||
|
||
/// The default instance of [BatteryPlatform] to use. | ||
/// | ||
/// Defaults to [MethodChannelBattery]. | ||
static BatteryPlatform get instance => _instance; | ||
|
||
/// Platform-specific plugins should set this with their own platform-specific | ||
/// class that extends [BatteryPlatform] when they register themselves. | ||
static set instance(BatteryPlatform instance) { | ||
PlatformInterface.verifyToken(instance, _token); | ||
_instance = instance; | ||
} | ||
|
||
/// Gets the battery level from device. | ||
Future<int> batteryLevel() { | ||
throw UnimplementedError('batteryLevel() has not been implemented.'); | ||
} | ||
|
||
/// gets battery state from device. | ||
Stream<BatteryState> onBatteryStateChanged() { | ||
throw UnimplementedError( | ||
'onBatteryStateChanged() has not been implemented.'); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/battery/battery_platform_interface/lib/enums/battery_state.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/// Indicates the current battery state. | ||
enum BatteryState { | ||
/// The battery is completely full of energy. | ||
full, | ||
|
||
/// The battery is currently storing energy. | ||
charging, | ||
|
||
/// The battery is currently losing energy. | ||
discharging | ||
} |
51 changes: 51 additions & 0 deletions
51
packages/battery/battery_platform_interface/lib/method_channel/method_channel_battery.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:flutter/services.dart'; | ||
import 'package:meta/meta.dart'; | ||
|
||
import 'package:battery_platform_interface/battery_platform_interface.dart'; | ||
|
||
import '../battery_platform_interface.dart'; | ||
|
||
/// An implementation of [BatteryPlatform] that uses method channels. | ||
class MethodChannelBattery extends BatteryPlatform { | ||
/// The method channel used to interact with the native platform. | ||
@visibleForTesting | ||
MethodChannel channel = MethodChannel('plugins.flutter.io/battery'); | ||
|
||
/// The event channel used to interact with the native platform. | ||
@visibleForTesting | ||
EventChannel eventChannel = EventChannel('plugins.flutter.io/charging'); | ||
|
||
/// Method channel for getting battery level. | ||
Future<int> batteryLevel() async { | ||
return (await channel.invokeMethod('getBatteryLevel')).toInt(); | ||
} | ||
|
||
/// Stream variable for storing battery state. | ||
Stream<BatteryState> _onBatteryStateChanged; | ||
|
||
/// Event channel for getting battery change state. | ||
Stream<BatteryState> onBatteryStateChanged() { | ||
if (_onBatteryStateChanged == null) { | ||
_onBatteryStateChanged = eventChannel | ||
.receiveBroadcastStream() | ||
.map((dynamic event) => _parseBatteryState(event)); | ||
} | ||
return _onBatteryStateChanged; | ||
} | ||
} | ||
|
||
/// Method for parsing battery state. | ||
BatteryState _parseBatteryState(String state) { | ||
switch (state) { | ||
case 'full': | ||
return BatteryState.full; | ||
case 'charging': | ||
return BatteryState.charging; | ||
case 'discharging': | ||
return BatteryState.discharging; | ||
default: | ||
throw ArgumentError('$state is not a valid BatteryState.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: battery_platform_interface | ||
description: A common platform interface for the battery plugin. | ||
homepage: https://github.com/flutter/plugins/tree/master/packages/battery | ||
# NOTE: We strongly prefer non-breaking changes, even at the expense of a | ||
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes | ||
version: 1.0.0 | ||
|
||
dependencies: | ||
flutter: | ||
sdk: flutter | ||
meta: ^1.1.8 | ||
plugin_platform_interface: ^1.0.2 | ||
|
||
dev_dependencies: | ||
flutter_test: | ||
sdk: flutter | ||
mockito: ^4.1.1 | ||
pedantic: ^1.8.0 | ||
|
||
environment: | ||
sdk: ">=2.7.0 <3.0.0" | ||
flutter: ">=1.9.1+hotfix.4 <2.0.0" |
63 changes: 63 additions & 0 deletions
63
packages/battery/battery_platform_interface/test/method_channel_battery_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright 2017 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. | ||
|
||
import 'package:flutter/services.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
import 'package:battery_platform_interface/battery_platform_interface.dart'; | ||
|
||
import 'package:battery_platform_interface/method_channel/method_channel_battery.dart'; | ||
|
||
void main() { | ||
TestWidgetsFlutterBinding.ensureInitialized(); | ||
|
||
group("$MethodChannelBattery", () { | ||
MethodChannelBattery methodChannelBattery; | ||
|
||
setUp(() async { | ||
methodChannelBattery = MethodChannelBattery(); | ||
|
||
methodChannelBattery.channel | ||
.setMockMethodCallHandler((MethodCall methodCall) async { | ||
switch (methodCall.method) { | ||
case 'getBatteryLevel': | ||
return 90; | ||
default: | ||
return null; | ||
} | ||
}); | ||
|
||
MethodChannel(methodChannelBattery.eventChannel.name) | ||
.setMockMethodCallHandler((MethodCall methodCall) async { | ||
switch (methodCall.method) { | ||
case 'listen': | ||
await ServicesBinding.instance.defaultBinaryMessenger | ||
.handlePlatformMessage( | ||
methodChannelBattery.eventChannel.name, | ||
methodChannelBattery.eventChannel.codec | ||
.encodeSuccessEnvelope('full'), | ||
(_) {}, | ||
); | ||
break; | ||
case 'cancel': | ||
default: | ||
return null; | ||
} | ||
}); | ||
}); | ||
|
||
/// Test for batetry level call. | ||
test("getBatteryLevel", () async { | ||
final int result = await methodChannelBattery.batteryLevel(); | ||
expect(result, 90); | ||
}); | ||
|
||
/// Test for battery changed state call. | ||
test("onBatteryChanged", () async { | ||
final BatteryState result = | ||
await methodChannelBattery.onBatteryStateChanged().first; | ||
expect(result, BatteryState.full); | ||
}); | ||
}); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.