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

Commit 364b010c authored by Philipp Weiß's avatar Philipp Weiß Committed by Android (Google) Code Review
Browse files

Merge "Redesign QSSecurityFooter dialog" into oc-dev

parents c08c1700 48e353ce
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@
    android:paddingStart="@dimen/qs_footer_padding_start"
    android:paddingEnd="@dimen/qs_footer_padding_end"
    android:gravity="center_vertical"
    android:background="?android:attr/colorPrimaryDark" >
    android:background="?android:attr/colorPrimary" >

    <TextView
        android:id="@+id/footer_text"
@@ -39,6 +39,7 @@
        android:layout_width="@dimen/qs_footer_icon_size"
        android:layout_height="@dimen/qs_footer_icon_size"
        android:contentDescription="@null"
        android:src="@drawable/ic_info_outline" />
        android:src="@drawable/ic_info_outline"
        android:tint="?android:attr/textColorSecondary"/>

</LinearLayout>
+83 −68
Original line number Diff line number Diff line
@@ -27,90 +27,105 @@
        android:paddingTop="?android:attr/dialogPreferredPadding"
        android:paddingRight="?android:attr/dialogPreferredPadding"
        android:paddingLeft="?android:attr/dialogPreferredPadding"
        android:orientation="vertical">
        <LinearLayout
            android:id="@+id/device_management_disclosures"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="?android:attr/dialogPreferredPadding"
            android:orientation="vertical">
            <TextView
            android:id="@+id/device_owner_warning"
                android:id="@+id/device_management_subtitle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
            style="@android:style/TextAppearance.Material.Subhead"
            android:textColor="?android:attr/textColorPrimaryInverse"
                android:text="@string/monitoring_title_device_owned"
                style="@android:style/TextAppearance.Material.Title"
                android:textColor="?android:attr/textColorPrimary"
                android:paddingBottom="@dimen/qs_footer_dialog_subtitle_padding"
            />
        <LinearLayout
            <TextView
                android:id="@+id/device_management_warning"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
            android:orientation="horizontal">
            <ImageView
                android:id="@+id/vpn_icon"
                android:layout_width="@dimen/qs_footer_dialog_icon_size"
                android:layout_height="wrap_content"
                android:paddingTop="?android:attr/dialogPreferredPadding"
                android:layout_marginStart="@dimen/qs_footer_dialog_icon_margin"
                android:layout_marginEnd="@dimen/qs_footer_dialog_icon_margin"
                android:scaleType="fitCenter"
                android:src="@drawable/ic_qs_vpn"
                android:tint="?android:attr/textColorPrimaryInverse"
                android:adjustViewBounds="true"/>
                android:text="@null"
                style="@android:style/TextAppearance.Material.Subhead"
                android:textColor="?android:attr/textColorPrimary"
            />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/ca_certs_disclosures"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="?android:attr/dialogPreferredPadding"
            android:orientation="vertical">
            <TextView
                    android:id="@+id/vpn_subtitle"
                android:id="@+id/ca_certs_subtitle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                    android:paddingTop="?android:attr/dialogPreferredPadding"
                    android:text="@string/monitoring_subtitle_vpn"
                android:text="@string/monitoring_subtitle_ca_certificate"
                style="@android:style/TextAppearance.Material.Title"
                    android:textColor="?android:attr/textColorPrimaryInverse"
                android:textColor="?android:attr/textColorPrimary"
                android:paddingBottom="@dimen/qs_footer_dialog_subtitle_padding"
            />
            <TextView
                    android:id="@+id/vpn_warning"
                android:id="@+id/ca_certs_warning"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@null"
                style="@android:style/TextAppearance.Material.Subhead"
                    android:textColor="?android:attr/textColorPrimaryInverse"
                android:textColor="?android:attr/textColorPrimary"
            />
        </LinearLayout>
        </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <ImageView
                android:id="@+id/network_logging_icon"
                android:layout_width="@dimen/qs_footer_dialog_icon_size"
                android:layout_height="wrap_content"
                android:paddingTop="?android:attr/dialogPreferredPadding"
                android:layout_marginStart="@dimen/qs_footer_dialog_icon_margin"
                android:layout_marginEnd="@dimen/qs_footer_dialog_icon_margin"
                android:scaleType="fitCenter"
                android:src="@drawable/ic_qs_network_logging"
                android:tint="?android:attr/textColorPrimaryInverse"
                android:adjustViewBounds="true"/>

        <LinearLayout
            android:id="@+id/network_logging_disclosures"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="?android:attr/dialogPreferredPadding"
            android:orientation="vertical">
            <TextView
                android:id="@+id/network_logging_subtitle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                    android:paddingTop="?android:attr/dialogPreferredPadding"
                android:text="@string/monitoring_subtitle_network_logging"
                style="@android:style/TextAppearance.Material.Title"
                    android:textColor="?android:attr/textColorPrimaryInverse"
                android:textColor="?android:attr/textColorPrimary"
                android:paddingBottom="@dimen/qs_footer_dialog_subtitle_padding"
            />
            <TextView
                android:id="@+id/network_logging_warning"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                    android:text="@string/monitoring_description_network_logging"
                android:text="@null"
                style="@android:style/TextAppearance.Material.Subhead"
                    android:textColor="?android:attr/textColorPrimaryInverse"
                android:textColor="?android:attr/textColorPrimary"
            />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/vpn_disclosures"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="?android:attr/dialogPreferredPadding"
            android:orientation="vertical">
            <TextView
                android:id="@+id/vpn_subtitle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/monitoring_subtitle_vpn"
                style="@android:style/TextAppearance.Material.Title"
                android:textColor="?android:attr/textColorPrimary"
                android:paddingBottom="@dimen/qs_footer_dialog_subtitle_padding"
            />
            <TextView
                android:id="@+id/vpn_warning"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@null"
                style="@android:style/TextAppearance.Material.Subhead"
                android:textColor="?android:attr/textColorPrimary"
            />
        </LinearLayout>
    </LinearLayout>
