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

Commit ad00cb08 authored by Raj Yengisetty's avatar Raj Yengisetty Committed by Steve Kondik
Browse files

Protected apps

Fix up protected apps filter.

Move filtering to correct place (when querying providers,
ResolveInfo.activityInfo is null), and port over commit
4dad4a4e from cm-11.0.

Protected Apps: do not filter components from the same UID

pm: Use ArraySet instead of HashSet

packagemanager: Use ArrayMap/ArraySet as per AOSP

 * To reduce memory consumption

Change-Id: Ic690387cd21fdfa09ef5fb19bd3de9305050cf6e

fw: Fix protected apps implementation.

 Currently a protected component could be accessed
 from any other means other than the launcher, entirely
 defeating its purpose. Instead, hook into the activity
 stack supervisor and quelch attempts at invocation
 of protected components.

 This implementation also provides feedback to the user
 on any attempt to start the component when its in a
 protected state.

TICKET: CYNGNOS-84
Change-Id: Ib0165e7504adb08e21e9566c7394b37dffd280d4

pm: Avoid filtering out protected components in implicit queries.

  Implicity queries resolve the target component for an intent, the
  intent (if fired) will be gated by the protected apps feature
  implementation within the activity stack supervisor.

Change-Id: Ib079cfa6093f472d4b85f6b4a986440a764affa3
TICKET: FEIJ-1449

am: Don't protect apps that atttempt to grant uri perms.

  If an application is delegating uri permissions through
  the disambiguation dialog, we need to ignore the global
  protected apps concept to make sure the functionality still
  works.

  TODO: Refactor the protected apps implementation to function
  with startActivityAsCaller within the system process and the
  android package.

  TICKET: FEIJ-420

Change-Id: I8ba974a7b25dffe654d32e859064ae86cd9dc7f8

am: Handle unchecked activity starts for protected components.

  Previously if you received a notification from a protected app,
  since AM would state that the calling package was also the target
  package, the protected apps implementation would allow you to
  launch into the application. Mitigate this by hooking into
  the unchecked activity start stack (pending intent launches)
  globally.

Change-Id: I0371593ade9e4af2554962873d89a0f82a639b57
TICKET: PAELLA-216 FEIJ-160 FEIJ-177

pm: Allow fall through for protected apps validator activity.

  Otherwise protecting the settings application leads to some weird
  behavior.

TICKET: CYNGNOS-1915
Change-Id: I4821a07aadf73e7664c44275d8ed80709c7fde8c

am: Cancel protected app notification on validation launch.

Change-Id: I89d7366e97db04874baa5b19c2dfee7f0100c848
TICKET: CYNGNOS-2130

am: clear protected apps from recents

Remove newly protected apps from recent tasks if any activity
in the stack is a restricted component.

FEIJ-1361
Change-Id: Ifd337bfe8356613d098ff00c575db117d35f2017

am: clear state for every protected app invocation.

Change-Id: I7766e050b8bedb46ff9293a5d61451e6c998fb0b
TICKET: CYNGNOS-2962

pm: Use sourcerecord if available for protected app validation.

  A source record serves as a beneficial historical record to
  see if an activity start has been redirected numerous times.

  This fixes issues where applications that redirect implicitly
  and are protected would constantly spam to be authed.

Change-Id: Ibeb9eae4279a0cdd65635392316eabb485adfa27
TICKET: PAELLA-216 FEIJ-160 FEIJ-177

core: Improve protected apps notification message

