Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8b182839 authored by Doris Ling's avatar Doris Ling Committed by android-build-merger
Browse files

Merge "Update subtext for Security settings." into oc-dev

am: a0e617f9

Change-Id: I4ca0f307c5fdedb46ffd98bc85d5774c3ef74238
parents c27f924e a0e617f9
Loading
Loading
Loading
Loading
+6 −43
Original line number Diff line number Diff line
@@ -1227,54 +1227,17 @@ public class SecuritySettings extends SettingsPreferenceFragment

        @Override
        public void setListening(boolean listening) {
            if (!listening) {
                return;
            }
            int packageVerifierState = Settings.Secure.getInt(mContext.getContentResolver(),
                    Settings.Secure.PACKAGE_VERIFIER_STATE, 0);
            DashboardFeatureProvider dashboardFeatureProvider =
                    FeatureFactory.getFactory(mContext).getDashboardFeatureProvider(mContext);
            if (packageVerifierState == PACKAGE_VERIFIER_STATE_ENABLED) {
                // Calling the feature provider could potentially be slow, so do this on a separate
                // thread so as to not block the loading of Settings.
                Executors.newSingleThreadExecutor().execute(new Runnable() {
                    @Override
                    public void run() {
                        DashboardCategory dashboardCategory =
                                dashboardFeatureProvider.getTilesForCategory(
                                        CategoryKey.CATEGORY_SECURITY);
                        mSummaryLoader.setSummary(SummaryProvider.this,
                                getPackageVerifierSummary(dashboardCategory));
                    }
                });
            } else {
                final FingerprintManager fpm = Utils.getFingerprintManagerOrNull(mContext);
            if (listening) {
                final FingerprintManager fpm =
                    Utils.getFingerprintManagerOrNull(mContext);
                if (fpm != null && fpm.isHardwareDetected()) {
                    mSummaryLoader.setSummary(this,
                        mContext.getString(R.string.security_dashboard_summary));
                } else {
                    mSummaryLoader.setSummary(this, null);
                }
            }
        }

        @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
        String getPackageVerifierSummary(DashboardCategory dashboardCategory) {
            int tilesCount = (dashboardCategory != null) ? dashboardCategory.getTilesCount() : 0;
            if (tilesCount == 0) {
                return null;
            }
            for (int i = 0; i < tilesCount; i++) {
                Tile tile = dashboardCategory.getTile(i);
                if (!KEY_PACKAGE_VERIFIER_STATUS.equals(tile.key)) {
                    continue;
                    mSummaryLoader.setSummary(this, mContext.getString(
                        R.string.security_dashboard_summary_no_fingerprint));
                }
                String summaryUri = tile.metaData.getString(
                        TileUtils.META_DATA_PREFERENCE_SUMMARY_URI, null);
                return TileUtils.getTextFromUri(mContext, summaryUri,
                        new ArrayMap<>(), TileUtils.META_DATA_PREFERENCE_SUMMARY);
            }
            return null;
        }
    }

+16 −41
Original line number Diff line number Diff line
@@ -101,24 +101,7 @@ public class SecuritySettingsTest {
    }

    @Test
    @Config(shadows = {
            ShadowSecureSettings.class,
    })
    public void testSummaryProvider_packageVerifierDisabled() {
        // Package verifier state is set to disabled.
        ShadowSecureSettings.putInt(null, Settings.Secure.PACKAGE_VERIFIER_STATE, -1);
        mSummaryProvider.setListening(true);

        verify(mSummaryLoader, times(1)).setSummary(any(), isNull(String.class));
    }

    @Test
    @Config(shadows = {
            ShadowSecureSettings.class,
    })
    public void testSummaryProvider_hasFingerPrint_hasStaticSummary() {
        // Package verifier state is set to disabled.
        ShadowSecureSettings.putInt(null, Settings.Secure.PACKAGE_VERIFIER_STATE, -1);
        final FingerprintManager fpm = mock(FingerprintManager.class);
        when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT))
                .thenReturn(true);
@@ -133,37 +116,29 @@ public class SecuritySettingsTest {
    }

    @Test
    public void testGetPackageVerifierSummary_nullInput() {
        assertThat(mSummaryProvider.getPackageVerifierSummary(null)).isNull();
    public void testSummaryProvider_noFpFeature_shouldSetSummaryWithNoFingerprint() {
        final FingerprintManager fpm = mock(FingerprintManager.class);
        when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT))
            .thenReturn(false);

        when(mDashboardCategory.getTilesCount()).thenReturn(0);
        mSummaryProvider.setListening(true);

        assertThat(mSummaryProvider.getPackageVerifierSummary(mDashboardCategory)).isNull();
        verify(mContext).getString(R.string.security_dashboard_summary_no_fingerprint);
    }

    @Test
    public void testGetPackageVerifierSummary_noMatchingTile() {
        when(mDashboardCategory.getTilesCount()).thenReturn(1);
        when(mDashboardCategory.getTile(0)).thenReturn(new Tile());
    public void testSummaryProvider_noFpHardware_shouldSetSummaryWithNoFingerprint() {
        final FingerprintManager fpm = mock(FingerprintManager.class);
        when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT))
            .thenReturn(true);

        assertThat(mSummaryProvider.getPackageVerifierSummary(mDashboardCategory)).isNull();
    }
        // Cast to Object to workaround a robolectric casting bug
        when((Object) mContext.getSystemService(FingerprintManager.class)).thenReturn(fpm);
        when(fpm.isHardwareDetected()).thenReturn(false);

    @Test
    @Config(shadows = {
            ShadowTileUtils.class,
    })
    public void testGetPackageVerifierSummary_matchingTile() {
        when(mDashboardCategory.getTilesCount()).thenReturn(1);
        Tile tile = new Tile();
        tile.key = SecuritySettings.KEY_PACKAGE_VERIFIER_STATUS;
        Bundle bundle = new Bundle();
        bundle.putString(TileUtils.META_DATA_PREFERENCE_SUMMARY_URI, "content://host/path");
        tile.metaData = bundle;
        when(mDashboardCategory.getTile(0)).thenReturn(tile);

        assertThat(mSummaryProvider.getPackageVerifierSummary(mDashboardCategory))
                .isEqualTo(MOCK_SUMMARY);
        mSummaryProvider.setListening(true);

        verify(mContext).getString(R.string.security_dashboard_summary_no_fingerprint);
    }

    @Test