</ScrollView>
+2 −0
Original line number Diff line number Diff line
@@ -282,6 +282,8 @@
    <dimen name="qs_footer_dialog_icon_size">24sp</dimen>
    <!-- Left and right margin of the icons -->
    <dimen name="qs_footer_dialog_icon_margin">8sp</dimen>
    <!-- Padding between subtitles and the following text in the QSFooter dialog -->
    <dimen name="qs_footer_dialog_subtitle_padding">20dp</dimen>

    <!-- Zen mode panel: condition item button padding -->
    <dimen name="zen_mode_condition_detail_button_padding">8dp</dimen>
+126 −93
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;

@@ -224,117 +225,152 @@ public class QSSecurityFooter implements OnClickListener, DialogInterface.OnClic
    @Override
    public void onClick(DialogInterface dialog, int which) {
        if (which == DialogInterface.BUTTON_NEGATIVE) {
            final Intent settingsIntent = new Intent(ACTION_VPN_SETTINGS);
            mActivityStarter.postStartActivityDismissingKeyguard(settingsIntent, 0);
            final Intent intent = new Intent(Settings.ACTION_ENTERPRISE_PRIVACY_SETTINGS);
            mDialog.dismiss();
            mActivityStarter.postStartActivityDismissingKeyguard(intent, 0);
        }
    }

    private void createDialog() {
        final String deviceOwnerPackage = mSecurityController.getDeviceOwnerName();
        final String profileOwnerPackage = mSecurityController.getProfileOwnerName();
        final boolean isNetworkLoggingEnabled = mSecurityController.isNetworkLoggingEnabled();
        final String primaryVpn = mSecurityController.getPrimaryVpnName();
        final String profileVpn = mSecurityController.getWorkProfileVpnName();
        final boolean isDeviceManaged = mSecurityController.isDeviceManaged();
        final boolean hasWorkProfile = mSecurityController.hasWorkProfile();
        final CharSequence deviceOwnerOrganization =
                mSecurityController.getDeviceOwnerOrganizationName();
        boolean hasProfileOwner = mSecurityController.hasProfileOwner();
        final boolean hasCACerts = mSecurityController.hasCACertInCurrentUser();
        final boolean hasCACertsInWorkProfile = mSecurityController.hasCACertInWorkProfile();
        final boolean isNetworkLoggingEnabled = mSecurityController.isNetworkLoggingEnabled();
        final String vpnName = mSecurityController.getPrimaryVpnName();
        final String vpnNameWorkProfile = mSecurityController.getWorkProfileVpnName();

        mDialog = new SystemUIDialog(mContext);
        mDialog.setTitle(getTitle(deviceOwnerPackage));
        CharSequence msg = getMessage(deviceOwnerPackage, profileOwnerPackage, primaryVpn,
                profileVpn, deviceOwnerOrganization, hasProfileOwner);
        if (deviceOwnerPackage == null) {
            mDialog.setMessage(msg);
            if (mSecurityController.isVpnEnabled() && !mSecurityController.isVpnRestricted()) {
                mDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getSettingsButton(), this);
            }
        } else {
        mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        View dialogView = LayoutInflater.from(mContext)
               .inflate(R.layout.quick_settings_footer_dialog, null, false);
        mDialog.setView(dialogView);
            TextView deviceOwnerWarning =
                    (TextView) dialogView.findViewById(R.id.device_owner_warning);
            deviceOwnerWarning.setText(msg);
            // Make the link "learn more" clickable.
            deviceOwnerWarning.setMovementMethod(new LinkMovementMethod());
            if (primaryVpn == null) {
                dialogView.findViewById(R.id.vpn_icon).setVisibility(View.GONE);
                dialogView.findViewById(R.id.vpn_subtitle).setVisibility(View.GONE);
                dialogView.findViewById(R.id.vpn_warning).setVisibility(View.GONE);
        mDialog.setButton(DialogInterface.BUTTON_POSITIVE, getPositiveButton(), this);

        // device management section
        CharSequence managementMessage = getManagementMessage(isDeviceManaged,
                deviceOwnerOrganization);
        if (managementMessage == null) {
            dialogView.findViewById(R.id.device_management_disclosures).setVisibility(View.GONE);
        } else {
                final SpannableStringBuilder message = new SpannableStringBuilder();
                message.append(mContext.getString(R.string.monitoring_description_do_body_vpn,
                        primaryVpn));
                if (!mSecurityController.isVpnRestricted()) {
                    message.append(mContext.getString(
                            R.string.monitoring_description_vpn_settings_separator));
                    message.append(mContext.getString(R.string.monitoring_description_vpn_settings),
                            new VpnSpan(), 0);
            dialogView.findViewById(R.id.device_management_disclosures).setVisibility(View.VISIBLE);
            TextView deviceManagementWarning =
                    (TextView) dialogView.findViewById(R.id.device_management_warning);
            deviceManagementWarning.setText(managementMessage);
            mDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getSettingsButton(), this);
        }

                TextView vpnWarning = (TextView) dialogView.findViewById(R.id.vpn_warning);
                vpnWarning.setText(message);
                // Make the link "Open VPN Settings" clickable.
                vpnWarning.setMovementMethod(new LinkMovementMethod());
        // ca certificate section
        CharSequence caCertsMessage = getCaCertsMessage(isDeviceManaged, hasCACerts,
                hasCACertsInWorkProfile);
        if (caCertsMessage == null) {
            dialogView.findViewById(R.id.ca_certs_disclosures).setVisibility(View.GONE);
        } else {
            dialogView.findViewById(R.id.ca_certs_disclosures).setVisibility(View.VISIBLE);
            TextView caCertsWarning = (TextView) dialogView.findViewById(R.id.ca_certs_warning);
            caCertsWarning.setText(caCertsMessage);
            // Make "Open trusted credentials"-link clickable
            caCertsWarning.setMovementMethod(new LinkMovementMethod());
        }
            if (!isNetworkLoggingEnabled) {
                dialogView.findViewById(R.id.network_logging_icon).setVisibility(View.GONE);
                dialogView.findViewById(R.id.network_logging_subtitle).setVisibility(View.GONE);
                dialogView.findViewById(R.id.network_logging_warning).setVisibility(View.GONE);

        // network logging section
        CharSequence networkLoggingMessage = getNetworkLoggingMessage(isNetworkLoggingEnabled);
        if (networkLoggingMessage == null) {
            dialogView.findViewById(R.id.network_logging_disclosures).setVisibility(View.GONE);
        } else {
            dialogView.findViewById(R.id.network_logging_disclosures).setVisibility(View.VISIBLE);
            TextView networkLoggingWarning =
                    (TextView) dialogView.findViewById(R.id.network_logging_warning);
            networkLoggingWarning.setText(networkLoggingMessage);
        }

        // vpn section
        CharSequence vpnMessage = getVpnMessage(isDeviceManaged, hasWorkProfile, vpnName,
                vpnNameWorkProfile);
        if (vpnMessage == null) {
            dialogView.findViewById(R.id.vpn_disclosures).setVisibility(View.GONE);
        } else {
            dialogView.findViewById(R.id.vpn_disclosures).setVisibility(View.VISIBLE);
            TextView vpnWarning = (TextView) dialogView.findViewById(R.id.vpn_warning);
            vpnWarning.setText(vpnMessage);
            // Make "Open VPN Settings"-link clickable
            vpnWarning.setMovementMethod(new LinkMovementMethod());
        }

        mDialog.setButton(DialogInterface.BUTTON_POSITIVE, getPositiveButton(), this);
        mDialog.show();
        mDialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        mDialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
    }

    private String getSettingsButton() {
        return mContext.getString(R.string.status_bar_settings_settings_button);
        return mContext.getString(R.string.monitoring_button_view_policies);
    }

    private String getPositiveButton() {
        return mContext.getString(R.string.quick_settings_done);
    }

    protected CharSequence getMessage(String deviceOwnerPackage, String profileOwnerPackage,
            String primaryVpn, String profileVpn, CharSequence deviceOwnerOrganization,
            boolean hasProfileOwner) {
        if (deviceOwnerPackage != null) {
    protected CharSequence getManagementMessage(boolean isDeviceManaged,
            CharSequence organizationName) {
        if (!isDeviceManaged) return null;
        if (organizationName != null)
            return mContext.getString(
                    R.string.monitoring_description_named_management, organizationName);
        return mContext.getString(R.string.monitoring_description_management);
    }

    protected CharSequence getCaCertsMessage(boolean isDeviceManaged, boolean hasCACerts,
            boolean hasCACertsInWorkProfile) {
        if (!(hasCACerts || hasCACertsInWorkProfile)) return null;
        if (isDeviceManaged) {
            return mContext.getString(R.string.monitoring_description_management_ca_certificate);
        }
        if (hasCACertsInWorkProfile) {
            return mContext.getString(
                    R.string.monitoring_description_managed_profile_ca_certificate);
        }
        return mContext.getString(R.string.monitoring_description_ca_certificate);
    }

    protected CharSequence getNetworkLoggingMessage(boolean isNetworkLoggingEnabled) {
        if (!isNetworkLoggingEnabled) return null;
        return mContext.getString(R.string.monitoring_description_management_network_logging);
    }

    protected CharSequence getVpnMessage(boolean isDeviceManaged, boolean hasWorkProfile,
            String vpnName, String vpnNameWorkProfile) {
        if (vpnName == null && vpnNameWorkProfile == null) return null;
        final SpannableStringBuilder message = new SpannableStringBuilder();
            if (deviceOwnerOrganization != null) {
                message.append(mContext.getString(
                        R.string.monitoring_description_do_header_with_name,
                        deviceOwnerOrganization, deviceOwnerPackage));
        if (isDeviceManaged) {
            if (vpnName != null && vpnNameWorkProfile != null) {
                message.append(mContext.getString(R.string.monitoring_description_two_named_vpns,
                        vpnName, vpnNameWorkProfile));
            } else {
                message.append(mContext.getString(R.string.monitoring_description_do_header_generic,
                        deviceOwnerPackage));
                message.append(mContext.getString(R.string.monitoring_description_named_vpn,
                        vpnName != null ? vpnName : vpnNameWorkProfile));
            }
            message.append("\n\n");
            message.append(mContext.getString(R.string.monitoring_description_do_body));
            message.append(mContext.getString(
                    R.string.monitoring_description_do_learn_more_separator));
            message.append(mContext.getString(R.string.monitoring_description_do_learn_more),
                    new EnterprisePrivacySpan(), 0);
            return message;
        } else if (primaryVpn != null) {
            if (profileVpn != null) {
                return mContext.getString(R.string.monitoring_description_app_personal_work,
                        profileOwnerPackage, profileVpn, primaryVpn);
        } else {
                return mContext.getString(R.string.monitoring_description_app_personal,
                        primaryVpn);
            }
        } else if (profileVpn != null) {
            return mContext.getString(R.string.monitoring_description_app_work,
                    profileOwnerPackage, profileVpn);
        } else if (profileOwnerPackage != null && hasProfileOwner) {
            return mContext.getString(R.string.do_disclosure_with_name,
                    profileOwnerPackage);
            if (vpnName != null && vpnNameWorkProfile != null) {
                message.append(mContext.getString(R.string.monitoring_description_two_named_vpns,
                        vpnName, vpnNameWorkProfile));
            } else if (vpnNameWorkProfile != null) {
                message.append(mContext.getString(
                        R.string.monitoring_description_managed_profile_named_vpn,
                        vpnNameWorkProfile));
            } else if (hasWorkProfile) {
                message.append(mContext.getString(
                        R.string.monitoring_description_personal_profile_named_vpn, vpnName));
            } else {
            // No device owner, no personal VPN, no work VPN, no user owner. Why are we here?
            return null;
                message.append(mContext.getString(R.string.monitoring_description_named_vpn,
                        vpnName));
            }
        }
        message.append(mContext.getString(R.string.monitoring_description_vpn_settings_separator));
        message.append(mContext.getString(R.string.monitoring_description_vpn_settings),
                new VpnSpan(), 0);
        return message;
    }

    private int getTitle(String deviceOwner) {
@@ -397,26 +433,23 @@ public class QSSecurityFooter implements OnClickListener, DialogInterface.OnClic
        }
    }

    protected class EnterprisePrivacySpan extends ClickableSpan {
    protected class VpnSpan extends ClickableSpan {
        @Override
        public void onClick(View widget) {
            final Intent intent = new Intent(Settings.ACTION_ENTERPRISE_PRIVACY_SETTINGS);
            final Intent intent = new Intent(Settings.ACTION_VPN_SETTINGS);
            mDialog.dismiss();
            mActivityStarter.postStartActivityDismissingKeyguard(intent, 0);
        }

        // for testing, to compare two CharSequences containing VpnSpans
        @Override
        public boolean equals(Object object) {
            return object instanceof EnterprisePrivacySpan;
        }
            return object instanceof VpnSpan;
        }

    protected class VpnSpan extends ClickableSpan {
        @Override
        public void onClick(View widget) {
            final Intent intent = new Intent(Settings.ACTION_VPN_SETTINGS);
            mDialog.dismiss();
            mActivityStarter.postStartActivityDismissingKeyguard(intent, 0);
        public int hashCode() {
            return 314159257; // prime
        }
    }
}
+54 −44

File changed.

Preview size limit exceeded, changes collapsed.