From 87aee0102a25016c48e9db9abe96a89924739f39 Mon Sep 17 00:00:00 2001 From: Oksana Shevchenko Date: Tue, 30 Jun 2020 01:04:59 +0300 Subject: [PATCH 1/5] 04-LedApplication add application to control leds on the hikey board Signed-off-by: Oksana Shevchenko --- .../apps/LedControlApplication/.gitignore | 14 ++ .../apps/LedControlApplication/Android.mk | 22 +++ .../apps/LedControlApplication/app/.gitignore | 1 + .../LedControlApplication/app/build.gradle | 34 ++++ .../app/proguard-rules.pro | 21 +++ .../app/ExampleInstrumentedTest.java | 26 +++ .../app/src/main/AndroidManifest.xml | 21 +++ .../ledcontrol/ledservice/ILedInterface.aidl | 10 + .../shevchenko/ledcontrol/app/LedType.java | 15 ++ .../ledcontrol/app/MainActivity.java | 102 +++++++++++ .../drawable-v24/ic_launcher_foreground.xml | 30 +++ .../res/drawable/ic_launcher_background.xml | 170 +++++++++++++++++ .../app/src/main/res/layout/activity_main.xml | 98 ++++++++++ .../res/mipmap-anydpi-v26/ic_launcher.xml | 5 + .../mipmap-anydpi-v26/ic_launcher_round.xml | 5 + .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3593 bytes .../res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 5339 bytes .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2636 bytes .../res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 3388 bytes .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4926 bytes .../res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 7472 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 7909 bytes .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 11873 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 10652 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 16570 bytes .../app/src/main/res/values/colors.xml | 6 + .../app/src/main/res/values/strings.xml | 3 + .../app/src/main/res/values/styles.xml | 11 ++ .../ledcontrol/app/ExampleUnitTest.java | 17 ++ .../apps/LedControlApplication/build.gradle | 29 +++ .../LedControlApplication/gradle.properties | 15 ++ .../gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 54329 bytes .../gradle/wrapper/gradle-wrapper.properties | 6 + .../apps/LedControlApplication/gradlew | 172 ++++++++++++++++++ .../apps/LedControlApplication/gradlew.bat | 84 +++++++++ .../LedControlApplication/settings.gradle | 2 + 36 files changed, 919 insertions(+) create mode 100644 hikey960/packages/apps/LedControlApplication/.gitignore create mode 100644 hikey960/packages/apps/LedControlApplication/Android.mk create mode 100644 hikey960/packages/apps/LedControlApplication/app/.gitignore create mode 100644 hikey960/packages/apps/LedControlApplication/app/build.gradle create mode 100644 hikey960/packages/apps/LedControlApplication/app/proguard-rules.pro create mode 100644 hikey960/packages/apps/LedControlApplication/app/src/androidTest/java/com/example/shevchenko/ledcontrol/app/ExampleInstrumentedTest.java create mode 100644 hikey960/packages/apps/LedControlApplication/app/src/main/AndroidManifest.xml create mode 100644 hikey960/packages/apps/LedControlApplication/app/src/main/aidl/com/example/shevchenko/ledcontrol/ledservice/ILedInterface.aidl create mode 100644 hikey960/packages/apps/LedControlApplication/app/src/main/java/com/example/shevchenko/ledcontrol/app/LedType.java create mode 100644 hikey960/packages/apps/LedControlApplication/app/src/main/java/com/example/shevchenko/ledcontrol/app/MainActivity.java create mode 100644 hikey960/packages/apps/LedControlApplication/app/src/main/res/drawable-v24/ic_launcher_foreground.xml create mode 100644 hikey960/packages/apps/LedControlApplication/app/src/main/res/drawable/ic_launcher_background.xml create mode 100644 hikey960/packages/apps/LedControlApplication/app/src/main/res/layout/activity_main.xml create mode 100644 hikey960/packages/apps/LedControlApplication/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml create mode 100644 hikey960/packages/apps/LedControlApplication/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml create mode 100644 hikey960/packages/apps/LedControlApplication/app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 hikey960/packages/apps/LedControlApplication/app/src/main/res/mipmap-hdpi/ic_launcher_round.png create mode 100644 hikey960/packages/apps/LedControlApplication/app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 hikey960/packages/apps/LedControlApplication/app/src/main/res/mipmap-mdpi/ic_launcher_round.png create mode 100644 hikey960/packages/apps/LedControlApplication/app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 hikey960/packages/apps/LedControlApplication/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png create mode 100644 hikey960/packages/apps/LedControlApplication/app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 hikey960/packages/apps/LedControlApplication/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 hikey960/packages/apps/LedControlApplication/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 hikey960/packages/apps/LedControlApplication/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 hikey960/packages/apps/LedControlApplication/app/src/main/res/values/colors.xml create mode 100644 hikey960/packages/apps/LedControlApplication/app/src/main/res/values/strings.xml create mode 100644 hikey960/packages/apps/LedControlApplication/app/src/main/res/values/styles.xml create mode 100644 hikey960/packages/apps/LedControlApplication/app/src/test/java/com/example/shevchenko/ledcontrol/app/ExampleUnitTest.java create mode 100644 hikey960/packages/apps/LedControlApplication/build.gradle create mode 100644 hikey960/packages/apps/LedControlApplication/gradle.properties create mode 100644 hikey960/packages/apps/LedControlApplication/gradle/wrapper/gradle-wrapper.jar create mode 100644 hikey960/packages/apps/LedControlApplication/gradle/wrapper/gradle-wrapper.properties create mode 100755 hikey960/packages/apps/LedControlApplication/gradlew create mode 100644 hikey960/packages/apps/LedControlApplication/gradlew.bat create mode 100644 hikey960/packages/apps/LedControlApplication/settings.gradle diff --git a/hikey960/packages/apps/LedControlApplication/.gitignore b/hikey960/packages/apps/LedControlApplication/.gitignore new file mode 100644 index 0000000..603b140 --- /dev/null +++ b/hikey960/packages/apps/LedControlApplication/.gitignore @@ -0,0 +1,14 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx diff --git a/hikey960/packages/apps/LedControlApplication/Android.mk b/hikey960/packages/apps/LedControlApplication/Android.mk new file mode 100644 index 0000000..cd19bc2 --- /dev/null +++ b/hikey960/packages/apps/LedControlApplication/Android.mk @@ -0,0 +1,22 @@ +LOCAL_PATH := $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_MODULE_TAGS := optional +LOCAL_SRC_FILES := \ + $(call all-java-files-under, app/src/main/java) \ + $(call all-Iaidl-files-under, app/src/main/aidl) + +LOCAL_PACKAGE_NAME := LedControlApplication +LOCAL_MANIFEST_FILE := app/src/main/AndroidManifest.xml +LOCAL_CERTIFICATE := platform +LOCAL_PRIVATE_PLATFORM_APIS := true +LOCAL_USE_AAPT2 := true +LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/app/src/main/res +LOCAL_STATIC_ANDROID_LIBRARIES := \ + android-support-v7-appcompat \ + android-support-constraint-layout + +LOCAL_STATIC_JAVA_LIBRARIES += \ + android-support-constraint-layout-solver + +include $(BUILD_PACKAGE) diff --git a/hikey960/packages/apps/LedControlApplication/app/.gitignore b/hikey960/packages/apps/LedControlApplication/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/hikey960/packages/apps/LedControlApplication/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/hikey960/packages/apps/LedControlApplication/app/build.gradle b/hikey960/packages/apps/LedControlApplication/app/build.gradle new file mode 100644 index 0000000..19cc766 --- /dev/null +++ b/hikey960/packages/apps/LedControlApplication/app/build.gradle @@ -0,0 +1,34 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 28 + buildToolsVersion "29.0.3" + + defaultConfig { + applicationId "com.example.shevchenko.ledcontrol.app" + minSdkVersion 27 + targetSdkVersion 28 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + + implementation 'com.android.support:appcompat-v7:28.0.0' + implementation 'com.android.support.constraint:constraint-layout:1.1.3' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'com.android.support.test:runner:1.0.2' + androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' +} diff --git a/hikey960/packages/apps/LedControlApplication/app/proguard-rules.pro b/hikey960/packages/apps/LedControlApplication/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/hikey960/packages/apps/LedControlApplication/app/proguard-rules.pro @@ -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 diff --git a/hikey960/packages/apps/LedControlApplication/app/src/androidTest/java/com/example/shevchenko/ledcontrol/app/ExampleInstrumentedTest.java b/hikey960/packages/apps/LedControlApplication/app/src/androidTest/java/com/example/shevchenko/ledcontrol/app/ExampleInstrumentedTest.java new file mode 100644 index 0000000..17d7573 --- /dev/null +++ b/hikey960/packages/apps/LedControlApplication/app/src/androidTest/java/com/example/shevchenko/ledcontrol/app/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.shevchenko.ledcontrol.app; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + + assertEquals("com.example.shevchenko.ledcontrol.app", appContext.getPackageName()); + } +} diff --git a/hikey960/packages/apps/LedControlApplication/app/src/main/AndroidManifest.xml b/hikey960/packages/apps/LedControlApplication/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..bd3095c --- /dev/null +++ b/hikey960/packages/apps/LedControlApplication/app/src/main/AndroidManifest.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/hikey960/packages/apps/LedControlApplication/app/src/main/aidl/com/example/shevchenko/ledcontrol/ledservice/ILedInterface.aidl b/hikey960/packages/apps/LedControlApplication/app/src/main/aidl/com/example/shevchenko/ledcontrol/ledservice/ILedInterface.aidl new file mode 100644 index 0000000..adf0d3c --- /dev/null +++ b/hikey960/packages/apps/LedControlApplication/app/src/main/aidl/com/example/shevchenko/ledcontrol/ledservice/ILedInterface.aidl @@ -0,0 +1,10 @@ +package com.example.shevchenko.ledcontrol.ledservice; + +/** + * ILedInterface aidl interface + */ +interface ILedInterface { + + boolean updateState(String ledType, boolean turnOn); + boolean getLedState(String ledType); +} diff --git a/hikey960/packages/apps/LedControlApplication/app/src/main/java/com/example/shevchenko/ledcontrol/app/LedType.java b/hikey960/packages/apps/LedControlApplication/app/src/main/java/com/example/shevchenko/ledcontrol/app/LedType.java new file mode 100644 index 0000000..8113529 --- /dev/null +++ b/hikey960/packages/apps/LedControlApplication/app/src/main/java/com/example/shevchenko/ledcontrol/app/LedType.java @@ -0,0 +1,15 @@ +package com.example.shevchenko.ledcontrol.app; + +public enum LedType { + USER_LED_1("user_led1"), USER_LED_2("user_led2"), USER_LED_3("user_led3"), USER_LED_4("user_led4"), BT_LED("bt_active"), WIFI_LED("wifi_active"); + private final String name; + + LedType(String name) { + this.name = name; + } + + public String getName() { + return name; + } +} + diff --git a/hikey960/packages/apps/LedControlApplication/app/src/main/java/com/example/shevchenko/ledcontrol/app/MainActivity.java b/hikey960/packages/apps/LedControlApplication/app/src/main/java/com/example/shevchenko/ledcontrol/app/MainActivity.java new file mode 100644 index 0000000..122b130 --- /dev/null +++ b/hikey960/packages/apps/LedControlApplication/app/src/main/java/com/example/shevchenko/ledcontrol/app/MainActivity.java @@ -0,0 +1,102 @@ +package com.example.shevchenko.ledcontrol.app; + +import android.content.ComponentName; +import android.content.Intent; +import android.content.ServiceConnection; +import android.os.IBinder; +import android.os.RemoteException; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.CheckBox; + +import com.example.shevchenko.ledcontrol.ledservice.ILedInterface; + +public class MainActivity extends AppCompatActivity { + private final static String TAG = "LedControlApplication"; + private ILedInterface ledService; + + private ServiceConnection connection = new ServiceConnection() { + @Override + public void onServiceConnected(ComponentName name, IBinder service) { + if (service != null) { + ledService = ILedInterface.Stub.asInterface(service); + } + } + + @Override + public void onServiceDisconnected(ComponentName name) { + + } + }; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + final CheckBox led1 = findViewById(R.id.checkBoxLed1); + final CheckBox led2 = findViewById(R.id.checkBoxLed2); + final CheckBox led3 = findViewById(R.id.checkBoxLed3); + final CheckBox led4 = findViewById(R.id.checkBoxLed4); + final CheckBox btLed = findViewById(R.id.checkBoxBTLed); + final CheckBox wifiLed = findViewById(R.id.checkBoxWifiLed); + final Button btnUpdate = findViewById(R.id.btnUpdate); + final Button btnRefresh = findViewById(R.id.btnRefresh); + + btnUpdate.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + try { + boolean isLed1TurnOn = led1.isChecked(); + boolean isLed2TurnOn = led2.isChecked(); + boolean isLed3TurnOn = led3.isChecked(); + boolean isLed4TurnOn = led4.isChecked(); + boolean isBtLedTurnOn = btLed.isChecked(); + boolean isWifiLedTurnOn = wifiLed.isChecked(); + + ledService.updateState(LedType.USER_LED_1.getName(), isLed1TurnOn); + ledService.updateState(LedType.USER_LED_2.getName(), isLed2TurnOn); + ledService.updateState(LedType.USER_LED_3.getName(), isLed3TurnOn); + ledService.updateState(LedType.USER_LED_4.getName(), isLed4TurnOn); + ledService.updateState(LedType.BT_LED.getName(), isBtLedTurnOn); + ledService.updateState(LedType.WIFI_LED.getName(), isWifiLedTurnOn); + } catch (RemoteException | NullPointerException e) { + Log.e(TAG, e.getMessage()); + } + } + }); + + btnRefresh.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + try { + led1.setChecked(ledService.getLedState(LedType.USER_LED_1.getName())); + led2.setChecked(ledService.getLedState(LedType.USER_LED_2.getName())); + led3.setChecked(ledService.getLedState(LedType.USER_LED_3.getName())); + led4.setChecked(ledService.getLedState(LedType.USER_LED_4.getName())); + btLed.setChecked(ledService.getLedState(LedType.BT_LED.getName())); + wifiLed.setChecked(ledService.getLedState(LedType.WIFI_LED.getName())); + } catch (RemoteException | NullPointerException e) { + Log.e(TAG, e.getMessage()); + } + } + }); + + final Intent intent = new Intent(); + intent.setClassName("com.example.shevchenko.ledcontrol.ledservice", "com.example.shevchenko.ledcontrol.ledservice.LedService"); + try { + bindService(intent, connection, BIND_AUTO_CREATE); + } catch (SecurityException e) { + Log.e(TAG, "bind to service failed by security reason"); + } + } + + @Override + protected void onDestroy() { + super.onDestroy(); + unbindService(connection); + } +} diff --git a/hikey960/packages/apps/LedControlApplication/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/hikey960/packages/apps/LedControlApplication/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/hikey960/packages/apps/LedControlApplication/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/hikey960/packages/apps/LedControlApplication/app/src/main/res/drawable/ic_launcher_background.xml b/hikey960/packages/apps/LedControlApplication/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/hikey960/packages/apps/LedControlApplication/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/hikey960/packages/apps/LedControlApplication/app/src/main/res/layout/activity_main.xml b/hikey960/packages/apps/LedControlApplication/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..78e973d --- /dev/null +++ b/hikey960/packages/apps/LedControlApplication/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,98 @@ + + + + + + + + + + + + + + + +