Skip to content
Snippets Groups Projects
Commit 1b9fd205 authored by Isaac Katzenelson's avatar Isaac Katzenelson
Browse files

Call onServiceConnected only after callback is saved in the service.

Prevent the onServiceConnected to be called prematurely. Until now
it was called in the manager and so that a client may rely on the
callback being called before it was actually available to the service
to use.

Bug: 293511169
Test: atest android.net.wifi.sharedconnectivity.cts
Change-Id: I698378a057990bd8ea73974130fa29ab1cd7c738
parent 66c1ccac
No related branches found
No related tags found
No related merge requests found
......@@ -81,6 +81,19 @@ public class SharedConnectivityManager {
mCallback = callback;
}
@Override
public void onServiceConnected() {
if (mCallback != null) {
final long token = Binder.clearCallingIdentity();
try {
mExecutor.execute(() -> mCallback.onServiceConnected());
} finally {
Binder.restoreCallingIdentity(token);
}
}
}
@Override
public void onHotspotNetworksUpdated(@NonNull List<HotspotNetwork> networks) {
if (mCallback != null) {
final long token = Binder.clearCallingIdentity();
......@@ -117,6 +130,7 @@ public class SharedConnectivityManager {
}
}
@Override
public void onHotspotNetworkConnectionStatusChanged(
@NonNull HotspotNetworkConnectionStatus status) {
if (mCallback != null) {
......@@ -251,7 +265,6 @@ public class SharedConnectivityManager {
synchronized (mProxyDataLock) {
mProxyMap.put(callback, proxy);
}
callback.onServiceConnected();
} catch (RemoteException e) {
Log.e(TAG, "Exception in registerCallback", e);
callback.onRegisterCallbackFailed(e);
......
......@@ -31,4 +31,5 @@ interface ISharedConnectivityCallback {
oneway void onKnownNetworksUpdated(in List<KnownNetwork> networks);
oneway void onKnownNetworkConnectionStatusChanged(in KnownNetworkConnectionStatus status);
oneway void onSharedConnectivitySettingsChanged(in SharedConnectivitySettingsState state);
oneway void onServiceConnected();
}
......@@ -276,6 +276,11 @@ public abstract class SharedConnectivityService extends Service {
private void onRegisterCallback(ISharedConnectivityCallback callback) {
mRemoteCallbackList.register(callback);
try {
callback.onServiceConnected();
} catch (RemoteException e) {
if (DEBUG) Log.w(TAG, "Exception in onRegisterCallback", e);
}
if (mCountDownLatch != null) {
mCountDownLatch.countDown();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment