Default apps setting for managed profile
1. Print settings already support managed profile. Follow the UI of that. ProfileSettingsPreferenceFragment is created to act as the base class for per-profile setting. 2. Only show browser and dialer default setting in managed profile. BUG=26707733 Change-Id: I20d00203e14db58ec03638f692dd83a1bd50c59c
This commit is contained in:
@@ -2713,8 +2713,6 @@
|
||||
</intent-filter>
|
||||
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
||||
android:value="com.android.settings.applications.ManageDefaultApps" />
|
||||
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
|
||||
android:value="true" />
|
||||
</activity>
|
||||
|
||||
<!-- Conditional receivers, only enabled during silenced state, default off-->
|
||||
|
@@ -24,6 +24,7 @@ import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
@@ -31,6 +32,7 @@ import android.util.ArraySet;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.android.settings.AppListPreference;
|
||||
import com.android.settings.Utils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@@ -135,7 +137,8 @@ public class DefaultEmergencyPreference extends AppListPreference {
|
||||
|
||||
public static boolean isAvailable(Context context) {
|
||||
return isCapable(context)
|
||||
&& context.getPackageManager().resolveActivity(QUERY_INTENT, 0) != null;
|
||||
&& context.getPackageManager().resolveActivity(QUERY_INTENT, 0) != null
|
||||
&& !Utils.isManagedProfile(UserManager.get(context)) ;
|
||||
}
|
||||
|
||||
public static boolean isCapable(Context context) {
|
||||
|
@@ -25,6 +25,7 @@ import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
import android.service.notification.NotificationAssistantService;
|
||||
import android.util.AttributeSet;
|
||||
@@ -34,6 +35,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.notification.ManagedServiceSettings;
|
||||
|
||||
public class DefaultNotificationAssistantPreference extends AppListPreference {
|
||||
@@ -108,4 +110,8 @@ public class DefaultNotificationAssistantPreference extends AppListPreference {
|
||||
c.emptyText = R.string.no_notification_listeners;
|
||||
return c;
|
||||
}
|
||||
|
||||
public static boolean isAvailable(Context context) {
|
||||
return !Utils.isManagedProfile(UserManager.get(context));
|
||||
}
|
||||
}
|
||||
|
@@ -17,6 +17,7 @@ package com.android.settings.applications;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.os.UserManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
@@ -24,6 +25,7 @@ import android.util.AttributeSet;
|
||||
import com.android.internal.telephony.SmsApplication;
|
||||
import com.android.internal.telephony.SmsApplication.SmsApplicationData;
|
||||
import com.android.settings.AppListPreference;
|
||||
import com.android.settings.Utils;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
@@ -69,7 +71,7 @@ public class DefaultSmsPreference extends AppListPreference {
|
||||
public static boolean isAvailable(Context context) {
|
||||
TelephonyManager tm =
|
||||
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
return tm.isSmsCapable();
|
||||
return tm.isSmsCapable() && !Utils.isManagedProfile(UserManager.get(context));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -18,9 +18,11 @@ package com.android.settings.applications;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
import android.support.v7.preference.Preference;
|
||||
@@ -28,6 +30,7 @@ import android.support.v7.preference.Preference;
|
||||
import com.android.internal.logging.MetricsLogger;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.voice.VoiceInputListPreference;
|
||||
|
||||
/**
|
||||
@@ -175,4 +178,8 @@ public class ManageAssist extends SettingsPreferenceFragment
|
||||
mDefaultAssitPref.setValue(assistPackage);
|
||||
updateUi();
|
||||
}
|
||||
|
||||
public static boolean isAvailable(Context context) {
|
||||
return !Utils.isManagedProfile(UserManager.get(context));
|
||||
}
|
||||
}
|
||||
|
@@ -26,6 +26,7 @@ import android.os.Handler;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.provider.Settings;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
@@ -33,29 +34,32 @@ import android.util.Log;
|
||||
import com.android.internal.content.PackageMonitor;
|
||||
import com.android.internal.logging.MetricsLogger;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Index;
|
||||
import com.android.settings.search.Indexable;
|
||||
import com.android.settings.utils.ProfileSettingsPreferenceFragment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class ManageDefaultApps extends SettingsPreferenceFragment
|
||||
public class ManageDefaultApps extends ProfileSettingsPreferenceFragment
|
||||
implements Preference.OnPreferenceClickListener, Indexable {
|
||||
|
||||
private static final String TAG = ManageDefaultApps.class.getSimpleName();
|
||||
|
||||
private static final String KEY_ASSIST_AND_VOICE_INPUT = "assist_and_voice_input";
|
||||
private static final String KEY_DEFAULT_BROWSER = "default_browser";
|
||||
private static final String KEY_DEFAULT_PHONE_APP = "default_phone_app";
|
||||
private static final String KEY_DEFAULT_EMERGENCY_APP = "default_emergency_app";
|
||||
private static final String KEY_SMS_APPLICATION = "default_sms_app";
|
||||
private static final String KEY_DEFAULT_NOTIFICATION_ASST = "default_notification_asst_app";
|
||||
|
||||
private DefaultBrowserPreference mDefaultBrowserPreference;
|
||||
private PackageManager mPm;
|
||||
private int myUserId;
|
||||
|
||||
|
||||
private static final long DELAY_UPDATE_BROWSER_MILLIS = 500;
|
||||
|
||||
private final Handler mHandler = new Handler();
|
||||
@@ -130,6 +134,7 @@ public class ManageDefaultApps extends SettingsPreferenceFragment
|
||||
mPm = getPackageManager();
|
||||
myUserId = UserHandle.myUserId();
|
||||
|
||||
|
||||
mDefaultBrowserPreference = (DefaultBrowserPreference) findPreference(KEY_DEFAULT_BROWSER);
|
||||
mDefaultBrowserPreference.setOnPreferenceChangeListener(
|
||||
new Preference.OnPreferenceChangeListener() {
|
||||
@@ -151,7 +156,7 @@ public class ManageDefaultApps extends SettingsPreferenceFragment
|
||||
}
|
||||
return result;
|
||||
}
|
||||
});
|
||||
});
|
||||
final boolean isRestrictedUser = UserManager.get(getActivity())
|
||||
.getUserInfo(myUserId).isRestricted();
|
||||
|
||||
@@ -169,6 +174,14 @@ public class ManageDefaultApps extends SettingsPreferenceFragment
|
||||
removePreference(KEY_DEFAULT_EMERGENCY_APP);
|
||||
}
|
||||
|
||||
if (!ManageAssist.isAvailable(getActivity())) {
|
||||
removePreference(KEY_ASSIST_AND_VOICE_INPUT);
|
||||
}
|
||||
|
||||
if (!DefaultNotificationAssistantPreference.isAvailable(getActivity())) {
|
||||
removePreference(KEY_DEFAULT_NOTIFICATION_ASST);
|
||||
}
|
||||
|
||||
if (DefaultEmergencyPreference.isCapable(getActivity())) {
|
||||
Index.getInstance(getActivity()).updateFromClassNameResource(
|
||||
ManageDefaultApps.class.getName(), true, true);
|
||||
@@ -200,31 +213,36 @@ public class ManageDefaultApps extends SettingsPreferenceFragment
|
||||
}
|
||||
|
||||
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(
|
||||
Context context, boolean enabled) {
|
||||
SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = R.xml.default_apps;
|
||||
return Arrays.asList(sir);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
final ArrayList<String> result = new ArrayList<String>();
|
||||
|
||||
// Remove SMS Application if the device does not support SMS
|
||||
final boolean isRestrictedUser = UserManager.get(context)
|
||||
.getUserInfo(UserHandle.myUserId()).isRestricted();
|
||||
if (!DefaultSmsPreference.isAvailable(context) || isRestrictedUser) {
|
||||
result.add(KEY_SMS_APPLICATION);
|
||||
new BaseSearchIndexProvider() {
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(
|
||||
Context context, boolean enabled) {
|
||||
SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = R.xml.default_apps;
|
||||
return Arrays.asList(sir);
|
||||
}
|
||||
|
||||
if (!DefaultEmergencyPreference.isAvailable(context)) {
|
||||
result.add(KEY_DEFAULT_EMERGENCY_APP);
|
||||
}
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
final ArrayList<String> result = new ArrayList<String>();
|
||||
|
||||
// Remove SMS Application if the device does not support SMS
|
||||
final boolean isRestrictedUser = UserManager.get(context)
|
||||
.getUserInfo(UserHandle.myUserId()).isRestricted();
|
||||
if (!DefaultSmsPreference.isAvailable(context) || isRestrictedUser) {
|
||||
result.add(KEY_SMS_APPLICATION);
|
||||
}
|
||||
|
||||
if (!DefaultEmergencyPreference.isAvailable(context)) {
|
||||
result.add(KEY_DEFAULT_EMERGENCY_APP);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
protected String getIntentActionString() {
|
||||
return Settings.ACTION_MANAGE_DEFAULT_APPS_SETTINGS;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@@ -33,8 +33,6 @@ import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.print.PrintJob;
|
||||
import android.print.PrintJobId;
|
||||
import android.print.PrintJobInfo;
|
||||
@@ -52,22 +50,18 @@ import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemSelectedListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.internal.content.PackageMonitor;
|
||||
import com.android.internal.logging.MetricsLogger;
|
||||
import com.android.settings.DialogCreatable;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.utils.ProfileSettingsPreferenceFragment;
|
||||
import com.android.settings.dashboard.SummaryLoader;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Indexable;
|
||||
import com.android.settings.search.SearchIndexableRaw;
|
||||
import com.android.settingslib.drawer.UserAdapter;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.util.ArrayList;
|
||||
@@ -76,8 +70,8 @@ import java.util.List;
|
||||
/**
|
||||
* Fragment with the top level print settings.
|
||||
*/
|
||||
public class PrintSettingsFragment extends SettingsPreferenceFragment
|
||||
implements DialogCreatable, Indexable, OnItemSelectedListener, OnClickListener {
|
||||
public class PrintSettingsFragment extends ProfileSettingsPreferenceFragment
|
||||
implements DialogCreatable, Indexable, OnClickListener {
|
||||
public static final String TAG = "PrintSettingsFragment";
|
||||
private static final int LOADER_ID_PRINT_JOBS_LOADER = 1;
|
||||
|
||||
@@ -122,8 +116,6 @@ public class PrintSettingsFragment extends SettingsPreferenceFragment
|
||||
private PreferenceCategory mPrintServicesCategory;
|
||||
|
||||
private PrintJobsController mPrintJobsController;
|
||||
private UserAdapter mProfileSpinnerAdapter;
|
||||
private Spinner mSpinner;
|
||||
private Button mAddNewServiceButton;
|
||||
|
||||
@Override
|
||||
@@ -188,14 +180,11 @@ public class PrintSettingsFragment extends SettingsPreferenceFragment
|
||||
|
||||
contentRoot.addView(emptyView);
|
||||
setEmptyView(emptyView);
|
||||
}
|
||||
|
||||
final UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
|
||||
mProfileSpinnerAdapter = UserAdapter.createUserSpinnerAdapter(um, getActivity());
|
||||
if (mProfileSpinnerAdapter != null) {
|
||||
mSpinner = (Spinner) setPinnedHeaderView(R.layout.spinner_view);
|
||||
mSpinner.setAdapter(mProfileSpinnerAdapter);
|
||||
mSpinner.setOnItemSelectedListener(this);
|
||||
}
|
||||
@Override
|
||||
protected String getIntentActionString() {
|
||||
return Settings.ACTION_PRINT_SETTINGS;
|
||||
}
|
||||
|
||||
private void updateServicesPreferences() {
|
||||
@@ -326,24 +315,6 @@ public class PrintSettingsFragment extends SettingsPreferenceFragment
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
UserHandle selectedUser = mProfileSpinnerAdapter.getUserHandle(position);
|
||||
if (selectedUser.getIdentifier() != UserHandle.myUserId()) {
|
||||
Intent intent = new Intent(Settings.ACTION_PRINT_SETTINGS);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
getActivity().startActivityAsUser(intent, selectedUser);
|
||||
// Go back to default selection, which is the first one
|
||||
mSpinner.setSelection(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mAddNewServiceButton == v) {
|
||||
|
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source 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.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.Spinner;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settingslib.drawer.UserAdapter;
|
||||
|
||||
/**
|
||||
* Base fragment class for per profile settings.
|
||||
*/
|
||||
public abstract class ProfileSettingsPreferenceFragment extends SettingsPreferenceFragment {
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
final UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
|
||||
final UserAdapter profileSpinnerAdapter =
|
||||
UserAdapter.createUserSpinnerAdapter(um, getActivity());
|
||||
if (profileSpinnerAdapter != null) {
|
||||
final Spinner spinner = (Spinner) setPinnedHeaderView(R.layout.spinner_view);
|
||||
spinner.setAdapter(profileSpinnerAdapter);
|
||||
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position,
|
||||
long id) {
|
||||
UserHandle selectedUser = profileSpinnerAdapter.getUserHandle(position);
|
||||
if (selectedUser.getIdentifier() != UserHandle.myUserId()) {
|
||||
Intent intent = new Intent(getIntentActionString());
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
getActivity().startActivityAsUser(intent, selectedUser);
|
||||
// Go back to default selection, which is the first one
|
||||
spinner.setSelection(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
// Nothing to do
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return intent action string that will bring user to this fragment.
|
||||
*/
|
||||
protected abstract String getIntentActionString();
|
||||
|
||||
}
|
Reference in New Issue
Block a user