Home | History | Annotate | Download | only in pbapclient
      1 /*
      2  * Copyright (C) 2016 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of 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,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 package com.android.bluetooth.pbapclient;
     17 
     18 import com.android.bluetooth.pbapclient.BluetoothPbapCard;
     19 import com.android.bluetooth.pbapclient.BluetoothPbapClient;
     20 import android.os.Handler;
     21 import android.os.Message;
     22 import android.util.Log;
     23 
     24 import com.android.vcard.VCardEntry;
     25 
     26 import java.util.List;
     27 
     28 public class PbapHandler extends Handler {
     29     private static final String TAG = "PbapHandler";
     30 
     31     private PbapListener mListener;
     32 
     33     public PbapHandler(PbapListener listener) {
     34         mListener = listener;
     35     }
     36 
     37     @Override
     38     public void handleMessage(Message msg) {
     39         Log.d(TAG, "handleMessage " + msg.what);
     40         switch (msg.what) {
     41             case BluetoothPbapClient.EVENT_PULL_PHONE_BOOK_DONE:
     42                 Log.d(TAG, "EVENT_PULL_PHONE_BOOK_DONE with entries " +
     43                     ((List<VCardEntry>)(msg.obj)).size());
     44                 mListener.onPhoneBookPullDone((List<VCardEntry>) msg.obj);
     45                 break;
     46             case BluetoothPbapClient.EVENT_PULL_PHONE_BOOK_ERROR:
     47                 Log.d(TAG, "EVENT_PULL_PHONE_BOOK_ERROR");
     48                 mListener.onPhoneBookError();
     49                 break;
     50             case BluetoothPbapClient.EVENT_SESSION_CONNECTED:
     51                 Log.d(TAG, "EVENT_SESSION_CONNECTED");
     52                 mListener.onPbapClientConnected(true);
     53                 break;
     54             case BluetoothPbapClient.EVENT_SESSION_DISCONNECTED:
     55                 Log.d(TAG, "EVENT_SESSION_DISCONNECTED");
     56                 mListener.onPbapClientConnected(false);
     57                 break;
     58 
     59             // TODO(rni): Actually handle these cases.
     60             case BluetoothPbapClient.EVENT_SET_PHONE_BOOK_DONE:
     61                 Log.d(TAG, "EVENT_SET_PHONE_BOOK_DONE");
     62                 break;
     63             case BluetoothPbapClient.EVENT_PULL_VCARD_LISTING_DONE:
     64                 Log.d(TAG, "EVENT_PULL_VCARD_LISTING_DONE");
     65                 break;
     66             case BluetoothPbapClient.EVENT_PULL_VCARD_ENTRY_DONE:
     67                 Log.d(TAG, "EVENT_PULL_VCARD_ENTRY_DONE");
     68                 break;
     69             case BluetoothPbapClient.EVENT_PULL_PHONE_BOOK_SIZE_DONE:
     70                 Log.d(TAG, "EVENT_PULL_PHONE_BOOK_SIZE_DONE");
     71                 break;
     72             case BluetoothPbapClient.EVENT_PULL_VCARD_LISTING_SIZE_DONE:
     73                 Log.d(TAG, "EVENT_PULL_VCARD_LISTING_SIZE_DONE");
     74                 break;
     75             case BluetoothPbapClient.EVENT_SET_PHONE_BOOK_ERROR:
     76                 Log.d(TAG, "EVENT_SET_PHONE_BOOK_ERROR");
     77                 break;
     78             case BluetoothPbapClient.EVENT_PULL_VCARD_LISTING_ERROR:
     79                 Log.d(TAG, "EVENT_PULL_VCARD_LISTING_ERROR");
     80                 break;
     81             case BluetoothPbapClient.EVENT_PULL_VCARD_ENTRY_ERROR:
     82                 Log.d(TAG, "EVENT_PULL_VCARD_ENTRY_ERROR");
     83                 break;
     84             case BluetoothPbapClient.EVENT_PULL_PHONE_BOOK_SIZE_ERROR:
     85                 Log.d(TAG, "EVENT_PULL_PHONE_BOOK_SIZE_ERROR");
     86                 break;
     87             case BluetoothPbapClient.EVENT_PULL_VCARD_LISTING_SIZE_ERROR:
     88                 Log.d(TAG, "EVENT_PULL_VCARD_LISTING_SIZE_ERROR");
     89                 break;
     90             case BluetoothPbapClient.EVENT_SESSION_AUTH_REQUESTED:
     91                 Log.d(TAG, "EVENT_SESSION_AUTH_REQUESTED");
     92                 break;
     93             case BluetoothPbapClient.EVENT_SESSION_AUTH_TIMEOUT:
     94                 Log.d(TAG, "EVENT_SESSION_AUTH_TIMEOUT");
     95                 break;
     96             default:
     97                 Log.e(TAG, "unknown message " + msg);
     98                 break;
     99         }
    100     }
    101 
    102     public interface PbapListener {
    103         void onPhoneBookPullDone(List<VCardEntry> entries);
    104         void onPhoneBookError();
    105         void onPbapClientConnected(boolean status);
    106     }
    107 }
    108