ソースを参照

first commit

master
陈福行 4年前
コミット
aa1bcd4760
45個のファイルの変更2017行の追加0行の削除
  1. 14
    0
      .gitignore
  2. 214
    0
      .idea/codeStyles/Project.xml
  3. 5
    0
      .idea/codeStyles/codeStyleConfig.xml
  4. 6
    0
      .idea/compiler.xml
  5. 6
    0
      .idea/dictionaries
  6. 6
    0
      .idea/encodings.xml
  7. 22
    0
      .idea/gradle.xml
  8. 30
    0
      .idea/jarRepositories.xml
  9. 14
    0
      .idea/misc.xml
  10. 12
    0
      .idea/runConfigurations.xml
  11. 1
    0
      app/.gitignore
  12. 40
    0
      app/build.gradle
  13. 21
    0
      app/proguard-rules.pro
  14. 26
    0
      app/src/androidTest/java/com/elinkthings/ailinksecrettooldemo/ExampleInstrumentedTest.java
  15. 26
    0
      app/src/main/AndroidManifest.xml
  16. 330
    0
      app/src/main/java/com/elinkthings/ailinksecrettooldemo/AnalyticalDataUtil.java
  17. 592
    0
      app/src/main/java/com/elinkthings/ailinksecrettooldemo/MainActivity.java
  18. 27
    0
      app/src/main/java/com/elinkthings/ailinksecrettooldemo/OnAnalyticalListener.java
  19. 30
    0
      app/src/main/res/drawable-v24/ic_launcher_foreground.xml
  20. 170
    0
      app/src/main/res/drawable/ic_launcher_background.xml
  21. 59
    0
      app/src/main/res/layout/activity_main.xml
  22. 5
    0
      app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
  23. 5
    0
      app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
  24. バイナリ
      app/src/main/res/mipmap-hdpi/ic_launcher.png
  25. バイナリ
      app/src/main/res/mipmap-hdpi/ic_launcher_round.png
  26. バイナリ
      app/src/main/res/mipmap-mdpi/ic_launcher.png
  27. バイナリ
      app/src/main/res/mipmap-mdpi/ic_launcher_round.png
  28. バイナリ
      app/src/main/res/mipmap-xhdpi/ic_launcher.png
  29. バイナリ
      app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
  30. バイナリ
      app/src/main/res/mipmap-xxhdpi/ic_launcher.png
  31. バイナリ
      app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
  32. バイナリ
      app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
  33. バイナリ
      app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
  34. 6
    0
      app/src/main/res/values-zh/strings.xml
  35. 6
    0
      app/src/main/res/values/colors.xml
  36. 9
    0
      app/src/main/res/values/strings.xml
  37. 10
    0
      app/src/main/res/values/styles.xml
  38. 17
    0
      app/src/test/java/com/elinkthings/ailinksecrettooldemo/ExampleUnitTest.java
  39. 25
    0
      build.gradle
  40. 19
    0
      gradle.properties
  41. バイナリ
      gradle/wrapper/gradle-wrapper.jar
  42. 6
    0
      gradle/wrapper/gradle-wrapper.properties
  43. 172
    0
      gradlew
  44. 84
    0
      gradlew.bat
  45. 2
    0
      settings.gradle

+ 14
- 0
.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

+ 214
- 0
.idea/codeStyles/Project.xml ファイルの表示

@@ -0,0 +1,214 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99" />
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99" />
<option name="PACKAGES_TO_USE_IMPORT_ON_DEMAND">
<value />
</option>
<option name="IMPORT_LAYOUT_TABLE">
<value>
<package name="android" withSubpackages="true" static="false" />
<emptyLine />
<package name="com" withSubpackages="true" static="false" />
<emptyLine />
<package name="junit" withSubpackages="true" static="false" />
<emptyLine />
<package name="net" withSubpackages="true" static="false" />
<emptyLine />
<package name="org" withSubpackages="true" static="false" />
<emptyLine />
<package name="java" withSubpackages="true" static="false" />
<emptyLine />
<package name="javax" withSubpackages="true" static="false" />
<emptyLine />
<package name="" withSubpackages="true" static="false" />
<emptyLine />
<package name="" withSubpackages="true" static="true" />
<emptyLine />
</value>
</option>
<JavaCodeStyleSettings>
<option name="IMPORT_LAYOUT_TABLE">
<value>
<package name="android" withSubpackages="true" static="false" />
<emptyLine />
<package name="com" withSubpackages="true" static="false" />
<emptyLine />
<package name="junit" withSubpackages="true" static="false" />
<emptyLine />
<package name="net" withSubpackages="true" static="false" />
<emptyLine />
<package name="org" withSubpackages="true" static="false" />
<emptyLine />
<package name="java" withSubpackages="true" static="false" />
<emptyLine />
<package name="javax" withSubpackages="true" static="false" />
<emptyLine />
<package name="" withSubpackages="true" static="false" />
<emptyLine />
<package name="" withSubpackages="true" static="true" />
<emptyLine />
</value>
</option>
</JavaCodeStyleSettings>
<XML>
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" />
</XML>
<codeStyleSettings language="XML">
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="4" />
</indentOptions>
<arrangement>
<rules>
<section>
<rule>
<match>
<AND>
<NAME>xmlns:android</NAME>
<XML_NAMESPACE>Namespace:</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>xmlns:.*</NAME>
<XML_NAMESPACE>Namespace:</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:id</NAME>
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:name</NAME>
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>name</NAME>
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>style</NAME>
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:layout_width</NAME>
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:layout_height</NAME>
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:layout_.*</NAME>
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:width</NAME>
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:height</NAME>
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_NAMESPACE>.*</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
</rules>
</arrangement>
</codeStyleSettings>
</code_scheme>
</component>

