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

Commit 32f87fc6 authored by Amit Mahajan's avatar Amit Mahajan Committed by Gerrit Code Review
Browse files

Merge changes from topic "Delete RcsMessage code"

* changes:
  Remove the usage of Downloads.* constants.
  Delete unused RcsMessage code for now.
  Move EXTRA_SERVICE_STATE from Intent to ServiceState.
parents a9e6a280 89a60697
Loading
Loading
Loading
Loading
+0 −6
Original line number Diff line number Diff line
@@ -4514,12 +4514,6 @@ public class Intent implements Parcelable, Cloneable {
    @SystemApi
    public static final String EXTRA_LTE_EARFCN_RSRP_BOOST = "LteEarfcnRsrpBoost";

    /**
     * An parcelable extra used with {@link #ACTION_SERVICE_STATE} representing the service state.
     * @hide
     */
    public static final String EXTRA_SERVICE_STATE = "android.intent.extra.SERVICE_STATE";

    /**
     * The name of the extra used to define the text to be processed, as a
     * CharSequence. Note that this may be a styled CharSequence, so you must use
+18 −12
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.drm.DrmConvertedStatus;
import android.drm.DrmManagerClient;
import android.provider.Downloads;
import android.util.Log;

import java.io.FileNotFoundException;
@@ -33,6 +32,13 @@ public class DrmConvertSession {
    private int mConvertSessionId;
    private static final String TAG = "DrmConvertSession";

    // These values are copied from Downloads.Impl.* for backward compatibility since
    // {@link #close()} that uses it is marked @UnsupportedAppUsage.
    public static final int STATUS_SUCCESS = 200;
    public static final int STATUS_NOT_ACCEPTABLE = 406;
    public static final int STATUS_UNKNOWN_ERROR = 491;
    public static final int STATUS_FILE_ERROR = 492;

    private DrmConvertSession(DrmManagerClient drmClient, int convertSessionId) {
        mDrmClient = drmClient;
        mConvertSessionId = convertSessionId;
@@ -118,38 +124,38 @@ public class DrmConvertSession {
     * Ends a conversion session of a file.
     *
     * @param fileName The filename of the converted file.
     * @return Downloads.Impl.STATUS_SUCCESS if execution is ok.
     *         Downloads.Impl.STATUS_FILE_ERROR in case converted file can not
     *         be accessed. Downloads.Impl.STATUS_NOT_ACCEPTABLE if a problem
     * @return STATUS_SUCCESS if execution is ok.
     *         STATUS_FILE_ERROR in case converted file can not
     *         be accessed. STATUS_NOT_ACCEPTABLE if a problem
     *         occurs when accessing drm framework.
     *         Downloads.Impl.STATUS_UNKNOWN_ERROR if a general error occurred.
     *         STATUS_UNKNOWN_ERROR if a general error occurred.
     */
    @UnsupportedAppUsage
    public int close(String filename) {
        DrmConvertedStatus convertedStatus = null;
        int result = Downloads.Impl.STATUS_UNKNOWN_ERROR;
        int result = STATUS_UNKNOWN_ERROR;
        if (mDrmClient != null && mConvertSessionId >= 0) {
            try {
                convertedStatus = mDrmClient.closeConvertSession(mConvertSessionId);
                if (convertedStatus == null ||
                        convertedStatus.statusCode != DrmConvertedStatus.STATUS_OK ||
                        convertedStatus.convertedData == null) {
                    result = Downloads.Impl.STATUS_NOT_ACCEPTABLE;
                    result = STATUS_NOT_ACCEPTABLE;
                } else {
                    RandomAccessFile rndAccessFile = null;
                    try {
                        rndAccessFile = new RandomAccessFile(filename, "rw");
                        rndAccessFile.seek(convertedStatus.offset);
                        rndAccessFile.write(convertedStatus.convertedData);
                        result = Downloads.Impl.STATUS_SUCCESS;
                        result = STATUS_SUCCESS;
                    } catch (FileNotFoundException e) {
                        result = Downloads.Impl.STATUS_FILE_ERROR;
                        result = STATUS_FILE_ERROR;
                        Log.w(TAG, "File: " + filename + " could not be found.", e);
                    } catch (IOException e) {
                        result = Downloads.Impl.STATUS_FILE_ERROR;
                        result = STATUS_FILE_ERROR;
                        Log.w(TAG, "Could not access File: " + filename + " .", e);
                    } catch (IllegalArgumentException e) {
                        result = Downloads.Impl.STATUS_FILE_ERROR;
                        result = STATUS_FILE_ERROR;
                        Log.w(TAG, "Could not open file in mode: rw", e);
                    } catch (SecurityException e) {
                        Log.w(TAG, "Access to File: " + filename +
@@ -159,7 +165,7 @@ public class DrmConvertSession {
                            try {
                                rndAccessFile.close();
                            } catch (IOException e) {
                                result = Downloads.Impl.STATUS_FILE_ERROR;
                                result = STATUS_FILE_ERROR;
                                Log.w(TAG, "Failed to close File:" + filename
                                        + ".", e);
                            }
+10 −2
Original line number Diff line number Diff line
@@ -317,6 +317,14 @@ public class ServiceState implements Parcelable {
     */
    public static final int UNKNOWN_ID = -1;

    /**
     * A parcelable extra used with {@link Intent#ACTION_SERVICE_STATE} representing the service
     * state.
     * @hide
     */
    private static final String EXTRA_SERVICE_STATE = "android.intent.extra.SERVICE_STATE";


    private String mOperatorAlphaLong;
    private String mOperatorAlphaShort;
    private String mOperatorNumeric;
@@ -1292,7 +1300,7 @@ public class ServiceState implements Parcelable {
     */
    @UnsupportedAppUsage
    private void setFromNotifierBundle(Bundle m) {
        ServiceState ssFromBundle = m.getParcelable(Intent.EXTRA_SERVICE_STATE);
        ServiceState ssFromBundle = m.getParcelable(EXTRA_SERVICE_STATE);
        if (ssFromBundle != null) {
            copyFrom(ssFromBundle);
        }
@@ -1310,7 +1318,7 @@ public class ServiceState implements Parcelable {
     */
    @SystemApi
    public void fillInNotifierBundle(@NonNull Bundle m) {
        m.putParcelable(Intent.EXTRA_SERVICE_STATE, this);
        m.putParcelable(EXTRA_SERVICE_STATE, this);
        // serviceState already consists of below entries.
        // for backward compatibility, we continue fill in below entries.
        m.putInt("voiceRegState", mVoiceRegState);
+0 −92
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 android.telephony.ims;

import android.annotation.NonNull;
import android.annotation.WorkerThread;

/**
 * Rcs1To1Thread represents a single RCS conversation thread with a total of two
 * {@link RcsParticipant}s. Please see Section 5 (1-to-1 Messaging) - GSMA RCC.71 (RCS Universal
 * Profile Service Definition Document)
 *
 * @hide
 */
public class Rcs1To1Thread extends RcsThread {
    private int mThreadId;

    /**
     * Public constructor only for RcsMessageStoreController to initialize new threads.
     *
     * @hide
     */
    public Rcs1To1Thread(RcsControllerCall rcsControllerCall, int threadId) {
        super(rcsControllerCall, threadId);
        mThreadId = threadId;
    }

    /**
     * @return Returns {@code false} as this is always a 1 to 1 thread.
     */
    @Override
    public boolean isGroup() {
        return false;
    }

    /**
     * {@link Rcs1To1Thread}s can fall back to SMS as a back-up protocol. This function returns the
     * thread id to be used to query {@code content://mms-sms/conversation/#} to get the fallback
     * thread.
     *
     * @return The thread id to be used to query the mms-sms authority
     * @throws RcsMessageStoreException if the value could not be read from the storage
     */
    @WorkerThread
    public long getFallbackThreadId() throws RcsMessageStoreException {
        return mRcsControllerCall.call(
                (iRcs, callingPackage) -> iRcs.get1To1ThreadFallbackThreadId(mThreadId,
                        callingPackage));
    }

    /**
     * If the RCS client allows falling back to SMS, it needs to create an MMS-SMS thread in the
     * SMS/MMS Provider( see {@link android.provider.Telephony.MmsSms#CONTENT_CONVERSATIONS_URI}.
     * Use this function to link the {@link Rcs1To1Thread} to the MMS-SMS thread. This function
     * also updates the storage.
     *
     * @throws RcsMessageStoreException if the value could not be persisted into storage
     */
    @WorkerThread
    public void setFallbackThreadId(long fallbackThreadId) throws RcsMessageStoreException {
        mRcsControllerCall.callWithNoReturn(
                (iRcs, callingPackage) -> iRcs.set1To1ThreadFallbackThreadId(mThreadId,
                        fallbackThreadId, callingPackage));
    }

    /**
     * @return Returns the {@link RcsParticipant} that receives the messages sent in this thread.
     * @throws RcsMessageStoreException if the value could not be read from the storage
     */
    @NonNull
    @WorkerThread
    public RcsParticipant getRecipient() throws RcsMessageStoreException {
        return new RcsParticipant(
                mRcsControllerCall,
                mRcsControllerCall.call(
                        (iRcs, callingPackage) -> iRcs.get1To1ThreadOtherParticipantId(mThreadId,
                                callingPackage)));
    }
}
+0 −66
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 android.telephony.ims;

import android.content.Context;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.telephony.ims.aidl.IRcsMessage;

/**
 * A wrapper class around RPC calls that {@link RcsMessageManager} APIs to minimize boilerplate
 * code.
 *
 * @hide - not meant for public use
 */
class RcsControllerCall {
    private final Context mContext;

    RcsControllerCall(Context context) {
        mContext = context;
    }

    <R> R call(RcsServiceCall<R> serviceCall) throws RcsMessageStoreException {
        IRcsMessage iRcsMessage = IRcsMessage.Stub.asInterface(ServiceManager.getService(
                Context.TELEPHONY_RCS_MESSAGE_SERVICE));
        if (iRcsMessage == null) {
            throw new RcsMessageStoreException("Could not connect to RCS storage service");
        }

        try {
            return serviceCall.methodOnIRcs(iRcsMessage, mContext.getOpPackageName());
        } catch (RemoteException exception) {
            throw new RcsMessageStoreException(exception.getMessage());
        }
    }

    void callWithNoReturn(RcsServiceCallWithNoReturn serviceCall)
            throws RcsMessageStoreException {
        call((iRcsMessage, callingPackage) -> {
            serviceCall.methodOnIRcs(iRcsMessage, callingPackage);
            return null;
        });
    }

    interface RcsServiceCall<R> {
        R methodOnIRcs(IRcsMessage iRcs, String callingPackage) throws RemoteException;
    }

    interface RcsServiceCallWithNoReturn {
        void methodOnIRcs(IRcsMessage iRcs, String callingPackage) throws RemoteException;
    }
}
Loading