Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #158

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package com.tesla.tmd;
package com.wbtech.ums;

import org.json.JSONException;
import org.json.JSONObject;

import junit.framework.Assert;
import android.test.AndroidTestCase;

public class Test extends AndroidTestCase {
Expand Down
2 changes: 0 additions & 2 deletions sdk/android_sdk/sdk/src/java/com/wbtech/ums/AppInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

package com.wbtech.ums;

import com.wbtech.ums.UmsConstants;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@
*/
package com.wbtech.ums;

import android.content.Context;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.wbtech.ums.UmsConstants;

import android.content.Context;


class ClientdataManager {
private Context context;
Expand Down Expand Up @@ -77,7 +75,7 @@ public void judgeSession(final Context context){
CobubLog.i(UmsConstants.LOG_TAG,UsinglogManager.class, "judgeSession on clientdata");
try {
if (CommonUtil.isNewSession(context)) {
String session_id = CommonUtil.generateSession(context);
String session_id = CommonUtil.generateSession(context);
CobubLog.i(UmsConstants.LOG_TAG, UsinglogManager.class,"New Sessionid is " + session_id);
}
} catch (Exception e) {
Expand Down
56 changes: 37 additions & 19 deletions sdk/android_sdk/sdk/src/java/com/wbtech/ums/CommonUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,6 @@

package com.wbtech.ums;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.security.MessageDigest;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.UUID;
import java.util.concurrent.locks.ReentrantReadWriteLock;

import org.json.JSONArray;
import org.json.JSONObject;

import android.app.Activity;
import android.app.ActivityManager;
import android.content.ComponentName;
Expand All @@ -41,10 +25,26 @@
import android.os.Build;
import android.os.Environment;
import android.telephony.TelephonyManager;
import android.util.Log;

import com.wbtech.ums.UmsConstants;
import com.wbtech.ums.UmsAgent.SendPolicy;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.security.MessageDigest;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.UUID;
import java.util.concurrent.locks.ReentrantReadWriteLock;

class CommonUtil {
private static String USER_ID = "";
private static String curversion = "";
Expand Down Expand Up @@ -330,7 +330,20 @@ public static String getNetworkType(Context context) {
return typeString;
}

/**
* 判断是否是新的session
* cobub之前规则是,只要在【时间间隔】内,算一次session
* 1,app启动后,关闭,在【时间间隔】内启动session值相同
* 2,app启动后,后台运行,在【时间间隔】内启动session值相同
* 应修改:当app启动时,session重置
* @param context
* @return
*/
static boolean isNewSession(Context context) {
Log.i("longtest", "-----------------------------------------isNewSession");
/**
* 此处有疑问?
*/
if (context == null) {
CobubLog.e(UmsConstants.LOG_TAG, CommonUtil.class, "context is null");
return false;
Expand All @@ -341,10 +354,15 @@ static boolean isNewSession(Context context) {
long session_save_time = sp.getValue("session_save_time", 0);
CobubLog.i(UmsConstants.LOG_TAG, CommonUtil.class, "currenttime=" + currenttime);
CobubLog.i(UmsConstants.LOG_TAG, CommonUtil.class, "session_save_time=" + session_save_time);
/**
* 若当前时间-之前session最后一次保留时间 > 时间间隔
* 则 创建新session
*/
if (currenttime - session_save_time > getSessionContinueMillis(context)) {
CobubLog.i(UmsConstants.LOG_TAG, CommonUtil.class, "return true,create new session.");
return true;
}
// 否则为同一个session
CobubLog.i(UmsConstants.LOG_TAG, CommonUtil.class, "return false.At the same session.");
return false;
} catch (Exception e) {
Expand Down Expand Up @@ -564,7 +582,7 @@ public synchronized static String getSALT(Context context) {
String file_name = context.getPackageName().replace(".", "");
String sdCardRoot = Environment.getExternalStorageDirectory()
.getAbsolutePath();
int apiLevel = Integer.parseInt(android.os.Build.VERSION.SDK);
int apiLevel = Integer.parseInt(Build.VERSION.SDK);
File fileFromSDCard = new File(sdCardRoot +File.separator, "."+file_name);
File fileFromDData = new File(context.getFilesDir(),file_name);// 获取data/data/<package>/files
//4.4之後 /storage/emulated/0/Android/data/<package>/files
Expand All @@ -575,7 +593,7 @@ public synchronized static String getSALT(Context context) {

String saltString = "";
if (Environment.getExternalStorageState().equals(
android.os.Environment.MEDIA_MOUNTED)) {
Environment.MEDIA_MOUNTED)) {
// sdcard存在
if (!fileFromSDCard.exists()) {

Expand Down

This file was deleted.

3 changes: 0 additions & 3 deletions sdk/android_sdk/sdk/src/java/com/wbtech/ums/DeviceInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.UUID;

import com.wbtech.ums.UmsConstants;


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,12 @@ public void postEventInfo() {

if (CommonUtil.getReportPolicyMode(context) == SendPolicy.POST_NOW
&& CommonUtil.isNetworkAvailable(context)) {
// MyMessage message = NetworkUtil.Post(UmsConstants.BASE_URL
// + UmsConstants.EVENT_URL, postdata.toString());
MyMessage message = NetworkUtil.Post(UmsConstants.BASE_URL
+ UmsConstants.EVENT_URL, postdata.toString());
, postdata.toString());
// MyMessage message = NetworkUtil.Post("http://172.16.0.16/?sid=zhongqing", postdata.toString());
//MyMessage message = NetworkUtil.Post("http://172.16.0.16/", postdata.toString());

if (!message.isSuccess()) {
CobubLog.e(UmsConstants.LOG_TAG, EventManager.class, "Message="
Expand Down