+ 5
- 0
.idea/codeStyles/codeStyleConfig.xml ファイルの表示

@@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default (1)" />
</state>
</component>

+ 6
- 0
.idea/compiler.xml ファイルの表示

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="9" />
</component>
</project>

+ 6
- 0
.idea/dictionaries ファイルの表示

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectDictionaryState">
<dictionary name="xing" />
</component>
</project>

+ 6
- 0
.idea/encodings.xml ファイルの表示

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" defaultCharsetForPropertiesFiles="UTF-8" addBOMForNewFiles="with NO BOM">
<file url="PROJECT" charset="UTF-8" />
</component>
</project>

+ 22
- 0
.idea/gradle.xml ファイルの表示

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="testRunner" value="PLATFORM" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="$APPLICATION_HOME_DIR$/gradle/gradle-5.1.1" />
<option name="gradleJvm" value="1.8 (2)" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
</GradleProjectSettings>
</option>
</component>
</project>

+ 30
- 0
.idea/jarRepositories.xml ファイルの表示

@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="BintrayJCenter" />
<option name="name" value="BintrayJCenter" />
<option name="url" value="https://jcenter.bintray.com/" />
</remote-repository>
<remote-repository>
<option name="id" value="Google" />
<option name="name" value="Google" />
<option name="url" value="https://dl.google.com/dl/android/maven2/" />
</remote-repository>
<remote-repository>
<option name="id" value="maven" />
<option name="name" value="maven" />
<option name="url" value="https://jitpack.io" />
</remote-repository>
</component>
</project>

+ 14
- 0
.idea/misc.xml ファイルの表示

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakeSettings">
<configurations>
<configuration PROFILE_NAME="Debug" CONFIG_NAME="Debug" />
</configurations>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>

+ 12
- 0
.idea/runConfigurations.xml ファイルの表示

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
</set>
</option>
</component>
</project>

+ 1
- 0
app/.gitignore ファイルの表示

@@ -0,0 +1 @@
/build

+ 40
- 0
app/build.gradle ファイルの表示

@@ -0,0 +1,40 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 30
buildToolsVersion "30.0.2"

defaultConfig {
applicationId "com.elinkthings.ailinksecrettooldemo"
minSdkVersion 19
targetSdkVersion 30
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
}

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

implementation 'com.github.elinkthings:AILinkSecretAndroid:1.0.0'
}

+ 21
- 0
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

+ 26
- 0
app/src/androidTest/java/com/elinkthings/ailinksecrettooldemo/ExampleInstrumentedTest.java ファイルの表示

@@ -0,0 +1,26 @@
package com.elinkthings.ailinksecrettooldemo;

import android.content.Context;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.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 <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.elinkthings.ailinksecrettooldemo", appContext.getPackageName());
}
}

+ 26
- 0
app/src/main/AndroidManifest.xml ファイルの表示

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

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<!--兼容6.0以上的手机Ble-->
<uses-permission-sdk-23 android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission-sdk-23 android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>

+ 330
- 0
app/src/main/java/com/elinkthings/ailinksecrettooldemo/AnalyticalDataUtil.java ファイルの表示

@@ -0,0 +1,330 @@
package com.elinkthings.ailinksecrettooldemo;

import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor;
import android.bluetooth.BluetoothGattService;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.SystemClock;
import android.util.Log;

import com.elinkthings.ailinksecretlib.AiLinkBleCheckUtil;
import com.elinkthings.ailinksecretlib.BleConfig;
import com.elinkthings.ailinksecretlib.CmdConfig;
import com.elinkthings.ailinksecretlib.MyBleDeviceUtils;

import java.util.Arrays;
import java.util.UUID;

import androidx.annotation.NonNull;

