├── app ├── .gitignore ├── src │ ├── main │ │ ├── ic_launcher-playstore.png │ │ ├── res │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ ├── ic_launcher_background.png │ │ │ │ └── ic_launcher_foreground.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ ├── ic_launcher_background.png │ │ │ │ └── ic_launcher_foreground.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ ├── ic_launcher_background.png │ │ │ │ └── ic_launcher_foreground.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ ├── ic_launcher_background.png │ │ │ │ └── ic_launcher_foreground.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ ├── ic_launcher_background.png │ │ │ │ └── ic_launcher_foreground.png │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ └── ic_launcher.xml │ │ │ └── values │ │ │ │ └── strings.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── green_green_avk │ │ │ └── anothertermshellplugin │ │ │ └── ShellService.java │ ├── test │ │ └── java │ │ │ └── green_green_avk │ │ │ └── anothertermshellplugin_batteryinfo │ │ │ └── ExampleUnitTest.java │ ├── debug │ │ └── res │ │ │ └── values │ │ │ └── strings.xml │ └── androidTest │ │ └── java │ │ └── green_green_avk │ │ └── anothertermshellplugin_batteryinfo │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── .idea ├── .name ├── compiler.xml ├── vcs.xml ├── gradle.xml ├── jarRepositories.xml ├── codeStyles │ └── Project.xml └── misc.xml ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── README.md ├── .gitignore ├── LICENSE ├── gradle.properties ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | /release 3 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | Another Term Shell Plugin - Battery Info -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name='Another Term Shell Plugin - Battery Info' 2 | include ':app' 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/green-green-avk/AnotherTermShellPlugin-BatteryInfo/master/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/ic_launcher-playstore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/green-green-avk/AnotherTermShellPlugin-BatteryInfo/master/app/src/main/ic_launcher-playstore.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/green-green-avk/AnotherTermShellPlugin-BatteryInfo/master/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/green-green-avk/AnotherTermShellPlugin-BatteryInfo/master/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/green-green-avk/AnotherTermShellPlugin-BatteryInfo/master/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/green-green-avk/AnotherTermShellPlugin-BatteryInfo/master/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/green-green-avk/AnotherTermShellPlugin-BatteryInfo/master/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/green-green-avk/AnotherTermShellPlugin-BatteryInfo/master/app/src/main/res/mipmap-hdpi/ic_launcher_background.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/green-green-avk/AnotherTermShellPlugin-BatteryInfo/master/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/green-green-avk/AnotherTermShellPlugin-BatteryInfo/master/app/src/main/res/mipmap-mdpi/ic_launcher_background.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/green-green-avk/AnotherTermShellPlugin-BatteryInfo/master/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/green-green-avk/AnotherTermShellPlugin-BatteryInfo/master/app/src/main/res/mipmap-xhdpi/ic_launcher_background.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/green-green-avk/AnotherTermShellPlugin-BatteryInfo/master/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/green-green-avk/AnotherTermShellPlugin-BatteryInfo/master/app/src/main/res/mipmap-xxhdpi/ic_launcher_background.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/green-green-avk/AnotherTermShellPlugin-BatteryInfo/master/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/green-green-avk/AnotherTermShellPlugin-BatteryInfo/master/app/src/main/res/mipmap-xxxhdpi/ic_launcher_background.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/green-green-avk/AnotherTermShellPlugin-BatteryInfo/master/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Another Term Shell Plugin - Battery Info 2 | 3 | 4 | 5 | A very simple plugin that could be used as an example. 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Oct 14 20:48:15 PDT 2020 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/test/java/green_green_avk/anothertermshellplugin_batteryinfo/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package green_green_avk.anothertermshellplugin_batteryinfo; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.assertEquals; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /app/src/debug/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Another Term Shell Plugin - Battery Info (Debug) 4 | Just the battery status.

6 |

Usage example 7 | (from Another Term) 8 | (debug version):
9 | \"$TERMSH\" plugin green_green_avk.anothertermshellplugin_batteryinfo.debug 10 |

