| | |
| | | |
| | | import android.app.Service; |
| | | import android.content.Intent; |
| | | import android.content.SharedPreferences; |
| | | import android.os.IBinder; |
| | | import android.os.RemoteCallbackList; |
| | | import android.os.RemoteException; |
| | | import android.util.Base64; |
| | | import android.util.Log; |
| | | |
| | | import com.anyun.exam.lib.util.DESUtil; |
| | | import com.anyun.exam.lib.util.NetUtils; |
| | | |
| | | import androidx.annotation.Nullable; |
| | | |
| | |
| | | * All Rights Saved! Chongqing AnYun Tech co. LTD |
| | | */ |
| | | public class RemoteService extends Service { |
| | | |
| | | private static final String TAG = "RemoteService"; |
| | | private final static String LOAD_KEY = "RTKBaseStation"; |
| | | /**服务是否销毁标志*/ |
| | | private AtomicBoolean mIsServiceDestroyed = new AtomicBoolean(false); |
| | | private RemoteCallbackList<IListenerInterface> mListenerList = new RemoteCallbackList(); |
| | |
| | | public void onCreate() { |
| | | super.onCreate(); |
| | | Log.i(TAG,"onCreate()"); |
| | | startNative(); |
| | | new Thread(new Worker()).start(); |
| | | } |
| | | |
| | |
| | | mListenerList.finishBroadcast(); |
| | | } |
| | | } |
| | | |
| | | public String javaGetImei() { |
| | | return NetUtils.getDeviceId(getApplicationContext()); |
| | | } |
| | | |
| | | public String javaDESEncrypt(String plaintext, String key) { |
| | | try { |
| | | byte []des = DESUtil.encrypt(plaintext.getBytes("utf-8"), key); |
| | | return Base64.encodeToString(des, Base64.DEFAULT); |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public byte[] javaDESEncrypt(byte []plaintext, byte []key) { |
| | | try { |
| | | return DESUtil.encrypt(plaintext, key); |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public void SetPlatformKey(byte []key) { |
| | | String params = Base64.encodeToString(key, Base64.DEFAULT); |
| | | |
| | | SharedPreferences sharedPreferences = getSharedPreferences(LOAD_KEY, MODE_PRIVATE); |
| | | SharedPreferences.Editor editor = sharedPreferences.edit(); |
| | | editor.putString("platform_key", params); |
| | | editor.commit(); |
| | | } |
| | | |
| | | public byte[] GetPlatformKey() { |
| | | SharedPreferences sharedPreferences = getSharedPreferences(LOAD_KEY, MODE_PRIVATE); |
| | | String params = sharedPreferences.getString("platform_key", ""); |
| | | if (params.equals("")) { |
| | | return null; |
| | | } |
| | | return Base64.decode(params, Base64.DEFAULT); |
| | | } |
| | | |
| | | public void DeletePlatformKey() { |
| | | SharedPreferences sharedPreferences = getSharedPreferences(LOAD_KEY, MODE_PRIVATE); |
| | | SharedPreferences.Editor editor = sharedPreferences.edit(); |
| | | editor.putString("platform_key", ""); |
| | | editor.commit(); |
| | | } |
| | | |
| | | public void SetSharedValue(String key, int value) { |
| | | SharedPreferences sharedPreferences = getSharedPreferences(LOAD_KEY, MODE_PRIVATE); |
| | | SharedPreferences.Editor editor = sharedPreferences.edit(); |
| | | editor.putInt(key, value); |
| | | editor.commit(); |
| | | } |
| | | |
| | | public int GetSharedValue(String key) { |
| | | SharedPreferences sharedPreferences = getSharedPreferences(LOAD_KEY, MODE_PRIVATE); |
| | | return sharedPreferences.getInt(key, 0); |
| | | } |
| | | |
| | | // Used to load the 'native-lib' library on application startup. |
| | | static { |
| | | System.loadLibrary("native-lib"); |
| | | } |
| | | |
| | | public native void startNative(); |
| | | } |