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

Commit 1901ae3b authored by Sudheer Shanka's avatar Sudheer Shanka
Browse files

Add restricted padlocks to radio buttons.

Change-Id: Ibaf312a4c6c5fd9126ab7d45ccb094fc1bd46a1f
parent 3375206f
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -41,14 +41,14 @@
            android:layout_marginEnd="?android:attr/listPreferredItemPaddingEnd"
            android:checkedButton="@+id/redact_sensitive">

        <RadioButton
        <com.android.settings.RestrictedRadioButton
                android:id="@+id/show_all"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/redaction_vertical_margins"
                android:text="@string/lock_screen_notifications_summary_show" />

        <RadioButton
        <com.android.settings.RestrictedRadioButton
                android:id="@+id/redact_sensitive"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
+82 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */

package com.android.settings;

import android.content.Context;
import android.graphics.PorterDuff;
import android.util.AttributeSet;
import android.widget.RadioButton;
import android.widget.TextView;

import java.util.List;

import com.android.settingslib.RestrictedLockUtils;

import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;

public class RestrictedRadioButton extends RadioButton {
    private Context mContext;
    private boolean mDisabledByAdmin;
    private EnforcedAdmin mEnforcedAdmin;

    public RestrictedRadioButton(Context context) {
        this(context, null);
    }

    public RestrictedRadioButton(Context context, AttributeSet attrs) {
        this(context, attrs, com.android.internal.R.attr.radioButtonStyle);
    }

    public RestrictedRadioButton(Context context, AttributeSet attrs, int defStyleAttr) {
        this(context, attrs, defStyleAttr, 0);
    }

    public RestrictedRadioButton(Context context, AttributeSet attrs, int defStyleAttr,
            int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        mContext = context;
    }

    @Override
    public boolean performClick() {
        if (mDisabledByAdmin) {
            RestrictedLockUtils.sendShowAdminSupportDetailsIntent(mContext, mEnforcedAdmin);
            return true;
        }
        return super.performClick();
    }

    public void setDisabledByAdmin(EnforcedAdmin admin) {
        final boolean disabled = (admin != null);
        mEnforcedAdmin = admin;
        if (mDisabledByAdmin != disabled) {
            mDisabledByAdmin = disabled;
            RestrictedLockUtils.setTextViewAsDisabledByAdmin(mContext,
                    (TextView) this, mDisabledByAdmin);
            if (mDisabledByAdmin) {
                getButtonDrawable().setColorFilter(mContext.getColor(R.color.disabled_text_color),
                        PorterDuff.Mode.MULTIPLY);
            } else {
                getButtonDrawable().clearColorFilter();
            }
        }
    }

    public boolean isDisabledByAdmin() {
        return mDisabledByAdmin;
    }
}
 No newline at end of file
+34 −41
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.settings.notification;

import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
@@ -29,8 +28,15 @@ import android.widget.RadioGroup;

import com.android.internal.logging.MetricsLogger;
import com.android.settings.R;
import com.android.settings.RestrictedRadioButton;
import com.android.settings.SettingsActivity;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settingslib.RestrictedLockUtils;

import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS;
import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS;

import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;

public class RedactionInterstitial extends SettingsActivity {

@@ -52,10 +58,6 @@ public class RedactionInterstitial extends SettingsActivity {
     * available to be launched.
     */
    public static Intent createStartIntent(Context ctx) {
        if (isSecureNotificationsDisabled(ctx)) {
            // If there is no choices for the user, we should not start the activity.
            return null;
        } else {
        return new Intent(ctx, RedactionInterstitial.class)
                .putExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, true)
                .putExtra(EXTRA_PREFS_SET_BACK_TEXT, (String) null)
@@ -64,28 +66,13 @@ public class RedactionInterstitial extends SettingsActivity {
                .putExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID,
                        R.string.lock_screen_notifications_interstitial_title);
    }
    }

    private static boolean isSecureNotificationsDisabled(Context context) {
        final DevicePolicyManager dpm =
                (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
        return dpm != null && (dpm.getKeyguardDisabledFeatures(null)
                & DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS) != 0;
    }

    private static boolean isUnredactedNotificationsDisabled(Context context) {
        final DevicePolicyManager dpm =
                (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
        return dpm != null && (dpm.getKeyguardDisabledFeatures(null)
                & DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS) != 0;
    }

    public static class RedactionInterstitialFragment extends SettingsPreferenceFragment
            implements RadioGroup.OnCheckedChangeListener {

        private RadioGroup mRadioGroup;
        private RadioButton mShowAllButton;
        private RadioButton mRedactSensitiveButton;
        private RestrictedRadioButton mShowAllButton;
        private RestrictedRadioButton mRedactSensitiveButton;

        @Override
        protected int getMetricsCategory() {
@@ -102,26 +89,32 @@ public class RedactionInterstitial extends SettingsActivity {
        public void onViewCreated(View view, Bundle savedInstanceState) {
            super.onViewCreated(view, savedInstanceState);
            mRadioGroup = (RadioGroup) view.findViewById(R.id.radio_group);
            mShowAllButton = (RadioButton) view.findViewById(R.id.show_all);
            mRedactSensitiveButton = (RadioButton) view.findViewById(R.id.redact_sensitive);
            mShowAllButton = (RestrictedRadioButton) view.findViewById(R.id.show_all);
            mRedactSensitiveButton = (RestrictedRadioButton) view.findViewById(R.id.redact_sensitive);

            mRadioGroup.setOnCheckedChangeListener(this);

            // Disable buttons according to policy.
            if (isSecureNotificationsDisabled(getActivity())) {
                mShowAllButton.setEnabled(false);
                mRedactSensitiveButton.setEnabled(false);
            } else if (isUnredactedNotificationsDisabled(getActivity())) {
                mShowAllButton.setEnabled(false);
            }
        }

        @Override
        public void onResume() {
            super.onResume();
            // Disable buttons according to policy.

            checkNotificationFeaturesAndSetDisabled(mShowAllButton,
                    KEYGUARD_DISABLE_SECURE_NOTIFICATIONS |
                    KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS);
            checkNotificationFeaturesAndSetDisabled(mRedactSensitiveButton,
                    KEYGUARD_DISABLE_SECURE_NOTIFICATIONS);
            loadFromSettings();
        }

        private void checkNotificationFeaturesAndSetDisabled(RestrictedRadioButton button,
                int keyguardNotifications) {
            EnforcedAdmin admin = RestrictedLockUtils.checkIfKeyguardNotificationFeaturesDisabled(
                    getActivity(), keyguardNotifications);
            button.setDisabledByAdmin(admin);
        }

        private void loadFromSettings() {
            final boolean enabled = Settings.Secure.getInt(getContentResolver(),
                        Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0) != 0;
@@ -130,9 +123,9 @@ public class RedactionInterstitial extends SettingsActivity {

            int checkedButtonId = R.id.hide_all;
            if (enabled) {
                if (show && mShowAllButton.isEnabled()) {
                if (show && !mShowAllButton.isDisabledByAdmin()) {
                    checkedButtonId = R.id.show_all;
                } else if (mRedactSensitiveButton.isEnabled()) {
                } else if (!mRedactSensitiveButton.isDisabledByAdmin()) {
                    checkedButtonId = R.id.redact_sensitive;
                }
            }