11 | ]]>
12 |
13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2021 Aleksandr Kiselev 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 11 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 19 | 20 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | 23 | #-dontshrink 24 | #-dontoptimize 25 | #-dontobfuscate 26 | #-dontpreverify 27 | -ignorewarnings 28 | -------------------------------------------------------------------------------- /app/src/androidTest/java/green_green_avk/anothertermshellplugin_batteryinfo/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package green_green_avk.anothertermshellplugin_batteryinfo; 2 | 3 | import android.content.Context; 4 | 5 | import androidx.test.ext.junit.runners.AndroidJUnit4; 6 | import androidx.test.platform.app.InstrumentationRegistry; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | 11 | import static org.junit.Assert.assertEquals; 12 | 13 | /** 14 | * Instrumented test, which will execute on an Android device. 15 | * 16 | * @see Testing documentation 17 | */ 18 | @RunWith(AndroidJUnit4.class) 19 | public class ExampleInstrumentedTest { 20 | @Test 21 | public void useAppContext() { 22 | // Context of the app under test. 23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); 24 | 25 | assertEquals("green_green_avk.anothertermshellplugin_batteryinfo", appContext.getPackageName()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app's APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | #android.enableR8.fullMode=true 21 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | } 4 | 5 | android { 6 | compileSdkVersion 30 7 | 8 | compileOptions { 9 | sourceCompatibility JavaVersion.VERSION_1_8 10 | targetCompatibility JavaVersion.VERSION_1_8 11 | } 12 | 13 | defaultConfig { 14 | applicationId "green_green_avk.anothertermshellplugin_batteryinfo" 15 | minSdkVersion 14 16 | targetSdkVersion 30 17 | versionCode 7 18 | versionName "1.6" 19 | 20 | resConfigs "en" 21 | 22 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 23 | } 24 | 25 | buildTypes { 26 | debug { 27 | applicationIdSuffix ".debug" 28 | } 29 | release { 30 | minifyEnabled true 31 | shrinkResources true 32 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 33 | } 34 | } 35 | } 36 | 37 | dependencies { 38 | testImplementation 'junit:junit:4.13.2' 39 | androidTestImplementation 'androidx.test.ext:junit:1.1.3' 40 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' 41 | implementation 'androidx.annotation:annotation:1.2.0' 42 | implementation 'com.github.green-green-avk:anothertermshellpluginutils:1.15' 43 | implementation 'com.github.green-green-avk:anothertermshellpluginutils-side-plugin:1.0' 44 | } 45 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Another Term Shell Plugin - Battery Info 3 | Not present 4 | External power source: %s 5 | 6 | AC 7 | USB 8 | Wireless 9 | 10 | 11 | Unable to obtain 12 | Unknown 13 | Charging 14 | Discharging 15 | Not charging 16 | Full 17 | 18 | 19 | Unable to obtain 20 | Unknown 21 | Good 22 | Overheat 23 | Dead 24 | Overvoltage 25 | Unspecified 26 | Cold 27 | 28 | Just the battery status.

30 |

Usage example 31 | (from Another Term):
32 | \"$TERMSH\" plugin green_green_avk.anothertermshellplugin_batteryinfo 33 |

