Do not show hidden apps in DO/PO mode

Test: It does not show work profile apps anymore
Bug: 120078376
Change-Id: Ib60f989ddc3cc71e024c6a4a9f0cc3123331adc0
This commit is contained in:
Ricky Wai
2019-01-14 11:34:10 +00:00
parent 91c29d0ce9
commit e6a90389c9

View File

@@ -24,6 +24,7 @@ import android.app.AppDetailsActivity;
import android.app.AppGlobals;
import android.app.IApplicationThread;
import android.app.PendingIntent;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -115,6 +116,7 @@ public class LauncherAppsService extends SystemService {
private final ShortcutServiceInternal mShortcutServiceInternal;
private final PackageCallbackList<IOnAppsChangedListener> mListeners
= new PackageCallbackList<IOnAppsChangedListener>();
private final DevicePolicyManager mDpm;
private final MyPackageMonitor mPackageMonitor = new MyPackageMonitor();
@@ -133,6 +135,7 @@ public class LauncherAppsService extends SystemService {
LocalServices.getService(ShortcutServiceInternal.class));
mShortcutServiceInternal.addListener(mPackageMonitor);
mCallbackHandler = BackgroundThread.getHandler();
mDpm = (DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
}
@VisibleForTesting
@@ -319,28 +322,36 @@ public class LauncherAppsService extends SystemService {
}
final int callingUid = injectBinderCallingUid();
final ArrayList<ResolveInfo> result = new ArrayList<>(launcherActivities.getList());
final PackageManagerInternal pmInt =
LocalServices.getService(PackageManagerInternal.class);
if (packageName != null) {
// If this hidden app should not be shown, return the original list.
// Otherwise, inject hidden activity that forwards user to app details page.
if (result.size() > 0) {
final long ident = injectClearCallingIdentity();
try {
if (mUm.getUserInfo(user.getIdentifier()).isManagedProfile()) {
// Managed profile should not show hidden apps
return launcherActivities;
}
ApplicationInfo appInfo = pmInt.getApplicationInfo(packageName, /*flags*/ 0,
callingUid, user.getIdentifier());
if (shouldShowHiddenApp(appInfo)) {
ResolveInfo info = getHiddenAppActivityInfo(packageName, callingUid, user);
if (info != null) {
result.add(info);
}
if (mDpm.getDeviceOwnerComponentOnAnyUser() != null) {
// Device owner devices should not show hidden apps
return launcherActivities;
}
return new ParceledListSlice<>(result);
}
long ident = injectClearCallingIdentity();
try {
final ArrayList<ResolveInfo> result = new ArrayList<>(launcherActivities.getList());
final PackageManagerInternal pmInt =
LocalServices.getService(PackageManagerInternal.class);
if (packageName != null) {
// If this hidden app should not be shown, return the original list.
// Otherwise, inject hidden activity that forwards user to app details page.
if (result.size() > 0) {
return launcherActivities;
}
ApplicationInfo appInfo = pmInt.getApplicationInfo(packageName, /*flags*/ 0,
callingUid, user.getIdentifier());
if (shouldShowHiddenApp(appInfo)) {
ResolveInfo info = getHiddenAppActivityInfo(packageName, callingUid, user);
if (info != null) {
result.add(info);
}
}
return new ParceledListSlice<>(result);
}
final HashSet<String> visiblePackages = new HashSet<>();
for (ResolveInfo info : result) {
visiblePackages.add(info.activityInfo.packageName);