正在查看: imToken v3.28.8 应用的 MainActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: imToken v3.28.8 应用的 MainActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package org.consenlabs.imtoken;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.content.Intent;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import com.facebook.react.ReactActivity;
import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.ReactRootView;
import com.facebook.react.modules.core.PermissionListener;
import com.imagepicker.permissions.OnImagePickerPermissionsCallback;
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;
import java.lang.ref.WeakReference;
import java.util.concurrent.CountDownLatch;
import org.consenlabs.tokencore.wallet.model.TokenException;
public class MainActivity extends ReactActivity implements OnImagePickerPermissionsCallback {
private static int PERMISSIONS_REQUEST_LOCATION = 2;
private static int REQUEST_ENABLE_BT = 1;
public static MainActivity sInstance;
private static WeakReference<MainActivity> sWeakInstance;
private PermissionListener listener;
public CountDownLatch mPermissionLatch;
public int mPermissionResult = 0;
private Handler mUIHandler;
protected String getMainComponentName() {
return "token";
}
public static MainActivity getInstance() {
return sWeakInstance.get();
}
protected ReactActivityDelegate createReactActivityDelegate() {
return new ReactActivityDelegate(this, getMainComponentName()) {
protected ReactRootView createRootView() {
return new RNGestureHandlerEnabledRootView(MainActivity.this);
}
};
}
protected void onSaveInstanceState(Bundle bundle) {
super.onSaveInstanceState(bundle);
View findViewById = findViewById(android.R.id.content);
if (findViewById != null) {
findViewById.cancelPendingInputEvents();
}
}
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
sWeakInstance = new WeakReference<>(this);
this.mUIHandler = new Handler(getMainLooper());
sInstance = this;
}
protected void onResume() {
super.onResume();
getWindow().clearFlags(8192);
}
protected void onPause() {
getWindow().addFlags(8192);
super.onPause();
}
public void enableBluetooth() {
BluetoothAdapter defaultAdapter = BluetoothAdapter.getDefaultAdapter();
if (defaultAdapter == null) {
throw new TokenException("device_not_support_bluetooth");
}
if (defaultAdapter.isEnabled()) {
return;
}
Intent intent = new Intent("android.bluetooth.adapter.action.REQUEST_ENABLE");
if (getInstance() != null) {
this.mPermissionResult = -1;
this.mPermissionLatch = new CountDownLatch(1);
getInstance().startActivityForResult(intent, REQUEST_ENABLE_BT);
try {
this.mPermissionLatch.await();
if (this.mPermissionResult != -1) {
throw new TokenException("enable_bluetooth_failed");
}
} catch (InterruptedException unused) {
throw new TokenException("operation_timeout");
}
}
}
public void enableLocationPermission() {
if (ContextCompat.checkSelfPermission(this, "android.permission.ACCESS_COARSE_LOCATION") != 0) {
if (ActivityCompat.shouldShowRequestPermissionRationale(this, "android.permission.ACCESS_COARSE_LOCATION")) {
throw new TokenException("location_permission_forbidden");
}
this.mPermissionLatch = new CountDownLatch(1);
this.mPermissionResult = 0;
ActivityCompat.requestPermissions(this, new String[]{"android.permission.ACCESS_COARSE_LOCATION", "android.permission.ACCESS_FINE_LOCATION"}, PERMISSIONS_REQUEST_LOCATION);
try {
this.mPermissionLatch.await();
if (this.mPermissionResult != 0) {
throw new TokenException("enable_location_failed");
}
} catch (InterruptedException unused) {
throw new TokenException("operation_timeout");
}
}
}
public void checkDeviceLocationPowerOn() {
if (!isLocationPoweron(this)) {
throw new TokenException("location_power_off");
}
}
public void onActivityResult(int i, int i2, Intent intent) {
if (i == REQUEST_ENABLE_BT) {
this.mPermissionResult = i2;
CountDownLatch countDownLatch = this.mPermissionLatch;
if (countDownLatch != null) {
countDownLatch.countDown();
}
}
super.onActivityResult(i, i2, intent);
}
public void setPermissionListener(PermissionListener permissionListener) {
this.listener = permissionListener;
}
public void onRequestPermissionsResult(int i, String[] strArr, int[] iArr) {
PermissionListener permissionListener = this.listener;
if (permissionListener != null) {
permissionListener.onRequestPermissionsResult(i, strArr, iArr);
}
if (i == PERMISSIONS_REQUEST_LOCATION) {
int length = iArr.length;
int i2 = 0;
while (true) {
if (i2 >= length) {
break;
}
if (iArr[i2] == -1) {
this.mPermissionResult = -1;
break;
}
i2++;
}
}
CountDownLatch countDownLatch = this.mPermissionLatch;
if (countDownLatch != null) {
countDownLatch.countDown();
}
super.onRequestPermissionsResult(i, strArr, iArr);
}
public static final boolean isLocationPoweron(Context context) {
LocationManager locationManager = (LocationManager) context.getSystemService("location");
return locationManager.isProviderEnabled("gps") || locationManager.isProviderEnabled("network");
}
}