Fix problem with usb mode summary not updated correctly.

In UsbBackend, do not cache the usb state, but re-read it everytime when
we try to get the usb data mode.

Change-Id: I6f2863a59ee8df2c50901a630e3e145714c7dc46
Fix: 34234065
Test: make RunSettingsRoboTests
This commit is contained in:
Doris Ling
2017-02-17 15:22:13 -08:00
parent ad36812e88
commit 21711681ea
2 changed files with 32 additions and 7 deletions

View File

@@ -17,6 +17,7 @@
package com.android.settings.deviceinfo;
import android.content.Context;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.hardware.usb.UsbManager;
@@ -26,11 +27,15 @@ import com.android.settings.TestConfig;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentMatcher;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
import static org.mockito.Matchers.argThat;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@@ -57,4 +62,21 @@ public class UsbBackendTest {
UsbBackend usbBackend = new UsbBackend(mContext, mUserRestrictionUtil);
// Should not crash
}
@Test
public void getCurrentMode_shouldRegisterReceiverToGetUsbState() {
UsbBackend usbBackend = new UsbBackend(mContext, mUserRestrictionUtil);
usbBackend.getCurrentMode();
verify(mContext).registerReceiver(eq(null),
argThat(new ArgumentMatcher<IntentFilter>() {
@Override
public boolean matches(Object i) {
final IntentFilter intentFilter = (IntentFilter) i;
return intentFilter != null &&
UsbManager.ACTION_USB_STATE.equals(intentFilter.getAction(0));
}
}));
}
}