First run changes #809
5 changed files with 57 additions and 20 deletions
2
app
2
app
|
@ -1 +1 @@
|
|||
Subproject commit 67723813ccf6cd6b3d62873a561e914c5deedf26
|
||||
Subproject commit c1f73c2766b60e7a1141dbf3c3833b480f215b83
|
|
@ -127,14 +127,6 @@ public class MainActivity extends Activity implements DefaultHardwareBackBtnHand
|
|||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
// Request external storage permission on Android version >= 6
|
||||
checkPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
||||
STORAGE_PERMISSION_REQ_CODE,
|
||||
"LBRY requires access to your device storage to be able to download files and media.",
|
||||
this);
|
||||
}
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
currentActivity = this;
|
||||
|
||||
|
@ -361,6 +353,7 @@ public class MainActivity extends Activity implements DefaultHardwareBackBtnHand
|
|||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
|
||||
ReactContext reactContext = mReactInstanceManager.getCurrentReactContext();
|
||||
switch (requestCode) {
|
||||
case STORAGE_PERMISSION_REQ_CODE:
|
||||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
|
@ -369,22 +362,25 @@ public class MainActivity extends Activity implements DefaultHardwareBackBtnHand
|
|||
Uri.parse("package:" + getPackageName()));
|
||||
startActivityForResult(intent, OVERLAY_PERMISSION_REQ_CODE);
|
||||
}
|
||||
} else {
|
||||
// Permission not granted. Show a message and terminate the application
|
||||
Toast.makeText(this,
|
||||
"LBRY requires access to your device storage to be able to download files and media." +
|
||||
" Please enable the storage permission and restart the app.", Toast.LENGTH_LONG).show();
|
||||
if (serviceRunning) {
|
||||
ServiceHelper.stop(this, LbrynetService.class);
|
||||
if (reactContext != null) {
|
||||
reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
||||
.emit("onStoragePermissionGranted", null);
|
||||
}
|
||||
} else {
|
||||
// Permission not granted
|
||||
/*Toast.makeText(this,
|
||||
"LBRY requires access to your device storage to be able to download files and media." +
|
||||
" Please enable the storage permission and restart the app.", Toast.LENGTH_LONG).show();*/
|
||||
if (reactContext != null) {
|
||||
reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
||||
.emit("onStoragePermissionRefused", null);
|
||||
}
|
||||
finish();
|
||||
}
|
||||
break;
|
||||
|
||||
case PHONE_STATE_PERMISSION_REQ_CODE:
|
||||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
// Permission granted. Emit an onPhoneStatePermissionGranted event
|
||||
ReactContext reactContext = mReactInstanceManager.getCurrentReactContext();
|
||||
if (reactContext != null) {
|
||||
reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
||||
.emit("onPhoneStatePermissionGranted", null);
|
||||
|
@ -399,7 +395,6 @@ public class MainActivity extends Activity implements DefaultHardwareBackBtnHand
|
|||
case RECEIVE_SMS_PERMISSION_REQ_CODE:
|
||||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
// Permission granted. Emit an onPhoneStatePermissionGranted event
|
||||
ReactContext reactContext = mReactInstanceManager.getCurrentReactContext();
|
||||
if (reactContext != null) {
|
||||
reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
||||
.emit("onReceiveSmsPermissionGranted", null);
|
||||
|
@ -605,6 +600,15 @@ public class MainActivity extends Activity implements DefaultHardwareBackBtnHand
|
|||
true);
|
||||
}
|
||||
|
||||
public static void checkStoragePermission(Context context) {
|
||||
// Request read phone state permission
|
||||
checkPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
||||
STORAGE_PERMISSION_REQ_CODE,
|
||||
"LBRY requires access to your device storage to be able to download files and media.",
|
||||
context,
|
||||
true);
|
||||
}
|
||||
|
||||
private boolean isServiceRunning(Class<?> serviceClass) {
|
||||
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
|
||||
for (ActivityManager.RunningServiceInfo serviceInfo : manager.getRunningServices(Integer.MAX_VALUE)) {
|
||||
|
|
|
@ -62,6 +62,8 @@ public final class Utils {
|
|||
|
||||
public static final String SDK_URL = "http://127.0.0.1:5279";
|
||||
|
||||
public static final String SP_DOWNLOAD_DIR_KEY = "download_dir";
|
||||
|
||||
public static String getAndroidRelease() {
|
||||
return android.os.Build.VERSION.RELEASE;
|
||||
}
|
||||
|
@ -114,6 +116,16 @@ public final class Utils {
|
|||
return file.getAbsolutePath();
|
||||
}
|
||||
|
||||
public static String getConfiguredDownloadDirectory(Context context) {
|
||||
// use the default folder (usually [private files]/Download with WRITE_EXTERNAL_STOAGE permission not granted)
|
||||
// if none is configured or specified
|
||||
String defaultDirectory = String.format("%s/Download", getInternalStorageDir(context));
|
||||
|
||||
SharedPreferences pref = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
|
||||
String downloadDirectory = pref.getString(SP_DOWNLOAD_DIR_KEY, defaultDirectory);
|
||||
return downloadDirectory;
|
||||
}
|
||||
|
||||
public static void saveApiSecret(String secret, Context context, KeyStore keyStore) {
|
||||
try {
|
||||
SharedPreferences pref = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
|
||||
|
|
|
@ -207,6 +207,19 @@ public class UtilityModule extends ReactContextBaseJavaModule {
|
|||
}
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void canReadWriteStorage(final Promise promise) {
|
||||
promise.resolve(MainActivity.hasPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, MainActivity.getActivity()));
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void requestStoragePermission() {
|
||||
MainActivity activity = (MainActivity) MainActivity.getActivity();
|
||||
if (activity != null) {
|
||||
MainActivity.checkStoragePermission(activity);
|
||||
}
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void shareLogFile(Callback errorCallback) {
|
||||
String logFileName = "lbrynet.log";
|
||||
|
@ -450,4 +463,10 @@ public class UtilityModule extends ReactContextBaseJavaModule {
|
|||
|
||||
promise.resolve(null);
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void getDownloadDirectory(Promise promise) {
|
||||
// This obtains a public default download directory after the storage permission has been granted
|
||||
promise.resolve(Utils.getConfiguredDownloadDirectory(context));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,10 +73,12 @@ def configure_logging(conf):
|
|||
def start():
|
||||
keyring.set_keyring(LbryAndroidKeyring())
|
||||
private_storage_dir = lbrynet_android_utils.getAppInternalStorageDir(service.getApplicationContext())
|
||||
configured_download_dir = lbrynet_android_utils.getConfiguredDownloadDirectory(service.getApplicationContext())
|
||||
print('configured_download_dir={}'.format(configured_download_dir))
|
||||
conf = Config(
|
||||
data_dir=f'{private_storage_dir}/lbrynet',
|
||||
wallet_dir=f'{private_storage_dir}/lbryum',
|
||||
download_dir=f'{lbrynet_android_utils.getInternalStorageDir(service.getApplicationContext())}/Download',
|
||||
download_dir=configured_download_dir,
|
||||
blob_lru_cache_size=32,
|
||||
components_to_skip=[DHT_COMPONENT, HASH_ANNOUNCER_COMPONENT, PEER_PROTOCOL_SERVER_COMPONENT],
|
||||
save_blobs=False,
|
||||
|
|
Loading…
Reference in a new issue