blob: b39f56192e9134ce95c9f04f0bd87f480ca8d792 [file] [log] [blame]
Amith Yamasani43c69782010-12-01 09:04:36 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.settings.accounts;
18
Fan Zhangfc292472017-10-30 13:19:34 -070019import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
20
Amith Yamasani43c69782010-12-01 09:04:36 -080021import android.content.Context;
22import android.graphics.drawable.Drawable;
Amith Yamasani43c69782010-12-01 09:04:36 -080023
Philip P. Moltmanne3f72112018-08-28 15:01:43 -070024import com.android.settingslib.RestrictedLockUtilsInternal;
Sudheer Shanka9c324682016-01-18 11:17:23 +000025import com.android.settingslib.RestrictedPreference;
26
Amith Yamasani43c69782010-12-01 09:04:36 -080027/**
28 * ProviderPreference is used to display an image to the left of a provider name.
29 * The preference ultimately calls AccountManager.addAccount() for the account type.
30 */
Sudheer Shanka9c324682016-01-18 11:17:23 +000031public class ProviderPreference extends RestrictedPreference {
Amith Yamasani43c69782010-12-01 09:04:36 -080032 private String mAccountType;
33
34 public ProviderPreference(
35 Context context, String accountType, Drawable icon, CharSequence providerName) {
36 super(context);
Fan Zhange0d21402018-04-06 16:31:31 -070037 setIconSize(ICON_SIZE_MEDIUM);
Amith Yamasani43c69782010-12-01 09:04:36 -080038 mAccountType = accountType;
39 setIcon(icon);
40 setPersistent(false);
41 setTitle(providerName);
Sudheer Shankaba1a68b2016-01-25 22:39:34 +000042 useAdminDisabledSummary(true);
Amith Yamasani43c69782010-12-01 09:04:36 -080043 }
44
45 public String getAccountType() {
46 return mAccountType;
47 }
Sudheer Shanka9c324682016-01-18 11:17:23 +000048
Sudheer Shankaf755baf2016-01-29 22:12:30 +000049 public void checkAccountManagementAndSetDisabled(int userId) {
Philip P. Moltmanne3f72112018-08-28 15:01:43 -070050 EnforcedAdmin admin = RestrictedLockUtilsInternal.checkIfAccountManagementDisabled(
Sudheer Shankaf755baf2016-01-29 22:12:30 +000051 getContext(), getAccountType(), userId);
Sudheer Shanka9c324682016-01-18 11:17:23 +000052 setDisabledByAdmin(admin);
53 }
Amith Yamasani43c69782010-12-01 09:04:36 -080054}