Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 53fa4ec7 authored by Kenny Guy's avatar Kenny Guy
Browse files

Extend LauncherApps service to expose enabled state.

Provide methods for checking if a package or activity
is enabled for a given profile.

Change-Id: If9cb15dc9398a709e60e7b689b664c24c49fcc16
parent b0396038
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -7745,6 +7745,8 @@ package android.content.pm {
  public class LauncherApps {
    method public synchronized void addOnAppsChangedListener(android.content.pm.LauncherApps.OnAppsChangedListener);
    method public java.util.List<android.content.pm.LauncherActivityInfo> getActivityList(java.lang.String, android.os.UserHandle);
    method public boolean isActivityEnabledForProfile(android.content.ComponentName, android.os.UserHandle);
    method public boolean isPackageEnabledForProfile(java.lang.String, android.os.UserHandle);
    method public synchronized void removeOnAppsChangedListener(android.content.pm.LauncherApps.OnAppsChangedListener);
    method public android.content.pm.LauncherActivityInfo resolveActivity(android.content.Intent, android.os.UserHandle);
    method public void startActivityForProfile(android.content.ComponentName, android.graphics.Rect, android.os.Bundle, android.os.UserHandle);
+2 −0
Original line number Diff line number Diff line
@@ -35,4 +35,6 @@ interface ILauncherApps {
    ResolveInfo resolveActivity(in Intent intent, in UserHandle user);
    void startActivityAsUser(in ComponentName component, in Rect sourceBounds,
            in Bundle opts, in UserHandle user);
    boolean isPackageEnabled(String packageName, in UserHandle user);
    boolean isActivityEnabled(in ComponentName component, in UserHandle user);
}
+33 −0
Original line number Diff line number Diff line
@@ -186,6 +186,39 @@ public class LauncherApps {
        }
    }

    /**
     * Checks if the package is installed and enabled for a profile.
     *
     * @param packageName The package to check.
     * @param user The UserHandle of the profile.
     *
     * @return true if the package exists and is enabled.
     */
    public boolean isPackageEnabledForProfile(String packageName, UserHandle user) {
        try {
            return mService.isPackageEnabled(packageName, user);
        } catch (RemoteException re) {
            return false;
        }
    }

    /**
     * Checks if the activity exists and it enabled for a profile.
     *
     * @param component The activity to check.
     * @param user The UserHandle of the profile.
     *
     * @return true if the activity exists and is enabled.
     */
    public boolean isActivityEnabledForProfile(ComponentName component, UserHandle user) {
        try {
            return mService.isActivityEnabled(component, user);
        } catch (RemoteException re) {
            return false;
        }
    }


    /**
     * Adds a listener for changes to packages in current and managed profiles.
     *
+32 −0
Original line number Diff line number Diff line
@@ -16,14 +16,18 @@

package com.android.server.pm;

import android.app.AppGlobals;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.content.pm.ILauncherApps;
import android.content.pm.IOnAppsChangedListener;
import android.content.pm.IPackageManager;
import android.content.pm.PackageManager;
import android.content.pm.PackageInfo;
import android.content.pm.ResolveInfo;
import android.content.pm.UserInfo;
import android.graphics.Rect;
@@ -169,6 +173,34 @@ public class LauncherAppsService extends ILauncherApps.Stub {
        }
    }

    @Override
    public boolean isPackageEnabled(String packageName, UserHandle user)
            throws RemoteException {
        ensureInUserProfiles(user, "Cannot check package for unrelated profile " + user);
        long ident = Binder.clearCallingIdentity();
        try {
            IPackageManager pm = AppGlobals.getPackageManager();
            PackageInfo info = pm.getPackageInfo(packageName, 0, user.getIdentifier());
            return info != null && info.applicationInfo.enabled;
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
    }

    @Override
    public boolean isActivityEnabled(ComponentName component, UserHandle user)
            throws RemoteException {
        ensureInUserProfiles(user, "Cannot check component for unrelated profile " + user);
        long ident = Binder.clearCallingIdentity();
        try {
            IPackageManager pm = AppGlobals.getPackageManager();
            ActivityInfo info = pm.getActivityInfo(component, 0, user.getIdentifier());
            return info != null && info.isEnabled();
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
    }

    @Override
    public void startActivityAsUser(ComponentName component, Rect sourceBounds,
            Bundle opts, UserHandle user) throws RemoteException {