From ace81831518060eae0eecc310503cfaeea8ea1bd Mon Sep 17 00:00:00 2001 From: Rahul Kumar Patel Date: Sun, 12 Jan 2020 19:46:48 +0530 Subject: [PATCH] Details : Fix broken exodus reports due to change in APIs https://gitlab.com/AuroraOSS/AuroraStore/issues/274 --- .../com/aurora/store/SelfUpdateService.java | 35 +++++----------- .../store/notification/NotificationBase.java | 1 - .../store/notification/QuickNotification.java | 1 - .../com/aurora/store/task/ExodusTask.java | 42 +++++++++++++++++++ .../store/ui/details/views/ExodusPrivacy.java | 15 ++++--- app/src/main/res/layout/item_exodus.xml | 1 + app/src/main/res/layout/sheet_exodus.xml | 9 +--- 7 files changed, 63 insertions(+), 41 deletions(-) create mode 100644 app/src/main/java/com/aurora/store/task/ExodusTask.java diff --git a/app/src/main/java/com/aurora/store/SelfUpdateService.java b/app/src/main/java/com/aurora/store/SelfUpdateService.java index d65d2da79..671c6808c 100644 --- a/app/src/main/java/com/aurora/store/SelfUpdateService.java +++ b/app/src/main/java/com/aurora/store/SelfUpdateService.java @@ -1,11 +1,8 @@ package com.aurora.store; import android.app.Notification; -import android.app.NotificationChannel; -import android.app.NotificationManager; import android.app.Service; import android.content.Intent; -import android.graphics.Color; import android.os.Build; import android.os.IBinder; @@ -51,7 +48,7 @@ public class SelfUpdateService extends Service { private App app; private Fetch fetch; private FetchListener fetchListener; - private Gson gson = new Gson(); + private Gson gson; public static boolean isServiceRunning() { try { @@ -83,7 +80,8 @@ public class SelfUpdateService extends Service { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { startForeground(1, getNotification()); } else { - Notification notification = getNotification(new NotificationCompat.Builder(this)); + Notification notification = getNotification(new NotificationCompat.Builder(this, + Constants.NOTIFICATION_CHANNEL_GENERAL)); startForeground(1, notification); } startUpdate(); @@ -96,7 +94,7 @@ public class SelfUpdateService extends Service { } private void destroyService() { - Log.e("Self-update service destroyed"); + Log.d("Self-update service destroyed"); if (fetchListener != null) { fetch.removeListener(fetchListener); fetchListener = null; @@ -120,7 +118,7 @@ public class SelfUpdateService extends Service { } else downloadAndUpdate(update); } catch (Exception e) { - Log.d("Error checking self-update"); + Log.e("Error checking update"); destroyService(); } })); @@ -140,7 +138,7 @@ public class SelfUpdateService extends Service { fetch = DownloadManager.getFetchInstance(this); fetch.enqueue(requestList, result -> { - Log.d("Downloading latest self-update"); + Log.d("Downloading latest update"); }); fetchListener = getFetchListener(); @@ -157,30 +155,19 @@ public class SelfUpdateService extends Service { @RequiresApi(Build.VERSION_CODES.O) private Notification getNotification() { - String NOTIFICATION_CHANNEL_ID = BuildConfig.APPLICATION_ID; - String channelName = "Self Update Service"; - - NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_HIGH); - notificationChannel.setLightColor(Color.BLUE); - notificationChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC); - - NotificationManager manager = (NotificationManager) getSystemService(SelfUpdateService.NOTIFICATION_SERVICE); - manager.createNotificationChannel(notificationChannel); - - NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID); + NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, Constants.NOTIFICATION_CHANNEL_GENERAL); return getNotification(notificationBuilder); } private Notification getNotification(NotificationCompat.Builder builder) { - int versionCode = Build.VERSION.SDK_INT; return builder .setAutoCancel(true) - .setCategory(Notification.CATEGORY_PROGRESS) + .setCategory(Notification.CATEGORY_SERVICE) + .setColor(getResources().getColor(R.color.colorAccent)) .setContentTitle("Self update") .setContentText("Updating Aurora Store in background") .setOngoing(false) - .setPriority(versionCode >= Build.VERSION_CODES.O ? NotificationCompat.PRIORITY_DEFAULT : Notification.PRIORITY_DEFAULT) - .setSmallIcon(R.drawable.ic_update) + .setSmallIcon(R.drawable.ic_notification) .build(); } @@ -190,7 +177,7 @@ public class SelfUpdateService extends Service { public void onError(int groupId, @NotNull Download download, @NotNull Error error, @org.jetbrains.annotations.Nullable Throwable throwable, @NotNull FetchGroup fetchGroup) { if (groupId == hashCode) { - Log.d("Error self-updating %s", app.getDisplayName()); + Log.e("Error self-updating %s", app.getDisplayName()); destroyService(); } } diff --git a/app/src/main/java/com/aurora/store/notification/NotificationBase.java b/app/src/main/java/com/aurora/store/notification/NotificationBase.java index a6c65b24f..4f554d5ce 100644 --- a/app/src/main/java/com/aurora/store/notification/NotificationBase.java +++ b/app/src/main/java/com/aurora/store/notification/NotificationBase.java @@ -62,7 +62,6 @@ public class NotificationBase { return new NotificationCompat.Builder(context, Constants.NOTIFICATION_CHANNEL_GENERAL) .setAutoCancel(true) .setCategory(NotificationCompat.CATEGORY_PROGRESS) - .setColorized(true) .setColor(context.getResources().getColor(R.color.colorAccent)) .setContentIntent(getContentIntent()) .setContentTitle(app.getDisplayName()) diff --git a/app/src/main/java/com/aurora/store/notification/QuickNotification.java b/app/src/main/java/com/aurora/store/notification/QuickNotification.java index afcfe8894..ce9eb8da2 100644 --- a/app/src/main/java/com/aurora/store/notification/QuickNotification.java +++ b/app/src/main/java/com/aurora/store/notification/QuickNotification.java @@ -54,7 +54,6 @@ public class QuickNotification extends NotificationBase { manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); builder = new NotificationCompat.Builder(context, Constants.NOTIFICATION_CHANNEL_ALERT) .setAutoCancel(true) - .setColorized(true) .setColor(context.getResources().getColor(R.color.colorAccent)) .setContentTitle(contentTitle) .setContentText(contentText) diff --git a/app/src/main/java/com/aurora/store/task/ExodusTask.java b/app/src/main/java/com/aurora/store/task/ExodusTask.java new file mode 100644 index 000000000..5f3f8d273 --- /dev/null +++ b/app/src/main/java/com/aurora/store/task/ExodusTask.java @@ -0,0 +1,42 @@ +package com.aurora.store.task; + +import android.content.Context; +import android.content.ContextWrapper; + +import com.aurora.store.util.Util; + +import java.util.HashMap; +import java.util.Map; + +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; + +public class ExodusTask extends ContextWrapper { + /*This is Yalp Store's EXODUS API key, will replace with mine once I get it.*/ + private static final String EXODUS_API_KEY = "Token bf1108aec9c28c5c286c63e89230a71f77b35a5d"; + private Context context; + + public ExodusTask(Context context) { + super(context); + this.context = context; + } + + private static OkHttpClient getOkHttpClient(Context context) { + final OkHttpClient.Builder builder = new OkHttpClient.Builder(); + if (Util.isNetworkProxyEnabled(context)) + builder.proxy(Util.getNetworkProxy(context)); + return builder.build(); + } + + public String get(String url) throws Exception { + OkHttpClient client = getOkHttpClient(context); + Request request = new Request.Builder() + .header("Content-Type", "application/json") + .header("Accept", "application/json") + .header("Authorization", EXODUS_API_KEY) + .url(url).build(); + Response response = client.newCall(request).execute(); + return response.body().string(); + } +} diff --git a/app/src/main/java/com/aurora/store/ui/details/views/ExodusPrivacy.java b/app/src/main/java/com/aurora/store/ui/details/views/ExodusPrivacy.java index 4cbccf90d..b23bd7f5e 100644 --- a/app/src/main/java/com/aurora/store/ui/details/views/ExodusPrivacy.java +++ b/app/src/main/java/com/aurora/store/ui/details/views/ExodusPrivacy.java @@ -30,7 +30,7 @@ import com.aurora.store.model.App; import com.aurora.store.model.ExodusReport; import com.aurora.store.model.Report; import com.aurora.store.sheet.ExodusBottomSheet; -import com.aurora.store.task.NetworkTask; +import com.aurora.store.task.ExodusTask; import com.aurora.store.ui.details.DetailsActivity; import com.aurora.store.util.Log; import com.google.gson.Gson; @@ -73,11 +73,11 @@ public class ExodusPrivacy extends AbstractDetails { } private void get(String url) { - disposable.add(Observable.fromCallable(() -> new NetworkTask(context) + disposable.add(Observable.fromCallable(() -> new ExodusTask(context) .get(url)) .subscribeOn(Schedulers.computation()) .observeOn(AndroidSchedulers.mainThread()) - .subscribe(response -> parseResponse(response))); + .subscribe(this::parseResponse)); } private void parseResponse(String response) { @@ -106,16 +106,15 @@ public class ExodusPrivacy extends AbstractDetails { } if (report.getTrackers().size() > 0) { - setText(R.id.exodus_description, new StringBuilder() - .append(context.getString(R.string.exodus_hasTracker)) - .append(StringUtils.SPACE) - .append(report.getTrackers().size()).toString()); + setText(R.id.exodus_description, context.getString(R.string.exodus_hasTracker) + + StringUtils.SPACE + + report.getTrackers().size()); } else { setText(R.id.exodus_description, R.string.exodus_noTracker); } if (report.getTrackers().isEmpty()) - moreButton.setVisibility(View.GONE); + moreButton.setVisibility(View.INVISIBLE); else moreButton.setOnClickListener(v -> showBottomDialog()); } diff --git a/app/src/main/res/layout/item_exodus.xml b/app/src/main/res/layout/item_exodus.xml index 47487c141..20eef1e0b 100644 --- a/app/src/main/res/layout/item_exodus.xml +++ b/app/src/main/res/layout/item_exodus.xml @@ -29,6 +29,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" + android:tint="?android:attr/colorAccent" android:layout_margin="@dimen/margin_small" app:srcCompat="@drawable/ic_shield" /> diff --git a/app/src/main/res/layout/sheet_exodus.xml b/app/src/main/res/layout/sheet_exodus.xml index 02340315a..2c29cd9c5 100644 --- a/app/src/main/res/layout/sheet_exodus.xml +++ b/app/src/main/res/layout/sheet_exodus.xml @@ -19,19 +19,16 @@ --> + android:orientation="vertical"> @@ -69,10 +66,8 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" - android:layout_marginTop="@dimen/margin_small" android:maxLines="1" - android:text="@string/exodus_viewReport" - app:cornerRadius="20dp" /> + android:text="@string/exodus_viewReport" />