2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-31 06:05:12 +00:00

Fixed pairing requests not being displayed after clicking the notification

This commit is contained in:
Albert Vaca
2015-09-12 13:21:06 -07:00
parent 6b18c2f28e
commit 24ca5f706a
3 changed files with 112 additions and 88 deletions

View File

@@ -203,11 +203,12 @@ public class Device implements BaseLink.PackageReceiver {
return pairStatus == PairStatus.Requested;
}
public boolean isPairRequestedByOtherEnd() {
return pairStatus == PairStatus.RequestedByPeer;
}
public void addPairingCallback(PairingCallback callback) {
pairingCallback.add(callback);
if (pairStatus == PairStatus.RequestedByPeer) {
callback.incomingRequest();
}
}
public void removePairingCallback(PairingCallback callback) {
pairingCallback.remove(callback);
@@ -245,10 +246,10 @@ public class Device implements BaseLink.PackageReceiver {
//Send our own public key
NetworkPackage np = NetworkPackage.createPublicKeyPackage(context);
sendPackage(np, new SendPackageStatusCallback(){
sendPackage(np, new SendPackageStatusCallback() {
@Override
public void onSuccess() {
if (pairingTimer != null) pairingTimer.cancel();
hidePairingNotification(); //Will stop the pairingTimer if it was running
pairingTimer = new Timer();
pairingTimer.schedule(new TimerTask() {
@Override
@@ -256,10 +257,10 @@ public class Device implements BaseLink.PackageReceiver {
for (PairingCallback cb : pairingCallback) {
cb.pairingFailed(context.getString(R.string.error_timed_out));
}
Log.e("KDE/Device","Unpairing (timeout A)");
Log.e("KDE/Device", "Unpairing (timeout A)");
pairStatus = PairStatus.NotPaired;
}
}, 30*1000); //Time to wait for the other to accept
}, 30 * 1000); //Time to wait for the other to accept
pairStatus = PairStatus.Requested;
}
@@ -268,7 +269,7 @@ public class Device implements BaseLink.PackageReceiver {
for (PairingCallback cb : pairingCallback) {
cb.pairingFailed(context.getString(R.string.error_could_not_send_package));
}
Log.e("KDE/Device","Unpairing (sendFailed A)");
Log.e("KDE/Device", "Unpairing (sendFailed A)");
pairStatus = PairStatus.NotPaired;
}
@@ -276,8 +277,13 @@ public class Device implements BaseLink.PackageReceiver {
}
public int getNotificationId() {
return notificationId;
public void hidePairingNotification() {
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(notificationId);
if (pairingTimer != null) {
pairingTimer.cancel();
}
BackgroundService.removeGuiInUseCounter(context);
}
public void unpair() {
@@ -302,7 +308,7 @@ public class Device implements BaseLink.PackageReceiver {
//Log.e("Device", "Storing as trusted, deviceId: "+deviceId);
if (pairingTimer != null) pairingTimer.cancel();
hidePairingNotification();
pairStatus = PairStatus.Paired;
@@ -448,7 +454,7 @@ public class Device implements BaseLink.PackageReceiver {
if (pairStatus == PairStatus.Requested) {
//Log.e("Device","Unpairing (pair rejected)");
pairStatus = PairStatus.NotPaired;
if (pairingTimer != null) pairingTimer.cancel();
hidePairingNotification();
for (PairingCallback cb : pairingCallback) {
cb.pairingFailed(context.getString(R.string.error_canceled_by_other_peer));
}
@@ -476,7 +482,7 @@ public class Device implements BaseLink.PackageReceiver {
Log.i("KDE/Pairing","Pair answer");
if (pairingTimer != null) pairingTimer.cancel();
hidePairingNotification();
pairingDone();
@@ -490,6 +496,8 @@ public class Device implements BaseLink.PackageReceiver {
Resources res = context.getResources();
hidePairingNotification();
Notification noti = new NotificationCompat.Builder(context)
.setContentTitle(res.getString(R.string.pairing_request_from, getName()))
.setContentText(res.getString(R.string.tap_to_answer))
@@ -504,21 +512,20 @@ public class Device implements BaseLink.PackageReceiver {
final NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationId = (int)System.currentTimeMillis();
try {
BackgroundService.addGuiInUseCounter(context);
notificationManager.notify(notificationId, noti);
} catch(Exception e) {
//4.1 will throw an exception about not having the VIBRATE permission, ignore it.
//https://android.googlesource.com/platform/frameworks/base/+/android-4.2.1_r1.2%5E%5E!/
}
if (pairingTimer != null) pairingTimer.cancel();
pairingTimer = new Timer();
pairingTimer.schedule(new TimerTask() {
@Override
public void run() {
Log.e("KDE/Device","Unpairing (timeout B)");
hidePairingNotification();
pairStatus = PairStatus.NotPaired;
notificationManager.cancel(notificationId);
}
}, 25*1000); //Time to show notification, waiting for user to accept (peer will timeout in 30 seconds)
pairStatus = PairStatus.RequestedByPeer;
@@ -529,7 +536,7 @@ public class Device implements BaseLink.PackageReceiver {
Log.i("KDE/Pairing","Unpair request");
if (pairStatus == PairStatus.Requested) {
pairingTimer.cancel();
hidePairingNotification();
for (PairingCallback cb : pairingCallback) {
cb.pairingFailed(context.getString(R.string.error_canceled_by_other_peer));
}
@@ -805,4 +812,14 @@ public class Device implements BaseLink.PackageReceiver {
link.disconnect();
}
}
public BaseLink.ConnectionStarted getConnectionSource() {
for(BaseLink l : links) {
if (l.getConnectionSource() == BaseLink.ConnectionStarted.Locally) {
return BaseLink.ConnectionStarted.Locally;
}
}
return BaseLink.ConnectionStarted.Remotely;
}
}