Skip to content

Commit c2f4706

Browse files
committed
feat(server/common): use client request header as package name field
Signed-off-by: Trumeet <[email protected]>
1 parent a4cd9c3 commit c2f4706

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

BUILD.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
This guide tells you how to build this project and run it on your own devices.
33
It has two parts - Server (Docker) and client (Android).
44

5+
# Limits
6+
The relationship between the client and server is one to one, that means the "Official" APKs can only use "Official" server, your builds can't use it. So if you'd like to build the client, you will have to build the server as well.
7+
8+
Update checker will also not works on your builds, it only supports official clients.
9+
510
# Pre-requirements
611
Whatever to build the server or client, you should have a MiPush application which is registered in Mi dev console at first.
712

@@ -72,6 +77,4 @@ You can't use the same package name as the "Official" builds, you should change
7277

7378
Just copy `app/xmpush.properties.template` to `app/xmpush.properties`, and change the values.
7479

75-
Secondly, modify `common/src/main/java/moe/yuuta/common/Constants.java#CLIENT_ID` to the same package name.
76-
7780
Finally, pack it with Android Studio.

common/src/main/java/moe/yuuta/common/Constants.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public class Constants {
1414
public static final String EXTRA_REQUEST_LOCALE = EXTRA_MIPUSHTESTER_PREFIX + "request_locale";
1515
public static final String EXTRA_REQUEST_TIME = EXTRA_MIPUSHTESTER_PREFIX + "request_time";
1616
public static final String EXTRA_CLIENT_VERSION = EXTRA_MIPUSHTESTER_PREFIX + "client_version";
17-
// The package name of client, for more details, see BUILD.md
1817
public static final String TESTER_CLIENT_ID = "moe.yuuta.mipushtester";
1918
public static final String FRAMEWORK_CLIENT_ID = "top.trumeet.mipush";
2019
}

server/src/main/java/moe/yuuta/server/api/ApiHandlerImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ public void handlePush(RoutingContext routingContext) {
7979
return;
8080
}
8181
if ((request.getExtras() != null && request.getExtras().size() > 10) ||
82-
!DataVerifier.verify(request)) {
82+
!DataVerifier.verify(request) ||
83+
routingContext.request().getHeader(Constants.HEADER_PRODUCT) == null) {
8384
routingContext.response().setStatusCode(400).end();
8485
return;
8586
}
@@ -89,7 +90,7 @@ public void handlePush(RoutingContext routingContext) {
8990
new SimpleDateFormat("HH:mm:ss", Locale.CHINA).format(Calendar.getInstance(TimeZone.getTimeZone("Asia/Shanghai")).getTime()));
9091
Message message = new Message();
9192
message.setTicker(ticker);
92-
message.setRestrictedPackageName(Constants.TESTER_CLIENT_ID);
93+
message.setRestrictedPackageName(routingContext.request().getHeader(Constants.HEADER_PRODUCT));
9394
// FIXME
9495
message.setPassThrough(request.isPassThrough() ? Message.PASS_THROUGH_ENABLED :
9596
Message.PASS_THROUGH_DISABLED);

server/src/test/java/moe/yuuta/server/api/ApiHandlerImplTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ public void shouldHandleSuccessfulPush(TestContext testContext) {
349349
final int delayMs = 100;
350350
final String requestVersion = "Haoye1.0";
351351
final String requestLocale = "zh_TW";
352+
final String packageName = "android.sms";
352353

353354
// TODO: Test multiple situations for variety arguments (e.g. display)
354355
this.sendPushCallback = (Message message, String[] regIds, Map<String, String> customExtras, Handler<AsyncResult<HttpResponse<SendMessageResponse>>> handler) -> {
@@ -358,7 +359,7 @@ public void shouldHandleSuccessfulPush(TestContext testContext) {
358359
// TODO: Fully match the description
359360
testContext.assertNotNull(message.getDescription());
360361
testContext.assertNotEquals(message.getDescription(), "");
361-
testContext.assertEquals(message.getRestrictedPackageName(), Constants.TESTER_CLIENT_ID);
362+
testContext.assertEquals(message.getRestrictedPackageName(), packageName);
362363
testContext.assertEquals(message.getPassThrough(), Message.PASS_THROUGH_ENABLED);
363364
testContext.assertEquals(message.getNotifyForeground(), Message.NOTIFY_FOREGROUND_DISABLE);
364365
testContext.assertEquals(message.getConnpt(), Message.CONNPT_WIFI);
@@ -404,6 +405,7 @@ public void shouldHandleSuccessfulPush(TestContext testContext) {
404405
.putHeader("Accept-Language", Locale.ENGLISH.toString())
405406
.putHeader(Constants.HEADER_LOCALE, requestLocale)
406407
.putHeader(Constants.HEADER_VERSION, requestVersion)
408+
.putHeader(Constants.HEADER_PRODUCT, packageName)
407409
.setChunked(true)
408410
.write(ApiUtils.tryObjectToJson(request))
409411
.end();

0 commit comments

Comments
 (0)