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

Commit 834bb1cc authored by Nicolas Prevot's avatar Nicolas Prevot Committed by Android (Google) Code Review
Browse files

Merge "Introducing removable and non-removable ForwardingIntentFilters."

parents fd4235f2 6fee7d4c
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -247,7 +247,8 @@ interface IPackageManager {

    void clearPackagePersistentPreferredActivities(String packageName, int userId);

    void addForwardingIntentFilter(in IntentFilter filter, int userIdOrig, int userIdDest);
    void addForwardingIntentFilter(in IntentFilter filter, boolean removable, int userIdOrig,
            int userIdDest);

    void clearForwardingIntentFilters(int userIdOrig);

+13 −1
Original line number Diff line number Diff line
@@ -32,22 +32,29 @@ import android.os.UserHandle;
 */
class ForwardingIntentFilter extends IntentFilter {
    private static final String ATTR_USER_ID_DEST = "userIdDest";
    private static final String ATTR_REMOVABLE = "removable";
    private static final String ATTR_FILTER = "filter";

    private static final String TAG = "ForwardingIntentFilter";

    // If the intent matches the IntentFilter, then it can be forwarded to this userId.
    final int mUserIdDest;
    boolean mRemovable;

    ForwardingIntentFilter(IntentFilter filter, int userIdDest) {
    ForwardingIntentFilter(IntentFilter filter, boolean removable, int userIdDest) {
        super(filter);
        mUserIdDest = userIdDest;
        mRemovable = removable;
    }

    public int getUserIdDest() {
        return mUserIdDest;
    }

    public boolean isRemovable() {
        return mRemovable;
    }

    ForwardingIntentFilter(XmlPullParser parser) throws XmlPullParserException, IOException {
        String userIdDestString = parser.getAttributeValue(null, ATTR_USER_ID_DEST);
        if (userIdDestString == null) {
@@ -58,6 +65,10 @@ class ForwardingIntentFilter extends IntentFilter {
        } else {
            mUserIdDest = Integer.parseInt(userIdDestString);
        }
        String removableString = parser.getAttributeValue(null, ATTR_REMOVABLE);
        if (removableString != null) {
            mRemovable = Boolean.parseBoolean(removableString);
        }
        int outerDepth = parser.getDepth();
        String tagName = parser.getName();
        int type;
@@ -89,6 +100,7 @@ class ForwardingIntentFilter extends IntentFilter {

    public void writeToXml(XmlSerializer serializer) throws IOException {
        serializer.attribute(null, ATTR_USER_ID_DEST, Integer.toString(mUserIdDest));
        serializer.attribute(null, ATTR_REMOVABLE, Boolean.toString(mRemovable));
        serializer.startTag(null, ATTR_FILTER);
            super.writeToXml(serializer);
        serializer.endTag(null, ATTR_FILTER);
+4 −8
Original line number Diff line number Diff line
@@ -11112,13 +11112,9 @@ public class PackageManagerService extends IPackageManager.Stub {
        }
    }
    /*
     * For filters that are added with this method:
     * if an intent for the user whose id is userIdOrig matches the filter, then this intent can
     * also be resolved in the user whose id is userIdDest.
     */
    @Override
    public void addForwardingIntentFilter(IntentFilter filter, int userIdOrig, int userIdDest) {
    public void addForwardingIntentFilter(IntentFilter filter, boolean removable, int userIdOrig,
            int userIdDest) {
        int callingUid = Binder.getCallingUid();
        if (callingUid != Process.SYSTEM_UID) {
            throw new SecurityException(
@@ -11130,7 +11126,7 @@ public class PackageManagerService extends IPackageManager.Stub {
        }
        synchronized (mPackages) {
            mSettings.editForwardingIntentResolverLPw(userIdOrig).addFilter(
                    new ForwardingIntentFilter(filter, userIdDest));
                    new ForwardingIntentFilter(filter, removable, userIdDest));
            mSettings.writePackageRestrictionsLPr(userIdOrig);
        }
    }
@@ -11147,7 +11143,7 @@ public class PackageManagerService extends IPackageManager.Stub {
            HashSet<ForwardingIntentFilter> set =
                    new HashSet<ForwardingIntentFilter>(fir.filterSet());
            for (ForwardingIntentFilter fif : set) {
                fir.removeFilter(fif);
                if (fif.isRemovable()) fir.removeFilter(fif);
            }
            mSettings.writePackageRestrictionsLPr(userIdOrig);
        }
+4 −2
Original line number Diff line number Diff line
@@ -3094,10 +3094,12 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
            long id = Binder.clearCallingIdentity();
            try {
                if ((flags & DevicePolicyManager.FLAG_TO_PRIMARY_USER) != 0) {
                    pm.addForwardingIntentFilter(filter, callingUserId, UserHandle.USER_OWNER);
                    pm.addForwardingIntentFilter(filter, true /*removable*/, callingUserId,
                            UserHandle.USER_OWNER);
                }
                if ((flags & DevicePolicyManager.FLAG_TO_MANAGED_PROFILE) != 0) {
                    pm.addForwardingIntentFilter(filter, UserHandle.USER_OWNER, callingUserId);
                    pm.addForwardingIntentFilter(filter, true /*removable*/, UserHandle.USER_OWNER,
                            callingUserId);
                }
            } catch (RemoteException re) {
                // Shouldn't happen