Skip to content

Commit 1e9888e

Browse files
authored
Package info plugin moving to external (flutter#107)
* Initial commit of package_info * Add licensing and ChangeLog * Fix comments. * Add moar license headers. * Fix formatting and analyzer errors * Moar analyzer fixes
1 parent ff276b8 commit 1e9888e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1576
-0
lines changed

packages/package_info/.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.DS_Store
2+
.atom/
3+
.idea
4+
.packages
5+
.pub/
6+
build/
7+
ios/.generated/
8+
packages
9+
pubspec.lock

packages/package_info/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 0.0.1
2+
3+
* Initial release

packages/package_info/LICENSE

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2017 The Chromium Authors. All rights reserved.
2+
//
3+
// Redistribution and use in source and binary forms, with or without
4+
// modification, are permitted provided that the following conditions are
5+
// met:
6+
//
7+
// * Redistributions of source code must retain the above copyright
8+
// notice, this list of conditions and the following disclaimer.
9+
// * Redistributions in binary form must reproduce the above
10+
// copyright notice, this list of conditions and the following disclaimer
11+
// in the documentation and/or other materials provided with the
12+
// distribution.
13+
// * Neither the name of Your Company nor the names of its
14+
// contributors may be used to endorse or promote products derived from
15+
// this software without specific prior written permission.
16+
//
17+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

packages/package_info/README.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# package_info
2+
3+
This Flutter plugin provides an API for querying information about an
4+
application package.
5+
6+
# Usage
7+
8+
You can use the `PackageInfo` class to query information about the
9+
application package. This works both on iOS and Android.
10+
11+
```dart
12+
var version = await PackageInfo.getVersion();
13+
var buildNumber = await PackageInfo.getBuildNumber();
14+
```
15+
16+
## Getting Started
17+
18+
For help getting started with Flutter, view our online
19+
[documentation](http://flutter.io/).
20+
21+
For help on editing plugin code, view the [documentation](https://flutter.io/platform-plugins/#edit-code).
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
9+
10+
/gradle
11+
/gradlew
12+
/gradlew.bat
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
group 'io.flutter.plugins.packageinfo'
2+
version '1.0-SNAPSHOT'
3+
4+
buildscript {
5+
repositories {
6+
jcenter()
7+
}
8+
9+
dependencies {
10+
classpath 'com.android.tools.build:gradle:2.3.0'
11+
}
12+
}
13+
14+
allprojects {
15+
repositories {
16+
jcenter()
17+
}
18+
}
19+
20+
apply plugin: 'com.android.library'
21+
22+
android {
23+
compileSdkVersion 25
24+
buildToolsVersion '25.0.3'
25+
26+
defaultConfig {
27+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
28+
}
29+
lintOptions {
30+
disable 'InvalidPackage'
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.gradle.jvmargs=-Xmx1536M
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = 'package_info'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="io.flutter.plugins.packageinfo"
3+
android:versionCode="1"
4+
android:versionName="0.0.1">
5+
6+
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="21" />
7+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright 2017 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
package io.flutter.plugins.packageinfo;
6+
7+
import android.app.Activity;
8+
import android.content.Context;
9+
import android.content.pm.PackageInfo;
10+
import android.content.pm.PackageManager;
11+
import io.flutter.plugin.common.MethodCall;
12+
import io.flutter.plugin.common.MethodChannel;
13+
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
14+
import io.flutter.plugin.common.MethodChannel.Result;
15+
import io.flutter.plugin.common.PluginRegistry.Registrar;
16+
17+
/** PackageInfoPlugin */
18+
public class PackageInfoPlugin implements MethodCallHandler {
19+
private final Context context;
20+
21+
/** Plugin registration. */
22+
public static void registerWith(Registrar registrar) {
23+
final MethodChannel channel =
24+
new MethodChannel(registrar.messenger(), "plugins.flutter.io/package_info");
25+
channel.setMethodCallHandler(new PackageInfoPlugin(registrar.activity()));
26+
}
27+
28+
private PackageInfoPlugin(Activity activity) {
29+
this.context = activity;
30+
}
31+
32+
@Override
33+
public void onMethodCall(MethodCall call, Result result) {
34+
try {
35+
PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
36+
switch (call.method) {
37+
case "getVersion":
38+
result.success(info.versionName);
39+
break;
40+
case "getBuildNumber":
41+
result.success(String.valueOf(info.versionCode));
42+
break;
43+
default:
44+
result.notImplemented();
45+
}
46+
} catch (PackageManager.NameNotFoundException ex) {
47+
result.error("Name not found", ex.getMessage(), null);
48+
}
49+
}
50+
}
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.DS_Store
2+
.atom/
3+
.idea
4+
.packages
5+
.pub/
6+
build/
7+
ios/.generated/
8+
packages
9+
pubspec.lock
10+
.flutter-plugins
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# package_info_example
2+
3+
Demonstrates how to use the package_info plugin.
4+
5+
## Getting Started
6+
7+
For help getting started with Flutter, view our online
8+
[documentation](http://flutter.io/).
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$/android">
6+
<sourceFolder url="file://$MODULE_DIR$/android/app/src/main/java" isTestSource="false" />
7+
</content>
8+
<orderEntry type="jdk" jdkName="Android API 25 Platform" jdkType="Android SDK" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
<orderEntry type="library" name="Flutter for Android" level="project" />
11+
</component>
12+
</module>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
9+
GeneratedPluginRegistrant.java
10+
11+
/gradle
12+
/gradlew
13+
/gradlew.bat
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
def localProperties = new Properties()
2+
def localPropertiesFile = rootProject.file('local.properties')
3+
if (localPropertiesFile.exists()) {
4+
localPropertiesFile.withInputStream { stream ->
5+
localProperties.load(stream)
6+
}
7+
}
8+
9+
def flutterRoot = localProperties.getProperty('flutter.sdk')
10+
if (flutterRoot == null) {
11+
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
12+
}
13+
14+
apply plugin: 'com.android.application'
15+
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
16+
17+
android {
18+
compileSdkVersion 25
19+
buildToolsVersion '25.0.3'
20+
21+
lintOptions {
22+
disable 'InvalidPackage'
23+
}
24+
25+
defaultConfig {
26+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
27+
applicationId "io.flutter.plugins.packageinfoexample"
28+
}
29+
30+
buildTypes {
31+
release {
32+
// Signing with the debug keys for now, so `flutter run --release` works.
33+
signingConfig signingConfigs.debug
34+
}
35+
}
36+
}
37+
38+
flutter {
39+
source '../..'
40+
}
41+
42+
dependencies {
43+
androidTestCompile 'com.android.support:support-annotations:25.0.0'
44+
androidTestCompile 'com.android.support.test:runner:0.5'
45+
androidTestCompile 'com.android.support.test:rules:0.5'
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="io.flutter.plugins.packageinfoexample"
3+
android:versionCode="1"
4+
android:versionName="0.0.1">
5+
6+
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="21" />
7+
8+
<!-- The INTERNET permission is required for development. Specifically,
9+
flutter needs it to communicate with the running application
10+
to allow setting breakpoints, to provide hot reload, etc.
11+
-->
12+
<uses-permission android:name="android.permission.INTERNET"/>
13+
14+
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
15+
calls FlutterMain.startInitialization(this); in its onCreate method.
16+
In most cases you can leave this as-is, but you if you want to provide
17+
additional functionality it is fine to subclass or reimplement
18+
FlutterApplication and put your custom class here. -->
19+
<application android:name="io.flutter.app.FlutterApplication" android:label="package_info_example" android:icon="@mipmap/ic_launcher">
20+
<activity android:name=".MainActivity"
21+
android:launchMode="singleTop"
22+
android:theme="@android:style/Theme.Black.NoTitleBar"
23+
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection"
24+
android:hardwareAccelerated="true"
25+
android:windowSoftInputMode="adjustResize">
26+
<intent-filter>
27+
<action android:name="android.intent.action.MAIN"/>
28+
<category android:name="android.intent.category.LAUNCHER"/>
29+
</intent-filter>
30+
</activity>
31+
</application>
32+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2017 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
package io.flutter.plugins.packageinfoexample;
6+
7+
import android.os.Bundle;
8+
import io.flutter.app.FlutterActivity;
9+
import io.flutter.plugins.GeneratedPluginRegistrant;
10+
11+
public class MainActivity extends FlutterActivity {
12+
@Override
13+
protected void onCreate(Bundle savedInstanceState) {
14+
super.onCreate(savedInstanceState);
15+
GeneratedPluginRegistrant.registerWith(this);
16+
}
17+
}
Loading
Loading
Loading
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
buildscript {
2+
repositories {
3+
jcenter()
4+
}
5+
6+
dependencies {
7+
classpath 'com.android.tools.build:gradle:2.2.3'
8+
}
9+
}
10+
11+
allprojects {
12+
repositories {
13+
jcenter()
14+
}
15+
}
16+
17+
rootProject.buildDir = '../build'
18+
subprojects {
19+
project.buildDir = "${rootProject.buildDir}/${project.name}"
20+
project.evaluationDependsOn(':app')
21+
}
22+
23+
task clean(type: Delete) {
24+
delete rootProject.buildDir
25+
}
26+
27+
task wrapper(type: Wrapper) {
28+
gradleVersion = '2.14.1'
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.gradle.jvmargs=-Xmx1536M
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
include ':app'
2+
3+
def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()
4+
5+
def plugins = new Properties()
6+
def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')
7+
if (pluginsFile.exists()) {
8+
pluginsFile.withInputStream { stream -> plugins.load(stream) }
9+
}
10+
11+
plugins.each { name, path ->
12+
def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
13+
include ":$name"
14+
project(":$name").projectDir = pluginDirectory
15+
}

0 commit comments

Comments
 (0)