summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/SettingsInitialize.java
diff options
context:
space:
mode:
authorGustav Sennton <gsennton@google.com>2016-05-11 12:31:40 +0100
committerGustav Sennton <gsennton@google.com>2016-05-12 11:13:26 +0100
commit66313bb11df3aeab4c6e14385ad09ccd43c10114 (patch)
tree2e2cc17c671a552c7acc5fc4957352eec2863b28 /src/com/android/settings/SettingsInitialize.java
parent938501cf7634843460b03b6fe954e927166e1257 (diff)
downloadpackages_apps_Settings-66313bb11df3aeab4c6e14385ad09ccd43c10114.tar.gz
packages_apps_Settings-66313bb11df3aeab4c6e14385ad09ccd43c10114.tar.bz2
packages_apps_Settings-66313bb11df3aeab4c6e14385ad09ccd43c10114.zip
Disable WebViewSetting for non-admin users.
For an app to be able to know whether the WebViewSetting is enabled for a user we disable the setting at boot for non-admin users. In this way an app can call intent.resolveActivity[Info] for the WebViewSetting intent to check whether the WebViewSetting is enabled before linking to it. Bug: 28034166 Change-Id: I33b3fa10a38f2a2600cddd0891ef746126abdd61
Diffstat (limited to 'src/com/android/settings/SettingsInitialize.java')
-rw-r--r--src/com/android/settings/SettingsInitialize.java110
1 files changed, 110 insertions, 0 deletions
diff --git a/src/com/android/settings/SettingsInitialize.java b/src/com/android/settings/SettingsInitialize.java
new file mode 100644
index 0000000000..07fec0741a
--- /dev/null
+++ b/src/com/android/settings/SettingsInitialize.java
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2014 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;
+
+import android.content.BroadcastReceiver;
+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.os.UserHandle;
+import android.os.UserManager;
+import android.util.Log;
+
+import java.util.List;
+
+import static android.content.pm.PackageManager.GET_ACTIVITIES;
+import static android.content.pm.PackageManager.GET_META_DATA;
+import static android.content.pm.PackageManager.GET_RESOLVED_FILTER;
+import static android.content.pm.PackageManager.MATCH_DISABLED_COMPONENTS;
+
+/**
+ * Listens to {@link Intent.ACTION_BOOT_COMPLETED} and {@link Intent.ACTION_PRE_BOOT_COMPLETED}
+ * performs setup steps for a managed profile (disables the launcher icon of the Settings app,
+ * adds cross-profile intent filters for the appropriate Settings activities), and disables the
+ * webview setting for non-admin users.
+ */
+public class SettingsInitialize extends BroadcastReceiver {
+ private static final String TAG = "Settings";
+ private static final String PRIMARY_PROFILE_SETTING =
+ "com.android.settings.PRIMARY_PROFILE_CONTROLLED";
+
+ @Override
+ public void onReceive(Context context, Intent broadcast) {
+ final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
+ UserInfo userInfo = um.getUserInfo(UserHandle.myUserId());
+ final PackageManager pm = context.getPackageManager();
+ managedProfileSetup(context, pm, broadcast, userInfo);
+ webviewSettingSetup(context, pm, userInfo);
+ }
+
+ private void managedProfileSetup(Context context, final PackageManager pm, Intent broadcast,
+ UserInfo userInfo) {
+ if (userInfo == null || !userInfo.isManagedProfile()) {
+ return;
+ }
+ Log.i(TAG, "Received broadcast: " + broadcast.getAction()
+ + ". Setting up intent forwarding for managed profile.");
+ // Clear any previous intent forwarding we set up
+ pm.clearCrossProfileIntentFilters(userInfo.id);
+
+ // Set up intent forwarding for implicit intents
+ Intent intent = new Intent();
+ intent.addCategory(Intent.CATEGORY_DEFAULT);
+ intent.setPackage(context.getPackageName());
+
+ // Resolves activities for the managed profile (which we're running as)
+ List<ResolveInfo> resolvedIntents = pm.queryIntentActivities(intent,
+ GET_ACTIVITIES | GET_META_DATA | GET_RESOLVED_FILTER | MATCH_DISABLED_COMPONENTS);
+ final int count = resolvedIntents.size();
+ for (int i = 0; i < count; i++) {
+ ResolveInfo info = resolvedIntents.get(i);
+ if (info.filter != null && info.activityInfo != null
+ && info.activityInfo.metaData != null) {
+ boolean shouldForward = info.activityInfo.metaData.getBoolean(
+ PRIMARY_PROFILE_SETTING);
+ if (shouldForward) {
+ pm.addCrossProfileIntentFilter(info.filter, userInfo.id,
+ userInfo.profileGroupId, PackageManager.SKIP_CURRENT_PROFILE);
+ }
+ }
+ }
+
+ // Disable launcher icon
+ // Note: This needs to happen after forwarding intents, otherwise the main Settings
+ // intent gets lost
+ ComponentName settingsComponentName = new ComponentName(context, Settings.class);
+ pm.setComponentEnabledSetting(settingsComponentName,
+ PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
+ }
+
+ // Disable WebView Setting if the current user is not an admin
+ private void webviewSettingSetup(Context context, PackageManager pm, UserInfo userInfo) {
+ if (userInfo == null) {
+ return;
+ }
+ ComponentName settingsComponentName =
+ new ComponentName(context, WebViewImplementation.class);
+ pm.setComponentEnabledSetting(settingsComponentName,
+ userInfo.isAdmin() ?
+ PackageManager.COMPONENT_ENABLED_STATE_ENABLED :
+ PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
+ PackageManager.DONT_KILL_APP);
+ }
+}