2015-06-25 04:20:03 +05:30
|
|
|
/*
|
2020-08-17 16:17:20 +02:00
|
|
|
* SPDX-FileCopyrightText: 2015 Vineet Garg <grg.vineet@gmail.com>
|
2015-06-25 04:20:03 +05:30
|
|
|
*
|
2020-08-17 16:17:20 +02:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
2015-06-25 04:20:03 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
package org.kde.kdeconnect.Backends;
|
|
|
|
|
|
|
|
import org.kde.kdeconnect.Device;
|
2018-03-04 11:31:37 +01:00
|
|
|
import org.kde.kdeconnect.NetworkPacket;
|
2015-06-25 04:20:03 +05:30
|
|
|
|
2015-08-13 14:55:00 +05:30
|
|
|
/**
|
|
|
|
* This class separates the pairing interface for each type of link.
|
|
|
|
* Since different links can pair via different methods, like for LanLink certificate and public key should be shared,
|
|
|
|
* for Bluetooth link they should be paired via bluetooth etc.
|
|
|
|
* Each "Device" instance maintains a hash map for these pairing handlers so that there can be single pairing handler per
|
|
|
|
* per link type per device.
|
|
|
|
* Pairing handler keeps information about device, latest link, and pair status of the link
|
|
|
|
* During first pairing process, the pairing process is nearly same as old process.
|
|
|
|
* After that if any one of the link is paired, then we can say that device is paired, so new link will pair automatically
|
|
|
|
*/
|
|
|
|
|
|
|
|
public abstract class BasePairingHandler {
|
|
|
|
|
|
|
|
protected enum PairStatus{
|
|
|
|
NotPaired,
|
|
|
|
Requested,
|
|
|
|
RequestedByPeer,
|
|
|
|
Paired
|
|
|
|
}
|
|
|
|
|
|
|
|
public interface PairingHandlerCallback {
|
|
|
|
void incomingRequest();
|
|
|
|
void pairingDone();
|
|
|
|
void pairingFailed(String error);
|
|
|
|
void unpaired();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-27 00:01:30 +02:00
|
|
|
protected final Device mDevice;
|
2015-08-13 14:55:00 +05:30
|
|
|
protected PairStatus mPairStatus;
|
2018-10-27 00:01:30 +02:00
|
|
|
protected final PairingHandlerCallback mCallback;
|
2015-08-13 14:55:00 +05:30
|
|
|
|
2018-10-26 23:53:58 +02:00
|
|
|
protected BasePairingHandler(Device device, PairingHandlerCallback callback) {
|
2015-08-13 14:55:00 +05:30
|
|
|
this.mDevice = device;
|
|
|
|
this.mCallback = callback;
|
|
|
|
}
|
|
|
|
|
2018-10-26 23:53:58 +02:00
|
|
|
protected boolean isPaired() {
|
2015-08-13 14:55:00 +05:30
|
|
|
return mPairStatus == PairStatus.Paired;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isPairRequested() {
|
|
|
|
return mPairStatus == PairStatus.Requested;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isPairRequestedByPeer() {
|
|
|
|
return mPairStatus == PairStatus.RequestedByPeer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* To be implemented by respective pairing handler */
|
2023-03-17 18:56:52 +01:00
|
|
|
public abstract void packetReceived(NetworkPacket np);
|
2015-08-13 14:55:00 +05:30
|
|
|
public abstract void requestPairing();
|
|
|
|
public abstract void acceptPairing();
|
|
|
|
public abstract void rejectPairing();
|
|
|
|
public abstract void unpair();
|
2015-06-25 04:20:03 +05:30
|
|
|
|
|
|
|
}
|