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

Commit 428cec90 authored by Brad Ebinger's avatar Brad Ebinger
Browse files

Update docs to better document PhoneAccountHandle

Warns developers to not create PhoneAccountHandles with null
arguments. If they do, a log warning is printed, reminding them that the
APIs should not be used in this manner.

Bug: 26684527
Change-Id: I03895cac9d732ee618649d38176d48620f705a1b
parent ac329d3e
Loading
Loading
Loading
Loading
+21 −5
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.telecom;

import android.annotation.NonNull;
import android.content.ComponentName;
import android.os.Parcel;
import android.os.Parcelable;
@@ -33,6 +34,9 @@ import java.util.Objects;
 *      component name.</li>
 * </ul>
 *
 * Note: This Class requires a non-null {@link ComponentName} and {@link UserHandle} to operate
 * properly. Passing in invalid parameters will generate a log warning.
 *
 * See {@link PhoneAccount}, {@link TelecomManager}.
 */
public final class PhoneAccountHandle implements Parcelable {
@@ -41,15 +45,16 @@ public final class PhoneAccountHandle implements Parcelable {
    private final UserHandle mUserHandle;

    public PhoneAccountHandle(
            ComponentName componentName,
            String id) {
            @NonNull ComponentName componentName,
            @NonNull String id) {
        this(componentName, id, Process.myUserHandle());
    }

    public PhoneAccountHandle(
            ComponentName componentName,
            String id,
            UserHandle userHandle) {
            @NonNull ComponentName componentName,
            @NonNull String id,
            @NonNull UserHandle userHandle) {
        checkParameters(componentName, userHandle);
        mComponentName = componentName;
        mId = id;
        mUserHandle = userHandle;
@@ -136,6 +141,17 @@ public final class PhoneAccountHandle implements Parcelable {
        mUserHandle.writeToParcel(out, flags);
    }

    private void checkParameters(ComponentName componentName, UserHandle userHandle) {
        if(componentName == null) {
            android.util.Log.w("PhoneAccountHandle", new Exception("PhoneAccountHandle has " +
                    "been created with null ComponentName!"));
        }
        if(userHandle == null) {
            android.util.Log.w("PhoneAccountHandle", new Exception("PhoneAccountHandle has " +
                    "been created with null UserHandle!"));
        }
    }

    public static final Creator<PhoneAccountHandle> CREATOR = new Creator<PhoneAccountHandle>() {
        @Override
        public PhoneAccountHandle createFromParcel(Parcel in) {