From 9fea3de8f5205a6a95252d1e9ab8eaaeaf4e3660 Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Fri, 15 Feb 2019 15:42:16 -0800 Subject: [PATCH] Disable Launcher when starting in a managed profile - The launcher package is automatically enabled for work profiles due to DPM interpreting it as a critical component since it does not have any launchable activities. Once enabled, it is possible for an explicit broadcast to update smartspace or assistant state to trigger the process to be created for the work profile user, which ends up initializing logic which may call into LauncherApps (which is not allowed from the work profile). As a workaround, we disable the launcher application immediately upon detecting that it is running in a work profile. Bug: 120550382 Change-Id: I72c52fe598d41440a1fb59304b494a000277384b --- .../QuickstepProcessInitializer.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/quickstep/src/com/android/quickstep/QuickstepProcessInitializer.java b/quickstep/src/com/android/quickstep/QuickstepProcessInitializer.java index 2c3f77f213..befeee0db9 100644 --- a/quickstep/src/com/android/quickstep/QuickstepProcessInitializer.java +++ b/quickstep/src/com/android/quickstep/QuickstepProcessInitializer.java @@ -16,17 +16,36 @@ package com.android.quickstep; import android.content.Context; +import android.content.pm.PackageManager; +import android.os.UserManager; +import android.util.Log; +import com.android.launcher3.BuildConfig; import com.android.launcher3.MainProcessInitializer; import com.android.systemui.shared.system.ThreadedRendererCompat; @SuppressWarnings("unused") public class QuickstepProcessInitializer extends MainProcessInitializer { + private static final String TAG = "QuickstepProcessInitializer"; + public QuickstepProcessInitializer(Context context) { } @Override protected void init(Context context) { + // Workaround for b/120550382, an external app can cause the launcher process to start for + // a work profile user which we do not support. Disable the application immediately when we + // detect this to be the case. + UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE); + if (um.isManagedProfile()) { + PackageManager pm = context.getPackageManager(); + pm.setApplicationEnabledSetting(context.getPackageName(), + PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0 /* flags */); + Log.w(TAG, "Disabling " + BuildConfig.APPLICATION_ID + + ", unable to run in a managed profile"); + return; + } + super.init(context); // Elevate GPU priority for Quickstep and Remote animations.