Commit c81fbcf2 by nimengfei

ML2001守护宝源码

1 parent 52506f72
Showing with 3538 additions and 0 deletions
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<codeStyleSettings language="XML">
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="4" />
</indentOptions>
<arrangement>
<rules>
<section>
<rule>
<match>
<AND>
<NAME>xmlns:android</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>xmlns:.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:id</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:name</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>name</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>style</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
<order>ANDROID_ATTRIBUTE_ORDER</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>.*</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
</rules>
</arrangement>
</codeStyleSettings>
</code_scheme>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="testRunner" value="PLATFORM" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
</GradleProjectSettings>
</option>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="JDK" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
</set>
</option>
</component>
</project>
\ No newline at end of file
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion '29.0.3'
defaultConfig {
applicationId "com.agenew.duardian"
minSdkVersion 16
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.amap.api:location:4.5.1'
implementation 'com.amap.api:map2d:5.2.0'
implementation("com.squareup.okhttp3:okhttp:3.12.0")
implementation 'com.google.code.gson:gson:2.8.2'
}
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
No preview for this file type
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":1,"versionName":"1.0","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release","dirName":""},"path":"app-release.apk","properties":{}}]
\ No newline at end of file
package com.agenew.duardian;
import android.content.Context;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.agenew.duardian", appContext.getPackageName());
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.agenew.duardian"
android:sharedUserId="android.uid.system">
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.RECEIVE_MMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission
android:name="android.permission.WRITE_SETTINGS"
tools:ignore="ProtectedPermissions" />
<uses-permission
android:name="android.permission.WRITE_SECURE_SETTINGS"
tools:ignore="ProtectedPermissions" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<meta-data
android:name="com.amap.api.v2.apikey"
android:value="f64d6befddab6842522f5952bf8f8b41">
</meta-data>
<provider
android:name=".data.HeKangContentProvider"
android:authorities="com.agenew.duardian"
android:enabled="true"
android:exported="true" />
<receiver
android:name=".SimStateReceive"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.SIM_STATE_CHANGED" />
</intent-filter>
</receiver>
<service
android:name=".WorkService"
android:enabled="true"
android:exported="true" />
<receiver
android:name=".sms.SmsUpdateReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.agenew.duardian.update"/>
</intent-filter>
</receiver>
<receiver
android:name=".sms.SmsLocationReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.agenew.duardian.location" />
</intent-filter>
</receiver>
<!-- <activity android:name=".MainActivity">-->
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.MAIN" />-->
<!-- <category android:name="android.intent.category.LAUNCHER" />-->
<!-- </intent-filter>-->
<!-- </activity>-->
<service android:name=".LocationService"
android:enabled="true"
android:exported="true" />
<service android:name="com.amap.api.location.APSService" />
<receiver
android:name=".sms.SMSSendResultReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="hekang_sms_send_action" />
</intent-filter>
</receiver>
</application>
</manifest>
\ No newline at end of file
package com.agenew.duardian;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.net.Uri;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.IBinder;
import android.provider.Settings;
import android.util.Log;
import com.agenew.duardian.allinterface.DateListener;
import com.agenew.duardian.api.IotApi;
import com.agenew.duardian.api.IotNetApiCallback;
import com.agenew.duardian.provider.PostServiceApply;
import com.agenew.duardian.util.ParseResponseUtil;
import com.agenew.duardian.util.PhoneUtils;
import com.agenew.duardian.util.PreferencesUtil;
import com.amap.api.maps2d.AMapUtils;
import com.amap.api.maps2d.model.LatLng;
import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import okhttp3.FormBody;
public class LocationService extends Service {
private final String TAG = "LocationService";
private String mType = "";
private String mLongitude = "";
private String mLatitude = "";
private boolean WifiState = false;
private boolean isCellMode = false;
private boolean isWifiMode = false;
private boolean isGpsMode = false;
private double mCellLatitude = 0;
private double mCellLongitude = 0;
private double mWifiLatitude = 0;
private double mWifiLongitude = 0;
private double mGpsLatitude = 0;
private double mGpsLongitude = 0;
private float mAccuracy = 10000;
private float mWifiAccuracy = 1000;
private float mGpsAccuracy = 1000;
private int mErrorCount = 0;
private int mRequestLocationCount = 0;
private int mWifiAvailableErrorCount = 0;
private int mNetworkAvailableErrorCount = 0;
private LocationManager mLocationManager;
public AMapLocationClientOption mLocationOption = null;
public AMapLocationClient mLocationClient = null;
private Context mContext;
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
mContext = getApplicationContext();
Log.d(TAG, "LocationService is onCreate");
super.onCreate();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d(TAG, "onStartCommand");
readyToReqLocation();
return super.onStartCommand(intent, flags, startId);
}
private void readyToReqLocation() {
resetTheCounts();
reinitDate();
openGps();
WifiState = AdjustWifiState(mContext);
requestLocationUpdates();
initLocation(mContext);
}
private void reinitDate() {
WifiState = false;
isCellMode = false;
isWifiMode = false;
isGpsMode = false;
mCellLatitude = 0;
mCellLongitude = 0;
mWifiLatitude = 0;
mWifiLongitude = 0;
mGpsLatitude = 0;
mGpsLongitude = 0;
mAccuracy = 10000;
mWifiAccuracy = 1000;
mGpsAccuracy = 1000;
mType = "";
mLongitude = "";
mLatitude = "";
}
private boolean AdjustWifiState(Context context) {
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
if (wifiManager == null) {
return false;
}
if (wifiManager.isWifiEnabled()) {
if (wifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLED || wifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLING) {
return true;
} else {
wifiManager.setWifiEnabled(true);
return false;
}
} else {
wifiManager.setWifiEnabled(true);
return false;
}
}
public AMapLocationListener mLocationListener = new AMapLocationListener() {
@Override
public void onLocationChanged(AMapLocation amapLocation) {
Log.d(TAG, "onLocationChanged");
if (!PhoneUtils.isNetwork(mContext) && mNetworkAvailableErrorCount < 4) {
mNetworkAvailableErrorCount++;
Log.d(TAG, "network not available");
return;
}
if (amapLocation != null) {
if (amapLocation.getErrorCode() == 0) {
mRequestLocationCount++;
Log.d(TAG, "amapLocation.getLatitude(): " + amapLocation.getLatitude()
+ ", amapLocation.getLongitude(): " + amapLocation.getLongitude()
+ ", amapLocation.getAccuracy():" + amapLocation.getAccuracy()
+ "amapLocation.getLocationType()" + amapLocation.getLocationType());
if (amapLocation.getLocationType() == 6) {
if (amapLocation.getAccuracy() < mAccuracy) {
mAccuracy = amapLocation.getAccuracy();
mCellLatitude = amapLocation.getLatitude();
mCellLongitude = amapLocation.getLongitude();
isCellMode = true;
}
} else if (amapLocation.getLocationType() == 5) {
if (amapLocation.getAccuracy() < mWifiAccuracy) {
mWifiAccuracy = amapLocation.getAccuracy();
mWifiLatitude = amapLocation.getLatitude();
mWifiLongitude = amapLocation.getLongitude();
isWifiMode = true;
}
} else if (amapLocation.getLocationType() == 1) {
if (amapLocation.getAccuracy() < mGpsAccuracy) {
mGpsAccuracy = amapLocation.getAccuracy();
mGpsLatitude = amapLocation.getLatitude();
mGpsLongitude = amapLocation.getLongitude();
isGpsMode = true;
}
}
if (mRequestLocationCount > 12) {
if (isCellMode) {
mLatitude = String.valueOf(mCellLatitude);
mLongitude = String.valueOf(mCellLongitude);
mType = String.valueOf(AMapLocation.LOCATION_TYPE_CELL); //cell Loaction
}
if (isWifiMode && isGpsMode){
LatLng wifiLatLng = new LatLng(mWifiLatitude, mWifiLongitude);
LatLng gpsLatLng = new LatLng(mGpsLatitude, mGpsLongitude);
float distance = AMapUtils.calculateLineDistance(wifiLatLng, gpsLatLng);
if (distance > mWifiAccuracy + 60) {
mLatitude = String.valueOf(mWifiLatitude);
mLongitude = String.valueOf(mWifiLongitude);
mAccuracy = mWifiAccuracy;
mType = String.valueOf(AMapLocation.LOCATION_TYPE_WIFI);
} else {
mLatitude = String.valueOf(mGpsLatitude);
mLongitude = String.valueOf(mGpsLongitude);
mAccuracy = mGpsAccuracy;
mType = String.valueOf(AMapLocation.LOCATION_TYPE_GPS);
}
}else if (isWifiMode) {
mLatitude = String.valueOf(mWifiLatitude);
mLongitude = String.valueOf(mWifiLongitude);
mAccuracy = mWifiAccuracy;
mType = String.valueOf(AMapLocation.LOCATION_TYPE_WIFI);
}else if (isGpsMode) {
mLatitude = String.valueOf(mGpsLatitude);
mLongitude = String.valueOf(mGpsLongitude);
mAccuracy = mGpsAccuracy;
mType = String.valueOf(AMapLocation.LOCATION_TYPE_GPS);
}
Log.d(TAG, "LAST PERFECT INFO amapLocation.getLatitude(): " + mLatitude
+ ", amapLocation.getLongitude(): " + mLongitude
+ ", amapLocation.getAccuracy():" + mAccuracy
+ ", amapLocation.getLocationType():" + mType);
if (mLocationClient != null) {
mLocationClient.stopLocation();
}
handleGpsRelease();
if (!"".equals(mLongitude) && !"".equals(mLatitude) && !"".equals(mType)) {
postLocationInfo(mLongitude, mLatitude, mType);
} else {
mLongitude = "0";
mLatitude = "0";
postLocationInfo(mLongitude, mLatitude, mType);
}
}
} else {
Log.e(TAG, "location Error, ErrCode:"
+ amapLocation.getErrorCode() + ", errInfo:"
+ amapLocation.getErrorInfo());
handlerGpsError();
}
} else {
Log.d(TAG, "location Error");
handlerGpsError();
}
}
};
private void handleGpsRelease() {
if (mLocationClient != null) {
mLocationClient.stopLocation();
}
if (mLocListener != null) {
mLocationManager.removeUpdates(mLocListener);
mLocListener = null;
}
mLocationManager = null;
closeGps();
recoveryWifiState(mContext);
}
private void recoveryWifiState(Context context) {
if (!WifiState) {
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
wifiManager.setWifiEnabled(false);
}
}
private void handlerGpsError() {
Log.d(TAG, "handlerGpsError");
mErrorCount++;
if (mErrorCount > 6) {
if (!"".equals(mLongitude) && !"".equals(mLatitude)) {
postLocationInfo(mLongitude, mLatitude, mType);
}
handleGpsRelease();
}
}
private void postLocationInfo(String lng, String lat, String type) {
StringBuilder content = new StringBuilder();
String pm = "";
if ("1".equals(type)) {
pm = "5";
} else if ("5".equals(type)) {
pm = "7";
} else {
pm = "6";
}
String phoneNum = "";
Uri uri = Uri.parse("content://com.agenew.duardian/zte2100");
Cursor zte2100Cursor = mContext.getContentResolver().query(uri, new String[]{"mobile"}, null, null, null);
while (zte2100Cursor.moveToNext()) {
phoneNum = zte2100Cursor.getString(zte2100Cursor.getColumnIndex("mobile"));
}
if (phoneNum != null && !"".equals(phoneNum)) {
content.append(phoneNum);
} else if (PhoneUtils.getNativePhoneNumber(mContext) != null && !"".equals(PhoneUtils.getNativePhoneNumber(mContext))) {
content.append(PhoneUtils.getNativePhoneNumber(mContext));
}
zte2100Cursor.close();
content.append('|');
content.append("10003");
content.append('|');
content.append(PreferencesUtil.HE_KANG_VERSION);
content.append('|');
content.append(lng);
content.append('|');
content.append(lat);
content.append('|');
content.append(pm);
content.append('|');
content.append(PhoneUtils.getMcc(mContext));
content.append('|');
content.append(PhoneUtils.getMnc(mContext));
content.append('|');
content.append(PhoneUtils.getLAC(mContext));
content.append('|');
content.append(PhoneUtils.getCID(mContext));
content.append('|');
content.append('0');
content.append("|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0");
Log.d(TAG, "zte1003 : " + "" + content);
String message = "" + content;
FormBody.Builder requestBodyBuilder = PostServiceApply.jsonReqContent(PreferencesUtil.HE_KANG_ZTE1003, message);
IotApi.hekang_dynamic_service_apply(mContext, requestBodyBuilder, new IotNetApiCallback() {
@Override
public void onSuccess(String response) {
Log.d(TAG, "response = " + response);
Log.d(TAG, "ZTE1003 send successfully");
ParseResponseUtil parseResponseUtil = new ParseResponseUtil(mContext);
parseResponseUtil.startParse("ZTE1003", response, new DateListener() {
@Override
public void onComplate() {
Log.d(TAG, "The second position uploaded successfully");
}
@Override
public void onFailed() {
Log.d(TAG, "The second position uploaded failed");
}
});
}
@Override
public void onFailed(Exception e) {
Log.d(TAG, "ZTE1003 send failed");
}
});
}
private void initLocation(Context context) {
Log.d(TAG, "initLocation");
if (mLocationClient != null) {
mLocationClient.stopLocation();
}
mLocationClient = new AMapLocationClient(context);
mLocationClient.setLocationListener(mLocationListener);
mLocationOption = new AMapLocationClientOption();
mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
mLocationOption.setInterval(1000);
mLocationOption.setLocationCacheEnable(false);
mLocationOption.setSensorEnable(false);
AMapLocationClientOption.setOpenAlwaysScanWifi(true);
mLocationClient.setLocationOption(mLocationOption);
mLocationClient.startLocation();
}
private void openGps() {
boolean gpsEnabled = Settings.Secure.isLocationProviderEnabled(getContentResolver(), LocationManager.GPS_PROVIDER);
if (gpsEnabled) {
return;
} else {
Settings.Secure.putInt(getContentResolver(), Settings.Secure.LOCATION_MODE, 3);
}
}
private void closeGps() {
boolean gpsEnabled = Settings.Secure.isLocationProviderEnabled(getContentResolver(), LocationManager.GPS_PROVIDER);
if (gpsEnabled) {
Settings.Secure.putInt(getContentResolver(), Settings.Secure.LOCATION_MODE, 0);
} else {
return;
}
}
private void resetTheCounts() {
mErrorCount = 0;
mRequestLocationCount = 0;
mWifiAvailableErrorCount = 0;
mNetworkAvailableErrorCount = 0;
}
private void requestLocationUpdates() {
try {
mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (mLocationManager != null) {
mLocationManager.requestLocationUpdates("gps", 0, 0,
mLocListener);
}
} catch (SecurityException e) {
Log.w(TAG, "Exception: " + e.getMessage());
} catch (IllegalArgumentException e) {
Log.w(TAG, "Exception: " + e.getMessage());
}
}
public LocationListener mLocListener = new LocationListener() {
public void onLocationChanged(Location location) {
Log.v(TAG, "Enter onLocationChanged function");
}
public void onProviderDisabled(String provider) {
Log.v(TAG, "Enter onProviderDisabled function");
}
public void onProviderEnabled(String provider) {
Log.v(TAG, "Enter onProviderEnabled function");
}
public void onStatusChanged(String provider, int status, Bundle extras) {
Log.v(TAG, "Enter onStatusChanged function");
}
};
@Override
public void onDestroy() {
super.onDestroy();
}
}
package com.agenew.duardian;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public void onDestroy() {
super.onDestroy();
}
}
package com.agenew.duardian;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.telephony.TelephonyManager;
import android.util.Log;
public class SimStateReceive extends BroadcastReceiver {
private final static String ACTION_SIM_STATE_CHANGED = "android.intent.action.SIM_STATE_CHANGED";
private final static int SIM_VALID = 0;
private final static int SIM_INVALID = 1;
private int simState = SIM_INVALID;
private final static String TAG = "Duardian";
public int getSimState() {
return simState;
}
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(ACTION_SIM_STATE_CHANGED)) {
TelephonyManager tm = (TelephonyManager) context
.getSystemService(Service.TELEPHONY_SERVICE);
int state = tm.getSimState();
switch (state) {
case TelephonyManager.SIM_STATE_READY:
new Handler().postDelayed(new Runnable() {
public void run() {
Intent workIntent = new Intent(context, WorkService.class);
context.startService(workIntent);
}
}, 5000);
simState = SIM_VALID;
break;
case TelephonyManager.SIM_STATE_UNKNOWN:
Log.w(TAG, "SIM status is changed to SIM_STATE_UNKNOWN");
break;
case TelephonyManager.SIM_STATE_ABSENT:
Log.w(TAG, "SIM status is changed to SIM_STATE_ABSENT");
break;
case TelephonyManager.SIM_STATE_PIN_REQUIRED:
Log.w(TAG, "SIM status is changed to SIM_STATE_PIN_REQUIRED");
break;
case TelephonyManager.SIM_STATE_PUK_REQUIRED:
Log.w(TAG, "SIM status is changed to SIM_STATE_PUK_REQUIRED");
break;
case TelephonyManager.SIM_STATE_NETWORK_LOCKED:
Log.w(TAG, "SIM status is changed to SIM_STATE_NETWORK_LOCKED");
break;
default:
Log.w(TAG, "SIM status is Invailed");
simState = SIM_INVALID;
break;
}
}
}
}
package com.agenew.duardian;
import android.app.Service;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.widget.Toast;
import com.agenew.duardian.allinterface.DateListener;
import com.agenew.duardian.api.IotApi;
import com.agenew.duardian.provider.PostServiceApply;
import com.agenew.duardian.util.PhoneUtils;
import com.agenew.duardian.util.PreferencesUtil;
public class WorkService extends Service {
private final String TAG = "WorkService";
private final int zte2200Msg = 2200;
private final int zte2100Msg = 2100;
private final int zte1000Msg = 1000;
private final int sendMmsMsg = 1;
private Handler handler;
private Context mContext;
private PostServiceApply mPost;
public WorkService() {
}
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
}
@Override
public void onCreate() {
mContext = getApplicationContext();
IotApi.init();
mPost = new PostServiceApply(mContext);
HandlerInit();
super.onCreate();
}
private boolean prepareWork() {
boolean judge = true;
if (!PhoneUtils.ishasSimCard(mContext)) {
judge = false;
Log.d(TAG, "The phone does not have a sim card");
return judge;
}
if (PhoneUtils.IsAirModeOn(mContext)) {
judge = false;
Log.d(TAG, "AirMode on");
return judge;
}
if (PreferencesUtil.getOpenAccountStatus(mContext)) {
if (PhoneUtils.isSamePhoneNum(mContext)) {
judge = false;
Log.d(TAG, "You have already opened an account. You don't have to do it again");
} else if (PhoneUtils.isSameIccId(mContext)) {
judge = false;
Log.d(TAG, "You have already opened an account. You don't have to do it again");
} else {
judge = true;
Log.d(TAG, "Account number change, need to re-open account");
}
return judge;
}
return judge;
}
private void HandlerInit() {
HandlerThread handlerThread = new HandlerThread("http");
handlerThread.start();
handler = new HttpHandler(handlerThread.getLooper());
}
private class HttpHandler extends Handler {
public HttpHandler(Looper looper) {
super(looper);
}
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case zte2200Msg:
mPost.apiZte2200PostServiceApply(new DateListener() {
@Override
public void onComplate() {
PreferencesUtil.ZTE2200_ERROR_COUNT = 0;
handler.sendEmptyMessage(sendMmsMsg);
}
@Override
public void onFailed() {
if (PreferencesUtil.ZTE2200Retry && PreferencesUtil.ZTE2200_ERROR_COUNT < 4) {
Log.d(TAG, "ZTE2200_ERROR_COUNT = " + PreferencesUtil.ZTE2200_ERROR_COUNT);
handler.sendEmptyMessage(zte2200Msg);
} else if (PreferencesUtil.ZTE2200_ERROR_COUNT == 4) {
Log.d(TAG, "Fail times is out of count");
PreferencesUtil.ZTE2200_ERROR_COUNT = 0;
return;
}
}
});
break;
case sendMmsMsg:
mPost.prepareSendSms();
mPost.handleSendMsg();
handler.sendEmptyMessageDelayed(zte2100Msg, 63000);
break;
case zte2100Msg:
mPost.apiZte2100PostServiceApply(new DateListener() {
@Override
public void onComplate() {
PreferencesUtil.ZTE2100_ERROR_COUNT = 0;
handler.sendEmptyMessage(zte1000Msg);
}
@Override
public void onFailed() {
if (PreferencesUtil.ZTE2100Retry && PreferencesUtil.ZTE2100_ERROR_COUNT < 3) {
Log.d(TAG, "ZTE2200_ERROR_COUNT = " + PreferencesUtil.ZTE2100_ERROR_COUNT);
handler.sendEmptyMessage(zte2100Msg);
} else if (PreferencesUtil.ZTE2200_ERROR_COUNT == 3) {
Log.d(TAG, "Fail times is out of count");
PreferencesUtil.ZTE2100_ERROR_COUNT = 0;
return;
}
}
});
break;
case zte1000Msg:
mPost.apiZte1000PostServiceApply(new DateListener() {
@Override
public void onComplate() {
Toast.makeText(mContext, "开户成功", Toast.LENGTH_LONG).show();
Intent intent = new Intent("com.agenew.duardian.success");
mContext.sendBroadcastAsUser(intent, android.os.Process.myUserHandle());
Log.d(TAG, "开户成功");
}
@Override
public void onFailed() {
return;
}
});
break;
default:
break;
}
}
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
boolean isRun = prepareWork();
if (isRun) {
initResultTable();
handler.sendEmptyMessage(zte2200Msg);
if (PreferencesUtil.DBUG) {
Log.d(TAG, "WrokService is running");
}
} else {
if (PreferencesUtil.DBUG) {
Log.d(TAG, "WorkService do not need to be started");
}
}
return super.onStartCommand(intent, flags, startId);
}
private void initResultTable() {
Uri uri = Uri.parse("content://com.agenew.duardian/result");
ContentValues contentValues = new ContentValues();
contentValues.put("result", 0);
contentValues.put("iccid", "");
mContext.getContentResolver().update(uri, contentValues, "_id=1", null);
contentValues.clear();
}
}
package com.agenew.duardian.allinterface;
public interface DateListener {
public void onComplate();
public void onFailed();
}
package com.agenew.duardian.api;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
public class HttpExecutor {
private OkHttpClient mOkHttpClient;
public HttpExecutor(OkHttpClient okHttpClient) {
mOkHttpClient = okHttpClient;
}
public void get(String url, Callback callback) {
Request.Builder requestBuilder = new Request.Builder().url(url);
requestBuilder.get();
execute(requestBuilder.build(), callback);
}
public void post(String url, RequestBody requestBody, Callback callback) {
Request.Builder requestBuilder = new Request.Builder()
.url(url)
.post(requestBody);
execute(requestBuilder.build(), callback);
}
public void put(String url, RequestBody requestBody, Callback callback) {
Request.Builder requestBuilder = new Request.Builder().url(url);
requestBuilder.put(requestBody);
execute(requestBuilder.build(), callback);
}
public void delete(String url, Callback callback) {
Request.Builder requestBuilder = new Request.Builder().url(url);
requestBuilder.delete();
execute(requestBuilder.build(), callback);
}
public void delete(String url, RequestBody requestBody, Callback callback) {
Request.Builder requestBuilder = new Request.Builder().url(url);
requestBuilder.delete(requestBody);
execute(requestBuilder.build(), callback);
}
public void patch(String url, RequestBody requestBody, Callback callback) {
Request.Builder requestBuilder = new Request.Builder().url(url);
requestBuilder.patch(requestBody);
execute(requestBuilder.build(), callback);
}
public void head(String url, Callback callback) {
Request.Builder requestBuilder = new Request.Builder().url(url);
requestBuilder.head();
execute(requestBuilder.build(), callback);
}
public void execute(Request request, Callback callback) {
Call call = mOkHttpClient.newCall(request);
call.enqueue(callback);
}
}
package com.agenew.duardian.api;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.util.Log;
import com.agenew.duardian.util.PreferencesUtil;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import okhttp3.FormBody;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
public class IotApi {
public static HttpExecutor sHttpExecutor;
private static final int TIME_OUT_WRITE = 10;
private static final int TIME_OUT_READ = 10;
private static final int TIME_OUT_CONNECT = 10;
private static String TAG = "IotApi";
/**
* Init http client with token header.
*/
public static void init() {
OkHttpClient.Builder okHttpClientBuilder = new OkHttpClient.Builder()
.readTimeout(TIME_OUT_READ, TimeUnit.SECONDS)
.writeTimeout(TIME_OUT_WRITE, TimeUnit.SECONDS)
.connectTimeout(TIME_OUT_CONNECT, TimeUnit.SECONDS);
try {
MyOkHttpRetryInterceptor myOkHttpRetryInterceptor = new MyOkHttpRetryInterceptor.Builder()
.executionCount(3)
.retryInterval(1000)
.build();
okHttpClientBuilder.addInterceptor(myOkHttpRetryInterceptor);
} catch (Exception e) {
Log.d(TAG, e.toString());
}
sHttpExecutor = new HttpExecutor(okHttpClientBuilder.build());
}
/**
* Post.
*
* @param url the url
* @param requestBodyBuilder the request body string
* @param callback the callback
*/
public static void post(String url, FormBody.Builder requestBodyBuilder, IotNetApiCallback callback) {
RequestBody requestBody = requestBodyBuilder.build();
if (PreferencesUtil.DBUG) {
Log.d(TAG, "url: " + url + "requestBody = " + requestBody.toString());
}
sHttpExecutor.post(url, requestBody, new IotApiCallbackAdapter(callback));
}
/**
* Get.
*
* @param url the url
* @param callback the callback
*/
public static void get(String url, IotNetApiCallback callback) {
sHttpExecutor.get(url, new IotApiCallbackAdapter(callback));
Log.d(TAG, "get:" + url);
}
public static void hekang_service_apply(FormBody.Builder requestBodyBuilder, IotNetApiCallback callback) {
post(PreferencesUtil.HE_KANG_URI, requestBodyBuilder, callback);
}
public static void hekang_dynamic_service_apply(Context context, FormBody.Builder requestBodyBuilder, IotNetApiCallback callback) {
String tempUrl = "";
Uri uri = Uri.parse("content://com.agenew.duardian/zte2100");
Cursor zte2100Cursor = context.getContentResolver().query(uri, new String[]{"mobSite"}, "_id=1", null, null);
if (zte2100Cursor != null) {
while (zte2100Cursor.moveToNext()) {
tempUrl = zte2100Cursor.getString(zte2100Cursor.getColumnIndex("mobSite"));
}
zte2100Cursor.close();
}
if (tempUrl != null && !"".equals(tempUrl)) {
String dynamicUrl = tempUrl + "/s";
post(dynamicUrl, requestBodyBuilder, callback);
Log.d(TAG, "Using dynamic service url");
}else {
post(PreferencesUtil.HE_KANG_URI, requestBodyBuilder, callback);
}
}
private static Interceptor sTokenInterceptor = new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request.Builder builder = chain.request().newBuilder();
return chain.proceed(builder.build());
}
};
}
package com.agenew.duardian.api;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import com.agenew.duardian.util.PreferencesUtil;
import java.io.IOException;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;
import okhttp3.ResponseBody;
/**
* The type Iot api callback adapter.
* extend from okttp3.
*/
class IotApiCallbackAdapter implements Callback {
private static final int MSG_SUCCESS = 0;
private static final int MSG_FAILED = 1;
private IotNetApiCallback mIotNetApiCallback;
private Handler mHandler = new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MSG_SUCCESS:
if (mIotNetApiCallback != null) {
Bundle b = msg.getData();
String response = b.getString("response");
if (PreferencesUtil.DBUG) {
Log.d("Iot", "response: " + response);
}
try {
mIotNetApiCallback.onSuccess(response);
} catch (Exception e) {
Log.d("Iot", e.toString());
}
}
break;
case MSG_FAILED:
if (mIotNetApiCallback != null) {
Bundle b = msg.getData();
Exception e = (Exception) b.getSerializable("exception");
mIotNetApiCallback.onFailed(e);
if (PreferencesUtil.DBUG) {
Log.d("Iot", "response failed exception: " + e.toString());
}
}
break;
}
}
};
public IotApiCallbackAdapter(IotNetApiCallback iotNetApiCallback) {
mIotNetApiCallback = iotNetApiCallback;
}
@Override
public void onFailure(Call call, final IOException e) {
sendFailedMessage(e);
}
@Override
public void onResponse(Call call, Response response) throws IOException {
if (response.isSuccessful()) {
ResponseBody responseBody = response.body();
String responseString = responseBody.string();
sendSuccessMessage(responseString);
} else {
sendFailedMessage(new Exception(response.toString()));
}
}
private void sendSuccessMessage(String response) {
Message msg = mHandler.obtainMessage(MSG_SUCCESS);
Bundle b = new Bundle();
b.putString("response", response);
Log.d("response", response);
msg.setData(b);
mHandler.sendMessage(msg);
}
private void sendFailedMessage(Exception e) {
Message msg = mHandler.obtainMessage(MSG_FAILED);
Bundle b = new Bundle();
b.putSerializable("exception", e);
msg.setData(b);
mHandler.sendMessage(msg);
}
}
package com.agenew.duardian.api;
public interface IotNetApiCallback {
/**
* Called when the HTTP response code was 2xx.
*/
void onSuccess(String response);
/**
* Called when the request could not be executed due to cancellation, a connectivity problem,
* timeout or the HTTP response code was not 2xx.
*/
void onFailed(Exception e);
}
package com.agenew.duardian.api;
import java.io.IOException;
import java.io.InterruptedIOException;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
public class MyOkHttpRetryInterceptor implements Interceptor {
public int executionCount;//最大重试次数
private long retryInterval;//重试的间隔
MyOkHttpRetryInterceptor(Builder builder) {
this.executionCount = builder.executionCount;
this.retryInterval = builder.retryInterval;
}
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
Response response = doRequest(chain, request);
int retryNum = 0;
while ((response == null || !response.isSuccessful()) && retryNum <= executionCount) {
final long nextInterval = getRetryInterval();
try {
Thread.sleep(nextInterval);
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
throw new InterruptedIOException();
}
retryNum++;
// retry the request
response = doRequest(chain, request);
}
if (response == null) {
return chain.proceed(request);
}
return response;
}
private Response doRequest(Chain chain, Request request) {
Response response = null;
try {
response = chain.proceed(request);
} catch (Exception e) {
}
return response;
}
/**
* retry间隔时间
*/
public long getRetryInterval() {
return this.retryInterval;
}
public static final class Builder {
private int executionCount;
private long retryInterval;
public Builder() {
executionCount = 3;
retryInterval = 1000;
}
public Builder executionCount(int executionCount) {
this.executionCount = executionCount;
return this;
}
public Builder retryInterval(long retryInterval) {
this.retryInterval = retryInterval;
return this;
}
public MyOkHttpRetryInterceptor build() {
return new MyOkHttpRetryInterceptor(this);
}
}
}
package com.agenew.duardian.data;
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import androidx.annotation.Nullable;
public class DbOpenHelper extends SQLiteOpenHelper {
//数据库名
private static final String DATA_BASE_NAME = "hekangduardian.db";
//数据库版本号
private static final int DATE_BASE_VERSION = 1;
//表名-ZTE2200
public static final String ZTE2200_TABLE_NAME = "zte2200";
//表名-zte2100
public static final String ZTE2100_TABLE_NAME = "zte2100";
//表名-fun00-07
public static final String FUN00_TABLE_NAME = "fun00";
public static final String FUN01_TABLE_NAME = "fun01";
public static final String FUN02_TABLE_NAME = "fun02";
public static final String FUN03_TABLE_NAME = "fun03";
public static final String FUN04_TABLE_NAME = "fun04";
public static final String FUN05_TABLE_NAME = "fun05";
public static final String FUN06_TABLE_NAME = "fun06";
public static final String FUN07_TABLE_NAME = "fun07";
public static final String RESULT_TABLE_NAME = "result";
//table-ZTE2200(四列:主键自增长、ctSMS、cmSMS、unSMS)
private final String CREATE_ZTE2200_TABLE = "create table " + ZTE2200_TABLE_NAME
+ "(_id integer primary key AUTOINCREMENT, ctSMS text, cmSMS text, unSMS text)";
//table-ZTE2100(八列:主键自增长、mobile、platNo、mobSite)
private final String CREATE_ZTE2100_TABLE = "create table " + ZTE2100_TABLE_NAME
+ "(_id integer primary key AUTOINCREMENT, mobile text, platNo text, mobSite text, chatSite text, reserve1 text, reserve2 text, reserve3 text)";
//table-fun00 - 07
private final String CREATE_FUN00_TABLE = "create table " + FUN00_TABLE_NAME
+ "(_id integer primary key AUTOINCREMENT, platNum text, mobile text)";
private final String CREATE_FUN01_TABLE = "create table " + FUN01_TABLE_NAME
+ "(_id integer primary key AUTOINCREMENT, key1 text, smsflag1 text, key2 text, smsflag2 text, key3 text, Smsflag3 text, key4 text, Smsflag4 text)";
private final String CREATE_FUN02_TABLE = "create table " + FUN02_TABLE_NAME
+ "(_id integer primary key AUTOINCREMENT, time1 text, time2 text, time3 text, time4 text, time5 text, time6 text, time7 text, time8 text)";
private final String CREATE_FUN03_TABLE = "create table " + FUN03_TABLE_NAME
+ "(_id integer primary key AUTOINCREMENT, areaid text, areaName text, type text, luLang text, rdLng text, rdLat text, isogon text, lng1 text, lat1 text, lng2 text, lat2 text, notifyNum4 text, notifyNum3 text, notifyNum2 text, notifyNum1 text, freqTime text, timeStop text, timeStart text)";
private final String CREATE_FUN04_TABLE = "create table " + FUN04_TABLE_NAME
+ "(_id integer primary key AUTOINCREMENT, xmtimestart1 text, xmtimestop1 text, xmtimestart2 text, xmtimestop2 text, xmtimestart3 text, xmtimestop3 text, xmtimestart4 text, xmtimestop4 text)";
private final String CREATE_FUN05_TABLE = "create table " + FUN05_TABLE_NAME
+ "(_id integer primary key AUTOINCREMENT, sosKey1 text, sosKey2 text, sosKey3 text, sosKey4 text, sosKey5 text)";
private final String CREATE_FUN06_TABLE = "create table " + FUN06_TABLE_NAME
+ "(_id integer primary key AUTOINCREMENT, ConTimestar1 text, ConTimestop1 text, ConTimestar2 text, ConTimestop2 text, ConTimestar3 text, ConTimestop3 text, TimeInterval text)";
private final String CREATE_FUN07_TABLE = "create table " + FUN07_TABLE_NAME
+ "(_id integer primary key AUTOINCREMENT, switch text, whiteNum1 text, whiteNum2 text, whiteNum3 text, whiteNum4 text, whiteNum5 text, whiteNum6 text)";
private final String CREATE_RESULT_TABLE = "create table " + RESULT_TABLE_NAME
+ "(_id integer primary key AUTOINCREMENT, result integer, iccid text)";
public DbOpenHelper(@Nullable Context context) {
super(context, DATA_BASE_NAME, null, DATE_BASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
sqLiteDatabase.execSQL(CREATE_ZTE2200_TABLE);
sqLiteDatabase.execSQL(CREATE_ZTE2100_TABLE);
sqLiteDatabase.execSQL(CREATE_FUN00_TABLE);
sqLiteDatabase.execSQL(CREATE_FUN01_TABLE);
sqLiteDatabase.execSQL(CREATE_FUN02_TABLE);
sqLiteDatabase.execSQL(CREATE_FUN03_TABLE);
sqLiteDatabase.execSQL(CREATE_FUN04_TABLE);
sqLiteDatabase.execSQL(CREATE_FUN05_TABLE);
sqLiteDatabase.execSQL(CREATE_FUN06_TABLE);
sqLiteDatabase.execSQL(CREATE_FUN07_TABLE);
sqLiteDatabase.execSQL(CREATE_RESULT_TABLE);
initProviderData(sqLiteDatabase);
}
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
}
//init
private void initProviderData(SQLiteDatabase sqLiteDatabase) {
sqLiteDatabase.beginTransaction();
ContentValues contentValues = new ContentValues();
contentValues.put("ctSMS", "");
contentValues.put("cmSMS", "");
contentValues.put("unSMS", "");
sqLiteDatabase.insert(DbOpenHelper.ZTE2200_TABLE_NAME, null, contentValues);
contentValues.clear();
contentValues.put("mobile", "");
contentValues.put("platNo", "");
contentValues.put("mobSite", "");
contentValues.put("chatSite", "");
contentValues.put("reserve1", "");
contentValues.put("reserve2", "");
contentValues.put("reserve3", "");
sqLiteDatabase.insert(DbOpenHelper.ZTE2100_TABLE_NAME, null, contentValues);
contentValues.clear();
contentValues.put("platNum", "");
contentValues.put("mobile", "");
sqLiteDatabase.insert(DbOpenHelper.FUN00_TABLE_NAME, null, contentValues);
contentValues.clear();
contentValues.put("key1", "");
contentValues.put("smsflag1", "");
contentValues.put("key2", "");
contentValues.put("smsflag2", "");
contentValues.put("key3", "");
contentValues.put("Smsflag3", "");
contentValues.put("key4", "");
contentValues.put("Smsflag4", "");
sqLiteDatabase.insert(DbOpenHelper.FUN01_TABLE_NAME, null, contentValues);
contentValues.clear();
contentValues.put("time1", "");
contentValues.put("time2", "");
contentValues.put("time3", "");
contentValues.put("time4", "");
contentValues.put("time5", "");
contentValues.put("time6", "");
contentValues.put("time7", "");
contentValues.put("time8", "");
sqLiteDatabase.insert(DbOpenHelper.FUN02_TABLE_NAME, null, contentValues);
contentValues.clear();
contentValues.put("areaid", "");
contentValues.put("areaName", "");
contentValues.put("type", "");
contentValues.put("luLang", "");
contentValues.put("rdLng", "");
contentValues.put("rdLat", "");
contentValues.put("isogon", "");
contentValues.put("lng1", "");
contentValues.put("lat1", "");
contentValues.put("lng2", "");
contentValues.put("lat2", "");
contentValues.put("notifyNum4", "");
contentValues.put("notifyNum3", "");
contentValues.put("notifyNum2", "");
contentValues.put("notifyNum1", "");
contentValues.put("freqTime", "");
contentValues.put("timeStop", "");
contentValues.put("timeStart", "");
sqLiteDatabase.insert(DbOpenHelper.FUN03_TABLE_NAME, null, contentValues);
contentValues.clear();
contentValues.put("xmtimestart1", "");
contentValues.put("xmtimestop1", "");
contentValues.put("xmtimestart2", "");
contentValues.put("xmtimestop2", "");
contentValues.put("xmtimestart3", "");
contentValues.put("xmtimestop3", "");
contentValues.put("xmtimestart4", "");
contentValues.put("xmtimestop4", "");
sqLiteDatabase.insert(DbOpenHelper.FUN04_TABLE_NAME, null, contentValues);
contentValues.clear();
contentValues.put("sosKey1", "");
contentValues.put("sosKey2", "");
contentValues.put("sosKey3", "");
contentValues.put("sosKey4", "");
contentValues.put("sosKey5", "");
sqLiteDatabase.insert(DbOpenHelper.FUN05_TABLE_NAME, null, contentValues);
contentValues.clear();
contentValues.put("ConTimestar1", "");
contentValues.put("ConTimestop1", "");
contentValues.put("ConTimestar2", "");
contentValues.put("ConTimestop2", "");
contentValues.put("ConTimestar3", "");
contentValues.put("ConTimestop3", "");
contentValues.put("TimeInterval", "");
sqLiteDatabase.insert(DbOpenHelper.FUN06_TABLE_NAME, null, contentValues);
contentValues.clear();
contentValues.put("switch", "");
contentValues.put("whiteNum1", "");
contentValues.put("whiteNum2", "");
contentValues.put("whiteNum3", "");
contentValues.put("whiteNum4", "");
contentValues.put("whiteNum5", "");
contentValues.put("whiteNum6", "");
sqLiteDatabase.insert(DbOpenHelper.FUN07_TABLE_NAME, null, contentValues);
contentValues.clear();
contentValues.put("result", 0);
contentValues.put("iccid", "");
sqLiteDatabase.insert(DbOpenHelper.RESULT_TABLE_NAME, null, contentValues);
contentValues.clear();
sqLiteDatabase.setTransactionSuccessful();
sqLiteDatabase.endTransaction();
}
}
package com.agenew.duardian.data;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.Context;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
public class HeKangContentProvider extends ContentProvider {
private Context context;
private SQLiteDatabase sqLiteDatabase;
public static final String AUTHORITY = "com.agenew.duardian";
public static final int ZTE2200_URI_CODE = 2200;
public static final int ZTE2100_URI_CODE = 2100;
public static final int FUN00_URI_CODE = 0;
public static final int FUN01_URI_CODE = 1;
public static final int FUN02_URI_CODE = 2;
public static final int FUN03_URI_CODE = 3;
public static final int FUN04_URI_CODE = 4;
public static final int FUN05_URI_CODE = 5;
public static final int FUN06_URI_CODE = 6;
public static final int FUN07_URI_CODE = 7;
public static final int RESULT_URI_CODE = 8;
private static final UriMatcher uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
static {
uriMatcher.addURI(AUTHORITY, DbOpenHelper.ZTE2200_TABLE_NAME, ZTE2200_URI_CODE);
uriMatcher.addURI(AUTHORITY, DbOpenHelper.ZTE2100_TABLE_NAME, ZTE2100_URI_CODE);
uriMatcher.addURI(AUTHORITY, DbOpenHelper.FUN00_TABLE_NAME, FUN00_URI_CODE);
uriMatcher.addURI(AUTHORITY, DbOpenHelper.FUN01_TABLE_NAME, FUN01_URI_CODE);
uriMatcher.addURI(AUTHORITY, DbOpenHelper.FUN02_TABLE_NAME, FUN02_URI_CODE);
uriMatcher.addURI(AUTHORITY, DbOpenHelper.FUN03_TABLE_NAME, FUN03_URI_CODE);
uriMatcher.addURI(AUTHORITY, DbOpenHelper.FUN04_TABLE_NAME, FUN04_URI_CODE);
uriMatcher.addURI(AUTHORITY, DbOpenHelper.FUN05_TABLE_NAME, FUN05_URI_CODE);
uriMatcher.addURI(AUTHORITY, DbOpenHelper.FUN06_TABLE_NAME, FUN06_URI_CODE);
uriMatcher.addURI(AUTHORITY, DbOpenHelper.FUN07_TABLE_NAME, FUN07_URI_CODE);
uriMatcher.addURI(AUTHORITY, DbOpenHelper.RESULT_TABLE_NAME, RESULT_URI_CODE);
}
public HeKangContentProvider() {
}
private String getTableName(Uri uri) {
String tableName = null;
switch (uriMatcher.match(uri)) {
case ZTE2200_URI_CODE:
tableName = DbOpenHelper.ZTE2200_TABLE_NAME;
break;
case ZTE2100_URI_CODE:
tableName = DbOpenHelper.ZTE2100_TABLE_NAME;
break;
case FUN00_URI_CODE:
tableName = DbOpenHelper.FUN00_TABLE_NAME;
break;
case FUN01_URI_CODE:
tableName = DbOpenHelper.FUN01_TABLE_NAME;
break;
case FUN02_URI_CODE:
tableName = DbOpenHelper.FUN02_TABLE_NAME;
break;
case FUN03_URI_CODE:
tableName = DbOpenHelper.FUN03_TABLE_NAME;
break;
case FUN04_URI_CODE:
tableName = DbOpenHelper.FUN04_TABLE_NAME;
break;
case FUN05_URI_CODE:
tableName = DbOpenHelper.FUN05_TABLE_NAME;
break;
case FUN06_URI_CODE:
tableName = DbOpenHelper.FUN06_TABLE_NAME;
break;
case FUN07_URI_CODE:
tableName = DbOpenHelper.FUN07_TABLE_NAME;
break;
case RESULT_URI_CODE:
tableName = DbOpenHelper.RESULT_TABLE_NAME;
break;
}
return tableName;
}
@Override
public boolean onCreate() {
// TODO: Implement this to initialize your content provider on startup.
context = getContext();
sqLiteDatabase = new DbOpenHelper(context).getWritableDatabase();
return false;
}
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
String tableName = getTableName(uri);
if (tableName == null) {
throw new IllegalArgumentException("Unsupported URI:" + uri);
}
int count = sqLiteDatabase.delete(tableName, selection, selectionArgs);
if (count > 0) {
context.getContentResolver().notifyChange(uri, null);
}
return count;
}
@Override
public String getType(Uri uri) {
return null;
}
@Override
public Uri insert(Uri uri, ContentValues values) {
String tableName = getTableName(uri);
if (tableName == null) {
throw new IllegalArgumentException("Unsupported URI:" + uri);
}
sqLiteDatabase.insert(tableName, null, values);
context.getContentResolver().notifyChange(uri, null);
return uri;
}
@Override
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
String tableName = getTableName(uri);
if (tableName == null) {
throw new IllegalArgumentException("Unsupported URI:" + uri);
}
return sqLiteDatabase.query(tableName, projection, selection, selectionArgs, sortOrder, null, null);
}
@Override
public int update(Uri uri, ContentValues values, String selection,
String[] selectionArgs) {
String tableName = getTableName(uri);
if (tableName == null) {
throw new IllegalArgumentException("Unsupported URI:" + uri);
}
int row = sqLiteDatabase.update(tableName, values, selection, selectionArgs);
if (row > 0) {
context.getContentResolver().notifyChange(uri, null);
}
return row;
}
}
package com.agenew.duardian.provider;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.util.Log;
import com.agenew.duardian.allinterface.DateListener;
import com.agenew.duardian.api.IotApi;
import com.agenew.duardian.api.IotNetApiCallback;
import com.agenew.duardian.sms.SmsUtils;
import com.agenew.duardian.util.ParseResponseUtil;
import com.agenew.duardian.util.PhoneUtils;
import com.agenew.duardian.util.PreferencesUtil;
import okhttp3.FormBody;
public class PostServiceApply {
public static final String TAG = "PostServiceApply";
Context mContext;
ParseResponseUtil mParseResponse;
ZTEContentProvider mZteContent;
public PostServiceApply(Context context) {
mContext = context.getApplicationContext();
mParseResponse = new ParseResponseUtil(mContext);
mZteContent = new ZTEContentProvider(mContext);
}
public static FormBody.Builder jsonReqContent(String actType, String content) {
FormBody.Builder requestBodyBuilder = new FormBody.Builder();
requestBodyBuilder.add(PreferencesUtil.HE_KANG_REQ_SERVER_ACTTYPE, actType);
requestBodyBuilder.add(PreferencesUtil.HE_KANG_REQ_SERVER_REQCONTENT, content);
return requestBodyBuilder;
}
public void apiZte2200PostServiceApply(DateListener listener) {
FormBody.Builder requestBodyBuilder = jsonReqContent(PreferencesUtil.HE_KANG_ZTE2200, mZteContent.getZTE2200reqContent());
IotApi.hekang_service_apply(requestBodyBuilder, new IotNetApiCallback() {
@Override
public void onSuccess(String response) {
if (PreferencesUtil.DBUG) {
Log.d(TAG, "Zte2200 send successfully and response = " + response);
}
mParseResponse.startParse("ZTE2200", response, listener);
}
@Override
public void onFailed(Exception e) {
PreferencesUtil.ZTE2200Retry = true;
PreferencesUtil.ZTE2200_ERROR_COUNT = ++PreferencesUtil.ZTE2200_ERROR_COUNT;
Log.d(TAG, "Zte2200 send failed and e = " + e.toString());
listener.onFailed();
}
});
}
public void handleSendMsg() {
String message = mZteContent.getSendMsgString();
SmsUtils.sendSMS(PreferencesUtil.KeyPhoneNum, message, mContext);
}
public void apiZte2100PostServiceApply(DateListener listener) {
FormBody.Builder requestBodyBuilder = jsonReqContent(PreferencesUtil.HE_KANG_ZTE2100, mZteContent.getZTE2100reqContent());
IotApi.hekang_service_apply(requestBodyBuilder, new IotNetApiCallback() {
@Override
public void onSuccess(String response) {
if (PreferencesUtil.DBUG) {
Log.d(TAG, "Zte2100 send successfully and response =" + response);
}
mParseResponse.startParse("ZTE2100", response, listener);
}
@Override
public void onFailed(Exception e) {
PreferencesUtil.ZTE2100Retry = true;
PreferencesUtil.ZTE2100_ERROR_COUNT = ++PreferencesUtil.ZTE2100_ERROR_COUNT;
Log.d(TAG, "Zte2100 send error and e = " + e.toString() + "errorTimes = " + PreferencesUtil.ZTE2100_ERROR_COUNT);
}
});
}
public void apiZte1000PostServiceApply(DateListener listener) {
FormBody.Builder requestBodyBuilder = jsonReqContent(PreferencesUtil.HE_KANG_ZTE1000, mZteContent.getZTE1000reqContent());
IotApi.hekang_dynamic_service_apply(mContext , requestBodyBuilder, new IotNetApiCallback() {
@Override
public void onSuccess(String response) {
if (PreferencesUtil.DBUG) {
Log.d(TAG, "ZTE1000 send successfully and response = " + response);
}
mParseResponse.startParse("ZTE1000", response, listener);
}
@Override
public void onFailed(Exception e) {
Log.d(TAG, "Zte1000 send error and e = " + e.toString());
}
});
}
public void apiZte1003PostServiceApply(DateListener listener) {
FormBody.Builder requestBodyBuilder = jsonReqContent(PreferencesUtil.HE_KANG_ZTE1003, mZteContent.getZTE1003reqContent());
IotApi.hekang_dynamic_service_apply(mContext, requestBodyBuilder, new IotNetApiCallback() {
@Override
public void onSuccess(String response) {
if (PreferencesUtil.DBUG) {
Log.d(TAG, "ZTE1003 send successfully and response = " + response);
}
mParseResponse.startParse("ZTE1003", response, listener);
}
@Override
public void onFailed(Exception e) {
Log.d(TAG, "Zte1000 send error and e = " + e.toString());
}
});
}
public void prepareSendSms() {
String providerName = PhoneUtils.getProvidersName(mContext);
String cmPhoneNum = "";
String ctPhoneNum = "";
String unPhoneNum = "";
Uri uri = Uri.parse("content://com.agenew.duardian/zte2200");
Cursor zte2200Cursor = mContext.getContentResolver().query(uri, new String[]{"_id", "ctSMS", "cmSMS", "unSMS"}, null, null, null);
while (zte2200Cursor.moveToNext()) {
cmPhoneNum = PreferencesUtil.KeyPhoneNum = zte2200Cursor.getString(zte2200Cursor.getColumnIndex("cmSMS"));
ctPhoneNum = PreferencesUtil.KeyPhoneNum = zte2200Cursor.getString(zte2200Cursor.getColumnIndex("ctSMS"));
unPhoneNum = PreferencesUtil.KeyPhoneNum = zte2200Cursor.getString(zte2200Cursor.getColumnIndex("unSMS"));
}
if ("CM".equals(providerName)) {
PreferencesUtil.KeyPhoneNum = cmPhoneNum;
} else if ("CT".equals(providerName)) {
PreferencesUtil.KeyPhoneNum = ctPhoneNum;
} else if ("UN".equals(providerName)) {
PreferencesUtil.KeyPhoneNum = unPhoneNum;
} else {
if (PreferencesUtil.DBUG) {
Log.d(TAG, "sim providersName is illegal");
}
}
zte2200Cursor.close();
if (PreferencesUtil.DBUG) {
Log.d(TAG, "providerName = " + providerName + " KeyPhonenum = " + PreferencesUtil.KeyPhoneNum);
}
}
}
package com.agenew.duardian.provider;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.util.Log;
import com.agenew.duardian.util.PhoneUtils;
import com.agenew.duardian.util.PreferencesUtil;
public class ZTEContentProvider {
public final String TAG = "ZTEContentUtil";
public String ver = "HK.MC1702.V01";
public Context mContext;
public ZTEContentProvider(Context context) {
mContext = context;
}
public String getZTE2200reqContent() {
StringBuilder content = new StringBuilder();
content.append("10005");
content.append('|');
content.append(ver);
content.append('|');
content.append(PhoneUtils.getIccId(mContext));
content.append('|');
content.append(PhoneUtils.getImei(mContext));
if (PreferencesUtil.DBUG) {
Log.d(TAG, "zte2200 : " + "" + content);
}
return "" + content;
}
public String getZTE2100reqContent() {
StringBuilder content = new StringBuilder();
content.append("10005");
content.append('|');
content.append(ver);
content.append('|');
content.append(PhoneUtils.getIccId(mContext));
content.append('|');
content.append(PhoneUtils.getImei(mContext));
if (PreferencesUtil.DBUG) {
Log.d(TAG, "zte2100 : " + "" + content);
}
return "" + content;
}
public String getZTE1000reqContent() {
StringBuilder content = new StringBuilder();
String phoneNum = "";
Uri uri = Uri.parse("content://com.agenew.duardian/zte2100");
Cursor zte2100Cursor = mContext.getContentResolver().query(uri, new String[]{"mobile"}, null, null, null);
while (zte2100Cursor.moveToNext()) {
phoneNum = zte2100Cursor.getString(zte2100Cursor.getColumnIndex("mobile"));
}
if (phoneNum != null && !"".equals(phoneNum)) {
content.append(phoneNum);
} else if (PhoneUtils.getNativePhoneNumber(mContext) != null && !"".equals(PhoneUtils.getNativePhoneNumber(mContext))) {
phoneNum = PhoneUtils.getNativePhoneNumber(mContext);
content.append(phoneNum);
}else {
content.append("00000000000");
}
Log.d(TAG, "PhoneNum = " + phoneNum);
zte2100Cursor.close();
content.append('|');
content.append("10003");
content.append('|');
content.append("00");
if (PreferencesUtil.DBUG) {
Log.d(TAG, "zte1000 : " + "" + content);
}
return "" + content;
}
public String getZTE1003reqContent() {
StringBuilder content = new StringBuilder();
String phoneNum = "";
Uri uri = Uri.parse("content://com.agenew.duardian/zte2100");
Cursor zte2100Cursor = mContext.getContentResolver().query(uri, new String[]{"mobile"}, null, null, null);
while (zte2100Cursor.moveToNext()) {
phoneNum = zte2100Cursor.getString(zte2100Cursor.getColumnIndex("mobile"));
}
if (phoneNum != null && !"".equals(phoneNum)) {
content.append(phoneNum);
} else if (PhoneUtils.getNativePhoneNumber(mContext) != null && !"".equals(PhoneUtils.getNativePhoneNumber(mContext))) {
phoneNum = PhoneUtils.getNativePhoneNumber(mContext);
content.append(phoneNum);
}
Log.d(TAG, "PhoneNum = " + phoneNum);
zte2100Cursor.close();
content.append('|');
content.append("10003");
content.append('|');
content.append(PreferencesUtil.HE_KANG_VERSION);
content.append('|');
content.append("0");
content.append('|');
content.append("0");
content.append('|');
content.append("1");
content.append('|');
content.append(PhoneUtils.getMcc(mContext));
content.append('|');
content.append(PhoneUtils.getMnc(mContext));
content.append('|');
content.append(PhoneUtils.getLAC(mContext));
content.append('|');
content.append(PhoneUtils.getCID(mContext));
content.append('|');
content.append('0');
content.append("|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0");
if (PreferencesUtil.DBUG) {
Log.d(TAG, "zte1003 : " + "" + content);
}
return "" + content;
}
public String getSendMsgString() {
StringBuilder message = new StringBuilder();
message.append("ZTEKH");
message.append(ver);
message.append("ZTEKH");
message.append(PhoneUtils.getIccId(mContext));
message.append("ZTEKH");
message.append(PhoneUtils.getImei(mContext));
if (PreferencesUtil.DBUG) {
Log.d(TAG, "SendMsg : " + "" + message);
}
return "" + message;
}
}
package com.agenew.duardian.sms;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.SmsManager;
import android.util.Log;
import com.agenew.duardian.util.PreferencesUtil;
public class SMSSendResultReceiver extends BroadcastReceiver {
private final String TAG = "SMSSendResultReceiver";
@Override
public void onReceive(Context context, Intent intent) {
// TODO: This method is called when the BroadcastReceiver is receiving
// an Intent broadcast.
if (SmsUtils.SENT_SMS_ACTION.equals(intent.getAction())) {
switch (getResultCode()) {
case Activity.RESULT_OK:
if (PreferencesUtil.DBUG) {
Log.d(TAG, "Successfully sent SMS");
}
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
case SmsManager.RESULT_ERROR_RADIO_OFF:
case SmsManager.RESULT_ERROR_NULL_PDU:
default:
if (PreferencesUtil.DBUG) {
Log.d(TAG, "Failed to send SMS");
}
break;
}
}
}
}
package com.agenew.duardian.sms;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import com.agenew.duardian.LocationService;
import com.agenew.duardian.allinterface.DateListener;
import com.agenew.duardian.provider.PostServiceApply;
import com.agenew.duardian.util.PreferencesUtil;
public class SmsLocationReceiver extends BroadcastReceiver {
private final String TAG = "SmsLocationReceiver";
private final String HEKANG_LOCATION_ACTION = "com.agenew.duardian.location";
public SmsLocationReceiver() {
}
@Override
public void onReceive(Context context, Intent intent) {
// an Intent broadcast.
if (intent == null) {
return;
}
String action = intent.getAction();
if (HEKANG_LOCATION_ACTION.equals(action)) {
if (PreferencesUtil.getOpenAccountStatus(context)) {
PostServiceApply mPost;
mPost = new PostServiceApply(context);
mPost.apiZte1003PostServiceApply(new DateListener() {
@Override
public void onComplate() {
Log.d(TAG, "The first position uploaded successfully");
}
@Override
public void onFailed() {
Log.d(TAG, "The first position uploaded failed");
}
});
Intent locationIntent = new Intent(context, LocationService.class);
context.startService(locationIntent);
}
}
}
}
package com.agenew.duardian.sms;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import com.agenew.duardian.allinterface.DateListener;
import com.agenew.duardian.provider.PostServiceApply;
import com.agenew.duardian.util.PreferencesUtil;
public class SmsUpdateReceiver extends BroadcastReceiver {
private final String TAG = "SmsUpdateReceiver";
private final String HEKANG_UPDATE_ACTION = "com.agenew.duardian.update";
public SmsUpdateReceiver() {
}
@Override
public void onReceive(Context context, Intent intent) {
// an Intent broadcast.
if (intent == null) {
return;
}
String action = intent.getAction();
if (HEKANG_UPDATE_ACTION.equals(action)) {
if (PreferencesUtil.getOpenAccountStatus(context)) {
PostServiceApply mPost;
mPost = new PostServiceApply(context);
mPost.apiZte1000PostServiceApply(new DateListener() {
@Override
public void onComplate() {
Intent intent = new Intent("com.agenew.duardian.success");
context.sendBroadcastAsUser(intent, android.os.Process.myUserHandle());
Log.d(TAG, "Successfully updated platform data");
}
@Override
public void onFailed() {
Log.d(TAG, "Failed to update platform data");
}
});
}
}
}
}
package com.agenew.duardian.sms;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.telephony.SmsMessage;
import android.util.Log;
import com.agenew.duardian.util.PreferencesUtil;
import java.util.List;
public class SmsUtils {
public static final String TAG = "SmsUtils";
public static final String SENT_SMS_ACTION = "hekang_sms_send_action";
public static SmsMessage[] getMessagesFromIntent(Intent intent) {
Object[] messages = (Object[]) intent.getSerializableExtra("pdus");
if (messages == null) {
return null;
}
final int pduCount = messages.length;
SmsMessage[] msgs = new SmsMessage[pduCount];
try {
for (int i = 0; i < pduCount; i++) {
msgs[i] = SmsMessage.createFromPdu((byte[]) messages[i]);
}
} catch (Throwable e) {
return null;
}
return msgs;
}
public static void sendSMS(String phoneNumber, String message, Context context) {
if (phoneNumber == null || "".equals(phoneNumber) || "".equals(message) || message == null) {
if (PreferencesUtil.DBUG) {
Log.d(TAG, "phoneNumber or message is null");
}
return;
}
android.telephony.SmsManager smsManager = android.telephony.SmsManager.getDefault();
List<String> divideContents = smsManager.divideMessage(message);
Intent itSend = new Intent(SENT_SMS_ACTION);
PendingIntent sentPI = PendingIntent.getBroadcast(context, 0, itSend, PendingIntent.FLAG_UPDATE_CURRENT);
for (String text : divideContents) {
smsManager.sendTextMessage(phoneNumber, null, text, sentPI, null);
}
}
}
package com.agenew.duardian.util;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.util.Log;
import com.agenew.duardian.allinterface.DateListener;
public class ParseResponseUtil {
private final String TAG = "ParseResponseUtil";
private Context mContext;
public ParseResponseUtil(Context context) {
mContext = context;
}
public void startParse(String zte, String response, DateListener listener) {
String newResponse = trimResponse(response);
switch (zte) {
case "ZTE2200":
parseZTE2200Response(newResponse, listener);
break;
case "ZTE2100":
parseZTE2100Response(newResponse, listener);
break;
case "ZTE1000":
parseZTE1000Response(newResponse, listener);
break;
case "ZTE1003":
parseZTE1003Response(newResponse, listener);
break;
default:
return;
}
}
public void parseZTE2200Response(String response, DateListener listener) {
String resultType, respCode;
String[] strarray = response.split("[|]");
resultType = strarray[0];
respCode = strarray[2];
if ("0".equals(respCode) && "ZTE2200".equals(resultType)) {
PreferencesUtil.ZTE2200Retry = false;
Uri uri = Uri.parse("content://com.agenew.duardian/zte2200");
ContentValues contentValues = new ContentValues();
contentValues.put("ctSMS", strarray[3]);
contentValues.put("cmSMS", strarray[4]);
contentValues.put("unSMS", strarray[5]);
mContext.getContentResolver().update(uri, contentValues, "_id=1", null);
Cursor zte2200Cursor = mContext.getContentResolver().query(uri, new String[]{"_id", "ctSMS", "cmSMS", "unSMS"}, null, null, null);
if (zte2200Cursor != null) {
while (zte2200Cursor.moveToNext()) {
Log.d(TAG, "ID:" + zte2200Cursor.getInt(zte2200Cursor.getColumnIndex("_id"))
+ " ctSMS:" + zte2200Cursor.getString(zte2200Cursor.getColumnIndex("ctSMS"))
+ " cmSMS" + zte2200Cursor.getString(zte2200Cursor.getColumnIndex("cmSMS"))
+ " unSMS" + zte2200Cursor.getString(zte2200Cursor.getColumnIndex("unSMS")));
}
zte2200Cursor.close();
}
contentValues.clear();
if (PreferencesUtil.DBUG) {
Log.d(TAG, "ctSMS:" + strarray[3] + "cmSMS:" + strarray[4] + "unSMS:" + strarray[5]);
}
listener.onComplate();
} else {
PreferencesUtil.ZTE2200Retry = true;
PreferencesUtil.ZTE2200_ERROR_COUNT = ++PreferencesUtil.ZTE2200_ERROR_COUNT;
if (PreferencesUtil.DBUG) {
Log.d(TAG, "ZTE2200 response illegal");
}
listener.onFailed();
}
}
public void parseZTE2100Response(String response, DateListener listener) {
String resultType, respCode;
String[] strarray = response.split("[|]");
resultType = strarray[0];
respCode = strarray[2];
if ("0".equals(respCode) && "ZTE2100".equals(resultType)) {
PreferencesUtil.ZTE2100Retry = false;
Uri uri = Uri.parse("content://com.agenew.duardian/zte2100");
ContentValues contentValues = new ContentValues();
contentValues.put("mobile", strarray[3]);
contentValues.put("platNo", strarray[4]);
contentValues.put("mobSite", strarray[5]);
contentValues.put("chatSite", strarray[6]);
contentValues.put("reserve1", strarray[7]);
contentValues.put("reserve2", strarray[8]);
contentValues.put("reserve3", strarray[9]);
mContext.getContentResolver().update(uri, contentValues, "_id=1", null);
Cursor zte2100Cursor = mContext.getContentResolver().query(uri, new String[]{"_id", "mobile", "platNo", "mobSite"}, null, null, null);
if (zte2100Cursor != null) {
while (zte2100Cursor.moveToNext()) {
Log.d(TAG, "ID:" + zte2100Cursor.getInt(zte2100Cursor.getColumnIndex("_id"))
+ " mobile:" + zte2100Cursor.getString(zte2100Cursor.getColumnIndex("mobile"))
+ " platNo" + zte2100Cursor.getString(zte2100Cursor.getColumnIndex("platNo"))
+ " mobSite" + zte2100Cursor.getString(zte2100Cursor.getColumnIndex("mobSite")));
}
zte2100Cursor.close();
}
contentValues.clear();
listener.onComplate();
} else {
PreferencesUtil.ZTE2100Retry = true;
PreferencesUtil.ZTE2100_ERROR_COUNT++;
if (PreferencesUtil.DBUG) {
Log.d(TAG, "ZTE2100 response illegal");
}
listener.onFailed();
}
}
public void parseZTE1000Response(String response, DateListener listener) {
String resultType, respCode;
String[] whole = response.split("[,]");
String mainbranch = whole[0];
String[] validation = mainbranch.split("[|]");
resultType = validation[0];
respCode = validation[2];
if ("0".equals(respCode) && "ZTE1000".equals(resultType)) {
Uri uri = Uri.parse("content://com.agenew.duardian/result");
ContentValues contentValues = new ContentValues();
contentValues.put("result", 1);
contentValues.put("iccid", PhoneUtils.getIccId(mContext));
mContext.getContentResolver().update(uri, contentValues, "_id=1", null);
Cursor ResultCursor = mContext.getContentResolver().query(uri, new String[]{"_id", "result"}, null, null, null);
if (ResultCursor != null) {
while (ResultCursor.moveToNext()) {
Log.d(TAG, "result:" + ResultCursor.getInt(ResultCursor.getColumnIndex("result")));
}
ResultCursor.close();
}
contentValues.clear();
int length = whole.length;
for (int i = 1; i < length; i++) {
Log.d(TAG, i + "begin");
String otherbranch = whole[i];
String[] funcarray = customSplit(otherbranch);
parseFuncString(funcarray);
Log.d(TAG, i + "end" + " funcarray = " + funcarray.toString());
}
listener.onComplate();
} else {
listener.onFailed();
}
}
public void parseZTE1003Response(String response, DateListener listener) {
String resultType, respCode;
String[] strarray = response.split("[|]");
resultType = strarray[0];
respCode = strarray[2];
if ("0".equals(respCode) && "ZTE1003".equals(resultType)) {
listener.onComplate();
if (PreferencesUtil.DBUG) {
Log.d(TAG, "Location message returned successfully");
}
} else {
listener.onFailed();
}
}
public void parseFuncString(String[] funcarray) {
switch (funcarray[0]) {
case "00":
Uri uri0 = Uri.parse("content://com.agenew.duardian/fun00");
ContentValues contentValue0 = new ContentValues();
contentValue0.put("platNum", funcarray[1]);
contentValue0.put("mobile", funcarray[2]);
mContext.getContentResolver().update(uri0, contentValue0, "_id=1", null);
Cursor fun00Cursor = mContext.getContentResolver().query(uri0, new String[]{"_id", "platNum", "mobile"}, null, null, null);
if (fun00Cursor != null) {
while (fun00Cursor.moveToNext()) {
Log.d(TAG, "ID:" + fun00Cursor.getInt(fun00Cursor.getColumnIndex("_id"))
+ " platNum:" + fun00Cursor.getString(fun00Cursor.getColumnIndex("platNum"))
+ " mobile" + fun00Cursor.getString(fun00Cursor.getColumnIndex("mobile")));
}
fun00Cursor.close();
}
contentValue0.clear();
break;
case "01":
Uri uri1 = Uri.parse("content://com.agenew.duardian/fun01");
ContentValues contentValue1 = new ContentValues();
contentValue1.put("key1", funcarray[1]);
contentValue1.put("smsflag1", funcarray[2]);
contentValue1.put("key2", funcarray[3]);
contentValue1.put("smsflag2", funcarray[4]);
contentValue1.put("key3", funcarray[5]);
contentValue1.put("Smsflag3", funcarray[6]);
contentValue1.put("key4", funcarray[7]);
contentValue1.put("Smsflag3", funcarray[8]);
mContext.getContentResolver().update(uri1, contentValue1, "_id=1", null);
Cursor fun01Cursor = mContext.getContentResolver().query(uri1, new String[]{"_id", "key1", "smsflag1", "key2", "smsflag2"}, null, null, null);
if (fun01Cursor != null) {
while (fun01Cursor.moveToNext()) {
Log.d(TAG, "ID:" + fun01Cursor.getInt(fun01Cursor.getColumnIndex("_id"))
+ " key1:" + fun01Cursor.getString(fun01Cursor.getColumnIndex("key1"))
+ " smsflag1" + fun01Cursor.getString(fun01Cursor.getColumnIndex("smsflag1"))
+ " key2" + fun01Cursor.getString(fun01Cursor.getColumnIndex("key2"))
+ " smsflag2" + fun01Cursor.getString(fun01Cursor.getColumnIndex("smsflag2")));
}
fun01Cursor.close();
}
contentValue1.clear();
break;
case "02":
Uri uri2 = Uri.parse("content://com.agenew.duardian/fun02");
ContentValues contentValue2 = new ContentValues();
contentValue2.put("time1", funcarray[1]);
contentValue2.put("time2", funcarray[2]);
contentValue2.put("time3", funcarray[3]);
contentValue2.put("time4", funcarray[4]);
contentValue2.put("time5", funcarray[5]);
contentValue2.put("time6", funcarray[6]);
contentValue2.put("time7", funcarray[7]);
contentValue2.put("time8", funcarray[8]);
mContext.getContentResolver().update(uri2, contentValue2, "_id=1", null);
Cursor fun02Cursor = mContext.getContentResolver().query(uri2, new String[]{"_id", "time1", "time2", "time3", "time4"}, null, null, null);
if (fun02Cursor != null) {
while (fun02Cursor.moveToNext()) {
Log.d(TAG, "ID:" + fun02Cursor.getInt(fun02Cursor.getColumnIndex("_id"))
+ " time1:" + fun02Cursor.getString(fun02Cursor.getColumnIndex("time1"))
+ " time2:" + fun02Cursor.getString(fun02Cursor.getColumnIndex("time2"))
+ " time3:" + fun02Cursor.getString(fun02Cursor.getColumnIndex("time3"))
+ " time4:" + fun02Cursor.getString(fun02Cursor.getColumnIndex("time4")));
}
fun02Cursor.close();
}
contentValue2.clear();
break;
case "03":
int funclenth = funcarray.length;
Uri uri3 = Uri.parse("content://com.agenew.duardian/fun03");
ContentValues contentValue3 = new ContentValues();
contentValue3.put("areaid", funcarray[1]);
contentValue3.put("areaName", funcarray[2]);
contentValue3.put("type", funcarray[3]);
contentValue3.put("luLang", funcarray[4]);
contentValue3.put("rdLng", funcarray[5]);
contentValue3.put("rdLat", funcarray[6]);
contentValue3.put("isogon", funcarray[7]);
contentValue3.put("lng1", funcarray[8]);
contentValue3.put("lat1", funcarray[9]);
contentValue3.put("lng2", funcarray[10]);
contentValue3.put("lat2", funcarray[11]);
Log.d(TAG, "func lenth = " + funclenth + "");
contentValue3.put("notifyNum4", funcarray[funclenth - 1]);
contentValue3.put("notifyNum3", funcarray[funclenth - 2]);
contentValue3.put("notifyNum2", funcarray[funclenth - 3]);
contentValue3.put("notifyNum1", funcarray[funclenth - 4]);
contentValue3.put("freqTime", funcarray[funclenth - 5]);
contentValue3.put("timeStop", funcarray[funclenth - 6]);
contentValue3.put("timeStart", funcarray[funclenth - 7]);
mContext.getContentResolver().update(uri3, contentValue3, "_id=1", null);
Cursor fun03Cursor = mContext.getContentResolver().query(uri3, new String[]{"_id", "areaid", "areaName", "type", "luLang"}, null, null, null);
if (fun03Cursor != null) {
while (fun03Cursor.moveToNext()) {
Log.d(TAG, "ID:" + fun03Cursor.getInt(fun03Cursor.getColumnIndex("_id"))
+ " areaid:" + fun03Cursor.getString(fun03Cursor.getColumnIndex("areaid"))
+ " areaName" + fun03Cursor.getString(fun03Cursor.getColumnIndex("areaName"))
+ " type" + fun03Cursor.getString(fun03Cursor.getColumnIndex("type"))
+ " luLang" + fun03Cursor.getString(fun03Cursor.getColumnIndex("luLang")));
}
fun03Cursor.close();
}
contentValue3.clear();
break;
case "04": //No disturbing function settings
Uri uri4 = Uri.parse("content://com.agenew.duardian/fun04");
ContentValues contentValue4 = new ContentValues();
contentValue4.put("xmtimestart1", funcarray[1]);
contentValue4.put("xmtimestop1", funcarray[2]);
contentValue4.put("xmtimestart2", funcarray[3]);
contentValue4.put("xmtimestop2", funcarray[4]);
contentValue4.put("xmtimestart3", funcarray[5]);
contentValue4.put("xmtimestop3", funcarray[6]);
contentValue4.put("xmtimestart4", funcarray[7]);
contentValue4.put("xmtimestop4", funcarray[8]);
mContext.getContentResolver().update(uri4, contentValue4, "_id=1", null);
Cursor fun04Cursor = mContext.getContentResolver().query(uri4, new String[]{"_id", "xmtimestart1", "xmtimestop1", "xmtimestart2", "xmtimestop2"}, null, null, null);
if (fun04Cursor != null) {
while (fun04Cursor.moveToNext()) {
Log.d(TAG, "ID:" + fun04Cursor.getInt(fun04Cursor.getColumnIndex("_id"))
+ " xmtimestart1:" + fun04Cursor.getString(fun04Cursor.getColumnIndex("xmtimestart1"))
+ " xmtimestop1:" + fun04Cursor.getString(fun04Cursor.getColumnIndex("xmtimestop1"))
+ " xmtimestart2:" + fun04Cursor.getString(fun04Cursor.getColumnIndex("xmtimestart2"))
+ " xmtimestop2:" + fun04Cursor.getString(fun04Cursor.getColumnIndex("xmtimestop2")));
}
fun04Cursor.close();
}
contentValue4.clear();
break;
case "05": //SOS key settings
Uri uri5 = Uri.parse("content://com.agenew.duardian/fun05");
ContentValues contentValue5 = new ContentValues();
contentValue5.put("sosKey1", funcarray[1]);
contentValue5.put("sosKey2", funcarray[2]);
contentValue5.put("sosKey3", funcarray[3]);
contentValue5.put("sosKey4", funcarray[4]);
contentValue5.put("sosKey5", funcarray[5]);
mContext.getContentResolver().update(uri5, contentValue5, "_id=1", null);
Cursor fun05Cursor = mContext.getContentResolver().query(uri5, new String[]{"_id", "sosKey1", "sosKey2", "sosKey3", "sosKey4"}, null, null, null);
if (fun05Cursor != null) {
while (fun05Cursor.moveToNext()) {
Log.d(TAG, "ID:" + fun05Cursor.getInt(fun05Cursor.getColumnIndex("_id"))
+ " sosKey1:" + fun05Cursor.getString(fun05Cursor.getColumnIndex("sosKey1"))
+ " sosKey2:" + fun05Cursor.getString(fun05Cursor.getColumnIndex("sosKey2"))
+ " sosKey3:" + fun05Cursor.getString(fun05Cursor.getColumnIndex("sosKey3"))
+ " sosKey4:" + fun05Cursor.getString(fun05Cursor.getColumnIndex("sosKey4")));
}
fun05Cursor.close();
}
contentValue5.clear();
break;
case "06": //Continuous positioning settings
Uri uri6 = Uri.parse("content://com.agenew.duardian/fun06");
ContentValues contentValue6 = new ContentValues();
contentValue6.put("ConTimestar1", funcarray[1]);
contentValue6.put("ConTimestop1", funcarray[2]);
contentValue6.put("ConTimestar2", funcarray[3]);
contentValue6.put("ConTimestop2", funcarray[4]);
contentValue6.put("ConTimestar3", funcarray[5]);
contentValue6.put("ConTimestop3", funcarray[6]);
contentValue6.put("TimeInterval", funcarray[7]);
mContext.getContentResolver().update(uri6, contentValue6, "_id=1", null);
Cursor fun06Cursor = mContext.getContentResolver().query(uri6, new String[]{"_id", "ConTimestar1", "ConTimestop1", "ConTimestar2", "ConTimestop3"}, null, null, null);
if (fun06Cursor != null) {
while (fun06Cursor.moveToNext()) {
Log.d(TAG, "ID:" + fun06Cursor.getInt(fun06Cursor.getColumnIndex("_id"))
+ " ConTimestar1:" + fun06Cursor.getString(fun06Cursor.getColumnIndex("ConTimestar1"))
+ " ConTimestop1:" + fun06Cursor.getString(fun06Cursor.getColumnIndex("ConTimestop1"))
+ " ConTimestar2:" + fun06Cursor.getString(fun06Cursor.getColumnIndex("ConTimestar2"))
+ " ConTimestop3:" + fun06Cursor.getString(fun06Cursor.getColumnIndex("ConTimestop3")));
}
fun06Cursor.close();
}
contentValue6.clear();
break;
case "07": //whitelist settings
Uri uri7 = Uri.parse("content://com.agenew.duardian/fun06");
ContentValues contentValue7 = new ContentValues();
contentValue7.put("switch", funcarray[1]);
contentValue7.put("whiteNum1", funcarray[2]);
contentValue7.put("whiteNum2", funcarray[3]);
contentValue7.put("whiteNum3", funcarray[4]);
contentValue7.put("whiteNum4", funcarray[5]);
contentValue7.put("whiteNum5", funcarray[6]);
contentValue7.put("whiteNum6", funcarray[7]);
mContext.getContentResolver().update(uri7, contentValue7, "_id=1", null);
Cursor fun07Cursor = mContext.getContentResolver().query(uri7, new String[]{"_id", "switch", "whiteNum1", "whiteNum2", "whiteNum3"}, null, null, null);
if (fun07Cursor != null) {
while (fun07Cursor.moveToNext()) {
Log.d(TAG, "ID:" + fun07Cursor.getInt(fun07Cursor.getColumnIndex("_id"))
+ " switch:" + fun07Cursor.getString(fun07Cursor.getColumnIndex("switch"))
+ " whiteNum1:" + fun07Cursor.getString(fun07Cursor.getColumnIndex("whiteNum1"))
+ " whiteNum2:" + fun07Cursor.getString(fun07Cursor.getColumnIndex("whiteNum2"))
+ " whiteNum3:" + fun07Cursor.getString(fun07Cursor.getColumnIndex("whiteNum3")));
}
fun07Cursor.close();
}
contentValue7.clear();
break;
}
}
private String[] customSplit(String s) {
char[] chars = s.toCharArray();
int lenth = chars.length;
int size = 0;
for (int i = 0; i < lenth; i++) {
if (chars[i] == '|') {
size++;
}
}
String[] array = new String[size + 1];
String cur = s;
for (int i = size; i >= 0; i--) {
if (i == 0) {
array[i] = cur;
break;
}
int lastIndex = cur.lastIndexOf('|');
String temp = cur.substring(0, lastIndex);
if (temp.length() == cur.length()) {
array[i] = "";
} else {
array[i] = cur.substring(lastIndex + 1);
}
cur = temp;
}
return array;
}
public String trimResponse(String response) {
String tempResult = response.replaceAll("<", "");
String result = tempResult.replaceAll(">", "");
return result;
}
}
package com.agenew.duardian.util;
import android.content.Context;
import android.database.Cursor;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.provider.Settings;
import android.telephony.CellLocation;
import android.telephony.TelephonyManager;
import android.telephony.cdma.CdmaCellLocation;
import android.telephony.gsm.GsmCellLocation;
import android.util.Log;
import java.lang.reflect.Method;
public class PhoneUtils {
public static final String TAG = "PhoneUtils";
public static String CID = "";
public static String LAC = "";
public static boolean isNetwork(Context context) {
if (context != null) {
ConnectivityManager mConnectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
if (mNetworkInfo != null) {
Log.d("PHONE", "has network");
return mNetworkInfo.isAvailable();
}
}
Log.d("PHONE", "no network");
return false;
}
public static boolean IsAirModeOn(Context context) {
return (Settings.System.getInt(context.getContentResolver(),
Settings.System.AIRPLANE_MODE_ON, 0) == 1 ? true : false);
}
static public String getProperty(String key, String defaultValue) {
String value = defaultValue;
try {
Class<?> c = Class.forName("android.os.SystemProperties");
Method get = c.getMethod("get", String.class, String.class);
value = (String) (get.invoke(c, key, ""));
} catch (Exception e) {
e.printStackTrace();
} finally {
return value;
}
}
public static void getLacCid(Context context) {
int cid = 0;
int lac = 0;
TelephonyManager telephonyManager = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
CellLocation cel = telephonyManager.getCellLocation();
if (telephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA) {
CdmaCellLocation cdmaCellLocation = (CdmaCellLocation) cel;
cid = cdmaCellLocation.getBaseStationId();
lac = cdmaCellLocation.getNetworkId();
} else {
GsmCellLocation gsmCellLocation = (GsmCellLocation) cel;
cid = gsmCellLocation.getCid();
lac = gsmCellLocation.getLac();
}
CID = String.valueOf(cid);
LAC = String.valueOf(lac);
}
/**
* get CID
*
* @return CID
*/
public static String getCID(Context context) {
getLacCid(context);
return CID;
}
/**
* get LAC
*
* @return LAC
*/
public static String getLAC(Context context) {
getLacCid(context);
return LAC;
}
/**
* get Icc
*
* @return Icc
*/
public static String getIccId(Context context) {
TelephonyManager telephonyManager = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
String icc = telephonyManager.getSimSerialNumber();
return icc;
}
/**
* get sim Imei
*
* @return Imei
*/
public static String getImei(Context context) {
TelephonyManager telephonyManager = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
String imei = telephonyManager.getDeviceId();
return imei;
}
/**
* My phone num
*
* @return phone num
*/
public static String getNativePhoneNumber(Context context) {
String nativePhoneNumber = "N/A";
TelephonyManager telephonyManager = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
nativePhoneNumber = telephonyManager.getLine1Number();
if (PreferencesUtil.DBUG) {
Log.d(TAG, "nativePhoneNumber = " + nativePhoneNumber);
}
if (nativePhoneNumber != null) {
int length = nativePhoneNumber.length();
if (length >= 11) {
nativePhoneNumber = nativePhoneNumber.substring(length - 11, length);
}
}
return nativePhoneNumber;
}
/**
* IS HAS SIM?
*
* @return STATUS
*/
public static boolean ishasSimCard(Context context) {
TelephonyManager telephonyManager = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
int simState = telephonyManager.getSimState();
boolean result = true;
switch (simState) {
case TelephonyManager.SIM_STATE_ABSENT:
result = false; // no sim
break;
case TelephonyManager.SIM_STATE_UNKNOWN:
result = false;
break;
}
return result;
}
/**
* get sim IMSI
*
* @return IMSI
*/
public static String getIMSI(Context context) {
String IMSI;
TelephonyManager telephonyManager = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
IMSI = telephonyManager.getSubscriberId();
Log.d(TAG, "imsi = " + IMSI);
if (IMSI == null) {
IMSI = "";
}
return IMSI;
}
public static String getMcc(Context context) {
String mcc = "0";
mcc = getIMSI(context).substring(0, 3);
return mcc;
}
public static String getMnc(Context context) {
String mnc = "0";
mnc = getIMSI(context).substring(3, 5);
return mnc;
}
public static String getProvidersName(Context context) {
String mProvideName = "";
String IMSI = getIMSI(context);
if (IMSI != null) {
System.out.println(IMSI);
if (IMSI.startsWith("46000") || IMSI.startsWith("46002") || IMSI.startsWith("46007")) {
mProvideName = "CM";
} else if (IMSI.startsWith("46001") || IMSI.startsWith("46006")) {
mProvideName = "UN";
} else if (IMSI.startsWith("46003") || IMSI.startsWith("46011") || IMSI.startsWith("46005")) {
mProvideName = "CT";
}
}
return mProvideName;
}
public static boolean isSamePhoneNum(Context context) {
String currentPhoneNum = PhoneUtils.getNativePhoneNumber(context);
String lastStoragePhoneNum = "";
Uri uri = Uri.parse("content://com.agenew.duardian/zte2100");
Cursor zte2100Cursor = context.getContentResolver().query(uri, new String[]{"mobile"}, null, null, null);
if (zte2100Cursor != null) {
while (zte2100Cursor.moveToNext()) {
lastStoragePhoneNum = zte2100Cursor.getString(zte2100Cursor.getColumnIndex("mobile"));
}
zte2100Cursor.close();
}
if (currentPhoneNum != null && !"".equals(currentPhoneNum)) {
if (currentPhoneNum.equals(lastStoragePhoneNum)) {
return true;
}
} else {
if (PreferencesUtil.DBUG) {
Log.d(TAG, "Failed to get local number");
}
}
return false;
}
public static boolean isSameIccId(Context context){
String currentIccid = PhoneUtils.getIccId(context);
String lastStorageIccid = "";
Uri uri = Uri.parse("content://com.agenew.duardian/result");
Cursor resultCursor = context.getContentResolver().query(uri, new String[]{"iccid"}, "_id=1", null, null);
if (resultCursor != null) {
while (resultCursor.moveToNext()) {
lastStorageIccid = resultCursor.getString(resultCursor.getColumnIndex("iccid"));
}
resultCursor.close();
}
if (currentIccid != null && !"".equals(currentIccid)) {
if (currentIccid.equals(lastStorageIccid)) {
return true;
}
} else {
if (PreferencesUtil.DBUG) {
Log.d(TAG, "Failed to get local number");
}
}
return false;
}
}
\ No newline at end of file
package com.agenew.duardian.util;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
public class PreferencesUtil {
/*
* server He Kang key
* */
public final static String HE_KANG_URI = "http://mob.3gcare.cn/s";
public final static String HE_KANG_ZTE2200 = "ZTE2200";
public final static String HE_KANG_ZTE2100 = "ZTE2100";
public final static String HE_KANG_ZTE1000 = "ZTE1000";
public static final String HE_KANG_ZTE1003 = "ZTE1003";
public static final String HE_KANG_VERSION = "HK.MC1702.V01";
/*
* server request key
* */
public final static String HE_KANG_REQ_SERVER_ACTTYPE = "actType";
public final static String HE_KANG_REQ_SERVER_REQCONTENT = "reqContent";
/*
*switch
*/
public static boolean ZTE2200Retry = true;
public static int ZTE2200_ERROR_COUNT = 0;
public static boolean ZTE2100Retry = true;
public static int ZTE2100_ERROR_COUNT = 0;
/*
*debug
*/
public static final boolean DBUG = true;
/*
*current platform phone num
*/
public static String KeyPhoneNum = "";
public static boolean getOpenAccountStatus(Context context) {
int value = 0;
Uri uri = Uri.parse("content://com.agenew.duardian/result");
Cursor ResultCursor = context.getContentResolver().query(uri, new String[]{"result"}, "_id=1", null, null);
if (ResultCursor != null) {
while (ResultCursor.moveToNext()) {
value = ResultCursor.getInt(ResultCursor.getColumnIndex("result"));
}
ResultCursor.close();
}
return value == 1;
}
}
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
<aapt:attr name="android:fillColor">
<gradient
android:endX="85.84757"
android:endY="92.4963"
android:startX="42.9492"
android:startY="49.59793"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
</vector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillColor="#3DDC84"
android:pathData="M0,0h108v108h-108z" />
<path
android:fillColor="#00000000"
android:pathData="M9,0L9,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,0L19,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,0L29,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,0L39,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,0L49,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,0L59,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,0L69,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,0L79,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M89,0L89,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M99,0L99,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,9L108,9"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,19L108,19"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,29L108,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,39L108,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,49L108,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,59L108,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,69L108,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,79L108,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,89L108,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,99L108,99"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,29L89,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,39L89,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,49L89,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,59L89,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,69L89,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,79L89,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,19L29,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,19L39,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,19L49,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,19L59,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,19L69,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,19L79,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
</vector>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="20dip"
tools:context=".MainActivity">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/introduction"
android:textSize="25dp"/>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>
\ No newline at end of file
<resources>
<string name="app_name">守护宝</string>
<string name="introduction">自开户功能以及定位功能</string>
<string name="toast_tips_server_unavailable">服务器连接错误,请重试</string>
<string name="open_account_success">开户成功</string>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#6200EE</color>
<color name="colorPrimaryDark">#3700B3</color>
<color name="colorAccent">#03DAC5</color>
</resources>
<resources>
<string name="app_name">守护宝</string>
<string name="introduction">自开户功能以及定位功能</string>
<string name="toast_tips_server_unavailable">服务器连接错误,请重试</string>
<string name="open_account_success">开户成功</string>
</resources>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
package com.agenew.duardian;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}
\ No newline at end of file
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
No preview for this file type
#Tue Apr 07 10:41:48 CST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
#!/usr/bin/env sh
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi
exec "$JAVACMD" "$@"
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
rootProject.name='Duardian'
include ':app'
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!