WriteSystemSettingsPreferenceController.java revision c69f73f4d156fad10b5a30731e46b08e7ae0114d
1/*
2 * Copyright (C) 2017 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.applications.appinfo;
18
19import static android.Manifest.permission.WRITE_SETTINGS;
20
21import android.content.Context;
22import android.content.pm.PackageInfo;
23import android.os.UserManager;
24import android.support.v7.preference.Preference;
25
26import com.android.settings.SettingsPreferenceFragment;
27
28public class WriteSystemSettingsPreferenceController extends AppInfoPreferenceControllerBase {
29
30    private static final String KEY = "write_settings_apps";
31
32    public WriteSystemSettingsPreferenceController(Context context,
33            AppInfoDashboardFragment parent) {
34        super(context, parent, KEY);
35    }
36
37    @Override
38    public int getAvailabilityStatus() {
39        if (UserManager.get(mContext).isManagedProfile()) {
40            return DISABLED_FOR_USER;
41        }
42        final PackageInfo packageInfo = mParent.getPackageInfo();
43        if (packageInfo == null || packageInfo.requestedPermissions == null) {
44            return DISABLED_FOR_USER;
45        }
46        for (int i = 0; i < packageInfo.requestedPermissions.length; i++) {
47            if (packageInfo.requestedPermissions[i].equals(WRITE_SETTINGS)) {
48                return AVAILABLE;
49            }
50        }
51        return DISABLED_FOR_USER;
52    }
53
54    @Override
55    public void updateState(Preference preference) {
56        preference.setSummary(getSummary());
57    }
58
59    @Override
60    protected Class<? extends SettingsPreferenceFragment> getDetailFragmentClass() {
61        return WriteSettingsDetails.class;
62    }
63
64    @Override
65    public String getSummary() {
66        return WriteSettingsDetails.getSummary(mContext, mParent.getAppEntry()).toString();
67
68    }
69}
70