Flutter ACL Plugin
A Flutter plugin which provide ACL functioning by Unified Intelligence
Feature
- Collect device data: battery, device resource, network, app usage
- Collect location
- Collect notification
- Store and sync data to server
- Calculate score
IMPORTANT:
This plugin support both Android and iOS. Following features will not available on iOS version:
PermissionHelper.isNotificationListenerRunningPermissionHelper.goToNotificationListenerSettingPermissionHelper.isPackageUsageStatsEnablePermissionHelper.goToAppUsageSettingPlease wrap those functions call in platform condition check!
How to install
- Step 1: Install package
flutter pub add acl_sdk
- Step 2: This plugin use
firebase_messagingto handle server-side message and perform action. You need to install firebase on your project with at least 2 packagesfirebase_core: ^4.1.1,firebase_messaging: ^firebase_messaging: ^16.0.0
On Android
- Step 3: Find your android build.gradle file at
android\build.gradleand add following code to allow gradle build withaarlibrary
allprojects {
repositories {
...
// Add following lines
maven {
// [required] aar plugin
url "${project(':acl_sdk').projectDir}/build"
}
}
}
// ------- After added, your build.gradle will look like this -------
allprojects {
repositories {
google()
mavenCentral()
// Add following lines
maven {
// [required] aar plugin
url "${project(':acl_sdk').projectDir}/build"
}
}
}
rootProject.buildDir = "../build"
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(":app")
}
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
- Step 4: Since this plugin require
minSdkVersion = 24. You might need to update your projectminSdkVersionto make it compatible. To do this, please find anotherbuild.gradlefile atandroid\app\build.gradlethen editminSdkto24.- Note: Depend on your project's structure, you can set it by using
local.propertiesfile or use directly number24.
- Note: Depend on your project's structure, you can set it by using
defaultConfig {
...
minSdk = 24 // Edit this line
...
}
On iOS
- Step 3: Add Background mode which enable
Background fetch,Location updates,Remote notifications(See sampleinfo.plistbelow)
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
<string>remote-notification</string>
<string>location</string>
</array>
- Step 4: Add Location always privacy if your app doesn't have this permission.
Usage
- To initialize the plugin and register device
import 'package:acl_sdk/acl_sdk.dart';
...
final _aclSdkPlugin = AclSdk();
...
await _aclSdkPlugin.initialize(AppConfigCreateInput(
partnerId: '<your organization unique name>',
apiEndpoint: '<your api endpoint>',
apiKey: '<your api key>',
apiSecret: '<your api secret>',
appBundle: '<your app bundle>',
));
await _aclSdkPlugin.registerDevice();
- To map device with member
- Note:
- Please make sure that you've already execute
registerDeviceat least one time before you callmapDeviceMember. - Use this function whenever your app has
memberIdchange event except logout (E.g: Login, Switch account,...)
- Please make sure that you've already execute
- Note:
import 'package:acl_sdk/acl_sdk.dart';
...
final _aclSdkPlugin = AclSdk();
...
await _aclSdkPlugin.mapDeviceMember('<your member id>');
- To start collect data and location
await _aclSdkPlugin.startCollectData();
await _aclSdkPlugin.startCollectLocation();
- To listen to Unified Intelligence server message
- Note:
- You can use below sample code OR call
aclFCMOnReceiveHandlerdirectly in your custom handler. Therefore, don't worry if you've already had custom handler in your code. - If you call
aclFCMOnReceiveHandlerin your existing handler, it should be better to add it at the first line of your function. Because, there might be some overlap event which handle by both side (our plugin and your app). This case rarely happen but still need you to aware about it. - Our server message will always include
type(inRemoteMessage.data) with following value:SYNC_DATA,DEVICE_CONFIG,TRAIN,SCORE.
- You can use below sample code OR call
- Note:
import 'package:acl_sdk/work_manager_dispatchers/acl_fcm_on_receive_handler.dart';
...
// This line for background message handle (even when app killed)
FirebaseMessaging.onBackgroundMessage(aclFCMOnReceiveHandler);
// This line for foreground message handle
FirebaseMessaging.onMessage.listen(aclFCMOnReceiveHandler);
API
- To get device id
import 'package:acl_sdk/helpers/device_info_helper.dart';
...
final deviceId = await DeviceInfoHelper.generateDeviceId();
- To check app usage access
import 'package:acl_sdk/helpers/permission_helper.dart';
...
final isAllowAppUsage = await PermissionHelper.isPackageUsageStatsEnable()
- To open app usage setting
import 'package:acl_sdk/helpers/permission_helper.dart';
...
await PermissionHelper.goToAppUsageSetting();
- To check notification bind listener access
import 'package:acl_sdk/helpers/permission_helper.dart';
...
await PermissionHelper.isNotificationListenerRunning();
- To open setting notification bind listener
import 'package:acl_sdk/helpers/permission_helper.dart';
...
await PermissionHelper.goToNotificationListenerSetting();
- To trigger sync data manually
import 'package:acl_sdk/helpers/sync_data_helper.dart';
...
await SyncDataHelper.syncData();
-
For location access please use package
geolocator(recommend) or some other plugin that you prefer. -
On iOS
geolocatorrequest permission might not work. Please try to use other libraries to request permission (E.g.location_permissions)
Notes
-
When you handle request permission
Location alwayson your app. Please check when user go back to app from setting, if user allowLocation always, make sure you callawait _aclSdkPlugin.startCollectLocation();to start collect location immediately. -
On iOS, we're pushing notification to topic
sync_datain order to collect and synchronization data. Please make sure that you do not override this topic on your app.
Issues & Contribute
Please file any issues, bugs or feature requests as an issue on our GitHub page. Commercial support is available, you can contact us at thanh@unified-intelligence.io
Author
This acl_sdk plugin for Flutter is developed by Unified Intelligence
Libraries
- acl_sdk
- acl_sdk_method_channel
- acl_sdk_platform_interface
- constants/api_route
- constants/method_name
- database/acl_database
- database/daos/app_config
- database/daos/app_usage_audit
- database/daos/battery_audit
- database/daos/device_resource_audit
- database/daos/feature
- database/daos/location_audit
- database/daos/network_audit
- database/daos/notification_audit
- database/data_models/app_config
- database/data_models/app_usage_audit
- database/data_models/battery_audit
- database/data_models/device_resource_audit
- database/data_models/enums/battery_audit_status
- database/data_models/enums/notification_audit_type
- database/data_models/feature
- database/data_models/location_audit
- database/data_models/network_audit
- database/data_models/notification_audit
- extensions/date_time.extension
- helpers/app_usage_audit_helper
- helpers/battery_audit_helper
- helpers/device_info_helper
- helpers/device_resource_helper
- helpers/location_audit_helper
- helpers/network_audit_helper
- helpers/notification_audit_helper
- helpers/permission_helper
- helpers/sync_data_helper
- services/http_service
- work_manager_dispatchers/acl_fcm_on_receive_handler
- work_manager_dispatchers/collect_data
- work_manager_dispatchers/location_stream_hander