Add tethering client callbacks
The callbacks are fired when the list of connected clients or their IP addresses / hostname change. Test: flashed, connected 2 devices, verified callbacks Test: atest TetheringTests Bug: 135411507 Change-Id: I96291038cf7b39a67547a5f74fcd7cbedc1ca002
This commit is contained in:
committed by
markchien
parent
5cce783b41
commit
c8871c1b66
@@ -1,16 +1,16 @@
|
||||
/**
|
||||
* Copyright (c) 2019, The Android Open Source Project
|
||||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing perNmissions and
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package android.net;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package android.net;
|
||||
|
||||
import android.net.Network;
|
||||
import android.net.TetheredClient;
|
||||
import android.net.TetheringConfigurationParcel;
|
||||
import android.net.TetheringCallbackStartedParcel;
|
||||
import android.net.TetherStatesParcel;
|
||||
@@ -33,4 +34,5 @@ oneway interface ITetheringEventCallback
|
||||
void onUpstreamChanged(in Network network);
|
||||
void onConfigurationChanged(in TetheringConfigurationParcel config);
|
||||
void onTetherStatesChanged(in TetherStatesParcel states);
|
||||
void onTetherClientsChanged(in List<TetheredClient> clients);
|
||||
}
|
||||
|
||||
@@ -191,6 +191,15 @@ public final class TetheredClient implements Parcelable {
|
||||
return new AddressInfo[size];
|
||||
}
|
||||
};
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AddressInfo {"
|
||||
+ mAddress
|
||||
+ (mHostname != null ? ", hostname " + mHostname : "")
|
||||
+ "}";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -212,4 +221,13 @@ public final class TetheredClient implements Parcelable {
|
||||
return new TetheredClient[size];
|
||||
}
|
||||
};
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TetheredClient {hwAddr " + mMacAddress
|
||||
+ ", addresses " + mAddresses
|
||||
+ ", tetheringType " + mTetheringType
|
||||
+ "}";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package android.net;
|
||||
|
||||
import android.net.Network;
|
||||
import android.net.TetheredClient;
|
||||
import android.net.TetheringConfigurationParcel;
|
||||
import android.net.TetherStatesParcel;
|
||||
|
||||
@@ -29,4 +30,5 @@ parcelable TetheringCallbackStartedParcel {
|
||||
Network upstreamNetwork;
|
||||
TetheringConfigurationParcel config;
|
||||
TetherStatesParcel states;
|
||||
List<TetheredClient> tetheredClients;
|
||||
}
|
||||
@@ -375,6 +375,9 @@ public class TetheringManager {
|
||||
mTetherStatesParcel = states;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTetherClientsChanged(List<TetheredClient> clients) { }
|
||||
|
||||
public void waitForStarted() {
|
||||
mWaitForCallback.block(DEFAULT_TIMEOUT_MS);
|
||||
throwIfPermissionFailure(mError);
|
||||
@@ -921,6 +924,7 @@ public class TetheringManager {
|
||||
sendRegexpsChanged(parcel.config);
|
||||
maybeSendTetherableIfacesChangedCallback(parcel.states);
|
||||
maybeSendTetheredIfacesChangedCallback(parcel.states);
|
||||
callback.onClientsChanged(parcel.tetheredClients);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -951,6 +955,11 @@ public class TetheringManager {
|
||||
maybeSendTetheredIfacesChangedCallback(states);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTetherClientsChanged(final List<TetheredClient> clients) {
|
||||
executor.execute(() -> callback.onClientsChanged(clients));
|
||||
}
|
||||
};
|
||||
getConnector(c -> c.registerTetheringEventCallback(remoteCallback, callerPkg));
|
||||
mTetheringEventCallbacks.put(callback, remoteCallback);
|
||||
|
||||
Reference in New Issue
Block a user