mirror of
https://github.com/freeedcom/ai-codereviewer.git
synced 2025-07-01 05:14:17 +00:00
add project adins
This commit is contained in:
parent
ad06ac5505
commit
f8f85d679d
5299 changed files with 625430 additions and 0 deletions
|
@ -0,0 +1,34 @@
|
|||
package com.adins.mss.base.login;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.adins.mss.base.commons.ActivityModel;
|
||||
|
||||
/**
|
||||
* Created by Aditya Purwa on 1/6/2015.
|
||||
* Base class for login implementation.
|
||||
*/
|
||||
public abstract class LoginModel extends ActivityModel {
|
||||
/**
|
||||
* Initialize a new instance of context model.
|
||||
*
|
||||
* @param context The context for the model. Must be an activity.
|
||||
*/
|
||||
public LoginModel(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the login command.
|
||||
*
|
||||
* @return True if succeeded.
|
||||
*/
|
||||
public abstract boolean login();
|
||||
|
||||
/**
|
||||
* Execute the exit command.
|
||||
*
|
||||
* @return True if succeeded.
|
||||
*/
|
||||
public abstract boolean exit();
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:background="@drawable/bg_grayscale" >
|
||||
<View
|
||||
android:id="@+id/actionbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp"
|
||||
android:layout_alignParentTop="true"
|
||||
android:background="@drawable/actionbar_background" />
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/byDate"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="10dp"
|
||||
android:gravity="center_horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/dtm"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:ems="10"
|
||||
android:text="@string/select_reschedule_time"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/txtDtm"
|
||||
android:hint="@string/requiredField"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/dtm"
|
||||
android:layout_toLeftOf="@+id/btnDtm"
|
||||
android:editable="false"
|
||||
android:ems="10" />
|
||||
<ImageButton
|
||||
android:id="@+id/btnDtm"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignBottom="@+id/txtDtm"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:background="@drawable/ic_calendar" />
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:padding="10dp"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnReschedule"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:text="@string/btnReschedule" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnCancel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_toLeftOf="@+id/btnReschedule"
|
||||
android:text="@string/btnCancel" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</LinearLayout>
|
|
@ -0,0 +1,47 @@
|
|||
package com.adins.mss.odr.reassignment;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.adins.mss.constant.Global;
|
||||
import com.adins.mss.odr.CheckOrderActivity;
|
||||
|
||||
import org.acra.ACRA;
|
||||
|
||||
public class OrderReassignmentActivity extends CheckOrderActivity{
|
||||
private int taskType;
|
||||
private Bundle mArguments;
|
||||
@Override
|
||||
public void onAttach(Context activity) {
|
||||
super.onAttach(activity);
|
||||
setHasOptionsMenu(false);
|
||||
ACRA.getErrorReporter().putCustomData("LAST_CLASS_ACCESSED", getClass().getSimpleName());
|
||||
mArguments = getArguments();
|
||||
taskType = mArguments.getInt(Global.BUND_KEY_TASK_TYPE, 0);
|
||||
}
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
super.onCreateView(inflater, container, savedInstanceState);
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Intent getNextActivityIntent() {
|
||||
// TODO Auto-generated method stub
|
||||
super.getNextActivityIntent();
|
||||
Intent fragment = new Intent(getActivity(), OrderReassignmentResult.class);
|
||||
Bundle args = new Bundle();
|
||||
args.putString("startDate", txtStartDate.getText().toString());
|
||||
args.putString("endDate", txtEndDate.getText().toString());
|
||||
args.putString("nomorOrder", txtNomorOrder.getText().toString());
|
||||
args.putString("status", "1");
|
||||
fragment.putExtras(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/text_spin"
|
||||
android:singleLine="false"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:ellipsize="marquee"
|
||||
android:paddingLeft="40dp"
|
||||
android:paddingStart="40dp"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:textColor="@color/fontColorWhite" />
|
|
@ -0,0 +1,70 @@
|
|||
package com.adins.mss.base.dynamicform;
|
||||
|
||||
import com.adins.mss.dao.TaskD;
|
||||
import com.adins.mss.dao.TaskH;
|
||||
import com.adins.mss.foundation.http.MssRequestType;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class JsonRequestVerificationTask extends MssRequestType {
|
||||
/**
|
||||
* Property taskH
|
||||
*/
|
||||
@SerializedName("taskH")
|
||||
TaskH taskH;
|
||||
|
||||
/**
|
||||
* Property taskD
|
||||
*/
|
||||
@SerializedName("taskD")
|
||||
List<TaskD> taskD;
|
||||
|
||||
/**
|
||||
* Property notes
|
||||
*/
|
||||
@SerializedName("notes")
|
||||
String notes;
|
||||
|
||||
/**
|
||||
* Gets the notes
|
||||
*/
|
||||
public String getNotes() {
|
||||
return this.notes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the notes
|
||||
*/
|
||||
public void setNotes(String value) {
|
||||
this.notes = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the taskH
|
||||
*/
|
||||
public TaskH getTaskH() {
|
||||
return this.taskH;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the taskH
|
||||
*/
|
||||
public void setTaskH(TaskH value) {
|
||||
this.taskH = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the taskD
|
||||
*/
|
||||
public List<TaskD> getTaskD() {
|
||||
return this.taskD;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the taskD
|
||||
*/
|
||||
public void setTaskD(List<TaskD> value) {
|
||||
this.taskD = value;
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 8.7 KiB |
|
@ -0,0 +1,59 @@
|
|||
package com.adins.mss.odr.accounts.adapter;
|
||||
|
||||
import android.animation.ValueAnimator;
|
||||
import android.view.View;
|
||||
import android.view.animation.DecelerateInterpolator;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.adins.mss.base.dynamicform.form.questions.viewholder.ExpandableRecyclerView;
|
||||
import com.adins.mss.odr.R;
|
||||
|
||||
/**
|
||||
* Created by muhammad.aap on 11/30/2018.
|
||||
*/
|
||||
|
||||
public class ButtonOpportunityViewHolder extends ExpandableRecyclerView.GroupViewHolder {
|
||||
public TextView text;
|
||||
private boolean expanded;
|
||||
|
||||
public ButtonOpportunityViewHolder(View view){
|
||||
super(view);
|
||||
text = (TextView) itemView.findViewById(R.id.lblListHeader);
|
||||
}
|
||||
|
||||
public void bind(String questioGroupName){
|
||||
setText(questioGroupName);
|
||||
}
|
||||
public void expand() {
|
||||
ValueAnimator animator = ValueAnimator.ofFloat(0, 1);
|
||||
animator.setInterpolator(new DecelerateInterpolator());
|
||||
animator.setDuration(200);
|
||||
animator.start();
|
||||
expanded = true;
|
||||
}
|
||||
|
||||
public void collapse() {
|
||||
ValueAnimator animator = ValueAnimator.ofFloat(1, 0);
|
||||
animator.setInterpolator(new DecelerateInterpolator());
|
||||
animator.setDuration(200);
|
||||
animator.start();
|
||||
expanded = false;
|
||||
}
|
||||
|
||||
public void setExpanded(boolean expanded) {
|
||||
this.expanded = expanded;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExpanded() {
|
||||
return expanded;
|
||||
}
|
||||
|
||||
public void setText(String t) {
|
||||
text.setText(t);
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text.getText().toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.adins.mss.odr.catalogue.api;
|
||||
|
||||
import com.adins.mss.foundation.http.MssRequestType;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
* Created by olivia.dg on 11/30/2017.
|
||||
*/
|
||||
|
||||
public class LoadPdfRequest extends MssRequestType {
|
||||
@SerializedName("uuid_mkt_catalogue")
|
||||
private String uuidCatalogue;
|
||||
|
||||
public String getUuidCatalogue() {
|
||||
return uuidCatalogue;
|
||||
}
|
||||
|
||||
public void setUuidCatalogue(String uuidCatalogue) {
|
||||
this.uuidCatalogue = uuidCatalogue;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
package com.adins.mss.dao;
|
||||
|
||||
import com.adins.mss.base.util.ExcludeFromGson;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. Enable "keep" sections if you want to edit.
|
||||
/**
|
||||
* Entity mapped to table "MS_PAYMENTCHANNEL".
|
||||
*/
|
||||
public class PaymentChannel {
|
||||
|
||||
/** Not-null value. */
|
||||
@SerializedName("uuid_paymentchannel")
|
||||
private String uuid_paymentchannel;
|
||||
@SerializedName("usr_crt")
|
||||
private String usr_crt;
|
||||
@SerializedName("dtm_crt")
|
||||
private java.util.Date dtm_crt;
|
||||
@SerializedName("is_active")
|
||||
private String is_active;
|
||||
@SerializedName("code")
|
||||
private String code;
|
||||
@SerializedName("description")
|
||||
private String description;
|
||||
@SerializedName("payment_limit")
|
||||
private Double payment_limit;
|
||||
|
||||
public PaymentChannel() {
|
||||
}
|
||||
|
||||
public PaymentChannel(String uuid_paymentchannel) {
|
||||
this.uuid_paymentchannel = uuid_paymentchannel;
|
||||
}
|
||||
|
||||
public PaymentChannel(String uuid_paymentchannel, String usr_crt, java.util.Date dtm_crt, String is_active, String code, String description, Double payment_limit) {
|
||||
this.uuid_paymentchannel = uuid_paymentchannel;
|
||||
this.usr_crt = usr_crt;
|
||||
this.dtm_crt = dtm_crt;
|
||||
this.is_active = is_active;
|
||||
this.code = code;
|
||||
this.description = description;
|
||||
this.payment_limit = payment_limit;
|
||||
}
|
||||
|
||||
/** Not-null value. */
|
||||
public String getUuid_paymentchannel() {
|
||||
return uuid_paymentchannel;
|
||||
}
|
||||
|
||||
/** Not-null value; ensure this value is available before it is saved to the database. */
|
||||
public void setUuid_paymentchannel(String uuid_paymentchannel) {
|
||||
this.uuid_paymentchannel = uuid_paymentchannel;
|
||||
}
|
||||
|
||||
public String getUsr_crt() {
|
||||
return usr_crt;
|
||||
}
|
||||
|
||||
public void setUsr_crt(String usr_crt) {
|
||||
this.usr_crt = usr_crt;
|
||||
}
|
||||
|
||||
public java.util.Date getDtm_crt() {
|
||||
return dtm_crt;
|
||||
}
|
||||
|
||||
public void setDtm_crt(java.util.Date dtm_crt) {
|
||||
this.dtm_crt = dtm_crt;
|
||||
}
|
||||
|
||||
public String getIs_active() {
|
||||
return is_active;
|
||||
}
|
||||
|
||||
public void setIs_active(String is_active) {
|
||||
this.is_active = is_active;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public Double getPayment_limit() {
|
||||
return payment_limit;
|
||||
}
|
||||
|
||||
public void setPayment_limit(Double payment_limit) {
|
||||
this.payment_limit = payment_limit;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.adins.mss.coll.api;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by adityapurwa on 16/03/15.
|
||||
*/
|
||||
public interface FakeSynchronizationCallback<T> {
|
||||
public void onSuccess(List<T> entities);
|
||||
|
||||
public void onFailed();
|
||||
}
|
|
@ -0,0 +1,194 @@
|
|||
package com.adins.mss.logger;
|
||||
|
||||
/**
|
||||
* Class for store all values of variables which needed to send when application crash
|
||||
*
|
||||
* @author bong.rk
|
||||
*/
|
||||
public class ErrorBean {
|
||||
private String timestamp;
|
||||
private String appVersionCode;
|
||||
private String appVersionName;
|
||||
private String packageName;
|
||||
private String phoneModel;
|
||||
private String brand;
|
||||
private String product;
|
||||
private String totalWebSize;
|
||||
private String availableMemSize;
|
||||
private String stackTrace;
|
||||
private String crashConfigutation;
|
||||
private String display;
|
||||
private String userAppStartDate;
|
||||
private String userCrashDate;
|
||||
private String dumpsysMeminfo;
|
||||
private String logcat;
|
||||
private String deviceId;
|
||||
private String installationId;
|
||||
private String sharedPreferences;
|
||||
private String settingsSystem;
|
||||
|
||||
public ErrorBean() {
|
||||
}
|
||||
|
||||
public String getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public void setTimestamp(String timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
public String getAppVersionCode() {
|
||||
return appVersionCode;
|
||||
}
|
||||
|
||||
public void setAppVersionCode(String appVersionCode) {
|
||||
this.appVersionCode = appVersionCode;
|
||||
}
|
||||
|
||||
public String getAppVersionName() {
|
||||
return appVersionName;
|
||||
}
|
||||
|
||||
public void setAppVersionName(String appVersionName) {
|
||||
this.appVersionName = appVersionName;
|
||||
}
|
||||
|
||||
public String getPackageName() {
|
||||
return packageName;
|
||||
}
|
||||
|
||||
public void setPackageName(String packageName) {
|
||||
this.packageName = packageName;
|
||||
}
|
||||
|
||||
public String getPhoneModel() {
|
||||
return phoneModel;
|
||||
}
|
||||
|
||||
public void setPhoneModel(String phoneModel) {
|
||||
this.phoneModel = phoneModel;
|
||||
}
|
||||
|
||||
public String getBrand() {
|
||||
return brand;
|
||||
}
|
||||
|
||||
public void setBrand(String brand) {
|
||||
this.brand = brand;
|
||||
}
|
||||
|
||||
public String getProduct() {
|
||||
return product;
|
||||
}
|
||||
|
||||
public void setProduct(String product) {
|
||||
this.product = product;
|
||||
}
|
||||
|
||||
public String getTotalWebSize() {
|
||||
return totalWebSize;
|
||||
}
|
||||
|
||||
public void setTotalWebSize(String totalWebSize) {
|
||||
this.totalWebSize = totalWebSize;
|
||||
}
|
||||
|
||||
public String getAvailableMemSize() {
|
||||
return availableMemSize;
|
||||
}
|
||||
|
||||
public void setAvailableMemSize(String availableMemSize) {
|
||||
this.availableMemSize = availableMemSize;
|
||||
}
|
||||
|
||||
public String getStackTrace() {
|
||||
return stackTrace;
|
||||
}
|
||||
|
||||
public void setStackTrace(String stackTrace) {
|
||||
this.stackTrace = stackTrace;
|
||||
}
|
||||
|
||||
public String getCrashConfigutation() {
|
||||
return crashConfigutation;
|
||||
}
|
||||
|
||||
public void setCrashConfigutation(String crashConfigutation) {
|
||||
this.crashConfigutation = crashConfigutation;
|
||||
}
|
||||
|
||||
public String getDisplay() {
|
||||
return display;
|
||||
}
|
||||
|
||||
public void setDisplay(String display) {
|
||||
this.display = display;
|
||||
}
|
||||
|
||||
public String getUserAppStartDate() {
|
||||
return userAppStartDate;
|
||||
}
|
||||
|
||||
public void setUserAppStartDate(String userAppStartDate) {
|
||||
this.userAppStartDate = userAppStartDate;
|
||||
}
|
||||
|
||||
public String getUserCrashDate() {
|
||||
return userCrashDate;
|
||||
}
|
||||
|
||||
public void setUserCrashDate(String userCrashDate) {
|
||||
this.userCrashDate = userCrashDate;
|
||||
}
|
||||
|
||||
public String getDumpsysMeminfo() {
|
||||
return dumpsysMeminfo;
|
||||
}
|
||||
|
||||
public void setDumpsysMeminfo(String dumpsysMeminfo) {
|
||||
this.dumpsysMeminfo = dumpsysMeminfo;
|
||||
}
|
||||
|
||||
public String getLogcat() {
|
||||
return logcat;
|
||||
}
|
||||
|
||||
public void setLogcat(String logcat) {
|
||||
this.logcat = logcat;
|
||||
}
|
||||
|
||||
public String getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
public void setDeviceId(String deviceId) {
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
public String getInstallationId() {
|
||||
return installationId;
|
||||
}
|
||||
|
||||
public void setInstallationId(String installationId) {
|
||||
this.installationId = installationId;
|
||||
}
|
||||
|
||||
public String getSharedPreferences() {
|
||||
return sharedPreferences;
|
||||
}
|
||||
|
||||
public void setSharedPreferences(String sharedPreferences) {
|
||||
this.sharedPreferences = sharedPreferences;
|
||||
}
|
||||
|
||||
public String getSettingsSystem() {
|
||||
return settingsSystem;
|
||||
}
|
||||
|
||||
public void setSettingsSystem(String settingsSystem) {
|
||||
this.settingsSystem = settingsSystem;
|
||||
}
|
||||
|
||||
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 27 KiB |
Binary file not shown.
|
@ -0,0 +1,341 @@
|
|||
package com.adins.mss.foundation.security.storepreferences;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
|
||||
import com.adins.mss.base.crashlytics.FireCrash;
|
||||
import com.adins.mss.foundation.security.SAKFormatter;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
/**
|
||||
* Thanks to emmby at http://stackoverflow.com/questions/785973/what-is-the-most-appropriate-way-to-store-user-settings-in-android-application/6393502#6393502
|
||||
* <p>
|
||||
* Documentation: http://right-handed-monkey.blogspot.com/2014/04/obscured-shared-preferences-for-android.html
|
||||
* This class has the following additions over the original:
|
||||
* additional logic for handling the case for when the preferences were not originally encrypted, but now are.
|
||||
* The secret key is no longer hard coded, but defined at runtime based on the individual device.
|
||||
* The benefit is that if one device is compromised, it now only affects that device.
|
||||
* <p>
|
||||
* Simply replace your own SharedPreferences object in this one, and any data you read/write will be automatically encrypted and decrypted.
|
||||
* <p>
|
||||
* Updated usage:
|
||||
* ObscuredSharedPreferences prefs = ObscuredSharedPreferences.getPrefs(this, MY_APP_NAME, Context.MODE_PRIVATE);
|
||||
* //to get data
|
||||
* prefs.getString("foo", null);
|
||||
* //to store data
|
||||
* prefs.edit().putString("foo","bar").commit();
|
||||
*/
|
||||
public class ObscuredSharedPreferences implements SharedPreferences {
|
||||
protected static final String UTF8 = "UTF-8";
|
||||
//Set to true if a decryption error was detected
|
||||
//in the case of float, int, and long we can tell if there was a parse error
|
||||
//this does not detect an error in strings or boolean - that requires more sophisticated checks
|
||||
public static boolean decryptionErrorFlag = false;
|
||||
//this key is defined at runtime based on ANDROID_ID which is supposed to last the life of the device
|
||||
private static char[] SEKRIT = null;
|
||||
private static byte[] SALT = null;
|
||||
private static char[] backup_secret = null;
|
||||
private static byte[] backup_salt = null;
|
||||
protected SharedPreferences delegate;
|
||||
protected Context context;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param context
|
||||
* @param delegate - SharedPreferences object from the system
|
||||
*/
|
||||
public ObscuredSharedPreferences(Context context, SharedPreferences delegate) {
|
||||
this.delegate = delegate;
|
||||
this.context = context;
|
||||
//updated thanks to help from bkhall on github
|
||||
ObscuredSharedPreferences.setNewKey(Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID));
|
||||
ObscuredSharedPreferences.setNewSalt(Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID));
|
||||
}
|
||||
|
||||
/**
|
||||
* Only used to change to a new key during runtime.
|
||||
* If you don't want to use the default per-device key for example
|
||||
*
|
||||
* @param key
|
||||
*/
|
||||
public static void setNewKey(String key) {
|
||||
SEKRIT = key.toCharArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Only used to change to a new salt during runtime.
|
||||
* If you don't want to use the default per-device code for example
|
||||
*
|
||||
* @param salt - this must be a string in UT
|
||||
*/
|
||||
public static void setNewSalt(String salt) {
|
||||
try {
|
||||
SALT = salt.getBytes(UTF8);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor to grab the preferences object
|
||||
* To improve performance for multiple accesses, please store the returned object in a variable for reuse
|
||||
*
|
||||
* @param c - the context used to access the preferences.
|
||||
* @param domainName - domain the shared preferences should be stored under
|
||||
* @param contextMode - Typically Context.MODE_PRIVATE
|
||||
* @return
|
||||
*/
|
||||
public synchronized static ObscuredSharedPreferences getPrefs(Context c, String domainName, int contextMode) {
|
||||
//make sure to use application context since preferences live outside an Activity
|
||||
//use for objects that have global scope like: prefs or starting services
|
||||
ObscuredSharedPreferences prefs = new ObscuredSharedPreferences(
|
||||
c.getApplicationContext(), c.getApplicationContext().getSharedPreferences(domainName, contextMode));
|
||||
return prefs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Push key allows you to hold the current key being used into a holding location so that it can be retrieved later
|
||||
* The use case is for when you need to load a new key, but still want to restore the old one.
|
||||
*/
|
||||
public static void pushKey() {
|
||||
backup_secret = SEKRIT;
|
||||
}
|
||||
|
||||
/**
|
||||
* This takes the key previously saved by pushKey() and activates it as the current decryption key
|
||||
*/
|
||||
public static void popKey() {
|
||||
SEKRIT = backup_secret;
|
||||
}
|
||||
|
||||
/**
|
||||
* pushSalt() allows you to hold the current salt being used into a holding location so that it can be retrieved later
|
||||
* The use case is for when you need to load a new salt, but still want to restore the old one.
|
||||
*/
|
||||
public static void pushSalt() {
|
||||
backup_salt = SALT;
|
||||
}
|
||||
|
||||
/**
|
||||
* This takes the value previously saved by pushSalt() and activates it as the current salt
|
||||
*/
|
||||
public static void popSalt() {
|
||||
SALT = backup_salt;
|
||||
}
|
||||
|
||||
public Editor edit() {
|
||||
return new Editor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, ?> getAll() {
|
||||
throw new UnsupportedOperationException(); // left as an exercise to the reader
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBoolean(String key, boolean defValue) {
|
||||
//if these weren't encrypted, then it won't be a string
|
||||
String v;
|
||||
try {
|
||||
v = delegate.getString(key, null);
|
||||
} catch (ClassCastException e) {
|
||||
return delegate.getBoolean(key, defValue);
|
||||
}
|
||||
//Boolean string values should be 'true' or 'false'
|
||||
//Boolean.parseBoolean does not throw a format exception, so check manually
|
||||
String parsed = decrypt(v);
|
||||
if (!checkBooleanString(parsed)) {
|
||||
//could not decrypt the Boolean. Maybe the wrong key was used.
|
||||
decryptionErrorFlag = true;
|
||||
Log.w(this.getClass().getName(), "Warning, could not decrypt the value. Possible incorrect key used.");
|
||||
}
|
||||
return v != null ? Boolean.parseBoolean(parsed) : defValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function checks if a valid string is received on a request for a Boolean object
|
||||
*
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
private boolean checkBooleanString(String str) {
|
||||
return ("true".equalsIgnoreCase(str) || "false".equalsIgnoreCase(str));
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getFloat(String key, float defValue) {
|
||||
String v;
|
||||
try {
|
||||
v = delegate.getString(key, null);
|
||||
} catch (ClassCastException e) {
|
||||
return delegate.getFloat(key, defValue);
|
||||
}
|
||||
try {
|
||||
return Float.parseFloat(decrypt(v));
|
||||
} catch (NumberFormatException e) {
|
||||
//could not decrypt the number. Maybe we are using the wrong key?
|
||||
decryptionErrorFlag = true;
|
||||
Log.e(this.getClass().getName(), "Warning, could not decrypt the value. Possible incorrect key. " + e.getMessage());
|
||||
}
|
||||
return defValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInt(String key, int defValue) {
|
||||
String v;
|
||||
try {
|
||||
v = delegate.getString(key, null);
|
||||
} catch (ClassCastException e) {
|
||||
return delegate.getInt(key, defValue);
|
||||
}
|
||||
try {
|
||||
return Integer.parseInt(decrypt(v));
|
||||
} catch (NumberFormatException e) {
|
||||
//could not decrypt the number. Maybe we are using the wrong key?
|
||||
decryptionErrorFlag = true;
|
||||
Log.e(this.getClass().getName(), "Warning, could not decrypt the value. Possible incorrect key. " + e.getMessage());
|
||||
}
|
||||
return defValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLong(String key, long defValue) {
|
||||
String v;
|
||||
try {
|
||||
v = delegate.getString(key, null);
|
||||
} catch (ClassCastException e) {
|
||||
return delegate.getLong(key, defValue);
|
||||
}
|
||||
try {
|
||||
return Long.parseLong(decrypt(v));
|
||||
} catch (NumberFormatException e) {
|
||||
//could not decrypt the number. Maybe we are using the wrong key?
|
||||
decryptionErrorFlag = true;
|
||||
Log.e(this.getClass().getName(), "Warning, could not decrypt the value. Possible incorrect key. " + e.getMessage());
|
||||
}
|
||||
return defValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString(String key, String defValue) {
|
||||
final String v = delegate.getString(key, null);
|
||||
return v != null ? decrypt(v) : defValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(String s) {
|
||||
return delegate.contains(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerOnSharedPreferenceChangeListener(OnSharedPreferenceChangeListener onSharedPreferenceChangeListener) {
|
||||
delegate.registerOnSharedPreferenceChangeListener(onSharedPreferenceChangeListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterOnSharedPreferenceChangeListener(OnSharedPreferenceChangeListener onSharedPreferenceChangeListener) {
|
||||
delegate.unregisterOnSharedPreferenceChangeListener(onSharedPreferenceChangeListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getStringSet(String key, Set<String> defValues) {
|
||||
throw new RuntimeException("This class does not work with String Sets.");
|
||||
}
|
||||
|
||||
protected String encrypt(String value) {
|
||||
|
||||
try {
|
||||
byte[] cryptedBytes = SAKFormatter.cipherData(value);
|
||||
String result = new String(cryptedBytes);
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected String decrypt(String value) {
|
||||
try {
|
||||
String result = SAKFormatter.decipherData(value);
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
Log.e(this.getClass().getName(), "Warning, could not decrypt the value. It may be stored in plaintext. " + e.getMessage());
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
public class Editor implements SharedPreferences.Editor {
|
||||
protected SharedPreferences.Editor delegate;
|
||||
|
||||
public Editor() {
|
||||
this.delegate = ObscuredSharedPreferences.this.delegate.edit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Editor putBoolean(String key, boolean value) {
|
||||
delegate.putString(key, encrypt(Boolean.toString(value)));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Editor putFloat(String key, float value) {
|
||||
delegate.putString(key, encrypt(Float.toString(value)));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Editor putInt(String key, int value) {
|
||||
delegate.putString(key, encrypt(Integer.toString(value)));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Editor putLong(String key, long value) {
|
||||
delegate.putString(key, encrypt(Long.toString(value)));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Editor putString(String key, String value) {
|
||||
delegate.putString(key, encrypt(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
//to maintain compatibility with android level 7
|
||||
delegate.commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Editor clear() {
|
||||
delegate.clear();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean commit() {
|
||||
return delegate.commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Editor remove(String s) {
|
||||
delegate.remove(s);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public android.content.SharedPreferences.Editor putStringSet(String key, Set<String> values) {
|
||||
throw new RuntimeException("This class does not work with String Sets.");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue