share_usage_data setting

This commit is contained in:
Akinwale Ariwodola 2020-11-29 05:07:54 +01:00
parent c179243d22
commit 6c406c5a85

View file

@ -72,6 +72,7 @@ import com.google.android.gms.tasks.Task;
import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.Snackbar;
import com.google.firebase.iid.FirebaseInstanceId; import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.InstanceIdResult; import com.google.firebase.iid.InstanceIdResult;
import com.google.firebase.messaging.FirebaseMessaging;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
@ -114,7 +115,9 @@ import org.json.JSONObject;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.ConnectException; import java.net.ConnectException;
import java.net.URI; import java.net.URI;
import java.text.DecimalFormat; import java.text.DecimalFormat;
@ -340,6 +343,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
public static final String PREFERENCE_KEY_KEEP_SDK_BACKGROUND = "io.lbry.browser.preference.other.KeepSdkInBackground"; public static final String PREFERENCE_KEY_KEEP_SDK_BACKGROUND = "io.lbry.browser.preference.other.KeepSdkInBackground";
public static final String PREFERENCE_KEY_PARTICIPATE_DATA_NETWORK = "io.lbry.browser.preference.other.ParticipateInDataNetwork"; public static final String PREFERENCE_KEY_PARTICIPATE_DATA_NETWORK = "io.lbry.browser.preference.other.ParticipateInDataNetwork";
public static final String PREFERENCE_KEY_SEND_BUFFERING_EVENTS = "io.lbry.browser.preference.other.SendBufferingEvents"; public static final String PREFERENCE_KEY_SEND_BUFFERING_EVENTS = "io.lbry.browser.preference.other.SendBufferingEvents";
public static final String PREFERENCE_KEY_SHARE_USAGE_DATA = "io.lbry.browser.preference.other.ShareUsageData";
// Internal flags / setting preferences // Internal flags / setting preferences
public static final String PREFERENCE_KEY_INTERNAL_SKIP_WALLET_ACCOUNT = "io.lbry.browser.preference.internal.WalletSkipAccount"; public static final String PREFERENCE_KEY_INTERNAL_SKIP_WALLET_ACCOUNT = "io.lbry.browser.preference.internal.WalletSkipAccount";
@ -436,14 +440,13 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
LbryAnalytics.init(this); LbryAnalytics.init(this);
try { try {
FirebaseInstanceId.getInstance().getInstanceId().addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() { FirebaseMessaging.getInstance().getToken().addOnCompleteListener(new OnCompleteListener<String>() {
@Override @Override
public void onComplete(Task<InstanceIdResult> task) { public void onComplete(@NonNull Task<String> task) {
if (!task.isSuccessful()) { if (!task.isSuccessful()) {
return; return;
} }
// Get new Instance ID token firebaseMessagingToken = task.getResult();
firebaseMessagingToken = task.getResult().getToken();
} }
}); });
} catch (IllegalStateException ex) { } catch (IllegalStateException ex) {
@ -1823,7 +1826,21 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
checkSyncedWallet(); checkSyncedWallet();
} }
(new Thread() {
public void run() {
Map<String, Object> params = new HashMap<>();
try {
Log.d(TAG, "Calling settings_get");
Log.d(TAG, ((JSONObject) Lbry.parseResponse(Lbry.apiCall("settings_get", params, Lbry.SDK_CONNECTION_STRING))).toString(2));
} catch (Exception ex) {
// pass
Log.d(TAG, ex.getMessage(), ex);
}
}
}).start();
//findViewById(R.id.global_sdk_initializing_status).setVisibility(View.GONE); //findViewById(R.id.global_sdk_initializing_status).setVisibility(View.GONE);
checkAndEnableShareUsageData();
scheduleWalletBalanceUpdate(); scheduleWalletBalanceUpdate();
scheduleWalletSyncTask(); scheduleWalletSyncTask();
@ -3730,6 +3747,51 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
} }
} }
private void checkAndEnableShareUsageData() {
final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
boolean shareUsageData = sp.getBoolean(PREFERENCE_KEY_SHARE_USAGE_DATA, false);
if (shareUsageData) {
return;
}
(new AsyncTask<Void, Void, Void>() {
protected Void doInBackground(Void... params) {
PrintStream out = null;
try {
String fileContent = "true";
String path = String.format("%s/sud", Utils.getAppInternalStorageDir(MainActivity.this));
out = new PrintStream(new FileOutputStream(path));
out.print(fileContent);
} catch (Exception ex) {
// pass
} finally {
Helper.closeCloseable(out);
}
return null;
}
protected void onPostExecute(Void result) {
updateSdkSetting("share_usage_data", true);
sp.edit().putBoolean(PREFERENCE_KEY_SHARE_USAGE_DATA, true).apply();
}
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
public void updateSdkSetting(String key, Object value) {
(new Thread() {
public void run() {
Map<String, Object> params = new HashMap<>();
params.put(key, value);
try {
Lbry.parseResponse(Lbry.apiCall("settings_set", params, Lbry.SDK_CONNECTION_STRING));
} catch (Exception ex) {
// pass
Log.d(TAG, ex.getMessage(), ex);
}
}
}).start();
}
public interface BackPressInterceptor { public interface BackPressInterceptor {
boolean onBackPressed(); boolean onBackPressed();
} }