正在查看: Bedrock Radio v1.1.1 应用的 SystemSetting.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Bedrock Radio v1.1.1 应用的 SystemSetting.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.ninty.system.setting;
import android.app.Activity;
import android.app.NotificationManager;
import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.location.LocationManager;
import android.media.AudioManager;
import android.net.Uri;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.provider.Settings;
import android.util.Log;
import android.view.WindowManager;
import com.facebook.react.bridge.ActivityEventListener;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.LifecycleEventListener;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.google.common.primitives.Ints;
import com.google.firebase.analytics.FirebaseAnalytics;
public class SystemSetting extends ReactContextBaseJavaModule implements ActivityEventListener, LifecycleEventListener {
private static final String VOL_ALARM = "alarm";
private static final String VOL_MUSIC = "music";
private static final String VOL_NOTIFICATION = "notification";
private static final String VOL_RING = "ring";
private static final String VOL_SYSTEM = "system";
private static final String VOL_VOICE_CALL = "call";
private String TAG;
private volatile BroadcastReceiver airplaneBR;
private AudioManager am;
private volatile BroadcastReceiver bluetoothBR;
private LocationManager lm;
private volatile BroadcastReceiver locationBR;
private volatile BroadcastReceiver locationModeBR;
private ReactApplicationContext mContext;
private VolumeBroadcastReceiver volumeBR;
private volatile BroadcastReceiver wifiBR;
private WifiManager wm;
public String getName() {
return "SystemSetting";
}
public void onNewIntent(Intent intent) {
}
public SystemSetting(ReactApplicationContext reactApplicationContext) {
super(reactApplicationContext);
this.TAG = "SystemSetting";
this.mContext = reactApplicationContext;
reactApplicationContext.addLifecycleEventListener(this);
this.am = (AudioManager) this.mContext.getApplicationContext().getSystemService("audio");
this.wm = (WifiManager) this.mContext.getApplicationContext().getSystemService("wifi");
this.lm = (LocationManager) this.mContext.getApplicationContext().getSystemService(FirebaseAnalytics.Param.LOCATION);
this.volumeBR = new VolumeBroadcastReceiver();
}
private void registerVolumeReceiver() {
if (this.volumeBR.isRegistered()) {
return;
}
this.mContext.registerReceiver(this.volumeBR, new IntentFilter("android.media.VOLUME_CHANGED_ACTION"));
this.volumeBR.setRegistered(true);
}
private void unregisterVolumeReceiver() {
if (this.volumeBR.isRegistered()) {
this.mContext.unregisterReceiver(this.volumeBR);
this.volumeBR.setRegistered(false);
}
}
private void listenWifiState() {
if (this.wifiBR == null) {
synchronized (this) {
if (this.wifiBR == null) {
this.wifiBR = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("android.net.wifi.WIFI_STATE_CHANGED")) {
int intExtra = intent.getIntExtra("wifi_state", 0);
if (intExtra == 3 || intExtra == 1) {
SystemSetting.this.mContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("EventWifiChange", Boolean.valueOf(intExtra == 3));
}
}
}
};
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("android.net.wifi.WIFI_STATE_CHANGED");
this.mContext.registerReceiver(this.wifiBR, intentFilter);
}
}
}
}
private void listenBluetoothState() {
if (this.bluetoothBR == null) {
synchronized (this) {
if (this.bluetoothBR == null) {
this.bluetoothBR = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("android.bluetooth.adapter.action.STATE_CHANGED")) {
int intExtra = intent.getIntExtra("android.bluetooth.adapter.extra.STATE", 0);
if (intExtra == 12 || intExtra == 10) {
SystemSetting.this.mContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("EventBluetoothChange", Boolean.valueOf(intExtra == 12));
}
}
}
};
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("android.bluetooth.adapter.action.STATE_CHANGED");
this.mContext.registerReceiver(this.bluetoothBR, intentFilter);
}
}
}
}
private void listenLocationState() {
if (this.locationBR == null) {
synchronized (this) {
if (this.locationBR == null) {
this.locationBR = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("android.location.PROVIDERS_CHANGED")) {
SystemSetting.this.mContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("EventLocationChange", Boolean.valueOf(SystemSetting.this.isLocationEnable()));
}
}
};
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("android.location.PROVIDERS_CHANGED");
this.mContext.registerReceiver(this.locationBR, intentFilter);
}
}
}
}
private void listenLocationModeState() {
if (this.locationModeBR == null) {
synchronized (this) {
if (this.locationModeBR == null) {
this.locationModeBR = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("android.location.MODE_CHANGED")) {
SystemSetting.this.mContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("EventLocationModeChange", Integer.valueOf(SystemSetting.this.getLocationMode()));
}
}
};
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("android.location.MODE_CHANGED");
this.mContext.registerReceiver(this.locationModeBR, intentFilter);
}
}
}
}
private void listenAirplaneState() {
if (this.airplaneBR == null) {
synchronized (this) {
if (this.airplaneBR == null) {
this.airplaneBR = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
try {
int i = Settings.System.getInt(SystemSetting.this.mContext.getContentResolver(), "airplane_mode_on");
DeviceEventManagerModule.RCTDeviceEventEmitter jSModule = SystemSetting.this.mContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class);
boolean z = true;
if (i != 1) {
z = false;
}
jSModule.emit("EventAirplaneChange", Boolean.valueOf(z));
} catch (Settings.SettingNotFoundException e) {
Log.e(SystemSetting.this.TAG, "err", e);
}
}
};
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("android.intent.action.AIRPLANE_MODE");
this.mContext.registerReceiver(this.airplaneBR, intentFilter);
}
}
}
}
@ReactMethod
public void setScreenMode(int i, Promise promise) {
if (i != 0) {
i = 1;
}
checkAndSet("screen_brightness_mode", i, promise);
}
@ReactMethod
public void getScreenMode(Promise promise) {
try {
promise.resolve(Integer.valueOf(Settings.System.getInt(this.mContext.getContentResolver(), "screen_brightness_mode")));
} catch (Settings.SettingNotFoundException e) {
Log.e(this.TAG, "err", e);
promise.reject("-1", "get screen mode fail", e);
}
}
@ReactMethod
public void setBrightness(float f, Promise promise) {
checkAndSet("screen_brightness", (int) (f * 255.0f), promise);
}
@ReactMethod
public void setAppBrightness(float f) {
final Activity currentActivity = getCurrentActivity();
if (currentActivity == null) {
return;
}
final WindowManager.LayoutParams attributes = currentActivity.getWindow().getAttributes();
attributes.screenBrightness = f;
currentActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
currentActivity.getWindow().setAttributes(attributes);
}
});
}
@ReactMethod
public void getAppBrightness(Promise promise) {
Activity currentActivity = getCurrentActivity();
if (currentActivity == null) {
return;
}
try {
float f = currentActivity.getWindow().getAttributes().screenBrightness;
if (f < 0.0f) {
promise.resolve(Float.valueOf((Settings.System.getInt(this.mContext.getContentResolver(), "screen_brightness") * 1.0f) / 255.0f));
} else {
promise.resolve(Float.valueOf(f));
}
} catch (Exception e) {
Log.e(this.TAG, "err", e);
promise.reject("-1", "get app's brightness fail", e);
}
}
@ReactMethod
public void openWriteSetting() {
this.mContext.getCurrentActivity().startActivity(new Intent(SysSettings.WRITESETTINGS.action, Uri.parse("package:" + this.mContext.getPackageName())));
}
@ReactMethod
public void getBrightness(Promise promise) {
try {
promise.resolve(Float.valueOf((Settings.System.getInt(this.mContext.getContentResolver(), "screen_brightness") * 1.0f) / 255.0f));
} catch (Settings.SettingNotFoundException e) {
Log.e(this.TAG, "err", e);
promise.reject("-1", "get brightness fail", e);
}
}
@ReactMethod
public void setVolume(float f, ReadableMap readableMap) {
boolean isNotificationPolicyAccessGranted;
unregisterVolumeReceiver();
String string = readableMap.getString("type");
boolean z = readableMap.getBoolean("playSound");
boolean z2 = readableMap.getBoolean("showUI");
int volType = getVolType(string);
int i = z ? 4 : 0;
if (z2) {
i |= 1;
}
try {
this.am.setStreamVolume(volType, (int) (r5.getStreamMaxVolume(volType) * f), i);
} catch (SecurityException e) {
if (f == 0.0f) {
Log.w(this.TAG, "setVolume(0) failed. See https://github.com/c19354837/react-native-system-setting/issues/48");
NotificationManager notificationManager = (NotificationManager) this.mContext.getSystemService(VOL_NOTIFICATION);
if (Build.VERSION.SDK_INT >= 23) {
isNotificationPolicyAccessGranted = notificationManager.isNotificationPolicyAccessGranted();
if (!isNotificationPolicyAccessGranted) {
this.mContext.startActivity(new Intent("android.settings.NOTIFICATION_POLICY_ACCESS_SETTINGS"));
}
}
}
Log.e(this.TAG, "err", e);
}
registerVolumeReceiver();
}
@ReactMethod
public void getVolume(String str, Promise promise) {
promise.resolve(Float.valueOf(getNormalizationVolume(str)));
}
private void checkAndSet(java.lang.String r5, int r6, com.facebook.react.bridge.Promise r7) {
throw new UnsupportedOperationException("Method not decompiled: com.ninty.system.setting.SystemSetting.checkAndSet(java.lang.String, int, com.facebook.react.bridge.Promise):void");
}
public float getNormalizationVolume(String str) {
int volType = getVolType(str);
return (this.am.getStreamVolume(volType) * 1.0f) / this.am.getStreamMaxVolume(volType);
}
private int getVolType(String str) {
str.hashCode();
switch (str) {
case "system":
return 1;
case "call":
return 0;
case "ring":
return 2;
case "alarm":
return 4;
case "notification":
return 5;
default:
return 3;
}
}
@ReactMethod
public void isWifiEnabled(Promise promise) {
WifiManager wifiManager = this.wm;
if (wifiManager != null) {
promise.resolve(Boolean.valueOf(wifiManager.isWifiEnabled()));
} else {
promise.reject("-1", "get wifi manager fail");
}
}
@ReactMethod
public void switchWifiSilence() {
if (this.wm != null) {
listenWifiState();
this.wm.setWifiEnabled(!r0.isWifiEnabled());
return;
}
Log.w(this.TAG, "Cannot get wifi manager, switchWifi will be ignored");
}
@ReactMethod
public void switchWifi() {
switchSetting(SysSettings.WIFI);
}
@ReactMethod
public void isLocationEnabled(Promise promise) {
if (this.lm != null) {
promise.resolve(Boolean.valueOf(isLocationEnable()));
} else {
promise.reject("-1", "get location manager fail");
}
}
@ReactMethod
public void getLocationMode(Promise promise) {
if (this.lm != null) {
promise.resolve(Integer.valueOf(getLocationMode()));
} else {
promise.reject("-1", "get location manager fail");
}
}
public int getLocationMode() {
boolean isProviderEnabled = this.lm.isProviderEnabled("gps");
return this.lm.isProviderEnabled("network") ? (isProviderEnabled ? 1 : 0) | 2 : isProviderEnabled ? 1 : 0;
}
public boolean isLocationEnable() {
return this.lm.isProviderEnabled("gps") || this.lm.isProviderEnabled("network");
}
@ReactMethod
public void switchLocation() {
switchSetting(SysSettings.LOCATION);
}
@ReactMethod
public void isBluetoothEnabled(Promise promise) {
BluetoothAdapter defaultAdapter = BluetoothAdapter.getDefaultAdapter();
promise.resolve(Boolean.valueOf(defaultAdapter != null && defaultAdapter.isEnabled()));
}
@ReactMethod
public void switchBluetooth() {
switchSetting(SysSettings.BLUETOOTH);
}
@ReactMethod
public void switchBluetoothSilence() {
BluetoothAdapter defaultAdapter = BluetoothAdapter.getDefaultAdapter();
if (defaultAdapter != null) {
listenBluetoothState();
if (defaultAdapter.isEnabled()) {
defaultAdapter.disable();
} else {
defaultAdapter.enable();
}
}
}
@ReactMethod
public void activeListener(String str, Promise promise) {
str.hashCode();
switch (str) {
case "airplane":
listenAirplaneState();
promise.resolve((Object) null);
break;
case "locationMode":
listenLocationModeState();
promise.resolve((Object) null);
break;
case "wifi":
listenWifiState();
promise.resolve((Object) null);
break;
case "location":
listenLocationState();
promise.resolve((Object) null);
break;
case "bluetooth":
listenBluetoothState();
promise.resolve((Object) null);
break;
default:
promise.reject("-1", "unsupported listener type: " + str);
break;
}
}
@ReactMethod
public void isAirplaneEnabled(Promise promise) {
try {
boolean z = true;
if (Settings.System.getInt(this.mContext.getContentResolver(), "airplane_mode_on") != 1) {
z = false;
}
promise.resolve(Boolean.valueOf(z));
} catch (Settings.SettingNotFoundException e) {
Log.e(this.TAG, "err", e);
promise.reject("-1", "get airplane mode fail", e);
}
}
@ReactMethod
public void switchAirplane() {
switchSetting(SysSettings.AIRPLANE);
}
private void switchSetting(SysSettings sysSettings) {
if (this.mContext.getCurrentActivity() != null) {
this.mContext.addActivityEventListener(this);
this.mContext.getCurrentActivity().startActivityForResult(new Intent(sysSettings.action), sysSettings.requestCode);
return;
}
Log.w(this.TAG, "getCurrentActivity() return null, switch will be ignore");
}
@ReactMethod
public void openAppSystemSettings() {
Intent intent = new Intent("android.settings.APPLICATION_DETAILS_SETTINGS");
intent.addFlags(268435456);
intent.addFlags(Ints.MAX_POWER_OF_TWO);
intent.setData(Uri.parse("package:" + this.mContext.getPackageName()));
if (intent.resolveActivity(this.mContext.getPackageManager()) != null) {
this.mContext.startActivity(intent);
}
}
public void onActivityResult(Activity activity, int i, int i2, Intent intent) {
if (SysSettings.get(i) != SysSettings.UNKNOW) {
this.mContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("EventEnterForeground", (Object) null);
this.mContext.removeActivityEventListener(this);
}
}
public void onHostResume() {
registerVolumeReceiver();
}
public void onHostPause() {
unregisterVolumeReceiver();
}
public void onHostDestroy() {
if (this.wifiBR != null) {
this.mContext.unregisterReceiver(this.wifiBR);
this.wifiBR = null;
}
if (this.bluetoothBR != null) {
this.mContext.unregisterReceiver(this.bluetoothBR);
this.bluetoothBR = null;
}
if (this.locationBR != null) {
this.mContext.unregisterReceiver(this.locationBR);
this.locationBR = null;
}
if (this.locationModeBR != null) {
this.mContext.unregisterReceiver(this.locationModeBR);
this.locationBR = null;
}
if (this.airplaneBR != null) {
this.mContext.unregisterReceiver(this.airplaneBR);
this.airplaneBR = null;
}
}
private class VolumeBroadcastReceiver extends BroadcastReceiver {
private boolean isRegistered;
private VolumeBroadcastReceiver() {
this.isRegistered = false;
}
public void setRegistered(boolean z) {
this.isRegistered = z;
}
public boolean isRegistered() {
return this.isRegistered;
}
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("android.media.VOLUME_CHANGED_ACTION")) {
WritableMap createMap = Arguments.createMap();
createMap.putDouble(FirebaseAnalytics.Param.VALUE, SystemSetting.this.getNormalizationVolume(SystemSetting.VOL_MUSIC));
createMap.putDouble(SystemSetting.VOL_VOICE_CALL, SystemSetting.this.getNormalizationVolume(SystemSetting.VOL_VOICE_CALL));
createMap.putDouble(SystemSetting.VOL_SYSTEM, SystemSetting.this.getNormalizationVolume(SystemSetting.VOL_SYSTEM));
createMap.putDouble(SystemSetting.VOL_RING, SystemSetting.this.getNormalizationVolume(SystemSetting.VOL_RING));
createMap.putDouble(SystemSetting.VOL_MUSIC, SystemSetting.this.getNormalizationVolume(SystemSetting.VOL_MUSIC));
createMap.putDouble(SystemSetting.VOL_ALARM, SystemSetting.this.getNormalizationVolume(SystemSetting.VOL_ALARM));
createMap.putDouble(SystemSetting.VOL_NOTIFICATION, SystemSetting.this.getNormalizationVolume(SystemSetting.VOL_NOTIFICATION));
try {
SystemSetting.this.mContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("EventVolume", createMap);
} catch (RuntimeException unused) {
}
}
}
}
}