Search in sources :

Example 6 with NfcManager

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);
}
Also used : NfcManager(android.nfc.NfcManager) SummaryLoader(com.android.settings.dashboard.SummaryLoader) NfcAdapter(android.nfc.NfcAdapter) Test(org.junit.Test)

Example 7 with NfcManager

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
}
Also used : LocationManager(android.location.LocationManager) WifiManager(android.net.wifi.WifiManager) AudioManager(android.media.AudioManager) StreamSettings(cyanogenmod.profiles.StreamSettings) ConnectivityManager(android.net.ConnectivityManager) RingModeSettings(cyanogenmod.profiles.RingModeSettings) NfcManager(android.nfc.NfcManager) AirplaneModeSettings(cyanogenmod.profiles.AirplaneModeSettings) ConnectionSettings(cyanogenmod.profiles.ConnectionSettings)

Example 8 with NfcManager

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);
}
Also used : NfcManager(android.nfc.NfcManager) SummaryLoader(com.android.settings.dashboard.SummaryLoader) NfcAdapter(android.nfc.NfcAdapter) Test(org.junit.Test)

Example 9 with NfcManager

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);
}
Also used : NfcManager(android.nfc.NfcManager) SummaryLoader(com.android.settings.dashboard.SummaryLoader) NfcAdapter(android.nfc.NfcAdapter) Test(org.junit.Test)

Example 10 with NfcManager

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());
    }
}
Also used : NfcManager(android.nfc.NfcManager) NfcAdapter(android.nfc.NfcAdapter) Intent(android.content.Intent) UiObject2(android.support.test.uiautomator.UiObject2) MediumTest(androidx.test.filters.MediumTest) Test(org.junit.Test)

Aggregations

NfcManager (android.nfc.NfcManager)18 NfcAdapter (android.nfc.NfcAdapter)15 Test (org.junit.Test)7 SummaryLoader (com.android.settings.dashboard.SummaryLoader)6 Intent (android.content.Intent)3 SuppressLint (android.annotation.SuppressLint)2 PendingIntent (android.app.PendingIntent)2 IntentFilter (android.content.IntentFilter)2 Tag (android.nfc.Tag)2 Bundle (android.os.Bundle)2 LocationManager (android.location.LocationManager)1 AudioManager (android.media.AudioManager)1 ConnectivityManager (android.net.ConnectivityManager)1 WifiManager (android.net.wifi.WifiManager)1 UiObject2 (android.support.test.uiautomator.UiObject2)1 Toolbar (android.support.v7.widget.Toolbar)1 MediumTest (androidx.test.filters.MediumTest)1 AirplaneModeSettings (cyanogenmod.profiles.AirplaneModeSettings)1 ConnectionSettings (cyanogenmod.profiles.ConnectionSettings)1 RingModeSettings (cyanogenmod.profiles.RingModeSettings)1