Home | History | Annotate | Download | only in inputmethod
      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 
     17 package android.view.inputmethod;
     18 
     19 import android.os.IBinder;
     20 import android.os.Parcel;
     21 import android.os.Parcelable;
     22 
     23 /**
     24  * Information given to an {@link InputMethod} about a client connecting
     25  * to it.
     26  */
     27 public final class InputBinding implements Parcelable {
     28     static final String TAG = "InputBinding";
     29 
     30     /**
     31      * The connection back to the client.
     32      */
     33     final InputConnection mConnection;
     34 
     35     /**
     36      * A remotable token for the connection back to the client.
     37      */
     38     final IBinder mConnectionToken;
     39 
     40     /**
     41      * The UID where this binding came from.
     42      */
     43     final int mUid;
     44 
     45     /**
     46      * The PID where this binding came from.
     47      */
     48     final int mPid;
     49 
     50     /**
     51      * Constructor.
     52      *
     53      * @param conn The interface for communicating back with the application.
     54      * @param connToken A remoteable token for communicating across processes.
     55      * @param uid The user id of the client of this binding.
     56      * @param pid The process id of where the binding came from.
     57      */
     58     public InputBinding(InputConnection conn, IBinder connToken,
     59             int uid, int pid) {
     60         mConnection = conn;
     61         mConnectionToken = connToken;
     62         mUid = uid;
     63         mPid = pid;
     64     }
     65 
     66     /**
     67      * Constructor from an existing InputBinding taking a new local input
     68      * connection interface.
     69      *
     70      * @param conn The new connection interface.
     71      * @param binding Existing binding to copy.
     72      */
     73     public InputBinding(InputConnection conn, InputBinding binding) {
     74         mConnection = conn;
     75         mConnectionToken = binding.getConnectionToken();
     76         mUid = binding.getUid();
     77         mPid = binding.getPid();
     78     }
     79 
     80     InputBinding(Parcel source) {
     81         mConnection = null;
     82         mConnectionToken = source.readStrongBinder();
     83         mUid = source.readInt();
     84         mPid = source.readInt();
     85     }
     86 
     87     /**
     88      * Return the connection for interacting back with the application.
     89      */
     90     public InputConnection getConnection() {
     91         return mConnection;
     92     }
     93 
     94     /**
     95      * Return the token for the connection back to the application.  You can
     96      * not use this directly, it must be converted to a {@link InputConnection}
     97      * for you.
     98      */
     99     public IBinder getConnectionToken() {
    100         return mConnectionToken;
    101     }
    102 
    103     /**
    104      * Return the user id of the client associated with this binding.
    105      */
    106     public int getUid() {
    107         return mUid;
    108     }
    109 
    110     /**
    111      * Return the process id where this binding came from.
    112      */
    113     public int getPid() {
    114         return mPid;
    115     }
    116 
    117     @Override
    118     public String toString() {
    119         return "InputBinding{" + mConnectionToken
    120                 + " / uid " + mUid + " / pid " + mPid + "}";
    121     }
    122 
    123     /**
    124      * Used to package this object into a {@link Parcel}.
    125      *
    126      * @param dest The {@link Parcel} to be written.
    127      * @param flags The flags used for parceling.
    128      */
    129     public void writeToParcel(Parcel dest, int flags) {
    130         dest.writeStrongBinder(mConnectionToken);
    131         dest.writeInt(mUid);
    132         dest.writeInt(mPid);
    133     }
    134 
    135     /**
    136      * Used to make this class parcelable.
    137      */
    138     public static final Parcelable.Creator<InputBinding> CREATOR = new Parcelable.Creator<InputBinding>() {
    139         public InputBinding createFromParcel(Parcel source) {
    140             return new InputBinding(source);
    141         }
    142 
    143         public InputBinding[] newArray(int size) {
    144             return new InputBinding[size];
    145         }
    146     };
    147 
    148     public int describeContents() {
    149         return 0;
    150     }
    151 }
    152