Refactor: extract native lock and log

This commit is contained in:
Ming Ming 2023-08-26 23:49:28 +08:00
parent 9f43092dab
commit c496e2d1e2
52 changed files with 473 additions and 122 deletions

View file

@ -121,5 +121,6 @@ dependencies {
// fix crash on sdk33, need investigation
implementation "androidx.window:window:1.0.0"
implementation 'com.google.android.gms:play-services-maps:18.1.0'
implementation 'com.nkming.nc_photos.np_android_log:np_android_log'
coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:2.0.3"
}

View file

@ -1,6 +1,6 @@
package com.nkming.nc_photos
import com.nkming.nc_photos.plugin.LogConfig
import com.nkming.nc_photos.np_android_log.LogConfig
import io.flutter.BuildConfig
import io.flutter.app.FlutterApplication

View file

@ -1,9 +1,8 @@
package com.nkming.nc_photos
import android.content.Context
import com.nkming.nc_photos.plugin.logI
import io.flutter.Log
import java.util.*
import com.nkming.nc_photos.np_android_log.logI
import java.util.Locale
import javax.net.ssl.HostnameVerifier
import javax.net.ssl.HttpsURLConnection
import javax.net.ssl.SSLSession
@ -14,10 +13,14 @@ class CustomHostnameVerifier(context: Context) : HostnameVerifier {
* behavior
*/
override fun verify(hostname: String, session: SSLSession): Boolean {
return if (allowedHosts.contains(hostname.toLowerCase())) {
return if (allowedHosts.contains(
hostname.lowercase(Locale.getDefault())
)) {
// good
logI("CustomHostnameVerifier::verify",
"Allowing registered host: $hostname")
logI(
"CustomHostnameVerifier::verify",
"Allowing registered host: $hostname"
)
true
} else {
defaultHostnameVerifier.verify(hostname, session)
@ -29,7 +32,7 @@ class CustomHostnameVerifier(context: Context) : HostnameVerifier {
val certs = certManager.readAllCerts(context)
allowedHosts.clear()
for (c in certs) {
allowedHosts.add(c.first.host.toLowerCase())
allowedHosts.add(c.first.host.lowercase(Locale.getDefault()))
}
}

View file

@ -6,11 +6,11 @@ import android.os.Bundle
import androidx.annotation.NonNull
import com.google.android.gms.maps.MapsInitializer
import com.google.android.gms.maps.OnMapsSdkInitializedCallback
import com.nkming.nc_photos.np_android_log.logD
import com.nkming.nc_photos.np_android_log.logE
import com.nkming.nc_photos.np_android_log.logI
import com.nkming.nc_photos.plugin.NcPhotosPlugin
import com.nkming.nc_photos.plugin.UriUtil
import com.nkming.nc_photos.plugin.logD
import com.nkming.nc_photos.plugin.logE
import com.nkming.nc_photos.plugin.logI
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.EventChannel

View file

@ -1,8 +1,7 @@
package com.nkming.nc_photos
import android.app.Activity
import com.nkming.nc_photos.plugin.logE
import io.flutter.Log
import com.nkming.nc_photos.np_android_log.logE
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import javax.net.ssl.HttpsURLConnection
@ -50,9 +49,11 @@ class SelfSignedCertChannelHandler(activity: Activity) :
HttpsURLConnection.setDefaultSSLSocketFactory(_sslSocketFactory)
HttpsURLConnection.setDefaultHostnameVerifier(_hostNameVerifier)
} catch (e: Exception) {
logE("SelfSignedCertChannelHandler::init",
logE(
"SelfSignedCertChannelHandler::init",
"Failed while setting custom SSL handler, self-signed cert will not work",
e)
e
)
}
}
}

View file

@ -2,28 +2,29 @@ package com.nkming.nc_photos
import android.content.Context
import android.util.Pair
import com.nkming.nc_photos.plugin.logE
import com.nkming.nc_photos.plugin.logI
import io.flutter.Log
import com.nkming.nc_photos.np_android_log.logE
import com.nkming.nc_photos.np_android_log.logI
import org.json.JSONObject
import java.io.File
import java.io.FileInputStream
import java.security.cert.Certificate
import java.security.cert.CertificateException
import java.security.cert.CertificateFactory
import java.time.OffsetDateTime
import java.util.*
// Modifications to this class must also reflect on dart side
data class CertInfo(val host: String, val sha1: String, val subject: String,
data class CertInfo(
val host: String, val sha1: String, val subject: String,
val issuer: String, val startValidity: OffsetDateTime,
val endValidity: OffsetDateTime) {
val endValidity: OffsetDateTime
) {
companion object {
fun fromJson(json: JSONObject): CertInfo {
return CertInfo(json.getString("host"), json.getString("sha1"),
return CertInfo(
json.getString("host"), json.getString("sha1"),
json.getString("subject"), json.getString("issuer"),
OffsetDateTime.parse(json.getString("startValidity")),
OffsetDateTime.parse(json.getString("endValidity")))
OffsetDateTime.parse(json.getString("endValidity"))
)
}
}
}
@ -49,12 +50,16 @@ class SelfSignedCertManager {
val jsonFile = File(certDir, f.name + ".json")
val jsonStr = jsonFile.bufferedReader().use { it.readText() }
val info = CertInfo.fromJson(JSONObject(jsonStr))
logI("SelfSignedCertManager::readAllCerts",
"Found certificate: ${f.name} for host: ${info.host}")
logI(
"SelfSignedCertManager::readAllCerts",
"Found certificate: ${f.name} for host: ${info.host}"
)
products.add(Pair(info, c))
} catch (e: Exception) {
logE("SelfSignedCertManager::readAllCerts",
"Failed to read certificate file: ${f.name}", e)
logE(
"SelfSignedCertManager::readAllCerts",
"Failed to read certificate file: ${f.name}", e
)
}
}
return products
@ -89,8 +94,10 @@ class SelfSignedCertManager {
certDir.mkdir()
certDir
} else if (!certDir.isDirectory) {
logE("SelfSignedCertManager::openCertsDir",
"Removing certs file to make way for the directory")
logE(
"SelfSignedCertManager::openCertsDir",
"Removing certs file to make way for the directory"
)
certDir.delete()
certDir.mkdir()
certDir

View file

@ -1,6 +1,5 @@
#Fri Jun 23 08:50:38 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.2-bin.zip

View file

@ -1,4 +1,5 @@
include ':app'
includeBuild '../../np_android_log'
def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
def properties = new Properties()

View file

@ -1,6 +1,6 @@
import 'package:nc_photos/platform/k.dart' as platform_k;
import 'package:nc_photos/web/lock.dart' as web;
import 'package:nc_photos_plugin/nc_photos_plugin.dart' as plugin;
import 'package:np_platform_lock/np_platform_lock.dart' as plugin;
class Lock {
static Future<T> synchronized<T>(int lockId, Future<T> Function() fn) async {

View file

@ -18,6 +18,7 @@ import 'package:nc_photos/platform/k.dart' as platform_k;
import 'package:nc_photos/snack_bar_manager.dart';
import 'package:nc_photos/widget/page_visibility_mixin.dart';
import 'package:np_codegen/np_codegen.dart';
import 'package:np_platform_lock/np_platform_lock.dart';
import 'package:to_string/to_string.dart';
part 'developer/bloc.dart';

View file

@ -997,6 +997,13 @@ packages:
relative: true
source: path
version: "1.0.0"
np_platform_lock:
dependency: "direct main"
description:
path: "../np_platform_lock"
relative: true
source: path
version: "0.0.1"
np_string:
dependency: "direct main"
description:

View file

@ -109,6 +109,8 @@ dependencies:
path: ../np_log
np_math:
path: ../np_math
np_platform_lock:
path: ../np_platform_lock
np_string:
path: ../np_string
np_ui:

10
np_android_log/.gitignore vendored Normal file
View file

@ -0,0 +1,10 @@
*.iml
.gradle
/local.properties
.idea
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties

View file

@ -0,0 +1,54 @@
group 'com.nkming.nc_photos.np_android_log'
version '1.0-SNAPSHOT'
buildscript {
ext.kotlin_version = '1.8.20'
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
rootProject.allprojects {
repositories {
google()
mavenCentral()
}
}
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
android {
namespace 'com.nkming.nc_photos.np_android_log'
compileSdk 31
defaultConfig {
minSdk 21
consumerProguardFiles "consumer-rules.pro"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
}

View file

View file

@ -0,0 +1,23 @@
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true

View file

@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

21
np_android_log/proguard-rules.pro vendored Normal file
View file

@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

View file

@ -0,0 +1 @@
rootProject.name = "np_android_log"

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
</manifest>

View file

@ -1,10 +1,10 @@
package com.nkming.nc_photos.plugin
package com.nkming.nc_photos.np_android_log
class LogConfig {
companion object {
var isShowInfo = true
var isShowDebug = BuildConfig.DEBUG
var isShowVerbose = BuildConfig.DEBUG
var isShowDebug = true
var isShowVerbose = true
}
}

30
np_platform_lock/.gitignore vendored Normal file
View file

@ -0,0 +1,30 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/
# IntelliJ related
*.iml
*.ipr
*.iws
.idea/
# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/
# Flutter/Dart/Pub related
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
/pubspec.lock
**/doc/api/
.dart_tool/
.packages
build/

View file

@ -0,0 +1,30 @@
# 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.
version:
revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf
channel: stable
project_type: plugin
# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf
base_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf
- platform: android
create_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf
base_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf
# User provided section
# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'

View file

@ -0,0 +1 @@
include: package:np_lints/np.yaml

9
np_platform_lock/android/.gitignore vendored Normal file
View file

@ -0,0 +1,9 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.cxx

View file

@ -0,0 +1,56 @@
group 'com.nkming.nc_photos.np_platform_lock'
version '1.0-SNAPSHOT'
buildscript {
ext.kotlin_version = '1.8.20'
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
rootProject.allprojects {
repositories {
google()
mavenCentral()
}
}
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
android {
namespace 'com.nkming.nc_photos.np_platform_lock'
compileSdk 31
defaultConfig {
minSdk 21
consumerProguardFiles "consumer-rules.pro"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation "androidx.annotation:annotation:1.6.0"
implementation 'com.nkming.nc_photos.np_android_log:np_android_log'
}

View file

@ -0,0 +1,14 @@
## For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
#
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx1024m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
#
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
android.enableJetifier=true
android.useAndroidX=true

View file

@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View file

@ -0,0 +1,2 @@
rootProject.name = 'np_platform_lock'
includeBuild '../../np_android_log'

View file

@ -0,0 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.nkming.nc_photos.np_platform_lock">
</manifest>

View file

@ -0,0 +1,7 @@
package com.nkming.nc_photos.np_platform_lock
interface K {
companion object {
const val LIB_ID = "com.nkming.nc_photos.np_platform_lock"
}
}

View file

@ -1,5 +1,6 @@
package com.nkming.nc_photos.plugin
package com.nkming.nc_photos.np_platform_lock
import com.nkming.nc_photos.np_android_log.logW
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel

View file

@ -0,0 +1,27 @@
package com.nkming.nc_photos.np_platform_lock
import androidx.annotation.NonNull
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.plugin.common.MethodChannel
class NpPlatformLockPlugin : FlutterPlugin {
override fun onAttachedToEngine(
@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding
) {
lockChannelHandler = LockChannelHandler()
lockChannel = MethodChannel(
flutterPluginBinding.binaryMessenger, LockChannelHandler.CHANNEL
)
lockChannel.setMethodCallHandler(lockChannelHandler)
}
override fun onDetachedFromEngine(
@NonNull binding: FlutterPlugin.FlutterPluginBinding
) {
lockChannelHandler.dismiss()
lockChannel.setMethodCallHandler(null)
}
private lateinit var lockChannel: MethodChannel
private lateinit var lockChannelHandler: LockChannelHandler
}

View file

@ -0,0 +1,3 @@
library np_platform_lock;
export 'src/lock.dart';

View file

@ -0,0 +1 @@
const libId = "com.nkming.nc_photos.np_platform_lock";

View file

@ -1,5 +1,5 @@
import 'package:flutter/services.dart';
import 'package:nc_photos_plugin/src/k.dart' as k;
import 'package:np_platform_lock/src/k.dart' as k;
class Lock {
static Future<bool> tryLock(int lockId) async {

View file

@ -0,0 +1,24 @@
name: np_platform_lock
description: A new Flutter plugin project.
version: 0.0.1
homepage:
publish_to: none
environment:
sdk: '>=2.19.6 <3.0.0'
flutter: ">=3.3.0"
dependencies:
flutter:
sdk: flutter
dev_dependencies:
np_lints:
path: ../np_lints
flutter:
plugin:
platforms:
android:
package: com.nkming.nc_photos.np_platform_lock
pluginClass: NpPlatformLockPlugin

View file

@ -6,6 +6,7 @@ buildscript {
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
dependencies {
@ -26,7 +27,8 @@ apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
android {
compileSdkVersion 31
namespace 'com.nkming.nc_photos.plugin'
compileSdk 31
ndkVersion "23.2.8568313"
compileOptions {
@ -43,12 +45,8 @@ android {
disable 'LongLogTag'
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
minSdkVersion 21
minSdk 21
ndk {
abiFilters "armeabi-v7a", "arm64-v8a", "x86_64"
}
@ -67,4 +65,5 @@ dependencies {
implementation "androidx.core:core-ktx:1.10.1"
implementation "androidx.exifinterface:exifinterface:1.3.6"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "com.nkming.nc_photos.np_android_log:np_android_log"
}

View file

@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.2-bin.zip

View file

@ -1 +1,2 @@
rootProject.name = 'plugin'
includeBuild '../../np_android_log'

View file

@ -6,6 +6,9 @@ import android.graphics.BitmapFactory
import android.graphics.Matrix
import android.net.Uri
import androidx.exifinterface.media.ExifInterface
import com.nkming.nc_photos.np_android_log.logD
import com.nkming.nc_photos.np_android_log.logE
import com.nkming.nc_photos.np_android_log.logI
import java.io.InputStream
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind

View file

@ -3,6 +3,7 @@ package com.nkming.nc_photos.plugin
import android.content.Context
import android.net.Uri
import androidx.core.content.FileProvider
import com.nkming.nc_photos.np_android_log.logE
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import java.io.File

View file

@ -4,6 +4,7 @@ import android.content.Context
import android.content.Intent
import android.net.Uri
import androidx.core.content.ContextCompat
import com.nkming.nc_photos.np_android_log.logE
import com.nkming.nc_photos.plugin.image_processor.*
import io.flutter.plugin.common.EventChannel
import io.flutter.plugin.common.MethodCall

View file

@ -18,6 +18,10 @@ import androidx.core.app.NotificationChannelCompat
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.exifinterface.media.ExifInterface
import com.nkming.nc_photos.np_android_log.logD
import com.nkming.nc_photos.np_android_log.logE
import com.nkming.nc_photos.np_android_log.logI
import com.nkming.nc_photos.np_android_log.logW
import com.nkming.nc_photos.plugin.image_processor.*
import java.io.File
import java.io.Serializable
@ -116,13 +120,16 @@ class ImageProcessorService : Service() {
METHOD_DEEP_LAP_PORTRAIT -> onDeepLapPortrait(
startId, intent.extras!!
)
METHOD_ESRGAN -> onEsrgan(startId, intent.extras!!)
METHOD_ARBITRARY_STYLE_TRANSFER -> onArbitraryStyleTransfer(
startId, intent.extras!!
)
METHOD_DEEP_LAP_COLOR_POP -> onDeepLapColorPop(
startId, intent.extras!!
)
METHOD_NEUR_OP -> onNeurOp(startId, intent.extras!!)
METHOD_FILTER -> onFilter(startId, intent.extras!!)
else -> {
@ -141,40 +148,33 @@ class ImageProcessorService : Service() {
}
private fun onZeroDce(startId: Int, extras: Bundle) {
return onMethod(
startId, extras, { params ->
return onMethod(startId, extras, { params ->
ImageProcessorZeroDceCommand(
params, extras.getIntOrNull(EXTRA_ITERATION)
)
}
)
})
}
private fun onDeepLapPortrait(startId: Int, extras: Bundle) {
return onMethod(
startId, extras, { params ->
return onMethod(startId, extras, { params ->
ImageProcessorDeepLapPortraitCommand(
params, extras.getIntOrNull(EXTRA_RADIUS)
)
}
)
})
}
private fun onEsrgan(startId: Int, extras: Bundle) {
return onMethod(
startId, extras, { params -> ImageProcessorEsrganCommand(params) })
return onMethod(startId, extras,
{ params -> ImageProcessorEsrganCommand(params) })
}
private fun onArbitraryStyleTransfer(startId: Int, extras: Bundle) {
return onMethod(
startId, extras, { params ->
return onMethod(startId, extras, { params ->
ImageProcessorArbitraryStyleTransferCommand(
params,
extras.getParcelable(EXTRA_STYLE_URI)!!,
params, extras.getParcelable(EXTRA_STYLE_URI)!!,
extras.getFloat(EXTRA_WEIGHT)
)
}
)
})
}
private fun onDeepLapColorPop(startId: Int, extras: Bundle) {
@ -201,8 +201,7 @@ class ImageProcessorService : Service() {
val fileUrl = extras.getString(EXTRA_FILE_URL)!!
@Suppress("Unchecked_cast")
val headers =
@Suppress("Unchecked_cast") val headers =
extras.getSerializable(EXTRA_HEADERS) as HashMap<String, String>?
val filename = extras.getString(EXTRA_FILENAME)!!
val maxWidth = extras.getInt(EXTRA_MAX_WIDTH)
@ -211,8 +210,8 @@ class ImageProcessorService : Service() {
addCommand(
ImageProcessorFilterCommand(
ImageProcessorImageCommand.Params(
startId, fileUrl, headers, filename, maxWidth,
maxHeight, isSaveToServer
startId, fileUrl, headers, filename, maxWidth, maxHeight,
isSaveToServer
), filters
)
)
@ -231,8 +230,7 @@ class ImageProcessorService : Service() {
) {
val fileUrl = extras.getString(EXTRA_FILE_URL)!!
@Suppress("Unchecked_cast")
val headers =
@Suppress("Unchecked_cast") val headers =
extras.getSerializable(EXTRA_HEADERS) as HashMap<String, String>?
val filename = extras.getString(EXTRA_FILENAME)!!
val maxWidth = extras.getInt(EXTRA_MAX_WIDTH)
@ -241,8 +239,8 @@ class ImageProcessorService : Service() {
addCommand(
builder(
ImageProcessorImageCommand.Params(
startId, fileUrl, headers, filename, maxWidth,
maxHeight, isSaveToServer
startId, fileUrl, headers, filename, maxWidth, maxHeight,
isSaveToServer
)
)
)
@ -357,14 +355,16 @@ class ImageProcessorService : Service() {
cmds.removeFirst()
stopSelf(cmd.startId)
cmdTask = null
@Suppress("Deprecation")
if (cmds.isNotEmpty() && !isCancelled) {
@Suppress(
"Deprecation"
) if (cmds.isNotEmpty() && !isCancelled) {
runCommand()
}
}
}.apply {
@Suppress("Deprecation")
executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, cmd)
@Suppress("Deprecation") executeOnExecutor(
AsyncTask.THREAD_POOL_EXECUTOR, cmd
)
}
}
@ -375,8 +375,8 @@ class ImageProcessorService : Service() {
notificationManager.notify(
NOTIFICATION_ID, buildGracePeriodNotification()
)
@Suppress("Deprecation")
cmdTask = object : AsyncTask<Unit, Unit, Unit>(), AsyncTaskCancellable {
@Suppress("Deprecation") cmdTask =
object : AsyncTask<Unit, Unit, Unit>(), AsyncTaskCancellable {
override fun doInBackground(vararg params: Unit?) {
// 10 seconds
for (i in 0 until 20) {
@ -802,8 +802,7 @@ private open class ImageProcessorCommandTask(context: Context) :
}.use {
val responseCode = it.responseCode
if (responseCode / 100 == 2) {
val file =
File.createTempFile("img", null, getTempDir(context))
val file = File.createTempFile("img", null, getTempDir(context))
file.outputStream().use { oStream ->
it.inputStream.copyTo(oStream)
}
@ -918,8 +917,7 @@ private class EnhancedFileDevicePersister(context: Context) :
val context = context
}
private class EnhancedFileServerPersister :
EnhancedFilePersister {
private class EnhancedFileServerPersister : EnhancedFilePersister {
companion object {
const val TAG = "EnhancedFileServerPersister"
}

View file

@ -7,6 +7,8 @@ import android.content.Intent
import android.net.Uri
import android.os.Build
import android.provider.MediaStore
import com.nkming.nc_photos.np_android_log.logE
import com.nkming.nc_photos.np_android_log.logI
import io.flutter.embedding.engine.plugins.activity.ActivityAware
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
import io.flutter.plugin.common.EventChannel

View file

@ -2,6 +2,7 @@ package com.nkming.nc_photos.plugin
import android.content.Intent
import androidx.annotation.NonNull
import com.nkming.nc_photos.np_android_log.logE
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.embedding.engine.plugins.activity.ActivityAware
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
@ -31,12 +32,6 @@ class NcPhotosPlugin : FlutterPlugin, ActivityAware,
override fun onAttachedToEngine(
@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding
) {
lockChannelHandler = LockChannelHandler()
lockChannel = MethodChannel(
flutterPluginBinding.binaryMessenger, LockChannelHandler.CHANNEL
)
lockChannel.setMethodCallHandler(lockChannelHandler)
notificationChannel = MethodChannel(
flutterPluginBinding.binaryMessenger,
NotificationChannelHandler.CHANNEL
@ -130,8 +125,6 @@ class NcPhotosPlugin : FlutterPlugin, ActivityAware,
override fun onDetachedFromEngine(
@NonNull binding: FlutterPlugin.FlutterPluginBinding
) {
lockChannelHandler.dismiss()
lockChannel.setMethodCallHandler(null)
notificationChannel.setMethodCallHandler(null)
nativeEventChannel.setStreamHandler(null)
nativeEventMethodChannel.setMethodCallHandler(null)
@ -220,7 +213,6 @@ class NcPhotosPlugin : FlutterPlugin, ActivityAware,
private var pluginBinding: ActivityPluginBinding? = null
private lateinit var lockChannel: MethodChannel
private lateinit var notificationChannel: MethodChannel
private lateinit var nativeEventChannel: EventChannel
private lateinit var nativeEventMethodChannel: MethodChannel
@ -234,7 +226,6 @@ class NcPhotosPlugin : FlutterPlugin, ActivityAware,
private lateinit var preferenceMethodChannel: MethodChannel
private lateinit var imageLoaderMethodChannel: MethodChannel
private lateinit var lockChannelHandler: LockChannelHandler
private lateinit var mediaStoreChannelHandler: MediaStoreChannelHandler
private lateinit var permissionChannelHandler: PermissionChannelHandler
}

View file

@ -12,6 +12,7 @@ import android.net.Uri
import android.os.Build
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import com.nkming.nc_photos.np_android_log.logE
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import kotlin.math.max

View file

@ -3,6 +3,7 @@ package com.nkming.nc_photos.plugin
import android.content.Context
import android.net.Uri
import android.provider.MediaStore
import com.nkming.nc_photos.np_android_log.logI
interface UriUtil {
companion object {

View file

@ -3,6 +3,7 @@ package com.nkming.nc_photos.plugin
import android.app.PendingIntent
import android.os.Build
import android.os.Bundle
import com.nkming.nc_photos.np_android_log.logI
import java.io.Serializable
import java.net.HttpURLConnection

View file

@ -4,9 +4,9 @@ import android.content.Context
import android.content.res.AssetManager
import android.graphics.Bitmap
import android.net.Uri
import com.nkming.nc_photos.np_android_log.logI
import com.nkming.nc_photos.plugin.BitmapResizeMethod
import com.nkming.nc_photos.plugin.BitmapUtil
import com.nkming.nc_photos.plugin.logI
import com.nkming.nc_photos.plugin.use
class ArbitraryStyleTransfer(

View file

@ -1,7 +1,7 @@
package com.nkming.nc_photos.plugin.image_processor
import androidx.exifinterface.media.ExifInterface
import com.nkming.nc_photos.plugin.logI
import com.nkming.nc_photos.np_android_log.logI
/**
* Lossless rotation is done by modifying the EXIF orientation tag in such a way

View file

@ -5,7 +5,6 @@ export 'src/exception.dart';
export 'src/image.dart';
export 'src/image_loader.dart';
export 'src/image_processor.dart';
export 'src/lock.dart';
export 'src/logcat.dart';
export 'src/media_store.dart';
export 'src/native_event.dart';