Change-Id: Ib8bce9494bae2203260bdc844fe1f367d599b719
parent 8617c549
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -2216,6 +2216,28 @@ public class ApplicationPackageManager extends PackageManager {
        }
    }

    @Override
    public void setComponentProtectedSetting(ComponentName componentName, boolean newState) {
        try {
            mPM.setComponentProtectedSetting(componentName, newState, mContext.getUserId());
        } catch (RemoteException re) {
            Log.e(TAG, "Failed to set component protected setting", re);
        }
    }

    /** @hide */
    @Override
    public boolean isComponentProtected(String callingPackage, int callingUid,
            ComponentName componentName) {
        try {
            return mPM.isComponentProtected(callingPackage, callingUid, componentName,
                    mContext.getUserId());
        } catch (RemoteException re) {
            Log.e(TAG, "Failed to get component protected setting", re);
            return false;
        }
    }

    @Override
    public PackageInstaller getPackageInstaller() {
        synchronized (mLock) {
+10 −0
Original line number Diff line number Diff line
@@ -777,6 +777,13 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
     */
    public int networkSecurityConfigRes;

    /**
     * When true, indicates that any one component within this application is
     * protected.
     * @hide
     */
    public boolean protect = false;

    public void dump(Printer pw, String prefix) {
        dump(pw, prefix, DUMP_FLAG_ALL);
    }
@@ -940,6 +947,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
        backupAgentName = orig.backupAgentName;
        fullBackupContent = orig.fullBackupContent;
        networkSecurityConfigRes = orig.networkSecurityConfigRes;
        protect = orig.protect;
    }

    public String toString() {
@@ -997,6 +1005,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
        dest.writeInt(uiOptions);
        dest.writeInt(fullBackupContent);
        dest.writeInt(networkSecurityConfigRes);
        dest.writeInt(protect ? 1 : 0);
    }

    public static final Parcelable.Creator<ApplicationInfo> CREATOR
@@ -1054,6 +1063,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
        uiOptions = source.readInt();
        fullBackupContent = source.readInt();
        networkSecurityConfigRes = source.readInt();
        protect = source.readInt() != 0;
    }

    /**
+8 −0
Original line number Diff line number Diff line
@@ -573,4 +573,12 @@ interface IPackageManager {
    boolean isPackageDeviceAdminOnAnyUser(String packageName);

    List<String> getPreviousCodePaths(in String packageName);

    /** Protected Apps */
    void setComponentProtectedSetting(in ComponentName componentName,
    in boolean newState, int userId);

    /** Protected Apps */
    boolean isComponentProtected(in String callingPackage, in int callingUid,
    in ComponentName componentName, int userId);
}
+27 −0
Original line number Diff line number Diff line
@@ -2366,6 +2366,20 @@ public abstract class PackageManager {
    public static final String EXTRA_REQUEST_PERMISSIONS_RESULTS
            = "android.content.pm.extra.REQUEST_PERMISSIONS_RESULTS";

    /**
     * Flag for {@link #setComponentProtectedSetting(android.content.ComponentName, boolean)}:
     * This component or application has set to protected status
     * @hide
     */
    public static final boolean COMPONENT_PROTECTED_STATUS = false;

    /**
     * Flag for {@link #setComponentProtectedSetting(android.content.ComponentName, boolean)}:
     * This component or application has been explicitly set to visible status
     * @hide
     */
    public static final boolean COMPONENT_VISIBLE_STATUS = true;

    /**
     * String extra for {@link PackageInstallObserver} in the 'extras' Bundle in case of
     * {@link #INSTALL_FAILED_DUPLICATE_PERMISSION}.  This extra names the package which provides
@@ -5596,6 +5610,19 @@ public abstract class PackageManager {
     */
    public abstract @NonNull PackageInstaller getPackageInstaller();

    /**
     * Update Component protection state
     * @hide
     */
    public abstract void setComponentProtectedSetting(ComponentName componentName, boolean newState);

    /**
     * Return whether or not a specific component is protected
     * @hide
     */
    public abstract boolean isComponentProtected(String callingPackage, int callingUid,
            ComponentName componentName);

    /**
     * Adds a {@code CrossProfileIntentFilter}. After calling this method all
     * intents sent from the user with id sourceUserId can also be be resolved
+9 −0
Original line number Diff line number Diff line
@@ -5416,6 +5416,12 @@ public class PackageParser {
                && p.usesLibraryFiles != null) {
            return true;
        }
        if (state.protectedComponents != null) {
            boolean protect = state.protectedComponents.size() > 0;
            if (p.applicationInfo.protect != protect) {
                return true;
            }
        }
        return false;
    }

@@ -5454,6 +5460,9 @@ public class PackageParser {
            ai.enabled = false;
        }
        ai.enabledSetting = state.enabled;
        if (state.protectedComponents != null) {
            ai.protect = state.protectedComponents.size() > 0;
        }
    }

    public static ApplicationInfo generateApplicationInfo(Package p, int flags,
Loading