// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov. // Jad home page: http://www.geocities.com/kpdus/jad.html // Decompiler options: braces fieldsfirst space lnc package com.oliodevices.assist.app.core; import android.app.Activity; import android.app.ActivityManager; import android.app.NotificationManager; import android.app.PendingIntent; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.content.ActivityNotFoundException; import android.content.ComponentName; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.res.Resources; import android.database.Cursor; import android.graphics.BitmapFactory; import android.net.Uri; import android.support.v7.widget.Toolbar; import android.util.LongSparseArray; import android.view.View; import android.view.inputmethod.InputMethodManager; import android.widget.TextView; import android.widget.Toast; import com.olio.data.object.user.ActivityTime; import com.olio.data.object.user.Location; import com.olio.data.object.user.OlioContact; import com.olio.data.object.user.OlioContactBuilder; import com.olio.olios.model.SerializedUnitRecordMessagePayload; import com.olio.olios.model.record.SerializedRecord; import com.olio.util.ALog; import com.oliodevices.assist.BuildConfig; import com.oliodevices.assist.app.NotificationAggregatorService; import com.oliodevices.assist.app.activities.NotificationAccessActivity; import com.oliodevices.assist.app.api.OlioApi; import com.oliodevices.assist.app.api.UserManager; import com.oliodevices.assist.app.api.models.ContactInfo; import com.oliodevices.assist.app.detectors.firmware.FirmwareUpdateHelper; import com.oliodevices.assist.app.detectors.status_bar_detectors.NotificationHandlerService; import com.oliodevices.assist.app.detectors.web.WebActionListener; import java.lang.reflect.Method; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.Comparator; import java.util.Iterator; import java.util.List; import retrofit.Callback; import retrofit.RetrofitError; import retrofit.client.Response; import uk.co.chrisjenx.calligraphy.TypefaceUtils; public class Utils { private static final String ENABLED_NOTIFICATION_LISTENERS = "enabled_notification_listeners"; private static final String MARKET_URL = "market://details?id="; private static final int MIN_PASSWORD_LENGTH = 8; private static final String PLAYSTORE_URL = "https://play.google.com/store/apps/details?id="; public static final Comparator vipComparator = new Comparator() { public int compare(OlioContact oliocontact, OlioContact oliocontact1) { if (oliocontact.getName() == null && oliocontact1.getName() == null) { return 0; } if (oliocontact.getName() != null && oliocontact1.getName() == null) { return 1; } if (oliocontact.getName() == null) { return -1; } else { return oliocontact.getName().compareTo(oliocontact1.getName()); } } public volatile int compare(Object obj, Object obj1) { return compare((OlioContact)obj, (OlioContact)obj1); } }; public Utils() { } private static char[] addValueAtIndex(char ac[], int i, char c) { char ac1[] = new char[ac.length + 1]; for (int j = 0; j < i; j++) { ac1[j] = ac[j]; } ac1[i] = c; for (; i < ac.length; i++) { ac1[i + 1] = ac[i]; } return ac1; } public static String[] buildAddressArray(Context context, String s) { String as[] = new String[2]; as[0] = ""; as[1] = ""; if (s == null) { as[0] = context.getString(0x7f060112); return as; } int i = s.indexOf(", "); if (i >= 0) { as[0] = s.substring(0, i); as[1] = s.substring(i + 2); return as; } else { as[0] = s; return as; } } private static char[] deleteValueAtIndex(char ac[], int i) { char ac1[] = new char[ac.length - 1]; for (int j = 0; j < i; j++) { ac1[j] = ac[j]; } for (i++; i < ac.length; i++) { ac1[i - 1] = ac[i]; } return ac1; } public static boolean didServiceCrash(Context context, String s) { boolean flag; label0: { boolean flag1 = false; if (s == null || s.isEmpty()) { ALog.w("Must provide service name.", new Object[0]); } context = ((ActivityManager)context.getSystemService("activity")).getRunningServices(0x7fffffff); flag = flag1; if (context == null) { break label0; } context = context.iterator(); android.app.ActivityManager.RunningServiceInfo runningserviceinfo; do { flag = flag1; if (!context.hasNext()) { break label0; } runningserviceinfo = (android.app.ActivityManager.RunningServiceInfo)context.next(); } while (!s.equals(runningserviceinfo.service.getClassName()) || runningserviceinfo.crashCount <= 0); flag = true; } return flag; } public static void fixToolbarTypefaceHack(Resources resources, Toolbar toolbar) { Object obj = resources.getString(0x7f0600b2); obj = TypefaceUtils.load(resources.getAssets(), ((String) (obj))); float f = resources.getDimensionPixelSize(0x7f070055); int j = toolbar.getChildCount(); for (int i = 0; i < j; i++) { resources = toolbar.getChildAt(i); if (resources instanceof TextView) { ((TextView)resources).setTypeface(((android.graphics.Typeface) (obj))); ((TextView)resources).setAllCaps(true); ((TextView)resources).setTextSize(0, f); } } } public static String generateSecretKey(String s, String s1) { int i1 = 0; int l = 0; int k = 0; int j = 0; char ac1[] = "314159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812".toCharArray(); char ac2[] = "271828182845904523536028747135266249775724709369995957496696762772407663035354759457138217852516642742746639193200305992181741359662904357290033429526".toCharArray(); char ac3[] = "161803398874989484820458683436563811772030917980576286213544862270526046281890244970720720418939113748475408807538689175212663386222353693179318006076".toCharArray(); s1 = s1.toCharArray(); s = s.toCharArray(); int j1 = ac3.length; int i = 0; do { label0: { char ac[] = s; if (i < j1) { int k1 = Character.getNumericValue(ac3[i]); i1 += k1; l += k1; k = (k + Character.getNumericValue(ac1[l])) % s1.length; j = (j + Character.getNumericValue(ac2[i1])) % s.length; char c = s1[k]; s1 = deleteValueAtIndex(s1, k); s = addValueAtIndex(s, j, c); if (s1.length != 0) { break label0; } ac = s; } return getShaDigest(String.valueOf(ac), "SHA-256"); } i++; } while (true); } private static LongSparseArray getPeople(Context context) { Uri uri = android.provider.ContactsContract.Contacts.CONTENT_URI; String s1 = String.format("%s DESC", new Object[] { "times_contacted" }); LongSparseArray longsparsearray = new LongSparseArray(); if (context != null) { context = context.getContentResolver().query(uri, new String[] { "_id", "lookup", "display_name", "photo_thumb_uri", "times_contacted" }, null, null, s1); if (context != null) { String s; String s2; int i; long l; for (; context.moveToNext(); longsparsearray.put(l, OlioContactBuilder.anOlioContact().setName(s).setPhotoUri(s2).setPriority(i).setIsGroup(false))) { l = context.getLong(context.getColumnIndex("_id")); s = context.getString(context.getColumnIndex("display_name")); s2 = context.getString(context.getColumnIndex("photo_thumb_uri")); i = context.getInt(context.getColumnIndex("times_contacted")); } context.close(); } } return longsparsearray; } private static String getShaDigest(String s, String s1) { StringBuffer stringbuffer = new StringBuffer(); MessageDigest messagedigest = MessageDigest.getInstance(s1); messagedigest.update(s.getBytes()); s = messagedigest.digest(); int i = 0; _L2: if (i >= s.length) { break; /* Loop/switch isn't completed */ } stringbuffer.append(Integer.toString((s[i] & 0xff) + 256, 16).substring(1)); i++; if (true) goto _L2; else goto _L1 s; ALog.e((new StringBuilder()).append(s1).append(" digest Error, no such algorithm exception: ").append(s).toString(), new Object[0]); _L1: return stringbuffer.toString(); } public static void hideKeyboard(Activity activity) { View view = activity.getCurrentFocus(); if (view != null) { ((InputMethodManager)activity.getSystemService("input_method")).hideSoftInputFromWindow(view.getWindowToken(), 2); } } public static boolean isItemProtected(Context context, Object obj) { if (!(obj instanceof Location)) goto _L2; else goto _L1 _L1: obj = ((Location)obj).getDisplayName(); if (obj == null || !((String) (obj)).equalsIgnoreCase(context.getString(0x7f0600c1)) && !((String) (obj)).equalsIgnoreCase(context.getString(0x7f0601d8))) goto _L4; else goto _L3 _L3: return true; _L4: return false; _L2: if (obj instanceof ActivityTime) { obj = ((ActivityTime)obj).getName(); if (obj == null || !((String) (obj)).equalsIgnoreCase(context.getString(0x7f06016b))) { return false; } } else { return false; } if (true) goto _L3; else goto _L5 _L5: } public static boolean isNotificationAccessGranted(Context context) { String s = android.provider.Settings.Secure.getString(context.getContentResolver(), "enabled_notification_listeners"); context = context.getPackageName(); return s != null && s.contains(context); } public static boolean isServiceRunning(Context context, String s) { boolean flag; label0: { boolean flag1 = false; if (s == null || s.isEmpty()) { ALog.w("Must provide service name.", new Object[0]); } context = ((ActivityManager)context.getSystemService("activity")).getRunningServices(0x7fffffff); flag = flag1; if (context == null) { break label0; } context = context.iterator(); do { flag = flag1; if (!context.hasNext()) { break label0; } } while (!s.equals(((android.app.ActivityManager.RunningServiceInfo)context.next()).service.getClassName())); flag = true; } return flag; } public static boolean isValidPassword(String s) { while (s.length() < 8 || !s.matches(".*[A-Z].*")) { return false; } return s.matches(".*\\d.*"); } public static void launchPlayStore(Context context) { String s = context.getPackageName(); try { context.startActivity(new Intent("android.intent.action.VIEW", Uri.parse((new StringBuilder()).append("market://details?id=").append(s).toString()))); return; } catch (ActivityNotFoundException activitynotfoundexception) { context.startActivity(new Intent("android.intent.action.VIEW", Uri.parse((new StringBuilder()).append("https://play.google.com/store/apps/details?id=").append(s).toString()))); } } private static LongSparseArray mapEmailToPeople(Context context) { Uri uri = android.provider.ContactsContract.CommonDataKinds.Email.CONTENT_URI; LongSparseArray longsparsearray = new LongSparseArray(); if (context != null) { Cursor cursor = context.getContentResolver().query(uri, new String[] { "contact_id", "data1" }, null, null, null); if (cursor != null) { String s; for (; cursor.moveToNext(); context.add(s)) { long l = cursor.getLong(cursor.getColumnIndex("contact_id")); s = cursor.getString(cursor.getColumnIndex("data1")); ArrayList arraylist = (ArrayList)longsparsearray.get(l); context = arraylist; if (arraylist == null) { context = new ArrayList(); longsparsearray.put(l, context); } } cursor.close(); } } return longsparsearray; } private static LongSparseArray mapPhonesToPeople(Context context) { Uri uri = android.provider.ContactsContract.CommonDataKinds.Phone.CONTENT_URI; LongSparseArray longsparsearray = new LongSparseArray(); if (context != null) { Cursor cursor = context.getContentResolver().query(uri, new String[] { "contact_id", "data1", "data4" }, null, null, null); if (cursor != null) { do { if (!cursor.moveToNext()) { break; } long l = cursor.getLong(cursor.getColumnIndex("contact_id")); String s = cursor.getString(cursor.getColumnIndex("data4")); String s1 = cursor.getString(cursor.getColumnIndex("data1")); ArrayList arraylist = (ArrayList)longsparsearray.get(l); context = arraylist; if (arraylist == null) { context = new ArrayList(); longsparsearray.put(l, context); } if (s == null) { s = s1; } if (s != null && !s.isEmpty()) { context.add(s); } } while (true); cursor.close(); } } return longsparsearray; } public static ArrayList retrieveCalendars(Context context) { ArrayList arraylist = new ArrayList(); if (context != null) { Uri uri = android.provider.CalendarContract.Calendars.CONTENT_URI; String s = String.format("%s = 1", new Object[] { "visible" }); context = context.getContentResolver().query(uri, new String[] { "calendar_displayName", "visible" }, s, null, null); if (context != null) { for (; context.moveToNext(); arraylist.add(context.getString(context.getColumnIndex("calendar_displayName")))) { } context.close(); } } return arraylist; } public static ArrayList retrieveContactInfo(Context context) { ArrayList arraylist; Cursor cursor; arraylist = new ArrayList(); String s = String.format("%s ASC, %s ASC", new Object[] { "display_name", "data2" }); if (context == null) { break MISSING_BLOCK_LABEL_277; } cursor = context.getContentResolver().query(android.provider.ContactsContract.Data.CONTENT_URI, new String[] { "display_name", "photo_thumb_uri", "mimetype", "data1", "data2", "data3" }, "mimetype=?", new String[] { "vnd.android.cursor.item/postal-address_v2" }, s); if (cursor == null) { break MISSING_BLOCK_LABEL_277; } _L6: String s2; String s3; String s4; if (!cursor.moveToNext()) { break MISSING_BLOCK_LABEL_271; } s2 = cursor.getString(cursor.getColumnIndex("display_name")); s3 = cursor.getString(cursor.getColumnIndex("photo_thumb_uri")); s4 = cursor.getString(cursor.getColumnIndex("data1")); cursor.getInt(cursor.getColumnIndex("data2")); JVM INSTR tableswitch 0 2: default 200 // 0 252 // 1 230 // 2 241; goto _L1 _L2 _L3 _L4 _L2: break MISSING_BLOCK_LABEL_252; _L3: break; /* Loop/switch isn't completed */ _L1: String s1 = context.getString(0x7f060123); _L7: arraylist.add(new ContactInfo(s2, s3, s4, s1)); if (true) goto _L6; else goto _L5 _L5: s1 = context.getString(0x7f0600c1); goto _L7 _L4: s1 = context.getString(0x7f0601d8); goto _L7 s1 = cursor.getString(cursor.getColumnIndex("data3")); goto _L7 cursor.close(); return arraylist; } public static ArrayList retrieveContacts(Context context) { ArrayList arraylist = new ArrayList(); LongSparseArray longsparsearray = getPeople(context); LongSparseArray longsparsearray1 = mapPhonesToPeople(context); context = mapEmailToPeople(context); for (int i = 0; i < longsparsearray.size(); i++) { long l = longsparsearray.keyAt(i); OlioContactBuilder oliocontactbuilder = (OlioContactBuilder)longsparsearray.valueAt(i); ArrayList arraylist1 = (ArrayList)longsparsearray1.get(l); ArrayList arraylist2 = (ArrayList)context.get(l); oliocontactbuilder.addPhoneNumbers(arraylist1); oliocontactbuilder.addEmailAddresses(arraylist2); } for (int j = 0; j < longsparsearray.size(); j++) { context = ((OlioContactBuilder)longsparsearray.valueAt(j)).build(); if (!arraylist.contains(context)) { arraylist.add(context); } } return arraylist; } public static void showKeyboard(Activity activity, View view) { View view1 = view; if (view != null) goto _L2; else goto _L1 _L1: view = activity.getCurrentFocus(); view1 = view; if (view != null) goto _L2; else goto _L3 _L3: return; _L2: if (view1.requestFocus()) { ((InputMethodManager)activity.getSystemService("input_method")).showSoftInput(view1, 1); return; } if (true) goto _L3; else goto _L4 _L4: } public static void showKeyboardDelayed(Activity activity, View view) { int i = activity.getResources().getInteger(0x7f0a0005); view.postDelayed(new Runnable(activity, view) { final Activity val$activity; final View val$focus; public void run() { Utils.showKeyboard(activity, focus); } { activity = activity1; focus = view; super(); } }, i); } public static void showToastMessage(Context context, CharSequence charsequence) { charsequence = Toast.makeText(context, charsequence, 1); charsequence.setGravity(48, 0, context.getResources().getDimensionPixelOffset(0x7f07007c)); charsequence.show(); } public static void startServices(Context context) { ALog.d("startServices", new Object[0]); startServices(context, true); } public static void startServices(Context context, boolean flag) { boolean flag1; label0: { ALog.d("startServices", new Object[0]); context.startService(new Intent(context, com/oliodevices/assist/app/NotificationAggregatorService)); context.startService(new Intent(context, com/oliodevices/assist/app/detectors/web/WebActionListener)); flag1 = isNotificationAccessGranted(context); boolean flag2 = isServiceRunning(context, com/oliodevices/assist/app/detectors/status_bar_detectors/NotificationHandlerService.getName()); if (BuildConfig.LOG_LEVEL.value <= com.olio.util.ALog.Level.D.value) { Object obj; if (flag1) { obj = "granted."; } else { obj = "denied."; } ALog.d("Notification access %s", new Object[] { obj }); if (isServiceRunning(context, com/oliodevices/assist/app/NotificationAggregatorService.getName())) { obj = "is"; } else { obj = "is not"; } ALog.d("NotificationAggregatorService %s running", new Object[] { obj }); if (flag2) { obj = "is"; } else { obj = "is not"; } ALog.d("NotificationHandlerService %s running", new Object[] { obj }); if (didServiceCrash(context, com/oliodevices/assist/app/detectors/status_bar_detectors/NotificationHandlerService.getName())) { ALog.d("it appears to have crashed", new Object[0]); } } if (!flag2) { if (!flag) { break label0; } ALog.v("showing notification access activity", new Object[0]); obj = new Intent(context, com/oliodevices/assist/app/activities/NotificationAccessActivity); if (!(context instanceof Activity)) { ((Intent) (obj)).setFlags(0x10000000); } context.startActivity(((Intent) (obj))); } return; } ALog.v("creating notification", new Object[0]); Object obj2 = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"); ((Intent) (obj2)).setFlags(0x10000000); Object obj1; android.graphics.Bitmap bitmap; int i; if (!flag1) { i = 0x7f0600af; } else { i = 0x7f060186; } obj1 = context.getString(i); bitmap = BitmapFactory.decodeResource(context.getResources(), 0x7f0200d5); obj2 = PendingIntent.getActivity(context, 0, ((Intent) (obj2)), 0x40000000); obj1 = (new android.app.Notification.Builder(context)).setContentTitle(context.getString(0x7f06003e)).setContentText(((CharSequence) (obj1))).setSmallIcon(0x7f0200d5).setLargeIcon(bitmap).setContentIntent(((PendingIntent) (obj2))).setAutoCancel(true).build(); ((NotificationManager)context.getSystemService("notification")).notify(0, ((android.app.Notification) (obj1))); } public static void stopServices(Context context) { ALog.d("stopServices", new Object[0]); Intent intent = new Intent(context, com/oliodevices/assist/app/NotificationAggregatorService); Intent intent1 = new Intent(context, com/oliodevices/assist/app/detectors/web/WebActionListener); context.stopService(intent); context.stopService(intent1); } public static void unpairDevice(Context context, com.oliodevices.assist.app.fragments.ConfigWatchFragment.ConfigWatchCallbacks configwatchcallbacks, String s) { BluetoothDevice bluetoothdevice = configwatchcallbacks.getDevice(s); OlioApi.getInstance().unregisterUnit(s, new Callback(context, bluetoothdevice, configwatchcallbacks) { final com.oliodevices.assist.app.fragments.ConfigWatchFragment.ConfigWatchCallbacks val$callbacks; final Context val$context; final BluetoothDevice val$device; public void failure(RetrofitError retrofiterror) { int i; if (retrofiterror != null && retrofiterror.getResponse() != null) { i = retrofiterror.getResponse().getStatus(); } else { i = -1; } switch (i) { default: Utils.showToastMessage(context, context.getResources().getString(0x7f0601b3)); StringBuilder stringbuilder = (new StringBuilder()).append("Failed to unregister the unit: "); if (retrofiterror == null) { retrofiterror = "unknown reason"; } ALog.e(stringbuilder.append(retrofiterror).toString(), new Object[0]); return; case 401: Utils.showToastMessage(context, context.getResources().getString(0x7f0601c6)); Utils.unpairPhone(context, device, callbacks); ALog.d("Failed to unregister but unpairing phone anyway", new Object[0]); return; } } public volatile void success(Object obj, Response response) { success((Response)obj, response); } public void success(Response response, Response response1) { ALog.i("Successfully unregistered device.", new Object[0]); Utils.unpairPhone(context, device, callbacks); } { context = context1; device = bluetoothdevice; callbacks = configwatchcallbacks; super(); } }); } private static void unpairPhone(Context context, BluetoothDevice bluetoothdevice, com.oliodevices.assist.app.fragments.ConfigWatchFragment.ConfigWatchCallbacks configwatchcallbacks) { if (BluetoothAdapter.getDefaultAdapter().getState() == 10) { showToastMessage(context, context.getResources().getString(0x7f0601b4)); return; } try { bluetoothdevice.getClass().getMethod("removeBond", (Class[])null).invoke(bluetoothdevice, (Object[])null); } // Misplaced declaration of an exception variable catch (BluetoothDevice bluetoothdevice) { showToastMessage(context, context.getResources().getString(0x7f0601b3)); ALog.e("Unable to unpair watch", bluetoothdevice, new Object[0]); return; } FirmwareUpdateHelper.getInstance().removeAllFirmwareTransfers(); SerializedUnitRecordMessagePayload.deleteAll(context.getContentResolver()); SerializedRecord.deleteByType("do-not-disturb", context.getContentResolver()); SerializedRecord.deleteByType("watch-ui", context.getContentResolver()); UserManager.getInstance().updateUnitId(null); context.removeStickyBroadcast(new Intent("com.oliodevices.assist.intent.action.WATCH_VERSION")); context.removeStickyBroadcast(new Intent("com.oliodevices.assist.intent.action.FIRMWARE_AVAILABLE")); configwatchcallbacks.handleUnpairing(); } }