diff --git a/.metadata b/.metadata
index df45ecd..840c299 100644
--- a/.metadata
+++ b/.metadata
@@ -1,10 +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 and should not be manually edited.
+# This file should be version controlled.
version:
- revision: b101bfe32f634566e7cb2791a9efe19cf8828b15
- channel: beta
+ revision: cd41fdd495f6944ecd3506c21e94c6567b073278
+ channel: unknown
project_type: app
+
+# Tracks metadata for the flutter migrate command
+migration:
+ platforms:
+ - platform: root
+ create_revision: cd41fdd495f6944ecd3506c21e94c6567b073278
+ base_revision: cd41fdd495f6944ecd3506c21e94c6567b073278
+ - platform: android
+ create_revision: cd41fdd495f6944ecd3506c21e94c6567b073278
+ base_revision: cd41fdd495f6944ecd3506c21e94c6567b073278
+
+ # 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'
diff --git a/android/app/build.gradle b/android/app/build.gradle
index 710d120..97a6fde 100644
--- a/android/app/build.gradle
+++ b/android/app/build.gradle
@@ -8,7 +8,7 @@ if (localPropertiesFile.exists()) {
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
- throw new Exception("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
+ throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
@@ -28,24 +28,19 @@ apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
// compileSdkVersion flutter.compileSdkVersion
compileSdkVersion 32
- ndkVersion "23.1.7779620"
+ ndkVersion flutter.ndkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
- kotlinOptions {
- jvmTarget = '1.8'
- }
-
- sourceSets {
- main.java.srcDirs += 'src/main/kotlin'
- }
-
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "cn.com.motse.fengshui_compass"
+ // You can update the following values to match your application needs.
+ // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
+// minSdkVersion flutter.minSdkVersion
minSdkVersion 19
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
@@ -59,19 +54,8 @@ android {
signingConfig signingConfigs.debug
}
}
-
- lintOptions {
- disable 'InvalidPackage'
- disable "Instantiatable"
- checkReleaseBuilds false
- abortOnError false
- }
}
flutter {
source '../..'
}
-
-dependencies {
- implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
-}
diff --git a/android/app/src/debug/AndroidManifest.xml b/android/app/src/debug/AndroidManifest.xml
index 44c27bd..a42f077 100644
--- a/android/app/src/debug/AndroidManifest.xml
+++ b/android/app/src/debug/AndroidManifest.xml
@@ -1,6 +1,7 @@
+ * author: Blankj + * blog : http://blankj.com + * time : 2016/08/07 + * desc : utils about shell + *+ */ +public final class ComShellUtils { + public static final String TAG = "CommandExecution"; + + public final static String COMMAND_SU = "su"; + public final static String COMMAND_SH = "sh"; + public final static String COMMAND_EXIT = "exit\n"; + public final static String COMMAND_LINE_END = "\n"; + + /** + * Command执行结果 + * + * @author Mountain + */ + public static class CommandResult { + public int result = -1; + public String errorMsg; + public String successMsg; + + @Override + public String toString() { + return "CommandResult{" + + "result=" + result + + ", errorMsg='" + errorMsg + '\'' + + ", successMsg='" + successMsg + '\'' + + '}'; + } + } + + /** + * 执行命令—单条 + * + * @param command + * @param isRoot + * @return + */ + public static CommandResult execCommand(String command, boolean isRoot) { + String[] commands = {command}; + return execCommand(commands, isRoot); + } + + /** + * 执行命令-多条 + * + * @param commands + * @param isRoot + * @return + */ + public static CommandResult execCommand(String[] commands, boolean isRoot) { + CommandResult commandResult = new CommandResult(); + if (commands == null || commands.length == 0) return commandResult; + Process process = null; + DataOutputStream os = null; + BufferedReader successResult = null; + BufferedReader errorResult = null; + StringBuilder successMsg = null; + StringBuilder errorMsg = null; + try { + process = Runtime.getRuntime().exec(isRoot ? COMMAND_SU : COMMAND_SH); + os = new DataOutputStream(process.getOutputStream()); + for (String command : commands) { + if (command != null) { + os.write(command.getBytes()); + os.writeBytes(COMMAND_LINE_END); + os.flush(); + } + } + os.writeBytes(COMMAND_EXIT); + os.flush(); + commandResult.result = process.waitFor(); + //获取错误信息 + successMsg = new StringBuilder(); + errorMsg = new StringBuilder(); + successResult = new BufferedReader(new InputStreamReader(process.getInputStream())); + errorResult = new BufferedReader(new InputStreamReader(process.getErrorStream())); + String s; + while ((s = successResult.readLine()) != null) { + successMsg.append(s); + } + while ((s = errorResult.readLine()) != null) { + errorMsg.append(s); + } + commandResult.successMsg = successMsg.toString(); + commandResult.errorMsg = errorMsg.toString(); + Log.i(TAG, commandResult.result + " | " + commandResult.successMsg + + " | " + commandResult.errorMsg); + } catch (IOException e) { + String errmsg = e.getMessage(); + if (errmsg != null) { + Log.e(TAG, errmsg); + } else { + e.printStackTrace(); + } + } catch (Exception e) { + String errmsg = e.getMessage(); + if (errmsg != null) { + Log.e(TAG, errmsg); + } else { + e.printStackTrace(); + } + } finally { + try { + if (os != null) { + os.close(); + } + if (successResult != null) { + successResult.close(); + } + if (errorResult != null) { + errorResult.close(); + } + } catch (IOException e) { + String errmsg = e.getMessage(); + if (errmsg != null) { + Log.e(TAG, errmsg); + } else { + e.printStackTrace(); + } + } + if (process != null) { + process.destroy(); + } + } + return commandResult; + } +} diff --git a/android/app/src/main/java/cn/com/motse/fengshui_compass/MainActivity.java b/android/app/src/main/java/cn/com/motse/fengshui_compass/MainActivity.java new file mode 100644 index 0000000..749bfec --- /dev/null +++ b/android/app/src/main/java/cn/com/motse/fengshui_compass/MainActivity.java @@ -0,0 +1,45 @@ +package cn.com.motse.fengshui_compass; + + +import androidx.annotation.NonNull; + +import io.flutter.embedding.android.FlutterActivity; +import io.flutter.embedding.engine.FlutterEngine; +import io.flutter.plugin.common.MethodChannel; + +public class MainActivity extends FlutterActivity { + private static final String CHANNEL = "toggle_power"; + + @Override + public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) { + super.configureFlutterEngine(flutterEngine); + new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), CHANNEL) + .setMethodCallHandler( + (call, result) -> { + if (call.method.equals("turnOnPower")) { + String state = "1"; + String ioValue = "236"; + String cmdStr1 = "echo " + ioValue + " > /sys/class/gpio/export"; + String cmdStr2 = "echo out > /sys/class/gpio/gpio" + ioValue + "/direction"; + String cmdStr3 = "echo " + state + " > /sys/class/gpio/gpio" + ioValue + "/value"; + ComShellUtils.execCommand(cmdStr1, false); + ComShellUtils.execCommand(cmdStr2, false); + ComShellUtils.execCommand(cmdStr3, false); + result.success("on"); + } else if (call.method.equals("turnOffPower")) { + String state = "0"; + String ioValue = "236"; + String cmdStr1 = "echo " + ioValue + " > /sys/class/gpio/export"; + String cmdStr2 = "echo out > /sys/class/gpio/gpio" + ioValue + "/direction"; + String cmdStr3 = "echo " + state + " > /sys/class/gpio/gpio" + ioValue + "/value"; + ComShellUtils.execCommand(cmdStr1, false); + ComShellUtils.execCommand(cmdStr2, false); + ComShellUtils.execCommand(cmdStr3, false); + result.success("off"); + } else { + result.notImplemented(); + } + } + ); + } +} diff --git a/android/app/src/main/kotlin/cn/com/motse/fengshui_compass/MainActivity.kt b/android/app/src/main/kotlin/cn/com/motse/fengshui_compass/MainActivity.kt deleted file mode 100644 index b511c1a..0000000 --- a/android/app/src/main/kotlin/cn/com/motse/fengshui_compass/MainActivity.kt +++ /dev/null @@ -1,6 +0,0 @@ -package cn.com.motse.fengshui_compass - -import io.flutter.embedding.android.FlutterActivity - -class MainActivity: FlutterActivity() { -} diff --git a/android/app/src/main/res/drawable/launch_background.xml b/android/app/src/main/res/drawable/launch_background.xml index 94fd4e7..304732f 100644 --- a/android/app/src/main/res/drawable/launch_background.xml +++ b/android/app/src/main/res/drawable/launch_background.xml @@ -1,12 +1,12 @@