1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 * except in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the 10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 11 * KIND, either express or implied. See the License for the specific language governing 12 * permissions and limitations under the License. 13 */ 14 package com.android.settings.display; 15 16 import android.content.Context; 17 import android.os.UserHandle; 18 import android.support.v7.preference.Preference; 19 20 import com.android.settings.core.PreferenceController; 21 import com.android.settingslib.RestrictedLockUtils; 22 import com.android.settingslib.RestrictedPreference; 23 24 import static android.os.UserManager.DISALLOW_SET_WALLPAPER; 25 26 public class WallpaperPreferenceController extends PreferenceController { 27 28 private static final String KEY_WALLPAPER = "wallpaper"; 29 30 public WallpaperPreferenceController(Context context) { 31 super(context); 32 } 33 34 @Override 35 public boolean isAvailable() { 36 return true; 37 } 38 39 @Override 40 public String getPreferenceKey() { 41 return KEY_WALLPAPER; 42 } 43 44 @Override 45 public void updateState(Preference preference) { 46 disablePreferenceIfManaged((RestrictedPreference) preference); 47 } 48 49 private void disablePreferenceIfManaged(RestrictedPreference pref) { 50 final String restriction = DISALLOW_SET_WALLPAPER; 51 if (pref != null) { 52 pref.setDisabledByAdmin(null); 53 if (RestrictedLockUtils.hasBaseUserRestriction(mContext, 54 restriction, UserHandle.myUserId())) { 55 pref.setEnabled(false); 56 } else { 57 pref.checkRestrictionAndSetDisabled(restriction); 58 } 59 } 60 } 61 } 62