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

Commit 2ee89ea2 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Applications should -not- be able to set preferred activities.

I can't believe I let this slip through.  And in the SDK no less. :(

The APIs for setting preferred activities will now throw a security
exception when used.  This may break some apps, we'll see how it
goes.  If it is too bad we can just make these log and not throw
anything, but I would much prefer they throw an exception.

Change-Id: I3aed434750eef8b202aa9d5bd774a0121be521c6
parent d8929fa7
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -44348,7 +44348,7 @@
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 deprecated="deprecated"
 visibility="public"
>
<parameter name="filter" type="android.content.IntentFilter">
+11 −0
Original line number Diff line number Diff line
@@ -1896,6 +1896,10 @@ public abstract class PackageManager {
    public abstract List<PackageInfo> getPreferredPackages(int flags);

    /**
     * @deprecated This is a protected API that should not have been available
     * to third party applications.  It is the platform's responsibility for
     * assigning preferred activities and this can not be directly modified.
     * 
     * Add a new preferred activity mapping to the system.  This will be used
     * to automatically select the given activity component when
     * {@link Context#startActivity(Intent) Context.startActivity()} finds
@@ -1910,10 +1914,15 @@ public abstract class PackageManager {
     * @param activity The component name of the activity that is to be
     * preferred.
     */
    @Deprecated
    public abstract void addPreferredActivity(IntentFilter filter, int match,
            ComponentName[] set, ComponentName activity);

    /**
     * @deprecated This is a protected API that should not have been available
     * to third party applications.  It is the platform's responsibility for
     * assigning preferred activities and this can not be directly modified.
     * 
     * Replaces an existing preferred activity mapping to the system, and if that were not present
     * adds a new preferred activity.  This will be used
     * to automatically select the given activity component when
@@ -1930,6 +1939,7 @@ public abstract class PackageManager {
     * preferred.
     * @hide
     */
    @Deprecated
    public abstract void replacePreferredActivity(IntentFilter filter, int match,
            ComponentName[] set, ComponentName activity);

@@ -1937,6 +1947,7 @@ public abstract class PackageManager {
     * Remove all preferred activity mappings, previously added with
     * {@link #addPreferredActivity}, from the
     * system whose activities are implemented in the given package name.
     * An application can only clear its own package(s).
     *
     * @param packageName The name of the package whose preferred activity
     * mappings are to be removed.
+1 −1
Original line number Diff line number Diff line
@@ -648,7 +648,7 @@
         for details. -->
    <permission android:name="android.permission.SET_PREFERRED_APPLICATIONS"
        android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
        android:protectionLevel="dangerous"
        android:protectionLevel="signature"
        android:label="@string/permlab_setPreferredApplications"
        android:description="@string/permdesc_setPreferredApplications" />

+7 −3
Original line number Diff line number Diff line
@@ -6321,10 +6321,14 @@ class PackageManagerService extends IPackageManager.Stub {
    }

    public void clearPackagePreferredActivities(String packageName) {
        synchronized (mPackages) {
            int uid = Binder.getCallingUid();
            PackageParser.Package pkg = mPackages.get(packageName);
            if (pkg.applicationInfo.uid != uid) {
                mContext.enforceCallingOrSelfPermission(
                        android.Manifest.permission.SET_PREFERRED_APPLICATIONS, null);
            }

        synchronized (mPackages) {
            if (clearPackagePreferredActivitiesLP(packageName)) {
                mSettings.writeLP();
            }