Details : Fix broken exodus reports due to change in APIs

https://gitlab.com/AuroraOSS/AuroraStore/issues/274
This commit is contained in:
Rahul Kumar Patel
2020-01-12 19:46:48 +05:30
parent 512422dde6
commit ace8183151
7 changed files with 63 additions and 41 deletions

View File

@@ -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();
}
}

View File

@@ -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())

View File

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

View File

@@ -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();
}
}

View File

@@ -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());
}

View File

@@ -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" />

View File

@@ -19,19 +19,16 @@
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:targetApi="o">
android:orientation="vertical">
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="@dimen/margin_normal"
android:paddingHorizontal="@dimen/margin_normal"
android:text="@string/exodus_title_alt"
android:textAppearance="@style/TextAppearance.Aurora.DialogTitle" />
@@ -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" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/exodus_recycler"