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

Commit 676846ce authored by Shashank Mittal's avatar Shashank Mittal Committed by Steve Kondik
Browse files

AppOps: Fix mms control in AppOps.

Add support to check user permission before sending MMS.
Also seperate out SMS operations from MMS operations.

Change-Id: Ia5b73e6b6a2c48b608a0ef1d199429c6c0e21f75
parent 3cda31c8
Loading
Loading
Loading
Loading
+46 −1
Original line number Diff line number Diff line
@@ -223,7 +223,13 @@ public class AppOpsManager {
    /** @hide */
    public static final int OP_BLUETOOTH_CHANGE = 49;
    /** @hide */
    public static final int _NUM_OP = 50;
    public static final int OP_SEND_MMS = 50;
    /** @hide */
    public static final int OP_READ_MMS = 51;
    /** @hide */
    public static final int OP_WRITE_MMS = 52;
    /** @hide */
    public static final int _NUM_OP = 53;

    /** Access to coarse location information. */
    public static final String OPSTR_COARSE_LOCATION =
@@ -332,6 +338,12 @@ public class AppOpsManager {
            "android:wifi_change";
    private static final String OPSTR_BLUETOOTH_CHANGE =
            "android:bluetooth_change";
    private static final String OPSTR_SEND_MMS =
            "android:send_mms";
    private static final String OPSTR_READ_MMS =
            "android:read_mms";
    private static final String OPSTR_WRITE_MMS =
            "android:write_mms";

    /**
     * This maps each operation to the operation that serves as the
@@ -392,6 +404,9 @@ public class AppOpsManager {
            OP_ACTIVATE_VPN,
            OP_WIFI_CHANGE,
            OP_BLUETOOTH_CHANGE,
            OP_SEND_MMS,
            OP_READ_MMS,
            OP_WRITE_MMS,
    };

    /**
@@ -449,6 +464,9 @@ public class AppOpsManager {
            null,
            OPSTR_ACTIVATE_VPN,
            null,
            null,
            null,
            null,
    };

    /**
@@ -506,6 +524,9 @@ public class AppOpsManager {
        OPSTR_ACTIVATE_VPN,
        OPSTR_WIFI_CHANGE,
        OPSTR_BLUETOOTH_CHANGE,
        OPSTR_SEND_MMS,
        OPSTR_READ_MMS,
        OPSTR_WRITE_MMS,
    };

    /**
@@ -563,6 +584,9 @@ public class AppOpsManager {
            "ACTIVATE_VPN",
            "WIFI_CHANGE",
            "BLUETOOTH_CHANGE",
            "SEND_MMS",
            "READ_MMS",
            "WRITE_MMS",
    };

    /**
@@ -620,6 +644,9 @@ public class AppOpsManager {
            null, // no permission for activating vpn
            android.Manifest.permission.CHANGE_WIFI_STATE,
            android.Manifest.permission.BLUETOOTH,
            android.Manifest.permission.SEND_SMS,
            android.Manifest.permission.READ_SMS,
            android.Manifest.permission.WRITE_SMS,
    };

    /**
@@ -678,6 +705,9 @@ public class AppOpsManager {
            UserManager.DISALLOW_CONFIG_VPN, // ACTIVATE_VPN
            null, //WIFI_CHANGE
            null, //BLUETOOTH_CHANGE
            null, //SEND_MMS
            null, //READ_MMS
            null, //WRITE_MMS
    };

    /**
@@ -735,6 +765,9 @@ public class AppOpsManager {
            false, //ACTIVATE_VPN
            false, // WIFI_CHANGE
            false, // BLUETOOTH_CHANGE
            false, // SEND_MMS
            false, // READ_MMS
            false, // WRITE_MMS
    };

    /**
@@ -791,6 +824,9 @@ public class AppOpsManager {
            AppOpsManager.MODE_IGNORED, // OP_ACTIVATE_VPN
            AppOpsManager.MODE_ALLOWED,
            AppOpsManager.MODE_ALLOWED,
            AppOpsManager.MODE_ALLOWED,
            AppOpsManager.MODE_ALLOWED,
            AppOpsManager.MODE_ALLOWED,
    };

    /**
@@ -848,6 +884,9 @@ public class AppOpsManager {
            AppOpsManager.MODE_IGNORED, // OP_ACTIVATE_VPN
            AppOpsManager.MODE_ASK,     // OP_WIFI_CHANGE
            AppOpsManager.MODE_ASK,     // OP_BLUETOOTH_CHANGE
            AppOpsManager.MODE_ASK,     // OP_SEND_MMS
            AppOpsManager.MODE_ASK,     // OP_READ_MMS
            AppOpsManager.MODE_ASK,     // OP_WRITE_MMS
    };

    /**
@@ -904,6 +943,9 @@ public class AppOpsManager {
        false,    // OP_ACTIVATE_VPN
        true,     // OP_WIFI_CHANGE
        true,     // OP_BLUETOOTH_CHANGE
        true,     // OP_SEND_MMS
        true,     // OP_READ_MMS
        true,     // OP_WRITE_MMS
    };

    /**
@@ -964,6 +1006,9 @@ public class AppOpsManager {
            false,
            false,     // OP_WIFI_CHANGE
            false,     // OP_BLUETOOTH_CHANGE
            false,     // OP_SEND_MMS
            false,     // OP_READ_MMS
            false,     // OP_WRITE_MMS
    };

    private static HashMap<String, Integer> sOpStrToOp = new HashMap<String, Integer>();
+63 −0
Original line number Diff line number Diff line
/*
 * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
 * Not a Contribution.
 *
 * Copyright (C) 2007 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
@@ -42,6 +45,7 @@ import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.RequestWrapper;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.CoreProtocolPNames;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.params.HttpProtocolParams;
@@ -49,10 +53,13 @@ import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.BasicHttpProcessor;
import org.apache.http.protocol.HttpContext;

import android.app.ActivityThread;
import android.app.AppOpsManager;
import android.content.ContentResolver;
import android.content.Context;
import android.net.SSLCertificateSocketFactory;
import android.net.SSLSessionCache;
import android.os.Binder;
import android.os.Looper;
import android.util.Base64;
import android.util.Log;
@@ -248,46 +255,102 @@ public final class AndroidHttpClient implements HttpClient {
        return delegate.getConnectionManager();
    }

    private boolean isMmsRequest()
    {
        if(delegate.getParams().getParameter(CoreProtocolPNames.USER_AGENT).toString().contains("Android-Mms"))
            return true;

        return false;
    }

    private boolean checkMmsOps()
    {
        AppOpsManager appOps = (AppOpsManager) ActivityThread.currentApplication().getSystemService(Context.APP_OPS_SERVICE);
        int callingUid = Binder.getCallingUid();
        String callingPackage= ActivityThread.currentPackageName();

        if (appOps.noteOp(AppOpsManager.OP_SEND_MMS, callingUid, callingPackage) !=
                AppOpsManager.MODE_ALLOWED)
                return false;

        return true;
    }

    private String getMethod(HttpUriRequest request) {
        if(request != null)
            return request.getMethod();
        return null;
    }

    private String getMethod(HttpRequest request) {
        if(request != null)
            if(request.getRequestLine() != null)
                return request.getRequestLine().getMethod();
        return null;
    }

    private boolean checkMmsSendPermission(String method) {
        if(isMmsRequest() && method.equals("POST"))
            return checkMmsOps();
        return true;
    }

    public HttpResponse execute(HttpUriRequest request) throws IOException {
        if(!checkMmsSendPermission(getMethod(request)))
            throw new IOException("Permission denied");
        return delegate.execute(request);
    }

    public HttpResponse execute(HttpUriRequest request, HttpContext context)
            throws IOException {
        if(!checkMmsSendPermission(getMethod(request)))
            throw new IOException("Permission denied");
        return delegate.execute(request, context);
    }

    public HttpResponse execute(HttpHost target, HttpRequest request)
            throws IOException {
        if(!checkMmsSendPermission(getMethod(request)))
            throw new IOException("Permission denied");
        return delegate.execute(target, request);
    }

    public HttpResponse execute(HttpHost target, HttpRequest request,
            HttpContext context) throws IOException {
        if(!checkMmsSendPermission(getMethod(request)))
            throw new IOException("Permission denied");
        return delegate.execute(target, request, context);
    }

    public <T> T execute(HttpUriRequest request,
            ResponseHandler<? extends T> responseHandler)
            throws IOException, ClientProtocolException {
        if(!checkMmsSendPermission(getMethod(request)))
            throw new IOException("Permission denied");
        return delegate.execute(request, responseHandler);
    }

    public <T> T execute(HttpUriRequest request,
            ResponseHandler<? extends T> responseHandler, HttpContext context)
            throws IOException, ClientProtocolException {
        if(!checkMmsSendPermission(getMethod(request)))
            throw new IOException("Permission denied");
        return delegate.execute(request, responseHandler, context);
    }

    public <T> T execute(HttpHost target, HttpRequest request,
            ResponseHandler<? extends T> responseHandler) throws IOException,
            ClientProtocolException {
        if(!checkMmsSendPermission(getMethod(request)))
            throw new IOException("Permission denied");
        return delegate.execute(target, request, responseHandler);
    }

    public <T> T execute(HttpHost target, HttpRequest request,
            ResponseHandler<? extends T> responseHandler, HttpContext context)
            throws IOException, ClientProtocolException {
        if(!checkMmsSendPermission(getMethod(request)))
            throw new IOException("Permission denied");
        return delegate.execute(target, request, responseHandler, context);
    }

+12 −9
Original line number Diff line number Diff line
@@ -1917,15 +1917,15 @@
        <item>Trying to post notification</item>
        <item>Trying to access location</item>
        <item>Trying to make phone call</item>
        <item>Trying to read SMS/MMS</item>
        <item>Trying to write/modify SMS/MMS</item>
        <item>Trying to receive SMS/MMS</item>
        <item>Trying to receive SMS/MMS</item>
        <item>Trying to receive SMS/MMS</item>
        <item>Trying to receive SMS/MMS</item>
        <item>Trying to send SMS/MMS</item>
        <item>Trying to read SMS/MMS</item>
        <item>Trying to write/modify SMS/MMS</item>
        <item>Trying to read SMS</item>
        <item>Trying to write/modify SMS</item>
        <item>Trying to receive SMS</item>
        <item>Trying to receive emergency SMS</item>
        <item>Trying to receive MMS</item>
        <item>Trying to receive WAP push</item>
        <item>Trying to send SMS</item>
        <item>Trying to read ICC SMS</item>
        <item>Trying to write/modify ICC SMS</item>
        <item>Trying to modify settings</item>
        <item>Trying to draw on top</item>
        <item>Trying to access notifications</item>
@@ -1953,5 +1953,8 @@
        <item>Trying to activate vpn</item>
        <item>Trying to turn on/off Wifi</item>
        <item>Trying to trun on/off bluetooth</item>
        <item>Trying to send MMS</item>
        <item>Trying to read MMS</item>
        <item>Trying to write MMS</item>
    </string-array>
</resources>