Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorАлександр Зацепин <az@mapswithme.com>2017-09-29 14:42:10 +0300
committerArsentiy Milchakov <milcars@mapswithme.com>2017-09-29 17:48:58 +0300
commit19c5b06135be172f6c4b7494dcdce99eb29b948d (patch)
tree602b5bfb82224b7f09e0148773e63aeabf6a9a77
parent4512d638931d99bbe20e41df3e169b46bde14a36 (diff)
[android] Implemented secure storage on Java side
-rw-r--r--android/src/com/mapswithme/maps/auth/BaseMwmAuthorizationFragment.java23
-rw-r--r--android/src/com/mapswithme/maps/auth/SocialAuthDialogFragment.java16
-rw-r--r--android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java2
-rw-r--r--android/src/com/mapswithme/util/HttpClient.java9
-rw-r--r--android/src/com/mapswithme/util/SecureStorage.java22
5 files changed, 37 insertions, 35 deletions
diff --git a/android/src/com/mapswithme/maps/auth/BaseMwmAuthorizationFragment.java b/android/src/com/mapswithme/maps/auth/BaseMwmAuthorizationFragment.java
index f0b522795c..f9ff48de69 100644
--- a/android/src/com/mapswithme/maps/auth/BaseMwmAuthorizationFragment.java
+++ b/android/src/com/mapswithme/maps/auth/BaseMwmAuthorizationFragment.java
@@ -62,17 +62,20 @@ public abstract class BaseMwmAuthorizationFragment extends BaseMwmToolbarFragmen
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
- if (resultCode == Activity.RESULT_OK && requestCode == Constants.REQ_CODE_GET_SOCIAL_TOKEN
- && data != null)
+
+ if (requestCode != Constants.REQ_CODE_GET_SOCIAL_TOKEN
+ || resultCode != Activity.RESULT_OK || data == null)
{
- String socialToken = data.getStringExtra(Constants.EXTRA_SOCIAL_TOKEN);
- if (!TextUtils.isEmpty(socialToken))
- {
- onStartAuthorization();
- @Framework.SocialTokenType
- int type = data.getIntExtra(Constants.EXTRA_TOKEN_TYPE, -1);
- Framework.nativeAuthenticateUser(socialToken, type);
- }
+ return;
+ }
+
+ String socialToken = data.getStringExtra(Constants.EXTRA_SOCIAL_TOKEN);
+ if (!TextUtils.isEmpty(socialToken))
+ {
+ onStartAuthorization();
+ @Framework.SocialTokenType
+ int type = data.getIntExtra(Constants.EXTRA_TOKEN_TYPE, -1);
+ Framework.nativeAuthenticateUser(socialToken, type);
}
}
diff --git a/android/src/com/mapswithme/maps/auth/SocialAuthDialogFragment.java b/android/src/com/mapswithme/maps/auth/SocialAuthDialogFragment.java
index cf10af059f..1f271e3764 100644
--- a/android/src/com/mapswithme/maps/auth/SocialAuthDialogFragment.java
+++ b/android/src/com/mapswithme/maps/auth/SocialAuthDialogFragment.java
@@ -77,17 +77,17 @@ public class SocialAuthDialogFragment extends BaseMwmDialogFragment
@Framework.SocialTokenType int type)
{
Fragment caller = getTargetFragment();
+ if (caller == null)
+ return;
+
Intent data = null;
- if (caller != null)
+ if (resultCode == Activity.RESULT_OK)
{
- if (resultCode == Activity.RESULT_OK)
- {
- data = new Intent();
- data.putExtra(Constants.EXTRA_SOCIAL_TOKEN, socialToken);
- data.putExtra(Constants.EXTRA_TOKEN_TYPE, type);
- }
- caller.onActivityResult(Constants.REQ_CODE_GET_SOCIAL_TOKEN, Activity.RESULT_OK, data);
+ data = new Intent();
+ data.putExtra(Constants.EXTRA_SOCIAL_TOKEN, socialToken);
+ data.putExtra(Constants.EXTRA_TOKEN_TYPE, type);
}
+ caller.onActivityResult(Constants.REQ_CODE_GET_SOCIAL_TOKEN, resultCode, data);
}
@Override
diff --git a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java
index a5b1b4a043..0562643427 100644
--- a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java
+++ b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java
@@ -1353,7 +1353,7 @@ public class PlacePageView extends RelativeLayout
{
// TODO: Be careful, shouldShowUgc can return true only when all ui work about UGC is done.
// Now (01.08.2017) UI is not ready for UGC yet.
- if (true)
+ if (mMapObject.shouldShowUGC())
{
UGC.setListener(this);
UGC.requestUGC(mMapObject.getFeatureId());
diff --git a/android/src/com/mapswithme/util/HttpClient.java b/android/src/com/mapswithme/util/HttpClient.java
index 26ea0ffd8a..f4dd464eb0 100644
--- a/android/src/com/mapswithme/util/HttpClient.java
+++ b/android/src/com/mapswithme/util/HttpClient.java
@@ -65,7 +65,7 @@ public final class HttpClient
HttpURLConnection connection = null;
- logUrlSafely(p.url);
+ LOGGER.d(TAG, "Connecting to " + makeUrlSafe(p.url));
try
{
@@ -147,7 +147,7 @@ public final class HttpClient
// GET data from the server or receive response body
p.httpResponseCode = connection.getResponseCode();
LOGGER.d(TAG, "Received HTTP " + p.httpResponseCode + " from server, content encoding = "
- + connection.getContentEncoding() + ", for request = " + p.url);
+ + connection.getContentEncoding() + ", for request = " + makeUrlSafe(p.url));
if (p.httpResponseCode >= 300 && p.httpResponseCode < 400)
p.receivedUrl = connection.getHeaderField("Location");
@@ -239,10 +239,9 @@ public final class HttpClient
return in;
}
- private static void logUrlSafely(@NonNull final String url)
+ private static String makeUrlSafe(@NonNull final String url)
{
- String safeUrl = url.replaceAll("(token|password|key)=([^&]+)", "***");
- LOGGER.d(TAG, "Connecting to " + safeUrl);
+ return url.replaceAll("(token|password|key)=([^&]+)", "***");
}
private static class HttpHeader
diff --git a/android/src/com/mapswithme/util/SecureStorage.java b/android/src/com/mapswithme/util/SecureStorage.java
index b1ef9bf7f4..5ce394fad4 100644
--- a/android/src/com/mapswithme/util/SecureStorage.java
+++ b/android/src/com/mapswithme/util/SecureStorage.java
@@ -1,9 +1,11 @@
package com.mapswithme.util;
+import android.content.Context;
+import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
-import com.mapswithme.maps.BuildConfig;
+import com.mapswithme.maps.MwmApplication;
import com.mapswithme.util.log.Logger;
import com.mapswithme.util.log.LoggerFactory;
@@ -11,29 +13,27 @@ public final class SecureStorage
{
private static final Logger LOGGER = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.MISC);
private static final String TAG = SecureStorage.class.getSimpleName();
+ private static final SharedPreferences mPrefs
+ = MwmApplication.get().getSharedPreferences("secure", Context.MODE_PRIVATE);
private SecureStorage() {}
public static void save(@NonNull String key, @NonNull String value)
{
- if (BuildConfig.DEBUG)
- LOGGER.d(TAG, "save: key = " + key + ", value = " + value);
- // TODO: implement @alexzatsepin
+ LOGGER.d(TAG, "save: key = " + key);
+ mPrefs.edit().putString(key, value).apply();
}
@Nullable
public static String load(@NonNull String key)
{
- if (BuildConfig.DEBUG)
- LOGGER.d(TAG, "load: key = " + key);
- // TODO: implement @alexzatsepin
- return null;
+ LOGGER.d(TAG, "load: key = " + key);
+ return mPrefs.getString(key, null);
}
public static void remove(@NonNull String key)
{
- if (BuildConfig.DEBUG)
- LOGGER.d(TAG, "remove: key = " + key);
- // TODO: implement @alexzatsepin
+ LOGGER.d(TAG, "remove: key = " + key);
+ mPrefs.edit().remove(key).apply();
}
}