MCPcopy Create free account
hub / github.com/M66B/FairEmail / getConnection

Method getConnection

app/src/main/java/eu/faircode/email/PgpHelper.java:122–160  ·  view source on GitHub ↗
(Context context, long timeout)

Source from the content-addressed store, hash-verified

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);

Callers 1

executeMethod · 0.95

Calls 7

getPackageNameMethod · 0.95
iMethod · 0.95
bindToServiceMethod · 0.95
wMethod · 0.95
isBoundMethod · 0.95
unbindFromServiceMethod · 0.95
eMethod · 0.95

Tested by

no test coverage detected