Merge "Add "Your work policy info" entry in Privacy settings" into qt-dev

am: 9a1c75c57a

Change-Id: Idf96f32733b5a3aedab325cbeba4b67c1d20ce24
This commit is contained in:
Ivan Podogov
2019-06-17 05:49:13 -07:00
committed by android-build-merger
9 changed files with 392 additions and 15 deletions

View File

@@ -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();
}

View File

@@ -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;

View File

@@ -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;
}
}