Prevent crash

This commit is contained in:
M66B 2019-08-04 15:47:38 +02:00
parent a1462c210b
commit 4f540a2f10
5 changed files with 39 additions and 35 deletions

View File

@ -1071,38 +1071,41 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
final Intent settings = new Intent(
Settings.ACTION_IGNORE_BACKGROUND_DATA_RESTRICTIONS_SETTINGS,
Uri.parse("package:" + getPackageName()));
if (Util.dataSaving(this) && getPackageManager().resolveActivity(settings, 0) != null) {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
if (!prefs.getBoolean("nodata", false)) {
LayoutInflater inflater = LayoutInflater.from(this);
View view = inflater.inflate(R.layout.datasaving, null, false);
final CheckBox cbDontAsk = view.findViewById(R.id.cbDontAsk);
dialogDoze = new AlertDialog.Builder(this)
.setView(view)
.setCancelable(true)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
prefs.edit().putBoolean("nodata", cbDontAsk.isChecked()).apply();
startActivity(settings);
}
})
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
prefs.edit().putBoolean("nodata", cbDontAsk.isChecked()).apply();
}
})
.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialogInterface) {
dialogDoze = null;
}
})
.create();
dialogDoze.show();
if (Util.dataSaving(this) && getPackageManager().resolveActivity(settings, 0) != null)
try {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
if (!prefs.getBoolean("nodata", false)) {
LayoutInflater inflater = LayoutInflater.from(this);
View view = inflater.inflate(R.layout.datasaving, null, false);
final CheckBox cbDontAsk = view.findViewById(R.id.cbDontAsk);
dialogDoze = new AlertDialog.Builder(this)
.setView(view)
.setCancelable(true)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
prefs.edit().putBoolean("nodata", cbDontAsk.isChecked()).apply();
startActivity(settings);
}
})
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
prefs.edit().putBoolean("nodata", cbDontAsk.isChecked()).apply();
}
})
.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialogInterface) {
dialogDoze = null;
}
})
.create();
dialogDoze.show();
}
} catch (Throwable ex) {
Log.e(TAG, ex + "\n" + ex.getStackTrace());
}
}
}
}

View File

@ -2387,6 +2387,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
@Override
public void onCreate() {
Log.i(TAG, "Create version=" + Util.getSelfVersionName(this) + "/" + Util.getSelfVersionCode(this));
startForeground(NOTIFY_WAITING, getWaitingNotification());
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

View File

@ -21,7 +21,6 @@ package eu.faircode.netguard;
import android.annotation.TargetApi;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.Icon;
import android.os.Build;
@ -74,7 +73,7 @@ public class ServiceTileFilter extends TileService implements SharedPreferences.
prefs.edit().putBoolean("filter", !prefs.getBoolean("filter", false)).apply();
ServiceSinkhole.reload("tile", this, false);
} else
startActivity(new Intent(this, ActivityPro.class));
Toast.makeText(this, R.string.title_pro_feature, Toast.LENGTH_SHORT).show();
} else
Toast.makeText(this, R.string.msg_unavailable, Toast.LENGTH_SHORT).show();
}

View File

@ -21,7 +21,6 @@ package eu.faircode.netguard;
import android.annotation.TargetApi;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.Icon;
import android.os.Build;
@ -29,6 +28,7 @@ import android.preference.PreferenceManager;
import android.service.quicksettings.Tile;
import android.service.quicksettings.TileService;
import android.util.Log;
import android.widget.Toast;
@TargetApi(Build.VERSION_CODES.N)
public class ServiceTileGraph extends TileService implements SharedPreferences.OnSharedPreferenceChangeListener {
@ -71,7 +71,7 @@ public class ServiceTileGraph extends TileService implements SharedPreferences.O
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean stats = !prefs.getBoolean("show_stats", false);
if (stats && !IAB.isPurchased(ActivityPro.SKU_SPEED, this))
startActivity(new Intent(this, ActivityPro.class));
Toast.makeText(this, R.string.title_pro_feature, Toast.LENGTH_SHORT).show();
else
prefs.edit().putBoolean("show_stats", stats).apply();
ServiceSinkhole.reloadStats("tile", this);

View File

@ -304,6 +304,7 @@ Your internet traffic is not being sent to a remote VPN server.</string>
<string name="title_pro_details">Tap on a title for more information</string>
<string name="title_pro_challenge">Challenge</string>
<string name="title_pro_reponse">Response</string>
<string name="title_pro_feature">This is a pro feature</string>
<string-array name="themeNames">
<item>teal/orange</item>