That fuck shit the fascists are using
1package org.tm.archive.profiles;
2
3
4import android.accounts.Account;
5import android.accounts.AccountManager;
6import android.annotation.SuppressLint;
7import android.content.Context;
8import android.database.Cursor;
9import android.net.Uri;
10import android.os.AsyncTask;
11import android.provider.ContactsContract;
12import android.text.TextUtils;
13
14import androidx.annotation.NonNull;
15import androidx.annotation.Nullable;
16
17import org.signal.core.util.concurrent.ListenableFuture;
18import org.signal.core.util.concurrent.SettableFuture;
19import org.signal.core.util.logging.Log;
20import org.tm.archive.mms.MediaConstraints;
21import org.tm.archive.util.BitmapDecodingException;
22import org.tm.archive.util.BitmapUtil;
23
24public class SystemProfileUtil {
25
26 private static final String TAG = Log.tag(SystemProfileUtil.class);
27
28 @SuppressLint("StaticFieldLeak")
29 public static ListenableFuture<byte[]> getSystemProfileAvatar(final @NonNull Context context, MediaConstraints mediaConstraints) {
30 SettableFuture<byte[]> future = new SettableFuture<>();
31
32 new AsyncTask<Void, Void, byte[]>() {
33 @Override
34 protected @Nullable byte[] doInBackground(Void... params) {
35 try (Cursor cursor = context.getContentResolver().query(ContactsContract.Profile.CONTENT_URI, null, null, null, null)) {
36 while (cursor != null && cursor.moveToNext()) {
37 String photoUri = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.Profile.PHOTO_URI));
38
39 if (!TextUtils.isEmpty(photoUri)) {
40 try {
41 BitmapUtil.ScaleResult result = BitmapUtil.createScaledBytes(context, Uri.parse(photoUri), mediaConstraints);
42 return result.getBitmap();
43 } catch (BitmapDecodingException e) {
44 Log.w(TAG, e);
45 }
46 }
47 }
48 } catch (SecurityException se) {
49 Log.w(TAG, se);
50 }
51
52 return null;
53 }
54
55 @Override
56 protected void onPostExecute(@Nullable byte[] result) {
57 future.set(result);
58 }
59
60 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
61
62 return future;
63 }
64
65 @SuppressLint("StaticFieldLeak")
66 public static ListenableFuture<String> getSystemProfileName(final @NonNull Context context) {
67 SettableFuture<String> future = new SettableFuture<>();
68
69 new AsyncTask<Void, Void, String>() {
70 @Override
71 protected String doInBackground(Void... params) {
72 String name = null;
73
74 try (Cursor cursor = context.getContentResolver().query(ContactsContract.Profile.CONTENT_URI, null, null, null, null)) {
75 if (cursor != null && cursor.moveToNext()) {
76 name = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.Profile.DISPLAY_NAME));
77 }
78 } catch (SecurityException se) {
79 Log.w(TAG, se);
80 }
81
82 if (name == null) {
83 AccountManager accountManager = AccountManager.get(context);
84 Account[] accounts = accountManager.getAccountsByType("com.google");
85
86 for (Account account : accounts) {
87 if (!TextUtils.isEmpty(account.name)) {
88 if (account.name.contains("@")) {
89 name = account.name.substring(0, account.name.indexOf("@")).replace('.', ' ');
90 } else {
91 name = account.name.replace('.', ' ');
92 }
93
94 break;
95 }
96 }
97 }
98
99 return name;
100 }
101
102 @Override
103 protected void onPostExecute(@Nullable String result) {
104 future.set(result);
105 }
106 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
107
108 return future;
109 }
110
111
112}