/**
* xing<br>
* 2021/4/9<br>
* 解析数据类
*/
public class AnalyticalDataUtil {

/**
* 握手指令
*/
private final static int HANDSHAKE_FAILURE = 1;
private BluetoothGatt mBluetoothGatt;
/**
* 当前是否为握手状态
*/
private boolean mHandshakeStatus = true;
private String mMac;
private OnAnalyticalListener mOnAnalyticalListener;
private Handler mHandler = new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(@NonNull Message msg) {
switch (msg.what) {

case HANDSHAKE_FAILURE:
//握手失败,握手超时
if (mOnAnalyticalListener != null) {
mOnAnalyticalListener.onHandshake(mMac, false);
}
break;

}
}
};

public AnalyticalDataUtil(BluetoothGatt gatt, OnAnalyticalListener listener) {
mOnAnalyticalListener = listener;
mBluetoothGatt = gatt;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mBluetoothGatt.requestConnectionPriority(BluetoothGatt.CONNECTION_PRIORITY_HIGH);
}
mMac = gatt.getDevice().getAddress();
openAILinkNotify(gatt);

}


/**
* 通知返回数据
*/
public final void notifyData(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
byte[] hex = characteristic.getValue();
if (hex == null) {
return;
}
UUID uuid = characteristic.getUuid();
getAnalyticalData(gatt, uuid, hex);
}


private void getAnalyticalData(BluetoothGatt gatt, UUID uuid, byte[] hex) {
final String mac = gatt.getDevice().getAddress();
if (AiLinkBleCheckUtil.checkReturnDataFormat(hex)) {
//数据合法
if (mHandshakeStatus) {
//当前为握手状态
if (hex[0] == CmdConfig.SEND_BLE_START && hex[2] == CmdConfig.GET_HANDSHAKE) {
boolean isData = getHandshakeStatus(hex);
if (isData) {
//握手成功
mHandler.removeMessages(HANDSHAKE_FAILURE);
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
mHandshakeStatus = false;
if (mOnAnalyticalListener != null) {
mOnAnalyticalListener.onHandshake(mac, true);
}
}
}, 500);//需要延迟500,确保芯片第二次验证通过
} else {
if (mOnAnalyticalListener != null) {
mOnAnalyticalListener.onHandshake(mac, false);
}
}
mDataHandshake = null;
} else {
//不是握手状态
if (hex[0] == CmdConfig.SEND_BLE_START && hex[2] == CmdConfig.SET_HANDSHAKE) {
//是握手数据
byte[] bleDataHandshake = AiLinkBleCheckUtil.returnHandshakeDataFormat(hex);
sendHandshakePwd( bleDataHandshake);
} else {
protocolNotifyData(mac, uuid, hex);
}
}
} else {
//不是握手状态
if (hex[0] == CmdConfig.SEND_BLE_START && hex[2] == CmdConfig.SET_HANDSHAKE) {
//是握手数据
byte[] bleDataHandshake = AiLinkBleCheckUtil.returnHandshakeDataFormat(hex);
sendHandshakePwd( bleDataHandshake);
} else {
protocolNotifyData(mac, uuid, hex);
}

}
} else {
protocolNotifyData(mac, uuid, hex);
}
}


/**
* 符合数据格式的协议notify数据处理
*/
private void protocolNotifyData(String mac, UUID uuid, byte[] hex) {
if (hex == null) {
return;
}
byte[] payload;
if (hex.length > 0) {
switch (hex[0]) {
case CmdConfig.SEND_BLE_START:
payload = AiLinkBleCheckUtil.returnBleDataFormat(hex);
if (payload != null && payload.length >= 1) {
if (mOnAnalyticalListener != null) {
mOnAnalyticalListener.onAnalyticalData(mac, uuid, payload);
}
}
break;

case CmdConfig.SEND_MCU_START:
payload = AiLinkBleCheckUtil.returnMcuDataFormat(hex);
if (payload != null && payload.length >= 1) {
byte[] CID = new byte[]{hex[1], hex[2]};
byte[] data;
data = AiLinkBleCheckUtil.mcuEncrypt(CID, payload, mac);
if (data.length > 0) {
if (mOnAnalyticalListener != null) {
mOnAnalyticalListener.onAnalyticalData(mac, uuid, data);
}
}
}
break;
default:
if (mOnAnalyticalListener != null) {
mOnAnalyticalListener.onAnalyticalData(mac, uuid, hex);
}
break;
}
}
}


/**
* 设置通知AILink
*/
private void openAILinkNotify(BluetoothGatt gatt) {
setNotify(gatt, BleConfig.UUID_WRITE_NOTIFY_AILINK, BleConfig.UUID_NOTIFY_AILINK);
}

/**
* 开启多个Notify,如果多个服务,可重复调用
*
* @param gatt BluetoothGatt
* @param uuidNotify uuidNotify
*/
public void setNotify(BluetoothGatt gatt, UUID... uuidNotify) {
for (UUID uuid : uuidNotify) {
setOpenNotify(gatt, uuid);
}
}

/**
* 设置通知
*
* @param gatt BluetoothGatt
* @param uuidNotify uuidNotify
*/
private void setOpenNotify(BluetoothGatt gatt, UUID uuidNotify) {
BluetoothGattService mGattService = MyBleDeviceUtils.getService(gatt, BleConfig.UUID_SERVER_AILINK);
if (mGattService != null) {
BluetoothGattCharacteristic mCharacteristic = MyBleDeviceUtils.getServiceWrite(mGattService, uuidNotify);
if (mCharacteristic != null) {
mCharacteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT);//部分手机Notify需要设置这个后才会生效
gatt.setCharacteristicNotification(mCharacteristic, true);
BluetoothGattDescriptor bluetoothGattDescriptor = mCharacteristic.getDescriptor(BleConfig.UUID_NOTIFY_DESCRIPTOR);
if (bluetoothGattDescriptor != null) {
bluetoothGattDescriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
boolean sendOk = gatt.writeDescriptor(bluetoothGattDescriptor);
if (!sendOk) {
SystemClock.sleep(50);
sendOk = gatt.writeDescriptor(bluetoothGattDescriptor);
}
}
if (uuidNotify.toString().equals(BleConfig.UUID_WRITE_NOTIFY_AILINK.toString())) {
//AILink notify success
sendHandshake(gatt);
}
}
}

}


//---------------------握手指令发送校验 start--------------
private volatile byte[] mDataHandshake;

/**
* 明文握手
*/
public void sendHandshake(final BluetoothGatt gatt) {
if (mHandshakeStatus) {
sendCmd(initHandshakeArr());
mHandshakeStatus = true;
mHandler.removeMessages(HANDSHAKE_FAILURE);
mHandler.sendEmptyMessageDelayed(HANDSHAKE_FAILURE, 5000);

} else {
if (mOnAnalyticalListener != null) {
mOnAnalyticalListener.onHandshake(gatt.getDevice().getAddress(), true);
}
}
}

/**
* 密文握手
*/
public void sendHandshakePwd( byte[] hex) {
byte[] bytes = initHandshakeArrPwd(hex);
if (bytes != null) {
sendCmd(bytes);
}
}

private synchronized void sendCmd(final byte[] bytes) {
if (bytes != null) {

mHandler.post(new Runnable() {
@Override
public void run() {
SystemClock.sleep(100);
BluetoothGattService mGattService = MyBleDeviceUtils.getService(mBluetoothGatt, BleConfig.UUID_SERVER_AILINK);
if (mGattService != null) {
BluetoothGattCharacteristic mCharacteristic = MyBleDeviceUtils.getServiceWrite(mGattService, BleConfig.UUID_WRITE_NOTIFY_AILINK);
if (mCharacteristic != null) {
mCharacteristic.setValue(bytes);
mCharacteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE);
boolean b = mBluetoothGatt.writeCharacteristic(mCharacteristic);
Log.i("AnalyticalDataUtil","send:"+b);
}
}
}
});
}
}


/**
* @return APP握手指令
*/
private byte[] initHandshakeArr() {
mDataHandshake = AiLinkBleCheckUtil.getRandomKey(16);
return AiLinkBleCheckUtil.sendHandshakeFormat(mDataHandshake, CmdConfig.SET_HANDSHAKE);
}

/**
* @param hex 明文数据
* @return APP握手指令密文
*/
private byte[] initHandshakeArrPwd(byte[] hex) {
//加密数据
byte[] appDataHandshake = AiLinkBleCheckUtil.bleEncrypt(hex);
if (appDataHandshake != null) {
return AiLinkBleCheckUtil.sendHandshakeFormat(appDataHandshake, CmdConfig.GET_HANDSHAKE);
} else {
return null;
}
}

/**
* 校验握手数据是否正确
*/
private boolean getHandshakeStatus(byte[] data) {
if (mDataHandshake == null) {
return false;
}
//得到加密后的Payload
byte[] bleDataHandshake = AiLinkBleCheckUtil.returnHandshakeDataFormat(data);
//加密自己发送的数据
byte[] appDataHandshake = AiLinkBleCheckUtil.bleEncrypt(mDataHandshake);//加密后会改变传入的byte数据,如需要保留请先copy
//校验两次加密是否一致
return Arrays.equals(appDataHandshake, bleDataHandshake);
}


//---------------------握手指令发送校验 end-------------

public void close() {
if (mBluetoothGatt != null) {
mBluetoothGatt.disconnect();
mBluetoothGatt.close();
mBluetoothGatt = null;
}
}

}

+ 592
- 0
app/src/main/java/com/elinkthings/ailinksecrettooldemo/MainActivity.java ファイルの表示

@@ -0,0 +1,592 @@
package com.elinkthings.ailinksecrettooldemo;

import android.Manifest;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCallback;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor;
import android.bluetooth.BluetoothGattService;
import android.bluetooth.BluetoothManager;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.le.ScanCallback;
import android.bluetooth.le.ScanFilter;
import android.bluetooth.le.ScanResult;
import android.bluetooth.le.ScanSettings;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.LocationManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.ParcelUuid;
import android.provider.Settings;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;

import com.elinkthings.ailinksecretlib.BleConfig;
import com.elinkthings.ailinksecretlib.MyBleDeviceUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.annotation.RequiresPermission;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;

public class MainActivity extends AppCompatActivity implements View.OnClickListener, OnAnalyticalListener {


/**
* 停止搜索
*/
private final static int STOP_SEARCH = 2;
private final static int REFRESH_DATA = 3;
private final static int REFRESH_BLE_DATA = 4;


private Button btn_search, btn_stop, btn_clear;
private ListView listview1, listview2;

/**
* 蓝牙控制对象
*/
private BluetoothManager mBleManager;
private BluetoothAdapter mBluetoothAdapter;
private Context mContext;
private List<String> mList1 = new ArrayList<>();
private ArrayAdapter listAdapter1;
private List<String> mList2 = new ArrayList<>();
private ArrayAdapter listAdapter2;

private Handler mHandler = new Handler(Looper.getMainLooper()) {

@Override
public void handleMessage(@NonNull Message msg) {

switch (msg.what) {

case STOP_SEARCH:
stopScan();
break;

case REFRESH_DATA:
if (listAdapter2 != null) {
listAdapter2.notifyDataSetChanged();
}
break;

case REFRESH_BLE_DATA:
if (listAdapter1 != null) {
listAdapter1.notifyDataSetChanged();
}
break;

}

}
};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mContext = this;
init();

}

private void init() {
initView();
initData();
initBle();
initListener();


}

private void initData() {
listAdapter1 = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mList1);
listview1.setAdapter(listAdapter1);

listAdapter2 = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mList2);
listview2.setAdapter(listAdapter2);

}

@Override
public void onClick(View v) {

switch (v.getId()) {

case R.id.btn_search:
checkPermission();
break;
case R.id.btn_stop:
stopScan();
break;
case R.id.btn_clear:
mList2.clear();
mHandler.sendEmptyMessage(REFRESH_DATA);
break;


}


}

/**
* (16进制)
* BLE蓝牙返回的byte[]
* byte[]转字符串
*/
public String byte2HexStr(byte[] b) {
String hs = "";
if (b == null) {
return hs;
}
String stmp;
for (byte aB : b) {
int a = aB & 0XFF;
stmp = Integer.toHexString(a);
if (stmp.length() == 1)
hs = hs + "0" + stmp + " ";
else
hs = hs + stmp + " ";
}
return hs;
}

@Override
public void onAnalyticalData(String mac, UUID uuid, byte[] data) {
mList2.add("收到的数据:\nmac=" + mac + "\ndata=" + byte2HexStr(data));
mHandler.sendEmptyMessage(REFRESH_DATA);
}

@Override
public void onHandshake(String mac, boolean result) {

if (result) {
mList2.add("握手成功:mac=" + mac);
} else {
mList2.add("握手失败:mac=" + mac);
}
mHandler.sendEmptyMessage(REFRESH_DATA);
}

private void initListener() {
btn_search.setOnClickListener(this);
btn_stop.setOnClickListener(this);
btn_clear.setOnClickListener(this);
listview1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
stopScan();
if (mList1.size() > position) {
if (mAnalyticalDataUtil != null) {
mAnalyticalDataUtil.close();
}
String mac = mList1.get(position);
connectBleDevice(mac);
mList2.add("正在连接:mac=" + mac);
mHandler.sendEmptyMessage(REFRESH_DATA);
}

}
});

}

private void initView() {
btn_search = findViewById(R.id.btn_search);
btn_stop = findViewById(R.id.btn_stop);
btn_clear = findViewById(R.id.btn_clear);
listview1 = findViewById(R.id.listview1);
listview2 = findViewById(R.id.listview2);

}

private void initBle() {
if (mBleManager == null)
mBleManager = (BluetoothManager) this.getSystemService(Context.BLUETOOTH_SERVICE);
if (mBluetoothAdapter == null && mBleManager != null) {
mBluetoothAdapter = mBleManager.getAdapter();
}

}


/**
* 开始搜索
*/
private void startScan() {
mList1.clear();
mHandler.sendEmptyMessage(REFRESH_BLE_DATA);
scanLeDevice(BleConfig.UUID_SERVER_AILINK);
mHandler.sendEmptyMessageDelayed(STOP_SEARCH, 10 * 1000);
}

/**
* 搜索设备
* 扫描过于频繁会导致扫描失败
* 需要保证5次扫描总时长超过30s
*
* @param scanUUID 过滤的UUID(空/null代码不过滤)
*/
@RequiresPermission(allOf = {Manifest.permission.BLUETOOTH_ADMIN, Manifest.permission.BLUETOOTH})
public void scanLeDevice(UUID... scanUUID) {
if (!mBluetoothAdapter.isEnabled()) {
//蓝牙未开启
return;
}


try {
//扫描过于频繁会导致扫描失败
//需要保证5次扫描总时长超过30s
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
List<ScanFilter> filters = new ArrayList<>();
if (scanUUID != null && scanUUID.length > 0) {
for (UUID uuid : scanUUID) {
ScanFilter filter = new ScanFilter.Builder().setServiceUuid(new ParcelUuid(uuid)).build();
filters.add(filter);
}
}
if (mScanCallback == null)
mScanCallback = new MyScanCallback();
ScanSettings settings = new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build();
mBluetoothAdapter.getBluetoothLeScanner().startScan(filters, settings, mScanCallback);
} else {
mBluetoothAdapter.startLeScan(mLeScanCallback);
}

} catch (Exception e) {
e.printStackTrace();
}

}


/**
* 取消扫描
*/
public void stopScan() {
try {
if (mBluetoothAdapter != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (mBluetoothAdapter.getBluetoothLeScanner() != null) {
mBluetoothAdapter.getBluetoothLeScanner().stopScan(mScanCallback);
}

} else {
mBluetoothAdapter.stopLeScan(mLeScanCallback);
}

}
} catch (Exception e) {
e.printStackTrace();
}
}


/**
* 搜索结果的回调
*/
private BluetoothAdapter.LeScanCallback mLeScanCallback = new BluetoothAdapter.LeScanCallback() {
@Override
public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) {
if (device == null || scanRecord == null)
return;
String address = device.getAddress();
saveScanData(address);
}
};

private MyScanCallback mScanCallback;


/**
* 搜索结果的回调 5.0以上
*/
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private class MyScanCallback extends ScanCallback {

@Override
public void onScanResult(int callbackType, ScanResult result) {
super.onScanResult(callbackType, result);
String address = result.getDevice().getAddress();
saveScanData(address);

}

@Override
public void onBatchScanResults(List<ScanResult> results) {
super.onBatchScanResults(results);

}

@Override
public void onScanFailed(int errorCode) {
super.onScanFailed(errorCode);
//扫描失败

}
}

/**
* 搜索到的数据到列表
*/
private void saveScanData(String mac) {
if (!mList1.contains(mac)) {
mList1.add(mac);
mHandler.sendEmptyMessage(REFRESH_BLE_DATA);
}
}


/**
* 连接蓝牙设备
*
* @param mac 连接的设备地址
*/
private synchronized void connectBleDevice(String mac) {
if (!mBluetoothAdapter.isEnabled()) {
//蓝牙未开启
return;
}


BluetoothDevice device;
try {
device = mBluetoothAdapter.getRemoteDevice(mac);
if (device == null) {
//找不到需要连接的设备
return;
}
} catch (IllegalArgumentException e) {
//连接的设备地址无效
e.printStackTrace();
return;
}

device.connectGatt(mContext, false, mGattCallback);//连接操作

}


//------------------------------------------------------------------------------------------


/**
* 连接ble的回调操作类
*/
private MyBluetoothGattCallback mGattCallback = new MyBluetoothGattCallback();
;
private BluetoothGatt gattOld;
private AnalyticalDataUtil mAnalyticalDataUtil;

/**
* 连接ble的操作回调类
*/
private class MyBluetoothGattCallback extends BluetoothGattCallback {
@Override
public void onConnectionStateChange(final BluetoothGatt gatt, int status, int newState) {
try {
if (status == BluetoothGatt.GATT_SUCCESS) {
if (newState == BluetoothProfile.STATE_CONNECTED && gattOld != gatt) {
gatt.discoverServices();
mList2.add("连接成功:mac=" + gatt.getDevice().getAddress());
mHandler.sendEmptyMessage(REFRESH_DATA);
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
//避免系统多次回调断开连接的消息
mList2.add("连接断开:mac=" + gatt.getDevice().getAddress());
mHandler.sendEmptyMessage(REFRESH_DATA);
gatt.connect();
}
} else {
mList2.add("连接断开:mac=" + gatt.getDevice().getAddress() + " || " + status);
mHandler.sendEmptyMessage(REFRESH_DATA);
gatt.disconnect();
MyBleDeviceUtils.refreshDeviceCache(gatt);
}
} catch (NullPointerException e) {
e.printStackTrace();
}

}

@Override
public void onServicesDiscovered(final BluetoothGatt gatt, int status) {
if (status == BluetoothGatt.GATT_SUCCESS) {
gattOld = null;
//发现新服务
List<BluetoothGattService> mServices = gatt.getServices();

if (mServices.size() > 0) {
mList2.add("获取服务成功:mac=" + gatt.getDevice().getAddress());
mHandler.sendEmptyMessage(REFRESH_DATA);
//获取的服务列表不为空
mAnalyticalDataUtil = new AnalyticalDataUtil(gatt, MainActivity.this);
} else {
//连接失败:服务读取失败
mList2.add("获取服务失败:mac=" + gatt.getDevice().getAddress());
mHandler.sendEmptyMessage(REFRESH_DATA);
gatt.disconnect();
gatt.close();
MyBleDeviceUtils.refreshDeviceCache(gatt);
}

} else {
//服务读取失败
mList2.add("获取服务失败:mac=" + gatt.getDevice().getAddress());
mHandler.sendEmptyMessage(REFRESH_DATA);
}
}


@Override
public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {

}


@Override
public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {

}

@Override
public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
super.onDescriptorRead(gatt, descriptor, status);
}

@Override
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
super.onDescriptorWrite(gatt, descriptor, status);
}

@Override
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
//通知返回的数据
if (mAnalyticalDataUtil != null) {
mAnalyticalDataUtil.notifyData(gatt, characteristic);
}
}


@Override
public void onReliableWriteCompleted(BluetoothGatt gatt, int status) {
super.onReliableWriteCompleted(gatt, status);
}

@Override
public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) {
//回调信号强度

}


@Override
public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) {
super.onMtuChanged(gatt, mtu, status);
//TODO Mtu改变(一般用不上,可改变传送效率,兼容性待验)

}


}


// ------------------- 权限 ------------------

/**
* 检查权限
*/
private void checkPermission() {
// 没有蓝牙权限就请求蓝牙权限
if (!hasBluetooth()) {
requestBluetooth();
return;
}
// 没有定位权限就请求定位权限
if (!hasLocationPermission()) {
requestLocationPermission(this);
return;
}
// 没有定位服务就请求定位服务
if (!hasLocationService()) {
requestLocationService();
return;
}
// 都有了,OK
startScan();
}

/**
* 是否有定位权限
*
* @return boolean
*/
private boolean hasLocationPermission() {
return ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED;
}

/**
* 蓝牙是否打开
*
* @return boolean
*/
private boolean hasBluetooth() {
return BluetoothAdapter.getDefaultAdapter().isEnabled();
}

/**
* 定位服务是否打开
*
* @return boolean
*/
private boolean hasLocationService() {
LocationManager locationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
if (locationManager == null) {
return false;
}
return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) || locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
}

/**
* 申请定位权限
*/
private void requestLocationPermission(Activity activity) {
ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1);
}

/**
* 申请打开蓝牙
*/
private void requestBluetooth() {
Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(intent, 1);
}

/**
* 申请打开定位服务
*/
private void requestLocationService() {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivityForResult(intent, 2);
}


}

+ 27
- 0
app/src/main/java/com/elinkthings/ailinksecrettooldemo/OnAnalyticalListener.java ファイルの表示

@@ -0,0 +1,27 @@
package com.elinkthings.ailinksecrettooldemo;

import java.util.UUID;

/**
* xing<br>
* 2021/4/15<br>
* 解析数据接口
*/
public interface OnAnalyticalListener {

/**
* 解析后的透传数据,用于APP后续处理的
* @param mac mac
* @param uuid uuid
* @param data 数据
*/
void onAnalyticalData(String mac, UUID uuid, byte[] data);

/**
* 握手结果,在握手成功后才可以发送数据,否则可能会导致芯片丢弃发送的数据
* @param mac mac
* @param result 结果
*/
void onHandshake(String mac, boolean result);

}

+ 30
- 0
app/src/main/res/drawable-v24/ic_launcher_foreground.xml ファイルの表示

@@ -0,0 +1,30 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
<aapt:attr name="android:fillColor">
<gradient
android:endX="85.84757"
android:endY="92.4963"
android:startX="42.9492"
android:startY="49.59793"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
</vector>

+ 170
- 0
app/src/main/res/drawable/ic_launcher_background.xml ファイルの表示

