use of android.nfc.NfcManager in project android_packages_apps_Settings by SudaMod.
the class ConnectedDeviceDashboardFragmentTest method testSummaryProvider_hasNfc_shouldReturnNfcSummary.
@Test
public void testSummaryProvider_hasNfc_shouldReturnNfcSummary() {
final NfcManager nfcManager = mock(NfcManager.class);
final SummaryLoader summaryLoader = mock(SummaryLoader.class);
when(mContext.getApplicationContext()).thenReturn(mContext);
when(mContext.getSystemService(NFC_SERVICE)).thenReturn(nfcManager);
when(nfcManager.getDefaultAdapter()).thenReturn(mock(NfcAdapter.class));
SummaryLoader.SummaryProvider provider = new ConnectedDeviceDashboardFragment.SummaryProvider(mContext, summaryLoader);
provider.setListening(false);
verifyZeroInteractions(summaryLoader);
provider.setListening(true);
verify(mContext).getString(R.string.connected_devices_dashboard_summary);
}
use of android.nfc.NfcManager in project android_packages_apps_CMParts by LineageOS.
the class SetupActionsFragment method fillProfileWithCurrentSettings.
public static void fillProfileWithCurrentSettings(Context context, Profile profile) {
// bt
if (DeviceUtils.deviceSupportsBluetooth()) {
profile.setConnectionSettings(new ConnectionSettings(ConnectionSettings.PROFILE_CONNECTION_BLUETOOTH, BluetoothAdapter.getDefaultAdapter().isEnabled() ? 1 : 0, true));
}
// gps
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
boolean gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
profile.setConnectionSettings(new ConnectionSettings(ConnectionSettings.PROFILE_CONNECTION_GPS, gpsEnabled ? 1 : 0, true));
// wifi
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
profile.setConnectionSettings(new ConnectionSettings(ConnectionSettings.PROFILE_CONNECTION_WIFI, wifiManager.isWifiEnabled() ? 1 : 0, true));
// auto sync data
profile.setConnectionSettings(new ConnectionSettings(ConnectionSettings.PROFILE_CONNECTION_SYNC, ContentResolver.getMasterSyncAutomatically() ? 1 : 0, true));
// mobile data
if (DeviceUtils.deviceSupportsMobileData(context)) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
profile.setConnectionSettings(new ConnectionSettings(ConnectionSettings.PROFILE_CONNECTION_MOBILEDATA, cm.getMobileDataEnabled() ? 1 : 0, true));
}
// wifi hotspot
profile.setConnectionSettings(new ConnectionSettings(ConnectionSettings.PROFILE_CONNECTION_WIFIAP, wifiManager.isWifiApEnabled() ? 1 : 0, true));
// nfc
if (DeviceUtils.deviceSupportsNfc(context)) {
NfcManager nfcManager = (NfcManager) context.getSystemService(Context.NFC_SERVICE);
profile.setConnectionSettings(new ConnectionSettings(ConnectionSettings.PROFILE_CONNECTION_NFC, nfcManager.getDefaultAdapter().isEnabled() ? 1 : 0, true));
}
// alarm volume
final AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
profile.setStreamSettings(new StreamSettings(AudioManager.STREAM_ALARM, am.getStreamVolume(AudioManager.STREAM_ALARM), true));
// media volume
profile.setStreamSettings(new StreamSettings(AudioManager.STREAM_MUSIC, am.getStreamVolume(AudioManager.STREAM_MUSIC), true));
// ringtone volume
profile.setStreamSettings(new StreamSettings(AudioManager.STREAM_RING, am.getStreamVolume(AudioManager.STREAM_RING), true));
// notification volume
profile.setStreamSettings(new StreamSettings(AudioManager.STREAM_NOTIFICATION, am.getStreamVolume(AudioManager.STREAM_NOTIFICATION), true));
// ring mode
String ringValue;
switch(am.getRingerMode()) {
default:
case AudioManager.RINGER_MODE_NORMAL:
ringValue = "normal";
break;
case AudioManager.RINGER_MODE_SILENT:
ringValue = "mute";
break;
case AudioManager.RINGER_MODE_VIBRATE:
ringValue = "vibrate";
break;
}
profile.setRingMode(new RingModeSettings(ringValue, true));
// airplane mode
boolean airplaneMode = Settings.Global.getInt(context.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0) != 0;
profile.setAirplaneMode(new AirplaneModeSettings(airplaneMode ? 1 : 0, true));
// lock screen mode
// populated only from profiles, so we can read the current profile,
// but let's skip this one
}
use of android.nfc.NfcManager in project android_packages_apps_Settings by DirtyUnicorns.
the class ConnectedDeviceDashboardFragmentTest method testSummaryProvider_hasNfc_shouldReturnNfcSummary.
@Test
public void testSummaryProvider_hasNfc_shouldReturnNfcSummary() {
final NfcManager nfcManager = mock(NfcManager.class);
final SummaryLoader summaryLoader = mock(SummaryLoader.class);
when(mContext.getApplicationContext()).thenReturn(mContext);
when(mContext.getSystemService(NFC_SERVICE)).thenReturn(nfcManager);
when(nfcManager.getDefaultAdapter()).thenReturn(mock(NfcAdapter.class));
SummaryLoader.SummaryProvider provider = new ConnectedDeviceDashboardFragment.SummaryProvider(mContext, summaryLoader);
provider.setListening(false);
verifyZeroInteractions(summaryLoader);
provider.setListening(true);
verify(mContext).getString(R.string.connected_devices_dashboard_summary);
}
use of android.nfc.NfcManager in project platform_packages_apps_Settings by BlissRoms.
the class ConnectedDeviceDashboardFragmentTest method testSummaryProvider_hasNfc_shouldReturnNfcSummary.
@Test
public void testSummaryProvider_hasNfc_shouldReturnNfcSummary() {
final NfcManager nfcManager = mock(NfcManager.class);
final SummaryLoader summaryLoader = mock(SummaryLoader.class);
when(mContext.getApplicationContext()).thenReturn(mContext);
when(mContext.getSystemService(NFC_SERVICE)).thenReturn(nfcManager);
when(nfcManager.getDefaultAdapter()).thenReturn(mock(NfcAdapter.class));
SummaryLoader.SummaryProvider provider = new ConnectedDeviceDashboardFragment.SummaryProvider(mContext, summaryLoader);
provider.setListening(false);
verifyZeroInteractions(summaryLoader);
provider.setListening(true);
verify(mContext).getString(R.string.connected_devices_dashboard_summary);
}
use of android.nfc.NfcManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class ConnectedDeviceTests method testNFCToggle.
// This NFC toggle test is set up this way since there's no way to set
// the NFC flag to enabled or disabled without touching UI.
// This way, we get coverage for whether or not the toggle button works.
@Test
public void testNFCToggle() throws Exception {
NfcManager manager = (NfcManager) InstrumentationRegistry.getTargetContext().getSystemService(Context.NFC_SERVICE);
NfcAdapter nfcAdapter = manager.getDefaultAdapter();
boolean nfcInitiallyEnabled = nfcAdapter.isEnabled();
InstrumentationRegistry.getContext().startActivity(new Intent().setClassName(SETTINGS_PACKAGE, "com.android.settings.Settings$ConnectedDeviceDashboardActivity"));
UiObject2 nfcSetting = mDevice.wait(Until.findObject(By.text("NFC")), TIMEOUT);
nfcSetting.click();
Thread.sleep(TIMEOUT * 2);
if (nfcInitiallyEnabled) {
assertFalse("NFC wasn't disabled on toggle", nfcAdapter.isEnabled());
nfcSetting.click();
Thread.sleep(TIMEOUT * 2);
assertTrue("NFC wasn't enabled on toggle", nfcAdapter.isEnabled());
} else {
assertTrue("NFC wasn't enabled on toggle", nfcAdapter.isEnabled());
nfcSetting.click();
Thread.sleep(TIMEOUT * 2);
assertFalse("NFC wasn't disabled on toggle", nfcAdapter.isEnabled());
}
}
Aggregations