支持远程查询和切换桌面图标包
This commit is contained in:
1 parent
38e1bcc288
commit
b90660f5ec
4 files changed
+93
-1
No files matched your search
+68
@@ -0,0 +1,68 @@
|
||||
package com.ttstd.dialer.activity.settings.iconpack;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.ttstd.dialer.network.OkHttpManager;
|
||||
import com.ttstd.dialer.network.api.SnApi;
|
||||
import com.ttstd.dialer.utils.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import io.reactivex.rxjava3.schedulers.Schedulers;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
/** Applies family requests through the same repository as the local settings page. */
|
||||
public final class IconPackRemoteHandler {
|
||||
private static final String TAG = "IconPackRemoteHandler";
|
||||
private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
|
||||
|
||||
private IconPackRemoteHandler() {}
|
||||
|
||||
public static void handle(Context context, String requestId, String packageName) {
|
||||
if (!requestId.matches("[0-9a-f]{32}")) return;
|
||||
IconPackRepository repository = new IconPackRepository(context);
|
||||
(packageName == null ? repository.load() : repository.select(packageName))
|
||||
.subscribeOn(Schedulers.single())
|
||||
.subscribe(
|
||||
state -> report(requestId, toRemoteState(state)),
|
||||
error -> report(requestId, null)
|
||||
);
|
||||
}
|
||||
|
||||
private static Map<String, Object> toRemoteState(IconPackRepository.State state) {
|
||||
List<Map<String, Object>> entries = new ArrayList<>();
|
||||
for (IconPackRepository.Entry entry : state.entries) {
|
||||
if (entries.size() == 200) break;
|
||||
Map<String, Object> item = new HashMap<>();
|
||||
item.put("packageName", entry.packageName);
|
||||
item.put("label", entry.label.substring(0, Math.min(256, entry.label.length())));
|
||||
item.put("available", entry.available);
|
||||
entries.add(item);
|
||||
}
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("selectedPackage", state.selected);
|
||||
result.put("entries", entries);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void report(String requestId, Map<String, Object> state) {
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
payload.put("requestId", requestId);
|
||||
payload.put("state", state);
|
||||
RequestBody body = RequestBody.create(JSON, new Gson().toJson(payload));
|
||||
OkHttpManager.getInstance().getApiService(SnApi.class)
|
||||
.reportIconPackResult(body)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe(
|
||||
response -> {
|
||||
if (!response.isSuccess()) Logger.e(TAG, "Icon pack result rejected");
|
||||
},
|
||||
error -> Logger.e(TAG, "Icon pack result upload failed")
|
||||
);
|
||||
}
|
||||
}
|
||||
+6
-1
@@ -35,7 +35,12 @@ final class IconPackRepository {
|
||||
Single<State> load() { return Single.fromCallable(this::read); }
|
||||
Single<State> select(String packageName) {
|
||||
return Single.fromCallable(() -> {
|
||||
if (!packageName.isEmpty()) context.getPackageManager().getApplicationInfo(packageName, 0);
|
||||
if (!packageName.isEmpty()) {
|
||||
PackageManager pm = context.getPackageManager();
|
||||
if (!pm.getApplicationInfo(packageName, 0).enabled || !hasAppFilter(pm, packageName)) {
|
||||
throw new IllegalArgumentException("Icon pack is unavailable");
|
||||
}
|
||||
}
|
||||
IconCacheManager.getInstance().setDefaultIconPack(packageName);
|
||||
return read();
|
||||
});
|
||||
|
||||
@@ -25,6 +25,9 @@ import retrofit2.http.POST;
|
||||
import retrofit2.http.Part;
|
||||
|
||||
public interface SnApi {
|
||||
@POST("icon_pack_result")
|
||||
Observable<BaseResponse<Void>> reportIconPackResult(@Body RequestBody body);
|
||||
|
||||
/**
|
||||
* 设备确认绑定手机号(绑定即注册)。
|
||||
* <p>
|
||||
|
||||
@@ -31,6 +31,7 @@ import com.kongzue.dialogx.dialogs.MessageDialog;
|
||||
import com.tencent.mmkv.MMKV;
|
||||
import com.ttstd.dialer.BuildConfig;
|
||||
import com.ttstd.dialer.R;
|
||||
import com.ttstd.dialer.activity.settings.iconpack.IconPackRemoteHandler;
|
||||
import com.ttstd.dialer.alarmclock.AlarmSyncManager;
|
||||
import com.ttstd.dialer.bean.ApkInstalledInfo;
|
||||
import com.ttstd.dialer.bean.BaseResponse;
|
||||
@@ -133,6 +134,7 @@ public class PushExecutor {
|
||||
private static final String DEVICE_SMS_CONTENT = "27";
|
||||
private static final String DEVICE_CALL_SYNC = "28";
|
||||
private static final String DEVICE_REVERSE_DIAL_CONFIRM = "29";
|
||||
private static final String DEVICE_ICON_PACK = "30";
|
||||
|
||||
/** 绑定请求弹窗倒计时时长(秒) */
|
||||
private static final long BIND_REQUEST_COUNTDOWN_SECONDS = 60L;
|
||||
@@ -288,6 +290,9 @@ public class PushExecutor {
|
||||
case DEVICE_CALL_SYNC:
|
||||
syncCallRecords(extra);
|
||||
break;
|
||||
case DEVICE_ICON_PACK:
|
||||
handleIconPack(extra);
|
||||
break;
|
||||
default:
|
||||
Logger.e(TAG, "setPushMessage: default");
|
||||
}
|
||||
@@ -794,6 +799,17 @@ public class PushExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
private void handleIconPack(String extra) {
|
||||
try {
|
||||
JsonObject json = JsonParser.parseString(extra).getAsJsonObject();
|
||||
String requestId = json.get("requestId").getAsString();
|
||||
String packageName = json.has("packageName") ? json.get("packageName").getAsString() : null;
|
||||
IconPackRemoteHandler.handle(mContext, requestId, packageName);
|
||||
} catch (RuntimeException e) {
|
||||
Logger.e(TAG, "handleIconPack: invalid request");
|
||||
}
|
||||
}
|
||||
|
||||
private void syncCallRecords(String extra) {
|
||||
try {
|
||||
JsonObject json = JsonParser.parseString(extra).getAsJsonObject();
|
||||
|
||||
Reference in new issue
Block a user