Launch DO/PO sepecific settings when parental are enabled.
Test: make RunSettingsRoboTests && manual Bug: 161861348 Change-Id: I73ce27d0aa740f47e6ed3e4be9bee4d5eaf039ad
This commit is contained in:
@@ -23,6 +23,7 @@ import android.util.FeatureFlagUtils;
|
||||
|
||||
import com.android.settings.core.FeatureFlags;
|
||||
import com.android.settings.enterprise.EnterprisePrivacySettings;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
|
||||
/**
|
||||
* Top-level Settings activity
|
||||
@@ -213,7 +214,11 @@ public class Settings extends SettingsActivity {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (!EnterprisePrivacySettings.isPageEnabled(this)) {
|
||||
if (FeatureFactory.getFactory(this)
|
||||
.getEnterprisePrivacyFeatureProvider(this)
|
||||
.showParentalControls()) {
|
||||
finish();
|
||||
} else if (!EnterprisePrivacySettings.isPageEnabled(this)) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
@@ -137,4 +137,10 @@ public interface EnterprisePrivacyFeatureProvider {
|
||||
* info" page. Returns {@code true} if the activity has indeed been launched.
|
||||
*/
|
||||
boolean showWorkPolicyInfo();
|
||||
|
||||
/**
|
||||
* Launches the parental controls settings page. Returns {@code true} if the activity has
|
||||
* been launched.
|
||||
*/
|
||||
boolean showParentalControls();
|
||||
}
|
||||
|
@@ -40,6 +40,9 @@ import java.util.List;
|
||||
|
||||
public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFeatureProvider {
|
||||
|
||||
public static final String ACTION_PARENTAL_CONTROLS =
|
||||
"android.settings.SHOW_PARENTAL_CONTROLS";
|
||||
|
||||
private final Context mContext;
|
||||
private final DevicePolicyManager mDpm;
|
||||
private final PackageManager mPm;
|
||||
@@ -246,6 +249,34 @@ public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFe
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean showParentalControls() {
|
||||
Intent intent = getParentalControlsIntent();
|
||||
if (intent != null) {
|
||||
mContext.startActivity(intent);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private Intent getParentalControlsIntent() {
|
||||
final ComponentName componentName =
|
||||
mDpm.getProfileOwnerOrDeviceOwnerSupervisionComponent(new UserHandle(MY_USER_ID));
|
||||
if (componentName == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final Intent intent = new Intent(ACTION_PARENTAL_CONTROLS)
|
||||
.setPackage(componentName.getPackageName())
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
final List<ResolveInfo> activities = mPm.queryIntentActivitiesAsUser(intent, 0, MY_USER_ID);
|
||||
if (activities.size() != 0) {
|
||||
return intent;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private ComponentName getDeviceOwnerComponent() {
|
||||
if (!mPm.hasSystemFeature(PackageManager.FEATURE_DEVICE_ADMIN)) {
|
||||
return null;
|
||||
|
@@ -63,6 +63,7 @@ import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class EnterprisePrivacyFeatureProviderImplTest {
|
||||
|
||||
@@ -426,6 +427,17 @@ public class EnterprisePrivacyFeatureProviderImplTest {
|
||||
verify(mContext).startActivity(intentEquals(intent));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShowParentalControls() {
|
||||
when(mDevicePolicyManager.getProfileOwnerOrDeviceOwnerSupervisionComponent(any()))
|
||||
.thenReturn(mOwner);
|
||||
|
||||
// If the intent is resolved, then we can use it to launch the activity
|
||||
Intent intent = addParentalControlsIntent(mOwner.getPackageName());
|
||||
assertThat(mProvider.showParentalControls()).isTrue();
|
||||
verify(mContext).startActivity(intentEquals(intent));
|
||||
}
|
||||
|
||||
private Intent addWorkPolicyInfoIntent(
|
||||
String packageName, boolean deviceOwner, boolean profileOwner) {
|
||||
Intent intent = new Intent(Settings.ACTION_SHOW_WORK_POLICY_INFO);
|
||||
@@ -450,6 +462,23 @@ public class EnterprisePrivacyFeatureProviderImplTest {
|
||||
return intent;
|
||||
}
|
||||
|
||||
private Intent addParentalControlsIntent(String packageName) {
|
||||
Intent intent = new Intent(EnterprisePrivacyFeatureProviderImpl.ACTION_PARENTAL_CONTROLS);
|
||||
intent.setPackage(packageName);
|
||||
ResolveInfo resolveInfo = new ResolveInfo();
|
||||
resolveInfo.resolvePackageName = packageName;
|
||||
resolveInfo.activityInfo = new ActivityInfo();
|
||||
resolveInfo.activityInfo.name = "activityName";
|
||||
resolveInfo.activityInfo.packageName = packageName;
|
||||
|
||||
List<ResolveInfo> activities = ImmutableList.of(resolveInfo);
|
||||
when(mPackageManager.queryIntentActivities(intentEquals(intent), anyInt()))
|
||||
.thenReturn(activities);
|
||||
when(mPackageManager.queryIntentActivitiesAsUser(intentEquals(intent), anyInt(), anyInt()))
|
||||
.thenReturn(activities);
|
||||
return intent;
|
||||
}
|
||||
|
||||
private static class IntentMatcher implements ArgumentMatcher<Intent> {
|
||||
private final Intent mExpectedIntent;
|
||||
|
||||
|
Reference in New Issue
Block a user