Skip to content

Commit

Permalink
add remote update mh50 key and iv
Browse files Browse the repository at this point in the history
  • Loading branch information
Haleydu committed Aug 23, 2020
1 parent 5bbbf57 commit 46a3649
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ public class PreferenceManager {
public static final String PREFERENCES_USER_EMAIL = "user_email";
public static final String PREFERENCES_USER_ID = "user_id";
private static final String PREFERENCES_NAME = "cimoc_preferences";

public static final String PREFERENCES_MH50_KEY_MSG = "preferences_mh50_key_msg";
public static final String PREFERENCES_MH50_IV_MSG = "preferences_mh50_iv_msg";

private SharedPreferences mSharedPreferences;

public PreferenceManager(Context context) {
Expand Down
7 changes: 5 additions & 2 deletions app/src/main/java/com/hiroshi/cimoc/source/MH50.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.hiroshi.cimoc.source;

import android.util.Log;
import android.util.Pair;

import com.alibaba.fastjson.JSONArray;
import com.google.common.collect.Lists;
import com.hiroshi.cimoc.App;
import com.hiroshi.cimoc.manager.PreferenceManager;
import com.hiroshi.cimoc.model.Chapter;
import com.hiroshi.cimoc.model.Comic;
import com.hiroshi.cimoc.model.ImageUrl;
Expand Down Expand Up @@ -128,8 +131,8 @@ public Request getImagesRequest(String cid, String path) {

@Nullable
private String decrypt(String code) {
String key = "KA58ZAQ54321bbG1";
String iv = "A1B2C3DEF1G321bb";
String key = App.getPreferenceManager().getString(PreferenceManager.PREFERENCES_MH50_KEY_MSG, "KA58ZAQ54321bbG1");
String iv = App.getPreferenceManager().getString(PreferenceManager.PREFERENCES_MH50_IV_MSG, "A1B2C3DEF1G321bb");
try {
return DecryptionUtils.aesDecrypt(code, key, iv);
} catch (Exception e) {
Expand Down
35 changes: 35 additions & 0 deletions app/src/main/java/com/hiroshi/cimoc/ui/activity/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.facebook.drawee.interfaces.DraweeController;
import com.facebook.drawee.view.SimpleDraweeView;
Expand Down Expand Up @@ -199,6 +200,7 @@ protected void initData() {

showAuthorNotice();
showPermission();
getMh50KeyIv();
}

@Override
Expand Down Expand Up @@ -571,6 +573,39 @@ public void onComplete(@NonNull Task<Boolean> task) {
});
}

private void getMh50KeyIv() {
FirebaseRemoteConfig mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder()
.setMinimumFetchIntervalInSeconds(60*60)
.build();
mFirebaseRemoteConfig.setConfigSettingsAsync(configSettings);
mFirebaseRemoteConfig.setDefaultsAsync(R.xml.remote_config);
mFirebaseRemoteConfig.fetchAndActivate()
.addOnCompleteListener(this, new OnCompleteListener<Boolean>() {
@Override
public void onComplete(@NonNull Task<Boolean> task) {
if (task.isSuccessful()) {
boolean updated = task.getResult();
Log.d("FireBase_FirstOpenMsg", "Config params updated: " + updated);
} else {
Log.d("FireBase_FirstOpenMsg", "Config params updated Failed. ");
}

String mh50_key = mFirebaseRemoteConfig.getString("mh50_key_msg");
String mh50_iv = mFirebaseRemoteConfig.getString("mh50_iv_msg");

if (!mh50_key.equals(mPreference.getString(PreferenceManager.PREFERENCES_MH50_KEY_MSG, "KA58ZAQ54321bbG1"))){
mPreference.putString(PreferenceManager.PREFERENCES_MH50_KEY_MSG, mh50_key);
Toast.makeText(MainActivity.this,"漫画堆key已更新",Toast.LENGTH_LONG).show();
}
if (!mh50_iv.equals(mPreference.getString(PreferenceManager.PREFERENCES_MH50_IV_MSG, "A1B2C3DEF1G321bb"))){
mPreference.putString(PreferenceManager.PREFERENCES_MH50_IV_MSG, mh50_iv);
Toast.makeText(MainActivity.this,"漫画堆iv已更新",Toast.LENGTH_LONG).show();
}
}
});
}

private void showPermission() {
if (!PermissionUtils.hasAllPermissions(this)) {
MessageDialogFragment fragment = MessageDialogFragment.newInstance(R.string.main_permission,
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/xml/remote_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,13 @@
<key>first_open_msg</key>
<value>Welcome to Cimoc!</value>
</entry>
<entry>
<key>mh50_key_msg</key>
<value>KA58ZAQ54321bbG1</value>
</entry>
<entry>
<key>mh50_iv_msg</key>
<value>A1B2C3DEF1G321bb</value>
</entry>
</defaultsMap>
<!-- END xml_defaults -->

0 comments on commit 46a3649

Please sign in to comment.