Merge "(2/n) Stop user from enabling OHM setting if user is using 3-button mode" into sc-dev
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 193f521..8a6ff0d 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -7756,6 +7756,8 @@
<string name="help_url_battery_missing" translatable="false"></string>
<!-- url for vpn page if connected vpn is not a secure type -->
<string name="help_url_insecure_vpn" translatable="false"></string>
+ <!-- url for learning more about IT admin policy disabling -->
+ <string name="help_url_action_disabled_by_it_admin" translatable="false"></string>
<!-- User account title [CHAR LIMIT=30] -->
<string name="user_account_title">Account for content</string>
@@ -10823,22 +10825,24 @@
<!-- Summary of Android version info (when there is a pending upgrade available) [CHAR LIMIT=NONE] -->
<string name="android_version_pending_update_summary">Update available</string>
- <!-- Title for dialog displayed when user selects on a setting locked by an admin [CHAR LIMIT=30 BACKUP_MESSAGE_ID:4867639270211833535] -->
- <string name="disabled_by_policy_title">Action not allowed</string>
- <!-- Title for dialog displayed to tell user that changing volume was disallowed by an admin [CHAR LIMIT=50] -->
+ <!-- Title for dialog displayed when user taps a setting on their phone that's blocked by their IT admin [CHAR LIMIT=30 BACKUP_MESSAGE_ID:4867639270211833535] -->
+ <string name="disabled_by_policy_title">Blocked by your IT admin</string>
+ <!-- Title for dialog displayed to tell user that changing volume on their phone is blocked by their IT admin [CHAR LIMIT=50] -->
<string name="disabled_by_policy_title_adjust_volume">Can’t change volume</string>
- <!-- Title for dialog displayed to tell user that outgoing calls were disabled by an admin [CHAR LIMIT=50] -->
- <string name="disabled_by_policy_title_outgoing_calls">Calling not allowed</string>
- <!-- Title for dialog displayed to tell user that sending SMS were disabled by an admin [CHAR LIMIT=50] -->
- <string name="disabled_by_policy_title_sms">SMS not allowed</string>
- <!-- Title for dialog displayed to tell user that the camera was disabled by an admin [CHAR LIMIT=50] -->
- <string name="disabled_by_policy_title_camera">Camera not allowed</string>
- <!-- Title for dialog displayed to tell user that screenshots are disabled by an admin [CHAR LIMIT=50] -->
- <string name="disabled_by_policy_title_screen_capture">Screenshot not allowed</string>
+ <!-- Title for dialog displayed to tell user that outgoing calls are blocked by their IT admin [CHAR LIMIT=50] -->
+ <string name="disabled_by_policy_title_outgoing_calls">Can’t make calls</string>
+ <!-- Title for dialog displayed to tell user that sending SMS messages is blocked by their IT admin [CHAR LIMIT=50] -->
+ <string name="disabled_by_policy_title_sms">Can’t send SMS messages</string>
+ <!-- Title for dialog displayed to tell user that the camera on their phone is blocked by their IT admin [CHAR LIMIT=50] -->
+ <string name="disabled_by_policy_title_camera">Can’t use camera</string>
+ <!-- Title for dialog displayed to tell user that taking screenshots on their phone is blocked by their IT admin [CHAR LIMIT=50] -->
+ <string name="disabled_by_policy_title_screen_capture">Can’t take screenshots</string>
<!-- Title for dialog displayed to tell user that the app was suspended by an admin [CHAR LIMIT=50] -->
<string name="disabled_by_policy_title_suspend_packages">Can’t open this app</string>
<!-- Dialog title. This dialog lets a user know that a specific setting is blocked by their credit provider. Since the user purchased the device from the credit provider, the credit provider controls what they can access. [CHAR LIMIT=50] -->
<string name="disabled_by_policy_title_financed_device">Blocked by your credit provider</string>
+ <!-- Shown when the user tries to change phone settings that are blocked by their IT admin [CHAR LIMIT=200] -->
+ <string name="default_admin_support_msg">If you have questions, contact your IT admin</string>
<!-- Shown in dialog to allow user to see more information about the device admin [CHAR LIMIT=30] -->
<string name="admin_support_more_info">More details</string>
<!-- Shown in admin details page to warn user about policies the admin can set in a work profile. [CHAR LIMIT=NONE] -->
diff --git a/src/com/android/settings/applications/appinfo/AlarmsAndRemindersDetails.java b/src/com/android/settings/applications/appinfo/AlarmsAndRemindersDetails.java
index 25d7332..3765dd9 100644
--- a/src/com/android/settings/applications/appinfo/AlarmsAndRemindersDetails.java
+++ b/src/com/android/settings/applications/appinfo/AlarmsAndRemindersDetails.java
@@ -81,6 +81,9 @@
if (savedInstanceState != null) {
mUncommittedState = (Boolean) savedInstanceState.get(UNCOMMITTED_STATE_KEY);
+ if (mUncommittedState != null && isAppSpecific()) {
+ setResult(mUncommittedState ? RESULT_OK : RESULT_CANCELED);
+ }
}
addPreferencesFromResource(R.xml.alarms_and_reminders);
mSwitchPref = findPreference(KEY_SWITCH);
@@ -97,9 +100,11 @@
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
- final boolean checked = (Boolean) newValue;
if (preference == mSwitchPref) {
- mUncommittedState = checked;
+ mUncommittedState = (Boolean) newValue;
+ if (isAppSpecific()) {
+ setResult(mUncommittedState ? RESULT_OK : RESULT_CANCELED);
+ }
refreshUi();
return true;
}
@@ -125,6 +130,11 @@
newState ? 1 : 0);
}
+ private boolean isAppSpecific() {
+ return Settings.AlarmsAndRemindersAppActivity.class.getName().equals(
+ getIntent().getComponent().getClassName());
+ }
+
@Override
public void onPause() {
super.onPause();
@@ -133,10 +143,6 @@
}
if (mPermissionState != null && mUncommittedState != null
&& mUncommittedState != mPermissionState.isAllowed()) {
- if (Settings.AlarmsAndRemindersAppActivity.class.getName().equals(
- getIntent().getComponent().getClassName())) {
- setResult(mUncommittedState ? RESULT_OK : RESULT_CANCELED);
- }
setCanScheduleAlarms(mUncommittedState);
logPermissionChange(mUncommittedState, mPackageName);
mUncommittedState = null;
diff --git a/src/com/android/settings/applications/appinfo/AppButtonsPreferenceController.java b/src/com/android/settings/applications/appinfo/AppButtonsPreferenceController.java
index c3031ef..ea34faf 100644
--- a/src/com/android/settings/applications/appinfo/AppButtonsPreferenceController.java
+++ b/src/com/android/settings/applications/appinfo/AppButtonsPreferenceController.java
@@ -269,6 +269,8 @@
@Override
public void onClick(View v) {
+ mMetricsFeatureProvider.action(
+ mActivity, SettingsEnums.ACTION_APP_INFO_FORCE_STOP);
// force stop
if (mAppsControlDisallowedAdmin != null && !mAppsControlDisallowedBySystem) {
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(
@@ -724,6 +726,8 @@
mPackageName, AUTO_REVOKED_APP_INTERACTION__ACTION__OPEN_IN_SETTINGS);
}
mContext.startActivityAsUser(mAppLaunchIntent, new UserHandle(mUserId));
+ mMetricsFeatureProvider.action(mActivity,
+ SettingsEnums.ACTION_APP_INFO_OPEN, mPackageName);
}
}
diff --git a/src/com/android/settings/display/BatteryPercentagePreferenceController.java b/src/com/android/settings/display/BatteryPercentagePreferenceController.java
index 945ce47..448fb2b 100644
--- a/src/com/android/settings/display/BatteryPercentagePreferenceController.java
+++ b/src/com/android/settings/display/BatteryPercentagePreferenceController.java
@@ -17,6 +17,7 @@
import static android.provider.Settings.System.SHOW_BATTERY_PERCENT;
+import android.app.settings.SettingsEnums;
import android.content.Context;
import android.provider.Settings;
@@ -28,6 +29,7 @@
import com.android.settings.Utils;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settings.overlay.FeatureFactory;
/**
* A controller to manage the switch for showing battery percentage in the status bar.
@@ -75,6 +77,8 @@
boolean showPercentage = (Boolean) newValue;
Settings.System.putInt(mContext.getContentResolver(), SHOW_BATTERY_PERCENT,
showPercentage ? 1 : 0);
+ FeatureFactory.getFactory(mContext).getMetricsFeatureProvider()
+ .action(mContext, SettingsEnums.OPEN_BATTERY_PERCENTAGE, showPercentage);
return true;
}
}
diff --git a/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelper.java b/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelper.java
index 1140291..86ffa47 100644
--- a/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelper.java
+++ b/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelper.java
@@ -16,21 +16,17 @@
package com.android.settings.enterprise;
-import static android.app.admin.DevicePolicyManager.DEVICE_OWNER_TYPE_FINANCED;
-
import android.annotation.NonNull;
import android.annotation.UserIdInt;
import android.app.Activity;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
-import android.content.Intent;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Process;
import android.os.UserHandle;
-import android.os.UserManager;
import android.util.IconDrawableFactory;
import android.view.LayoutInflater;
import android.view.View;
@@ -42,12 +38,12 @@
import androidx.appcompat.app.AlertDialog;
import com.android.settings.R;
-import com.android.settings.Settings;
import com.android.settings.Utils;
-import com.android.settings.applications.specialaccess.deviceadmin.DeviceAdminAdd;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import com.android.settingslib.RestrictedLockUtilsInternal;
+import com.android.settingslib.enterprise.ActionDisabledByAdminController;
+import com.android.settingslib.enterprise.ActionDisabledByAdminControllerFactory;
import java.util.Objects;
@@ -60,10 +56,16 @@
@VisibleForTesting EnforcedAdmin mEnforcedAdmin;
private ViewGroup mDialogView;
private String mRestriction = null;
- private Activity mActivity;
+ private final Activity mActivity;
+ private final ActionDisabledByAdminController mActionDisabledByAdminController;
public ActionDisabledByAdminDialogHelper(Activity activity) {
mActivity = activity;
+ mActionDisabledByAdminController =
+ ActionDisabledByAdminControllerFactory.createInstance(
+ mActivity.getSystemService(DevicePolicyManager.class),
+ new ActionDisabledLearnMoreButtonLauncherImpl(),
+ new DeviceAdminStringProviderImpl(mActivity));
}
private @UserIdInt int getEnforcementAdminUserId(@NonNull EnforcedAdmin admin) {
@@ -83,10 +85,10 @@
mEnforcedAdmin = enforcedAdmin;
mRestriction = restriction;
final AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
- mDialogView = (ViewGroup) LayoutInflater.from(builder.getContext()).inflate(
+ mDialogView = (ViewGroup) LayoutInflater.from(mActivity).inflate(
R.layout.admin_support_details_dialog, null);
- initializeDialogViews(mDialogView, mEnforcedAdmin.component, getEnforcementAdminUserId(),
- mRestriction);
+ initializeDialogViews(mDialogView, mEnforcedAdmin, getEnforcementAdminUserId(),
+ mRestriction, mActionDisabledByAdminController);
builder.setPositiveButton(R.string.okay, null).setView(mDialogView);
maybeSetLearnMoreButton(builder);
return builder;
@@ -94,16 +96,7 @@
@VisibleForTesting
void maybeSetLearnMoreButton(AlertDialog.Builder builder) {
- // The "Learn more" button appears only if the restriction is enforced by an admin in the
- // same profile group. Otherwise the admin package and its policies are not accessible to
- // the current user.
- final UserManager um = UserManager.get(mActivity.getApplicationContext());
- if (um.isSameProfileGroup(getEnforcementAdminUserId(mEnforcedAdmin), um.getUserHandle())) {
- builder.setNeutralButton(R.string.learn_more, (dialog, which) -> {
- showAdminPolicies(mEnforcedAdmin, mActivity);
- mActivity.finish();
- });
- }
+ mActionDisabledByAdminController.setupLearnMoreButton(mActivity, builder);
}
public void updateDialog(String restriction, EnforcedAdmin admin) {
@@ -112,16 +105,18 @@
}
mEnforcedAdmin = admin;
mRestriction = restriction;
- initializeDialogViews(mDialogView, mEnforcedAdmin.component, getEnforcementAdminUserId(),
- mRestriction);
+ initializeDialogViews(mDialogView, mEnforcedAdmin, getEnforcementAdminUserId(),
+ mRestriction, mActionDisabledByAdminController);
}
- private void initializeDialogViews(View root, ComponentName admin, int userId,
- String restriction) {
+ private void initializeDialogViews(View root, EnforcedAdmin enforcedAdmin, int userId,
+ String restriction, ActionDisabledByAdminController controller) {
+ ComponentName admin = enforcedAdmin.component;
if (admin == null) {
return;
}
+ controller.updateEnforcedAdmin(enforcedAdmin, userId);
setAdminSupportIcon(root, admin, userId);
if (isNotCurrentUserOrProfile(admin, userId)) {
@@ -171,37 +166,8 @@
if (titleView == null) {
return;
}
- if (isFinancedDevice()) {
- titleView.setText(R.string.disabled_by_policy_title_financed_device);
- 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_SUSPEND_PACKAGES:
- titleView.setText(R.string.disabled_by_policy_title_suspend_packages);
- break;
- default:
- // Use general text if no specialized title applies
- titleView.setText(R.string.disabled_by_policy_title);
- }
+ titleView.setText(
+ mActionDisabledByAdminController.getAdminSupportTitle(restriction));
}
@VisibleForTesting
@@ -227,34 +193,12 @@
getEnforcementAdminUserId(enforcedAdmin));
}
}
+ final CharSequence supportContentString =
+ mActionDisabledByAdminController.getAdminSupportContentString(
+ mActivity, supportMessage);
final TextView textView = root.findViewById(R.id.admin_support_msg);
- if (supportMessage != null) {
- textView.setText(supportMessage);
+ if (supportContentString != null) {
+ textView.setText(supportContentString);
}
}
-
- @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, enforcedAdmin.user);
- } 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);
- }
- }
-
- private boolean isFinancedDevice() {
- final DevicePolicyManager dpm = mActivity.getSystemService(DevicePolicyManager.class);
- return dpm.isDeviceManaged() && dpm.getDeviceOwnerType(
- dpm.getDeviceOwnerComponentOnAnyUser()) == DEVICE_OWNER_TYPE_FINANCED;
- }
}
diff --git a/src/com/android/settings/enterprise/ActionDisabledLearnMoreButtonLauncherImpl.java b/src/com/android/settings/enterprise/ActionDisabledLearnMoreButtonLauncherImpl.java
new file mode 100644
index 0000000..b4d97e4
--- /dev/null
+++ b/src/com/android/settings/enterprise/ActionDisabledLearnMoreButtonLauncherImpl.java
@@ -0,0 +1,121 @@
+/*
+ * Copyright (C) 2021 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 java.util.Objects.requireNonNull;
+
+import android.app.Activity;
+import android.app.admin.DevicePolicyManager;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.UserHandle;
+import android.os.UserManager;
+
+import androidx.appcompat.app.AlertDialog;
+
+import com.android.settings.R;
+import com.android.settings.Settings;
+import com.android.settings.applications.specialaccess.deviceadmin.DeviceAdminAdd;
+import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
+import com.android.settingslib.enterprise.ActionDisabledLearnMoreButtonLauncher;
+
+import java.util.function.BiConsumer;
+
+/**
+ * Helper class to set up the "Learn more" button in the action disabled dialog.
+ */
+public class ActionDisabledLearnMoreButtonLauncherImpl
+ implements ActionDisabledLearnMoreButtonLauncher {
+
+ static final BiConsumer<Activity, EnforcedAdmin> SHOW_ADMIN_POLICIES =
+ (activity, enforcedAdmin) -> {
+ showAdminPolicies(enforcedAdmin, activity);
+ activity.finish();
+ };
+
+ static final BiConsumer<Activity, String> LAUNCH_HELP_PAGE = (activity, url) -> {
+ launchLearnMoreHelpPage(activity, url);
+ activity.finish();
+ };
+
+ @Override
+ public void setupLearnMoreButtonToShowAdminPolicies(
+ Activity activity,
+ AlertDialog.Builder builder,
+ int enforcementAdminUserId,
+ EnforcedAdmin enforcedAdmin) {
+ requireNonNull(activity);
+ requireNonNull(builder);
+ requireNonNull(enforcedAdmin);
+ // The "Learn more" button appears only if the restriction is enforced by an admin in the
+ // same profile group. Otherwise the admin package and its policies are not accessible to
+ // the current user.
+ final UserManager um = UserManager.get(activity);
+ if (um.isSameProfileGroup(enforcementAdminUserId, um.getUserHandle())) {
+ setupLearnMoreButton(builder, () ->
+ SHOW_ADMIN_POLICIES.accept(activity, enforcedAdmin));
+ }
+ }
+
+ @Override
+ public void setupLearnMoreButtonToLaunchHelpPage(
+ Activity activity,
+ AlertDialog.Builder builder,
+ String url) {
+ requireNonNull(activity);
+ requireNonNull(builder);
+ requireNonNull(url);
+ setupLearnMoreButton(builder, () -> LAUNCH_HELP_PAGE.accept(activity, url));
+ }
+
+ private void setupLearnMoreButton(AlertDialog.Builder builder, Runnable runnable) {
+ builder.setNeutralButton(R.string.learn_more, (dialog, which) -> {
+ runnable.run();
+ });
+ }
+
+ private static void launchLearnMoreHelpPage(Activity activity, String url) {
+ activity.startActivityAsUser(createLearnMoreIntent(url), UserHandle.SYSTEM);
+ }
+
+ private static Intent createLearnMoreIntent(String url) {
+ final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
+ | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
+ return intent;
+ }
+
+ private static void showAdminPolicies(
+ EnforcedAdmin enforcedAdmin,
+ 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, enforcedAdmin.user);
+ } 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/DeviceAdminStringProviderImpl.java b/src/com/android/settings/enterprise/DeviceAdminStringProviderImpl.java
new file mode 100644
index 0000000..68b2021
--- /dev/null
+++ b/src/com/android/settings/enterprise/DeviceAdminStringProviderImpl.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2021 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 java.util.Objects.requireNonNull;
+
+import android.content.Context;
+
+import com.android.settings.R;
+import com.android.settingslib.enterprise.DeviceAdminStringProvider;
+
+class DeviceAdminStringProviderImpl implements DeviceAdminStringProvider {
+ private final Context mContext;
+
+ DeviceAdminStringProviderImpl(Context context) {
+ mContext = requireNonNull(context);
+ }
+
+ @Override
+ public String getDefaultDisabledByPolicyTitle() {
+ return mContext.getString(R.string.disabled_by_policy_title);
+ }
+
+ @Override
+ public String getDisallowAdjustVolumeTitle() {
+ return mContext.getString(R.string.disabled_by_policy_title_adjust_volume);
+ }
+
+ @Override
+ public String getDisallowOutgoingCallsTitle() {
+ return mContext.getString(R.string.disabled_by_policy_title_outgoing_calls);
+ }
+
+ @Override
+ public String getDisallowSmsTitle() {
+ return mContext.getString(R.string.disabled_by_policy_title_sms);
+ }
+
+ @Override
+ public String getDisableCameraTitle() {
+ return mContext.getString(R.string.disabled_by_policy_title_camera);
+ }
+
+ @Override
+ public String getDisableScreenCaptureTitle() {
+ return mContext.getString(R.string.disabled_by_policy_title_screen_capture);
+ }
+
+ @Override
+ public String getSuspendPackagesTitle() {
+ return mContext.getString(R.string.disabled_by_policy_title_suspend_packages);
+ }
+
+ @Override
+ public String getDefaultDisabledByPolicyContent() {
+ return mContext.getString(R.string.default_admin_support_msg);
+ }
+
+ @Override
+ public String getLearnMoreHelpPageUrl() {
+ return mContext.getString(R.string.help_url_action_disabled_by_it_admin);
+ }
+
+ @Override
+ public String getDisabledByPolicyTitleForFinancedDevice() {
+ return mContext.getString(R.string.disabled_by_policy_title_financed_device);
+ }
+}
diff --git a/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java b/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
index 2b83288..965994d 100644
--- a/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
+++ b/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
@@ -49,6 +49,7 @@
import com.android.settingslib.applications.AppUtils;
import com.android.settingslib.applications.ApplicationsState;
import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.android.settingslib.utils.StringUtil;
import com.android.settingslib.widget.LayoutPreference;
import com.android.settingslib.widget.RadioButtonPreference;
@@ -113,6 +114,7 @@
@VisibleForTesting
boolean enableTriState = true;
+ private MetricsFeatureProvider mMetricsFeatureProvider;
private AppButtonsPreferenceController mAppButtonsPreferenceController;
private BackgroundActivityPreferenceController mBackgroundActivityPreferenceController;
@@ -240,6 +242,8 @@
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
+ mMetricsFeatureProvider = FeatureFactory.getFactory(getContext())
+ .getMetricsFeatureProvider();
final String packageName = getArguments().getString(EXTRA_PACKAGE_NAME);
if (enableTriState) {
@@ -262,6 +266,9 @@
initHeader();
if (enableTriState) {
initPreferenceForTriState(getContext());
+ final String packageName = mBatteryOptimizeUtils.getPackageName();
+ mMetricsFeatureProvider.action(getContext(),
+ SettingsEnums.OPEN_APP_BATTERY_USAGE, packageName);
} else {
initPreference(getContext());
}
@@ -411,9 +418,24 @@
@Override
public void onRadioButtonClicked(RadioButtonPreference selected) {
- updatePreferenceState(mUnrestrictedPreference, selected.getKey());
- updatePreferenceState(mOptimizePreference, selected.getKey());
- updatePreferenceState(mRestrictedPreference, selected.getKey());
+ final String selectedKey = selected.getKey();
+ updatePreferenceState(mUnrestrictedPreference, selectedKey);
+ updatePreferenceState(mOptimizePreference, selectedKey);
+ updatePreferenceState(mRestrictedPreference, selectedKey);
+
+ // Logs metric.
+ int metricCategory = 0;
+ if (selectedKey.equals(mUnrestrictedPreference.getKey())) {
+ metricCategory = SettingsEnums.ACTION_APP_BATTERY_USAGE_UNRESTRICTED;
+ } else if (selectedKey.equals(mOptimizePreference.getKey())) {
+ metricCategory = SettingsEnums.ACTION_APP_BATTERY_USAGE_OPTIMIZED;
+ } else if (selectedKey.equals(mRestrictedPreference.getKey())) {
+ metricCategory = SettingsEnums.ACTION_APP_BATTERY_USAGE_RESTRICTED;
+ }
+ if (metricCategory != 0) {
+ mMetricsFeatureProvider.action(getContext(),
+ metricCategory, mBatteryOptimizeUtils.getPackageName());
+ }
}
private void updatePreferenceState(RadioButtonPreference preference, String selectedKey) {
diff --git a/src/com/android/settings/fuelgauge/BatteryOptimizeUtils.java b/src/com/android/settings/fuelgauge/BatteryOptimizeUtils.java
index 1184a77..4a56040 100644
--- a/src/com/android/settings/fuelgauge/BatteryOptimizeUtils.java
+++ b/src/com/android/settings/fuelgauge/BatteryOptimizeUtils.java
@@ -27,6 +27,7 @@
/** A utility class for application usage operation. */
public class BatteryOptimizeUtils {
private static final String TAG = "BatteryOptimizeUtils";
+ private static final String UNKNOWN_PACKAGE = "unknown";
@VisibleForTesting AppOpsManager mAppOpsManager;
@VisibleForTesting BatteryUtils mBatteryUtils;
@@ -108,6 +109,10 @@
|| mPowerAllowListBackend.isDefaultActiveApp(mPackageName);
}
+ String getPackageName() {
+ return mPackageName == null ? UNKNOWN_PACKAGE : mPackageName;
+ }
+
private void refreshState() {
mPowerAllowListBackend.refreshList();
mAllowListed = mPowerAllowListBackend.isAllowlisted(mPackageName);
diff --git a/src/com/android/settings/fuelgauge/RestrictAppPreferenceController.java b/src/com/android/settings/fuelgauge/RestrictAppPreferenceController.java
index 1460d75..b960d4c 100644
--- a/src/com/android/settings/fuelgauge/RestrictAppPreferenceController.java
+++ b/src/com/android/settings/fuelgauge/RestrictAppPreferenceController.java
@@ -18,6 +18,7 @@
package com.android.settings.fuelgauge;
import android.app.AppOpsManager;
+import android.app.settings.SettingsEnums;
import android.content.Context;
import android.os.UserManager;
@@ -29,6 +30,7 @@
import com.android.settings.core.InstrumentedPreferenceFragment;
import com.android.settings.fuelgauge.batterytip.AppInfo;
import com.android.settings.fuelgauge.batterytip.BatteryTipUtils;
+import com.android.settings.overlay.FeatureFactory;
import java.util.List;
@@ -80,6 +82,8 @@
// start fragment
RestrictedAppDetails.startRestrictedAppDetails(mPreferenceFragment,
mAppInfos);
+ FeatureFactory.getFactory(mContext).getMetricsFeatureProvider()
+ .action(mContext, SettingsEnums.OPEN_APP_RESTRICTED_LIST);
return true;
}
diff --git a/src/com/android/settings/fuelgauge/RestrictedAppDetails.java b/src/com/android/settings/fuelgauge/RestrictedAppDetails.java
index db83140..77eaa23 100644
--- a/src/com/android/settings/fuelgauge/RestrictedAppDetails.java
+++ b/src/com/android/settings/fuelgauge/RestrictedAppDetails.java
@@ -44,8 +44,10 @@
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
import com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip;
import com.android.settings.fuelgauge.batterytip.tips.UnrestrictAppTip;
+import com.android.settings.overlay.FeatureFactory;
import com.android.settings.widget.AppCheckBoxPreference;
import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.android.settingslib.utils.StringUtil;
import java.util.List;
@@ -76,6 +78,8 @@
@VisibleForTesting
BatteryDatabaseManager mBatteryDatabaseManager;
+ private MetricsFeatureProvider mMetricsFeatureProvider;
+
public static void startRestrictedAppDetails(InstrumentedPreferenceFragment fragment,
List<AppInfo> appInfos) {
final Bundle args = new Bundle();
@@ -100,7 +104,8 @@
mIconDrawableFactory = IconDrawableFactory.newInstance(context);
mBatteryUtils = BatteryUtils.getInstance(context);
mBatteryDatabaseManager = BatteryDatabaseManager.getInstance(context);
-
+ mMetricsFeatureProvider =
+ FeatureFactory.getFactory(getContext()).getMetricsFeatureProvider();
refreshUi();
}
@@ -162,7 +167,9 @@
(Boolean) value);
fragment.setTargetFragment(this, 0 /* requestCode */);
fragment.show(getFragmentManager(), TAG);
-
+ mMetricsFeatureProvider.action(getContext(),
+ SettingsEnums.ACTION_APP_RESTRICTED_LIST_UNCHECKED,
+ appInfo.packageName);
return false;
});
diff --git a/src/com/android/settings/network/telephony/Enable2gPreferenceController.java b/src/com/android/settings/network/telephony/Enable2gPreferenceController.java
index 5c7d224..5ae04ed 100644
--- a/src/com/android/settings/network/telephony/Enable2gPreferenceController.java
+++ b/src/com/android/settings/network/telephony/Enable2gPreferenceController.java
@@ -80,7 +80,7 @@
&& carrierConfig != null
&& !carrierConfig.getBoolean(CarrierConfigManager.KEY_HIDE_ENABLE_2G)
&& mTelephonyManager.isRadioInterfaceCapabilitySupported(
- mTelephonyManager.CAPABILITY_ALLOWED_NETWORK_TYPES_USED);
+ mTelephonyManager.CAPABILITY_USES_ALLOWED_NETWORK_TYPES_BITMASK);
return visible ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
}
diff --git a/tests/robotests/Android.bp b/tests/robotests/Android.bp
index 337bad7..9b2e97f 100644
--- a/tests/robotests/Android.bp
+++ b/tests/robotests/Android.bp
@@ -72,10 +72,11 @@
static_libs: [
"SettingsLib-robo-testutils",
- "android-support-annotations",
+ "android-support-annotations",
"androidx.test.core",
"androidx.test.runner",
"androidx.test.ext.junit",
+ "androidx.test.espresso.core",
],
libs: [
diff --git a/tests/robotests/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelperTest.java b/tests/robotests/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelperTest.java
index 5c3dacd..6acc72f 100644
--- a/tests/robotests/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelperTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelperTest.java
@@ -21,7 +21,6 @@
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 static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
@@ -31,7 +30,6 @@
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.UserHandle;
@@ -43,8 +41,6 @@
import androidx.appcompat.app.AlertDialog;
import com.android.settings.R;
-import com.android.settings.Settings;
-import com.android.settings.applications.specialaccess.deviceadmin.DeviceAdminAdd;
import com.android.settings.testutils.CustomActivity;
import com.android.settings.testutils.shadow.ShadowActivity;
import com.android.settings.testutils.shadow.ShadowDevicePolicyManager;
@@ -69,6 +65,11 @@
ShadowActivity.class
})
public class ActionDisabledByAdminDialogHelperTest {
+ private static final ComponentName ADMIN_COMPONENT =
+ new ComponentName("some.package.name", "some.package.name.SomeClass");
+ private static final int USER_ID = 123;
+ private static final EnforcedAdmin ENFORCED_ADMIN =
+ new EnforcedAdmin(ADMIN_COMPONENT, UserHandle.of(USER_ID));
private ActionDisabledByAdminDialogHelper mHelper;
private Activity mActivity;
private org.robolectric.shadows.ShadowActivity mActivityShadow;
@@ -81,32 +82,6 @@
}
@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, UserHandle.of(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, UserHandle.of(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 = createAdminSupportDialogTitleTextView(view, mActivity);
@@ -150,6 +125,7 @@
final ViewGroup view = new FrameLayout(mActivity);
final TextView textView = createAdminSupportDialogTitleTextView(view, mActivity);
setupFinancedDevice(dpmShadow);
+ mHelper = new ActionDisabledByAdminDialogHelper(mActivity);
mHelper.setAdminSupportTitle(view, null);
@@ -196,7 +172,8 @@
mHelper.setAdminSupportDetails(mActivity, view, admin);
assertNotNull(admin.component);
- assertEquals("", Shadows.shadowOf(textView).innerText());
+ assertEquals(mActivity.getString(R.string.default_admin_support_msg),
+ Shadows.shadowOf(textView).innerText());
}
@Test
@@ -217,7 +194,8 @@
mHelper.setAdminSupportDetails(mActivity, textView, admin);
assertNull(admin.component);
- assertEquals("", Shadows.shadowOf(textView).innerText());
+ assertEquals(mActivity.getString(R.string.default_admin_support_msg),
+ Shadows.shadowOf(textView).innerText());
}
@Test
@@ -225,12 +203,11 @@
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");
- mHelper.mEnforcedAdmin = new EnforcedAdmin(component, UserHandle.of(123));
+ mHelper.prepareDialogBuilder(
+ /* restriction= */ null, ENFORCED_ADMIN);
// Set up for shadow call.
- userManagerShadow.getSameProfileGroupIds().put(123, 0);
+ userManagerShadow.getSameProfileGroupIds().put(USER_ID, 0);
// Test that the button is shown when user IDs are in the same profile group
AlertDialog.Builder builder = mock(AlertDialog.Builder.class);
diff --git a/tests/unit/src/com/android/settings/enterprise/ActionDisabledLearnMoreButtonLauncherImplTest.java b/tests/unit/src/com/android/settings/enterprise/ActionDisabledLearnMoreButtonLauncherImplTest.java
new file mode 100644
index 0000000..68468ed
--- /dev/null
+++ b/tests/unit/src/com/android/settings/enterprise/ActionDisabledLearnMoreButtonLauncherImplTest.java
@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) 2021 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 android.app.admin.DevicePolicyManager.EXTRA_DEVICE_ADMIN;
+
+import static com.android.settings.applications.specialaccess.deviceadmin.DeviceAdminAdd.EXTRA_CALLED_FROM_SUPPORT_DIALOG;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.verify;
+
+import android.app.Activity;
+import android.content.ComponentName;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.UserHandle;
+
+import androidx.test.runner.AndroidJUnit4;
+
+import com.android.settings.Settings;
+import com.android.settings.applications.specialaccess.deviceadmin.DeviceAdminAdd;
+import com.android.settingslib.RestrictedLockUtils;
+import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+
+@RunWith(AndroidJUnit4.class)
+public class ActionDisabledLearnMoreButtonLauncherImplTest {
+
+ private static final int ENFORCED_ADMIN_USER_ID = 123;
+ private static final ComponentName ADMIN_COMPONENT =
+ new ComponentName("some.package.name", "some.package.name.SomeClass");
+ private static final String URL = "https://testexample.com";
+ private static final Uri URI = Uri.parse(URL);
+
+ @Mock
+ private Activity mActivity;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void showAdminPolicies_noComponent_works() {
+ final EnforcedAdmin enforcedAdmin = createEnforcedAdmin(/* component= */ null);
+
+ ActionDisabledLearnMoreButtonLauncherImpl.SHOW_ADMIN_POLICIES
+ .accept(mActivity, enforcedAdmin);
+
+ final ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
+ verify(mActivity).startActivity(captor.capture());
+ assertThat(captor.getValue().getComponent().getClassName())
+ .isEqualTo(Settings.DeviceAdminSettingsActivity.class.getName());
+ }
+
+ @Test
+ public void showAdminPolicies_withComponent_works() {
+ final EnforcedAdmin enforcedAdmin = createEnforcedAdmin(ADMIN_COMPONENT);
+
+ ActionDisabledLearnMoreButtonLauncherImpl.SHOW_ADMIN_POLICIES
+ .accept(mActivity, enforcedAdmin);
+
+ final ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
+ verify(mActivity).startActivityAsUser(
+ captor.capture(),
+ eq(UserHandle.of(ENFORCED_ADMIN_USER_ID)));
+ assertDeviceAdminAddIntent(captor.getValue());
+ }
+
+ @Test
+ public void launchHelpPage_works() {
+ ActionDisabledLearnMoreButtonLauncherImpl.LAUNCH_HELP_PAGE.accept(mActivity, URL);
+
+ final ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
+ verify(mActivity).startActivityAsUser(captor.capture(), eq(UserHandle.SYSTEM));
+ assertActionViewIntent(captor.getValue());
+ }
+
+ private EnforcedAdmin createEnforcedAdmin(ComponentName component) {
+ return new RestrictedLockUtils.EnforcedAdmin(
+ component, UserHandle.of(ENFORCED_ADMIN_USER_ID));
+ }
+
+ private void assertDeviceAdminAddIntent(Intent intent) {
+ assertThat(intent.getComponent().getClassName())
+ .isEqualTo(DeviceAdminAdd.class.getName());
+ assertThat((ComponentName) intent.getParcelableExtra(EXTRA_DEVICE_ADMIN))
+ .isEqualTo(ADMIN_COMPONENT);
+ assertThat(intent.getBooleanExtra(
+ EXTRA_CALLED_FROM_SUPPORT_DIALOG,
+ /* defaultValue= */ false))
+ .isTrue();
+ }
+
+ private void assertActionViewIntent(Intent intent) {
+ assertThat(intent.getAction())
+ .isEqualTo(Intent.ACTION_VIEW);
+ assertThat(intent.getData())
+ .isEqualTo(URI);
+ }
+}
diff --git a/tests/unit/src/com/android/settings/network/telephony/Enable2gPreferenceControllerTest.java b/tests/unit/src/com/android/settings/network/telephony/Enable2gPreferenceControllerTest.java
index 5ade979..9fb8a31 100644
--- a/tests/unit/src/com/android/settings/network/telephony/Enable2gPreferenceControllerTest.java
+++ b/tests/unit/src/com/android/settings/network/telephony/Enable2gPreferenceControllerTest.java
@@ -96,7 +96,7 @@
@Test
public void getAvailabilityStatus_nullCarrierConfig_returnUnavailable() {
doReturn(true).when(mTelephonyManager).isRadioInterfaceCapabilitySupported(
- mTelephonyManager.CAPABILITY_ALLOWED_NETWORK_TYPES_USED);
+ mTelephonyManager.CAPABILITY_USES_ALLOWED_NETWORK_TYPES_BITMASK);
mPersistableBundle.putBoolean(CarrierConfigManager.KEY_HIDE_ENABLE_2G,
false);
doReturn(null).when(mCarrierConfigManager);
@@ -107,7 +107,7 @@
@Test
public void getAvailabilityStatus_capabilityNotSupported_returnUnavailable() {
doReturn(false).when(mTelephonyManager).isRadioInterfaceCapabilitySupported(
- mTelephonyManager.CAPABILITY_ALLOWED_NETWORK_TYPES_USED);
+ mTelephonyManager.CAPABILITY_USES_ALLOWED_NETWORK_TYPES_BITMASK);
mPersistableBundle.putBoolean(CarrierConfigManager.KEY_HIDE_ENABLE_2G,
false);
@@ -117,7 +117,7 @@
@Test
public void getAvailabilityStatus_returnAvailable() {
doReturn(true).when(mTelephonyManager).isRadioInterfaceCapabilitySupported(
- mTelephonyManager.CAPABILITY_ALLOWED_NETWORK_TYPES_USED);
+ mTelephonyManager.CAPABILITY_USES_ALLOWED_NETWORK_TYPES_BITMASK);
mPersistableBundle.putBoolean(CarrierConfigManager.KEY_HIDE_ENABLE_2G,
false);
@@ -146,7 +146,7 @@
// Setup state to allow disabling
doReturn(true).when(mTelephonyManager).isRadioInterfaceCapabilitySupported(
- mTelephonyManager.CAPABILITY_ALLOWED_NETWORK_TYPES_USED);
+ mTelephonyManager.CAPABILITY_USES_ALLOWED_NETWORK_TYPES_BITMASK);
mPersistableBundle.putBoolean(CarrierConfigManager.KEY_HIDE_ENABLE_2G,
false);