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

Commit 7c6f8328 authored by Leland Miller's avatar Leland Miller Committed by Android (Google) Code Review
Browse files

Merge changes from topic "permissions" into qt-dev

* changes:
  Check permissions in RcsMessageStoreController
  Use RcsMessageQueryResultParcelable
  Use RcsParticipantQueryResultParcelable
  Use RcsThreadQueryResultParcelable
parents f18a7b3a 336de534
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -57,7 +57,7 @@ import android.os.Bundle;
import android.os.RemoteException;
import android.telephony.ims.RcsFileTransferCreationParams;
import android.telephony.ims.RcsMessageCreationParams;
import android.telephony.ims.RcsMessageQueryResult;
import android.telephony.ims.RcsMessageQueryResultParcelable;
import android.telephony.ims.RcsQueryContinuationToken;

import com.android.ims.RcsTypeIdPair;
@@ -77,7 +77,7 @@ class RcsMessageQueryHelper {
        mContentResolver = contentResolver;
    }

    RcsMessageQueryResult performMessageQuery(Bundle bundle) throws RemoteException {
    RcsMessageQueryResultParcelable performMessageQuery(Bundle bundle) throws RemoteException {
        RcsQueryContinuationToken continuationToken = null;
        List<RcsTypeIdPair> messageTypeIdPairs = new ArrayList<>();

@@ -104,7 +104,7 @@ class RcsMessageQueryHelper {
            }
        }

        return new RcsMessageQueryResult(continuationToken, messageTypeIdPairs);
        return new RcsMessageQueryResultParcelable(continuationToken, messageTypeIdPairs);
    }

    void createContentValuesForGenericMessage(ContentValues contentValues, int threadId,
+557 −395

File changed.

Preview size limit exceeded, changes collapsed.

+4 −20
Original line number Diff line number Diff line
@@ -24,37 +24,21 @@ import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.RemoteException;
import android.telephony.ims.RcsParticipant;
import android.telephony.ims.RcsParticipantQueryResult;
import android.telephony.ims.RcsParticipantQueryResultParcelable;
import android.telephony.ims.RcsQueryContinuationToken;

import java.util.ArrayList;
import java.util.List;

class RcsParticipantQueryHelper {
    static final Uri CANONICAL_ADDRESSES_URI = Uri.parse("content://mms-sms/canonical-addresses");
    private final ContentResolver mContentResolver;

    RcsParticipantQueryHelper(ContentResolver contentResolver) {
        mContentResolver = contentResolver;
    }

    RcsParticipant getParticipantFromId(int participantId) throws RemoteException {
        RcsParticipant participant = null;
        try (Cursor cursor = mContentResolver.query(
                Uri.withAppendedPath(RCS_PARTICIPANT_URI, Integer.toString(participantId)),
                new String[]{RCS_PARTICIPANT_ID_COLUMN}, null, null)) {
            if (cursor == null || !cursor.moveToNext()) {
                throw new RemoteException("Could not find participant with id: " + participantId);
            }

            participant = new RcsParticipant(
                    cursor.getInt(cursor.getColumnIndex(RCS_PARTICIPANT_ID_COLUMN)));
        }
        return participant;
    }

    RcsParticipantQueryResult performParticipantQuery(Bundle bundle) throws RemoteException {
    RcsParticipantQueryResultParcelable performParticipantQuery(Bundle bundle)
            throws RemoteException {
        RcsQueryContinuationToken continuationToken = null;
        List<Integer> participantList = new ArrayList<>();

@@ -74,7 +58,7 @@ class RcsParticipantQueryHelper {
            }
        }

        return new RcsParticipantQueryResult(continuationToken, participantList);
        return new RcsParticipantQueryResultParcelable(continuationToken, participantList);
    }

    static Uri getUriForParticipant(int participantId) {
+61 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.telephony.ims;

import android.Manifest;
import android.app.AppOpsManager;
import android.content.Context;
import android.os.Binder;

class RcsPermissions {
    static void checkReadPermissions(Context context, String callingPackage) {
        int pid = Binder.getCallingPid();
        int uid = Binder.getCallingUid();

        context.enforcePermission(Manifest.permission.READ_SMS, pid, uid, null);

        checkOp(context, uid, callingPackage, AppOpsManager.OP_READ_SMS);
    }

    static void checkWritePermissions(Context context, String callingPackage) {
        int uid = Binder.getCallingUid();

        checkOp(context, uid, callingPackage, AppOpsManager.OP_WRITE_SMS);
    }

    /**
     * Notes the provided op, but throws even if the op mode is {@link AppOpsManager.MODE_IGNORED}.
     * <p>
     * {@link AppOpsManager.OP_WRITE_SMS} defaults to {@link AppOpsManager.MODE_IGNORED} to avoid
     * crashing applications written before the app op was introduced. Since this is a new API,
     * consumers should be aware of the permission requirements, and we should be safe to throw a
     * {@link SecurityException} instead of providing a dummy value (which could cause unexpected
     * application behavior and possible loss of user data). {@link AppOpsManager.OP_READ_SMS} is
     * not normally in {@link AppOpsManager.MODE_IGNORED}, but we maintain the same behavior for
     * consistency with handling of write permissions.
     */
    private static void checkOp(Context context, int uid, String callingPackage, int op) {
        AppOpsManager appOps = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);

        int mode = appOps.noteOp(op, uid, callingPackage);

        if (mode != AppOpsManager.MODE_ALLOWED) {
            throw new SecurityException(
                    AppOpsManager.opToName(op) + " not allowed for " + callingPackage);
        }
    }
}
+3 −3
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.RemoteException;
import android.telephony.ims.RcsQueryContinuationToken;
import android.telephony.ims.RcsThreadQueryResult;
import android.telephony.ims.RcsThreadQueryResultParcelable;

import com.android.ims.RcsTypeIdPair;

@@ -60,7 +60,7 @@ class RcsThreadQueryHelper {
        mParticipantQueryHelper = participantQueryHelper;
    }

    RcsThreadQueryResult performThreadQuery(Bundle bundle) throws RemoteException {
    RcsThreadQueryResultParcelable performThreadQuery(Bundle bundle) throws RemoteException {
        RcsQueryContinuationToken continuationToken = null;
        List<RcsTypeIdPair> rcsThreadIdList = new ArrayList<>();
        try (Cursor cursor = mContentResolver.query(RCS_THREAD_URI, null, bundle, null)) {
@@ -87,7 +87,7 @@ class RcsThreadQueryHelper {
                continuationToken = cursorExtras.getParcelable(QUERY_CONTINUATION_TOKEN);
            }
        }
        return new RcsThreadQueryResult(continuationToken, rcsThreadIdList);
        return new RcsThreadQueryResultParcelable(continuationToken, rcsThreadIdList);
    }

    int create1To1Thread(int participantId) throws RemoteException {
Loading