gecko-dev/mobile/android/base/restrictions/RestrictedProfileConfiguration.java
Sebastian Kaspari 4873e328c5 Bug 1189414 - Restricted Profiles: Clean up missing and unneeded restrictions. r=ally
* Synchronize nsIParentalControlsService.idl and Restriction.java
* Do not hide 'tools' menu but menu items of disabled features
* Hiding 'Report site issue' should not be configurable
* Restricted profiles: DISALLOW_INSTALL_APPS is a system restriction and should not be configurable
* RestrictedProfileConfiguration: Use AboutPages

--HG--
extra : commitid : 8DTKY8nESVS
extra : rebase_source : b0f91e9d578fbeea6093a1f6af9ffa645daa6d2a
2015-08-06 10:51:45 +02:00

87 lines
3.0 KiB
Java

/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.restrictions;
import org.mozilla.gecko.AboutPages;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.os.UserManager;
import java.util.Arrays;
import java.util.List;
public class RestrictedProfileConfiguration implements RestrictionConfiguration {
static List<Restriction> DEFAULT_RESTRICTIONS = Arrays.asList(
Restriction.DISALLOW_INSTALL_EXTENSION,
Restriction.DISALLOW_IMPORT_SETTINGS,
Restriction.DISALLOW_DEVELOPER_TOOLS,
Restriction.DISALLOW_CUSTOMIZE_HOME,
Restriction.DISALLOW_PRIVATE_BROWSING,
Restriction.DISALLOW_LOCATION_SERVICE,
Restriction.DISALLOW_DISPLAY_SETTINGS,
Restriction.DISALLOW_CLEAR_HISTORY,
Restriction.DISALLOW_MASTER_PASSWORD,
Restriction.DISALLOW_GUEST_BROWSING
);
private Context context;
public RestrictedProfileConfiguration(Context context) {
this.context = context.getApplicationContext();
}
@Override
public boolean isAllowed(Restriction restriction) {
boolean isAllowed = !getAppRestrictions(context).getBoolean(restriction.name, DEFAULT_RESTRICTIONS.contains(restriction));
if (isAllowed) {
// If this restriction is not enforced by the app setup then check wether this is a restriction that is
// enforced by the system.
isAllowed = !getUserRestrictions(context).getBoolean(restriction.name, false);
}
return isAllowed;
}
@Override
public boolean canLoadUrl(String url) {
if (!isAllowed(Restriction.DISALLOW_INSTALL_EXTENSION) && AboutPages.isAboutAddons(url)) {
return false;
}
if (!isAllowed(Restriction.DISALLOW_PRIVATE_BROWSING) && AboutPages.isAboutPrivateBrowsing(url)) {
return false;
}
if (AboutPages.isAboutConfig(url)) {
// Always block access to about:config to prevent circumventing restrictions (Bug 1189233)
return false;
}
return true;
}
@Override
public boolean isRestricted() {
return true;
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private Bundle getAppRestrictions(final Context context) {
final UserManager mgr = (UserManager) context.getSystemService(Context.USER_SERVICE);
return mgr.getApplicationRestrictions(context.getPackageName());
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private Bundle getUserRestrictions(final Context context) {
final UserManager mgr = (UserManager) context.getSystemService(Context.USER_SERVICE);
return mgr.getUserRestrictions();
}
}