2018-03-31 10:28:26 +01:00
|
|
|
package io.lbry.browser;
|
2017-12-28 19:06:31 +01:00
|
|
|
|
2019-09-05 15:59:51 +01:00
|
|
|
import android.annotation.SuppressLint;
|
2019-07-09 01:43:30 +01:00
|
|
|
import android.annotation.TargetApi;
|
2018-03-11 16:32:13 +01:00
|
|
|
import android.os.Build;
|
2017-12-28 19:06:31 +01:00
|
|
|
import android.os.Bundle;
|
2019-09-05 15:59:51 +01:00
|
|
|
import android.os.Environment;
|
2017-12-28 19:06:31 +01:00
|
|
|
import android.app.Activity;
|
2018-03-11 16:32:13 +01:00
|
|
|
import android.app.ActivityManager;
|
2018-08-20 16:00:16 +01:00
|
|
|
import android.content.BroadcastReceiver;
|
2019-09-05 15:59:51 +01:00
|
|
|
import android.content.ContentUris;
|
2018-03-11 16:32:13 +01:00
|
|
|
import android.content.Context;
|
2018-04-19 22:43:15 +01:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.IntentFilter;
|
2018-03-26 22:09:02 +01:00
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.content.SharedPreferences;
|
2019-08-30 18:31:49 +01:00
|
|
|
import android.database.Cursor;
|
2018-03-26 22:09:02 +01:00
|
|
|
import android.Manifest;
|
2018-03-11 16:32:13 +01:00
|
|
|
import android.net.Uri;
|
2019-09-05 15:59:51 +01:00
|
|
|
import android.provider.DocumentsContract;
|
2019-08-30 18:31:49 +01:00
|
|
|
import android.provider.MediaStore;
|
2018-03-11 16:32:13 +01:00
|
|
|
import android.provider.Settings;
|
2018-06-20 19:07:20 +01:00
|
|
|
import android.support.v4.app.ActivityCompat;
|
2018-08-20 16:00:16 +01:00
|
|
|
import android.support.v4.app.NotificationManagerCompat;
|
2018-06-20 19:07:20 +01:00
|
|
|
import android.support.v4.content.ContextCompat;
|
2018-09-03 02:57:54 +01:00
|
|
|
import android.telephony.SmsMessage;
|
2018-06-20 19:07:20 +01:00
|
|
|
import android.telephony.TelephonyManager;
|
2018-03-26 22:09:02 +01:00
|
|
|
import android.widget.Toast;
|
2017-12-28 19:06:31 +01:00
|
|
|
|
2018-03-18 15:42:16 +01:00
|
|
|
import com.brentvatne.react.ReactVideoPackage;
|
2018-09-01 22:04:50 +01:00
|
|
|
import com.dylanvann.fastimage.FastImageViewPackage;
|
2017-12-28 19:06:31 +01:00
|
|
|
import com.facebook.react.common.LifecycleState;
|
|
|
|
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
|
|
|
|
import com.facebook.react.ReactRootView;
|
|
|
|
import com.facebook.react.ReactInstanceManager;
|
2018-09-03 02:57:54 +01:00
|
|
|
import com.facebook.react.bridge.Arguments;
|
2018-08-20 16:00:16 +01:00
|
|
|
import com.facebook.react.bridge.ReactContext;
|
2019-05-27 10:30:33 +01:00
|
|
|
import com.facebook.react.bridge.WritableArray;
|
2018-09-03 02:57:54 +01:00
|
|
|
import com.facebook.react.bridge.WritableMap;
|
2018-08-20 16:00:16 +01:00
|
|
|
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
2019-07-09 01:43:30 +01:00
|
|
|
import com.facebook.react.modules.core.PermissionAwareActivity;
|
|
|
|
import com.facebook.react.modules.core.PermissionListener;
|
2017-12-28 19:06:31 +01:00
|
|
|
import com.facebook.react.shell.MainReactPackage;
|
2019-04-05 09:13:35 +01:00
|
|
|
import com.facebook.react.ReactRootView;
|
|
|
|
import com.reactnativecommunity.asyncstorage.AsyncStoragePackage;
|
2019-07-09 01:43:30 +01:00
|
|
|
import com.rnfs.RNFSPackage;
|
2019-04-05 09:13:35 +01:00
|
|
|
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;
|
|
|
|
import com.swmansion.gesturehandler.react.RNGestureHandlerPackage;
|
2019-08-13 12:32:38 +01:00
|
|
|
import com.swmansion.reanimated.ReanimatedPackage;
|
2018-08-13 10:00:02 +01:00
|
|
|
import com.RNFetchBlob.RNFetchBlobPackage;
|
2017-12-28 19:06:31 +01:00
|
|
|
|
2018-03-31 10:28:26 +01:00
|
|
|
import io.lbry.browser.reactpackages.LbryReactPackage;
|
2018-08-20 16:00:16 +01:00
|
|
|
import io.lbry.browser.reactmodules.BackgroundMediaModule;
|
2018-03-18 15:42:16 +01:00
|
|
|
|
2019-08-30 18:31:49 +01:00
|
|
|
import java.io.File;
|
2018-06-20 19:07:20 +01:00
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
import java.math.BigInteger;
|
2019-08-30 18:31:49 +01:00
|
|
|
import java.net.URISyntaxException;
|
2018-06-20 19:07:20 +01:00
|
|
|
import java.security.MessageDigest;
|
|
|
|
import java.security.NoSuchAlgorithmException;
|
2018-09-02 17:54:37 +01:00
|
|
|
import java.util.ArrayList;
|
2019-05-27 10:30:33 +01:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Iterator;
|
2018-09-02 17:54:37 +01:00
|
|
|
import java.util.List;
|
2018-06-20 19:07:20 +01:00
|
|
|
import java.util.Random;
|
|
|
|
|
2019-05-27 10:30:33 +01:00
|
|
|
import org.json.JSONObject;
|
|
|
|
import org.json.JSONArray;
|
|
|
|
import org.json.JSONException;
|
2019-07-09 01:43:30 +01:00
|
|
|
import org.reactnative.camera.RNCameraPackage;
|
2019-05-27 10:30:33 +01:00
|
|
|
|
2019-07-09 01:43:30 +01:00
|
|
|
public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler, PermissionAwareActivity {
|
2018-06-08 09:13:45 +01:00
|
|
|
|
2018-08-16 18:42:07 +01:00
|
|
|
private static Activity currentActivity = null;
|
|
|
|
|
2018-03-11 16:32:13 +01:00
|
|
|
private static final int OVERLAY_PERMISSION_REQ_CODE = 101;
|
2018-06-08 09:13:45 +01:00
|
|
|
|
|
|
|
private static final int STORAGE_PERMISSION_REQ_CODE = 201;
|
|
|
|
|
2018-06-20 19:07:20 +01:00
|
|
|
private static final int PHONE_STATE_PERMISSION_REQ_CODE = 202;
|
|
|
|
|
2018-09-03 02:57:54 +01:00
|
|
|
private static final int RECEIVE_SMS_PERMISSION_REQ_CODE = 203;
|
2019-08-30 18:31:49 +01:00
|
|
|
|
|
|
|
public static final int DOCUMENT_PICKER_RESULT_CODE = 301;
|
2018-08-22 13:50:59 +01:00
|
|
|
|
2019-01-21 17:11:31 +01:00
|
|
|
private BroadcastReceiver notificationsReceiver;
|
2018-08-20 16:00:16 +01:00
|
|
|
|
2018-09-03 02:57:54 +01:00
|
|
|
private BroadcastReceiver smsReceiver;
|
|
|
|
|
|
|
|
private BroadcastReceiver stopServiceReceiver;
|
|
|
|
|
2019-05-27 10:30:33 +01:00
|
|
|
private BroadcastReceiver downloadEventReceiver;
|
|
|
|
|
2017-12-28 19:06:31 +01:00
|
|
|
private ReactRootView mReactRootView;
|
2018-06-08 09:13:45 +01:00
|
|
|
|
2017-12-28 19:06:31 +01:00
|
|
|
private ReactInstanceManager mReactInstanceManager;
|
2018-06-08 09:13:45 +01:00
|
|
|
|
2018-03-26 22:09:02 +01:00
|
|
|
public static final String SHARED_PREFERENCES_NAME = "LBRY";
|
2018-06-08 09:13:45 +01:00
|
|
|
|
2018-06-20 19:07:20 +01:00
|
|
|
public static final String SALT_KEY = "salt";
|
|
|
|
|
|
|
|
public static final String DEVICE_ID_KEY = "deviceId";
|
|
|
|
|
2019-01-21 17:11:31 +01:00
|
|
|
public static final String SOURCE_NOTIFICATION_ID_KEY = "sourceNotificationId";
|
|
|
|
|
2018-08-06 11:51:55 +01:00
|
|
|
public static final String SETTING_KEEP_DAEMON_RUNNING = "keepDaemonRunning";
|
|
|
|
|
2018-09-02 17:54:37 +01:00
|
|
|
public static List<Integer> downloadNotificationIds = new ArrayList<Integer>();
|
|
|
|
|
2018-03-11 16:32:13 +01:00
|
|
|
/**
|
|
|
|
* Flag which indicates whether or not the service is running. Will be updated in the
|
|
|
|
* onResume method.
|
|
|
|
*/
|
|
|
|
private boolean serviceRunning;
|
2018-06-08 09:13:45 +01:00
|
|
|
|
2018-09-03 03:00:54 +01:00
|
|
|
private boolean receivedStopService;
|
|
|
|
|
2019-07-09 01:43:30 +01:00
|
|
|
private PermissionListener permissionListener;
|
|
|
|
|
2018-05-25 08:13:05 +01:00
|
|
|
protected String getMainComponentName() {
|
|
|
|
return "LBRYApp";
|
|
|
|
}
|
2018-06-08 09:13:45 +01:00
|
|
|
|
2017-12-28 19:06:31 +01:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
2018-03-26 22:09:02 +01:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
|
// Request external storage permission on Android version >= 6
|
2018-06-20 19:07:20 +01:00
|
|
|
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);
|
2018-03-11 16:32:13 +01:00
|
|
|
}
|
2018-06-08 09:13:45 +01:00
|
|
|
|
2017-12-28 19:06:31 +01:00
|
|
|
super.onCreate(savedInstanceState);
|
2018-08-16 18:42:07 +01:00
|
|
|
currentActivity = this;
|
2018-06-08 09:13:45 +01:00
|
|
|
|
2018-08-22 13:50:59 +01:00
|
|
|
// Register the stop service receiver (so that we close the activity if the user requests the service to stop)
|
|
|
|
registerStopReceiver();
|
|
|
|
|
2018-09-03 02:57:54 +01:00
|
|
|
// Register SMS receiver for handling verification texts
|
|
|
|
registerSmsReceiver();
|
|
|
|
|
2019-05-27 10:30:33 +01:00
|
|
|
// Register the receiver to emit download events
|
|
|
|
registerDownloadEventReceiver();
|
|
|
|
|
2018-03-11 16:32:13 +01:00
|
|
|
// Start the daemon service if it is not started
|
|
|
|
serviceRunning = isServiceRunning(LbrynetService.class);
|
|
|
|
if (!serviceRunning) {
|
|
|
|
ServiceHelper.start(this, "", LbrynetService.class, "lbrynetservice");
|
|
|
|
}
|
2018-06-08 09:13:45 +01:00
|
|
|
|
2019-04-05 09:13:35 +01:00
|
|
|
mReactRootView = new RNGestureHandlerEnabledRootView(this);
|
2017-12-28 19:06:31 +01:00
|
|
|
mReactInstanceManager = ReactInstanceManager.builder()
|
|
|
|
.setApplication(getApplication())
|
|
|
|
.setBundleAssetName("index.android.bundle")
|
|
|
|
.setJSMainModulePath("index")
|
|
|
|
.addPackage(new MainReactPackage())
|
2019-04-05 09:13:35 +01:00
|
|
|
.addPackage(new AsyncStoragePackage())
|
2018-09-01 22:04:50 +01:00
|
|
|
.addPackage(new FastImageViewPackage())
|
2018-03-18 15:42:16 +01:00
|
|
|
.addPackage(new ReactVideoPackage())
|
2019-08-13 12:32:38 +01:00
|
|
|
.addPackage(new ReanimatedPackage())
|
2019-07-09 01:43:30 +01:00
|
|
|
.addPackage(new RNCameraPackage())
|
2018-08-13 10:00:02 +01:00
|
|
|
.addPackage(new RNFetchBlobPackage())
|
2019-07-09 01:43:30 +01:00
|
|
|
.addPackage(new RNFSPackage())
|
2019-04-05 09:13:35 +01:00
|
|
|
.addPackage(new RNGestureHandlerPackage())
|
2018-03-18 15:42:16 +01:00
|
|
|
.addPackage(new LbryReactPackage())
|
|
|
|
.setUseDeveloperSupport(true)
|
2017-12-28 19:06:31 +01:00
|
|
|
.setInitialLifecycleState(LifecycleState.RESUMED)
|
|
|
|
.build();
|
|
|
|
mReactRootView.startReactApplication(mReactInstanceManager, "LBRYApp", null);
|
|
|
|
|
2019-01-21 17:11:31 +01:00
|
|
|
registerNotificationsReceiver();
|
2018-08-20 16:00:16 +01:00
|
|
|
|
2017-12-28 19:06:31 +01:00
|
|
|
setContentView(mReactRootView);
|
|
|
|
}
|
2018-06-08 09:13:45 +01:00
|
|
|
|
2019-05-27 10:30:33 +01:00
|
|
|
private void registerDownloadEventReceiver() {
|
|
|
|
IntentFilter intentFilter = new IntentFilter();
|
|
|
|
intentFilter.addAction(DownloadManager.ACTION_DOWNLOAD_EVENT);
|
|
|
|
downloadEventReceiver = new BroadcastReceiver() {
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
String downloadAction = intent.getStringExtra("action");
|
|
|
|
String uri = intent.getStringExtra("uri");
|
|
|
|
String outpoint = intent.getStringExtra("outpoint");
|
|
|
|
String fileInfoJson = intent.getStringExtra("file_info");
|
|
|
|
|
|
|
|
if (uri == null || outpoint == null || fileInfoJson == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
String eventName = null;
|
|
|
|
JSONObject json = new JSONObject(fileInfoJson);
|
|
|
|
WritableMap fileInfo = JSONObjectToMap(json);
|
|
|
|
WritableMap params = Arguments.createMap();
|
|
|
|
params.putString("uri", uri);
|
|
|
|
params.putString("outpoint", outpoint);
|
|
|
|
params.putMap("fileInfo", fileInfo);
|
|
|
|
|
|
|
|
if (DownloadManager.ACTION_UPDATE.equals(downloadAction)) {
|
|
|
|
double progress = intent.getDoubleExtra("progress", 0);
|
|
|
|
params.putDouble("progress", progress);
|
|
|
|
eventName = "onDownloadUpdated";
|
|
|
|
} else {
|
|
|
|
eventName = (DownloadManager.ACTION_START.equals(downloadAction)) ? "onDownloadStarted" : "onDownloadCompleted";
|
|
|
|
}
|
|
|
|
|
|
|
|
ReactContext reactContext = mReactInstanceManager.getCurrentReactContext();
|
|
|
|
if (reactContext != null) {
|
|
|
|
reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(eventName, params);
|
|
|
|
}
|
|
|
|
} catch (JSONException ex) {
|
|
|
|
// pass
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
registerReceiver(downloadEventReceiver, intentFilter);
|
|
|
|
}
|
|
|
|
|
2018-08-22 13:50:59 +01:00
|
|
|
private void registerStopReceiver() {
|
|
|
|
IntentFilter intentFilter = new IntentFilter();
|
|
|
|
intentFilter.addAction(LbrynetService.ACTION_STOP_SERVICE);
|
|
|
|
stopServiceReceiver = new BroadcastReceiver() {
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
2018-09-03 03:00:54 +01:00
|
|
|
MainActivity.this.receivedStopService = true;
|
2018-08-22 13:50:59 +01:00
|
|
|
MainActivity.this.finish();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
registerReceiver(stopServiceReceiver, intentFilter);
|
|
|
|
}
|
|
|
|
|
2019-01-21 17:11:31 +01:00
|
|
|
private void registerNotificationsReceiver() {
|
2018-08-20 16:00:16 +01:00
|
|
|
// Background media receiver
|
2019-01-21 17:11:31 +01:00
|
|
|
IntentFilter filter = new IntentFilter();
|
|
|
|
filter.addAction(BackgroundMediaModule.ACTION_PLAY);
|
|
|
|
filter.addAction(BackgroundMediaModule.ACTION_PAUSE);
|
|
|
|
notificationsReceiver = new BroadcastReceiver() {
|
2018-08-20 16:00:16 +01:00
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
String action = intent.getAction();
|
|
|
|
ReactContext reactContext = mReactInstanceManager.getCurrentReactContext();
|
|
|
|
if (reactContext != null) {
|
|
|
|
if (BackgroundMediaModule.ACTION_PLAY.equals(action)) {
|
|
|
|
reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
|
|
.emit("onBackgroundPlayPressed", null);
|
|
|
|
}
|
|
|
|
if (BackgroundMediaModule.ACTION_PAUSE.equals(action)) {
|
|
|
|
reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
|
|
.emit("onBackgroundPausePressed", null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2019-01-21 17:11:31 +01:00
|
|
|
registerReceiver(notificationsReceiver, filter);
|
2018-08-20 16:00:16 +01:00
|
|
|
}
|
|
|
|
|
2018-09-03 02:57:54 +01:00
|
|
|
public void registerSmsReceiver() {
|
|
|
|
if (!hasPermission(Manifest.permission.RECEIVE_SMS, this)) {
|
|
|
|
// don't create the receiver if we don't have the read sms permission
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
IntentFilter smsFilter = new IntentFilter();
|
|
|
|
smsFilter.addAction("android.provider.Telephony.SMS_RECEIVED");
|
|
|
|
smsReceiver = new BroadcastReceiver() {
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
// Get the message
|
|
|
|
Bundle bundle = intent.getExtras();
|
|
|
|
if (bundle != null) {
|
|
|
|
Object[] pdus = (Object[]) bundle.get("pdus");
|
|
|
|
if (pdus != null && pdus.length > 0) {
|
|
|
|
SmsMessage sms = SmsMessage.createFromPdu((byte[]) pdus[0]);
|
|
|
|
String text = sms.getMessageBody();
|
|
|
|
if (text == null || text.trim().length() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Retrieve verification code from the text message if it contains
|
|
|
|
// the strings "lbry", "verification code" and the colon (following the expected format)
|
|
|
|
text = text.toLowerCase();
|
|
|
|
if (text.indexOf("lbry") > -1 && text.indexOf("verification code") > -1 && text.indexOf(":") > -1) {
|
|
|
|
String code = text.substring(text.lastIndexOf(":") + 1).trim();
|
|
|
|
ReactContext reactContext = mReactInstanceManager.getCurrentReactContext();
|
|
|
|
if (reactContext != null) {
|
|
|
|
WritableMap params = Arguments.createMap();
|
|
|
|
params.putString("code", code);
|
|
|
|
reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
|
|
.emit("onVerificationCodeReceived", params);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
registerReceiver(smsReceiver, smsFilter);
|
|
|
|
}
|
2019-08-30 18:31:49 +01:00
|
|
|
|
2018-03-11 16:32:13 +01:00
|
|
|
@Override
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
if (requestCode == OVERLAY_PERMISSION_REQ_CODE) {
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
|
if (!Settings.canDrawOverlays(this)) {
|
|
|
|
// SYSTEM_ALERT_WINDOW permission not granted...
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-08-30 18:31:49 +01:00
|
|
|
|
|
|
|
if (requestCode == DOCUMENT_PICKER_RESULT_CODE) {
|
|
|
|
ReactContext reactContext = mReactInstanceManager.getCurrentReactContext();
|
|
|
|
if (reactContext != null) {
|
|
|
|
if (resultCode == RESULT_OK) {
|
|
|
|
Uri fileUri = data.getData();
|
2019-09-05 15:59:51 +01:00
|
|
|
String filePath = getRealPathFromURI_API19(this, fileUri);
|
|
|
|
WritableMap params = Arguments.createMap();
|
|
|
|
params.putString("path", filePath);
|
|
|
|
reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
|
|
.emit("onDocumentPickerFilePicked", params);
|
2019-08-30 18:31:49 +01:00
|
|
|
} else if (resultCode == RESULT_CANCELED) {
|
|
|
|
// user canceled or request failed
|
|
|
|
reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
|
|
.emit("onDocumentPickerCanceled", null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-03-11 16:32:13 +01:00
|
|
|
}
|
2018-06-08 09:13:45 +01:00
|
|
|
|
2018-08-16 18:42:07 +01:00
|
|
|
public static Activity getActivity() {
|
|
|
|
Activity activity = new Activity();
|
|
|
|
activity = currentActivity;
|
|
|
|
return activity;
|
|
|
|
}
|
|
|
|
|
2018-03-26 22:09:02 +01:00
|
|
|
@Override
|
|
|
|
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
|
|
|
|
switch (requestCode) {
|
|
|
|
case STORAGE_PERMISSION_REQ_CODE:
|
|
|
|
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
2018-05-19 23:35:43 +01:00
|
|
|
if (BuildConfig.DEBUG && !Settings.canDrawOverlays(this)) {
|
2018-03-26 22:09:02 +01:00
|
|
|
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
break;
|
2018-06-20 19:07:20 +01:00
|
|
|
|
|
|
|
case PHONE_STATE_PERMISSION_REQ_CODE:
|
|
|
|
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
2018-08-28 11:59:14 +01:00
|
|
|
// Permission granted. Emit an onPhoneStatePermissionGranted event
|
|
|
|
ReactContext reactContext = mReactInstanceManager.getCurrentReactContext();
|
|
|
|
if (reactContext != null) {
|
|
|
|
reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
|
|
.emit("onPhoneStatePermissionGranted", null);
|
|
|
|
}
|
2018-06-20 19:07:20 +01:00
|
|
|
} else {
|
|
|
|
// Permission not granted. Simply show a message.
|
|
|
|
Toast.makeText(this,
|
|
|
|
"No permission granted to read your device state. Rewards cannot be claimed.", Toast.LENGTH_LONG).show();
|
|
|
|
}
|
|
|
|
break;
|
2018-09-03 02:57:54 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
// register the receiver
|
|
|
|
if (smsReceiver == null) {
|
|
|
|
registerSmsReceiver();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Permission not granted. Simply show a message.
|
|
|
|
Toast.makeText(this,
|
|
|
|
"No permission granted to receive your SMS messages. You may have to enter the verification code manually.",
|
|
|
|
Toast.LENGTH_LONG).show();
|
|
|
|
}
|
|
|
|
break;
|
2018-03-26 22:09:02 +01:00
|
|
|
}
|
2019-07-09 01:43:30 +01:00
|
|
|
|
|
|
|
if (permissionListener != null) {
|
|
|
|
permissionListener.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
|
|
|
}
|
2018-03-26 22:09:02 +01:00
|
|
|
}
|
2017-12-28 19:06:31 +01:00
|
|
|
|
2018-06-20 19:07:20 +01:00
|
|
|
public static String acquireDeviceId(Context context) {
|
|
|
|
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
|
|
|
String id = null;
|
|
|
|
try {
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
|
id = telephonyManager.getImei(); // GSM
|
|
|
|
if (id == null) {
|
|
|
|
id = telephonyManager.getMeid(); // CDMA
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
id = telephonyManager.getDeviceId();
|
|
|
|
}
|
|
|
|
} catch (SecurityException ex) {
|
|
|
|
// Maybe the permission was not granted? Try to acquire permission
|
|
|
|
checkPhoneStatePermission(context);
|
|
|
|
} catch (Exception ex) {
|
|
|
|
// id could not be obtained. Display a warning that rewards cannot be claimed.
|
|
|
|
}
|
|
|
|
|
|
|
|
if (id == null || id.trim().length() == 0) {
|
|
|
|
Toast.makeText(context, "Rewards cannot be claimed because we could not identify your device.", Toast.LENGTH_LONG).show();
|
|
|
|
}
|
|
|
|
|
2018-08-16 10:48:34 +01:00
|
|
|
SharedPreferences sp = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
|
|
|
|
SharedPreferences.Editor editor = sp.edit();
|
|
|
|
editor.putString(DEVICE_ID_KEY, id);
|
|
|
|
editor.commit();
|
2018-06-20 19:07:20 +01:00
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2017-12-28 19:06:31 +01:00
|
|
|
@Override
|
|
|
|
public void invokeDefaultOnBackPressed() {
|
|
|
|
super.onBackPressed();
|
|
|
|
}
|
2018-06-08 09:13:45 +01:00
|
|
|
|
2017-12-28 19:06:31 +01:00
|
|
|
@Override
|
|
|
|
protected void onPause() {
|
|
|
|
super.onPause();
|
2018-06-08 09:13:45 +01:00
|
|
|
|
2017-12-28 19:06:31 +01:00
|
|
|
if (mReactInstanceManager != null) {
|
|
|
|
mReactInstanceManager.onHostPause(this);
|
|
|
|
}
|
|
|
|
}
|
2018-06-08 09:13:45 +01:00
|
|
|
|
2017-12-28 19:06:31 +01:00
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
|
|
|
super.onResume();
|
2018-06-08 09:13:45 +01:00
|
|
|
|
|
|
|
SharedPreferences sp = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
|
2018-06-18 14:20:37 +01:00
|
|
|
serviceRunning = isServiceRunning(LbrynetService.class);
|
|
|
|
if (!serviceRunning) {
|
|
|
|
ServiceHelper.start(this, "", LbrynetService.class, "lbrynetservice");
|
2018-03-11 16:32:13 +01:00
|
|
|
}
|
2018-06-08 09:13:45 +01:00
|
|
|
|
2017-12-28 19:06:31 +01:00
|
|
|
if (mReactInstanceManager != null) {
|
|
|
|
mReactInstanceManager.onHostResume(this, this);
|
|
|
|
}
|
|
|
|
}
|
2018-06-08 09:13:45 +01:00
|
|
|
|
2017-12-28 19:06:31 +01:00
|
|
|
@Override
|
|
|
|
protected void onDestroy() {
|
2018-03-26 22:09:02 +01:00
|
|
|
// check service running setting and end it here
|
|
|
|
SharedPreferences sp = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
|
2018-08-06 11:51:55 +01:00
|
|
|
boolean shouldKeepDaemonRunning = sp.getBoolean(SETTING_KEEP_DAEMON_RUNNING, true);
|
2018-03-26 22:09:02 +01:00
|
|
|
if (!shouldKeepDaemonRunning) {
|
|
|
|
serviceRunning = isServiceRunning(LbrynetService.class);
|
|
|
|
if (serviceRunning) {
|
|
|
|
ServiceHelper.stop(this, LbrynetService.class);
|
|
|
|
}
|
|
|
|
}
|
2018-04-19 22:43:15 +01:00
|
|
|
|
2019-01-21 17:11:31 +01:00
|
|
|
if (notificationsReceiver != null) {
|
|
|
|
unregisterReceiver(notificationsReceiver);
|
|
|
|
notificationsReceiver = null;
|
2018-08-22 13:50:59 +01:00
|
|
|
}
|
|
|
|
|
2018-09-03 02:57:54 +01:00
|
|
|
if (smsReceiver != null) {
|
|
|
|
unregisterReceiver(smsReceiver);
|
|
|
|
smsReceiver = null;
|
|
|
|
}
|
|
|
|
|
2019-05-27 10:30:33 +01:00
|
|
|
if (downloadEventReceiver != null) {
|
|
|
|
unregisterReceiver(downloadEventReceiver);
|
|
|
|
downloadEventReceiver = null;
|
|
|
|
}
|
|
|
|
|
2018-08-22 13:50:59 +01:00
|
|
|
if (stopServiceReceiver != null) {
|
|
|
|
unregisterReceiver(stopServiceReceiver);
|
|
|
|
stopServiceReceiver = null;
|
2018-08-20 16:00:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
|
2018-09-02 17:54:37 +01:00
|
|
|
notificationManager.cancel(BackgroundMediaModule.NOTIFICATION_ID);
|
2019-05-27 10:30:33 +01:00
|
|
|
notificationManager.cancel(DownloadManager.DOWNLOAD_NOTIFICATION_GROUP_ID);
|
2018-09-02 17:54:37 +01:00
|
|
|
if (downloadNotificationIds != null) {
|
|
|
|
for (int i = 0; i < downloadNotificationIds.size(); i++) {
|
|
|
|
notificationManager.cancel(downloadNotificationIds.get(i));
|
|
|
|
}
|
|
|
|
}
|
2018-09-03 03:00:54 +01:00
|
|
|
if (receivedStopService || !isServiceRunning(LbrynetService.class)) {
|
|
|
|
notificationManager.cancelAll();
|
|
|
|
}
|
2017-12-28 19:06:31 +01:00
|
|
|
super.onDestroy();
|
2018-06-08 09:13:45 +01:00
|
|
|
|
2017-12-28 19:06:31 +01:00
|
|
|
if (mReactInstanceManager != null) {
|
|
|
|
mReactInstanceManager.onHostDestroy(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
|
|
|
if (mReactInstanceManager != null) {
|
|
|
|
mReactInstanceManager.onBackPressed();
|
|
|
|
} else {
|
|
|
|
super.onBackPressed();
|
|
|
|
}
|
2018-03-26 22:09:02 +01:00
|
|
|
}
|
2018-06-08 09:13:45 +01:00
|
|
|
|
2019-07-09 01:43:30 +01:00
|
|
|
@TargetApi(Build.VERSION_CODES.M)
|
|
|
|
public void requestPermissions(String[] permissions, int requestCode, PermissionListener listener) {
|
|
|
|
permissionListener = listener;
|
|
|
|
ActivityCompat.requestPermissions(this, permissions, requestCode);
|
|
|
|
}
|
|
|
|
|
2018-05-25 08:13:05 +01:00
|
|
|
@Override
|
|
|
|
public void onNewIntent(Intent intent) {
|
|
|
|
if (mReactInstanceManager != null) {
|
|
|
|
mReactInstanceManager.onNewIntent(intent);
|
|
|
|
}
|
2019-01-21 17:11:31 +01:00
|
|
|
|
|
|
|
if (intent != null) {
|
|
|
|
int sourceNotificationId = intent.getIntExtra(SOURCE_NOTIFICATION_ID_KEY, -1);
|
|
|
|
if (sourceNotificationId > -1) {
|
|
|
|
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
|
|
|
|
notificationManager.cancel(sourceNotificationId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-25 08:13:05 +01:00
|
|
|
super.onNewIntent(intent);
|
|
|
|
}
|
2018-06-08 09:13:45 +01:00
|
|
|
|
2018-08-28 11:59:14 +01:00
|
|
|
private static void checkPermission(String permission, int requestCode, String rationale, Context context, boolean forceRequest) {
|
2018-06-20 19:07:20 +01:00
|
|
|
if (ContextCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) {
|
|
|
|
// Should we show an explanation?
|
2018-08-28 11:59:14 +01:00
|
|
|
if (!forceRequest && ActivityCompat.shouldShowRequestPermissionRationale((Activity) context, permission)) {
|
2018-06-20 19:07:20 +01:00
|
|
|
Toast.makeText(context, rationale, Toast.LENGTH_LONG).show();
|
|
|
|
} else {
|
|
|
|
ActivityCompat.requestPermissions((Activity) context, new String[] { permission }, requestCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-28 11:59:14 +01:00
|
|
|
private static void checkPermission(String permission, int requestCode, String rationale, Context context) {
|
|
|
|
checkPermission(permission, requestCode, rationale, context, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean hasPermission(String permission, Context context) {
|
|
|
|
return (ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void checkPhoneStatePermission(Context context) {
|
2018-06-20 19:07:20 +01:00
|
|
|
// Request read phone state permission
|
|
|
|
checkPermission(Manifest.permission.READ_PHONE_STATE,
|
|
|
|
PHONE_STATE_PERMISSION_REQ_CODE,
|
|
|
|
"LBRY requires optional access to be able to identify your device for rewards. " +
|
|
|
|
"You cannot claim rewards without this permission.",
|
2018-08-28 11:59:14 +01:00
|
|
|
context,
|
|
|
|
true);
|
2018-06-20 19:07:20 +01:00
|
|
|
}
|
|
|
|
|
2018-09-03 02:57:54 +01:00
|
|
|
public static void checkReceiveSmsPermission(Context context) {
|
|
|
|
// Request read phone state permission
|
|
|
|
checkPermission(Manifest.permission.RECEIVE_SMS,
|
|
|
|
RECEIVE_SMS_PERMISSION_REQ_CODE,
|
|
|
|
"LBRY requires access to be able to read a verification text message for rewards.",
|
|
|
|
context,
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
|
2018-03-26 22:09:02 +01:00
|
|
|
private boolean isServiceRunning(Class<?> serviceClass) {
|
2018-03-11 16:32:13 +01:00
|
|
|
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
|
|
|
|
for (ActivityManager.RunningServiceInfo serviceInfo : manager.getRunningServices(Integer.MAX_VALUE)) {
|
|
|
|
if (serviceClass.getName().equals(serviceInfo.service.getClassName())) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2017-12-28 19:06:31 +01:00
|
|
|
|
2018-03-11 16:32:13 +01:00
|
|
|
return false;
|
|
|
|
}
|
2019-05-27 10:30:33 +01:00
|
|
|
|
|
|
|
private static WritableMap JSONObjectToMap(JSONObject jsonObject) throws JSONException {
|
|
|
|
WritableMap map = Arguments.createMap();
|
|
|
|
Iterator<String> keys = jsonObject.keys();
|
|
|
|
while(keys.hasNext()) {
|
|
|
|
String key = keys.next();
|
|
|
|
Object value = jsonObject.get(key);
|
|
|
|
if (value instanceof JSONArray) {
|
|
|
|
map.putArray(key, JSONArrayToList((JSONArray) value));
|
|
|
|
} else if (value instanceof JSONObject) {
|
|
|
|
map.putMap(key, JSONObjectToMap((JSONObject) value));
|
|
|
|
} else if (value instanceof Boolean) {
|
|
|
|
map.putBoolean(key, (Boolean) value);
|
|
|
|
} else if (value instanceof Integer) {
|
|
|
|
map.putInt(key, (Integer) value);
|
|
|
|
} else if (value instanceof Double) {
|
|
|
|
map.putDouble(key, (Double) value);
|
|
|
|
} else if (value instanceof String) {
|
|
|
|
map.putString(key, (String) value);
|
|
|
|
} else {
|
|
|
|
map.putString(key, value.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static WritableArray JSONArrayToList(JSONArray jsonArray) throws JSONException {
|
|
|
|
WritableArray array = Arguments.createArray();
|
|
|
|
for(int i = 0; i < jsonArray.length(); i++) {
|
|
|
|
Object value = jsonArray.get(i);
|
|
|
|
if (value instanceof JSONArray) {
|
|
|
|
array.pushArray(JSONArrayToList((JSONArray) value));
|
|
|
|
} else if (value instanceof JSONObject) {
|
|
|
|
array.pushMap(JSONObjectToMap((JSONObject) value));
|
|
|
|
} else if (value instanceof Boolean) {
|
|
|
|
array.pushBoolean((Boolean) value);
|
|
|
|
} else if (value instanceof Integer) {
|
|
|
|
array.pushInt((Integer) value);
|
|
|
|
} else if (value instanceof Double) {
|
|
|
|
array.pushDouble((Double) value);
|
|
|
|
} else if (value instanceof String) {
|
|
|
|
array.pushString((String) value);
|
|
|
|
} else {
|
|
|
|
array.pushString(value.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return array;
|
|
|
|
}
|
2019-09-05 15:59:51 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* https://gist.github.com/HBiSoft/15899990b8cd0723c3a894c1636550a8
|
|
|
|
*/
|
|
|
|
@SuppressLint("NewApi")
|
|
|
|
public static String getRealPathFromURI_API19(final Context context, final Uri uri) {
|
|
|
|
|
|
|
|
final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
|
|
|
|
|
|
|
|
// DocumentProvider
|
|
|
|
if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
|
|
|
|
// ExternalStorageProvider
|
|
|
|
if (isExternalStorageDocument(uri)) {
|
|
|
|
final String docId = DocumentsContract.getDocumentId(uri);
|
|
|
|
final String[] split = docId.split(":");
|
|
|
|
final String type = split[0];
|
|
|
|
|
|
|
|
// This is for checking Main Memory
|
|
|
|
if ("primary".equalsIgnoreCase(type)) {
|
|
|
|
if (split.length > 1) {
|
|
|
|
return Environment.getExternalStorageDirectory() + "/" + split[1];
|
|
|
|
} else {
|
|
|
|
return Environment.getExternalStorageDirectory() + "/";
|
|
|
|
}
|
|
|
|
// This is for checking SD Card
|
|
|
|
} else {
|
|
|
|
return "storage" + "/" + docId.replace(":", "/");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
// DownloadsProvider
|
|
|
|
else if (isDownloadsDocument(uri)) {
|
|
|
|
String fileName = getFilePath(context, uri);
|
|
|
|
if (fileName != null) {
|
|
|
|
return Environment.getExternalStorageDirectory().toString() + "/Download/" + fileName;
|
|
|
|
}
|
|
|
|
|
|
|
|
String id = DocumentsContract.getDocumentId(uri);
|
|
|
|
if (id.startsWith("raw:")) {
|
|
|
|
id = id.replaceFirst("raw:", "");
|
|
|
|
File file = new File(id);
|
|
|
|
if (file.exists())
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
|
|
|
|
return getDataColumn(context, contentUri, null, null);
|
|
|
|
}
|
|
|
|
// MediaProvider
|
|
|
|
else if (isMediaDocument(uri)) {
|
|
|
|
final String docId = DocumentsContract.getDocumentId(uri);
|
|
|
|
final String[] split = docId.split(":");
|
|
|
|
final String type = split[0];
|
|
|
|
|
|
|
|
Uri contentUri = null;
|
|
|
|
if ("image".equals(type)) {
|
|
|
|
contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
|
|
|
|
} else if ("video".equals(type)) {
|
|
|
|
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
|
|
|
|
} else if ("audio".equals(type)) {
|
|
|
|
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
|
|
|
|
}
|
|
|
|
|
|
|
|
final String selection = "_id=?";
|
|
|
|
final String[] selectionArgs = new String[]{
|
|
|
|
split[1]
|
|
|
|
};
|
|
|
|
|
|
|
|
return getDataColumn(context, contentUri, selection, selectionArgs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// MediaStore (and general)
|
|
|
|
else if ("content".equalsIgnoreCase(uri.getScheme())) {
|
|
|
|
|
|
|
|
// Return the remote address
|
|
|
|
if (isGooglePhotosUri(uri))
|
|
|
|
return uri.getLastPathSegment();
|
|
|
|
|
|
|
|
return getDataColumn(context, uri, null, null);
|
|
|
|
}
|
|
|
|
// File
|
|
|
|
else if ("file".equalsIgnoreCase(uri.getScheme())) {
|
|
|
|
return uri.getPath();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
|
|
|
|
Cursor cursor = null;
|
|
|
|
final String column = "_data";
|
|
|
|
final String[] projection = {
|
|
|
|
column
|
|
|
|
};
|
|
|
|
|
|
|
|
try {
|
|
|
|
cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
|
|
|
|
if (cursor != null && cursor.moveToFirst()) {
|
|
|
|
final int index = cursor.getColumnIndexOrThrow(column);
|
|
|
|
return cursor.getString(index);
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
if (cursor != null)
|
|
|
|
cursor.close();
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static String getFilePath(Context context, Uri uri) {
|
|
|
|
Cursor cursor = null;
|
|
|
|
final String[] projection = { MediaStore.MediaColumns.DISPLAY_NAME };
|
|
|
|
|
|
|
|
try {
|
|
|
|
cursor = context.getContentResolver().query(uri, projection, null, null, null);
|
|
|
|
if (cursor != null && cursor.moveToFirst()) {
|
|
|
|
final int index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DISPLAY_NAME);
|
|
|
|
return cursor.getString(index);
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
if (cursor != null)
|
|
|
|
cursor.close();
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param uri The Uri to check.
|
|
|
|
* @return Whether the Uri authority is ExternalStorageProvider.
|
|
|
|
*/
|
|
|
|
public static boolean isExternalStorageDocument(Uri uri) {
|
|
|
|
return "com.android.externalstorage.documents".equals(uri.getAuthority());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param uri The Uri to check.
|
|
|
|
* @return Whether the Uri authority is DownloadsProvider.
|
|
|
|
*/
|
|
|
|
public static boolean isDownloadsDocument(Uri uri) {
|
|
|
|
return "com.android.providers.downloads.documents".equals(uri.getAuthority());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param uri The Uri to check.
|
|
|
|
* @return Whether the Uri authority is MediaProvider.
|
|
|
|
*/
|
|
|
|
public static boolean isMediaDocument(Uri uri) {
|
|
|
|
return "com.android.providers.media.documents".equals(uri.getAuthority());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param uri The Uri to check.
|
|
|
|
* @return Whether the Uri authority is Google Photos.
|
|
|
|
*/
|
|
|
|
public static boolean isGooglePhotosUri(Uri uri) {
|
|
|
|
return "com.google.android.apps.photos.content".equals(uri.getAuthority());
|
|
|
|
}
|
2018-03-11 16:32:13 +01:00
|
|
|
}
|