Merge "Update pref fragment for "see all" in app & notification" into pi-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index dbe231b..feb1b05 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -2955,7 +2955,7 @@
android:value="com.android.settings.applications.appinfo.ExternalSourcesDetails" />
</activity>
- <activity android:name="ShowAdminSupportDetailsDialog"
+ <activity android:name=".enterprise.ActionDisabledByAdminDialog"
android:theme="@style/Transparent"
android:excludeFromRecents="true"
android:launchMode="singleTop">
diff --git a/res/layout/admin_support_details_content.xml b/res/layout/admin_support_details_content.xml
deleted file mode 100644
index 7c756c4..0000000
--- a/res/layout/admin_support_details_content.xml
+++ /dev/null
@@ -1,34 +0,0 @@
-<?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.
--->
-<merge xmlns:android="http://schemas.android.com/apk/res/android">
- <TextView android:id="@+id/admin_support_msg"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:textAppearance="@android:style/TextAppearance.Material.Subhead"
- android:text="@string/default_admin_support_msg"
- android:maxLength="200"
- android:autoLink="email|phone|web"
- android:textColor="?android:attr/textColorSecondary" />
- <TextView android:id="@+id/admins_policies_list"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:paddingTop="@dimen/admin_details_dialog_link_padding_top"
- android:text="@string/admin_support_more_info"
- android:textAppearance="@android:style/TextAppearance.Material.Subhead"
- android:textColor="?android:attr/colorAccent"
- android:clickable="true"
- android:background="?android:attr/selectableItemBackground" />
-</merge>
\ No newline at end of file
diff --git a/res/layout/admin_support_details_dialog.xml b/res/layout/admin_support_details_dialog.xml
index c83add3..7de91d0 100644
--- a/res/layout/admin_support_details_dialog.xml
+++ b/res/layout/admin_support_details_dialog.xml
@@ -23,7 +23,7 @@
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
- android:paddingBottom="@dimen/admin_details_dialog_padding">
+ android:paddingBottom="@dimen/admin_details_dialog_title_bottom_padding">
<ImageView android:id="@+id/admin_support_icon"
android:layout_width="@dimen/admin_details_dialog_icon_size"
android:layout_height="@dimen/admin_details_dialog_icon_size"
@@ -46,7 +46,14 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
- <include layout="@layout/admin_support_details_content" />
+ <TextView android:id="@+id/admin_support_msg"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textAppearance="@android:style/TextAppearance.Material.Subhead"
+ android:text="@string/default_admin_support_msg"
+ android:maxLength="200"
+ android:autoLink="email|phone|web"
+ android:textColor="?android:attr/textColorSecondary"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
diff --git a/res/layout/admin_support_details_empty_view.xml b/res/layout/admin_support_details_empty_view.xml
deleted file mode 100644
index bbbbbbc..0000000
--- a/res/layout/admin_support_details_empty_view.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-<?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.
--->
-<!-- Layout used for displaying admin support details in empty preference fragments. -->
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/admin_support_details"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:padding="@*android:dimen/preference_fragment_padding_side"
- android:gravity="center_vertical"
- android:orientation="vertical"
- android:visibility="gone">
- <include layout="@layout/admin_support_details_content" />
-</LinearLayout>
\ No newline at end of file
diff --git a/res/layout/preference_list_fragment.xml b/res/layout/preference_list_fragment.xml
index b84aa38..eeea9c4 100644
--- a/res/layout/preference_list_fragment.xml
+++ b/res/layout/preference_list_fragment.xml
@@ -62,8 +62,6 @@
android:gravity="center_vertical"
android:visibility="gone" />
- <include layout="@layout/admin_support_details_empty_view" />
-
<RelativeLayout android:id="@+id/button_bar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index c684dc6..9fddbcd 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -239,8 +239,12 @@
<!-- Admin support contact details dialog. -->
<dimen name="admin_details_dialog_padding">24dp</dimen>
+ <dimen name="admin_details_dialog_title_bottom_padding">20dp</dimen>
<dimen name="admin_details_dialog_icon_size">48dp</dimen>
<dimen name="admin_details_dialog_link_padding_top">36dp</dimen>
+ <dimen name="admin_details_dialog_learn_more_button_top_margin">24dp</dimen>
+ <dimen name="admin_details_dialog_learn_more_button_padding">8dp</dimen>
+ <dimen name="admin_details_dialog_learn_more_button_minWidth">88dp</dimen>
<!-- Button bar padding for unmount button. -->
<dimen name="unmount_button_padding">8dp</dimen>
diff --git a/src/com/android/settings/MasterClear.java b/src/com/android/settings/MasterClear.java
index 9ad32e2..46e0d41 100644
--- a/src/com/android/settings/MasterClear.java
+++ b/src/com/android/settings/MasterClear.java
@@ -57,6 +57,7 @@
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.core.InstrumentedFragment;
import com.android.settings.core.SubSettingLauncher;
+import com.android.settings.enterprise.ActionDisabledByAdminDialogHelper;
import com.android.settings.password.ChooseLockSettingsHelper;
import com.android.settings.password.ConfirmLockPattern;
import com.android.settingslib.RestrictedLockUtils;
@@ -503,10 +504,11 @@
if (disallow && !Utils.isDemoUser(context)) {
return inflater.inflate(R.layout.master_clear_disallowed_screen, null);
} else if (admin != null) {
- View view = inflater.inflate(R.layout.admin_support_details_empty_view, null);
- ShowAdminSupportDetailsDialog.setAdminSupportDetails(getActivity(), view, admin, false);
- view.setVisibility(View.VISIBLE);
- return view;
+ new ActionDisabledByAdminDialogHelper(getActivity())
+ .prepareDialogBuilder(UserManager.DISALLOW_FACTORY_RESET, admin)
+ .setOnDismissListener(__ -> getActivity().finish())
+ .show();
+ return new View(getContext());
}
mContentView = inflater.inflate(R.layout.master_clear, null);
diff --git a/src/com/android/settings/MasterClearConfirm.java b/src/com/android/settings/MasterClearConfirm.java
index 59736fd..a92c8f8 100644
--- a/src/com/android/settings/MasterClearConfirm.java
+++ b/src/com/android/settings/MasterClearConfirm.java
@@ -34,6 +34,7 @@
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.core.InstrumentedFragment;
+import com.android.settings.enterprise.ActionDisabledByAdminDialogHelper;
import com.android.settingslib.RestrictedLockUtils;
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
@@ -151,10 +152,11 @@
UserManager.DISALLOW_FACTORY_RESET, UserHandle.myUserId())) {
return inflater.inflate(R.layout.master_clear_disallowed_screen, null);
} else if (admin != null) {
- View view = inflater.inflate(R.layout.admin_support_details_empty_view, null);
- ShowAdminSupportDetailsDialog.setAdminSupportDetails(getActivity(), view, admin, false);
- view.setVisibility(View.VISIBLE);
- return view;
+ new ActionDisabledByAdminDialogHelper(getActivity())
+ .prepareDialogBuilder(UserManager.DISALLOW_FACTORY_RESET, admin)
+ .setOnDismissListener(__ -> getActivity().finish())
+ .show();
+ return new View(getActivity());
}
mContentView = inflater.inflate(R.layout.master_clear_confirm, null);
establishFinalConfirmationState();
@@ -167,9 +169,9 @@
TextView confirmationMessage =
(TextView) mContentView.findViewById(R.id.master_clear_confirm);
if (confirmationMessage != null) {
- String accessibileText = new StringBuilder(currentTitle).append(",").append(
+ String accessibleText = new StringBuilder(currentTitle).append(",").append(
confirmationMessage.getText()).toString();
- getActivity().setTitle(Utils.createAccessibleSequence(currentTitle, accessibileText));
+ getActivity().setTitle(Utils.createAccessibleSequence(currentTitle, accessibleText));
}
}
diff --git a/src/com/android/settings/ResetNetwork.java b/src/com/android/settings/ResetNetwork.java
index 8043750..591ce0a 100644
--- a/src/com/android/settings/ResetNetwork.java
+++ b/src/com/android/settings/ResetNetwork.java
@@ -45,6 +45,7 @@
import com.android.internal.telephony.PhoneConstants;
import com.android.settings.core.InstrumentedFragment;
import com.android.settings.core.SubSettingLauncher;
+import com.android.settings.enterprise.ActionDisabledByAdminDialogHelper;
import com.android.settings.password.ChooseLockSettingsHelper;
import com.android.settings.password.ConfirmLockPattern;
import com.android.settingslib.RestrictedLockUtils;
@@ -245,10 +246,11 @@
UserManager.DISALLOW_NETWORK_RESET, UserHandle.myUserId())) {
return inflater.inflate(R.layout.network_reset_disallowed_screen, null);
} else if (admin != null) {
- View view = inflater.inflate(R.layout.admin_support_details_empty_view, null);
- ShowAdminSupportDetailsDialog.setAdminSupportDetails(getActivity(), view, admin, false);
- view.setVisibility(View.VISIBLE);
- return view;
+ new ActionDisabledByAdminDialogHelper(getActivity())
+ .prepareDialogBuilder(UserManager.DISALLOW_NETWORK_RESET, admin)
+ .setOnDismissListener(__ -> getActivity().finish())
+ .show();
+ return new View(getContext());
}
mContentView = inflater.inflate(R.layout.reset_network, null);
diff --git a/src/com/android/settings/ResetNetworkConfirm.java b/src/com/android/settings/ResetNetworkConfirm.java
index edded11..d735c06 100644
--- a/src/com/android/settings/ResetNetworkConfirm.java
+++ b/src/com/android/settings/ResetNetworkConfirm.java
@@ -27,7 +27,6 @@
import android.net.wifi.WifiManager;
import android.os.AsyncTask;
import android.os.Bundle;
-import android.os.RecoverySystem;
import android.os.UserHandle;
import android.os.UserManager;
import android.support.annotation.VisibleForTesting;
@@ -42,6 +41,7 @@
import com.android.ims.ImsManager;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.telephony.PhoneConstants;
+import com.android.settings.enterprise.ActionDisabledByAdminDialogHelper;
import com.android.settings.wrapper.RecoverySystemWrapper;
import com.android.settings.core.InstrumentedFragment;
import com.android.settingslib.RestrictedLockUtils;
@@ -197,10 +197,11 @@
UserManager.DISALLOW_NETWORK_RESET, UserHandle.myUserId())) {
return inflater.inflate(R.layout.network_reset_disallowed_screen, null);
} else if (admin != null) {
- View view = inflater.inflate(R.layout.admin_support_details_empty_view, null);
- ShowAdminSupportDetailsDialog.setAdminSupportDetails(getActivity(), view, admin, false);
- view.setVisibility(View.VISIBLE);
- return view;
+ new ActionDisabledByAdminDialogHelper(getActivity())
+ .prepareDialogBuilder(UserManager.DISALLOW_NETWORK_RESET, admin)
+ .setOnDismissListener(__ -> getActivity().finish())
+ .show();
+ return new View(getContext());
}
mContentView = inflater.inflate(R.layout.reset_network_confirm, null);
establishFinalConfirmationState();
diff --git a/src/com/android/settings/RestrictedSettingsFragment.java b/src/com/android/settings/RestrictedSettingsFragment.java
index bbb317b..b17ca84 100644
--- a/src/com/android/settings/RestrictedSettingsFragment.java
+++ b/src/com/android/settings/RestrictedSettingsFragment.java
@@ -17,6 +17,7 @@
package com.android.settings;
import android.app.Activity;
+import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -30,6 +31,7 @@
import android.widget.TextView;
import com.android.settings.dashboard.RestrictedDashboardFragment;
+import com.android.settings.enterprise.ActionDisabledByAdminDialogHelper;
import com.android.settingslib.RestrictedLockUtils;
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
@@ -67,7 +69,6 @@
private RestrictionsManager mRestrictionsManager;
private final String mRestrictionKey;
- private View mAdminSupportDetails;
private EnforcedAdmin mEnforcedAdmin;
private TextView mEmptyTextView;
@@ -85,6 +86,8 @@
}
};
+ private AlertDialog mActionDisabledDialog;
+
/**
* @param restrictionKey The restriction key to check before pin protecting
* this settings page. Pass in {@link RESTRICT_IF_OVERRIDABLE} if it should
@@ -116,7 +119,6 @@
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
- mAdminSupportDetails = initAdminSupportDetailsView();
mEmptyTextView = initEmptyTextView();
}
@@ -204,10 +206,6 @@
return restricted && mRestrictionsManager.hasRestrictionsProvider();
}
- private View initAdminSupportDetailsView() {
- return getActivity().findViewById(R.id.admin_support_details);
- }
-
protected TextView initEmptyTextView() {
TextView emptyView = (TextView) getActivity().findViewById(android.R.id.empty);
return emptyView;
@@ -229,11 +227,14 @@
@Override
protected void onDataSetChanged() {
highlightPreferenceIfNeeded();
- if (mAdminSupportDetails != null && isUiRestrictedByOnlyAdmin()) {
+ if (isUiRestrictedByOnlyAdmin()
+ && (mActionDisabledDialog == null || !mActionDisabledDialog.isShowing())) {
final EnforcedAdmin admin = getRestrictionEnforcedAdmin();
- ShowAdminSupportDetailsDialog.setAdminSupportDetails(getActivity(),
- mAdminSupportDetails, admin, false);
- setEmptyView(mAdminSupportDetails);
+ mActionDisabledDialog = new ActionDisabledByAdminDialogHelper(getActivity())
+ .prepareDialogBuilder(mRestrictionKey, admin)
+ .setOnDismissListener(__ -> getActivity().finish())
+ .show();
+ setEmptyView(new View(getContext()));
} else if (mEmptyTextView != null) {
setEmptyView(mEmptyTextView);
}
diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java
index 8b71df1..15b3c66 100644
--- a/src/com/android/settings/SettingsActivity.java
+++ b/src/com/android/settings/SettingsActivity.java
@@ -523,7 +523,7 @@
if (startingFragment != null) {
Intent modIntent = new Intent(superIntent);
modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
- Bundle args = superIntent.getExtras();
+ Bundle args = superIntent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
if (args != null) {
args = new Bundle(args);
} else {
diff --git a/src/com/android/settings/ShowAdminSupportDetailsDialog.java b/src/com/android/settings/ShowAdminSupportDetailsDialog.java
deleted file mode 100644
index 321f93d..0000000
--- a/src/com/android/settings/ShowAdminSupportDetailsDialog.java
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- * Copyright (C) 2015 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;
-
-import android.app.Activity;
-import android.app.AlertDialog;
-import android.app.AppGlobals;
-import android.app.admin.DevicePolicyManager;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.Intent;
-import android.content.pm.ActivityInfo;
-import android.graphics.drawable.Drawable;
-import android.os.Bundle;
-import android.os.Process;
-import android.os.RemoteException;
-import android.os.UserHandle;
-import android.os.UserManager;
-import android.util.Log;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.widget.ImageView;
-import android.widget.TextView;
-
-import com.android.settingslib.RestrictedLockUtils;
-import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
-
-import java.util.Objects;
-
-public class ShowAdminSupportDetailsDialog extends Activity
- implements DialogInterface.OnDismissListener {
-
- private static final String TAG = "AdminSupportDialog";
-
- private EnforcedAdmin mEnforcedAdmin;
- private View mDialogView;
- private String mRestriction = null;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- mEnforcedAdmin = getAdminDetailsFromIntent(getIntent());
- mRestriction = getRestrictionFromIntent(getIntent());
-
- AlertDialog.Builder builder = new AlertDialog.Builder(this);
- mDialogView = LayoutInflater.from(builder.getContext()).inflate(
- R.layout.admin_support_details_dialog, null);
- initializeDialogViews(mDialogView, mEnforcedAdmin.component, mEnforcedAdmin.userId,
- mRestriction);
- builder.setOnDismissListener(this)
- .setPositiveButton(R.string.okay, null)
- .setView(mDialogView)
- .show();
- }
-
- @Override
- public void onNewIntent(Intent intent) {
- super.onNewIntent(intent);
- EnforcedAdmin admin = getAdminDetailsFromIntent(intent);
- String restriction = getRestrictionFromIntent(intent);
- if (!mEnforcedAdmin.equals(admin) || !Objects.equals(mRestriction, restriction)) {
- mEnforcedAdmin = admin;
- mRestriction = restriction;
- initializeDialogViews(mDialogView, mEnforcedAdmin.component, mEnforcedAdmin.userId,
- mRestriction);
- }
- }
-
- private EnforcedAdmin getAdminDetailsFromIntent(Intent intent) {
- EnforcedAdmin admin = new EnforcedAdmin(null, UserHandle.myUserId());
- if (intent == null) {
- return admin;
- }
- admin.component = intent.getParcelableExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN);
- admin.userId = intent.getIntExtra(Intent.EXTRA_USER_ID, UserHandle.myUserId());
- return admin;
- }
-
- private String getRestrictionFromIntent(Intent intent) {
- if (intent == null) return null;
- return intent.getStringExtra(DevicePolicyManager.EXTRA_RESTRICTION);
- }
-
- private void initializeDialogViews(View root, ComponentName admin, int userId,
- String restriction) {
- if (admin != null) {
- if (!RestrictedLockUtils.isAdminInCurrentUserOrProfile(this, admin)
- || !RestrictedLockUtils.isCurrentUserOrProfile(this, userId)) {
- admin = null;
- } else {
- ActivityInfo ai = null;
- try {
- ai = AppGlobals.getPackageManager().getReceiverInfo(admin, 0 /* flags */,
- userId);
- } catch (RemoteException e) {
- Log.w(TAG, "Missing reciever info", e);
- }
- if (ai != null) {
- Drawable icon = ai.loadIcon(getPackageManager());
- Drawable badgedIcon = getPackageManager().getUserBadgedIcon(
- icon, new UserHandle(userId));
- ((ImageView) root.findViewById(R.id.admin_support_icon)).setImageDrawable(
- badgedIcon);
- }
- }
- }
-
- setAdminSupportTitle(root, restriction);
- setAdminSupportDetails(this, root, new EnforcedAdmin(admin, userId), true);
- }
-
- private void setAdminSupportTitle(View root, String restriction) {
- final TextView titleView = (TextView) root.findViewById(R.id.admin_support_dialog_title);
- if (titleView == null) {
- return;
- }
- if (restriction == null) {
- titleView.setText(R.string.disabled_by_policy_title);
- return;
- }
- switch(restriction) {
- case UserManager.DISALLOW_ADJUST_VOLUME:
- titleView.setText(R.string.disabled_by_policy_title_adjust_volume);
- break;
- case UserManager.DISALLOW_OUTGOING_CALLS:
- titleView.setText(R.string.disabled_by_policy_title_outgoing_calls);
- break;
- case UserManager.DISALLOW_SMS:
- titleView.setText(R.string.disabled_by_policy_title_sms);
- break;
- case DevicePolicyManager.POLICY_DISABLE_CAMERA:
- titleView.setText(R.string.disabled_by_policy_title_camera);
- break;
- case DevicePolicyManager.POLICY_DISABLE_SCREEN_CAPTURE:
- titleView.setText(R.string.disabled_by_policy_title_screen_capture);
- break;
- case DevicePolicyManager.POLICY_MANDATORY_BACKUPS:
- titleView.setText(R.string.disabled_by_policy_title_turn_off_backups);
- break;
- default:
- // Use general text if no specialized title applies
- titleView.setText(R.string.disabled_by_policy_title);
- }
- }
-
- public static void setAdminSupportDetails(final Activity activity, View root,
- final EnforcedAdmin enforcedAdmin, final boolean finishActivity) {
- if (enforcedAdmin == null) {
- return;
- }
-
- if (enforcedAdmin.component != null) {
- DevicePolicyManager dpm = (DevicePolicyManager) activity.getSystemService(
- Context.DEVICE_POLICY_SERVICE);
- if (!RestrictedLockUtils.isAdminInCurrentUserOrProfile(activity,
- enforcedAdmin.component) || !RestrictedLockUtils.isCurrentUserOrProfile(
- activity, enforcedAdmin.userId)) {
- enforcedAdmin.component = null;
- } else {
- if (enforcedAdmin.userId == UserHandle.USER_NULL) {
- enforcedAdmin.userId = UserHandle.myUserId();
- }
- CharSequence supportMessage = null;
- if (UserHandle.isSameApp(Process.myUid(), Process.SYSTEM_UID)) {
- supportMessage = dpm.getShortSupportMessageForUser(
- enforcedAdmin.component, enforcedAdmin.userId);
- }
- if (supportMessage != null) {
- TextView textView = (TextView) root.findViewById(R.id.admin_support_msg);
- textView.setText(supportMessage);
- }
- }
- }
-
- root.findViewById(R.id.admins_policies_list).setOnClickListener(
- new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Intent intent = new Intent();
- if (enforcedAdmin.component != null) {
- intent.setClass(activity, DeviceAdminAdd.class);
- intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,
- enforcedAdmin.component);
- intent.putExtra(DeviceAdminAdd.EXTRA_CALLED_FROM_SUPPORT_DIALOG, true);
- // DeviceAdminAdd class may need to run as managed profile.
- activity.startActivityAsUser(intent,
- new UserHandle(enforcedAdmin.userId));
- } else {
- intent.setClass(activity, Settings.DeviceAdminSettingsActivity.class);
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- // Activity merges both managed profile and parent users
- // admins so show as same user as this activity.
- activity.startActivity(intent);
- }
- if (finishActivity) {
- activity.finish();
- }
- }
- });
- }
-
- @Override
- public void onDismiss(DialogInterface dialog) {
- finish();
- }
-}
diff --git a/src/com/android/settings/core/PreferenceControllerListHelper.java b/src/com/android/settings/core/PreferenceControllerListHelper.java
index bec7c09..a4808a1 100644
--- a/src/com/android/settings/core/PreferenceControllerListHelper.java
+++ b/src/com/android/settings/core/PreferenceControllerListHelper.java
@@ -26,6 +26,7 @@
import android.text.TextUtils;
import android.util.Log;
+import com.android.settings.core.PreferenceXmlParserUtils.MetadataFlag;
import com.android.settingslib.core.AbstractPreferenceController;
import org.xmlpull.v1.XmlPullParserException;
@@ -52,7 +53,8 @@
final List<BasePreferenceController> controllers = new ArrayList<>();
List<Bundle> preferenceMetadata;
try {
- preferenceMetadata = PreferenceXmlParserUtils.extractMetadata(context, xmlResId);
+ preferenceMetadata = PreferenceXmlParserUtils.extractMetadata(context, xmlResId,
+ MetadataFlag.FLAG_NEED_KEY | MetadataFlag.FLAG_NEED_PREF_CONTROLLER);
} catch (IOException | XmlPullParserException e) {
Log.e(TAG, "Failed to parse preference xml for getting controllers");
return controllers;
diff --git a/src/com/android/settings/core/PreferenceXmlParserUtils.java b/src/com/android/settings/core/PreferenceXmlParserUtils.java
index e07ca9b..7afe8d8 100644
--- a/src/com/android/settings/core/PreferenceXmlParserUtils.java
+++ b/src/com/android/settings/core/PreferenceXmlParserUtils.java
@@ -18,10 +18,14 @@
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.annotation.XmlRes;
import android.content.Context;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.os.Bundle;
+import android.support.annotation.IntDef;
+import android.support.annotation.VisibleForTesting;
+import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
@@ -33,6 +37,8 @@
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -43,12 +49,41 @@
public class PreferenceXmlParserUtils {
private static final String TAG = "PreferenceXmlParserUtil";
-
+ @VisibleForTesting
+ static final String PREF_SCREEN_TAG = "PreferenceScreen";
private static final List<String> SUPPORTED_PREF_TYPES = Arrays.asList(
"Preference", "PreferenceCategory", "PreferenceScreen");
+ /**
+ * Flag definition to indicate which metadata should be extracted when
+ * {@link #extractMetadata(Context, int, int)} is called. The flags can be combined by using |
+ * (binary or).
+ */
+ @IntDef(flag = true, value = {
+ MetadataFlag.FLAG_INCLUDE_PREF_SCREEN,
+ MetadataFlag.FLAG_NEED_KEY,
+ MetadataFlag.FLAG_NEED_PREF_TYPE,
+ MetadataFlag.FLAG_NEED_PREF_CONTROLLER,
+ MetadataFlag.FLAG_NEED_PREF_TITLE,
+ MetadataFlag.FLAG_NEED_PREF_SUMMARY,
+ MetadataFlag.FLAG_NEED_PREF_ICON})
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface MetadataFlag {
+ int FLAG_INCLUDE_PREF_SCREEN = 1;
+ int FLAG_NEED_KEY = 1 << 1;
+ int FLAG_NEED_PREF_TYPE = 1 << 2;
+ int FLAG_NEED_PREF_CONTROLLER = 1 << 3;
+ int FLAG_NEED_PREF_TITLE = 1 << 4;
+ int FLAG_NEED_PREF_SUMMARY = 1 << 5;
+ int FLAG_NEED_PREF_ICON = 1 << 6;
+ }
+
+ public static final String METADATA_PREF_TYPE = "type";
public static final String METADATA_KEY = "key";
public static final String METADATA_CONTROLLER = "controller";
+ public static final String METADATA_TITLE = "title";
+ public static final String METADATA_SUMMARY = "summary";
+ public static final String METADATA_ICON = "icon";
private static final String ENTRIES_SEPARATOR = "|";
@@ -107,11 +142,11 @@
/**
* Extracts metadata from preference xml and put them into a {@link Bundle}.
*
- * TODO(zhfan): Similar logic exists in {@link SliceBuilderUtils} and
- * {@link UniquePreferenceTest}. Need refactoring to consolidate them all.
+ * @param xmlResId xml res id of a preference screen
+ * @param flags Should be one or more of {@link MetadataFlag}.
*/
@NonNull
- public static List<Bundle> extractMetadata(Context context, int xmlResId)
+ public static List<Bundle> extractMetadata(Context context, @XmlRes int xmlResId, int flags)
throws IOException, XmlPullParserException {
final List<Bundle> metadata = new ArrayList<>();
if (xmlResId <= 0) {
@@ -132,16 +167,37 @@
continue;
}
final String nodeName = parser.getName();
+ if (!hasFlag(flags, MetadataFlag.FLAG_INCLUDE_PREF_SCREEN)
+ && TextUtils.equals(PREF_SCREEN_TAG, nodeName)) {
+ continue;
+ }
if (!SUPPORTED_PREF_TYPES.contains(nodeName) && !nodeName.endsWith("Preference")) {
continue;
}
final Bundle preferenceMetadata = new Bundle();
final AttributeSet attrs = Xml.asAttributeSet(parser);
- preferenceMetadata.putString(METADATA_KEY, getDataKey(context, attrs));
- preferenceMetadata.putString(METADATA_CONTROLLER, getController(context, attrs));
+ if (hasFlag(flags, MetadataFlag.FLAG_NEED_PREF_TYPE)) {
+ preferenceMetadata.putString(METADATA_PREF_TYPE, nodeName);
+ }
+ if (hasFlag(flags, MetadataFlag.FLAG_NEED_KEY)) {
+ preferenceMetadata.putString(METADATA_KEY, getDataKey(context, attrs));
+ }
+ if (hasFlag(flags, MetadataFlag.FLAG_NEED_PREF_CONTROLLER)) {
+ preferenceMetadata.putString(METADATA_CONTROLLER, getController(context, attrs));
+ }
+ if (hasFlag(flags, MetadataFlag.FLAG_NEED_PREF_TITLE)) {
+ preferenceMetadata.putString(METADATA_TITLE, getDataTitle(context, attrs));
+ }
+ if (hasFlag(flags, MetadataFlag.FLAG_NEED_PREF_SUMMARY)) {
+ preferenceMetadata.putString(METADATA_SUMMARY, getDataSummary(context, attrs));
+ }
+ if (hasFlag(flags, MetadataFlag.FLAG_NEED_PREF_ICON)) {
+ preferenceMetadata.putInt(METADATA_ICON, getDataIcon(context, attrs));
+ }
metadata.add(preferenceMetadata);
} while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
&& (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth));
+ parser.close();
return metadata;
}
@@ -161,6 +217,10 @@
return data;
}
+ private static boolean hasFlag(int flags, @MetadataFlag int flag) {
+ return (flags & flag) != 0;
+ }
+
private static String getDataEntries(Context context, AttributeSet set, int[] attrs,
int resId) {
final TypedArray sa = context.obtainStyledAttributes(set, attrs);
diff --git a/src/com/android/settings/dashboard/RestrictedDashboardFragment.java b/src/com/android/settings/dashboard/RestrictedDashboardFragment.java
index 99aaff4..de0b396 100644
--- a/src/com/android/settings/dashboard/RestrictedDashboardFragment.java
+++ b/src/com/android/settings/dashboard/RestrictedDashboardFragment.java
@@ -19,6 +19,7 @@
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import android.app.Activity;
+import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -31,9 +32,9 @@
import android.view.View;
import android.widget.TextView;
+import com.android.settings.enterprise.ActionDisabledByAdminDialogHelper;
import com.android.settings.R;
import com.android.settings.RestrictedSettingsFragment;
-import com.android.settings.ShowAdminSupportDetailsDialog;
import com.android.settingslib.RestrictedLockUtils;
/**
@@ -69,7 +70,6 @@
private RestrictionsManager mRestrictionsManager;
private final String mRestrictionKey;
- private View mAdminSupportDetails;
private EnforcedAdmin mEnforcedAdmin;
private TextView mEmptyTextView;
@@ -86,6 +86,7 @@
}
}
};
+ private AlertDialog mActionDisabledDialog;
/**
* @param restrictionKey The restriction key to check before pin protecting
@@ -118,7 +119,6 @@
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
- mAdminSupportDetails = initAdminSupportDetailsView();
mEmptyTextView = initEmptyTextView();
}
@@ -206,10 +206,6 @@
return restricted && mRestrictionsManager.hasRestrictionsProvider();
}
- private View initAdminSupportDetailsView() {
- return getActivity().findViewById(R.id.admin_support_details);
- }
-
protected TextView initEmptyTextView() {
TextView emptyView = (TextView) getActivity().findViewById(android.R.id.empty);
return emptyView;
@@ -231,11 +227,14 @@
@Override
protected void onDataSetChanged() {
highlightPreferenceIfNeeded();
- if (mAdminSupportDetails != null && isUiRestrictedByOnlyAdmin()) {
+ if (isUiRestrictedByOnlyAdmin()
+ && (mActionDisabledDialog == null || !mActionDisabledDialog.isShowing())) {
final EnforcedAdmin admin = getRestrictionEnforcedAdmin();
- ShowAdminSupportDetailsDialog.setAdminSupportDetails(getActivity(),
- mAdminSupportDetails, admin, false);
- setEmptyView(mAdminSupportDetails);
+ mActionDisabledDialog = new ActionDisabledByAdminDialogHelper(getActivity())
+ .prepareDialogBuilder(mRestrictionKey, admin)
+ .setOnDismissListener(__ -> getActivity().finish())
+ .show();
+ setEmptyView(new View(getContext()));
} else if (mEmptyTextView != null) {
setEmptyView(mEmptyTextView);
}
diff --git a/src/com/android/settings/enterprise/ActionDisabledByAdminDialog.java b/src/com/android/settings/enterprise/ActionDisabledByAdminDialog.java
new file mode 100644
index 0000000..37c5124
--- /dev/null
+++ b/src/com/android/settings/enterprise/ActionDisabledByAdminDialog.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2018 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.enterprise;
+
+import android.app.Activity;
+import android.app.admin.DevicePolicyManager;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.UserHandle;
+
+import com.android.settingslib.RestrictedLockUtils;
+import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
+
+public class ActionDisabledByAdminDialog extends Activity
+ implements DialogInterface.OnDismissListener {
+
+ private ActionDisabledByAdminDialogHelper mDialogHelper;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ final RestrictedLockUtils.EnforcedAdmin enforcedAdmin =
+ getAdminDetailsFromIntent(getIntent());
+ final String restriction = getRestrictionFromIntent(getIntent());
+ mDialogHelper = new ActionDisabledByAdminDialogHelper(this);
+ mDialogHelper.prepareDialogBuilder(restriction, enforcedAdmin)
+ .setOnDismissListener(this)
+ .show();
+ }
+
+ @Override
+ public void onNewIntent(Intent intent) {
+ super.onNewIntent(intent);
+ final EnforcedAdmin admin = getAdminDetailsFromIntent(intent);
+ final String restriction = getRestrictionFromIntent(intent);
+ mDialogHelper.updateDialog(restriction, admin);
+ }
+
+ @android.support.annotation.VisibleForTesting
+ EnforcedAdmin getAdminDetailsFromIntent(Intent intent) {
+ final EnforcedAdmin admin = new EnforcedAdmin(null, UserHandle.myUserId());
+ if (intent == null) {
+ return admin;
+ }
+ admin.component = intent.getParcelableExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN);
+ admin.userId = intent.getIntExtra(Intent.EXTRA_USER_ID, UserHandle.myUserId());
+ return admin;
+ }
+
+ @android.support.annotation.VisibleForTesting
+ String getRestrictionFromIntent(Intent intent) {
+ if (intent == null) return null;
+ return intent.getStringExtra(DevicePolicyManager.EXTRA_RESTRICTION);
+ }
+
+ @Override
+ public void onDismiss(DialogInterface dialog) {
+ finish();
+ }
+}
diff --git a/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelper.java b/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelper.java
new file mode 100644
index 0000000..3429957
--- /dev/null
+++ b/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelper.java
@@ -0,0 +1,204 @@
+/*
+ * Copyright (C) 2018 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.enterprise;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.AppGlobals;
+import android.app.admin.DevicePolicyManager;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.ActivityInfo;
+import android.graphics.drawable.Drawable;
+import android.os.Process;
+import android.os.RemoteException;
+import android.os.UserHandle;
+import android.os.UserManager;
+import android.support.annotation.VisibleForTesting;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import com.android.settings.DeviceAdminAdd;
+import com.android.settings.R;
+import com.android.settings.Settings;
+import com.android.settingslib.RestrictedLockUtils;
+import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
+
+import java.util.Objects;
+
+/**
+ * Helper class for {@link ActionDisabledByAdminDialog} which sets up the dialog.
+ */
+public class ActionDisabledByAdminDialogHelper {
+
+ private static final String TAG = ActionDisabledByAdminDialogHelper.class.getName();
+ private EnforcedAdmin mEnforcedAdmin;
+ private ViewGroup mDialogView;
+ private String mRestriction = null;
+ private Activity mActivity;
+
+ public ActionDisabledByAdminDialogHelper(Activity activity) {
+ mActivity = activity;
+ }
+
+ public AlertDialog.Builder prepareDialogBuilder(String restriction,
+ EnforcedAdmin enforcedAdmin) {
+ mEnforcedAdmin = enforcedAdmin;
+ mRestriction = restriction;
+
+ final AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
+ mDialogView = (ViewGroup) LayoutInflater.from(builder.getContext()).inflate(
+ R.layout.admin_support_details_dialog, null);
+ initializeDialogViews(mDialogView, mEnforcedAdmin.component, mEnforcedAdmin.userId,
+ mRestriction);
+ return builder
+ .setPositiveButton(R.string.okay, null)
+ .setNeutralButton(R.string.admin_more_details,
+ (dialog, which) -> {
+ showAdminPolicies(mEnforcedAdmin, mActivity);
+ mActivity.finish();
+ })
+ .setView(mDialogView);
+ }
+
+ public void updateDialog(String restriction, EnforcedAdmin admin) {
+ if (mEnforcedAdmin.equals(admin) && Objects.equals(mRestriction, restriction)) {
+ return;
+ }
+ mEnforcedAdmin = admin;
+ mRestriction = restriction;
+ initializeDialogViews(mDialogView, mEnforcedAdmin.component, mEnforcedAdmin.userId,
+ mRestriction);
+ }
+
+ private void initializeDialogViews(View root, ComponentName admin, int userId,
+ String restriction) {
+ if (admin == null) {
+ return;
+ }
+ if (!RestrictedLockUtils.isAdminInCurrentUserOrProfile(mActivity, admin)
+ || !RestrictedLockUtils.isCurrentUserOrProfile(mActivity, userId)) {
+ admin = null;
+ } else {
+ ActivityInfo ai = null;
+ try {
+ ai = AppGlobals.getPackageManager().getReceiverInfo(admin, 0 /* flags */,
+ userId);
+ } catch (RemoteException e) {
+ Log.w(TAG, "Missing reciever info", e);
+ }
+ if (ai != null) {
+ final Drawable icon = ai.loadIcon(mActivity.getPackageManager());
+ final Drawable badgedIcon = mActivity.getPackageManager().getUserBadgedIcon(
+ icon, new UserHandle(userId));
+ ((ImageView) root.findViewById(R.id.admin_support_icon)).setImageDrawable(
+ badgedIcon);
+ }
+ }
+
+ setAdminSupportTitle(root, restriction);
+ setAdminSupportDetails(mActivity, root, new EnforcedAdmin(admin, userId));
+ }
+
+ @VisibleForTesting
+ void setAdminSupportTitle(View root, String restriction) {
+ final TextView titleView = root.findViewById(R.id.admin_support_dialog_title);
+ if (titleView == null) {
+ return;
+ }
+ if (restriction == null) {
+ titleView.setText(R.string.disabled_by_policy_title);
+ return;
+ }
+ switch (restriction) {
+ case UserManager.DISALLOW_ADJUST_VOLUME:
+ titleView.setText(R.string.disabled_by_policy_title_adjust_volume);
+ break;
+ case UserManager.DISALLOW_OUTGOING_CALLS:
+ titleView.setText(R.string.disabled_by_policy_title_outgoing_calls);
+ break;
+ case UserManager.DISALLOW_SMS:
+ titleView.setText(R.string.disabled_by_policy_title_sms);
+ break;
+ case DevicePolicyManager.POLICY_DISABLE_CAMERA:
+ titleView.setText(R.string.disabled_by_policy_title_camera);
+ break;
+ case DevicePolicyManager.POLICY_DISABLE_SCREEN_CAPTURE:
+ titleView.setText(R.string.disabled_by_policy_title_screen_capture);
+ break;
+ case DevicePolicyManager.POLICY_MANDATORY_BACKUPS:
+ titleView.setText(R.string.disabled_by_policy_title_turn_off_backups);
+ break;
+ default:
+ // Use general text if no specialized title applies
+ titleView.setText(R.string.disabled_by_policy_title);
+ }
+ }
+
+ @VisibleForTesting
+ void setAdminSupportDetails(final Activity activity, final View root,
+ final EnforcedAdmin enforcedAdmin) {
+ if (enforcedAdmin == null || enforcedAdmin.component == null) {
+ return;
+ }
+ final DevicePolicyManager dpm = (DevicePolicyManager) activity.getSystemService(
+ Context.DEVICE_POLICY_SERVICE);
+ if (!RestrictedLockUtils.isAdminInCurrentUserOrProfile(activity,
+ enforcedAdmin.component) || !RestrictedLockUtils.isCurrentUserOrProfile(
+ activity, enforcedAdmin.userId)) {
+ enforcedAdmin.component = null;
+ } else {
+ if (enforcedAdmin.userId == UserHandle.USER_NULL) {
+ enforcedAdmin.userId = UserHandle.myUserId();
+ }
+ CharSequence supportMessage = null;
+ if (UserHandle.isSameApp(Process.myUid(), Process.SYSTEM_UID)) {
+ supportMessage = dpm.getShortSupportMessageForUser(
+ enforcedAdmin.component, enforcedAdmin.userId);
+ }
+ if (supportMessage != null) {
+ final TextView textView = root.findViewById(R.id.admin_support_msg);
+ textView.setText(supportMessage);
+ }
+ }
+ }
+
+ @VisibleForTesting
+ void showAdminPolicies(final EnforcedAdmin enforcedAdmin, final Activity activity) {
+ final Intent intent = new Intent();
+ if (enforcedAdmin.component != null) {
+ intent.setClass(activity, DeviceAdminAdd.class);
+ intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,
+ enforcedAdmin.component);
+ intent.putExtra(DeviceAdminAdd.EXTRA_CALLED_FROM_SUPPORT_DIALOG, true);
+ // DeviceAdminAdd class may need to run as managed profile.
+ activity.startActivityAsUser(intent,
+ new UserHandle(enforcedAdmin.userId));
+ } else {
+ intent.setClass(activity, Settings.DeviceAdminSettingsActivity.class);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ // Activity merges both managed profile and parent users
+ // admins so show as same user as this activity.
+ activity.startActivity(intent);
+ }
+ }
+}
diff --git a/src/com/android/settings/enterprise/OWNERS b/src/com/android/settings/enterprise/OWNERS
index bab2fe2..5811673 100644
--- a/src/com/android/settings/enterprise/OWNERS
+++ b/src/com/android/settings/enterprise/OWNERS
@@ -1,4 +1,7 @@
# Default reviewers for this and subdirectories.
sandness@google.com
+tonymak@google.com
+yuemingw@google.com
+arangelov@google.com
# Emergency approvers in case the above are not available
\ No newline at end of file
diff --git a/src/com/android/settings/nfc/AndroidBeam.java b/src/com/android/settings/nfc/AndroidBeam.java
index 8377f14..4e90680 100644
--- a/src/com/android/settings/nfc/AndroidBeam.java
+++ b/src/com/android/settings/nfc/AndroidBeam.java
@@ -28,11 +28,11 @@
import android.widget.Switch;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.settings.enterprise.ActionDisabledByAdminDialogHelper;
import com.android.settingslib.HelpUtils;
import com.android.settings.core.InstrumentedFragment;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
-import com.android.settings.ShowAdminSupportDetailsDialog;
import com.android.settings.widget.SwitchBar;
import com.android.settingslib.RestrictedLockUtils;
@@ -70,11 +70,10 @@
mBeamDisallowedByBase = RestrictedLockUtils.hasBaseUserRestriction(getActivity(),
UserManager.DISALLOW_OUTGOING_BEAM, UserHandle.myUserId());
if (!mBeamDisallowedByBase && admin != null) {
- View view = inflater.inflate(R.layout.admin_support_details_empty_view, null);
- ShowAdminSupportDetailsDialog.setAdminSupportDetails(getActivity(), view, admin, false);
- view.setVisibility(View.VISIBLE);
+ new ActionDisabledByAdminDialogHelper(getActivity())
+ .prepareDialogBuilder(UserManager.DISALLOW_OUTGOING_BEAM, admin).show();
mBeamDisallowedByOnlyAdmin = true;
- return view;
+ return new View(getContext());
}
mView = inflater.inflate(R.layout.android_beam, container, false);
return mView;
diff --git a/src/com/android/settings/slices/SliceDataConverter.java b/src/com/android/settings/slices/SliceDataConverter.java
index d77f427..e7b53d0 100644
--- a/src/com/android/settings/slices/SliceDataConverter.java
+++ b/src/com/android/settings/slices/SliceDataConverter.java
@@ -16,21 +16,28 @@
package com.android.settings.slices;
+import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_CONTROLLER;
+import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_ICON;
+import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_KEY;
+import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_SUMMARY;
+import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_TITLE;
+
import android.content.Context;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
+import android.os.Bundle;
import android.provider.SearchIndexableResource;
-import android.support.annotation.DrawableRes;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Xml;
+import com.android.settings.core.PreferenceXmlParserUtils;
+import com.android.settings.core.PreferenceXmlParserUtils.MetadataFlag;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.DatabaseIndexingUtils;
import com.android.settings.search.Indexable.SearchIndexProvider;
-import com.android.settings.core.PreferenceXmlParserUtils;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@@ -144,35 +151,32 @@
+ nodeName + " at " + parser.getPositionDescription());
}
- final int outerDepth = parser.getDepth();
final AttributeSet attrs = Xml.asAttributeSet(parser);
final String screenTitle = PreferenceXmlParserUtils.getDataTitle(mContext, attrs);
// TODO (b/67996923) Investigate if we need headers for Slices, since they never
// correspond to an actual setting.
- while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
- && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
- if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
- continue;
- }
+ final List<Bundle> metadata = PreferenceXmlParserUtils.extractMetadata(mContext,
+ xmlResId,
+ MetadataFlag.FLAG_NEED_KEY
+ | MetadataFlag.FLAG_NEED_PREF_CONTROLLER
+ | MetadataFlag.FLAG_NEED_PREF_TYPE
+ | MetadataFlag.FLAG_NEED_PREF_TITLE
+ | MetadataFlag.FLAG_NEED_PREF_ICON
+ | MetadataFlag.FLAG_NEED_PREF_SUMMARY);
+ for (Bundle bundle : metadata) {
// TODO (b/67996923) Non-controller Slices should become intent-only slices.
// Note that without a controller, dynamic summaries are impossible.
- // TODO (b/67996923) This will not work if preferences have nested intents:
- // <pref ....>
- // <intent action="blab"/> </pref>
- final String controllerClassName = PreferenceXmlParserUtils.getController(mContext,
- attrs);
+ final String controllerClassName = bundle.getString(METADATA_CONTROLLER);
if (TextUtils.isEmpty(controllerClassName)) {
continue;
}
-
- final String title = PreferenceXmlParserUtils.getDataTitle(mContext, attrs);
- final String key = PreferenceXmlParserUtils.getDataKey(mContext, attrs);
- @DrawableRes final int iconResId = PreferenceXmlParserUtils.getDataIcon(mContext,
- attrs);
- final String summary = PreferenceXmlParserUtils.getDataSummary(mContext, attrs);
+ final String key = bundle.getString(METADATA_KEY);
+ final String title = bundle.getString(METADATA_TITLE);
+ final String summary = bundle.getString(METADATA_SUMMARY);
+ final int iconResId = bundle.getInt(METADATA_ICON);
final int sliceType = SliceBuilderUtils.getSliceType(mContext, controllerClassName,
key);
@@ -194,7 +198,7 @@
} catch (IOException e) {
Log.w(TAG, "IO Error parsing PreferenceScreen: ", e);
} catch (Resources.NotFoundException e) {
- Log.w(TAG, "Resoucre not found error parsing PreferenceScreen: ", e);
+ Log.w(TAG, "Resource not found error parsing PreferenceScreen: ", e);
} finally {
if (parser != null) parser.close();
}
diff --git a/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java b/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java
index 2bfd796..6f2accd 100644
--- a/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java
+++ b/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java
@@ -156,7 +156,7 @@
final SettingsActivity activity = (SettingsActivity) getActivity();
- mEmptyView = (TextView) getView().findViewById(android.R.id.empty);
+ mEmptyView = getView().findViewById(android.R.id.empty);
setEmptyView(mEmptyView);
String emptyViewText = activity.getString(R.string.wifi_calling_off_explanation)
+ activity.getString(R.string.wifi_calling_off_explanation_2);
@@ -217,6 +217,12 @@
}
@Override
+ public int getHelpResource() {
+ // Return 0 to suppress help icon. The help will be populated by parent page.
+ return 0;
+ }
+
+ @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
diff --git a/tests/robotests/res/xml-mcc998/location_settings.xml b/tests/robotests/res/xml-mcc998/location_settings.xml
index 993af86..f61ca63 100644
--- a/tests/robotests/res/xml-mcc998/location_settings.xml
+++ b/tests/robotests/res/xml-mcc998/location_settings.xml
@@ -18,14 +18,20 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:key="fake_title_key"
- android:title="screen_title"
- settings:controller="com.android.settings.slices.FakePreferenceController">
+ android:title="screen_title">
<Preference
- android:key="key"
+ android:key="key1"
android:title="title"
android:icon="@drawable/ic_android"
- android:summary="summary"
+ android:summary="summary1"
settings:controller="com.android.settings.core.BadPreferenceController"/>
+ <Preference
+ android:key="key2"
+ android:title="title"
+ android:icon="@drawable/ic_android"
+ android:summary="summary2"
+ settings:controller="com.android.settings.slices.FakePreferenceController"/>
+
</PreferenceScreen>
\ No newline at end of file
diff --git a/tests/robotests/res/xml-mcc999/location_settings.xml b/tests/robotests/res/xml-mcc999/location_settings.xml
index 5619c77..de77bfa 100644
--- a/tests/robotests/res/xml-mcc999/location_settings.xml
+++ b/tests/robotests/res/xml-mcc999/location_settings.xml
@@ -17,8 +17,7 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:key="fake_title_key"
- android:title="screen_title"
- settings:controller="com.android.settings.slices.FakePreferenceController">
+ android:title="screen_title">
<Preference
android:key="key"
diff --git a/tests/robotests/src/com/android/settings/search/PreferenceXmlParserUtilTest.java b/tests/robotests/src/com/android/settings/core/PreferenceXmlParserUtilTest.java
similarity index 71%
rename from tests/robotests/src/com/android/settings/search/PreferenceXmlParserUtilTest.java
rename to tests/robotests/src/com/android/settings/core/PreferenceXmlParserUtilTest.java
index 0c5f788..458bc02 100644
--- a/tests/robotests/src/com/android/settings/search/PreferenceXmlParserUtilTest.java
+++ b/tests/robotests/src/com/android/settings/core/PreferenceXmlParserUtilTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 The Android Open Source Project
+ * Copyright (C) 2018 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.
@@ -12,21 +12,21 @@
* 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.search;
+package com.android.settings.core;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.content.res.XmlResourceParser;
import android.os.Bundle;
+import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Xml;
import com.android.settings.R;
-import com.android.settings.core.PreferenceXmlParserUtils;
+import com.android.settings.core.PreferenceXmlParserUtils.MetadataFlag;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
@@ -169,8 +169,9 @@
@Config(qualifiers = "mcc999")
public void extractMetadata_shouldContainKeyAndControllerName()
throws IOException, XmlPullParserException {
- final List<Bundle> metadata =
- PreferenceXmlParserUtils.extractMetadata(mContext, R.xml.location_settings);
+ List<Bundle> metadata = PreferenceXmlParserUtils.extractMetadata(mContext,
+ R.xml.location_settings,
+ MetadataFlag.FLAG_NEED_KEY | MetadataFlag.FLAG_NEED_PREF_CONTROLLER);
assertThat(metadata).isNotEmpty();
for (Bundle bundle : metadata) {
@@ -179,6 +180,70 @@
}
}
+ @Test
+ @Config(qualifiers = "mcc999")
+ public void extractMetadata_requestTitle_shouldContainTitle()
+ throws IOException, XmlPullParserException {
+ List<Bundle> metadata = PreferenceXmlParserUtils.extractMetadata(mContext,
+ R.xml.location_settings, MetadataFlag.FLAG_NEED_PREF_TITLE);
+ for (Bundle bundle : metadata) {
+ assertThat(bundle.getString(PreferenceXmlParserUtils.METADATA_TITLE)).isNotNull();
+ }
+ }
+
+ @Test
+ @Config(qualifiers = "mcc999")
+ public void extractMetadata_requestSummary_shouldContainSummary()
+ throws IOException, XmlPullParserException {
+ List<Bundle> metadata = PreferenceXmlParserUtils.extractMetadata(mContext,
+ R.xml.location_settings, MetadataFlag.FLAG_NEED_PREF_SUMMARY);
+ for (Bundle bundle : metadata) {
+ assertThat(bundle.getString(PreferenceXmlParserUtils.METADATA_SUMMARY)).isNotNull();
+ }
+ }
+
+ @Test
+ @Config(qualifiers = "mcc999")
+ public void extractMetadata_requestIcon_shouldContainIcon()
+ throws IOException, XmlPullParserException {
+ List<Bundle> metadata = PreferenceXmlParserUtils.extractMetadata(mContext,
+ R.xml.location_settings, MetadataFlag.FLAG_NEED_PREF_ICON);
+ for (Bundle bundle : metadata) {
+ assertThat(bundle.getInt(PreferenceXmlParserUtils.METADATA_ICON)).isNotEqualTo(0);
+ }
+ }
+
+ @Test
+ @Config(qualifiers = "mcc999")
+ public void extractMetadata_requestPrefType_shouldContainPrefType()
+ throws IOException, XmlPullParserException {
+ List<Bundle> metadata = PreferenceXmlParserUtils.extractMetadata(mContext,
+ R.xml.location_settings, MetadataFlag.FLAG_NEED_PREF_TYPE);
+ for (Bundle bundle : metadata) {
+ assertThat(bundle.getString(PreferenceXmlParserUtils.METADATA_PREF_TYPE)).isNotNull();
+ }
+ }
+
+ @Test
+ @Config(qualifiers = "mcc999")
+ public void extractMetadata_requestIncludeScreen_shouldContainScreen()
+ throws IOException, XmlPullParserException {
+ List<Bundle> metadata = PreferenceXmlParserUtils.extractMetadata(mContext,
+ R.xml.location_settings,
+ MetadataFlag.FLAG_NEED_PREF_TYPE | MetadataFlag.FLAG_INCLUDE_PREF_SCREEN);
+
+ boolean hasPreferenceScreen = false;
+ for (Bundle bundle : metadata) {
+ if (TextUtils.equals(bundle.getString(PreferenceXmlParserUtils.METADATA_PREF_TYPE),
+ PreferenceXmlParserUtils.PREF_SCREEN_TAG)) {
+ hasPreferenceScreen = true;
+ break;
+ }
+ }
+
+ assertThat(hasPreferenceScreen).isTrue();
+ }
+
/**
* @param resId the ID for the XML preference
* @return an XML resource parser that points to the start tag
diff --git a/tests/robotests/src/com/android/settings/datetime/timezone/model/TimeZoneDataTest.java b/tests/robotests/src/com/android/settings/datetime/timezone/model/TimeZoneDataTest.java
index e6073a8..4a624b7 100644
--- a/tests/robotests/src/com/android/settings/datetime/timezone/model/TimeZoneDataTest.java
+++ b/tests/robotests/src/com/android/settings/datetime/timezone/model/TimeZoneDataTest.java
@@ -73,13 +73,13 @@
CountryTimeZones US = mock(CountryTimeZones.class);
when(US.getCountryIso()).thenReturn("us");
when(US.getTimeZoneMappings()).thenReturn(Arrays.asList(
- new CountryTimeZones.TimeZoneMapping("Unknown/Secret_City", true),
- new CountryTimeZones.TimeZoneMapping("Unknown/Secret_City2", false)
+ TimeZoneMapping.createForTests("Unknown/Secret_City", true),
+ TimeZoneMapping.createForTests("Unknown/Secret_City2", false)
));
CountryTimeZones GB = mock(CountryTimeZones.class);
when(GB.getCountryIso()).thenReturn("gb");
when(GB.getTimeZoneMappings()).thenReturn(Collections.singletonList(
- new TimeZoneMapping("Unknown/Secret_City", true)
+ TimeZoneMapping.createForTests("Unknown/Secret_City", true)
));
when(mCountryZonesFinder.lookupCountryTimeZonesForZoneId("Unknown/Secret_City"))
.thenReturn(Arrays.asList(US, GB));
diff --git a/tests/robotests/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelperTest.java b/tests/robotests/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelperTest.java
new file mode 100644
index 0000000..981ce13
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelperTest.java
@@ -0,0 +1,186 @@
+/*
+ * Copyright (C) 2018 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.enterprise;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import android.app.Activity;
+import android.app.admin.DevicePolicyManager;
+import android.content.ComponentName;
+import android.content.Intent;
+import android.content.pm.UserInfo;
+import android.os.Process;
+import android.os.UserManager;
+import android.view.ViewGroup;
+import android.widget.FrameLayout;
+import android.widget.TextView;
+
+import com.android.settings.DeviceAdminAdd;
+import com.android.settings.R;
+import com.android.settings.Settings;
+import com.android.settings.testutils.CustomActivity;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.testutils.shadow.ShadowActivity;
+import com.android.settings.testutils.shadow.ShadowDevicePolicyManager;
+import com.android.settings.testutils.shadow.ShadowProcess;
+import com.android.settings.testutils.shadow.ShadowUserManager;
+import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.Robolectric;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.Shadows;
+import org.robolectric.annotation.Config;
+import org.robolectric.shadow.api.Shadow;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(shadows = {
+ ShadowDevicePolicyManager.class,
+ ShadowUserManager.class,
+ ShadowActivity.class,
+ ShadowProcess.class
+})
+public class ActionDisabledByAdminDialogHelperTest {
+ private ActionDisabledByAdminDialogHelper mHelper;
+ private Activity mActivity;
+ private org.robolectric.shadows.ShadowActivity mActivityShadow;
+
+ @Before
+ public void setUp() {
+ mActivity = Robolectric.buildActivity(CustomActivity.class).get();
+ mActivityShadow = Shadow.extract(mActivity);
+ mHelper = new ActionDisabledByAdminDialogHelper(mActivity);
+ }
+
+ @Test
+ public void testShowAdminPoliciesWithComponent() {
+ final int userId = 123;
+ final ComponentName component = new ComponentName("some.package.name",
+ "some.package.name.SomeClass");
+ final EnforcedAdmin admin = new EnforcedAdmin(component, userId);
+
+ mHelper.showAdminPolicies(admin, mActivity);
+
+ final Intent intent = mActivityShadow.getNextStartedActivity();
+ assertTrue(
+ intent.getBooleanExtra(DeviceAdminAdd.EXTRA_CALLED_FROM_SUPPORT_DIALOG, false));
+ assertEquals(component,
+ intent.getParcelableExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN));
+ }
+
+ @Test
+ public void testShowAdminPoliciesWithoutComponent() {
+ final int userId = 123;
+ final EnforcedAdmin admin = new EnforcedAdmin(null, userId);
+ mHelper.showAdminPolicies(admin, mActivity);
+ final Intent intent = mActivityShadow.getNextStartedActivity();
+ assertEquals(intent.getComponent(), new ComponentName(mActivity,
+ Settings.DeviceAdminSettingsActivity.class.getName()));
+ }
+
+ @Test
+ public void testSetAdminSupportTitle() {
+ final ViewGroup view = new FrameLayout(mActivity);
+ final TextView textView = new TextView(mActivity);
+ textView.setId(R.id.admin_support_dialog_title);
+ view.addView(textView);
+
+ mHelper.setAdminSupportTitle(view, UserManager.DISALLOW_ADJUST_VOLUME);
+ assertEquals(Shadows.shadowOf(textView).innerText(),
+ mActivity.getString(R.string.disabled_by_policy_title_adjust_volume));
+
+ mHelper.setAdminSupportTitle(view, UserManager.DISALLOW_OUTGOING_CALLS);
+ assertEquals(Shadows.shadowOf(textView).innerText(),
+ mActivity.getString(R.string.disabled_by_policy_title_outgoing_calls));
+
+ mHelper.setAdminSupportTitle(view, UserManager.DISALLOW_SMS);
+ assertEquals(Shadows.shadowOf(textView).innerText(),
+ mActivity.getString(R.string.disabled_by_policy_title_sms));
+
+ mHelper.setAdminSupportTitle(view, DevicePolicyManager.POLICY_DISABLE_CAMERA);
+ assertEquals(Shadows.shadowOf(textView).innerText(),
+ mActivity.getString(R.string.disabled_by_policy_title_camera));
+
+ mHelper.setAdminSupportTitle(view, DevicePolicyManager.POLICY_DISABLE_SCREEN_CAPTURE);
+ assertEquals(Shadows.shadowOf(textView).innerText(),
+ mActivity.getString(R.string.disabled_by_policy_title_screen_capture));
+
+ mHelper.setAdminSupportTitle(view, DevicePolicyManager.POLICY_MANDATORY_BACKUPS);
+ assertEquals(Shadows.shadowOf(textView).innerText(),
+ mActivity.getString(R.string.disabled_by_policy_title_turn_off_backups));
+
+ mHelper.setAdminSupportTitle(view, "another restriction");
+ assertEquals(Shadows.shadowOf(textView).innerText(),
+ mActivity.getString(R.string.disabled_by_policy_title));
+
+ mHelper.setAdminSupportTitle(view, null);
+ assertEquals(Shadows.shadowOf(textView).innerText(),
+ mActivity.getString(R.string.disabled_by_policy_title));
+ }
+
+ @Test
+ public void testSetAdminSupportDetails() {
+ final DevicePolicyManager dpm = RuntimeEnvironment.application.getSystemService(
+ DevicePolicyManager.class);
+ final ShadowDevicePolicyManager dpmShadow = Shadow.extract(dpm);
+ final UserManager userManager = RuntimeEnvironment.application.getSystemService(
+ UserManager.class);
+ final ShadowUserManager userManagerShadow = Shadow.extract(userManager);
+ final ViewGroup view = new FrameLayout(mActivity);
+ final ComponentName component = new ComponentName("some.package.name",
+ "some.package.name.SomeClass");
+ final EnforcedAdmin admin = new EnforcedAdmin(component, 123);
+ final TextView textView = new TextView(mActivity);
+
+ textView.setId(R.id.admin_support_msg);
+ view.addView(textView);
+ dpmShadow.setShortSupportMessageForUser(component, 123, "some message");
+ dpmShadow.setIsAdminActiveAsUser(true);
+ userManagerShadow.addProfile(new UserInfo(123, null, 0));
+ ShadowProcess.setMyUid(Process.SYSTEM_UID);
+
+ mHelper.setAdminSupportDetails(mActivity, view, admin);
+ assertNotNull(admin.component);
+ assertEquals("some message", Shadows.shadowOf(textView).innerText());
+ }
+
+ @Test
+ public void testSetAdminSupportDetailsNotAdmin() {
+ final DevicePolicyManager dpm = RuntimeEnvironment.application.getSystemService(
+ DevicePolicyManager.class);
+ final ShadowDevicePolicyManager dpmShadow = Shadow.extract(dpm);
+ final UserManager userManager = RuntimeEnvironment.application.getSystemService(
+ UserManager.class);
+ final ShadowUserManager userManagerShadow = Shadow.extract(userManager);
+ final ComponentName component = new ComponentName("some.package.name",
+ "some.package.name.SomeClass");
+ final EnforcedAdmin admin = new EnforcedAdmin(component, 123);
+
+ dpmShadow.setShortSupportMessageForUser(component, 123, "some message");
+ dpmShadow.setIsAdminActiveAsUser(false);
+ userManagerShadow.addProfile(new UserInfo(123, null, 0));
+
+ mHelper.setAdminSupportDetails(mActivity, null, admin);
+ assertNull(admin.component);
+ }
+}
+
diff --git a/tests/robotests/src/com/android/settings/enterprise/ActionDisabledByAdminDialogTest.java b/tests/robotests/src/com/android/settings/enterprise/ActionDisabledByAdminDialogTest.java
new file mode 100644
index 0000000..ebdfad6
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/enterprise/ActionDisabledByAdminDialogTest.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2018 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.enterprise;
+
+import android.app.admin.DevicePolicyManager;
+import android.content.ComponentName;
+import android.content.Intent;
+import android.os.UserHandle;
+
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class ActionDisabledByAdminDialogTest {
+
+ private ActionDisabledByAdminDialog mDialog;
+
+ @Before
+ public void setUp() {
+ mDialog = new ActionDisabledByAdminDialog();
+ }
+
+ @Test
+ public void testGetAdminDetailsFromIntent() {
+ final int userId = 123;
+ final ComponentName component = new ComponentName("com.some.package", ".SomeClass");
+ final EnforcedAdmin expectedAdmin = new EnforcedAdmin(component, userId);
+
+ final Intent intent = new Intent();
+ intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, component);
+ intent.putExtra(Intent.EXTRA_USER_ID, userId);
+ Assert.assertEquals(expectedAdmin, mDialog.getAdminDetailsFromIntent(intent));
+ }
+
+ @Test
+ public void testGetAdminDetailsFromNullIntent() {
+ final int userId = UserHandle.myUserId();
+ final EnforcedAdmin expectedAdmin = new EnforcedAdmin(null, userId);
+
+ Assert.assertEquals(expectedAdmin, mDialog.getAdminDetailsFromIntent(null));
+ }
+
+ @Test
+ public void testGetRestrictionFromIntent() {
+ final String restriction = "someRestriction";
+ final Intent intent = new Intent();
+
+ intent.putExtra(DevicePolicyManager.EXTRA_RESTRICTION, restriction);
+ Assert.assertEquals(restriction, mDialog.getRestrictionFromIntent(intent));
+ }
+
+ @Test
+ public void testGetRestrictionFromNullIntent() {
+ Assert.assertEquals(null, mDialog.getRestrictionFromIntent(null));
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/search/BaseSearchIndexProviderTest.java b/tests/robotests/src/com/android/settings/search/BaseSearchIndexProviderTest.java
index 905361c..df60654 100644
--- a/tests/robotests/src/com/android/settings/search/BaseSearchIndexProviderTest.java
+++ b/tests/robotests/src/com/android/settings/search/BaseSearchIndexProviderTest.java
@@ -116,7 +116,7 @@
final List<AbstractPreferenceController> controllers =
provider.getPreferenceControllers(mContext);
- assertThat(controllers).hasSize(3);
+ assertThat(controllers).hasSize(2);
}
public static class NotAvailablePreferenceController
diff --git a/tests/robotests/src/com/android/settings/testutils/CustomActivity.java b/tests/robotests/src/com/android/settings/testutils/CustomActivity.java
new file mode 100644
index 0000000..d4c7341
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/testutils/CustomActivity.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2018 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.testutils;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.UserHandle;
+
+public class CustomActivity extends Activity {
+ @Override
+ public void startActivityAsUser(Intent intent, UserHandle user) {}
+}
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowActivity.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowActivity.java
new file mode 100644
index 0000000..0f67bbf
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowActivity.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2018 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.testutils.shadow;
+
+import android.content.Intent;
+import android.os.UserHandle;
+
+import com.android.settings.testutils.CustomActivity;
+
+import org.robolectric.annotation.Implementation;
+import org.robolectric.annotation.Implements;
+import org.robolectric.shadows.ShadowApplication;
+
+@Implements(CustomActivity.class)
+public class ShadowActivity extends org.robolectric.shadows.ShadowActivity {
+
+ @Implementation
+ public void startActivityAsUser(Intent intent, UserHandle user) {
+ ShadowApplication.getInstance().startActivity(intent);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowDevicePolicyManager.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowDevicePolicyManager.java
new file mode 100644
index 0000000..77daae0
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowDevicePolicyManager.java
@@ -0,0 +1,41 @@
+package com.android.settings.testutils.shadow;
+
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.app.admin.DevicePolicyManager;
+import android.content.ComponentName;
+
+import org.robolectric.annotation.Implementation;
+import org.robolectric.annotation.Implements;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * This shadow if using {@link ShadowDevicePolicyManagerWrapper} is not possible.
+ */
+@Implements(DevicePolicyManager.class)
+public class ShadowDevicePolicyManager extends org.robolectric.shadows.ShadowDevicePolicyManager {
+ private Map<Integer, CharSequence> mSupportMessagesMap = new HashMap<>();
+ private boolean mIsAdminActiveAsUser = false;
+
+ public void setShortSupportMessageForUser(ComponentName admin, int userHandle, String message) {
+ mSupportMessagesMap.put(Objects.hash(admin, userHandle), message);
+ }
+
+ @Implementation
+ public @Nullable CharSequence getShortSupportMessageForUser(@NonNull ComponentName admin,
+ int userHandle) {
+ return mSupportMessagesMap.get(Objects.hash(admin, userHandle));
+ }
+
+ @Implementation
+ public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
+ return mIsAdminActiveAsUser;
+ }
+
+ public void setIsAdminActiveAsUser(boolean active) {
+ mIsAdminActiveAsUser = active;
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowProcess.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowProcess.java
new file mode 100644
index 0000000..eea3ee8
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowProcess.java
@@ -0,0 +1,18 @@
+package com.android.settings.testutils.shadow;
+
+import org.robolectric.annotation.Implementation;
+import org.robolectric.annotation.Implements;
+
+@Implements(android.os.Process.class)
+public class ShadowProcess {
+ private static int sUid;
+
+ public static void setMyUid(int uid) {
+ sUid = uid;
+ }
+
+ @Implementation
+ public static int myUid() {
+ return sUid;
+ }
+}
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowUserManager.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowUserManager.java
index dfd4b7f..9979ddb 100644
--- a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowUserManager.java
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowUserManager.java
@@ -17,7 +17,6 @@
package com.android.settings.testutils.shadow;
import android.annotation.UserIdInt;
-import android.content.Context;
import android.content.pm.UserInfo;
import android.os.UserHandle;
import android.os.UserManager;
@@ -31,7 +30,6 @@
import org.robolectric.shadow.api.Shadow;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -42,10 +40,12 @@
private SparseArray<UserInfo> mUserInfos = new SparseArray<>();
private final List<String> mRestrictions = new ArrayList<>();
private final Map<String, List<EnforcingUser>> mRestrictionSources = new HashMap<>();
+ private List<UserInfo> mUserProfileInfos = new ArrayList<>();
@Resetter
public void reset() {
mRestrictions.clear();
+ mUserProfileInfos.clear();
}
public void setUserInfo(int userHandle, UserInfo userInfo) {
@@ -57,9 +57,13 @@
return mUserInfos.get(userHandle);
}
+ public void addProfile(UserInfo userInfo) {
+ mUserProfileInfos.add(userInfo);
+ }
+
@Implementation
public List<UserInfo> getProfiles(@UserIdInt int userHandle) {
- return Collections.emptyList();
+ return mUserProfileInfos;
}
@Implementation
diff --git a/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSettingsForSubTest.java b/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSettingsForSubTest.java
new file mode 100644
index 0000000..d60f8cf
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSettingsForSubTest.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2018 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.wifi.calling;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class WifiCallingSettingsForSubTest {
+
+ @Test
+ public void getHelpResource_shouldReturn0() {
+ assertThat(new WifiCallingSettingsForSub().getHelpResource())
+ .isEqualTo(0);
+ }
+}
diff --git a/tests/robotests/src/libcore/util/CountryTimeZones.java b/tests/robotests/src/libcore/util/CountryTimeZones.java
deleted file mode 100644
index 2087848..0000000
--- a/tests/robotests/src/libcore/util/CountryTimeZones.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (C) 2018 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 libcore.util;
-
-import java.util.List;
-
-/**
- * Empty implementation of CountryTimeZones for Robolectric test.
- */
-public class CountryTimeZones {
- public CountryTimeZones() {
- }
-
- public final static class TimeZoneMapping {
- public final String timeZoneId;
- public final boolean showInPicker;
-
- public TimeZoneMapping(String timeZoneId, boolean showInPicker) {
- this.timeZoneId = timeZoneId;
- this.showInPicker = showInPicker;
- }
- }
-
- public List<TimeZoneMapping> getTimeZoneMappings() {
- return null;
- }
-
- public String getCountryIso() {
- return null;
- }
-}
diff --git a/tests/robotests/src/libcore/util/CountryZonesFinder.java b/tests/robotests/src/libcore/util/CountryZonesFinder.java
deleted file mode 100644
index 51149ec..0000000
--- a/tests/robotests/src/libcore/util/CountryZonesFinder.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (C) 2018 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 libcore.util;
-
-import java.util.List;
-
-/**
- * Empty implementation of CountryZonesFinder for Robolectric test.
- */
-public class CountryZonesFinder {
- public CountryZonesFinder(List<CountryTimeZones> countryTimeZonesList) {}
-
- public List<String> lookupAllCountryIsoCodes() {
- return null;
- }
-
- public List<CountryTimeZones> lookupCountryTimeZonesForZoneId(String zoneId) {
- return null;
- }
-
- public CountryTimeZones lookupCountryTimeZones(String countryIso) {
- return null;
- }
-}
diff --git a/tests/unit/src/com/android/settings/core/UniquePreferenceTest.java b/tests/unit/src/com/android/settings/core/UniquePreferenceTest.java
index e208709..98ffddd 100644
--- a/tests/unit/src/com/android/settings/core/UniquePreferenceTest.java
+++ b/tests/unit/src/com/android/settings/core/UniquePreferenceTest.java
@@ -20,17 +20,16 @@
import android.content.Context;
import android.content.res.Resources;
-import android.content.res.XmlResourceParser;
+import android.os.Bundle;
import android.platform.test.annotations.Presubmit;
import android.provider.SearchIndexableResource;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.MediumTest;
import android.support.test.runner.AndroidJUnit4;
import android.text.TextUtils;
-import android.util.AttributeSet;
import android.util.Log;
-import android.util.Xml;
+import com.android.settings.core.PreferenceXmlParserUtils.MetadataFlag;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.DatabaseIndexingUtils;
import com.android.settings.search.Indexable;
@@ -40,7 +39,6 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
@@ -56,8 +54,7 @@
private static final String TAG = "UniquePreferenceTest";
private static final List<String> IGNORE_PREF_TYPES = Arrays.asList(
"com.android.settingslib.widget.FooterPreference");
- private static final List<String> SUPPORTED_PREF_TYPES = Arrays.asList(
- "Preference", "PreferenceCategory", "PreferenceScreen");
+
private static final List<String> WHITELISTED_DUPLICATE_KEYS = Arrays.asList(
"owner_info_settings", // Lock screen message in security - multiple xml files
// contain this because security page is constructed by
@@ -177,48 +174,32 @@
}
for (SearchIndexableResource sir : resourcesToIndex) {
- if (sir.xmlResId <= 0) {
- Log.d(TAG, className + " doesn't have a valid xml to index.");
- continue;
- }
- final XmlResourceParser parser = mContext.getResources().getXml(sir.xmlResId);
+ final List<Bundle> metadata = PreferenceXmlParserUtils.extractMetadata(mContext,
+ sir.xmlResId,
+ MetadataFlag.FLAG_INCLUDE_PREF_SCREEN
+ | MetadataFlag.FLAG_NEED_KEY
+ | MetadataFlag.FLAG_NEED_PREF_TYPE);
- int type;
- while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
- && type != XmlPullParser.START_TAG) {
- // Parse next until start tag is found
- }
- final int outerDepth = parser.getDepth();
-
- do {
- if (type != XmlPullParser.START_TAG) {
+ for (Bundle bundle : metadata) {
+ final String type = bundle.getString(PreferenceXmlParserUtils.METADATA_PREF_TYPE);
+ if (IGNORE_PREF_TYPES.contains(type)) {
continue;
}
- final String nodeName = parser.getName();
- if (IGNORE_PREF_TYPES.contains(nodeName)) {
- continue;
- }
- if (!SUPPORTED_PREF_TYPES.contains(nodeName) && !nodeName.endsWith("Preference")) {
- continue;
- }
- final AttributeSet attrs = Xml.asAttributeSet(parser);
- final String key = PreferenceXmlParserUtils.getDataKey(mContext, attrs);
+ final String key = bundle.getString(PreferenceXmlParserUtils.METADATA_KEY);
if (TextUtils.isEmpty(key)) {
Log.e(TAG, "Every preference must have an key; found null key"
- + " in " + className
- + " at " + parser.getPositionDescription());
+ + " in " + className);
nullKeyClasses.add(className);
continue;
}
if (uniqueKeys.contains(key) && !WHITELISTED_DUPLICATE_KEYS.contains(key)) {
- Log.e(TAG, "Every preference key must unique; found " + nodeName
+ Log.e(TAG, "Every preference key must unique; found "
+ " in " + className
- + " at " + parser.getPositionDescription());
+ + " / " + key);
duplicatedKeys.add(key);
}
uniqueKeys.add(key);
- } while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
- && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth));
+ }
}
}