1/* 2 * Copyright (C) 2007-2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 * use this file except in compliance with the License. You may obtain a copy of 6 * the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations under 14 * the License. 15 */ 16 17package android.view.inputmethod; 18 19import android.os.IBinder; 20import android.os.Parcel; 21import android.os.Parcelable; 22import android.text.TextUtils; 23 24/** 25 * Information given to an {@link InputMethod} about a client connecting 26 * to it. 27 */ 28public final class InputBinding implements Parcelable { 29 static final String TAG = "InputBinding"; 30 31 /** 32 * The connection back to the client. 33 */ 34 final InputConnection mConnection; 35 36 /** 37 * A remotable token for the connection back to the client. 38 */ 39 final IBinder mConnectionToken; 40 41 /** 42 * The UID where this binding came from. 43 */ 44 final int mUid; 45 46 /** 47 * The PID where this binding came from. 48 */ 49 final int mPid; 50 51 /** 52 * Constructor. 53 * 54 * @param conn The interface for communicating back with the application. 55 * @param connToken A remoteable token for communicating across processes. 56 * @param uid The user id of the client of this binding. 57 * @param pid The process id of where the binding came from. 58 */ 59 public InputBinding(InputConnection conn, IBinder connToken, 60 int uid, int pid) { 61 mConnection = conn; 62 mConnectionToken = connToken; 63 mUid = uid; 64 mPid = pid; 65 } 66 67 /** 68 * Constructor from an existing InputBinding taking a new local input 69 * connection interface. 70 * 71 * @param conn The new connection interface. 72 * @param binding Existing binding to copy. 73 */ 74 public InputBinding(InputConnection conn, InputBinding binding) { 75 mConnection = conn; 76 mConnectionToken = binding.getConnectionToken(); 77 mUid = binding.getUid(); 78 mPid = binding.getPid(); 79 } 80 81 InputBinding(Parcel source) { 82 mConnection = null; 83 mConnectionToken = source.readStrongBinder(); 84 mUid = source.readInt(); 85 mPid = source.readInt(); 86 } 87 88 /** 89 * Return the connection for interacting back with the application. 90 */ 91 public InputConnection getConnection() { 92 return mConnection; 93 } 94 95 /** 96 * Return the token for the connection back to the application. You can 97 * not use this directly, it must be converted to a {@link InputConnection} 98 * for you. 99 */ 100 public IBinder getConnectionToken() { 101 return mConnectionToken; 102 } 103 104 /** 105 * Return the user id of the client associated with this binding. 106 */ 107 public int getUid() { 108 return mUid; 109 } 110 111 /** 112 * Return the process id where this binding came from. 113 */ 114 public int getPid() { 115 return mPid; 116 } 117 118 @Override 119 public String toString() { 120 return "InputBinding{" + mConnectionToken 121 + " / uid " + mUid + " / pid " + mPid + "}"; 122 } 123 124 /** 125 * Used to package this object into a {@link Parcel}. 126 * 127 * @param dest The {@link Parcel} to be written. 128 * @param flags The flags used for parceling. 129 */ 130 public void writeToParcel(Parcel dest, int flags) { 131 dest.writeStrongBinder(mConnectionToken); 132 dest.writeInt(mUid); 133 dest.writeInt(mPid); 134 } 135 136 /** 137 * Used to make this class parcelable. 138 */ 139 public static final Parcelable.Creator<InputBinding> CREATOR = new Parcelable.Creator<InputBinding>() { 140 public InputBinding createFromParcel(Parcel source) { 141 return new InputBinding(source); 142 } 143 144 public InputBinding[] newArray(int size) { 145 return new InputBinding[size]; 146 } 147 }; 148 149 public int describeContents() { 150 return 0; 151 } 152} 153