Fix robotests failure in connectivity settings

Bug: 174212358
Test: make -j42 RunSettingsRoboTests
Change-Id: I50baeb18b00f16808dc958d77251a01ba991adf6
This commit is contained in:
Hugh Chen
2020-11-25 16:13:18 +08:00
parent 2a6ffedfee
commit e61a5e3bc7
9 changed files with 112 additions and 59 deletions

View File

@@ -16,6 +16,8 @@
package com.android.settings.testutils.shadow;
import static org.robolectric.shadow.api.Shadow.newInstanceOf;
import android.app.Activity;
import android.content.Context;
import android.nfc.NfcAdapter;
@@ -24,16 +26,18 @@ import android.os.Bundle;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.Resetter;
import org.robolectric.util.ReflectionHelpers;
import org.robolectric.util.ReflectionHelpers.ClassParameter;
/**
* Shadow of {@link NfcAdapter}.
*/
@Implements(NfcAdapter.class)
public class ShadowNfcAdapter {
@Implements(value = NfcAdapter.class)
public class ShadowNfcAdapter extends org.robolectric.shadows.ShadowNfcAdapter {
private static boolean sReaderModeEnabled;
private static Object sNfcAdapter = newInstanceOf("android.nfc.NfcAdapter");
private boolean mIsNfcEnabled = false;
private int mState = NfcAdapter.STATE_ON;
private boolean mIsSecureNfcSupported = false;
@Implementation
protected void enableReaderMode(Activity activity, NfcAdapter.ReaderCallback callback,
@@ -43,8 +47,7 @@ public class ShadowNfcAdapter {
@Implementation
protected static NfcAdapter getDefaultAdapter(Context context) {
return ReflectionHelpers.callConstructor(
NfcAdapter.class, ClassParameter.from(Context.class, context));
return (NfcAdapter) sNfcAdapter;
}
@Implementation
@@ -52,6 +55,28 @@ public class ShadowNfcAdapter {
return mIsNfcEnabled;
}
public void setEnabled(boolean enable) {
mIsNfcEnabled = enable;
}
@Implementation
protected int getAdapterState() {
return mState;
}
public void setAdapterState(int state) {
this.mState = state;
}
@Implementation
protected boolean isSecureNfcSupported() {
return mIsSecureNfcSupported;
}
public void setSecureNfcSupported(boolean supported) {
this.mIsSecureNfcSupported = supported;
}
@Implementation
protected boolean enable() {
mIsNfcEnabled = true;