Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Zfinix committed Dec 9, 2020
0 parents commit f6ff132
Show file tree
Hide file tree
Showing 100 changed files with 3,000 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.DS_Store
.dart_tool/

.packages
.pub/

build/
19 changes: 19 additions & 0 deletions .idea/libraries/Dart_SDK.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/runConfigurations/example_lib_main_dart.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: 022b333a089afb81c471ec43d1f1f4f26305d876
channel: dev

project_type: plugin
19 changes: 19 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "carrier_info",
"request": "launch",
"type": "dart"
},
{
"name": "example",
"cwd": "example",
"request": "launch",
"type": "dart"
}
]
}
Binary file added 1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.0.1

* TODO: Describe initial release.
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TODO: Add your license here.
79 changes: 79 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# 📱 Carrier Info

Carrier Info gets networkType, networkGeneration, mobileCountryCode, mobileCountryCode, e.t.c from both android and ios devices. It's a port from this [js project](https://github.com/react-native-webrtc/react-native-carrier-info) and an improvement on the existing [flt_telephony_info package](https://pub.dev/packages/flt_telephony_info).

## 📸 Screen Shots

<p float="left">
<img src="https://github.com/Zfinix/carrier_info/blob/main/1.png?raw=true" width="200">
</p>

### allowsVOIP (iOS only)

```dart
bool carrierInfo = await CarrierInfo.allowsVOIP; // Indicates if the carrier allows VoIP calls to be made on its network.
```

- If you configure a device for a carrier and then remove the SIM card, this property retains the Boolean value indicating the carrier’s policy regarding VoIP.
- Always return `true` on Android.

### carrierName

```dart
String carrierInfo = await CarrierInfo.carrierName; // The name of the user’s home cellular service provider.
```

- This string is provided by the carrier and formatted for presentation to the user. The value does not change if the user is roaming; it always represents the provider with whom the user has an account.
- If you configure a device for a carrier and then remove the SIM card, this property retains the name of the carrier.
- The value for this property is 'nil' if the device was never configured for a carrier.

### isoCountryCode

```dart
String carrierInfo = await CarrierInfo.isoCountryCode; // The ISO country code for the user’s cellular service provider.
```

- This property uses the ISO 3166-1 country code representation.
- The value for this property is 'nil' if any of the following apply:
- The device is in Airplane mode.
- There is no SIM card in the device.
- The device is outside of cellular service range.

### mobileCountryCode

```dart
String carrierInfo = await CarrierInfo.mobileCountryCode; //The mobile country code (MCC) for the user’s cellular service provider.
```

- MCCs are defined by ITU-T Recommendation E.212, “List of Mobile Country or Geographical Area Codes.”
- The value for this property is 'nil' if any of the following apply:
- There is no SIM card in the device.
- The device is outside of cellular service range.
- The value may be 'nil' on hardware prior to iPhone 4S when in Airplane mode.

### mobileNetworkCode

```dart
String carrierInfo = await CarrierInfo.mobileNetworkCode // The mobile network code (MNC) for the user’s cellular service provider.
```

- The value for this property is 'nil' if any of the following apply:
- There is no SIM card in the device.
- The device is outside of cellular service range.
- The value may be 'nil' on hardware prior to iPhone 4S when in Airplane mode.

### networkGeneration

```dart
String carrierInfo = await CarrierInfo.networkGeneration // 5G, 4G ... 2G
```

### radioType

```dart
String carrierInfo = await CarrierInfo.radioType // LTE, HSDPA, e.t.c
```

## ✨ Contribution

Lots of PR's would be needed to make this plugin standard, as for iOS there's a permanent limitation for getting the exact data usage, there's only one way arount it and it's super complex.
8 changes: 8 additions & 0 deletions android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
43 changes: 43 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
group 'com.chizi.carrier_info'
version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

rootProject.allprojects {
repositories {
google()
jcenter()
}
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 29

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
minSdkVersion 16
}
lintOptions {
disable 'InvalidPackage'
}
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
3 changes: 3 additions & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
5 changes: 5 additions & 0 deletions android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
1 change: 1 addition & 0 deletions android/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'carrier_info'
5 changes: 5 additions & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.chizi.carrier_info">
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.chizi.carrier_info

import androidx.annotation.NonNull
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.embedding.engine.plugins.activity.ActivityAware
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.PluginRegistry


/** CarrierInfoPlugin */
class CarrierInfoPlugin: FlutterPlugin,
PluginRegistry.RequestPermissionsResultListener, ActivityAware {
/// The MethodChannel that will the communication between Flutter and native Android
///
/// This local reference serves to register the plugin with the Flutter Engine and unregister it
/// when the Flutter Engine is detached from the Activity

private var channel: MethodChannel? = null
private val channelID = "plugins.chizi.tech/carrier_info"
private var handler: MethodCallHandlerImpl? = null

override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
setupChannel(flutterPluginBinding)
}

override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
teardownChannel()
}

private fun setupChannel(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
channel = MethodChannel(flutterPluginBinding.binaryMessenger, channelID)
handler = MethodCallHandlerImpl(flutterPluginBinding.applicationContext, null)
channel?.setMethodCallHandler(handler)
}

override fun onAttachedToActivity(binding: ActivityPluginBinding) {
handler?.setActivity(binding.activity)
}

override fun onDetachedFromActivityForConfigChanges() {
handler?.setActivity(null)
}

override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {
onAttachedToActivity(binding)
binding.addRequestPermissionsResultListener(this)
}

override fun onDetachedFromActivity() {
onDetachedFromActivity()
}




private fun teardownChannel() {
channel?.setMethodCallHandler(null)
channel = null
handler = null
}

override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>?, grantResults: IntArray?): Boolean {
handler?.onRequestPermissionsResult(requestCode,permissions, grantResults)
return true
}
}
Loading

0 comments on commit f6ff132

Please sign in to comment.