2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-09-01 06:35:09 +00:00

Apply some coding style to TelephonyPlugin

Summary: Unify coding style, remove commented code

Reviewers: #kde_connect, albertvaka

Reviewed By: #kde_connect, albertvaka

Subscribers: albertvaka, #kde_connect

Tags: #kde_connect

Differential Revision: https://phabricator.kde.org/D10519
This commit is contained in:
Nicolas Fella
2018-02-22 00:48:55 +01:00
parent 97d69c674a
commit 82db080a51

View File

@@ -47,26 +47,13 @@ import java.util.TimerTask;
public class TelephonyPlugin extends Plugin { public class TelephonyPlugin extends Plugin {
public final static String PACKAGE_TYPE_TELEPHONY = "kdeconnect.telephony"; private final static String PACKAGE_TYPE_TELEPHONY = "kdeconnect.telephony";
public final static String PACKAGE_TYPE_TELEPHONY_REQUEST = "kdeconnect.telephony.request"; public final static String PACKAGE_TYPE_TELEPHONY_REQUEST = "kdeconnect.telephony.request";
private int lastState = TelephonyManager.CALL_STATE_IDLE; private int lastState = TelephonyManager.CALL_STATE_IDLE;
private NetworkPackage lastPackage = null; private NetworkPackage lastPackage = null;
private boolean isMuted = false; private boolean isMuted = false;
private int telephonyPermissionExplanation = R.string.telephony_permission_explanation;
private int telephonyOptionalPermissionExplanation = R.string.telephony_optional_permission_explanation;
@Override
public String getDisplayName() {
return context.getResources().getString(R.string.pref_plugin_telephony);
}
@Override
public String getDescription() {
return context.getResources().getString(R.string.pref_plugin_telephony_desc);
}
private final BroadcastReceiver receiver = new BroadcastReceiver() { private final BroadcastReceiver receiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
@@ -80,12 +67,12 @@ public class TelephonyPlugin extends Plugin {
final Bundle bundle = intent.getExtras(); final Bundle bundle = intent.getExtras();
if (bundle == null) return; if (bundle == null) return;
final Object[] pdus = (Object[]) bundle.get("pdus"); final Object[] pdus = (Object[]) bundle.get("pdus");
ArrayList<SmsMessage> messages = new ArrayList<SmsMessage>(); ArrayList<SmsMessage> messages = new ArrayList<>();
for (Object pdu : pdus) { for (Object pdu : pdus) {
// I hope, but am not sure, that the pdus array is in the order that the parts // I hope, but am not sure, that the pdus array is in the order that the parts
// of the SMS message should be // of the SMS message should be
// If it is not, I belive the pdu contains the information necessary to put it // If it is not, I believe the pdu contains the information necessary to put it
// in order, but in my testing the order seems to be correct, so I won't worry // in order, but in my testing the order seems to be correct, so I won't worry
// about it now. // about it now.
messages.add(SmsMessage.createFromPdu((byte[]) pdu)); messages.add(SmsMessage.createFromPdu((byte[]) pdu));
@@ -103,7 +90,8 @@ public class TelephonyPlugin extends Plugin {
intState = TelephonyManager.CALL_STATE_OFFHOOK; intState = TelephonyManager.CALL_STATE_OFFHOOK;
String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER); String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
if (number == null) number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER); if (number == null)
number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
final int finalIntState = intState; final int finalIntState = intState;
final String finalNumber = number; final String finalNumber = number;
@@ -114,9 +102,17 @@ public class TelephonyPlugin extends Plugin {
} }
}; };
private void callBroadcastReceived(int state, String phoneNumber) { @Override
public String getDisplayName() {
return context.getResources().getString(R.string.pref_plugin_telephony);
}
//Log.e("TelephonyPlugin", "callBroadcastReceived"); @Override
public String getDescription() {
return context.getResources().getString(R.string.pref_plugin_telephony_desc);
}
private void callBroadcastReceived(int state, String phoneNumber) {
NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_TELEPHONY); NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_TELEPHONY);
@@ -221,14 +217,11 @@ public class TelephonyPlugin extends Plugin {
private void smsBroadcastReceived(ArrayList<SmsMessage> messages) { private void smsBroadcastReceived(ArrayList<SmsMessage> messages) {
if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) {
if (!(messages.size() > 0)) if (!(messages.size() > 0)) {
{
throw new AssertionError("This method requires at least one message"); throw new AssertionError("This method requires at least one message");
} }
} }
//Log.e("SmsBroadcastReceived", message.toString());
NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_TELEPHONY); NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_TELEPHONY);
np.set("event", "sms"); np.set("event", "sms");
@@ -260,19 +253,17 @@ public class TelephonyPlugin extends Plugin {
} }
device.sendPackage(np); device.sendPackage(np);
} }
@Override @Override
public boolean onCreate() { public boolean onCreate() {
//Log.e("TelephonyPlugin", "onCreate");
IntentFilter filter = new IntentFilter("android.provider.Telephony.SMS_RECEIVED"); IntentFilter filter = new IntentFilter("android.provider.Telephony.SMS_RECEIVED");
filter.setPriority(500); filter.setPriority(500);
filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED); filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
context.registerReceiver(receiver, filter); context.registerReceiver(receiver, filter);
permissionExplanation = telephonyPermissionExplanation; permissionExplanation = R.string.telephony_permission_explanation;
optionalPermissionExplanation = telephonyOptionalPermissionExplanation; optionalPermissionExplanation = R.string.telephony_optional_permission_explanation;
return true; return true;
} }
@@ -293,7 +284,6 @@ public class TelephonyPlugin extends Plugin {
} }
isMuted = true; isMuted = true;
} }
//Log.e("TelephonyPlugin", "mute");
} }
//Do nothing //Do nothing
return true; return true;