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 17 package com.android.bluetooth.pbapclient; 18 19 import android.os.Handler; 20 import android.util.Log; 21 22 import javax.obex.Authenticator; 23 import javax.obex.PasswordAuthentication; 24 25 /* ObexAuthentication is a required component for PBAP in order to support backwards compatibility 26 * with PSE devices prior to PBAP 1.2. With profiles prior to 1.2 the actual initiation of 27 * authentication is implementation defined. 28 */ 29 30 31 class BluetoothPbapObexAuthenticator implements Authenticator { 32 33 private static final String TAG = "BtPbapObexAuthenticator"; 34 private static final boolean DBG = Utils.DBG; 35 36 //Default session key for legacy devices is 0000 37 private String mSessionKey = "0000"; 38 39 private final Handler mCallback; 40 BluetoothPbapObexAuthenticator(Handler callback)41 BluetoothPbapObexAuthenticator(Handler callback) { 42 mCallback = callback; 43 } 44 45 @Override onAuthenticationChallenge(String description, boolean isUserIdRequired, boolean isFullAccess)46 public PasswordAuthentication onAuthenticationChallenge(String description, 47 boolean isUserIdRequired, boolean isFullAccess) { 48 PasswordAuthentication pa = null; 49 if (DBG) Log.v(TAG, "onAuthenticationChallenge: starting"); 50 51 if (mSessionKey != null && mSessionKey.length() != 0) { 52 if (DBG) Log.v(TAG, "onAuthenticationChallenge: mSessionKey=" + mSessionKey); 53 pa = new PasswordAuthentication(null, mSessionKey.getBytes()); 54 } else { 55 if (DBG) { 56 Log.v(TAG, 57 "onAuthenticationChallenge: mSessionKey is empty, timeout/cancel occured"); 58 } 59 } 60 61 return pa; 62 } 63 64 @Override onAuthenticationResponse(byte[] userName)65 public byte[] onAuthenticationResponse(byte[] userName) { 66 if (DBG) Log.v(TAG, "onAuthenticationResponse: " + userName); 67 /* required only in case PCE challenges PSE which we don't do now */ 68 return null; 69 } 70 71 } 72