Challenge/response, fixes

This commit is contained in:
M66B 2015-12-31 10:03:32 +01:00
parent 62564e2190
commit 12fb62fea0
8 changed files with 165 additions and 68 deletions

View File

@ -542,7 +542,8 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
return true;
case R.id.menu_app_system:
if (IAB.isPurchased(ActivityPro.SKU_SELECT, ActivityMain.this)) {
boolean manage = prefs.getBoolean("manage_system", false);
if (manage == !item.isChecked() || IAB.isPurchased(ActivityPro.SKU_SELECT, ActivityMain.this)) {
item.setChecked(!item.isChecked());
prefs.edit().putBoolean("show_system", item.isChecked()).apply();
} else

View File

@ -22,13 +22,19 @@ package eu.faircode.netguard;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
public class ActivityPro extends AppCompatActivity {
@ -38,12 +44,12 @@ public class ActivityPro extends AppCompatActivity {
// adb shell pm clear com.android.vending
public static final String SKU_SELECT = "select";
public static final String SKU_DEFAULTS = "defaults";
//public static final String SKU_NOTIFY = "notify";
public static final String SKU_THEME = "theme";
public static final String SKU_SPEED = "speed";
public static final String SKU_BACKUP = "backup";
public static final String SKU_DONATION = "donation";
//public static final String SKU_DEFAULTS = "android.test.purchased";
public static final String SKU_NOTIFY = "android.test.purchased";
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -56,8 +62,37 @@ public class ActivityPro extends AppCompatActivity {
getSupportActionBar().setTitle(R.string.title_pro);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
updateState();
TextView tvChallenge = (TextView) findViewById(R.id.tvChallenge);
tvChallenge.setText(Build.SERIAL);
EditText etResponse = (EditText) findViewById(R.id.etResponse);
etResponse.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// Do nothing
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// Do nothing
}
@Override
public void afterTextChanged(Editable editable) {
try {
if (Util.sha256(Build.SERIAL, "").equals(editable.toString())) {
IAB.setBought(SKU_DONATION, ActivityPro.this);
updateState();
}
} catch (Throwable ex) {
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
}
}
});
try {
iab = new IAB(new IAB.Delegate() {
@Override
@ -67,7 +102,7 @@ public class ActivityPro extends AppCompatActivity {
iab.isPurchased(SKU_DONATION);
final Button btnSelect = (Button) findViewById(R.id.btnSelect);
final Button btnDefaults = (Button) findViewById(R.id.btnDefaults);
final Button btnNotify = (Button) findViewById(R.id.btnNotify);
final Button btnTheme = (Button) findViewById(R.id.btnTheme);
final Button btnSpeed = (Button) findViewById(R.id.btnSpeed);
final Button btnBackup = (Button) findViewById(R.id.btnBackup);
@ -78,8 +113,8 @@ public class ActivityPro extends AppCompatActivity {
try {
if (view == btnSelect)
startIntentSenderForResult(iab.getBuyIntent(SKU_SELECT).getIntentSender(), view.getId(), new Intent(), 0, 0, 0);
else if (view == btnDefaults)
startIntentSenderForResult(iab.getBuyIntent(SKU_DEFAULTS).getIntentSender(), view.getId(), new Intent(), 0, 0, 0);
else if (view == btnNotify)
startIntentSenderForResult(iab.getBuyIntent(SKU_NOTIFY).getIntentSender(), view.getId(), new Intent(), 0, 0, 0);
else if (view == btnTheme)
startIntentSenderForResult(iab.getBuyIntent(SKU_THEME).getIntentSender(), view.getId(), new Intent(), 0, 0, 0);
else if (view == btnSpeed)
@ -94,13 +129,13 @@ public class ActivityPro extends AppCompatActivity {
};
btnSelect.setOnClickListener(listener);
btnDefaults.setOnClickListener(listener);
btnNotify.setOnClickListener(listener);
btnTheme.setOnClickListener(listener);
btnSpeed.setOnClickListener(listener);
btnBackup.setOnClickListener(listener);
btnSelect.setEnabled(true);
btnDefaults.setEnabled(true);
btnNotify.setEnabled(true);
btnTheme.setEnabled(true);
btnSpeed.setEnabled(true);
btnBackup.setEnabled(true);
@ -140,8 +175,8 @@ public class ActivityPro extends AppCompatActivity {
IAB.setBought(SKU_SELECT, this);
updateState();
break;
case R.id.btnDefaults:
IAB.setBought(SKU_DEFAULTS, this);
case R.id.btnNotify:
IAB.setBought(SKU_NOTIFY, this);
updateState();
break;
case R.id.btnTheme:
@ -162,26 +197,29 @@ public class ActivityPro extends AppCompatActivity {
private void updateState() {
Button btnSelect = (Button) findViewById(R.id.btnSelect);
Button btnDefaults = (Button) findViewById(R.id.btnDefaults);
Button btnNotify = (Button) findViewById(R.id.btnNotify);
Button btnTheme = (Button) findViewById(R.id.btnTheme);
Button btnSpeed = (Button) findViewById(R.id.btnSpeed);
Button btnBackup = (Button) findViewById(R.id.btnBackup);
TextView tvSelect = (TextView) findViewById(R.id.tvSelect);
TextView tvDefaults = (TextView) findViewById(R.id.tvDefaults);
TextView tvNotify = (TextView) findViewById(R.id.tvNotify);
TextView tvTheme = (TextView) findViewById(R.id.tvTheme);
TextView tvSpeed = (TextView) findViewById(R.id.tvSpeed);
TextView tvBackup = (TextView) findViewById(R.id.tvBackup);
LinearLayout llChallenge = (LinearLayout) findViewById(R.id.llChallenge);
btnSelect.setVisibility(IAB.isPurchased(SKU_SELECT, this) ? View.GONE : View.VISIBLE);
btnDefaults.setVisibility(IAB.isPurchased(SKU_DEFAULTS, this) ? View.GONE : View.VISIBLE);
btnNotify.setVisibility(IAB.isPurchased(SKU_NOTIFY, this) ? View.GONE : View.VISIBLE);
btnTheme.setVisibility(IAB.isPurchased(SKU_THEME, this) ? View.GONE : View.VISIBLE);
btnSpeed.setVisibility(IAB.isPurchased(SKU_SPEED, this) ? View.GONE : View.VISIBLE);
btnBackup.setVisibility(IAB.isPurchased(SKU_BACKUP, this) ? View.GONE : View.VISIBLE);
tvSelect.setVisibility(IAB.isPurchased(SKU_SELECT, this) ? View.VISIBLE : View.GONE);
tvDefaults.setVisibility(IAB.isPurchased(SKU_DEFAULTS, this) ? View.VISIBLE : View.GONE);
tvNotify.setVisibility(IAB.isPurchased(SKU_NOTIFY, this) ? View.VISIBLE : View.GONE);
tvTheme.setVisibility(IAB.isPurchased(SKU_THEME, this) ? View.VISIBLE : View.GONE);
tvSpeed.setVisibility(IAB.isPurchased(SKU_SPEED, this) ? View.VISIBLE : View.GONE);
tvBackup.setVisibility(IAB.isPurchased(SKU_BACKUP, this) ? View.VISIBLE : View.GONE);
llChallenge.setVisibility(IAB.isPurchased(SKU_DONATION, this) ? View.GONE : View.VISIBLE);
}
}

View File

@ -279,18 +279,8 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere
@Override
@TargetApi(Build.VERSION_CODES.M)
public void onSharedPreferenceChanged(SharedPreferences prefs, String name) {
if ("whitelist_wifi".equals(name) ||
"screen_wifi".equals(name) ||
"whitelist_other".equals(name) ||
"screen_other".equals(name) ||
"whitelist_roaming".equals(name)) {
if (prefs.getBoolean(name, false) && !IAB.isPurchased(ActivityPro.SKU_DEFAULTS, this)) {
prefs.edit().putBoolean(name, false).apply();
((SwitchPreference) getPreferenceScreen().findPreference(name)).setChecked(false);
startActivity(new Intent(this, ActivityPro.class));
return;
}
} else if ("dark_theme".equals(name)) {
// Pro features
if ("dark_theme".equals(name)) {
if (prefs.getBoolean(name, false) && !IAB.isPurchased(ActivityPro.SKU_THEME, this)) {
prefs.edit().putBoolean(name, false).apply();
((SwitchPreference) getPreferenceScreen().findPreference(name)).setChecked(false);
@ -322,16 +312,9 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere
requestPermissions(new String[]{Manifest.permission.READ_PHONE_STATE}, REQUEST_ROAMING_INTERNATIONAL);
} else
SinkholeService.reload("other", "setting changed", this);
} else if ("manage_system".equals(name)) {
SharedPreferences.Editor editor = prefs.edit();
if (prefs.getBoolean(name, false)) {
editor.putBoolean("show_system", true);
editor.putBoolean("show_user", true);
} else {
editor.putBoolean("show_user", true);
editor.putBoolean("show_system", false);
}
editor.apply();
prefs.edit().putBoolean("show_system", prefs.getBoolean(name, false)).apply();
SinkholeService.reload(null, "setting changed", this);
} else if ("auto_enable".equals(name))

View File

@ -160,7 +160,7 @@ public class IAB implements ServiceConnection {
public static boolean isPurchased(String sku, Context context) {
SharedPreferences prefs = context.getSharedPreferences("IAB", Context.MODE_PRIVATE);
return (prefs.getBoolean(sku, false) || prefs.getBoolean(ActivityPro.SKU_DONATION, false) || Util.isDebuggable(context));
return (prefs.getBoolean(sku, false) || prefs.getBoolean(ActivityPro.SKU_DONATION, false));
}
public static String getResult(int responseCode) {

View File

@ -49,8 +49,10 @@ public class Receiver extends BroadcastReceiver {
// Application added
if (!intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
// Show notification
int uid = intent.getIntExtra(Intent.EXTRA_UID, 0);
notifyApplication(uid, context);
if (IAB.isPurchased(ActivityPro.SKU_NOTIFY, context)) {
int uid = intent.getIntExtra(Intent.EXTRA_UID, 0);
notifyApplication(uid, context);
}
}
} else if (Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())) {
@ -110,7 +112,8 @@ public class Receiver extends BroadcastReceiver {
// Build notification
Intent main = new Intent(context, ActivityMain.class);
main.putExtra(ActivityMain.EXTRA_SEARCH, name);
if (IAB.isPurchased(ActivityPro.SKU_SELECT, context))
main.putExtra(ActivityMain.EXTRA_SEARCH, name);
PendingIntent pi = PendingIntent.getActivity(context, 999, main, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder notification = new NotificationCompat.Builder(context)

View File

@ -52,9 +52,11 @@ import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -515,6 +517,17 @@ public class Util {
return sb.toString();
}
public static String sha256(String text, String salt) throws NoSuchAlgorithmException, UnsupportedEncodingException {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] bytes = (text + salt).getBytes("UTF-8");
digest.update(bytes, 0, bytes.length);
bytes = digest.digest();
StringBuilder sb = new StringBuilder();
for (byte b : bytes)
sb.append(String.format("%02X", b));
return sb.toString();
}
public static void sendLogcat(final Uri uri, final Context context) {
AsyncTask task = new AsyncTask<Object, Object, Intent>() {
@Override

View File

@ -15,19 +15,29 @@
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_pro_description"
android:textAppearance="@android:style/TextAppearance.Material.Medium" />
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:layout_marginTop="8dp">
<TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:layout_width="0dp"
android:layout_height="?android:attr/listPreferredItemHeight"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center_vertical"
android:text="@string/title_pro_select"
android:textAppearance="@android:style/TextAppearance.Material.Medium" />
android:textAppearance="@android:style/TextAppearance.Material.Small" />
<Button
android:id="@+id/btnSelect"
@ -42,7 +52,7 @@
<TextView
android:id="@+id/tvSelect"
android:layout_width="0dp"
android:layout_height="?android:attr/listPreferredItemHeight"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical|center_horizontal"
android:text="@string/title_pro_bought"
@ -51,30 +61,33 @@
android:visibility="gone" />
</TableRow>
<TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:layout_width="0dp"
android:layout_height="?android:attr/listPreferredItemHeight"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center_vertical"
android:text="@string/title_pro_defaults"
android:textAppearance="@android:style/TextAppearance.Material.Medium" />
android:text="@string/title_pro_notify"
android:textAppearance="@android:style/TextAppearance.Material.Small" />
<Button
android:id="@+id/btnDefaults"
android:id="@+id/btnNotify"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:enabled="false"
android:gravity="center_vertical|center_horizontal"
android:text="@string/title_pro_buy"
android:visibility="gone" />
<TextView
android:id="@+id/tvDefaults"
android:id="@+id/tvNotify"
android:layout_width="0dp"
android:layout_height="?android:attr/listPreferredItemHeight"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical|center_horizontal"
android:text="@string/title_pro_bought"
@ -83,30 +96,33 @@
android:visibility="gone" />
</TableRow>
<TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:layout_width="0dp"
android:layout_height="?android:attr/listPreferredItemHeight"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center_vertical"
android:text="@string/title_pro_theme"
android:textAppearance="@android:style/TextAppearance.Material.Medium" />
android:textAppearance="@android:style/TextAppearance.Material.Small" />
<Button
android:id="@+id/btnTheme"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:enabled="false"
android:gravity="center_vertical|center_horizontal"
android:text="@string/title_pro_buy"
android:visibility="gone" />
<TextView
android:id="@+id/tvTheme"
android:layout_width="0dp"
android:layout_height="?android:attr/listPreferredItemHeight"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical|center_horizontal"
android:text="@string/title_pro_bought"
@ -115,30 +131,33 @@
android:visibility="gone" />
</TableRow>
<TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:layout_width="0dp"
android:layout_height="?android:attr/listPreferredItemHeight"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center_vertical"
android:text="@string/title_pro_speed"
android:textAppearance="@android:style/TextAppearance.Material.Medium" />
android:textAppearance="@android:style/TextAppearance.Material.Small" />
<Button
android:id="@+id/btnSpeed"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:enabled="false"
android:gravity="center_vertical|center_horizontal"
android:text="@string/title_pro_buy"
android:visibility="gone" />
<TextView
android:id="@+id/tvSpeed"
android:layout_width="0dp"
android:layout_height="?android:attr/listPreferredItemHeight"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical|center_horizontal"
android:text="@string/title_pro_bought"
@ -147,30 +166,33 @@
android:visibility="gone" />
</TableRow>
<TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:layout_width="0dp"
android:layout_height="?android:attr/listPreferredItemHeight"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center_vertical"
android:text="@string/title_pro_backup"
android:textAppearance="@android:style/TextAppearance.Material.Medium" />
android:textAppearance="@android:style/TextAppearance.Material.Small" />
<Button
android:id="@+id/btnBackup"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:enabled="false"
android:gravity="center_vertical|center_horizontal"
android:text="@string/title_pro_buy"
android:visibility="gone" />
<TextView
android:id="@+id/tvBackup"
android:layout_width="0dp"
android:layout_height="?android:attr/listPreferredItemHeight"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical|center_horizontal"
android:text="@string/title_pro_bought"
@ -179,6 +201,40 @@
android:visibility="gone" />
</TableRow>
</TableLayout>
<LinearLayout
android:id="@+id/llChallenge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/title_pro_challenge"
android:textAppearance="@android:style/TextAppearance.Material.Medium" />
<TextView
android:id="@+id/tvChallenge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_pro_challenge"
android:textAppearance="@android:style/TextAppearance.Material.Medium"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/title_pro_reponse"
android:textAppearance="@android:style/TextAppearance.Material.Medium" />
<EditText
android:id="@+id/etResponse"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>

View File

@ -94,13 +94,16 @@ Since NetGuard has no internet permission, you know your internet traffic is not
<string name="title_block">Block</string>
<string name="title_pro">Pro features</string>
<string name="title_pro_description">You can buy the following convenience features:</string>
<string name="title_pro_select">Search, filter, sort</string>
<string name="title_pro_defaults">Rule defaults</string>
<string name="title_pro_notify">New application notification</string>
<string name="title_pro_theme">Theme</string>
<string name="title_pro_speed">Speed notification graph</string>
<string name="title_pro_backup">Export/import</string>
<string name="title_pro_buy">Details</string>
<string name="title_pro_bought">Enabled</string>
<string name="title_pro_challenge">Challenge</string>
<string name="title_pro_reponse">Response</string>
<string name="fingerprint" translatable="false">ef46f813d2c8a064d72c936b9b96d1cccc989378</string>
</resources>