Added experimental AirPods Pro detection code

This commit is contained in:
dosse91
2019-12-21 10:05:09 +01:00
parent 9450983100
commit 85f25ce813
9 changed files with 17 additions and 8 deletions
+2 -2
View File
@@ -6,8 +6,8 @@ android {
applicationId "com.dosse.airpods"
minSdkVersion 23
targetSdkVersion 23
versionCode 12
versionName '1.2'
versionCode 13
versionName '1.3'
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
@@ -46,7 +46,8 @@ public class PodsService extends Service {
private static BluetoothLeScanner btScanner;
private static int leftStatus=15, rightStatus=15, caseStatus=15;
private static boolean chargeL=false, chargeR=false, chargeCase=false;
private static boolean chargeL=false, chargeR=false, chargeCase=false,
pro=false; //todo: replace boolean switch for support of multiple models
/**
* The following method (startAirPodsScanner) creates a bluetoth LE scanner.
@@ -70,6 +71,7 @@ public class PodsService extends Service {
* - The 12th and 13th characters in the string represent the charge of the left and right pods. Under unknown circumstances, they are right and left instead (see isFlipped). Values between 0 and 10 are battery 0-100%; Value 15 means it's disconnected
* - The 15th character in the string represents the charge of the case. Values between 0 and 10 are battery 0-100%; Value 15 means it's disconnected
* - The 14th character in the string represents the "in charge" status. Bit 0 (LSB) is the left pod; Bit 1 is the right pod; Bit 2 is the case. Bit 3 might be case open/closed but I'm not sure and it's not used
* - The 7th character in the string represents the AirPods model (E=AirPods pro)
*
* After decoding a beacon, the status is written to leftStatus, rightStatus, caseStatus, chargeL, chargeR, chargeCase so that the NotificationThread can use the information
*
@@ -151,6 +153,7 @@ public class PodsService extends Service {
chargeL = (chargeStatus & 0b00000001) != 0;
chargeR = (chargeStatus & 0b00000010) != 0;
chargeCase = (chargeStatus & 0b00000100) != 0;
pro = a.charAt(7)=='E'; //detect if these are AirPods pro or regular ones
lastSeenConnected = System.currentTimeMillis();
} catch (Throwable t) {
if(ENABLE_LOGGING) Log.d(TAG, "" + t);
@@ -276,10 +279,16 @@ public class PodsService extends Service {
mBuilder.setCustomBigContentView(locationDisabledBig);
}
if(notificationShowing){
if(ENABLE_LOGGING) Log.d(TAG,"Left: "+leftStatus+(chargeL?"+":"")+" "+"Right: "+rightStatus+(chargeR?"+":"")+" "+"Case: "+caseStatus+(chargeCase?"+":""));
notificationBig.setImageViewResource(R.id.leftPodImg,leftStatus<=10?R.drawable.left_pod:R.drawable.left_pod_disconnected);
notificationBig.setImageViewResource(R.id.rightPodImg,rightStatus<=10?R.drawable.right_pod:R.drawable.right_pod_disconnected);
notificationBig.setImageViewResource(R.id.podCaseImg,caseStatus<=10?R.drawable.pod_case:R.drawable.pod_case_disconnected);
if(ENABLE_LOGGING) Log.d(TAG,"Left: "+leftStatus+(chargeL?"+":"")+" "+"Right: "+rightStatus+(chargeR?"+":"")+" "+"Case: "+caseStatus+(chargeCase?"+":"")+" "+"Pro: "+pro);
if(pro){
notificationBig.setImageViewResource(R.id.leftPodImg, leftStatus <= 10 ? R.drawable.left_podpro : R.drawable.left_podpro_disconnected);
notificationBig.setImageViewResource(R.id.rightPodImg, rightStatus <= 10 ? R.drawable.right_podpro : R.drawable.right_podpro_disconnected);
notificationBig.setImageViewResource(R.id.podCaseImg, caseStatus <= 10 ? R.drawable.podpro_case : R.drawable.podpro_case_disconnected);
}else {
notificationBig.setImageViewResource(R.id.leftPodImg, leftStatus <= 10 ? R.drawable.left_pod : R.drawable.left_pod_disconnected);
notificationBig.setImageViewResource(R.id.rightPodImg, rightStatus <= 10 ? R.drawable.right_pod : R.drawable.right_pod_disconnected);
notificationBig.setImageViewResource(R.id.podCaseImg, caseStatus <= 10 ? R.drawable.pod_case : R.drawable.pod_case_disconnected);
}
if(System.currentTimeMillis()-lastSeenConnected<TIMEOUT_CONNECTED) {
notificationBig.setViewVisibility(R.id.leftPodText, View.VISIBLE);
notificationBig.setViewVisibility(R.id.rightPodText, View.VISIBLE);
Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

+1 -1
View File
@@ -7,7 +7,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
classpath 'com.android.tools.build:gradle:3.5.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files