Fix EthernetManager.addListener dependency in Tethering settings.

Ethernet service related files are going to be moved into Connectivity
module. EthernetManager.addListener(listener, exectuor) will be exposed
out as module-lib API. Replace the current API usage with the one to be
exposed.

android.os.HandlerExecutor is a hidden API which isn't visible to modules,
try to replace HanlderExecutor class with Handler.post itself although
Setttings can still access this API.

Bug: 210586283
Test: m
Change-Id: I618b43769c68897f4724fae8213181be1cc770c6
This commit is contained in:
Xiao Ma
2022-01-18 06:44:52 +00:00
parent 0ccb8750b9
commit f621c4ba14
2 changed files with 8 additions and 10 deletions

View File

@@ -39,7 +39,6 @@ import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.HandlerExecutor;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.SearchIndexableResource;
@@ -324,14 +323,14 @@ public class TetherSettings extends RestrictedSettingsFragment
mStartTetheringCallback = new OnStartTetheringCallback(this);
mTetheringEventCallback = new TetheringEventCallback();
mTm.registerTetheringEventCallback(new HandlerExecutor(mHandler), mTetheringEventCallback);
mTm.registerTetheringEventCallback(r -> mHandler.post(r), mTetheringEventCallback);
mMassStorageActive = Environment.MEDIA_SHARED.equals(Environment.getExternalStorageState());
registerReceiver();
mEthernetListener = new EthernetListener();
if (mEm != null)
mEm.addListener(mEthernetListener);
mEm.addListener(mEthernetListener, r -> mHandler.post(r));
updateUsbState();
updateBluetoothAndEthernetState();

View File

@@ -48,13 +48,12 @@ public final class EthernetTetherPreferenceController extends TetherBasePreferen
@OnLifecycleEvent(Lifecycle.Event.ON_START)
public void onStart() {
mEthernetListener = new EthernetManager.Listener() {
@Override
public void onAvailabilityChanged(String iface, boolean isAvailable) {
new Handler(Looper.getMainLooper()).post(() -> updateState(mPreference));
}
};
mEthernetManager.addListener(mEthernetListener);
mEthernetListener = (iface, isAvailable) -> updateState(mPreference);
final Handler handler = new Handler(Looper.getMainLooper());
// Executor will execute to post the updateState event to a new handler which is created
// from the main looper when the {@link EthernetManager.Listener.onAvailabilityChanged}
// is triggerd.
mEthernetManager.addListener(mEthernetListener, r -> handler.post(r));
}
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)