resolve merge conflicts of d5b3a5d
to nyc-mr1-dev
Change-Id: I1eb01bfdad24935efbbdbeaee0dcf1c374a2cadb
This commit is contained in:
@@ -7532,5 +7532,11 @@
|
|||||||
|
|
||||||
<!-- Button label that redirects user who needs help for signin to help screen [CHAR LIMIT=NONE]-->
|
<!-- Button label that redirects user who needs help for signin to help screen [CHAR LIMIT=NONE]-->
|
||||||
<string name="support_sign_in_required_help">Can\'t access your account?</string>
|
<string name="support_sign_in_required_help">Can\'t access your account?</string>
|
||||||
|
<!-- [CHAR LIMIT=60] Title of work profile setting page -->
|
||||||
|
<string name="managed_profile_settings_title">Work profile settings</string>
|
||||||
|
<!-- [CHAR LIMIT=60] The preference title for enabling cross-profile remote contact search -->
|
||||||
|
<string name="managed_profile_contact_search_title">Contact search</string>
|
||||||
|
<!-- [CHAR LIMIT=NONE] The preference summary for enabling cross-profile remote contact search -->
|
||||||
|
<string name="managed_profile_contact_search_summary">Allow contact searches by your organization to identify callers and contacts</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
33
res/xml/managed_profile_settings.xml
Normal file
33
res/xml/managed_profile_settings.xml
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
|
||||||
|
android:title="@string/managed_profile_settings_title">
|
||||||
|
|
||||||
|
<SwitchPreference
|
||||||
|
android:key="work_mode"
|
||||||
|
android:summary="@string/work_mode_summary"
|
||||||
|
android:title="@string/work_mode_label"/>
|
||||||
|
|
||||||
|
<com.android.settingslib.RestrictedSwitchPreference
|
||||||
|
android:key="contacts_search"
|
||||||
|
android:summary="@string/managed_profile_contact_search_summary"
|
||||||
|
android:title="@string/managed_profile_contact_search_title"
|
||||||
|
settings:useAdditionalSummary="true"
|
||||||
|
/>
|
||||||
|
|
||||||
|
</PreferenceScreen>
|
@@ -138,6 +138,7 @@ public class Settings extends SettingsActivity {
|
|||||||
}
|
}
|
||||||
public static class ScreenLockSuggestionActivity extends ChooseLockGeneric { /* empty */ }
|
public static class ScreenLockSuggestionActivity extends ChooseLockGeneric { /* empty */ }
|
||||||
public static class WallpaperSettingsActivity extends SettingsActivity { /* empty */ }
|
public static class WallpaperSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
|
public static class ManagedProfileSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
|
|
||||||
// Categories.
|
// Categories.
|
||||||
public static class WirelessSettings extends SettingsActivity { /* empty */ }
|
public static class WirelessSettings extends SettingsActivity { /* empty */ }
|
||||||
|
@@ -57,6 +57,7 @@ import com.android.settings.accessibility.AccessibilitySettingsForSetupWizard;
|
|||||||
import com.android.settings.accessibility.CaptionPropertiesFragment;
|
import com.android.settings.accessibility.CaptionPropertiesFragment;
|
||||||
import com.android.settings.accounts.AccountSettings;
|
import com.android.settings.accounts.AccountSettings;
|
||||||
import com.android.settings.accounts.AccountSyncSettings;
|
import com.android.settings.accounts.AccountSyncSettings;
|
||||||
|
import com.android.settings.accounts.ManagedProfileSettings;
|
||||||
import com.android.settings.applications.AdvancedAppSettings;
|
import com.android.settings.applications.AdvancedAppSettings;
|
||||||
import com.android.settings.applications.DrawOverlayDetails;
|
import com.android.settings.applications.DrawOverlayDetails;
|
||||||
import com.android.settings.applications.InstalledAppDetails;
|
import com.android.settings.applications.InstalledAppDetails;
|
||||||
@@ -330,6 +331,7 @@ public class SettingsActivity extends SettingsDrawerActivity
|
|||||||
AdvancedAppSettings.class.getName(),
|
AdvancedAppSettings.class.getName(),
|
||||||
WallpaperTypeSettings.class.getName(),
|
WallpaperTypeSettings.class.getName(),
|
||||||
VrListenerSettings.class.getName(),
|
VrListenerSettings.class.getName(),
|
||||||
|
ManagedProfileSettings.class.getName(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@@ -39,9 +39,7 @@ import android.os.Process;
|
|||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.provider.SearchIndexableResource;
|
import android.provider.SearchIndexableResource;
|
||||||
import android.support.v14.preference.SwitchPreference;
|
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
import android.support.v7.preference.Preference.OnPreferenceChangeListener;
|
|
||||||
import android.support.v7.preference.Preference.OnPreferenceClickListener;
|
import android.support.v7.preference.Preference.OnPreferenceClickListener;
|
||||||
import android.support.v7.preference.PreferenceGroup;
|
import android.support.v7.preference.PreferenceGroup;
|
||||||
import android.support.v7.preference.PreferenceScreen;
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
@@ -55,6 +53,7 @@ import com.android.internal.logging.MetricsProto.MetricsEvent;
|
|||||||
import com.android.settings.AccessiblePreferenceCategory;
|
import com.android.settings.AccessiblePreferenceCategory;
|
||||||
import com.android.settings.DimmableIconPreference;
|
import com.android.settings.DimmableIconPreference;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.SettingsActivity;
|
||||||
import com.android.settings.SettingsPreferenceFragment;
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
@@ -84,7 +83,7 @@ import static android.provider.Settings.EXTRA_AUTHORITIES;
|
|||||||
*/
|
*/
|
||||||
public class AccountSettings extends SettingsPreferenceFragment
|
public class AccountSettings extends SettingsPreferenceFragment
|
||||||
implements AuthenticatorHelper.OnAccountsUpdateListener,
|
implements AuthenticatorHelper.OnAccountsUpdateListener,
|
||||||
OnPreferenceClickListener, OnPreferenceChangeListener, Indexable {
|
OnPreferenceClickListener, Indexable {
|
||||||
public static final String TAG = "AccountSettings";
|
public static final String TAG = "AccountSettings";
|
||||||
|
|
||||||
private static final String KEY_ACCOUNT = "account";
|
private static final String KEY_ACCOUNT = "account";
|
||||||
@@ -116,14 +115,14 @@ public class AccountSettings extends SettingsPreferenceFragment
|
|||||||
* The preference that displays the add account button.
|
* The preference that displays the add account button.
|
||||||
*/
|
*/
|
||||||
public DimmableIconPreference addAccountPreference;
|
public DimmableIconPreference addAccountPreference;
|
||||||
/**
|
|
||||||
* The preference that displays the button to toggle work profile.
|
|
||||||
*/
|
|
||||||
public SwitchPreference workModeSwitch;
|
|
||||||
/**
|
/**
|
||||||
* The preference that displays the button to remove the managed profile
|
* The preference that displays the button to remove the managed profile
|
||||||
*/
|
*/
|
||||||
public Preference removeWorkProfilePreference;
|
public Preference removeWorkProfilePreference;
|
||||||
|
/**
|
||||||
|
* The preference that displays managed profile settings.
|
||||||
|
*/
|
||||||
|
public Preference managedProfilePreference;
|
||||||
/**
|
/**
|
||||||
* The {@link AuthenticatorHelper} that holds accounts data for this profile.
|
* The {@link AuthenticatorHelper} that holds accounts data for this profile.
|
||||||
*/
|
*/
|
||||||
@@ -239,23 +238,12 @@ public class AccountSettings extends SettingsPreferenceFragment
|
|||||||
).show();
|
).show();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
if (preference == profileData.managedProfilePreference) {
|
||||||
return false;
|
Bundle arguments = new Bundle();
|
||||||
}
|
arguments.putParcelable(Intent.EXTRA_USER, profileData.userInfo.getUserHandle());
|
||||||
|
((SettingsActivity) getActivity()).startPreferencePanel(
|
||||||
@Override
|
ManagedProfileSettings.class.getName(), arguments,
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
R.string.managed_profile_settings_title, null, null, 0);
|
||||||
// Check the preference
|
|
||||||
final int count = mProfiles.size();
|
|
||||||
for (int i = 0; i < count; i++) {
|
|
||||||
ProfileData profileData = mProfiles.valueAt(i);
|
|
||||||
if (preference == profileData.workModeSwitch) {
|
|
||||||
final int userId = profileData.userInfo.id;
|
|
||||||
if ((boolean) newValue) {
|
|
||||||
mUm.trySetQuietModeDisabled(userId, null);
|
|
||||||
} else {
|
|
||||||
mUm.setQuietModeEnabled(userId, true);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -314,10 +302,8 @@ public class AccountSettings extends SettingsPreferenceFragment
|
|||||||
profileData.preferenceGroup.setSummary(workGroupSummary);
|
profileData.preferenceGroup.setSummary(workGroupSummary);
|
||||||
((AccessiblePreferenceCategory) profileData.preferenceGroup).setContentDescription(
|
((AccessiblePreferenceCategory) profileData.preferenceGroup).setContentDescription(
|
||||||
getString(R.string.accessibility_category_work, workGroupSummary));
|
getString(R.string.accessibility_category_work, workGroupSummary));
|
||||||
profileData.workModeSwitch = newWorkModeSwitchPreference(context);
|
|
||||||
final UserHandle userHandle = profileData.userInfo.getUserHandle();
|
|
||||||
profileData.workModeSwitch.setChecked(!mUm.isQuietModeEnabled(userHandle));
|
|
||||||
profileData.removeWorkProfilePreference = newRemoveWorkProfilePreference(context);
|
profileData.removeWorkProfilePreference = newRemoveWorkProfilePreference(context);
|
||||||
|
profileData.managedProfilePreference = newManagedProfileSettings();
|
||||||
} else {
|
} else {
|
||||||
profileData.preferenceGroup.setTitle(R.string.category_personal);
|
profileData.preferenceGroup.setTitle(R.string.category_personal);
|
||||||
((AccessiblePreferenceCategory) profileData.preferenceGroup).setContentDescription(
|
((AccessiblePreferenceCategory) profileData.preferenceGroup).setContentDescription(
|
||||||
@@ -351,15 +337,6 @@ public class AccountSettings extends SettingsPreferenceFragment
|
|||||||
return preference;
|
return preference;
|
||||||
}
|
}
|
||||||
|
|
||||||
private SwitchPreference newWorkModeSwitchPreference(Context context) {
|
|
||||||
SwitchPreference preference = new SwitchPreference(getPrefContext());
|
|
||||||
preference.setTitle(R.string.work_mode_label);
|
|
||||||
preference.setSummary(R.string.work_mode_summary);
|
|
||||||
preference.setOnPreferenceChangeListener(this);
|
|
||||||
preference.setOrder(ORDER_NEXT_TO_LAST);
|
|
||||||
return preference;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Preference newRemoveWorkProfilePreference(Context context) {
|
private Preference newRemoveWorkProfilePreference(Context context) {
|
||||||
Preference preference = new Preference(getPrefContext());
|
Preference preference = new Preference(getPrefContext());
|
||||||
preference.setTitle(R.string.remove_managed_profile_label);
|
preference.setTitle(R.string.remove_managed_profile_label);
|
||||||
@@ -369,6 +346,16 @@ public class AccountSettings extends SettingsPreferenceFragment
|
|||||||
return preference;
|
return preference;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Preference newManagedProfileSettings() {
|
||||||
|
Preference preference = new Preference(getPrefContext());
|
||||||
|
preference.setTitle(R.string.managed_profile_settings_title);
|
||||||
|
preference.setIcon(R.drawable.ic_sysbar_quicksettings);
|
||||||
|
preference.setOnPreferenceClickListener(this);
|
||||||
|
preference.setOrder(ORDER_NEXT_TO_LAST);
|
||||||
|
return preference;
|
||||||
|
}
|
||||||
|
|
||||||
private String getWorkGroupSummary(Context context, UserInfo userInfo) {
|
private String getWorkGroupSummary(Context context, UserInfo userInfo) {
|
||||||
PackageManager packageManager = context.getPackageManager();
|
PackageManager packageManager = context.getPackageManager();
|
||||||
ApplicationInfo adminApplicationInfo = Utils.getAdminApplicationInfo(context, userInfo.id);
|
ApplicationInfo adminApplicationInfo = Utils.getAdminApplicationInfo(context, userInfo.id);
|
||||||
@@ -428,12 +415,12 @@ public class AccountSettings extends SettingsPreferenceFragment
|
|||||||
R.string.managed_profile_not_available_label);
|
R.string.managed_profile_not_available_label);
|
||||||
profileData.preferenceGroup.addPreference(mProfileNotAvailablePreference);
|
profileData.preferenceGroup.addPreference(mProfileNotAvailablePreference);
|
||||||
}
|
}
|
||||||
if (profileData.workModeSwitch != null) {
|
|
||||||
profileData.preferenceGroup.addPreference(profileData.workModeSwitch);
|
|
||||||
}
|
|
||||||
if (profileData.removeWorkProfilePreference != null) {
|
if (profileData.removeWorkProfilePreference != null) {
|
||||||
profileData.preferenceGroup.addPreference(profileData.removeWorkProfilePreference);
|
profileData.preferenceGroup.addPreference(profileData.removeWorkProfilePreference);
|
||||||
}
|
}
|
||||||
|
if (profileData.managedProfilePreference != null) {
|
||||||
|
profileData.preferenceGroup.addPreference(profileData.managedProfilePreference);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ArrayList<AccountPreference> getAccountTypePreferences(AuthenticatorHelper helper,
|
private ArrayList<AccountPreference> getAccountTypePreferences(AuthenticatorHelper helper,
|
||||||
@@ -594,18 +581,6 @@ public class AccountSettings extends SettingsPreferenceFragment
|
|||||||
getActivity().invalidateOptionsMenu();
|
getActivity().invalidateOptionsMenu();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action.equals(Intent.ACTION_MANAGED_PROFILE_AVAILABLE)
|
|
||||||
|| action.equals(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE)) {
|
|
||||||
// We assume there's only one managed profile, otherwise this needs to change.
|
|
||||||
ProfileData profileData = mProfiles.valueAt(1);
|
|
||||||
if (intent.getIntExtra(Intent.EXTRA_USER_HANDLE,
|
|
||||||
UserHandle.USER_NULL) == profileData.userInfo.id) {
|
|
||||||
profileData.workModeSwitch.setChecked(
|
|
||||||
!mUm.isQuietModeEnabled(profileData.userInfo.getUserHandle()));
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Log.w(TAG, "Cannot handle received broadcast: " + intent.getAction());
|
Log.w(TAG, "Cannot handle received broadcast: " + intent.getAction());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -614,8 +589,6 @@ public class AccountSettings extends SettingsPreferenceFragment
|
|||||||
IntentFilter intentFilter = new IntentFilter();
|
IntentFilter intentFilter = new IntentFilter();
|
||||||
intentFilter.addAction(Intent.ACTION_MANAGED_PROFILE_REMOVED);
|
intentFilter.addAction(Intent.ACTION_MANAGED_PROFILE_REMOVED);
|
||||||
intentFilter.addAction(Intent.ACTION_MANAGED_PROFILE_ADDED);
|
intentFilter.addAction(Intent.ACTION_MANAGED_PROFILE_ADDED);
|
||||||
intentFilter.addAction(Intent.ACTION_MANAGED_PROFILE_AVAILABLE);
|
|
||||||
intentFilter.addAction(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE);
|
|
||||||
context.registerReceiver(this, intentFilter);
|
context.registerReceiver(this, intentFilter);
|
||||||
listeningToManagedProfileEvents = true;
|
listeningToManagedProfileEvents = true;
|
||||||
}
|
}
|
||||||
@@ -729,18 +702,24 @@ public class AccountSettings extends SettingsPreferenceFragment
|
|||||||
if (!RestrictedLockUtils.hasBaseUserRestriction(context,
|
if (!RestrictedLockUtils.hasBaseUserRestriction(context,
|
||||||
DISALLOW_MODIFY_ACCOUNTS, userInfo.id)) {
|
DISALLOW_MODIFY_ACCOUNTS, userInfo.id)) {
|
||||||
SearchIndexableRaw data = new SearchIndexableRaw(context);
|
SearchIndexableRaw data = new SearchIndexableRaw(context);
|
||||||
data = new SearchIndexableRaw(context);
|
|
||||||
data.title = res.getString(R.string.add_account_label);
|
data.title = res.getString(R.string.add_account_label);
|
||||||
data.screenTitle = screenTitle;
|
data.screenTitle = screenTitle;
|
||||||
result.add(data);
|
result.add(data);
|
||||||
}
|
}
|
||||||
if (userInfo.isManagedProfile()) {
|
if (userInfo.isManagedProfile()) {
|
||||||
|
{
|
||||||
SearchIndexableRaw data = new SearchIndexableRaw(context);
|
SearchIndexableRaw data = new SearchIndexableRaw(context);
|
||||||
data = new SearchIndexableRaw(context);
|
|
||||||
data.title = res.getString(R.string.remove_managed_profile_label);
|
data.title = res.getString(R.string.remove_managed_profile_label);
|
||||||
data.screenTitle = screenTitle;
|
data.screenTitle = screenTitle;
|
||||||
result.add(data);
|
result.add(data);
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
SearchIndexableRaw data = new SearchIndexableRaw(context);
|
||||||
|
data.title = res.getString(R.string.managed_profile_settings_title);
|
||||||
|
data.screenTitle = screenTitle;
|
||||||
|
result.add(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
185
src/com/android/settings/accounts/ManagedProfileSettings.java
Normal file
185
src/com/android/settings/accounts/ManagedProfileSettings.java
Normal file
@@ -0,0 +1,185 @@
|
|||||||
|
/*
|
||||||
|
* 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.accounts;
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.UserHandle;
|
||||||
|
import android.os.UserManager;
|
||||||
|
import android.provider.Settings;
|
||||||
|
import android.support.v14.preference.SwitchPreference;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.android.internal.logging.MetricsProto;
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
|
import com.android.settingslib.RestrictedSwitchPreference;
|
||||||
|
|
||||||
|
import static android.provider.Settings.Secure.MANAGED_PROFILE_CONTACT_REMOTE_SEARCH;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setting page for managed profile.
|
||||||
|
* FIXME: It currently assumes there is only one managed profile.
|
||||||
|
*/
|
||||||
|
public class ManagedProfileSettings extends SettingsPreferenceFragment
|
||||||
|
implements Preference.OnPreferenceChangeListener {
|
||||||
|
|
||||||
|
private SwitchPreference mWorkModePreference;
|
||||||
|
private RestrictedSwitchPreference mContactPrefrence;
|
||||||
|
|
||||||
|
private UserManager mUserManager;
|
||||||
|
private UserHandle mManagedUser;
|
||||||
|
private Context mContext;
|
||||||
|
|
||||||
|
private ManagedProfileBroadcastReceiver mManagedProfileBroadcastReceiver;
|
||||||
|
|
||||||
|
private static final String KEY_WORK_MODE = "work_mode";
|
||||||
|
private static final String KEY_CONTACT = "contacts_search";
|
||||||
|
|
||||||
|
private static final String TAG = "ManagedProfileSettings";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle icicle) {
|
||||||
|
super.onCreate(icicle);
|
||||||
|
addPreferencesFromResource(R.xml.managed_profile_settings);
|
||||||
|
mWorkModePreference = (SwitchPreference) findPreference(KEY_WORK_MODE);
|
||||||
|
mWorkModePreference.setOnPreferenceChangeListener(this);
|
||||||
|
mContactPrefrence = (RestrictedSwitchPreference) findPreference(KEY_CONTACT);
|
||||||
|
mContactPrefrence.setOnPreferenceChangeListener(this);
|
||||||
|
mContext = getActivity().getApplicationContext();
|
||||||
|
mUserManager = (UserManager) getSystemService(Context.USER_SERVICE);
|
||||||
|
mManagedUser = getManagedUserFromArgument();
|
||||||
|
if (mManagedUser == null) {
|
||||||
|
getActivity().finish();
|
||||||
|
}
|
||||||
|
mManagedProfileBroadcastReceiver = new ManagedProfileBroadcastReceiver();
|
||||||
|
mManagedProfileBroadcastReceiver.register(getActivity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
loadDataAndPopulateUi();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
mManagedProfileBroadcastReceiver.unregister(getActivity());
|
||||||
|
}
|
||||||
|
|
||||||
|
private UserHandle getManagedUserFromArgument() {
|
||||||
|
Bundle arguments = getArguments();
|
||||||
|
if (arguments != null) {
|
||||||
|
UserHandle userHandle = arguments.getParcelable(Intent.EXTRA_USER);
|
||||||
|
if (userHandle != null) {
|
||||||
|
if (mUserManager.isManagedProfile(userHandle.getIdentifier())) {
|
||||||
|
return userHandle;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadDataAndPopulateUi() {
|
||||||
|
if (mWorkModePreference != null) {
|
||||||
|
mWorkModePreference.setChecked(
|
||||||
|
!mUserManager.isQuietModeEnabled(mManagedUser));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mContactPrefrence != null) {
|
||||||
|
int value = Settings.Secure.getIntForUser(getContentResolver(),
|
||||||
|
MANAGED_PROFILE_CONTACT_REMOTE_SEARCH, 0, mManagedUser.getIdentifier());
|
||||||
|
mContactPrefrence.setChecked(value != 0);
|
||||||
|
RestrictedLockUtils.EnforcedAdmin enforcedAdmin =
|
||||||
|
RestrictedLockUtils.checkIfRemoteContactSearchDisallowed(
|
||||||
|
mContext, mManagedUser.getIdentifier());
|
||||||
|
mContactPrefrence.setDisabledByAdmin(enforcedAdmin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getMetricsCategory() {
|
||||||
|
return MetricsProto.MetricsEvent.ACCOUNTS_WORK_PROFILE_SETTINGS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
|
if (preference == mWorkModePreference) {
|
||||||
|
if ((boolean) newValue) {
|
||||||
|
mUserManager.trySetQuietModeDisabled(mManagedUser.getIdentifier(), null);
|
||||||
|
} else {
|
||||||
|
mUserManager.setQuietModeEnabled(mManagedUser.getIdentifier(), true);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (preference == mContactPrefrence) {
|
||||||
|
int value = ((boolean) newValue == true) ? 1 : 0;
|
||||||
|
Settings.Secure.putIntForUser(getContentResolver(),
|
||||||
|
MANAGED_PROFILE_CONTACT_REMOTE_SEARCH, value, mManagedUser.getIdentifier());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ManagedProfileBroadcastReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
final String action = intent.getAction();
|
||||||
|
Log.v(TAG, "Received broadcast: " + action);
|
||||||
|
if (action.equals(Intent.ACTION_MANAGED_PROFILE_REMOVED)) {
|
||||||
|
if (intent.getIntExtra(Intent.EXTRA_USER_HANDLE,
|
||||||
|
UserHandle.USER_NULL) == mManagedUser.getIdentifier()) {
|
||||||
|
getActivity().finish();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (action.equals(Intent.ACTION_MANAGED_PROFILE_AVAILABLE)
|
||||||
|
|| action.equals(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE)) {
|
||||||
|
if (intent.getIntExtra(Intent.EXTRA_USER_HANDLE,
|
||||||
|
UserHandle.USER_NULL) == mManagedUser.getIdentifier()) {
|
||||||
|
mWorkModePreference.setChecked(
|
||||||
|
!mUserManager.isQuietModeEnabled(mManagedUser));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Log.w(TAG, "Cannot handle received broadcast: " + intent.getAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void register(Context context) {
|
||||||
|
IntentFilter intentFilter = new IntentFilter();
|
||||||
|
intentFilter.addAction(Intent.ACTION_MANAGED_PROFILE_REMOVED);
|
||||||
|
intentFilter.addAction(Intent.ACTION_MANAGED_PROFILE_AVAILABLE);
|
||||||
|
intentFilter.addAction(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE);
|
||||||
|
context.registerReceiver(this, intentFilter);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unregister(Context context) {
|
||||||
|
context.unregisterReceiver(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user