From 1a8787e34f27d1ea8ecc8d7b0044ae9f650760e8 Mon Sep 17 00:00:00 2001 From: yy1717 <fctom1215@outlook.com> Date: 星期四, 23 七月 2020 10:16:34 +0800 Subject: [PATCH] 坐标 --- lib/src/main/java/com/anyun/exam/lib/Upgrade.java | 267 ++++++++++++++++++++++++++++++++++++++++++++ lib/src/main/java/com/anyun/exam/lib/RemoteService.java | 89 ++++++++------ 2 files changed, 315 insertions(+), 41 deletions(-) diff --git a/lib/src/main/java/com/anyun/exam/lib/RemoteService.java b/lib/src/main/java/com/anyun/exam/lib/RemoteService.java index 7fbe4ae..cded731 100644 --- a/lib/src/main/java/com/anyun/exam/lib/RemoteService.java +++ b/lib/src/main/java/com/anyun/exam/lib/RemoteService.java @@ -43,6 +43,10 @@ private int msgId = 0; private Speaker speaker = null; private boolean ttsInitSucc = false; + private int ringIndex = -1; + private Uri ringUri; + + private Upgrade upgrade = null; private IRemoteInterface.Stub iRemoteInterface = new IRemoteInterface.Stub(){ @Override @@ -93,50 +97,56 @@ new Thread(new TestThread()).start(); -// PlayRing(this); + upgrade = Upgrade.getInstance(getApplicationContext()); + upgrade.CheckUpgrade(); + + ringUri = GetRingIndex(this, "Mira"); + PlayRing(this, ringUri); } - public void PlayRing(Context context) { + private Uri GetRingIndex(Context context, String ring) { RingtoneManager ringtoneManager= new RingtoneManager(context); // 閾冨0绠$悊鍣� ringtoneManager.setType(RingtoneManager.TYPE_NOTIFICATION); for (int i = 0; i < ringtoneManager.getCursor().getCount(); i++) { - Log.i(TAG, "閾冨0鍚嶇О " + ringtoneManager.getRingtone(i).getTitle(context)); - - if (ringtoneManager.getRingtone(i).getTitle(this).equals("Carina")) { - Log.d(TAG, "鎾斁閾冨0"); - - final MediaPlayer mediaPlayer = new MediaPlayer(); - Uri src = ringtoneManager.getRingtoneUri(i); - - try { - mediaPlayer.setDataSource(context, src); - mediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM); - mediaPlayer.setLooping(false); - mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { - @Override - public void onCompletion(MediaPlayer mp) { - // 鍦ㄦ挱鏀惧畬姣曡鍥炶皟 - Log.d(TAG, "鎾斁瀹屾垚"); - mediaPlayer.stop(); - mediaPlayer.release(); - } - }); - - mediaPlayer.prepareAsync(); - mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { - @Override - public void onPrepared(MediaPlayer mp) { - // 瑁呰浇瀹屾瘯鍥炶皟 - Log.d(TAG, "瑁呰浇瀹屾瘯鍥炶皟"); - mediaPlayer.start(); - } - }); - - } catch (Exception e) { - - } - break; + if (ringtoneManager.getRingtone(i).getTitle(context).equals(ring)) { + Log.d(TAG, "寰楀埌閾冨0 " + i); + return ringtoneManager.getRingtoneUri(i); } + } + return null; + } + + public void PlayRing(Context context, Uri src) { + if (src == null) + return; + + final MediaPlayer mediaPlayer = new MediaPlayer(); + try { + mediaPlayer.setDataSource(context, src); + mediaPlayer.setAudioStreamType(AudioManager.STREAM_NOTIFICATION); + mediaPlayer.setLooping(false); + mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { + @Override + public void onCompletion(MediaPlayer mp) { + // 鍦ㄦ挱鏀惧畬姣曡鍥炶皟 + Log.d(TAG, "鎾斁瀹屾垚"); + mediaPlayer.stop(); + mediaPlayer.release(); + } + }); + + mediaPlayer.prepareAsync(); + mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { + @Override + public void onPrepared(MediaPlayer mp) { + // 瑁呰浇瀹屾瘯鍥炶皟 + Log.d(TAG, "瑁呰浇瀹屾瘯鍥炶皟"); + mediaPlayer.start(); + } + }); + + } catch (Exception e) { + Log.e(TAG, e.getMessage()); } } @@ -190,9 +200,6 @@ if (!mIsServiceDestroyed.get()){ onMessageArrived(cmd, value); } - - - } public String javaDESEncrypt(String plaintext, String key) { diff --git a/lib/src/main/java/com/anyun/exam/lib/Upgrade.java b/lib/src/main/java/com/anyun/exam/lib/Upgrade.java new file mode 100644 index 0000000..e42cd9c --- /dev/null +++ b/lib/src/main/java/com/anyun/exam/lib/Upgrade.java @@ -0,0 +1,267 @@ +package com.anyun.exam.lib; + +import android.content.Context; +import android.content.SharedPreferences; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; +import android.content.pm.Signature; +import android.os.Handler; +import android.util.Log; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.BufferedReader; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.nio.file.Path; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.List; +import java.util.Locale; + +public class Upgrade { + public static final String TAG = Upgrade.class.getCanonicalName(); + private static final String newProgramIndUrl = "http://upgrade.safeluck.com/ftp/aykj4/aks3.json"; + private static Upgrade instance = null; + private Context context; + private DownloadManagerUtil downloadManagerUtil = null; + private InstallUtil installUtil = null; + + public static Upgrade getInstance(Context context) { + if (instance == null) { + synchronized (Upgrade.class) { + if (instance == null) { + instance = new Upgrade(context); + } + } + } + return instance; + } + + private Upgrade(Context context) { + this.context = context; + + installUtil = InstallUtil.getInstance(context); + downloadManagerUtil = DownloadManagerUtil.getInstance(context); + downloadManagerUtil.SetDMCallback(new DMCB()); + } + + private String CheckNewVersion(String urlStr) { + HttpURLConnection uRLConnection = null; + InputStream is = null; + BufferedReader buffer = null; + String result = null; + try { + URL url = new URL(urlStr); + uRLConnection = (HttpURLConnection) url.openConnection(); + uRLConnection.setConnectTimeout(8000); + uRLConnection.setReadTimeout(8000); + uRLConnection.setRequestMethod("GET"); + is = uRLConnection.getInputStream(); + buffer = new BufferedReader(new InputStreamReader(is)); + StringBuilder strBuilder = new StringBuilder(); + String line; + while ((line = buffer.readLine()) != null) { + strBuilder.append(line); + } + result = strBuilder.toString(); + } catch (Exception e) { + e.printStackTrace(); + Log.e(TAG, "http post error"); + } finally { + if (buffer != null) { + try { + buffer.close(); + } catch (IOException ignored) { + } + } + if (is != null) { + try { + is.close(); + } catch (IOException ignored) { + + } + } + if (uRLConnection != null) { + uRLConnection.disconnect(); + } + } + return result; + } + + class DfuFileInfo { + boolean valid = false; + int appVerCode = 0; + String appUrl = null; + int systemVerCode = 0; + String systemUrl = null; + + public void setValid(boolean en) { + this.valid = en; + } + + public void setApp(int code, String url) { + this.appVerCode = code; + this.appUrl = url; + } + public void setSystem(int code, String url) { + this.systemVerCode = code; + this.systemUrl = url; + } + + public boolean getValid() { + return valid; + } + public int getAppVerCode() { + return appVerCode; + } + public String getAppUrl() { + return appUrl; + } + public int getSystemVerCode() { + return systemVerCode; + } + public String getSystemUrl() { + return systemUrl; + } + } + + private DfuFileInfo parseJson(String result, int province, int city) { + Log.d(TAG, "parseJson province " + province + " city " + city); + + DfuFileInfo dfuFileInfo = new DfuFileInfo(); + + try { + JSONObject obj = new JSONObject(result); + + JSONArray jsonarray = obj.getJSONArray("province"); + + boolean marchProvince = false; + + for (int i = 0; !marchProvince && i < jsonarray.length(); i++) { + JSONObject obj2 = jsonarray.getJSONObject(i); + + int pid = obj2.getInt("id"); + Log.d(TAG, "pid = " + pid); + + if (pid == province) { + JSONArray jsonarray2 = obj2.getJSONArray("city"); + + boolean marchCity = false; + + // 鍖归厤鐪乮d鎴愬姛 + marchProvince = true; + + for (int j = 0; !marchCity && j < jsonarray2.length(); j++) { + // 閬嶅巻甯俰d缁� + JSONObject obj3 = jsonarray2.getJSONObject(j); + + JSONArray jsonarray3 = obj3.getJSONArray("id"); + + marchCity = false; + + for (int k = 0; k < jsonarray3.length(); k++) { + // 閬嶅巻甯俰d + int cid = jsonarray3.getInt(k); + Log.d(TAG, "cid = " + cid); + + if (cid == 0) { + Log.d(TAG, "March GeneralCity"); + dfuFileInfo.setValid(true); + if (obj3.has("appVersionCode") && obj3.has("appUpgradeUrl")) { + dfuFileInfo.setApp(obj3.getInt("appVersionCode"), obj3.getString("appUpgradeUrl")); + } + if (obj3.has("systemVersionCode") && obj3.has("systemUpgradeUrl")) { + dfuFileInfo.setSystem(obj3.getInt("systemVersionCode"), obj3.getString("systemUpgradeUrl")); + } + } + + if (cid == city) { + marchCity = true; + Log.d(TAG, "March City"); + dfuFileInfo.setValid(true); + if (obj3.has("appVersionCode") && obj3.has("appUpgradeUrl")) { + dfuFileInfo.setApp(obj3.getInt("appVersionCode"), obj3.getString("appUpgradeUrl")); + } + if (obj3.has("systemVersionCode") && obj3.has("systemUpgradeUrl")) { + dfuFileInfo.setSystem(obj3.getInt("systemVersionCode"), obj3.getString("systemUpgradeUrl")); + } + break; + } + } + } + } + } + Log.d(TAG, "Parse End"); + } catch (JSONException e) { + Log.e(TAG, e.getMessage()); + dfuFileInfo.setValid(false); + } + return dfuFileInfo; + } + + class CheckNewVersionThread implements Runnable { + @Override + public void run() { + Log.d(TAG, "妫�鏌ュ崌绾х珯鐐�"); + + String result = CheckNewVersion(newProgramIndUrl); + + if (result != null) { + DfuFileInfo dfuFileInfo = parseJson(result, 53, 100); + if (dfuFileInfo != null && dfuFileInfo.getValid()) { + if (dfuFileInfo.getAppVerCode() > 0 && dfuFileInfo.getAppUrl() != null) { + if (installUtil.getVerCode() < dfuFileInfo.getAppVerCode()) { + Log.d(TAG, "涓嬭浇鍦板潃 " + dfuFileInfo.getAppUrl()); + + downloadManagerUtil.DownloadFile(dfuFileInfo.getAppUrl(), "aks3.apk", "aks3", "椹捐�僡pp鍗囩骇"); +// downloadManagerUtil.DownloadFile("https://ftp-idc.pconline.com.cn/pub/download/201010/AutoCAD2007.rar?md5=KeZ0iEmKKGEWJ5c7OVxk_w&expires=1592964150", "aks3.apk", "aks3", "椹捐�僡pp鍗囩骇"); + } + } + if (dfuFileInfo.getSystemVerCode() > 0 && dfuFileInfo.getSystemUrl() != null) { + + } + } + } + + handlerCheckNewVersion.removeCallbacks(runnableCheckNewVersion); + handlerCheckNewVersion.postDelayed(runnableCheckNewVersion, 30*60*1000); + } + } + + Handler handlerCheckNewVersion = new Handler(); + Runnable runnableCheckNewVersion = new Runnable() { + @Override + public void run() { + new Thread(new CheckNewVersionThread()).start(); + } + }; + + public void CheckUpgrade() { + handlerCheckNewVersion.removeCallbacks(runnableCheckNewVersion); + handlerCheckNewVersion.postDelayed(runnableCheckNewVersion, 100); + } + + class DMCB implements DownloadManagerCallback { + @Override + public void DownloadComplete(String title, String path) { + if (title != null && path != null) { + if (title.equals("aks3")) { + Signature[] sig = installUtil.getSignature(); + Signature[] sig2 = installUtil.getSignature(path); + + if (sig != null && sig2 != null && installUtil.getFingerprint(sig[0], "SHA-1").equals(installUtil.getFingerprint(sig2[0], "SHA-1"))) { + installUtil.InstallApp(path); + } + } + } + } + } +} -- Gitblit v1.8.0