@@ -0,0 +1,170 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillColor="#3DDC84"
android:pathData="M0,0h108v108h-108z" />
<path
android:fillColor="#00000000"
android:pathData="M9,0L9,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,0L19,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,0L29,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,0L39,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,0L49,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,0L59,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,0L69,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,0L79,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M89,0L89,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M99,0L99,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,9L108,9"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,19L108,19"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,29L108,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,39L108,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,49L108,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,59L108,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,69L108,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,79L108,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,89L108,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,99L108,99"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,29L89,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,39L89,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,49L89,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,59L89,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,69L89,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,79L89,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,19L29,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,19L39,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,19L49,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,19L59,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,19L69,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,19L79,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
</vector>

+ 59
- 0
app/src/main/res/layout/activity_main.xml ファイルの表示

@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<LinearLayout
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
android:padding="10dp">

<Button
android:id="@+id/btn_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/search" />

<Button
android:id="@+id/btn_stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/stop" />

<Button
android:id="@+id/btn_clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/clear"
/>


</LinearLayout>


<ListView
android:id="@+id/listview1"
android:layout_width="match_parent"
android:layout_height="300dp"
app:layout_constraintTop_toBottomOf="@id/layout"
android:padding="10dp">

</ListView>
<ListView
android:id="@+id/listview2"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/listview1"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll"
android:padding="10dp">

</ListView>

</androidx.constraintlayout.widget.ConstraintLayout>

+ 5
- 0
app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml ファイルの表示

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>

+ 5
- 0
app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml ファイルの表示

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>

バイナリ
app/src/main/res/mipmap-hdpi/ic_launcher.png ファイルの表示


バイナリ
app/src/main/res/mipmap-hdpi/ic_launcher_round.png ファイルの表示


バイナリ
app/src/main/res/mipmap-mdpi/ic_launcher.png ファイルの表示


バイナリ
app/src/main/res/mipmap-mdpi/ic_launcher_round.png ファイルの表示


バイナリ
app/src/main/res/mipmap-xhdpi/ic_launcher.png ファイルの表示


バイナリ
app/src/main/res/mipmap-xhdpi/ic_launcher_round.png ファイルの表示


バイナリ
app/src/main/res/mipmap-xxhdpi/ic_launcher.png ファイルの表示


バイナリ
app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png ファイルの表示


バイナリ
app/src/main/res/mipmap-xxxhdpi/ic_launcher.png ファイルの表示


バイナリ
app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png ファイルの表示


+ 6
- 0
app/src/main/res/values-zh/strings.xml ファイルの表示

@@ -0,0 +1,6 @@
<resources>
<string name="app_name">AILinkEncryptionSdk</string>
<string name="clear">清空</string>
<string name="search">搜索</string>
<string name="stop">停止</string>
</resources>

+ 6
- 0
app/src/main/res/values/colors.xml ファイルの表示

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#6200EE</color>
<color name="colorPrimaryDark">#3700B3</color>
<color name="colorAccent">#03DAC5</color>
</resources>

+ 9
- 0
app/src/main/res/values/strings.xml ファイルの表示

@@ -0,0 +1,9 @@
<resources>
<string name="app_name">AILinkEncryptionSdk</string>


<string name="search">search</string>
<string name="stop">stop</string>
<string name="clear">clear</string>

</resources>

+ 10
- 0
app/src/main/res/values/styles.xml ファイルの表示

@@ -0,0 +1,10 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

</resources>

+ 17
- 0
app/src/test/java/com/elinkthings/ailinksecrettooldemo/ExampleUnitTest.java ファイルの表示

@@ -0,0 +1,17 @@
package com.elinkthings.ailinksecrettooldemo;

import org.junit.Test;

import static org.junit.Assert.*;

/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}

+ 25
- 0
build.gradle ファイルの表示

@@ -0,0 +1,25 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.1"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

+ 19
- 0
gradle.properties ファイルの表示

@@ -0,0 +1,19 @@
# 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
# 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
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true

バイナリ
gradle/wrapper/gradle-wrapper.jar ファイルの表示


+ 6
- 0
gradle/wrapper/gradle-wrapper.properties ファイルの表示

@@ -0,0 +1,6 @@
#Thu Apr 22 19:01:02 CST 2021
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip

+ 172
- 0
gradlew ファイルの表示

@@ -0,0 +1,172 @@
#!/usr/bin/env sh

##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################

# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null

APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

warn () {
echo "$*"
}

die () {
echo
echo "$*"
echo
exit 1
}

# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar

# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi

# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi

# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi

# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option

if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi

# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")

# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "$@"

+ 84
- 0
gradlew.bat ファイルの表示

@@ -0,0 +1,84 @@
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################

@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto init

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:init
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args

:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2

:win9xME_args_slurp
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1

:mainEnd
if "%OS%"=="Windows_NT" endlocal

:omega

+ 2
- 0
settings.gradle ファイルの表示

@@ -0,0 +1,2 @@
include ':app'
rootProject.name = "AILinkSecretToolDemo"

読み込み中…
キャンセル
保存