34 | ]]>
35 |
36 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | 29 | 30 | 34 | 35 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
7 | 8 | 9 | 10 | xmlns:android 11 | 12 | ^$ 13 | 14 | 15 | 16 |
17 |
18 | 19 | 20 | 21 | xmlns:.* 22 | 23 | ^$ 24 | 25 | 26 | BY_NAME 27 | 28 |
29 |
30 | 31 | 32 | 33 | .*:id 34 | 35 | http://schemas.android.com/apk/res/android 36 | 37 | 38 | 39 |
40 |
41 | 42 | 43 | 44 | .*:name 45 | 46 | http://schemas.android.com/apk/res/android 47 | 48 | 49 | 50 |
51 |
52 | 53 | 54 | 55 | name 56 | 57 | ^$ 58 | 59 | 60 | 61 |
62 |
63 | 64 | 65 | 66 | style 67 | 68 | ^$ 69 | 70 | 71 | 72 |
73 |
74 | 75 | 76 | 77 | .* 78 | 79 | ^$ 80 | 81 | 82 | BY_NAME 83 | 84 |
85 |
86 | 87 | 88 | 89 | .* 90 | 91 | http://schemas.android.com/apk/res/android 92 | 93 | 94 | ANDROID_ATTRIBUTE_ORDER 95 | 96 |
97 |
98 | 99 | 100 | 101 | .* 102 | 103 | .* 104 | 105 | 106 | BY_NAME 107 | 108 |
109 |
110 |
111 |
112 |
113 |
-------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 32 | 53 | 54 | 55 | 56 | 57 | 58 | 60 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /app/src/main/java/green_green_avk/anothertermshellplugin/ShellService.java: -------------------------------------------------------------------------------- 1 | package green_green_avk.anothertermshellplugin; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.content.IntentFilter; 6 | import android.os.BatteryManager; 7 | import android.os.Build; 8 | import android.os.Bundle; 9 | import android.os.ParcelFileDescriptor; 10 | 11 | import androidx.annotation.ArrayRes; 12 | import androidx.annotation.NonNull; 13 | 14 | import java.io.FileOutputStream; 15 | import java.io.IOException; 16 | import java.io.OutputStream; 17 | import java.util.Locale; 18 | import java.util.concurrent.ExecutionException; 19 | 20 | import green_green_avk.anothertermshellplugin_batteryinfo.R; 21 | import green_green_avk.anothertermshellpluginutils.BaseShellService; 22 | import green_green_avk.anothertermshellpluginutils.ExecutionContext; 23 | import green_green_avk.anothertermshellpluginutils.MainThreadHelper; 24 | import green_green_avk.anothertermshellpluginutils.Protocol; 25 | import green_green_avk.anothertermshellpluginutils.Utils; 26 | 27 | public final class ShellService extends BaseShellService { 28 | 29 | private String getIntStr(final int v, @ArrayRes final int resId) { 30 | final String[] strs = 31 | this.getResources().getStringArray(resId); 32 | try { 33 | return strs[v]; 34 | } catch (final IndexOutOfBoundsException e) { 35 | return strs[0]; 36 | } 37 | } 38 | 39 | private String getFlagsStr(final int v, @ArrayRes final int resId) { 40 | final String[] strs = 41 | this.getResources().getStringArray(resId); 42 | final StringBuilder r = new StringBuilder(); 43 | for (int i = 0; i < strs.length; i++) { 44 | if ((v & (1 << i)) != 0) { 45 | if (i != 0) r.append(", "); 46 | r.append(strs[i]); 47 | } 48 | } 49 | return r.toString(); 50 | } 51 | 52 | private static final class BatteryInfo { 53 | private boolean present = false; 54 | private int plugged; 55 | private int level; // % 56 | private int status; 57 | private int health; 58 | private int temperature; // 0.1 C 59 | private int voltage; 60 | private String technology; 61 | private int current_now = 0; 62 | private int current_average = 0; 63 | private int charge_counter = -1; 64 | private long energy_counter = -1; 65 | } 66 | 67 | private static BatteryInfo getBatteryInfo(@NonNull final Context context) { 68 | final BatteryInfo r = new BatteryInfo(); 69 | final Intent batteryStatus = context.registerReceiver(null, 70 | new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); 71 | if (batteryStatus == null) return null; 72 | r.plugged = batteryStatus.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0); 73 | if (!(r.present = batteryStatus.getBooleanExtra(BatteryManager.EXTRA_PRESENT, false))) 74 | return r; 75 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 76 | final BatteryManager bm = (BatteryManager) context.getSystemService(BATTERY_SERVICE); 77 | r.level = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY); 78 | r.current_now = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CURRENT_NOW); 79 | r.current_average = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CURRENT_AVERAGE); 80 | r.charge_counter = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CHARGE_COUNTER); 81 | r.energy_counter = bm.getLongProperty(BatteryManager.BATTERY_PROPERTY_ENERGY_COUNTER); 82 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 83 | r.status = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_STATUS); 84 | } else { 85 | r.status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, 0); 86 | } 87 | } else { 88 | final int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); 89 | final int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1); 90 | if (level < 0 || scale < 1) r.level = -1; 91 | else r.level = (int) ((level / (double) scale) * 100); 92 | r.status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, 0); 93 | } 94 | r.health = batteryStatus.getIntExtra(BatteryManager.EXTRA_HEALTH, 0); 95 | r.temperature = batteryStatus.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, Integer.MIN_VALUE); 96 | r.voltage = batteryStatus.getIntExtra(BatteryManager.EXTRA_VOLTAGE, 0); 97 | r.technology = batteryStatus.getStringExtra(BatteryManager.EXTRA_TECHNOLOGY); 98 | return r; 99 | } 100 | 101 | @Override 102 | protected int onExec(@NonNull final ExecutionContext execCtx, 103 | @NonNull final byte[][] args, @NonNull final ParcelFileDescriptor[] fds) { 104 | final OutputStream stderr = new FileOutputStream(fds[2].getFileDescriptor()); 105 | final OutputStream stdout = new FileOutputStream(fds[1].getFileDescriptor()); 106 | try { 107 | final BatteryInfo r; 108 | try { 109 | r = MainThreadHelper.run(() -> getBatteryInfo(ShellService.this)); 110 | } catch (final ExecutionException e) { 111 | Utils.write(stderr, e.getMessage() + "\n"); 112 | return 1; 113 | } catch (final InterruptedException e) { 114 | Utils.write(stderr, e.getMessage() + "\n"); 115 | return 1; 116 | } 117 | if (r == null) { 118 | Utils.write(stderr, "Can't get battery info\n"); 119 | return 1; 120 | } 121 | Utils.write(stdout, String.format(Locale.ROOT, 122 | getString(R.string.msg_external_power_source_s) + "\n", 123 | getFlagsStr(r.plugged, R.array.msg_battery_plugged) 124 | )); 125 | if (!r.present) { 126 | Utils.write(stdout, getString(R.string.msg_battery_not_present) + "\n"); 127 | return 0; 128 | } 129 | Utils.write(stdout, String.format(Locale.ROOT, 130 | "%d%% / %s / %s / %d.%d °C / %d %sV / %s\n", 131 | r.level, 132 | getIntStr(r.status, R.array.msg_battery_status), 133 | getIntStr(r.health, R.array.msg_battery_health), 134 | r.temperature / 10, r.temperature % 10, 135 | // https://stackoverflow.com/questions/24500795/android-battery-voltage-unit-discrepancies 136 | r.voltage, r.voltage < 500 ? "" : "m", 137 | r.technology 138 | )); 139 | if (r.energy_counter >= 0) 140 | Utils.write(stdout, String.format(Locale.ROOT, 141 | "%d µA / %d µA / %d µA·h / %d nW·h\n", 142 | r.current_now, 143 | r.current_average, 144 | r.charge_counter, 145 | r.energy_counter 146 | )); 147 | return 0; 148 | } finally { 149 | try { 150 | stdout.close(); 151 | } catch (final IOException ignored) { 152 | } 153 | try { 154 | stderr.close(); 155 | } catch (final IOException ignored) { 156 | } 157 | } 158 | } 159 | 160 | @Override 161 | protected Bundle onMeta() { 162 | final Bundle b = new Bundle(); 163 | b.putInt(Protocol.META_KEY_INFO_RES_ID, R.string.desc_plugin); 164 | b.putInt(Protocol.META_KEY_INFO_RES_TYPE, Protocol.STRING_CONTENT_TYPE_XML_AT); 165 | return b; 166 | } 167 | } 168 | --------------------------------------------------------------------------------