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

Commit 6c160b22 authored by Sahin Caliskan's avatar Sahin Caliskan Committed by android-build-merger
Browse files

Merge "Implement RcsParticipant (base)" am: a2e577d8

am: 2ff17556

Change-Id: I19e23c04feb02fc895f56f41fff1cbfd0a8f2971
parents 861b2b29 2ff17556
Loading
Loading
Loading
Loading
+98 −4
Original line number Diff line number Diff line
@@ -15,22 +15,111 @@
 */
package android.telephony.ims;

import static android.telephony.ims.RcsMessageStore.TAG;

import android.annotation.NonNull;
import android.annotation.WorkerThread;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.telephony.Rlog;
import android.telephony.ims.aidl.IRcs;
import android.text.TextUtils;

import com.android.internal.util.Preconditions;

/**
 * RcsParticipant is an RCS capable contact that can participate in {@link RcsThread}s.
 * @hide - TODO(sahinc) make this public
 */
public class RcsParticipant implements Parcelable {
    // The row ID of this participant in the database
    private int mId;
    // The phone number of this participant
    private String mCanonicalAddress;
    // The RCS alias of this participant. This is different than the name of the contact in the
    // Contacts app - i.e. RCS protocol allows users to define aliases for themselves that doesn't
    // require other users to add them as contacts and give them a name.
    private String mAlias;

    /**
     * Returns the row id of this participant.
     * Constructor for {@link com.android.internal.telephony.ims.RcsMessageStoreController}
     * to create instances of participants. This is not meant to be part of the SDK.
     *
     * @hide
     */
    public RcsParticipant(int id, @NonNull String canonicalAddress) {
        mId = id;
        mCanonicalAddress = canonicalAddress;
    }

    /**
     * @return Returns the canonical address (i.e. normalized phone number) for this participant
     */
    public String getCanonicalAddress() {
        return mCanonicalAddress;
    }

    /**
     * Sets the canonical address for this participant and updates it in storage.
     * @param canonicalAddress the canonical address to update to.
     */
    @WorkerThread
    public void setCanonicalAddress(@NonNull String canonicalAddress) {
        Preconditions.checkNotNull(canonicalAddress);
        if (canonicalAddress.equals(mCanonicalAddress)) {
            return;
        }

        mCanonicalAddress = canonicalAddress;

        try {
            IRcs iRcs = IRcs.Stub.asInterface(ServiceManager.getService("ircs"));
            if (iRcs != null) {
                iRcs.updateRcsParticipantCanonicalAddress(mId, mCanonicalAddress);
            }
        } catch (RemoteException re) {
            Rlog.e(TAG, "RcsParticipant: Exception happened during setCanonicalAddress", re);
        }
    }

    /**
     * @return Returns the alias for this participant. Alias is usually the real name of the person
     * themselves.
     */
    public String getAlias() {
        return mAlias;
    }

    /**
     * Sets the alias for this participant and persists it in storage. Alias is usually the real
     * name of the person themselves.
     */
    @WorkerThread
    public void setAlias(String alias) {
        if (TextUtils.equals(mAlias, alias)) {
            return;
        }
        mAlias = alias;

        try {
            IRcs iRcs = IRcs.Stub.asInterface(ServiceManager.getService("ircs"));
            if (iRcs != null) {
                iRcs.updateRcsParticipantAlias(mId, mAlias);
            }
        } catch (RemoteException re) {
            Rlog.e(TAG, "RcsParticipant: Exception happened during setCanonicalAddress", re);
        }
    }

    /**
     * Returns the row id of this participant. This is not meant to be part of the SDK
     *
     * TODO(sahinc) implement
     * @hide
     */
    public int getId() {
        return 12345;
        return mId;
    }

    public static final Creator<RcsParticipant> CREATOR = new Creator<RcsParticipant>() {
@@ -46,6 +135,9 @@ public class RcsParticipant implements Parcelable {
    };

    protected RcsParticipant(Parcel in) {
        mId = in.readInt();
        mCanonicalAddress = in.readString();
        mAlias = in.readString();
    }

    @Override
@@ -55,6 +147,8 @@ public class RcsParticipant implements Parcelable {

    @Override
    public void writeToParcel(Parcel dest, int flags) {

        dest.writeInt(mId);
        dest.writeString(mCanonicalAddress);
        dest.writeString(mAlias);
    }
}
+7 −2
Original line number Diff line number Diff line
@@ -37,8 +37,13 @@ interface IRcs {

    Rcs1To1Thread createRcs1To1Thread(in RcsParticipant participant);

    RcsParticipant createRcsParticipant(String canonicalAddress);

    // RcsThread APIs
    int getMessageCount(int rcsThreadId);

    // RcsParticipant APIs
    RcsParticipant createRcsParticipant(String canonicalAddress);

    void updateRcsParticipantCanonicalAddress(int id, String canonicalAddress);

    void updateRcsParticipantAlias(int id, String alias);
}
 No newline at end of file
+46 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 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.tests.ims;

import static com.google.common.truth.Truth.assertThat;

import android.os.Bundle;
import android.support.test.runner.AndroidJUnit4;
import android.telephony.ims.RcsParticipant;

import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
public class RcsParticipantTest {
    private static final int ID = 123;
    private static final String ALIAS = "alias";
    private static final String CANONICAL_ADDRESS = "+1234567890";

    @Test
    public void testCanUnparcel() {
        RcsParticipant rcsParticipant = new RcsParticipant(ID, CANONICAL_ADDRESS);
        rcsParticipant.setAlias(ALIAS);

        Bundle bundle = new Bundle();
        bundle.putParcelable("Some key", rcsParticipant);
        rcsParticipant = bundle.getParcelable("Some key");

        assertThat(rcsParticipant.getId()).isEqualTo(ID);
        assertThat(rcsParticipant.getAlias()).isEqualTo(ALIAS);
        assertThat(rcsParticipant.getCanonicalAddress()).isEqualTo(CANONICAL_ADDRESS);
    }
}