Created
July 7, 2014 09:15
-
-
Save Szil/2f1eb86f0d24b16331be to your computer and use it in GitHub Desktop.
mobilinfo-updatemanager
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package info.kallaim.gdfinfo; | |
import android.app.Notification; | |
import android.app.NotificationManager; | |
import android.content.ContentValues; | |
import android.content.Context; | |
import android.content.Intent; | |
import android.content.SharedPreferences; | |
import android.content.SharedPreferences.Editor; | |
import android.database.sqlite.SQLiteDatabase; | |
import android.net.ConnectivityManager; | |
import android.net.NetworkInfo; | |
import android.preference.PreferenceManager; | |
import android.support.v4.app.NotificationCompat.Builder; | |
import java.io.BufferedReader; | |
import java.io.ByteArrayInputStream; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.io.InputStreamReader; | |
import java.net.HttpURLConnection; | |
import java.net.URL; | |
import java.net.URLConnection; | |
import java.security.SecureRandom; | |
import java.security.cert.CertificateException; | |
import java.security.cert.X509Certificate; | |
import java.text.DateFormat; | |
import java.text.ParseException; | |
import java.text.SimpleDateFormat; | |
import java.util.ArrayList; | |
import java.util.Collections; | |
import java.util.Date; | |
import java.util.Locale; | |
import java.util.zip.GZIPInputStream; | |
import javax.net.ssl.HostnameVerifier; | |
import javax.net.ssl.HttpsURLConnection; | |
import javax.net.ssl.SSLContext; | |
import javax.net.ssl.SSLSession; | |
import javax.net.ssl.TrustManager; | |
import javax.net.ssl.X509TrustManager; | |
public class UpdateManager | |
{ | |
static final HostnameVerifier DO_NOT_VERIFY = new HostnameVerifier() | |
{ | |
public boolean verify(String paramAnonymousString, SSLSession paramAnonymousSSLSession) | |
{ | |
return true; | |
} | |
}; | |
private Context context; | |
private SQLiteDatabase db; | |
private DbContext dbHelper; | |
private SharedPreferences preferences; | |
public UpdateManager(Context paramContext) | |
{ | |
this.context = paramContext; | |
this.preferences = PreferenceManager.getDefaultSharedPreferences(paramContext); | |
} | |
private static void trustAllHosts() | |
{ | |
TrustManager[] arrayOfTrustManager = new TrustManager[1]; | |
arrayOfTrustManager[0 = new X509TrustManager() | |
{ | |
public void checkClientTrusted(X509Certificate[] paramAnonymousArrayOfX509Certificate, String paramAnonymousString) | |
throws CertificateException | |
{} | |
public void checkServerTrusted(X509Certificate[] paramAnonymousArrayOfX509Certificate, String paramAnonymousString) | |
throws CertificateException | |
{} | |
public X509Certificate[] getAcceptedIssuers() | |
{ | |
return new X509Certificate[0]; | |
} | |
}; | |
try | |
{ | |
SSLContext localSSLContext = SSLContext.getInstance("TLS"); | |
localSSLContext.init(null, arrayOfTrustManager, new SecureRandom()); | |
HttpsURLConnection.setDefaultSSLSocketFactory(localSSLContext.getSocketFactory()); | |
return; | |
} | |
catch (Exception localException) | |
{ | |
localException.printStackTrace(); | |
} | |
} | |
public boolean CheckUpdate() | |
{ | |
boolean bool1 = true; | |
NetworkInfo localNetworkInfo = ((ConnectivityManager)this.context.getSystemService("connectivity")).getActiveNetworkInfo(); | |
SharedPreferences localSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this.context); | |
String str1 = localSharedPreferences.getString("username", ""); | |
String str2 = localSharedPreferences.getString("password", ""); | |
String str3 = localSharedPreferences.getString("dbversion", "200001010000"); | |
if (localNetworkInfo.isConnected()) | |
{ | |
this.dbHelper = new DbContext(this.context); | |
this.db = this.dbHelper.getWritableDatabase(); | |
} | |
try | |
{ | |
URL localURL = new URL("https://services.gdf.hu/web/mobile/mobilservice.svc/checkupdate/" + str1 + "/" + str3); | |
trustAllHosts(); | |
HttpURLConnection localHttpURLConnection = (HttpURLConnection)localURL.openConnection(); | |
String str4 = Base64.encode((str1 + ":" + str2).getBytes()); | |
localHttpURLConnection.setRequestProperty("Authorization", "Basic " + str4); | |
InputStream localInputStream = localHttpURLConnection.getInputStream(); | |
InputStreamReader localInputStreamReader = new InputStreamReader(localInputStream); | |
String str5 = new BufferedReader(localInputStreamReader).readLine(); | |
int i = str5.indexOf('>'); | |
int j = str5.indexOf('<', i); | |
boolean bool2 = str5.substring(i + 1, j).equals("false"); | |
if (bool2) { | |
bool1 = false; | |
} | |
return bool1; | |
} | |
catch (IOException localIOException) {} | |
return bool1; | |
} | |
public String Update(boolean paramBoolean) | |
{ | |
NetworkInfo localNetworkInfo = ((ConnectivityManager)this.context.getSystemService("connectivity")).getActiveNetworkInfo(); | |
SharedPreferences localSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this.context); | |
String str1 = localSharedPreferences.getString("username", ""); | |
String str2 = localSharedPreferences.getString("password", ""); | |
if ((str1.equals("")) || (str2.equals(""))) { | |
this.context.startActivity(new Intent(this.context, AppPreferenceActivity.class)); | |
} | |
while ((!localNetworkInfo.isConnected()) || (!CheckUpdate())) { | |
return null; | |
} | |
this.dbHelper = new DbContext(this.context); | |
this.db = this.dbHelper.getWritableDatabase(); | |
for (;;) | |
{ | |
String str5; | |
ContentValues localContentValues; | |
String[] arrayOfString; | |
try | |
{ | |
URL localURL = new URL("https://services.gdf.hu/web/mobile/mobilservice.svc/getdata/" + str1); | |
trustAllHosts(); | |
HttpURLConnection localHttpURLConnection = (HttpURLConnection)localURL.openConnection(); | |
String str3 = Base64.encode((str1 + ":" + str2).getBytes()); | |
localHttpURLConnection.setRequestProperty("Authorization", "Basic " + str3); | |
InputStream localInputStream = localHttpURLConnection.getInputStream(); | |
InputStreamReader localInputStreamReader1 = new InputStreamReader(localInputStream); | |
String str4 = new BufferedReader(localInputStreamReader1).readLine(); | |
int i = str4.indexOf('>'); | |
int j = str4.indexOf('<', i); | |
GZIPInputStream localGZIPInputStream = new GZIPInputStream(new ByteArrayInputStream(Base64.decode(str4.substring(i + 1, j)))); | |
this.db.execSQL("DELETE FROM " + DbContext.TIMETABLE); | |
this.db.execSQL("DELETE FROM " + DbContext.EXAMS); | |
this.db.execSQL("DELETE FROM " + DbContext.SUBJECTS); | |
this.db.execSQL("DELETE FROM " + DbContext.OFFICEHOURS); | |
InputStreamReader localInputStreamReader2 = new InputStreamReader(localGZIPInputStream); | |
BufferedReader localBufferedReader = new BufferedReader(localInputStreamReader2); | |
this.db.beginTransaction(); | |
localArrayList = new ArrayList(); | |
str5 = localBufferedReader.readLine(); | |
if (str5 == null) | |
{ | |
this.db.setTransactionSuccessful(); | |
this.db.endTransaction(); | |
localGZIPInputStream.close(); | |
localBufferedReader.close(); | |
Collections.sort(localArrayList); | |
String str6 = (String)localArrayList.get(-1 + localArrayList.size()); | |
Date localDate = new SimpleDateFormat("yyyy.MM.dd. HH:mm:ss", new Locale("HU")).parse(str6); | |
SimpleDateFormat localSimpleDateFormat1 = new SimpleDateFormat("yyyyMMddHHmm", new Locale("HU")); | |
SimpleDateFormat localSimpleDateFormat2 = new SimpleDateFormat("yyyy. MM. dd. HH:mm"); | |
String str7 = localSimpleDateFormat1.format(localDate).toString(); | |
SharedPreferences.Editor localEditor2 = localSharedPreferences.edit(); | |
localEditor2.putBoolean("UserDataValid", true); | |
localEditor2.putString("dbversion", str7); | |
String str8 = localSimpleDateFormat2.format(new Date()); | |
localEditor2.putString("lastupdate", str8); | |
localEditor2.commit(); | |
if (paramBoolean) | |
{ | |
NotificationManager localNotificationManager = (NotificationManager)this.context.getSystemService("notification"); | |
Notification localNotification = new NotificationCompat.Builder(this.context).setContentTitle("GDF mobilinfo").setContentText("Az adatbázis frissítve: " + str8 + ".").setSmallIcon(2130837507).getNotification(); | |
localNotification.flags = 16; | |
localNotificationManager.notify(1, localNotification); | |
} | |
return null; | |
} | |
localContentValues = new ContentValues(); | |
arrayOfString = str5.split(";", -1); | |
if (str5.startsWith("O;")) | |
{ | |
localContentValues.put(DbContext.T_DATE, arrayOfString[1]); | |
localContentValues.put(DbContext.T_BEGIN, arrayOfString[2]); | |
localContentValues.put(DbContext.T_END, arrayOfString[3]); | |
localContentValues.put(DbContext.T_LENGTH, arrayOfString[4]); | |
localContentValues.put(DbContext.T_GROUP, arrayOfString[5]); | |
localContentValues.put(DbContext.T_CLASSTYPE, arrayOfString[6]); | |
localContentValues.put(DbContext.T_ROOM, arrayOfString[7]); | |
localContentValues.put(DbContext.T_TEACHER, arrayOfString[8]); | |
localContentValues.put(DbContext.T_SUBJECTNAME, arrayOfString[9]); | |
localContentValues.put(DbContext.T_LASTCHANGED, arrayOfString[10]); | |
localContentValues.put(DbContext.T_DEPARTMENT, arrayOfString[11].substring(0, 8)); | |
localContentValues.put(DbContext.T_SUBJECTCODE, arrayOfString[12]); | |
localContentValues.put(DbContext.T_WEEKNUMBER, arrayOfString[13]); | |
localContentValues.put(DbContext.T_DAYNUMBER, arrayOfString[14]); | |
localArrayList.add(arrayOfString[10]); | |
this.db.insert(DbContext.TIMETABLE, null, localContentValues); | |
continue; | |
} | |
} | |
catch (IOException localIOException) | |
{ | |
localIOException.printStackTrace(); | |
SharedPreferences.Editor localEditor1 = localSharedPreferences.edit(); | |
localEditor1.putBoolean("UserDataValid", false); | |
localEditor1.commit(); | |
return "Hibás felhasználónév/jelszó!"; | |
if (str5.startsWith("F;")) | |
{ | |
localContentValues.put(DbContext.O_TEACHER, arrayOfString[1]); | |
localContentValues.put(DbContext.O_INSTITUTE, arrayOfString[2]); | |
localContentValues.put(DbContext.O_ROOM, arrayOfString[3]); | |
localContentValues.put(DbContext.O_PHONE, arrayOfString[4]); | |
localContentValues.put(DbContext.O_DAY, arrayOfString[5]); | |
localContentValues.put(DbContext.O_EMAIL, arrayOfString[6]); | |
localContentValues.put(DbContext.O_SUBJECTS, arrayOfString[7]); | |
localContentValues.put(DbContext.O_NOTE, arrayOfString[8]); | |
localContentValues.put(DbContext.O_BEGIN, arrayOfString[9]); | |
localContentValues.put(DbContext.O_END, arrayOfString[10]); | |
localContentValues.put(DbContext.O_LASTCHANGED, arrayOfString[11]); | |
localArrayList.add(arrayOfString[11]); | |
this.db.insert(DbContext.OFFICEHOURS, null, localContentValues); | |
continue; | |
} | |
} | |
catch (ParseException localParseException) | |
{ | |
ArrayList localArrayList; | |
localParseException.printStackTrace(); | |
return null; | |
if (str5.startsWith("V;")) | |
{ | |
localContentValues.put(DbContext.E_SUBJECT, arrayOfString[1]); | |
localContentValues.put(DbContext.E_SIGNDATE, arrayOfString[2]); | |
localContentValues.put(DbContext.E_EXAMDATE, arrayOfString[3]); | |
localContentValues.put(DbContext.E_SIGNVALUE, arrayOfString[4]); | |
localContentValues.put(DbContext.E_TEACHER, arrayOfString[5]); | |
localArrayList.add(arrayOfString[2]); | |
localArrayList.add(arrayOfString[3]); | |
this.db.insert(DbContext.EXAMS, null, localContentValues); | |
continue; | |
} | |
} | |
finally | |
{ | |
this.db.close(); | |
} | |
if (str5.startsWith("T;")) | |
{ | |
localContentValues.put(DbContext.S_SUBJECT, arrayOfString[1]); | |
this.db.insert(DbContext.SUBJECTS, null, localContentValues); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment