Merge "Add Always on VPN to Privacy Settings page"
This commit is contained in:
committed by
Android (Google) Code Review
commit
42248f0066
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.content.Context;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
|
||||
public class AlwaysOnVpnManagedProfilePreferenceController extends PreferenceController {
|
||||
|
||||
private static final String KEY_ALWAYS_ON_VPN_MANAGED_PROFILE = "always_on_vpn_managed_profile";
|
||||
private final EnterprisePrivacyFeatureProvider mFeatureProvider;
|
||||
|
||||
public AlwaysOnVpnManagedProfilePreferenceController(Context context) {
|
||||
super(context);
|
||||
mFeatureProvider = FeatureFactory.getFactory(context)
|
||||
.getEnterprisePrivacyFeatureProvider(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
preference.setVisible(mFeatureProvider.isAlwaysOnVpnSetInManagedProfile());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_ALWAYS_ON_VPN_MANAGED_PROFILE;
|
||||
}
|
||||
}
|
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.content.Context;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
|
||||
public class AlwaysOnVpnPrimaryUserPreferenceController extends PreferenceController {
|
||||
|
||||
private static final String KEY_ALWAYS_ON_VPN_PRIMARY_USER = "always_on_vpn_primary_user";
|
||||
private final EnterprisePrivacyFeatureProvider mFeatureProvider;
|
||||
|
||||
public AlwaysOnVpnPrimaryUserPreferenceController(Context context) {
|
||||
super(context);
|
||||
mFeatureProvider = FeatureFactory.getFactory(context)
|
||||
.getEnterprisePrivacyFeatureProvider(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
preference.setTitle(mFeatureProvider.isInCompMode()
|
||||
? R.string.enterprise_privacy_always_on_vpn_personal
|
||||
: R.string.enterprise_privacy_always_on_vpn_device);
|
||||
preference.setVisible(mFeatureProvider.isAlwaysOnVpnSetInPrimaryUser());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_ALWAYS_ON_VPN_PRIMARY_USER;
|
||||
}
|
||||
}
|
@@ -25,6 +25,12 @@ public interface EnterprisePrivacyFeatureProvider {
|
||||
*/
|
||||
boolean hasDeviceOwner();
|
||||
|
||||
/**
|
||||
* Returns whether the device is in COMP mode (primary user managed by a Device Owner app and
|
||||
* work profile managed by a Profile Owner app).
|
||||
*/
|
||||
boolean isInCompMode();
|
||||
|
||||
/**
|
||||
* Returns the time at which the Device Owner last retrieved security logs, or {@code null} if
|
||||
* logs were never retrieved by the Device Owner on this device.
|
||||
@@ -42,4 +48,14 @@ public interface EnterprisePrivacyFeatureProvider {
|
||||
* logs were never retrieved by the Device Owner on this device.
|
||||
*/
|
||||
Date getLastNetworkLogRetrievalTime();
|
||||
|
||||
/**
|
||||
* Returns whether the Device Owner in the primary user set an always-on VPN.
|
||||
*/
|
||||
boolean isAlwaysOnVpnSetInPrimaryUser();
|
||||
|
||||
/**
|
||||
* Returns whether the Profile Owner in the managed profile (if any) set an always-on VPN.
|
||||
*/
|
||||
boolean isAlwaysOnVpnSetInManagedProfile();
|
||||
}
|
||||
|
@@ -17,20 +17,32 @@
|
||||
package com.android.settings.enterprise;
|
||||
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
|
||||
import com.android.settings.applications.PackageManagerWrapper;
|
||||
import com.android.settings.vpn2.ConnectivityManagerWrapper;
|
||||
import com.android.settings.vpn2.VpnUtils;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFeatureProvider {
|
||||
|
||||
private final DevicePolicyManagerWrapper mDpm;
|
||||
private final PackageManagerWrapper mPm;
|
||||
private final UserManager mUm;
|
||||
private final ConnectivityManagerWrapper mCm;
|
||||
|
||||
private static final int MY_USER_ID = UserHandle.myUserId();
|
||||
|
||||
public EnterprisePrivacyFeatureProviderImpl(DevicePolicyManagerWrapper dpm,
|
||||
PackageManagerWrapper pm) {
|
||||
PackageManagerWrapper pm, UserManager um, ConnectivityManagerWrapper cm) {
|
||||
mDpm = dpm;
|
||||
mPm = pm;
|
||||
mUm = um;
|
||||
mCm = cm;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -41,19 +53,47 @@ public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFe
|
||||
return mDpm.getDeviceOwnerComponentOnAnyUser() != null;
|
||||
}
|
||||
|
||||
private int getManagedProfileUserId() {
|
||||
for (final UserInfo userInfo : mUm.getProfiles(MY_USER_ID)) {
|
||||
if (userInfo.isManagedProfile()) {
|
||||
return userInfo.id;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInCompMode() {
|
||||
return hasDeviceOwner() && getManagedProfileUserId() != -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getLastSecurityLogRetrievalTime() {
|
||||
final long timestamp = mDpm.getLastSecurityLogRetrievalTime();
|
||||
return timestamp < 0 ? null : new Date(timestamp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getLastBugReportRequestTime() {
|
||||
final long timestamp = mDpm.getLastBugReportRequestTime();
|
||||
return timestamp < 0 ? null : new Date(timestamp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getLastNetworkLogRetrievalTime() {
|
||||
final long timestamp = mDpm.getLastNetworkLogRetrievalTime();
|
||||
return timestamp < 0 ? null : new Date(timestamp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAlwaysOnVpnSetInPrimaryUser() {
|
||||
return VpnUtils.isAlwaysOnVpnSet(mCm, MY_USER_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAlwaysOnVpnSetInManagedProfile() {
|
||||
final int managedProfileUserId = getManagedProfileUserId();
|
||||
return managedProfileUserId != -1 &&
|
||||
VpnUtils.isAlwaysOnVpnSet(mCm, managedProfileUserId);
|
||||
}
|
||||
}
|
||||
|
@@ -61,6 +61,8 @@ public class EnterprisePrivacySettings extends DashboardFragment {
|
||||
controllers.add(new NetworkLogsPreferenceController(context));
|
||||
controllers.add(new BugReportsPreferenceController(context));
|
||||
controllers.add(new SecurityLogsPreferenceController(context));
|
||||
controllers.add(new AlwaysOnVpnPrimaryUserPreferenceController(context));
|
||||
controllers.add(new AlwaysOnVpnManagedProfilePreferenceController(context));
|
||||
return controllers;
|
||||
}
|
||||
|
||||
|
@@ -18,6 +18,8 @@ package com.android.settings.overlay;
|
||||
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.os.UserManager;
|
||||
import android.support.annotation.Keep;
|
||||
|
||||
import com.android.settings.applications.ApplicationFeatureProvider;
|
||||
@@ -37,6 +39,7 @@ import com.android.settings.security.SecurityFeatureProvider;
|
||||
import com.android.settings.security.SecurityFeatureProviderImpl;
|
||||
import com.android.settings.search2.SearchFeatureProvider;
|
||||
import com.android.settings.search2.SearchFeatureProviderImpl;
|
||||
import com.android.settings.vpn2.ConnectivityManagerWrapperImpl;
|
||||
|
||||
/**
|
||||
* {@link FeatureFactory} implementation for AOSP Settings.
|
||||
@@ -101,7 +104,10 @@ public class FeatureFactoryImpl extends FeatureFactory {
|
||||
mEnterprisePrivacyFeatureProvider = new EnterprisePrivacyFeatureProviderImpl(
|
||||
new DevicePolicyManagerWrapperImpl((DevicePolicyManager) context
|
||||
.getSystemService(Context.DEVICE_POLICY_SERVICE)),
|
||||
new PackageManagerWrapperImpl(context.getPackageManager()));
|
||||
new PackageManagerWrapperImpl(context.getPackageManager()),
|
||||
UserManager.get(context),
|
||||
new ConnectivityManagerWrapperImpl((ConnectivityManager) context
|
||||
.getSystemService(Context.CONNECTIVITY_SERVICE)));
|
||||
}
|
||||
return mEnterprisePrivacyFeatureProvider;
|
||||
}
|
||||
|
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.vpn2;
|
||||
|
||||
/**
|
||||
* This interface replicates a subset of the android.net.ConnectivityManager (CM). The interface
|
||||
* exists so that we can use a thin wrapper around the CM in production code and a mock in tests.
|
||||
* We cannot directly mock or shadow the CM, because some of the methods we rely on are marked as
|
||||
* hidden and are thus invisible to Robolectric.
|
||||
*/
|
||||
public interface ConnectivityManagerWrapper {
|
||||
|
||||
/**
|
||||
* Calls {@code ConnectivityManager.getAlwaysOnVpnPackageForUser()}.
|
||||
*
|
||||
* @see android.net.ConnectivityManager#getAlwaysOnVpnPackageForUser
|
||||
*/
|
||||
String getAlwaysOnVpnPackageForUser(int userId);
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.vpn2;
|
||||
|
||||
import android.net.ConnectivityManager;
|
||||
|
||||
public class ConnectivityManagerWrapperImpl implements ConnectivityManagerWrapper {
|
||||
|
||||
private final ConnectivityManager mCm;
|
||||
|
||||
public ConnectivityManagerWrapperImpl(ConnectivityManager cm) {
|
||||
mCm = cm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAlwaysOnVpnPackageForUser(int userId) {
|
||||
return mCm.getAlwaysOnVpnPackageForUser(userId);
|
||||
}
|
||||
}
|
@@ -82,4 +82,8 @@ public class VpnUtils {
|
||||
return IConnectivityManager.Stub.asInterface(
|
||||
ServiceManager.getService(Context.CONNECTIVITY_SERVICE));
|
||||
}
|
||||
|
||||
public static boolean isAlwaysOnVpnSet(ConnectivityManagerWrapper cm, final int userId) {
|
||||
return cm.getAlwaysOnVpnPackageForUser(userId) != null;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user