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

Commit b99e3fec authored by Jorge Ruesga's avatar Jorge Ruesga Committed by Gerrit Code Review
Browse files

profiles: respect lockscreen policies



Don't allow to change lockscreen mode if there is a device administrador that avoid it

Change-Id: I2485f96fba41c60248260ee03ffa0614e94195b4
Signed-off-by: default avatarJorge Ruesga <jorge@ruesga.com>
parent c384f713
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -115,6 +115,7 @@
    <!-- Profiles - system settings -->
    <string name="profile_system_settings_title">System settings</string>
    <string name="profile_lockmode_title">Lock screen mode</string>
    <string name="profile_lockmode_policy_disabled_summary">This profile option is disabled by a device administrator policy</string>
    <string name="profile_lockmode_insecure_summary">Don\'t ask for PIN or password</string>
    <string name="profile_lockmode_disabled_summary">Disable lock screen</string>
    <string name="profile_airplanemode_title">Airplane mode</string>
+11 −1
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.app.ProfileGroup;
import android.app.ProfileManager;
import android.app.RingModeSettings;
import android.app.StreamSettings;
import android.app.admin.DevicePolicyManager;
import android.bluetooth.BluetoothAdapter;
import android.content.ContentResolver;
import android.content.Context;
@@ -65,6 +66,7 @@ import android.widget.EditText;
import android.widget.ListView;
import android.widget.SeekBar;
import android.widget.TextView;

import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.SubSettings;
@@ -75,6 +77,7 @@ import com.android.settings.profiles.actions.item.AirplaneModeItem;
import com.android.settings.profiles.actions.item.AppGroupItem;
import com.android.settings.profiles.actions.item.BrightnessItem;
import com.android.settings.profiles.actions.item.ConnectionOverrideItem;
import com.android.settings.profiles.actions.item.DisabledItem;
import com.android.settings.profiles.actions.item.DozeModeItem;
import com.android.settings.profiles.actions.item.Header;
import com.android.settings.profiles.actions.item.Item;
@@ -217,7 +220,14 @@ public class SetupActionsFragment extends SettingsPreferenceFragment
        mItems.add(new Header(getString(R.string.profile_system_settings_title)));
        mItems.add(new RingModeItem(mProfile.getRingMode()));
        mItems.add(new AirplaneModeItem(mProfile.getAirplaneMode()));
        DevicePolicyManager dpm = (DevicePolicyManager) getSystemService(
                Context.DEVICE_POLICY_SERVICE);
        if (!dpm.requireSecureKeyguard()) {
            mItems.add(new LockModeItem(mProfile));
        } else {
            mItems.add(new DisabledItem(R.string.profile_lockmode_title,
                    R.string.profile_lockmode_policy_disabled_summary));
        }
        mItems.add(new BrightnessItem(mProfile.getBrightness()));

        final Activity activity = getActivity();
+1 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ public class ItemListAdapter extends ArrayAdapter<Item> {

    public enum RowType {
        HEADER_ITEM,
        DISABLED_ITEM,
        CONNECTION_ITEM,
        VOLUME_STREAM_ITEM,
        NAME_ITEM,
+67 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The CyanogenMod 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.profiles.actions.item;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.android.settings.R;
import com.android.settings.profiles.actions.ItemListAdapter;

public class DisabledItem implements Item {

    private final int mResTitle;
    private final int mResSummary;

    public DisabledItem(int resTitle, int resSummary) {
       mResTitle = resTitle;
       mResSummary = resSummary;
    }

    @Override
    public ItemListAdapter.RowType getRowType() {
        return ItemListAdapter.RowType.DISABLED_ITEM;
    }

    @Override
    public boolean isEnabled() {
        return false;
    }

    @Override
    public View getView(LayoutInflater inflater, View convertView, ViewGroup parent) {
        View view;
        if (convertView == null) {
            view = inflater.inflate(R.layout.list_two_line_item, parent, false);
            // Do some initialization
        } else {
            view = convertView;
        }

        TextView text = (TextView) view.findViewById(R.id.title);
        text.setText(mResTitle);
        text.setEnabled(false);

        TextView desc = (TextView) view.findViewById(R.id.summary);
        desc.setText(mResSummary);
        desc.setEnabled(false);

        return view;
    }

}