summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/com/android/settings/enterprise/EnterprisePrivacyFeatureProvider.java13
-rw-r--r--src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java103
-rw-r--r--src/com/android/settings/privacy/WorkPolicyInfoPreferenceController.java53
3 files changed, 156 insertions, 13 deletions
diff --git a/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProvider.java b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProvider.java
index 048782ea35..46f9b71f23 100644
--- a/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProvider.java
+++ b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProvider.java
@@ -124,4 +124,17 @@ public interface EnterprisePrivacyFeatureProvider {
* profile (if any).
*/
int getNumberOfActiveDeviceAdminsForCurrentUserAndManagedProfile();
+
+ /**
+ * Returns {@code true} if it is possilbe to resolve an Intent to launch the "Your work policy
+ * info" page provided by the active Device Owner or Profile Owner app if it exists, {@code
+ * false} otherwise.
+ */
+ boolean hasWorkPolicyInfo();
+
+ /**
+ * Launches the Device Owner or Profile Owner's activity that displays the "Your work policy
+ * info" page. Returns {@code true} if the activity has indeed been launched.
+ */
+ boolean showWorkPolicyInfo();
}
diff --git a/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java
index 40859885b0..d095d88038 100644
--- a/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java
+++ b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java
@@ -21,6 +21,7 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
import android.content.pm.UserInfo;
import android.content.res.Resources;
import android.net.ConnectivityManager;
@@ -61,19 +62,7 @@ public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFe
@Override
public boolean hasDeviceOwner() {
- if (!mPm.hasSystemFeature(PackageManager.FEATURE_DEVICE_ADMIN)) {
- return false;
- }
- return mDpm.getDeviceOwnerComponentOnAnyUser() != null;
- }
-
- private int getManagedProfileUserId() {
- for (final UserInfo userInfo : mUm.getProfiles(MY_USER_ID)) {
- if (userInfo.isManagedProfile()) {
- return userInfo.id;
- }
- }
- return UserHandle.USER_NULL;
+ return getDeviceOwnerComponent() != null;
}
@Override
@@ -234,6 +223,94 @@ public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFe
return activeAdmins;
}
+ @Override
+ public boolean hasWorkPolicyInfo() {
+ return (getWorkPolicyInfoIntentDO() != null) || (getWorkPolicyInfoIntentPO() != null);
+ }
+
+ @Override
+ public boolean showWorkPolicyInfo() {
+ Intent intent = getWorkPolicyInfoIntentDO();
+ if (intent != null) {
+ mContext.startActivity(intent);
+ return true;
+ }
+
+ intent = getWorkPolicyInfoIntentPO();
+ final UserInfo userInfo = getManagedProfileUserInfo();
+ if (intent != null && userInfo != null) {
+ mContext.startActivityAsUser(intent, userInfo.getUserHandle());
+ return true;
+ }
+
+ return false;
+ }
+
+ private ComponentName getDeviceOwnerComponent() {
+ if (!mPm.hasSystemFeature(PackageManager.FEATURE_DEVICE_ADMIN)) {
+ return null;
+ }
+ return mDpm.getDeviceOwnerComponentOnAnyUser();
+ }
+
+ private UserInfo getManagedProfileUserInfo() {
+ for (final UserInfo userInfo : mUm.getProfiles(MY_USER_ID)) {
+ if (userInfo.isManagedProfile()) {
+ return userInfo;
+ }
+ }
+ return null;
+ }
+
+ private int getManagedProfileUserId() {
+ final UserInfo userInfo = getManagedProfileUserInfo();
+ if (userInfo != null) {
+ return userInfo.id;
+ }
+ return UserHandle.USER_NULL;
+ }
+
+ private Intent getWorkPolicyInfoIntentDO() {
+ final ComponentName ownerComponent = getDeviceOwnerComponent();
+ if (ownerComponent == null) {
+ return null;
+ }
+
+ // Only search for the required action in the Device Owner's package
+ final Intent intent =
+ new Intent(mResources.getString(R.string.config_work_policy_info_intent_action))
+ .setPackage(ownerComponent.getPackageName());
+ final List<ResolveInfo> activities = mPm.queryIntentActivities(intent, 0);
+ if (activities.size() != 0) {
+ return intent;
+ }
+
+ return null;
+ }
+
+ private Intent getWorkPolicyInfoIntentPO() {
+ final int userId = getManagedProfileUserId();
+ if (userId == UserHandle.USER_NULL) {
+ return null;
+ }
+
+ final ComponentName ownerComponent = mDpm.getProfileOwnerAsUser(userId);
+ if (ownerComponent == null) {
+ return null;
+ }
+
+ // Only search for the required action in the Profile Owner's package
+ final Intent intent =
+ new Intent(mResources.getString(R.string.config_work_policy_info_intent_action))
+ .setPackage(ownerComponent.getPackageName());
+ final List<ResolveInfo> activities = mPm.queryIntentActivitiesAsUser(intent, 0, userId);
+ if (activities.size() != 0) {
+ return intent;
+ }
+
+ return null;
+ }
+
protected static class EnterprisePrivacySpan extends ClickableSpan {
private final Context mContext;
diff --git a/src/com/android/settings/privacy/WorkPolicyInfoPreferenceController.java b/src/com/android/settings/privacy/WorkPolicyInfoPreferenceController.java
new file mode 100644
index 0000000000..45c2c21d57
--- /dev/null
+++ b/src/com/android/settings/privacy/WorkPolicyInfoPreferenceController.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2019 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.privacy;
+
+import android.content.Context;
+import android.text.TextUtils;
+
+import androidx.annotation.NonNull;
+import androidx.preference.Preference;
+
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.enterprise.EnterprisePrivacyFeatureProvider;
+import com.android.settings.overlay.FeatureFactory;
+
+public class WorkPolicyInfoPreferenceController extends BasePreferenceController {
+
+ private final @NonNull EnterprisePrivacyFeatureProvider mEnterpriseProvider;
+
+ public WorkPolicyInfoPreferenceController(Context context, String preferenceKey) {
+ super(context, preferenceKey);
+ mEnterpriseProvider =
+ FeatureFactory.getFactory(context).getEnterprisePrivacyFeatureProvider(context);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return mEnterpriseProvider.hasWorkPolicyInfo()
+ ? AVAILABLE_UNSEARCHABLE
+ : UNSUPPORTED_ON_DEVICE;
+ }
+
+ @Override
+ public boolean handlePreferenceTreeClick(Preference preference) {
+ if (TextUtils.equals(getPreferenceKey(), preference.getKey())) {
+ mEnterpriseProvider.showWorkPolicyInfo();
+ return true;
+ }
+ return false;
+ }
+}