blob: 23627cdb0fae589b83fdb8ed8171097483675a61 [file] [log] [blame]
Bartosz Fabianowski482908f2017-01-19 17:20:03 +01001/*
2 * Copyright (C) 2017 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 */
14package com.android.settings.enterprise;
15
16import android.content.Context;
17import android.content.Intent;
18import android.net.Uri;
19import android.provider.ContactsContract;
20import android.provider.MediaStore;
21import android.support.v7.preference.Preference;
22
23import com.android.settings.R;
24import com.android.settings.applications.ApplicationFeatureProvider;
25import com.android.settings.core.PreferenceController;
26import com.android.settings.overlay.FeatureFactory;
27
28public class EnterpriseSetDefaultAppsPreferenceController extends PreferenceController {
29
30 private static final String KEY_DEFAULT_APPS = "number_enterprise_set_default_apps";
31 private final ApplicationFeatureProvider mFeatureProvider;
32
33 public EnterpriseSetDefaultAppsPreferenceController(Context context) {
34 super(context);
35 mFeatureProvider = FeatureFactory.getFactory(context)
36 .getApplicationFeatureProvider(context);
37 }
38
39 @Override
40 public void updateState(Preference preference) {
41 // Browser
42 int num = mFeatureProvider.findPersistentPreferredActivities(new Intent[] {
43 buildIntent(Intent.ACTION_VIEW, Intent.CATEGORY_BROWSABLE, "http:", null)}).size();
44 // Camera
45 num += mFeatureProvider.findPersistentPreferredActivities(new Intent[] {
46 new Intent(MediaStore.ACTION_IMAGE_CAPTURE),
47 new Intent(MediaStore.ACTION_VIDEO_CAPTURE)}).size();
48 // Map
49 num += mFeatureProvider.findPersistentPreferredActivities(new Intent[] {
50 buildIntent(Intent.ACTION_VIEW, null, "geo:", null)}).size();
51 // E-mail
52 num += mFeatureProvider.findPersistentPreferredActivities(new Intent[] {
53 new Intent(Intent.ACTION_SENDTO), new Intent(Intent.ACTION_SEND),
54 new Intent(Intent.ACTION_SEND_MULTIPLE)}).size();
55 // Calendar
56 num += mFeatureProvider.findPersistentPreferredActivities(new Intent[] {
57 buildIntent(Intent.ACTION_INSERT, null, null, "vnd.android.cursor.dir/event")})
58 .size();
59 // Contacts
60 num += mFeatureProvider.findPersistentPreferredActivities(new Intent[] {
61 buildIntent(Intent.ACTION_PICK, null, null,
62 ContactsContract.Contacts.CONTENT_TYPE)}).size();
63 // Dialer
64 num += mFeatureProvider.findPersistentPreferredActivities(new Intent[] {
65 new Intent(Intent.ACTION_DIAL), new Intent(Intent.ACTION_CALL)}).size();
66
67 if (num == 0) {
68 preference.setVisible(false);
69 } else {
70 preference.setVisible(true);
71 preference.setTitle(mContext.getResources().getQuantityString(
72 R.plurals.enterprise_privacy_number_enterprise_set_default_apps,
73 num, num));
74 }
75 }
76
77 @Override
78 public boolean isAvailable() {
79 return true;
80 }
81
82 @Override
83 public String getPreferenceKey() {
84 return KEY_DEFAULT_APPS;
85 }
86
87 private static Intent buildIntent(String action, String category, String protocol,
88 String type) {
89 final Intent intent = new Intent(action);
90 if (category != null) {
91 intent.addCategory(category);
92 }
93 if (protocol != null) {
94 intent.setData(Uri.parse(protocol));
95 }
96 if (type != null) {
97 intent.setType(type);
98 }
99 return intent;
100 }
101}