| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.security; |
| 18 |
|
| 19 |
import android.os.RemoteException; |
| 20 |
import android.os.ServiceManager; |
| 21 |
import android.os.ServiceSpecificException; |
| 22 |
import android.security.apc.IConfirmationCallback; |
| 23 |
import android.security.apc.IProtectedConfirmation; |
| 24 |
import android.security.apc.ResponseCode; |
| 25 |
import android.util.Log; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
public class AndroidProtectedConfirmation { |
| 31 |
private static final String TAG = "AndroidProtectedConfirmation"; |
| 32 |
|
| 33 |
public static final int ERROR_OK = ResponseCode.OK; |
| 34 |
public static final int ERROR_CANCELED = ResponseCode.CANCELLED; |
| 35 |
public static final int ERROR_ABORTED = ResponseCode.ABORTED; |
| 36 |
public static final int ERROR_OPERATION_PENDING = ResponseCode.OPERATION_PENDING; |
| 37 |
public static final int ERROR_IGNORED = ResponseCode.IGNORED; |
| 38 |
public static final int ERROR_SYSTEM_ERROR = ResponseCode.SYSTEM_ERROR; |
| 39 |
public static final int ERROR_UNIMPLEMENTED = ResponseCode.UNIMPLEMENTED; |
| 40 |
|
| 41 |
public static final int FLAG_UI_OPTION_INVERTED = |
| 42 |
IProtectedConfirmation.FLAG_UI_OPTION_INVERTED; |
| 43 |
public static final int FLAG_UI_OPTION_MAGNIFIED = |
| 44 |
IProtectedConfirmation.FLAG_UI_OPTION_MAGNIFIED; |
| 45 |
|
| 46 |
private IProtectedConfirmation mProtectedConfirmation; |
| 47 |
|
| 48 |
public AndroidProtectedConfirmation() { |
| 49 |
mProtectedConfirmation = null; |
| 50 |
} |
| 51 |
|
| 52 |
private synchronized IProtectedConfirmation getService() { |
| 53 |
if (mProtectedConfirmation == null) { |
| 54 |
mProtectedConfirmation = IProtectedConfirmation.Stub.asInterface(ServiceManager |
| 55 |
.getService("android.security.apc")); |
| 56 |
} |
| 57 |
return mProtectedConfirmation; |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
public int presentConfirmationPrompt(IConfirmationCallback listener, String promptText, |
| 72 |
byte[] extraData, String locale, int uiOptionsAsFlags) { |
| 73 |
try { |
| 74 |
getService().presentPrompt(listener, promptText, extraData, locale, |
| 75 |
uiOptionsAsFlags); |
| 76 |
return ERROR_OK; |
| 77 |
} catch (RemoteException e) { |
| 78 |
Log.w(TAG, "Cannot connect to keystore", e); |
| 79 |
return ERROR_SYSTEM_ERROR; |
| 80 |
} catch (ServiceSpecificException e) { |
| 81 |
return e.errorCode; |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
public int cancelConfirmationPrompt(IConfirmationCallback listener) { |
| 93 |
try { |
| 94 |
getService().cancelPrompt(listener); |
| 95 |
return ERROR_OK; |
| 96 |
} catch (RemoteException e) { |
| 97 |
Log.w(TAG, "Cannot connect to keystore", e); |
| 98 |
return ERROR_SYSTEM_ERROR; |
| 99 |
} catch (ServiceSpecificException e) { |
| 100 |
return e.errorCode; |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
public boolean isConfirmationPromptSupported() { |
| 110 |
try { |
| 111 |
return getService().isSupported(); |
| 112 |
} catch (RemoteException e) { |
| 113 |
Log.w(TAG, "Cannot connect to keystore", e); |
| 114 |
return false; |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
} |