(Context context, long timeout)
| 120 | } |
| 121 | |
| 122 | private static OpenPgpServiceConnection getConnection(Context context, long timeout) { |
| 123 | final String pkg = PgpHelper.getPackageName(context); |
| 124 | Log.i("PGP binding to " + pkg + " timeout=" + timeout); |
| 125 | |
| 126 | CountDownLatch latch = new CountDownLatch(1); |
| 127 | OpenPgpServiceConnection pgpService = new OpenPgpServiceConnection(context, pkg, |
| 128 | new OpenPgpServiceConnection.OnBound() { |
| 129 | @Override |
| 130 | public void onBound(IOpenPgpService2 service) { |
| 131 | Log.i("Bound to " + pkg); |
| 132 | latch.countDown(); |
| 133 | } |
| 134 | |
| 135 | @Override |
| 136 | public void onError(Exception ex) { |
| 137 | Log.i(ex.getMessage()); |
| 138 | latch.countDown(); |
| 139 | } |
| 140 | }); |
| 141 | pgpService.bindToService(); |
| 142 | |
| 143 | try { |
| 144 | latch.await(timeout, TimeUnit.MILLISECONDS); |
| 145 | } catch (InterruptedException ex) { |
| 146 | Log.w(ex); |
| 147 | } |
| 148 | |
| 149 | Log.i("PGP bound=" + pgpService.isBound()); |
| 150 | if (!pgpService.isBound()) { |
| 151 | try { |
| 152 | pgpService.unbindFromService(); |
| 153 | } catch (Throwable ex) { |
| 154 | Log.e(ex); |
| 155 | } |
| 156 | throw new OperationCanceledException(); |
| 157 | } |
| 158 | |
| 159 | return pgpService; |
| 160 | } |
| 161 | |
| 162 | static String getPackageName(Context context) { |
| 163 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); |
no test coverage detected