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

Commit 870e09fc authored by Romain Guy's avatar Romain Guy
Browse files

Fixes #1963229. Introduces Context#isRestricted().

A restricted Context is a special type of Context that prevents specific features
from being used. For instance, android:onClick, used by View, can be dangerous when
used from within apps widgets. By using a restricted Context to inflate apps widgets,
widgets providers are prevented from using android:onClick.
parent 453dd50e
Loading
Loading
Loading
Loading
+22 −0
Original line number Original line Diff line number Diff line
@@ -27810,6 +27810,17 @@
<parameter name="modeFlags" type="int">
<parameter name="modeFlags" type="int">
</parameter>
</parameter>
</method>
</method>
<method name="isRestricted"
 return="boolean"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="obtainStyledAttributes"
<method name="obtainStyledAttributes"
 return="android.content.res.TypedArray"
 return="android.content.res.TypedArray"
 abstract="false"
 abstract="false"
@@ -28323,6 +28334,17 @@
 visibility="public"
 visibility="public"
>
>
</field>
</field>
<field name="CONTEXT_RESTRICTED"
 type="int"
 transient="false"
 volatile="false"
 value="4"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="INPUT_METHOD_SERVICE"
<field name="INPUT_METHOD_SERVICE"
 type="java.lang.String"
 type="java.lang.String"
 transient="false"
 transient="false"
+7 −0
Original line number Original line Diff line number Diff line
@@ -184,6 +184,7 @@ class ApplicationContext extends Context {
    private StatusBarManager mStatusBarManager = null;
    private StatusBarManager mStatusBarManager = null;
    private TelephonyManager mTelephonyManager = null;
    private TelephonyManager mTelephonyManager = null;
    private ClipboardManager mClipboardManager = null;
    private ClipboardManager mClipboardManager = null;
    private boolean mRestricted;


    private final Object mSync = new Object();
    private final Object mSync = new Object();


@@ -1336,6 +1337,7 @@ class ApplicationContext extends Context {
            mMainThread.getPackageInfo(packageName, flags);
            mMainThread.getPackageInfo(packageName, flags);
        if (pi != null) {
        if (pi != null) {
            ApplicationContext c = new ApplicationContext();
            ApplicationContext c = new ApplicationContext();
            c.mRestricted = (flags & CONTEXT_RESTRICTED) == CONTEXT_RESTRICTED;
            c.init(pi, null, mMainThread);
            c.init(pi, null, mMainThread);
            if (c.mResources != null) {
            if (c.mResources != null) {
                return c;
                return c;
@@ -1347,6 +1349,11 @@ class ApplicationContext extends Context {
            "Application package " + packageName + " not found");
            "Application package " + packageName + " not found");
    }
    }


    @Override
    public boolean isRestricted() {
        return mRestricted;
    }

    private File getDataDirFile() {
    private File getDataDirFile() {
        if (mPackageInfo != null) {
        if (mPackageInfo != null) {
            return mPackageInfo.getDataDirFile();
            return mPackageInfo.getDataDirFile();
+1 −1
Original line number Original line Diff line number Diff line
@@ -269,7 +269,7 @@ public class AppWidgetHostView extends FrameLayout {
        try {
        try {
            if (mInfo != null) {
            if (mInfo != null) {
                Context theirContext = mContext.createPackageContext(
                Context theirContext = mContext.createPackageContext(
                        mInfo.provider.getPackageName(), 0 /* no flags */);
                        mInfo.provider.getPackageName(), Context.CONTEXT_RESTRICTED);
                LayoutInflater inflater = (LayoutInflater)
                LayoutInflater inflater = (LayoutInflater)
                        theirContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                        theirContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                inflater = inflater.cloneInContext(theirContext);
                inflater = inflater.cloneInContext(theirContext);
+18 −0
Original line number Original line Diff line number Diff line
@@ -1655,6 +1655,13 @@ public abstract class Context {
     */
     */
    public static final int CONTEXT_IGNORE_SECURITY = 0x00000002;
    public static final int CONTEXT_IGNORE_SECURITY = 0x00000002;
    
    
    /**
     * Flag for use with {@link #createPackageContext}: a restricted context may
     * disable specific features. For instance, a View associated with a restricted
     * context would ignore particular XML attributes.
     */
    public static final int CONTEXT_RESTRICTED = 0x00000004;

    /**
    /**
     * Return a new Context object for the given application name.  This
     * Return a new Context object for the given application name.  This
     * Context is the same as what the named application gets when it is
     * Context is the same as what the named application gets when it is
@@ -1682,4 +1689,15 @@ public abstract class Context {
     */
     */
    public abstract Context createPackageContext(String packageName,
    public abstract Context createPackageContext(String packageName,
            int flags) throws PackageManager.NameNotFoundException;
            int flags) throws PackageManager.NameNotFoundException;

    /**
     * Indicates whether this Context is restricted.
     * 
     * @return True if this Context is restricted, false otherwise.
     * 
     * @see #CONTEXT_RESTRICTED
     */
    public boolean isRestricted() {
        return false;
    }
}
}
+5 −0
Original line number Original line Diff line number Diff line
@@ -430,4 +430,9 @@ public class ContextWrapper extends Context {
        throws PackageManager.NameNotFoundException {
        throws PackageManager.NameNotFoundException {
        return mBase.createPackageContext(packageName, flags);
        return mBase.createPackageContext(packageName, flags);
    }
    }

    @Override
    public boolean isRestricted() {
        return mBase.isRestricted();
    }
}
}
Loading